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_shmctl.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(shmid_ds_t)
  15. #include "ipc_defs.h"
  16. #ifdef HAVE_SYS_SHM_H
  17. /* The C library generally exports the struct the current kernel expects. */
  18. # include <sys/shm.h>
  19. typedef struct shmid_ds shmid_ds_t;
  20. #elif defined HAVE_LINUX_SHM_H
  21. /* The linux header might provide the right struct. */
  22. # include <linux/shm.h>
  23. typedef struct shmid64_ds shmid_ds_t;
  24. #endif
  25. #include MPERS_DEFS
  26. #include "xlat/shmctl_flags.h"
  27. static void
  28. print_shmid_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. shmid_ds_t shmid_ds;
  34. switch (cmd) {
  35. case IPC_SET:
  36. case IPC_STAT:
  37. if (umove_or_printaddr(tcp, addr, &shmid_ds))
  38. return;
  39. tprints("{shm_perm={");
  40. printuid("uid=", shmid_ds.shm_perm.uid);
  41. printuid(", gid=", shmid_ds.shm_perm.gid);
  42. tprints(", mode=");
  43. print_numeric_umode_t(shmid_ds.shm_perm.mode);
  44. if (cmd != IPC_STAT) {
  45. tprints("}, ...}");
  46. break;
  47. }
  48. tprintf(", key=%u", (unsigned) shmid_ds.shm_perm.__key);
  49. printuid(", cuid=", shmid_ds.shm_perm.cuid);
  50. printuid(", cgid=", shmid_ds.shm_perm.cgid);
  51. tprints("}");
  52. tprintf(", shm_segsz=%u", (unsigned) shmid_ds.shm_segsz);
  53. tprintf(", shm_cpid=%u", (unsigned) shmid_ds.shm_cpid);
  54. tprintf(", shm_lpid=%u", (unsigned) shmid_ds.shm_lpid);
  55. tprintf(", shm_nattch=%u", (unsigned) shmid_ds.shm_nattch);
  56. tprintf(", shm_atime=%u", (unsigned) shmid_ds.shm_atime);
  57. tprintf(", shm_dtime=%u", (unsigned) shmid_ds.shm_dtime);
  58. tprintf(", shm_ctime=%u", (unsigned) shmid_ds.shm_ctime);
  59. tprints("}");
  60. break;
  61. default:
  62. printaddr(addr);
  63. break;
  64. }
  65. }
  66. SYS_FUNC(shmctl)
  67. {
  68. if (entering(tcp)) {
  69. tprintf("%d, ", (int) tcp->u_arg[0]);
  70. PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
  71. tprints(", ");
  72. } else {
  73. const kernel_ulong_t addr = tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2];
  74. print_shmid_ds(tcp, addr, tcp->u_arg[1]);
  75. }
  76. return 0;
  77. }