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_shm.c 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. #ifdef HAVE_SYS_SHM_H
  15. # include <sys/shm.h>
  16. #elif defined HAVE_LINUX_SHM_H
  17. # include <linux/shm.h>
  18. #endif
  19. #ifndef SHM_HUGE_SHIFT
  20. # define SHM_HUGE_SHIFT 26
  21. #endif
  22. #ifndef SHM_HUGE_MASK
  23. # define SHM_HUGE_MASK 0x3f
  24. #endif
  25. #include "xlat/shm_resource_flags.h"
  26. #include "xlat/shm_flags.h"
  27. SYS_FUNC(shmget)
  28. {
  29. printxval(ipc_private, (unsigned int) tcp->u_arg[0], NULL);
  30. tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
  31. unsigned int flags = tcp->u_arg[2] & ~0777;
  32. const unsigned int mask = SHM_HUGE_MASK << SHM_HUGE_SHIFT;
  33. const unsigned int hugetlb_value = flags & mask;
  34. flags &= ~mask;
  35. if (flags || !hugetlb_value)
  36. printflags(shm_resource_flags, flags, NULL);
  37. if (hugetlb_value) {
  38. tprintf("%s%u<<",
  39. flags ? "|" : "",
  40. hugetlb_value >> SHM_HUGE_SHIFT);
  41. print_xlat_u(SHM_HUGE_SHIFT);
  42. }
  43. if (flags || hugetlb_value)
  44. tprints("|");
  45. print_numeric_umode_t(tcp->u_arg[2] & 0777);
  46. return RVAL_DECODED;
  47. }
  48. SYS_FUNC(shmat)
  49. {
  50. if (entering(tcp)) {
  51. tprintf("%d, ", (int) tcp->u_arg[0]);
  52. if (indirect_ipccall(tcp)) {
  53. printaddr(tcp->u_arg[3]);
  54. tprints(", ");
  55. printflags(shm_flags, tcp->u_arg[1], "SHM_???");
  56. } else {
  57. printaddr(tcp->u_arg[1]);
  58. tprints(", ");
  59. printflags(shm_flags, tcp->u_arg[2], "SHM_???");
  60. }
  61. return 0;
  62. } else {
  63. if (syserror(tcp))
  64. return 0;
  65. if (indirect_ipccall(tcp)) {
  66. union {
  67. uint64_t r64;
  68. uint32_t r32;
  69. } u;
  70. if (umoven(tcp, tcp->u_arg[2], current_wordsize, &u) < 0)
  71. return RVAL_NONE;
  72. tcp->u_rval = (sizeof(u.r32) == current_wordsize)
  73. ? u.r32 : u.r64;
  74. }
  75. return RVAL_HEX;
  76. }
  77. }
  78. SYS_FUNC(shmdt)
  79. {
  80. printaddr(tcp->u_arg[indirect_ipccall(tcp) ? 3 : 0]);
  81. return RVAL_DECODED;
  82. }