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>
40 #ifdef HAVE_LINUX_PERF_EVENT_H
41 # include <linux/perf_event.h>
44 #if HAVE_LONG_LONG_OFF_T
46 * Hacks for systems that have a long long off_t
48 # define flock64 flock /* Horrid hack */
49 # define printflock printflock64 /* Horrider hack */
52 static const struct xlat fcntlcmds[] = {
53 { F_DUPFD, "F_DUPFD" },
54 { F_GETFD, "F_GETFD" },
55 { F_SETFD, "F_SETFD" },
56 { F_GETFL, "F_GETFL" },
57 { F_SETFL, "F_SETFL" },
58 { F_GETLK, "F_GETLK" },
59 { F_SETLK, "F_SETLK" },
60 { F_SETLKW, "F_SETLKW" },
61 { F_GETOWN, "F_GETOWN" },
62 { F_SETOWN, "F_SETOWN" },
64 { F_RSETLK, "F_RSETLK" },
67 { F_RSETLKW, "F_RSETLKW" },
70 { F_RGETLK, "F_RGETLK" },
76 { F_SETSIG, "F_SETSIG" },
79 { F_GETSIG, "F_GETSIG" },
82 { F_CHKFL, "F_CHKFL" },
85 { F_DUP2FD, "F_DUP2FD" },
88 { F_ALLOCSP, "F_ALLOCSP" },
91 { F_ISSTREAM, "F_ISSTREAM" },
97 { F_NPRIV, "F_NPRIV" },
100 { F_QUOTACL, "F_QUOTACL" },
103 { F_BLOCKS, "F_BLOCKS" },
106 { F_BLKSIZE, "F_BLKSIZE" },
109 { F_GETOWN, "F_GETOWN" },
112 { F_SETOWN, "F_SETOWN" },
115 { F_REVOKE, "F_REVOKE" },
118 { F_SETLK, "F_SETLK" },
121 { F_SETLKW, "F_SETLKW" },
124 { F_FREESP, "F_FREESP" },
127 { F_GETLK, "F_GETLK" },
130 { F_SETLK64, "F_SETLK64" },
133 { F_SETLKW64, "F_SETLKW64" },
136 { F_FREESP64, "F_FREESP64" },
139 { F_GETLK64, "F_GETLK64" },
142 { F_SHARE, "F_SHARE" },
145 { F_UNSHARE, "F_UNSHARE" },
148 { F_SETLEASE, "F_SETLEASE" },
151 { F_GETLEASE, "F_GETLEASE" },
154 { F_NOTIFY, "F_NOTIFY" },
156 #ifdef F_DUPFD_CLOEXEC
157 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
162 static const struct xlat fdflags[] = {
164 { FD_CLOEXEC, "FD_CLOEXEC" },
171 static const struct xlat flockcmds[] = {
172 { LOCK_SH, "LOCK_SH" },
173 { LOCK_EX, "LOCK_EX" },
174 { LOCK_NB, "LOCK_NB" },
175 { LOCK_UN, "LOCK_UN" },
181 static const struct xlat lockfcmds[] = {
182 { F_RDLCK, "F_RDLCK" },
183 { F_WRLCK, "F_WRLCK" },
184 { F_UNLCK, "F_UNLCK" },
186 { F_EXLCK, "F_EXLCK" },
189 { F_SHLCK, "F_SHLCK" },
195 static const struct xlat notifyflags[] = {
197 { DN_ACCESS, "DN_ACCESS" },
200 { DN_MODIFY, "DN_MODIFY" },
203 { DN_CREATE, "DN_CREATE" },
206 { DN_DELETE, "DN_DELETE" },
209 { DN_RENAME, "DN_RENAME" },
212 { DN_ATTRIB, "DN_ATTRIB" },
215 { DN_MULTISHOT, "DN_MULTISHOT" },
221 static const struct xlat whence[] = {
222 { SEEK_SET, "SEEK_SET" },
223 { SEEK_CUR, "SEEK_CUR" },
224 { SEEK_END, "SEEK_END" },
228 static const struct xlat perf_event_open_flags[] = {
229 #ifdef PERF_FLAG_FD_NO_GROUP
230 { PERF_FLAG_FD_NO_GROUP, "PERF_FLAG_FD_NO_GROUP" },
232 #ifdef PERF_FLAG_FD_OUTPUT
233 { PERF_FLAG_FD_OUTPUT, "PERF_FLAG_FD_OUTPUT" },
235 #ifdef PERF_FLAG_PID_CGROUP
236 { PERF_FLAG_PID_CGROUP, "PERF_FLAG_PID_CGROUP" },
241 #ifndef HAVE_LONG_LONG_OFF_T
244 printflock(struct tcb *tcp, long addr, int getlk)
248 #if SUPPORTED_PERSONALITIES > 1
249 if (current_wordsize != sizeof(fl.l_start)) {
250 if (current_wordsize == 4) {
251 /* 32-bit x86 app on x86_64 and similar cases */
255 int32_t l_start; /* off_t */
256 int32_t l_len; /* off_t */
257 int32_t l_pid; /* pid_t */
259 if (umove(tcp, addr, &fl32) < 0) {
263 fl.l_type = fl32.l_type;
264 fl.l_whence = fl32.l_whence;
265 fl.l_start = fl32.l_start;
266 fl.l_len = fl32.l_len;
267 fl.l_pid = fl32.l_pid;
269 /* let people know we have a problem here */
270 tprintf("{ <decode error: unsupported wordsize %d> }",
277 if (umove(tcp, addr, &fl) < 0) {
283 printxval(lockfcmds, fl.l_type, "F_???");
284 tprints(", whence=");
285 printxval(whence, fl.l_whence, "SEEK_???");
286 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
288 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
294 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
297 printflock64(struct tcb *tcp, long addr, int getlk)
301 if (umove(tcp, addr, &fl) < 0) {
306 printxval(lockfcmds, fl.l_type, "F_???");
307 tprints(", whence=");
308 printxval(whence, fl.l_whence, "SEEK_???");
309 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
311 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
318 sys_fcntl(struct tcb *tcp)
321 printfd(tcp, tcp->u_arg[0]);
323 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
324 switch (tcp->u_arg[1]) {
327 printflags(fdflags, tcp->u_arg[2], "FD_???");
329 case F_SETOWN: case F_DUPFD:
330 #ifdef F_DUPFD_CLOEXEC
331 case F_DUPFD_CLOEXEC:
333 tprintf(", %ld", tcp->u_arg[2]);
337 tprint_open_modes(tcp->u_arg[2]);
339 case F_SETLK: case F_SETLKW:
344 printflock(tcp, tcp->u_arg[2], 0);
350 /* Linux glibc defines SETLK64 as SETLK,
351 even though the kernel has different values - as does Solaris. */
352 #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
355 #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
359 printflock64(tcp, tcp->u_arg[2], 0);
365 printflags(notifyflags, tcp->u_arg[2], "DN_???");
371 printxval(lockfcmds, tcp->u_arg[2], "F_???");
377 switch (tcp->u_arg[1]) {
379 #ifdef F_DUPFD_CLOEXEC
380 case F_DUPFD_CLOEXEC:
382 case F_SETFD: case F_SETFL:
383 case F_SETLK: case F_SETLKW:
384 case F_SETOWN: case F_GETOWN:
393 if (syserror(tcp) || tcp->u_rval == 0)
395 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
396 return RVAL_HEX|RVAL_STR;
400 tcp->auxstr = sprint_open_modes(tcp->u_rval);
401 return RVAL_HEX|RVAL_STR;
404 printflock(tcp, tcp->u_arg[2], 1);
407 #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
411 printflock64(tcp, tcp->u_arg[2], 1);
418 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
419 return RVAL_HEX|RVAL_STR;
422 tprintf(", %#lx", tcp->u_arg[2]);
432 sys_flock(struct tcb *tcp)
435 printfd(tcp, tcp->u_arg[0]);
437 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
444 sys_close(struct tcb *tcp)
447 printfd(tcp, tcp->u_arg[0]);
453 do_dup2(struct tcb *tcp, int flags_arg)
456 printfd(tcp, tcp->u_arg[0]);
458 printfd(tcp, tcp->u_arg[1]);
459 if (flags_arg >= 0) {
461 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
468 sys_dup2(struct tcb *tcp)
470 return do_dup2(tcp, -1);
474 sys_dup3(struct tcb *tcp)
476 return do_dup2(tcp, 2);
481 sys_getdtablesize(struct tcb *tcp)
488 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
491 unsigned nfds, fdsize;
497 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
498 if (args[0] > 1024*1024)
502 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
505 fds = malloc(fdsize);
510 for (i = 0; i < 3; i++) {
517 tprintf(", %#lx", arg);
520 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
525 for (j = 0, sep = ""; j < nfds; j++) {
526 if (FD_ISSET(j, fds)) {
536 printtv_bitness(tcp, args[4], bitness, 0);
539 static char outstr[1024];
541 #define end_outstr (outstr + sizeof(outstr))
549 tcp->auxstr = "Timeout";
553 fds = malloc(fdsize);
559 for (i = 0; i < 3; i++) {
563 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
565 for (j = 0; j < args[0]; j++) {
566 if (FD_ISSET(j, fds)) {
567 /* +2 chars needed at the end: ']',NUL */
568 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
570 outptr += sprintf(outptr, "%s%s [%u",
572 i == 0 ? "in" : i == 1 ? "out" : "except",
579 outptr += sprintf(outptr, " %u", j);
585 if (outptr != outstr)
591 /* This contains no useful information on SunOS. */
593 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
594 outptr += sprintf(outptr, "%sleft ", sep);
595 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
599 tcp->auxstr = outstr;
607 sys_oldselect(struct tcb *tcp)
611 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
615 return decode_select(tcp, args, BITNESS_CURRENT);
620 sys_osf_select(struct tcb *tcp)
622 long *args = tcp->u_arg;
623 return decode_select(tcp, args, BITNESS_32);
627 static const struct xlat epollctls[] = {
629 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
632 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
635 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
640 static const struct xlat epollevents[] = {
642 { EPOLLIN, "EPOLLIN" },
645 { EPOLLPRI, "EPOLLPRI" },
648 { EPOLLOUT, "EPOLLOUT" },
651 { EPOLLRDNORM, "EPOLLRDNORM" },
654 { EPOLLRDBAND, "EPOLLRDBAND" },
657 { EPOLLWRNORM, "EPOLLWRNORM" },
660 { EPOLLWRBAND, "EPOLLWRBAND" },
663 { EPOLLMSG, "EPOLLMSG" },
666 { EPOLLERR, "EPOLLERR" },
669 { EPOLLHUP, "EPOLLHUP" },
672 { EPOLLRDHUP, "EPOLLRDHUP" },
675 { EPOLLONESHOT, "EPOLLONESHOT" },
678 { EPOLLET, "EPOLLET" },
683 /* Not aliased to printargs_ld: we want it to have a distinct address */
685 sys_epoll_create(struct tcb *tcp)
687 return printargs_ld(tcp);
690 static const struct xlat epollflags[] = {
692 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
694 #ifdef EPOLL_NONBLOCK
695 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
701 sys_epoll_create1(struct tcb *tcp)
704 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
708 #ifdef HAVE_SYS_EPOLL_H
710 print_epoll_event(struct epoll_event *ev)
713 printflags(epollevents, ev->events, "EPOLL???");
714 /* We cannot know what format the program uses, so print u32 and u64
715 which will cover every value. */
716 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
717 ev->data.u32, ev->data.u64);
722 sys_epoll_ctl(struct tcb *tcp)
725 printfd(tcp, tcp->u_arg[0]);
727 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
729 printfd(tcp, tcp->u_arg[2]);
731 if (tcp->u_arg[3] == 0)
734 #ifdef HAVE_SYS_EPOLL_H
735 struct epoll_event ev;
736 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
737 print_epoll_event(&ev);
747 epoll_wait_common(struct tcb *tcp)
750 printfd(tcp, tcp->u_arg[0]);
754 tprintf("%lx", tcp->u_arg[1]);
755 else if (tcp->u_rval == 0)
758 #ifdef HAVE_SYS_EPOLL_H
759 struct epoll_event ev, *start, *cur, *end;
763 start = (struct epoll_event *) tcp->u_arg[1];
764 end = start + tcp->u_rval;
765 for (cur = start; cur < end; ++cur) {
768 if (umove(tcp, (long) cur, &ev) == 0)
769 print_epoll_event(&ev);
778 tprintf(" %#lx", (long) start);
783 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
788 sys_epoll_wait(struct tcb *tcp)
790 epoll_wait_common(tcp);
795 sys_epoll_pwait(struct tcb *tcp)
797 epoll_wait_common(tcp);
800 print_sigset(tcp, tcp->u_arg[4], 0);
806 sys_io_setup(struct tcb *tcp)
809 tprintf("%ld, ", tcp->u_arg[0]);
812 tprintf("0x%0lx", tcp->u_arg[1]);
814 unsigned long user_id;
815 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
816 tprintf("{%lu}", user_id);
825 sys_io_destroy(struct tcb *tcp)
828 tprintf("%lu", tcp->u_arg[0]);
835 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
839 iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
841 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
842 static const struct {
846 { "pread", SUB_COMMON },
847 { "pwrite", SUB_COMMON },
848 { "fsync", SUB_NONE },
849 { "fdsync", SUB_NONE },
851 { "poll", SUB_POLL },
852 { "noop", SUB_NONE },
853 { "preadv", SUB_VECTOR },
854 { "pwritev", SUB_VECTOR },
857 if (cmd < ARRAY_SIZE(cmds)) {
858 *sub = cmds[cmd].sub;
859 return cmds[cmd].name;
862 sprintf(buf, "%u /* SUB_??? */", cmd);
866 /* Not defined in libaio.h */
868 # define IOCB_RESFD (1 << 0)
872 print_common_flags(struct iocb *iocb)
874 if (iocb->u.c.flags & IOCB_RESFD)
875 tprintf("resfd=%d, ", iocb->u.c.resfd);
876 if (iocb->u.c.flags & ~IOCB_RESFD)
877 tprintf("flags=%x, ", iocb->u.c.flags);
880 #endif /* HAVE_LIBAIO_H */
883 sys_io_submit(struct tcb *tcp)
887 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
889 /* and if nr is negative? */
895 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
897 for (i = 0; i < nr; i++, iocbs++) {
905 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
906 umove(tcp, (unsigned long)iocbp, &iocb)) {
912 tprintf("data:%p, ", iocb.data);
914 tprintf("key:%u, ", iocb.key);
915 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
916 if (iocb.aio_reqprio)
917 tprintf("reqprio:%d, ", iocb.aio_reqprio);
918 tprintf("filedes:%d", iocb.aio_fildes);
921 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
923 printstr(tcp, (unsigned long)iocb.u.c.buf,
926 tprintf(", buf:%p", iocb.u.c.buf);
928 tprintf(", nbytes:%lu, offset:%llx",
931 print_common_flags(&iocb);
934 tprintf(", %llx, ", iocb.u.v.offset);
935 print_common_flags(&iocb);
936 tprint_iov(tcp, iocb.u.v.nr,
937 (unsigned long)iocb.u.v.vec,
938 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
941 tprintf(", %x", iocb.u.poll.events);
951 #warning "libaio-devel is not available => no io_submit decoding"
952 tprintf("%#lx", tcp->u_arg[2]);
960 sys_io_cancel(struct tcb *tcp)
966 tprintf("%lu, ", tcp->u_arg[0]);
968 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
969 tprintf("{%p, %u, %u, %u, %d}, ",
971 (unsigned)iocb.aio_lio_opcode,
972 (unsigned)iocb.aio_reqprio, iocb.aio_fildes);
981 struct io_event event;
982 if (umove(tcp, tcp->u_arg[2], &event) == 0)
983 tprintf("{%p, %p, %ld, %ld}",
984 event.data, event.obj,
985 event.res, event.res2);
995 sys_io_getevents(struct tcb *tcp)
998 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
1001 if (tcp->u_rval == 0) {
1004 #ifdef HAVE_LIBAIO_H
1005 struct io_event *events = (void *)tcp->u_arg[3];
1006 long i, nr = tcp->u_rval;
1008 for (i = 0; i < nr; i++, events++) {
1009 struct io_event event;
1016 if (umove(tcp, (unsigned long)events, &event) != 0) {
1020 tprintf("{%p, %p, %ld, %ld}", event.data,
1021 event.obj, event.res, event.res2);
1029 print_timespec(tcp, tcp->u_arg[4]);
1035 sys_select(struct tcb *tcp)
1037 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1041 sys_pselect6(struct tcb *tcp)
1043 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1044 if (entering(tcp)) {
1049 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1050 tprintf(", %#lx", tcp->u_arg[5]);
1053 if (data.len < sizeof(long))
1054 tprintf("%#lx", (long)data.ss);
1056 print_sigset(tcp, (long)data.ss, 0);
1057 tprintf(", %lu}", data.len);
1064 do_eventfd(struct tcb *tcp, int flags_arg)
1066 if (entering(tcp)) {
1067 tprintf("%lu", tcp->u_arg[0]);
1068 if (flags_arg >= 0) {
1070 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1077 sys_eventfd(struct tcb *tcp)
1079 return do_eventfd(tcp, -1);
1083 sys_eventfd2(struct tcb *tcp)
1085 return do_eventfd(tcp, 1);
1089 sys_perf_event_open(struct tcb *tcp)
1091 if (entering(tcp)) {
1092 tprintf("%#lx, %d, %d, %d, ",
1094 (int) tcp->u_arg[1],
1095 (int) tcp->u_arg[2],
1096 (int) tcp->u_arg[3]);
1097 printflags(perf_event_open_flags, tcp->u_arg[4],