]> granicus.if.org Git - strace/blob - kcmp.c
Change the license of strace to LGPL-2.1-or-later
[strace] / kcmp.c
1 /*
2  * Copyright (c) 2015 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2015-2017 The strace developers.
4  * All rights reserved.
5  *
6  * SPDX-License-Identifier: LGPL-2.1-or-later
7  */
8
9 #include "defs.h"
10 #include "print_fields.h"
11 #include "xlat/kcmp_types.h"
12
13 struct strace_kcmp_epoll_slot {
14         uint32_t efd;
15         uint32_t tfd;
16         uint32_t toff;
17 };
18
19 static void
20 printpidfd(struct tcb *tcp, pid_t pid, int fd)
21 {
22         /*
23          * XXX We want to use printfd here, but we should figure out which
24          *     process in strace's PID NS is referred to first.
25          */
26         tprintf("%d", fd);
27 }
28
29 #define PRINT_FIELD_PIDFD(prefix_, where_, field_, tcp_, pid_)          \
30         do {                                                            \
31                 STRACE_PRINTF("%s%s=", (prefix_), #field_);             \
32                 printpidfd((tcp_), (pid_), (where_).field_);            \
33         } while (0)
34
35 SYS_FUNC(kcmp)
36 {
37         pid_t pid1 = tcp->u_arg[0];
38         pid_t pid2 = tcp->u_arg[1];
39         int type = tcp->u_arg[2];
40         kernel_ulong_t idx1 = tcp->u_arg[3];
41         kernel_ulong_t idx2 = tcp->u_arg[4];
42
43         tprintf("%d, %d, ", pid1, pid2);
44         printxval(kcmp_types, type, "KCMP_???");
45
46         switch (type) {
47                 case KCMP_FILE:
48                         tprints(", ");
49                         printpidfd(tcp, pid1, idx1);
50                         tprints(", ");
51                         printpidfd(tcp, pid1, idx2);
52
53                         break;
54
55                 case KCMP_EPOLL_TFD: {
56                         struct strace_kcmp_epoll_slot slot;
57
58                         tprints(", ");
59                         printpidfd(tcp, pid1, idx1);
60                         tprints(", ");
61
62                         if (umove_or_printaddr(tcp, idx2, &slot))
63                                 break;
64
65                         PRINT_FIELD_PIDFD("{",  slot, efd, tcp, pid2);
66                         PRINT_FIELD_PIDFD(", ", slot, tfd, tcp, pid2);
67                         PRINT_FIELD_U(", ", slot, toff);
68                         tprints("}");
69
70                         break;
71                 }
72
73                 case KCMP_FILES:
74                 case KCMP_FS:
75                 case KCMP_IO:
76                 case KCMP_SIGHAND:
77                 case KCMP_SYSVSEM:
78                 case KCMP_VM:
79                         break;
80                 default:
81                         tprintf(", %#" PRI_klx ", %#" PRI_klx, idx1, idx2);
82         }
83
84         return RVAL_DECODED;
85 }