]> granicus.if.org Git - strace/commitdiff
Enhance shmctl syscall decoding
authorElvira Khabirova <lineprinter0@gmail.com>
Fri, 31 Jul 2015 15:43:21 +0000 (18:43 +0300)
committerDmitry V. Levin <ldv@altlinux.org>
Fri, 28 Aug 2015 08:46:23 +0000 (08:46 +0000)
Make parser of shmctl syscall print struct shmid_ds.

* ipc_shmctl.c (shmid_ds_t): New typedef.  Mpersify it.
(print_shmid_ds): New function.  Use shmid_ds_t.
(sys_shmctl): Use print_shmid_ds.
* tests/ipc_shm.c: Update for struct shmid_ds support.

ipc_shmctl.c
tests/ipc_shm.c

index 6bb468f022801a9158b0bac9b20587aa85189099..4bd6c85ce4e56d45b35a83cd2c4abc94c3fbc8cd 100644 (file)
 
 #include <sys/shm.h>
 
+#include DEF_MPERS_TYPE(shmid_ds_t)
+#include <sys/shm.h>
+typedef struct shmid_ds shmid_ds_t;
+#include MPERS_DEFS
+
 #include "xlat/shmctl_flags.h"
 
+static void
+print_shmid_ds(struct tcb *tcp, const long addr, int cmd)
+{
+       if (cmd & IPC_64)
+               cmd &= ~IPC_64;
+       shmid_ds_t shmid_ds;
+       switch (cmd) {
+       case IPC_SET:
+       case IPC_STAT:
+               if (umove_or_printaddr(tcp, addr, &shmid_ds))
+                       return;
+
+               tprints("{shm_perm={");
+               printuid("uid=", shmid_ds.shm_perm.uid);
+               printuid(", gid=", shmid_ds.shm_perm.gid);
+               tprints(", mode=");
+               tprints(sprintmode(shmid_ds.shm_perm.mode));
+
+               if (cmd != IPC_STAT) {
+                       tprints("}, ...}");
+                       break;
+               }
+
+               tprintf(", key=%u", (unsigned) shmid_ds.shm_perm.__key);
+               printuid(", cuid=", shmid_ds.shm_perm.cuid);
+               printuid(", cgid=", shmid_ds.shm_perm.cgid);
+               tprints("}");
+               tprintf(", shm_segsz=%u", (unsigned) shmid_ds.shm_segsz);
+               tprintf(", shm_cpid=%u", (unsigned) shmid_ds.shm_cpid);
+               tprintf(", shm_lpid=%u", (unsigned) shmid_ds.shm_lpid);
+               tprintf(", shm_nattch=%u", (unsigned) shmid_ds.shm_nattch);
+               tprintf(", shm_atime=%u", (unsigned) shmid_ds.shm_atime);
+               tprintf(", shm_dtime=%u", (unsigned) shmid_ds.shm_dtime);
+               tprintf(", shm_ctime=%u", (unsigned) shmid_ds.shm_ctime);
+               tprints("}");
+               break;
+
+       default:
+               printaddr(addr);
+               break;
+       }
+}
+
 SYS_FUNC(shmctl)
 {
-       tprintf("%lu, ", tcp->u_arg[0]);
-       PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
-       tprints(", ");
-       printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]);
-       return RVAL_DECODED;
+       if (entering(tcp)) {
+               tprintf("%lu, ", tcp->u_arg[0]);
+               PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
+               tprints(", ");
+       } else {
+               const long addr = tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2];
+               print_shmid_ds(tcp, addr, tcp->u_arg[1]);
+       }
+       return 0;
 }
index 95a1d578f9c62bc3810aad825e257a49b74eaccf..b5c9784b87722682c46427592d2aa655e5808a0d 100644 (file)
@@ -15,7 +15,17 @@ main(void)
 
        if (shmctl(id, IPC_STAT, &ds))
                goto fail;
-       printf("shmctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\n", id, &ds);
+       printf("shmctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{shm_perm=\\{uid=%u, gid=%u, "
+               "mode=%#o, key=%u, cuid=%u, cgid=%u\\}, shm_segsz=%u, shm_cpid=%u, "
+               "shm_lpid=%u, shm_nattch=%u, shm_atime=%u, shm_dtime=%u, "
+               "shm_ctime=%u\\}\\) += 0\n",
+               id, (unsigned) ds.shm_perm.uid, (unsigned) ds.shm_perm.gid,
+               (unsigned) ds.shm_perm.mode, (unsigned) ds.shm_perm.__key,
+               (unsigned) ds.shm_perm.cuid, (unsigned) ds.shm_perm.cgid,
+               (unsigned) ds.shm_segsz, (unsigned) ds.shm_cpid,
+               (unsigned) ds.shm_lpid, (unsigned) ds.shm_nattch,
+               (unsigned) ds.shm_atime, (unsigned) ds.shm_dtime,
+               (unsigned) ds. shm_ctime);
 
        int max = shmctl(0, SHM_INFO, &ds);
        if (max < 0)