/*
- * This file is part of poll strace test.
+ * Check decoding of poll syscall.
*
- * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
- * Copyright (c) 2016-2017 The strace developers.
+ * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@altlinux.org>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
# include <poll.h>
# include <stdio.h>
# include <stdlib.h>
+# include <string.h>
# include <unistd.h>
#define PRINT_EVENT(flag, member) \
int
main(int ac, char **av)
{
+# ifdef PATH_TRACING_FD
+ skip_if_unavailable("/proc/self/fd/");
+# endif
+
tprintf("%s", "");
assert(syscall(__NR_poll, NULL, 42, 0) == -1);
if (ENOSYS == errno)
perror_msg_and_skip("poll");
+
+# ifndef PATH_TRACING_FD
tprintf("poll(NULL, 42, 0) = -1 EFAULT (%m)\n");
+# endif
int fds[2];
if (pipe(fds) || pipe(fds))
int rc = syscall(__NR_poll, tail_fds0, 0, timeout);
assert(rc == 0);
+# ifndef PATH_TRACING_FD
tprintf("poll([], 0, %d) = %d (Timeout)\n", timeout, rc);
+# endif
rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
assert(rc == 3);
+# ifndef PATH_TRACING_FD
tprintf("poll(");
print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
ARRAY_SIZE(pfds0), abbrev);
(unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
tprintf(")\n");
+# endif /* !PATH_TRACING_FD */
tail_fds0[0].fd = -1;
tail_fds0[2].fd = -3;
rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
assert(rc == 2);
+# ifndef PATH_TRACING_FD
tprintf("poll(");
print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
ARRAY_SIZE(pfds0), abbrev);
(unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
tprintf(")\n");
+# endif /* !PATH_TRACING_FD */
tail_fds0[1].fd = -2;
tail_fds0[4].fd = -5;
rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
assert(rc == 1);
+# ifndef PATH_TRACING_FD
tprintf("poll(");
print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
ARRAY_SIZE(pfds0), abbrev);
(unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
tprintf(")\n");
+# endif /* !PATH_TRACING_FD */
struct pollfd pfds1[] = {
{ .fd = 1, .events = POLLIN | POLLPRI | POLLRDNORM | POLLRDBAND },
rc = syscall(__NR_poll, tail_fds1, ARRAY_SIZE(pfds1), timeout);
assert(rc == 0);
+# ifndef PATH_TRACING_FD
tprintf("poll(");
print_pollfd_array_entering(tail_fds1, ARRAY_SIZE(pfds1),
ARRAY_SIZE(pfds1), abbrev);
tprintf(", %u, %d) = %d (Timeout)\n",
(unsigned int) ARRAY_SIZE(pfds1), timeout, rc);
+# endif /* !PATH_TRACING_FD */
const void *const efault = tail_fds0 + ARRAY_SIZE(pfds0);
rc = syscall(__NR_poll, efault, 1, 0);
assert(rc == -1);
+
+# ifndef PATH_TRACING_FD
tprintf("poll(%p, 1, 0) = -1 EFAULT (%m)\n", efault);
+# endif
const unsigned int valid = 1;
const void *const epfds = tail_fds0 + ARRAY_SIZE(pfds0) - valid;
rc = syscall(__NR_poll, epfds, valid + 1, 0);
assert(rc == -1);
+
+# ifndef PATH_TRACING_FD
+ tprintf("poll(");
+ print_pollfd_array_entering(epfds, valid + 1, valid, abbrev);
+ errno = EFAULT;
+ tprintf(", %u, 0) = -1 EFAULT (%m)\n", valid + 1);
+# endif /* !PATH_TRACING_FD */
+
+# ifdef PATH_TRACING_FD
+ memcpy(tail_fds0, pfds0, sizeof(pfds0));
+ tail_fds0[4].fd = PATH_TRACING_FD;
+
+ rc = syscall(__NR_poll, tail_fds0, ARRAY_SIZE(pfds0), timeout);
+ assert(rc == 3);
+
+ tprintf("poll(");
+ print_pollfd_array_entering(tail_fds0, ARRAY_SIZE(pfds0),
+ ARRAY_SIZE(pfds0), abbrev);
+ tprintf(", %u, %d) = %d (",
+ (unsigned int) ARRAY_SIZE(pfds0), timeout, rc);
+ print_pollfd_array_exiting(tail_fds0, ARRAY_SIZE(pfds0), abbrev);
+ tprintf(")\n");
+
+ rc = syscall(__NR_poll, epfds, valid + 1, 0);
+ assert(rc == -1);
+
+ /* the 1st pollfd element is readable and contains PATH_TRACING_FD */
tprintf("poll(");
print_pollfd_array_entering(epfds, valid + 1, valid, abbrev);
errno = EFAULT;
tprintf(", %u, 0) = -1 EFAULT (%m)\n", valid + 1);
+# endif /* PATH_TRACING_FD */
tprintf("+++ exited with 0 +++\n");
return 0;