]> granicus.if.org Git - strace/blob - ipc_msgctl.c
rtnl_neightbl: always decode struct ndt_config and struct ndt_stats
[strace] / ipc_msgctl.c
1 /*
2  * Copyright (c) 1993 Ulrich Pegelow <pegelow@moorea.uni-muenster.de>
3  * Copyright (c) 1993 Branko Lankester <branko@hacktic.nl>
4  * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
5  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * Copyright (c) 2003-2006 Roland McGrath <roland@redhat.com>
7  * Copyright (c) 2006-2015 Dmitry V. Levin <ldv@altlinux.org>
8  * Copyright (c) 2015-2018 The strace developers.
9  * All rights reserved.
10  *
11  * SPDX-License-Identifier: LGPL-2.1-or-later
12  */
13
14 #include "defs.h"
15
16 #include DEF_MPERS_TYPE(msqid_ds_t)
17
18 #include "ipc_defs.h"
19
20 #ifdef HAVE_SYS_MSG_H
21 /* The C library generally exports the struct the current kernel expects. */
22 # include <sys/msg.h>
23 typedef struct msqid_ds msqid_ds_t;
24 #elif defined HAVE_LINUX_MSG_H
25 /* The linux header might provide the right struct. */
26 # include <linux/msg.h>
27 typedef struct msqid64_ds msqid_ds_t;
28 #endif
29
30 #include MPERS_DEFS
31
32 #include "xlat/msgctl_flags.h"
33
34 static void
35 print_msqid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
36 {
37         /* TODO: We don't properly decode old compat ipc calls. */
38         if (cmd & IPC_64)
39                 cmd &= ~IPC_64;
40         msqid_ds_t msqid_ds;
41         switch (cmd) {
42         case IPC_SET:
43         case IPC_STAT:
44                 if (umove_or_printaddr(tcp, addr, &msqid_ds))
45                         return;
46
47                 tprints("{msg_perm={");
48                 printuid("uid=", msqid_ds.msg_perm.uid);
49                 printuid(", gid=", msqid_ds.msg_perm.gid);
50                 tprints(", mode=");
51                 print_numeric_umode_t(msqid_ds.msg_perm.mode);
52
53                 if (cmd != IPC_STAT) {
54                         tprints("}, ...}");
55                         break;
56                 }
57
58                 tprintf(", key=%u", (unsigned) msqid_ds.msg_perm.__key);
59                 printuid(", cuid=", msqid_ds.msg_perm.cuid);
60                 printuid(", cgid=", msqid_ds.msg_perm.cgid);
61                 tprints("}");
62                 tprintf(", msg_stime=%u", (unsigned) msqid_ds.msg_stime);
63                 tprintf(", msg_rtime=%u", (unsigned) msqid_ds.msg_rtime);
64                 tprintf(", msg_ctime=%u", (unsigned) msqid_ds.msg_ctime);
65                 tprintf(", msg_qnum=%u", (unsigned) msqid_ds.msg_qnum);
66                 tprintf(", msg_qbytes=%u", (unsigned) msqid_ds.msg_qbytes);
67                 tprintf(", msg_lspid=%u", (unsigned) msqid_ds.msg_lspid);
68                 tprintf(", msg_lrpid=%u", (unsigned) msqid_ds.msg_lrpid);
69                 tprints("}");
70                 break;
71
72         default:
73                 printaddr(addr);
74                 break;
75         }
76 }
77
78 SYS_FUNC(msgctl)
79 {
80         if (entering(tcp)) {
81                 tprintf("%d, ", (int) tcp->u_arg[0]);
82                 PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
83                 tprints(", ");
84         } else {
85                 const kernel_ulong_t addr = tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2];
86                 print_msqid_ds(tcp, addr, tcp->u_arg[1]);
87         }
88         return 0;
89 }