From d0a61871c8c591505a60f244f4e7be40b28dfc9b Mon Sep 17 00:00:00 2001 From: Elvira Khabirova Date: Tue, 18 Aug 2015 02:01:26 +0300 Subject: [PATCH] Enhance msgctl syscall decoding Make parser of msgctl syscall print struct msqid_ds. * ipc_msgctl.c (msqid_ds_t): New typedef. Mpersify it. (print_msqid_ds): New function. Use msqid_ds_t. (sys_msgctl): Use print_msqid_ds. * tests/ipc_msg.c: Update for struct msqid_ds support. --- ipc_msgctl.c | 60 ++++++++++++++++++++++++++++++++++++++++++++----- tests/ipc_msg.c | 12 +++++++++- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/ipc_msgctl.c b/ipc_msgctl.c index 35d00baf..a97dd1a1 100644 --- a/ipc_msgctl.c +++ b/ipc_msgctl.c @@ -34,14 +34,64 @@ #include "ipc_defs.h" #include +#include DEF_MPERS_TYPE(msqid_ds_t) +typedef struct msqid_ds msqid_ds_t; +#include MPERS_DEFS #include "xlat/msgctl_flags.h" +static void +print_msqid_ds(struct tcb *tcp, const long addr, int cmd) +{ + if (cmd & IPC_64) + cmd &= ~IPC_64; + msqid_ds_t msqid_ds; + switch (cmd) { + case IPC_SET: + case IPC_STAT: + if (umove_or_printaddr(tcp, addr, &msqid_ds)) + return; + + tprints("{msg_perm={"); + printuid("uid=", msqid_ds.msg_perm.uid); + printuid(", gid=", msqid_ds.msg_perm.gid); + tprints(", mode="); + tprints(sprintmode(msqid_ds.msg_perm.mode)); + + if (cmd != IPC_STAT) { + tprints("}, ...}"); + break; + } + + tprintf(", key=%u", (unsigned) msqid_ds.msg_perm.__key); + printuid(", cuid=", msqid_ds.msg_perm.cuid); + printuid(", cgid=", msqid_ds.msg_perm.cgid); + tprints("}"); + tprintf(", msg_stime=%u", (unsigned) msqid_ds.msg_stime); + tprintf(", msg_rtime=%u", (unsigned) msqid_ds.msg_rtime); + tprintf(", msg_ctime=%u", (unsigned) msqid_ds.msg_ctime); + tprintf(", msg_qnum=%u", (unsigned) msqid_ds.msg_qnum); + tprintf(", msg_qbytes=%u", (unsigned) msqid_ds.msg_qbytes); + tprintf(", msg_lspid=%u", (unsigned) msqid_ds.msg_lspid); + tprintf(", msg_lrpid=%u", (unsigned) msqid_ds.msg_lrpid); + tprints("}"); + break; + + default: + printaddr(addr); + break; + } +} + SYS_FUNC(msgctl) { - tprintf("%lu, ", tcp->u_arg[0]); - PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???"); - tprints(", "); - printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]); - return RVAL_DECODED; + if (entering(tcp)) { + tprintf("%lu, ", tcp->u_arg[0]); + PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???"); + tprints(", "); + } else { + const long addr = tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2]; + print_msqid_ds(tcp, addr, tcp->u_arg[1]); + } + return 0; } diff --git a/tests/ipc_msg.c b/tests/ipc_msg.c index 12df6226..42d4c66d 100644 --- a/tests/ipc_msg.c +++ b/tests/ipc_msg.c @@ -15,7 +15,17 @@ main(void) if (msgctl(id, IPC_STAT, &ds)) goto fail; - printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, %p\\) += 0\n", id, &ds); + printf("msgctl\\(%d, (IPC_64\\|)?IPC_STAT, \\{msg_perm=\\{uid=%u, gid=%u, " + "mode=%#o, key=%u, cuid=%u, cgid=%u\\}, msg_stime=%u, msg_rtime=%u, " + "msg_ctime=%u, msg_qnum=%u, msg_qbytes=%u, msg_lspid=%u, " + "msg_lrpid=%u\\}\\) += 0\n", + id, (unsigned) ds.msg_perm.uid, (unsigned) ds.msg_perm.gid, + (unsigned) ds.msg_perm.mode, (unsigned) ds.msg_perm.__key, + (unsigned) ds.msg_perm.cuid, (unsigned) ds.msg_perm.cgid, + (unsigned) ds.msg_stime, (unsigned) ds.msg_rtime, + (unsigned) ds.msg_ctime, (unsigned) ds.msg_qnum, + (unsigned) ds.msg_qbytes, (unsigned) ds.msg_lspid, + (unsigned) ds.msg_lrpid); int max = msgctl(0, MSG_INFO, &ds); if (max < 0)