]> granicus.if.org Git - strace/blob - ipc_shmctl.c
evdev: decode struct input_absinfo regardless of in-kernel definitions
[strace] / ipc_shmctl.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(shmid_ds_t)
17
18 #include "ipc_defs.h"
19
20 #ifdef HAVE_SYS_SHM_H
21 /* The C library generally exports the struct the current kernel expects. */
22 # include <sys/shm.h>
23 typedef struct shmid_ds shmid_ds_t;
24 #elif defined HAVE_LINUX_SHM_H
25 /* The linux header might provide the right struct. */
26 # include <linux/shm.h>
27 typedef struct shmid64_ds shmid_ds_t;
28 #endif
29
30 #include MPERS_DEFS
31
32 #include "xlat/shmctl_flags.h"
33
34 static void
35 print_shmid_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         shmid_ds_t shmid_ds;
41         switch (cmd) {
42         case IPC_SET:
43         case IPC_STAT:
44                 if (umove_or_printaddr(tcp, addr, &shmid_ds))
45                         return;
46
47                 tprints("{shm_perm={");
48                 printuid("uid=", shmid_ds.shm_perm.uid);
49                 printuid(", gid=", shmid_ds.shm_perm.gid);
50                 tprints(", mode=");
51                 print_numeric_umode_t(shmid_ds.shm_perm.mode);
52
53                 if (cmd != IPC_STAT) {
54                         tprints("}, ...}");
55                         break;
56                 }
57
58                 tprintf(", key=%u", (unsigned) shmid_ds.shm_perm.__key);
59                 printuid(", cuid=", shmid_ds.shm_perm.cuid);
60                 printuid(", cgid=", shmid_ds.shm_perm.cgid);
61                 tprints("}");
62                 tprintf(", shm_segsz=%u", (unsigned) shmid_ds.shm_segsz);
63                 tprintf(", shm_cpid=%u", (unsigned) shmid_ds.shm_cpid);
64                 tprintf(", shm_lpid=%u", (unsigned) shmid_ds.shm_lpid);
65                 tprintf(", shm_nattch=%u", (unsigned) shmid_ds.shm_nattch);
66                 tprintf(", shm_atime=%u", (unsigned) shmid_ds.shm_atime);
67                 tprintf(", shm_dtime=%u", (unsigned) shmid_ds.shm_dtime);
68                 tprintf(", shm_ctime=%u", (unsigned) shmid_ds.shm_ctime);
69                 tprints("}");
70                 break;
71
72         default:
73                 printaddr(addr);
74                 break;
75         }
76 }
77
78 SYS_FUNC(shmctl)
79 {
80         if (entering(tcp)) {
81                 tprintf("%d, ", (int) tcp->u_arg[0]);
82                 PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
83                 tprints(", ");
84         } else {
85                 const kernel_ulong_t addr = tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2];
86                 print_shmid_ds(tcp, addr, tcp->u_arg[1]);
87         }
88         return 0;
89 }