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

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