1 /*
2 * Copyright (c) 2015 Dmitry V. Levin <ldv@strace.io>
3 * Copyright (c) 2015-2021 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 <linux/kcmp.h>
11 #include "xlat/kcmp_types.h"
12
13 #define PRINT_FIELD_PIDFD(where_, field_, tcp_, pid_) \
14 do { \
15 tprints_field_name(#field_); \
16 printfd_pid_tracee_ns((tcp_), (pid_), (where_).field_); \
17 } while (0)
18
19 SYS_FUNC(kcmp)
20 {
21 pid_t pid1 = tcp->u_arg[0];
22 pid_t pid2 = tcp->u_arg[1];
23 int type = tcp->u_arg[2];
24 kernel_ulong_t idx1 = tcp->u_arg[3];
25 kernel_ulong_t idx2 = tcp->u_arg[4];
26
27 /* pid1 */
28 printpid(tcp, pid1, PT_TGID);
29 tprint_arg_next();
30
31 /* pid2 */
32 printpid(tcp, pid2, PT_TGID);
33 tprint_arg_next();
34
35 /* type */
36 printxval(kcmp_types, type, "KCMP_???");
37
38 switch (type) {
39 case KCMP_FILE:
40 /* idx1 */
41 tprint_arg_next();
42 printfd_pid_tracee_ns(tcp, pid1, idx1);
43
44 /* idx2 */
45 tprint_arg_next();
46 printfd_pid_tracee_ns(tcp, pid2, idx2);
47
48 break;
49
50 case KCMP_EPOLL_TFD: {
51 struct kcmp_epoll_slot slot;
52
53 /* idx1 */
54 tprint_arg_next();
55 printfd_pid_tracee_ns(tcp, pid1, idx1);
56 tprint_arg_next();
57
58 /* idx2 */
59 if (umove_or_printaddr(tcp, idx2, &slot))
60 break;
61
62 tprint_struct_begin();
63 PRINT_FIELD_PIDFD(slot, efd, tcp, pid2);
64 tprint_struct_next();
65 PRINT_FIELD_PIDFD(slot, tfd, tcp, pid2);
66 tprint_struct_next();
67 PRINT_FIELD_U(slot, toff);
68 tprint_struct_end();
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 /* idx1 */
82 tprint_arg_next();
83 PRINT_VAL_X(idx1);
84
85 /* idx2 */
86 tprint_arg_next();
87 PRINT_VAL_X(idx2);
88 }
89
90 return RVAL_DECODED;
91 }