summaryrefslogtreecommitdiff
path: root/src/epoll.c
diff options
context:
space:
mode:
authorDmitry V. Levin <ldv@strace.io>2021-02-03 08:00:00 +0000
committerDmitry V. Levin <ldv@strace.io>2021-02-03 08:00:00 +0000
commitecb3ed78107c851f71696df6730a15afff91ed3d (patch)
tree0b3d2b083040fc9b08d129f80d027ff41b995059 /src/epoll.c
parentc47943de06204a269e16f732e7c9c71d4284b23f (diff)
downloadstrace-ecb3ed78107c851f71696df6730a15afff91ed3d.tar.gz
Move source files into src subdirectory
* src/Makefile.am: New file. * src/.gitignore: Likewise. * scno.am: Move into src subdirectory. * scno.head: Likewise. * strace-graph: Likewise. * strace-log-merge: Likewise. * linux/: Likewise. * types/: Likewise. * xlat/: Likewise. * *.awk: Likewise. * *.c: Likewise. * *.h: Likewise. * *.sh: Likewise. * .gitignore: Update. * Makefile.am: Update. * bootstrap: Update. * configure.ac: Update. * debian/rules: Update. * debian/strace-udeb.install: Update. * debian/strace.examples: Update. * debian/strace.install: Update. * debian/strace64.install: Update. * m4/gen_bpf_attr_m4.sh: Update. * m4/mpers.m4: Update. * tests/Makefile.am: Update. * tests/init.sh: Update. * tests/legacy_syscall_info.test: Update. * tests/strace-log-merge-error.test: Update. * tests/strace-log-merge-suffix.test: Update.
Diffstat (limited to 'src/epoll.c')
-rw-r--r--src/epoll.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/src/epoll.c b/src/epoll.c
new file mode 100644
index 000000000..d87e0b8bc
--- /dev/null
+++ b/src/epoll.c
@@ -0,0 +1,111 @@
+/*
+ * Copyright (c) 2004-2007 Ulrich Drepper <drepper@redhat.com>
+ * Copyright (c) 2004 Roland McGrath <roland@redhat.com>
+ * Copyright (c) 2005-2015 Dmitry V. Levin <ldv@strace.io>
+ * Copyright (c) 2015-2018 The strace developers.
+ * All rights reserved.
+ *
+ * SPDX-License-Identifier: LGPL-2.1-or-later
+ */
+
+#include "defs.h"
+#include <fcntl.h>
+#include <sys/epoll.h>
+
+SYS_FUNC(epoll_create)
+{
+ tprintf("%d", (int) tcp->u_arg[0]);
+
+ return RVAL_DECODED | RVAL_FD;
+}
+
+#include "xlat/epollflags.h"
+
+SYS_FUNC(epoll_create1)
+{
+ printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
+
+ return RVAL_DECODED | RVAL_FD;
+}
+
+#include "xlat/epollevents.h"
+
+static void
+print_epoll_data(const epoll_data_t data)
+{
+ /*
+ * We cannot know what format the tracee uses, so
+ * print both u32 and u66 which will cover every value.
+ */
+ tprint_struct_begin();
+ PRINT_FIELD_U(data, u32);
+ tprint_struct_next();
+ PRINT_FIELD_U(data, u64);
+ tprint_struct_end();
+}
+
+static bool
+print_epoll_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
+{
+ const struct epoll_event *ev = elem_buf;
+
+ tprint_struct_begin();
+ PRINT_FIELD_FLAGS(*ev, events, epollevents, "EPOLL???");
+ tprint_struct_next();
+ PRINT_FIELD_OBJ_VAL(*ev, data, print_epoll_data);
+ tprint_struct_end();
+
+ return true;
+}
+
+#include "xlat/epollctls.h"
+
+SYS_FUNC(epoll_ctl)
+{
+ printfd(tcp, tcp->u_arg[0]);
+ tprints(", ");
+ const unsigned int op = tcp->u_arg[1];
+ printxval(epollctls, op, "EPOLL_CTL_???");
+ tprints(", ");
+ printfd(tcp, tcp->u_arg[2]);
+ tprints(", ");
+ struct epoll_event ev;
+ if (EPOLL_CTL_DEL == op)
+ printaddr(tcp->u_arg[3]);
+ else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
+ print_epoll_event(tcp, &ev, sizeof(ev), 0);
+
+ return RVAL_DECODED;
+}
+
+static void
+epoll_wait_common(struct tcb *tcp)
+{
+ if (entering(tcp)) {
+ printfd(tcp, tcp->u_arg[0]);
+ tprints(", ");
+ } else {
+ struct epoll_event ev;
+ print_array(tcp, tcp->u_arg[1], tcp->u_rval, &ev, sizeof(ev),
+ tfetch_mem, print_epoll_event, 0);
+ tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
+ }
+}
+
+SYS_FUNC(epoll_wait)
+{
+ epoll_wait_common(tcp);
+ return 0;
+}
+
+SYS_FUNC(epoll_pwait)
+{
+ epoll_wait_common(tcp);
+ if (exiting(tcp)) {
+ tprints(", ");
+ /* NB: kernel requires arg[5] == NSIG_BYTES */
+ print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
+ tprintf(", %" PRI_klu, tcp->u_arg[5]);
+ }
+ return 0;
+}