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.

mq.c 2.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. * Copyright (c) 2004 Ulrich Drepper <drepper@redhat.com>
  3. * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
  4. * Copyright (c) 2015-2019 The strace developers.
  5. * All rights reserved.
  6. *
  7. * SPDX-License-Identifier: LGPL-2.1-or-later
  8. */
  9. #include "defs.h"
  10. #include <fcntl.h>
  11. SYS_FUNC(mq_open)
  12. {
  13. printpath(tcp, tcp->u_arg[0]);
  14. tprints(", ");
  15. /* flags */
  16. tprint_open_modes(tcp->u_arg[1]);
  17. if (tcp->u_arg[1] & O_CREAT) {
  18. /* mode */
  19. tprints(", ");
  20. print_numeric_umode_t(tcp->u_arg[2]);
  21. tprints(", ");
  22. printmqattr(tcp, tcp->u_arg[3], false);
  23. }
  24. return RVAL_DECODED | RVAL_FD;
  25. }
  26. static int
  27. do_mq_timedsend(struct tcb *const tcp, const print_obj_by_addr_fn print_ts)
  28. {
  29. printfd(tcp, tcp->u_arg[0]);
  30. tprints(", ");
  31. printstrn(tcp, tcp->u_arg[1], tcp->u_arg[2]);
  32. tprintf(", %" PRI_klu ", %u, ", tcp->u_arg[2],
  33. (unsigned int) tcp->u_arg[3]);
  34. print_ts(tcp, tcp->u_arg[4]);
  35. return RVAL_DECODED;
  36. }
  37. #if HAVE_ARCH_TIME32_SYSCALLS
  38. SYS_FUNC(mq_timedsend_time32)
  39. {
  40. return do_mq_timedsend(tcp, print_timespec32);
  41. }
  42. #endif
  43. SYS_FUNC(mq_timedsend_time64)
  44. {
  45. return do_mq_timedsend(tcp, print_timespec64);
  46. }
  47. static int
  48. do_mq_timedreceive(struct tcb *const tcp, const print_obj_by_addr_fn print_ts)
  49. {
  50. if (entering(tcp)) {
  51. printfd(tcp, tcp->u_arg[0]);
  52. tprints(", ");
  53. } else {
  54. if (syserror(tcp))
  55. printaddr(tcp->u_arg[1]);
  56. else
  57. printstrn(tcp, tcp->u_arg[1], tcp->u_rval);
  58. tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
  59. printnum_int(tcp, tcp->u_arg[3], "%u");
  60. tprints(", ");
  61. /*
  62. * Since the timeout parameter is read by the kernel
  63. * on entering syscall, it has to be decoded the same way
  64. * whether the syscall has failed or not.
  65. */
  66. temporarily_clear_syserror(tcp);
  67. print_ts(tcp, tcp->u_arg[4]);
  68. restore_cleared_syserror(tcp);
  69. }
  70. return 0;
  71. }
  72. #if HAVE_ARCH_TIME32_SYSCALLS
  73. SYS_FUNC(mq_timedreceive_time32)
  74. {
  75. return do_mq_timedreceive(tcp, print_timespec32);
  76. }
  77. #endif
  78. SYS_FUNC(mq_timedreceive_time64)
  79. {
  80. return do_mq_timedreceive(tcp, print_timespec64);
  81. }
  82. SYS_FUNC(mq_notify)
  83. {
  84. printfd(tcp, tcp->u_arg[0]);
  85. tprints(", ");
  86. print_sigevent(tcp, tcp->u_arg[1]);
  87. return RVAL_DECODED;
  88. }
  89. SYS_FUNC(mq_getsetattr)
  90. {
  91. if (entering(tcp)) {
  92. printfd(tcp, tcp->u_arg[0]);
  93. tprints(", ");
  94. printmqattr(tcp, tcp->u_arg[1], true);
  95. tprints(", ");
  96. } else {
  97. printmqattr(tcp, tcp->u_arg[2], true);
  98. }
  99. return 0;
  100. }