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.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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-2020 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. #include SHM_H_PROVIDER
  17. typedef struct NAME_OF_STRUCT_SHMID_DS shmid_ds_t;
  18. #include MPERS_DEFS
  19. #include "xlat/shmctl_flags.h"
  20. static void
  21. print_shmid_ds(struct tcb *const tcp, const kernel_ulong_t addr, int cmd)
  22. {
  23. /* TODO: We don't properly decode old compat ipc calls. */
  24. if (cmd & IPC_64)
  25. cmd &= ~IPC_64;
  26. shmid_ds_t shmid_ds;
  27. switch (cmd) {
  28. case IPC_SET:
  29. case IPC_STAT:
  30. if (umove_or_printaddr(tcp, addr, &shmid_ds))
  31. return;
  32. tprints("{shm_perm={");
  33. printuid("uid=", shmid_ds.shm_perm.uid);
  34. printuid(", gid=", shmid_ds.shm_perm.gid);
  35. tprints(", mode=");
  36. print_numeric_umode_t(shmid_ds.shm_perm.mode);
  37. if (cmd != IPC_STAT) {
  38. tprints("}, ...}");
  39. break;
  40. }
  41. tprintf(", key=%u",
  42. (unsigned) shmid_ds.shm_perm.NAME_OF_STRUCT_IPC_PERM_KEY);
  43. printuid(", cuid=", shmid_ds.shm_perm.cuid);
  44. printuid(", cgid=", shmid_ds.shm_perm.cgid);
  45. tprints("}");
  46. tprintf(", shm_segsz=%u", (unsigned) shmid_ds.shm_segsz);
  47. tprintf(", shm_cpid=%u", (unsigned) shmid_ds.shm_cpid);
  48. tprintf(", shm_lpid=%u", (unsigned) shmid_ds.shm_lpid);
  49. tprintf(", shm_nattch=%u", (unsigned) shmid_ds.shm_nattch);
  50. tprintf(", shm_atime=%u", (unsigned) shmid_ds.shm_atime);
  51. tprintf(", shm_dtime=%u", (unsigned) shmid_ds.shm_dtime);
  52. tprintf(", shm_ctime=%u", (unsigned) shmid_ds.shm_ctime);
  53. tprints("}");
  54. break;
  55. default:
  56. printaddr(addr);
  57. break;
  58. }
  59. }
  60. SYS_FUNC(shmctl)
  61. {
  62. if (entering(tcp)) {
  63. tprintf("%d, ", (int) tcp->u_arg[0]);
  64. PRINTCTL(shmctl_flags, tcp->u_arg[1], "SHM_???");
  65. tprints(", ");
  66. } else {
  67. const kernel_ulong_t addr = tcp->u_arg[indirect_ipccall(tcp) ? 3 : 2];
  68. print_shmid_ds(tcp, addr, tcp->u_arg[1]);
  69. }
  70. return 0;
  71. }