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_msg.c 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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 "ipc_defs.h"
  15. #include MSG_H_PROVIDER
  16. #include "xlat/ipc_msg_flags.h"
  17. #include "xlat/ipc_private.h"
  18. #include "xlat/resource_flags.h"
  19. SYS_FUNC(msgget)
  20. {
  21. printxval(ipc_private, (unsigned int) tcp->u_arg[0], NULL);
  22. tprints(", ");
  23. if (printflags(resource_flags, tcp->u_arg[1] & ~0777, NULL) != 0)
  24. tprints("|");
  25. print_numeric_umode_t(tcp->u_arg[1] & 0777);
  26. return RVAL_DECODED;
  27. }
  28. static void
  29. tprint_msgsnd(struct tcb *const tcp, const kernel_ulong_t addr,
  30. const kernel_ulong_t count, const unsigned int flags)
  31. {
  32. tprint_msgbuf(tcp, addr, count);
  33. printflags(ipc_msg_flags, flags, "MSG_???");
  34. }
  35. SYS_FUNC(msgsnd)
  36. {
  37. tprintf("%d, ", (int) tcp->u_arg[0]);
  38. if (indirect_ipccall(tcp)) {
  39. tprint_msgsnd(tcp, tcp->u_arg[3], tcp->u_arg[1],
  40. tcp->u_arg[2]);
  41. } else {
  42. tprint_msgsnd(tcp, tcp->u_arg[1], tcp->u_arg[2],
  43. tcp->u_arg[3]);
  44. }
  45. return RVAL_DECODED;
  46. }
  47. static void
  48. tprint_msgrcv(struct tcb *const tcp, const kernel_ulong_t addr,
  49. const kernel_ulong_t count, const kernel_ulong_t msgtyp)
  50. {
  51. tprint_msgbuf(tcp, addr, count);
  52. tprintf("%" PRI_kld ", ", msgtyp);
  53. }
  54. static int
  55. fetch_msgrcv_args(struct tcb *const tcp, const kernel_ulong_t addr,
  56. kernel_ulong_t *const pair)
  57. {
  58. if (current_wordsize == sizeof(*pair)) {
  59. if (umoven_or_printaddr(tcp, addr, 2 * sizeof(*pair), pair))
  60. return -1;
  61. } else {
  62. unsigned int tmp[2];
  63. if (umove_or_printaddr(tcp, addr, &tmp))
  64. return -1;
  65. pair[0] = tmp[0];
  66. pair[1] = (int) tmp[1];
  67. }
  68. return 0;
  69. }
  70. SYS_FUNC(msgrcv)
  71. {
  72. if (entering(tcp)) {
  73. tprintf("%d, ", (int) tcp->u_arg[0]);
  74. } else {
  75. if (indirect_ipccall(tcp)) {
  76. const bool direct =
  77. #ifdef SPARC64
  78. current_wordsize == 8 ||
  79. #endif
  80. get_tcb_priv_ulong(tcp) != 0;
  81. if (direct) {
  82. tprint_msgrcv(tcp, tcp->u_arg[3],
  83. tcp->u_arg[1], tcp->u_arg[4]);
  84. } else {
  85. kernel_ulong_t pair[2];
  86. if (fetch_msgrcv_args(tcp, tcp->u_arg[3], pair))
  87. tprintf(", %" PRI_klu ", ", tcp->u_arg[1]);
  88. else
  89. tprint_msgrcv(tcp, pair[0],
  90. tcp->u_arg[1], pair[1]);
  91. }
  92. printflags(ipc_msg_flags, tcp->u_arg[2], "MSG_???");
  93. } else {
  94. tprint_msgrcv(tcp, tcp->u_arg[1],
  95. tcp->u_arg[2], tcp->u_arg[3]);
  96. printflags(ipc_msg_flags, tcp->u_arg[4], "MSG_???");
  97. }
  98. }
  99. return 0;
  100. }