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.
This commit is contained in:
Elvira Khabirova 2015-07-31 18:43:21 +03:00 committed by Dmitry V. Levin
parent b7699b55dd
commit 0a6af9b0a4
2 changed files with 68 additions and 6 deletions

View File

@ -35,13 +35,65 @@
#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;
}

View 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)