From: Elvira Khabirova Date: Fri, 31 Jul 2015 15:43:21 +0000 (+0300) Subject: Enhance shmctl syscall decoding X-Git-Tag: v4.11~230 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=0a6af9b0a45553587954ef306d56e78ac1f4f363;p=strace Enhance shmctl syscall decoding 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. --- diff --git a/ipc_shmctl.c b/ipc_shmctl.c index 6bb468f0..4bd6c85c 100644 --- a/ipc_shmctl.c +++ b/ipc_shmctl.c @@ -35,13 +35,65 @@ #include +#include DEF_MPERS_TYPE(shmid_ds_t) +#include +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; } diff --git a/tests/ipc_shm.c b/tests/ipc_shm.c index 95a1d578..b5c9784b 100644 --- a/tests/ipc_shm.c +++ b/tests/ipc_shm.c @@ -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)