2 * Copyright (c) 1991, 1992 Paul Kranenburg <pk@cs.few.eur.nl>
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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifdef HAVE_SYS_EPOLL_H
35 # include <sys/epoll.h>
37 #ifdef HAVE_LINUX_PERF_EVENT_H
38 # include <linux/perf_event.h>
41 static const struct xlat fcntlcmds[] = {
42 { F_DUPFD, "F_DUPFD" },
43 { F_GETFD, "F_GETFD" },
44 { F_SETFD, "F_SETFD" },
45 { F_GETFL, "F_GETFL" },
46 { F_SETFL, "F_SETFL" },
47 { F_GETLK, "F_GETLK" },
48 { F_SETLK, "F_SETLK" },
49 { F_SETLKW, "F_SETLKW" },
50 { F_GETOWN, "F_GETOWN" },
51 { F_SETOWN, "F_SETOWN" },
53 { F_RSETLK, "F_RSETLK" },
56 { F_RSETLKW, "F_RSETLKW" },
59 { F_RGETLK, "F_RGETLK" },
65 { F_SETSIG, "F_SETSIG" },
68 { F_GETSIG, "F_GETSIG" },
71 { F_CHKFL, "F_CHKFL" },
74 { F_DUP2FD, "F_DUP2FD" },
77 { F_ALLOCSP, "F_ALLOCSP" },
80 { F_ISSTREAM, "F_ISSTREAM" },
86 { F_NPRIV, "F_NPRIV" },
89 { F_QUOTACL, "F_QUOTACL" },
92 { F_BLOCKS, "F_BLOCKS" },
95 { F_BLKSIZE, "F_BLKSIZE" },
98 { F_GETOWN, "F_GETOWN" },
101 { F_SETOWN, "F_SETOWN" },
104 { F_REVOKE, "F_REVOKE" },
107 { F_SETLK, "F_SETLK" },
110 { F_SETLKW, "F_SETLKW" },
113 { F_FREESP, "F_FREESP" },
116 { F_GETLK, "F_GETLK" },
119 { F_SETLK64, "F_SETLK64" },
122 { F_SETLKW64, "F_SETLKW64" },
125 { F_FREESP64, "F_FREESP64" },
128 { F_GETLK64, "F_GETLK64" },
131 { F_SHARE, "F_SHARE" },
134 { F_UNSHARE, "F_UNSHARE" },
137 { F_SETLEASE, "F_SETLEASE" },
140 { F_GETLEASE, "F_GETLEASE" },
143 { F_NOTIFY, "F_NOTIFY" },
145 #ifdef F_DUPFD_CLOEXEC
146 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
151 static const struct xlat fdflags[] = {
153 { FD_CLOEXEC, "FD_CLOEXEC" },
160 static const struct xlat flockcmds[] = {
161 { LOCK_SH, "LOCK_SH" },
162 { LOCK_EX, "LOCK_EX" },
163 { LOCK_NB, "LOCK_NB" },
164 { LOCK_UN, "LOCK_UN" },
170 static const struct xlat lockfcmds[] = {
171 { F_RDLCK, "F_RDLCK" },
172 { F_WRLCK, "F_WRLCK" },
173 { F_UNLCK, "F_UNLCK" },
175 { F_EXLCK, "F_EXLCK" },
178 { F_SHLCK, "F_SHLCK" },
184 static const struct xlat notifyflags[] = {
186 { DN_ACCESS, "DN_ACCESS" },
189 { DN_MODIFY, "DN_MODIFY" },
192 { DN_CREATE, "DN_CREATE" },
195 { DN_DELETE, "DN_DELETE" },
198 { DN_RENAME, "DN_RENAME" },
201 { DN_ATTRIB, "DN_ATTRIB" },
204 { DN_MULTISHOT, "DN_MULTISHOT" },
210 static const struct xlat perf_event_open_flags[] = {
211 #ifdef PERF_FLAG_FD_NO_GROUP
212 { PERF_FLAG_FD_NO_GROUP, "PERF_FLAG_FD_NO_GROUP" },
214 #ifdef PERF_FLAG_FD_OUTPUT
215 { PERF_FLAG_FD_OUTPUT, "PERF_FLAG_FD_OUTPUT" },
217 #ifdef PERF_FLAG_PID_CGROUP
218 { PERF_FLAG_PID_CGROUP, "PERF_FLAG_PID_CGROUP" },
226 printflock64(struct tcb *tcp, long addr, int getlk)
230 if (umove(tcp, addr, &fl) < 0) {
235 printxval(lockfcmds, fl.l_type, "F_???");
236 tprints(", whence=");
237 printxval(whence_codes, fl.l_whence, "SEEK_???");
238 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
240 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
248 printflock(struct tcb *tcp, long addr, int getlk)
252 #if SUPPORTED_PERSONALITIES > 1
254 if (current_personality == 0) {
255 printflock64(tcp, addr, getlk);
259 if (current_wordsize != sizeof(fl.l_start)) {
260 if (current_wordsize == 4) {
261 /* 32-bit x86 app on x86_64 and similar cases */
265 int32_t l_start; /* off_t */
266 int32_t l_len; /* off_t */
267 int32_t l_pid; /* pid_t */
269 if (umove(tcp, addr, &fl32) < 0) {
273 fl.l_type = fl32.l_type;
274 fl.l_whence = fl32.l_whence;
275 fl.l_start = fl32.l_start;
276 fl.l_len = fl32.l_len;
277 fl.l_pid = fl32.l_pid;
279 /* let people know we have a problem here */
280 tprintf("<decode error: unsupported wordsize %d>",
287 if (umove(tcp, addr, &fl) < 0) {
293 printxval(lockfcmds, fl.l_type, "F_???");
294 tprints(", whence=");
295 printxval(whence_codes, fl.l_whence, "SEEK_???");
297 tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len);
299 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
302 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
308 sys_fcntl(struct tcb *tcp)
311 printfd(tcp, tcp->u_arg[0]);
313 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
314 switch (tcp->u_arg[1]) {
317 printflags(fdflags, tcp->u_arg[2], "FD_???");
319 case F_SETOWN: case F_DUPFD:
320 #ifdef F_DUPFD_CLOEXEC
321 case F_DUPFD_CLOEXEC:
323 tprintf(", %ld", tcp->u_arg[2]);
327 tprint_open_modes(tcp->u_arg[2]);
329 case F_SETLK: case F_SETLKW:
334 printflock(tcp, tcp->u_arg[2], 0);
340 /* Linux glibc defines SETLK64 as SETLK,
341 even though the kernel has different values - as does Solaris. */
342 #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
345 #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
349 printflock64(tcp, tcp->u_arg[2], 0);
355 printflags(notifyflags, tcp->u_arg[2], "DN_???");
361 printxval(lockfcmds, tcp->u_arg[2], "F_???");
367 switch (tcp->u_arg[1]) {
369 #ifdef F_DUPFD_CLOEXEC
370 case F_DUPFD_CLOEXEC:
372 case F_SETFD: case F_SETFL:
373 case F_SETLK: case F_SETLKW:
374 case F_SETOWN: case F_GETOWN:
383 if (syserror(tcp) || tcp->u_rval == 0)
385 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
386 return RVAL_HEX|RVAL_STR;
390 tcp->auxstr = sprint_open_modes(tcp->u_rval);
391 return RVAL_HEX|RVAL_STR;
394 printflock(tcp, tcp->u_arg[2], 1);
397 #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
401 printflock64(tcp, tcp->u_arg[2], 1);
408 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
409 return RVAL_HEX|RVAL_STR;
412 tprintf(", %#lx", tcp->u_arg[2]);
422 sys_flock(struct tcb *tcp)
425 printfd(tcp, tcp->u_arg[0]);
427 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
434 sys_close(struct tcb *tcp)
437 printfd(tcp, tcp->u_arg[0]);
443 do_dup2(struct tcb *tcp, int flags_arg)
446 printfd(tcp, tcp->u_arg[0]);
448 printfd(tcp, tcp->u_arg[1]);
449 if (flags_arg >= 0) {
451 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
458 sys_dup2(struct tcb *tcp)
460 return do_dup2(tcp, -1);
464 sys_dup3(struct tcb *tcp)
466 return do_dup2(tcp, 2);
471 sys_getdtablesize(struct tcb *tcp)
478 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
486 /* Kernel truncates arg[0] to int, we do the same. */
487 nfds = (int) args[0];
489 /* Kernel rejects negative nfds, so we don't parse it either. */
494 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
495 if (nfds > 1024*1024)
499 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
500 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
502 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
505 tprintf("%d", (int) args[0]);
508 fds = malloc(fdsize);
512 for (i = 0; i < 3; i++) {
518 if (!verbose(tcp) || !fds) {
519 tprintf(", %#lx", arg);
522 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
527 for (j = 0, sep = "";; j++) {
528 j = next_set_bit(fds, j, nfds);
539 printtv_bitness(tcp, args[4], bitness, 0);
542 static char outstr[1024];
544 #define end_outstr (outstr + sizeof(outstr))
550 ready_fds = tcp->u_rval;
551 if (ready_fds == 0) {
552 tcp->auxstr = "Timeout";
556 fds = malloc(fdsize);
562 for (i = 0; i < 3 && ready_fds > 0; i++) {
566 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
569 j = next_set_bit(fds, j, nfds);
572 /* +2 chars needed at the end: ']',NUL */
573 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
575 outptr += sprintf(outptr, "%s%s [%u",
577 i == 0 ? "in" : i == 1 ? "out" : "except",
584 outptr += sprintf(outptr, " %u", j);
587 if (--ready_fds == 0)
590 if (outptr != outstr)
594 /* This contains no useful information on SunOS. */
596 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
597 outptr += sprintf(outptr, "%sleft ", sep);
598 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
602 tcp->auxstr = outstr;
610 sys_oldselect(struct tcb *tcp)
614 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
618 return decode_select(tcp, args, BITNESS_CURRENT);
623 sys_osf_select(struct tcb *tcp)
625 long *args = tcp->u_arg;
626 return decode_select(tcp, args, BITNESS_32);
630 static const struct xlat epollctls[] = {
632 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
635 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
638 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
643 static const struct xlat epollevents[] = {
645 { EPOLLIN, "EPOLLIN" },
648 { EPOLLPRI, "EPOLLPRI" },
651 { EPOLLOUT, "EPOLLOUT" },
654 { EPOLLRDNORM, "EPOLLRDNORM" },
657 { EPOLLRDBAND, "EPOLLRDBAND" },
660 { EPOLLWRNORM, "EPOLLWRNORM" },
663 { EPOLLWRBAND, "EPOLLWRBAND" },
666 { EPOLLMSG, "EPOLLMSG" },
669 { EPOLLERR, "EPOLLERR" },
672 { EPOLLHUP, "EPOLLHUP" },
675 { EPOLLRDHUP, "EPOLLRDHUP" },
678 { EPOLLONESHOT, "EPOLLONESHOT" },
681 { EPOLLET, "EPOLLET" },
686 /* Not aliased to printargs_ld: we want it to have a distinct address */
688 sys_epoll_create(struct tcb *tcp)
690 return printargs_ld(tcp);
693 static const struct xlat epollflags[] = {
695 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
697 #ifdef EPOLL_NONBLOCK
698 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
704 sys_epoll_create1(struct tcb *tcp)
707 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
711 #ifdef HAVE_SYS_EPOLL_H
713 print_epoll_event(struct epoll_event *ev)
716 printflags(epollevents, ev->events, "EPOLL???");
717 /* We cannot know what format the program uses, so print u32 and u64
718 which will cover every value. */
719 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
720 ev->data.u32, ev->data.u64);
725 sys_epoll_ctl(struct tcb *tcp)
728 printfd(tcp, tcp->u_arg[0]);
730 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
732 printfd(tcp, tcp->u_arg[2]);
734 if (tcp->u_arg[3] == 0)
737 #ifdef HAVE_SYS_EPOLL_H
738 struct epoll_event ev;
739 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
740 print_epoll_event(&ev);
750 epoll_wait_common(struct tcb *tcp)
753 printfd(tcp, tcp->u_arg[0]);
757 tprintf("%lx", tcp->u_arg[1]);
758 else if (tcp->u_rval == 0)
761 #ifdef HAVE_SYS_EPOLL_H
762 struct epoll_event ev, *start, *cur, *end;
766 start = (struct epoll_event *) tcp->u_arg[1];
767 end = start + tcp->u_rval;
768 for (cur = start; cur < end; ++cur) {
771 if (umove(tcp, (long) cur, &ev) == 0)
772 print_epoll_event(&ev);
781 tprintf(" %#lx", (long) start);
786 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
791 sys_epoll_wait(struct tcb *tcp)
793 epoll_wait_common(tcp);
798 sys_epoll_pwait(struct tcb *tcp)
800 epoll_wait_common(tcp);
803 /* NB: kernel requires arg[5] == NSIG / 8 */
804 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
805 tprintf(", %lu", tcp->u_arg[5]);
811 sys_select(struct tcb *tcp)
813 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
817 sys_pselect6(struct tcb *tcp)
819 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
826 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
827 if (current_wordsize == 4) {
832 r = umove(tcp, tcp->u_arg[5], &data32);
833 data.ptr = data32.ptr;
834 data.len = data32.len;
837 r = umove(tcp, tcp->u_arg[5], &data);
839 tprintf(", %#lx", tcp->u_arg[5]);
842 /* NB: kernel requires data.len == NSIG / 8 */
843 print_sigset_addr_len(tcp, data.ptr, data.len);
844 tprintf(", %lu}", data.len);
851 do_eventfd(struct tcb *tcp, int flags_arg)
854 tprintf("%lu", tcp->u_arg[0]);
855 if (flags_arg >= 0) {
857 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
864 sys_eventfd(struct tcb *tcp)
866 return do_eventfd(tcp, -1);
870 sys_eventfd2(struct tcb *tcp)
872 return do_eventfd(tcp, 1);
876 sys_perf_event_open(struct tcb *tcp)
879 tprintf("%#lx, %d, %d, %d, ",
883 (int) tcp->u_arg[3]);
884 printflags(perf_event_open_flags, tcp->u_arg[4],