Mirror of strace – the linux syscall tracer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ipc_msgctl.c 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. #include "defs.h"
  14. #include DEF_MPERS_TYPE(msqid_ds_t)
  15. #include "ipc_defs.h"
  16. #ifdef HAVE_SYS_MSG_H
  17. /* The C library generally exports the struct the current kernel expects. */
  18. # include <sys/msg.h>
  19. typedef struct msqid_ds msqid_ds_t;
  20. #elif defined HAVE_LINUX_MSG_H
  21. /* The linux header might provide the right struct. */
  22. # include <linux/msg.h>
  23. typedef struct msqid64_ds msqid_ds_t;
  24. #endif
  25. #include MPERS_DEFS
  26. #include "xlat/msgctl_flags.h"
  27. static void
  28. print_msqid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
  29. {
  30. /* TODO: We don't properly decode old compat ipc calls. */
  31. if (cmd & IPC_64)
  32. cmd &= ~IPC_64;
  33. msqid_ds_t msqid_ds;
  34. switch (cmd) {
  35. case IPC_SET:
  36. case IPC_STAT:
  37. if (umove_or_printaddr(tcp, addr, &msqid_ds))
  38. return;
  39. tprints("{msg_perm={");
  40. printuid("uid=", msqid_ds.msg_perm.uid);
  41. printuid(", gid=", msqid_ds.msg_perm.gid);
  42. tprints(", mode=");
  43. print_numeric_umode_t(msqid_ds.msg_perm.mode);
  44. if (cmd != IPC_STAT) {
  45. tprints("}, ...}");
  46. break;
  47. }
  48. tprintf(", key=%u", (unsigned) msqid_ds.msg_perm.__key);
  49. printuid(", cuid=", msqid_ds.msg_perm.cuid);
  50. printuid(", cgid=", msqid_ds.msg_perm.cgid);
  51. tprints("}");
  52. tprintf(", msg_stime=%u", (unsigned) msqid_ds.msg_stime);
  53. tprintf(", msg_rtime=%u", (unsigned) msqid_ds.msg_rtime);
  54. tprintf(", msg_ctime=%u", (unsigned) msqid_ds.msg_ctime);
  55. tprintf(", msg_qnum=%u", (unsigned) msqid_ds.msg_qnum);
  56. tprintf(", msg_qbytes=%u", (unsigned) msqid_ds.msg_qbytes);
  57. tprintf(", msg_lspid=%u", (unsigned) msqid_ds.msg_lspid);
  58. tprintf(", msg_lrpid=%u", (unsigned) msqid_ds.msg_lrpid);
  59. tprints("}");
  60. break;
  61. default:
  62. printaddr(addr);
  63. break;
  64. }
  65. }
  66. SYS_FUNC(msgctl)
  67. {
  68. if (entering(tcp)) {
  69. tprintf("%d, ", (int) tcp->u_arg[0]);
  70. PRINTCTL(msgctl_flags, tcp->u_arg[1], "MSG_???");
  71. tprints(", ");
  72. } else {
  73. const kernel_ulong_t addr = tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2];
  74. print_msqid_ds(tcp, addr, tcp->u_arg[1]);
  75. }
  76. return 0;
  77. }