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.

epoll.c 2.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * Copyright (c) 2004-2007 Ulrich Drepper <drepper@redhat.com>
  3. * Copyright (c) 2004 Roland McGrath <roland@redhat.com>
  4. * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@altlinux.org>
  5. * Copyright (c) 2015-2018 The strace developers.
  6. * All rights reserved.
  7. *
  8. * SPDX-License-Identifier: LGPL-2.1-or-later
  9. */
  10. #include "defs.h"
  11. #include <fcntl.h>
  12. #include <sys/epoll.h>
  13. SYS_FUNC(epoll_create)
  14. {
  15. tprintf("%d", (int) tcp->u_arg[0]);
  16. return RVAL_DECODED | RVAL_FD;
  17. }
  18. #include "xlat/epollflags.h"
  19. SYS_FUNC(epoll_create1)
  20. {
  21. printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
  22. return RVAL_DECODED | RVAL_FD;
  23. }
  24. #include "xlat/epollevents.h"
  25. static bool
  26. print_epoll_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
  27. {
  28. const struct epoll_event *ev = elem_buf;
  29. tprints("{");
  30. printflags(epollevents, ev->events, "EPOLL???");
  31. /* We cannot know what format the program uses, so print u32 and u64
  32. which will cover every value. */
  33. tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
  34. ev->data.u32, ev->data.u64);
  35. return true;
  36. }
  37. #include "xlat/epollctls.h"
  38. SYS_FUNC(epoll_ctl)
  39. {
  40. printfd(tcp, tcp->u_arg[0]);
  41. tprints(", ");
  42. const unsigned int op = tcp->u_arg[1];
  43. printxval(epollctls, op, "EPOLL_CTL_???");
  44. tprints(", ");
  45. printfd(tcp, tcp->u_arg[2]);
  46. tprints(", ");
  47. struct epoll_event ev;
  48. if (EPOLL_CTL_DEL == op)
  49. printaddr(tcp->u_arg[3]);
  50. else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
  51. print_epoll_event(tcp, &ev, sizeof(ev), 0);
  52. return RVAL_DECODED;
  53. }
  54. static void
  55. epoll_wait_common(struct tcb *tcp)
  56. {
  57. if (entering(tcp)) {
  58. printfd(tcp, tcp->u_arg[0]);
  59. tprints(", ");
  60. } else {
  61. struct epoll_event ev;
  62. print_array(tcp, tcp->u_arg[1], tcp->u_rval, &ev, sizeof(ev),
  63. tfetch_mem, print_epoll_event, 0);
  64. tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
  65. }
  66. }
  67. SYS_FUNC(epoll_wait)
  68. {
  69. epoll_wait_common(tcp);
  70. return 0;
  71. }
  72. SYS_FUNC(epoll_pwait)
  73. {
  74. epoll_wait_common(tcp);
  75. if (exiting(tcp)) {
  76. tprints(", ");
  77. /* NB: kernel requires arg[5] == NSIG_BYTES */
  78. print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
  79. tprintf(", %" PRI_klu, tcp->u_arg[5]);
  80. }
  81. return 0;
  82. }