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.
38 #ifdef HAVE_SYS_EPOLL_H
39 #include <sys/epoll.h>
45 #if HAVE_LONG_LONG_OFF_T
47 * Hacks for systems that have a long long off_t
49 #define flock64 flock /* Horrid hack */
50 #define printflock printflock64 /* Horrider hack */
54 static const struct xlat fcntlcmds[] = {
55 { F_DUPFD, "F_DUPFD" },
56 { F_GETFD, "F_GETFD" },
57 { F_SETFD, "F_SETFD" },
58 { F_GETFL, "F_GETFL" },
59 { F_SETFL, "F_SETFL" },
60 { F_GETLK, "F_GETLK" },
61 { F_SETLK, "F_SETLK" },
62 { F_SETLKW, "F_SETLKW" },
63 { F_GETOWN, "F_GETOWN" },
64 { F_SETOWN, "F_SETOWN" },
66 { F_RSETLK, "F_RSETLK" },
69 { F_RSETLKW, "F_RSETLKW" },
72 { F_RGETLK, "F_RGETLK" },
78 { F_SETSIG, "F_SETSIG" },
81 { F_GETSIG, "F_GETSIG" },
84 { F_CHKFL, "F_CHKFL" },
87 { F_DUP2FD, "F_DUP2FD" },
90 { F_ALLOCSP, "F_ALLOCSP" },
93 { F_ISSTREAM, "F_ISSTREAM" },
99 { F_NPRIV, "F_NPRIV" },
102 { F_QUOTACL, "F_QUOTACL" },
105 { F_BLOCKS, "F_BLOCKS" },
108 { F_BLKSIZE, "F_BLKSIZE" },
111 { F_GETOWN, "F_GETOWN" },
114 { F_SETOWN, "F_SETOWN" },
117 { F_REVOKE, "F_REVOKE" },
120 { F_SETLK, "F_SETLK" },
123 { F_SETLKW, "F_SETLKW" },
126 { F_FREESP, "F_FREESP" },
129 { F_GETLK, "F_GETLK" },
132 { F_SETLK64, "F_SETLK64" },
135 { F_SETLKW64, "F_SETLKW64" },
138 { F_FREESP64, "F_FREESP64" },
141 { F_GETLK64, "F_GETLK64" },
144 { F_SHARE, "F_SHARE" },
147 { F_UNSHARE, "F_UNSHARE" },
150 { F_SETLEASE, "F_SETLEASE" },
153 { F_GETLEASE, "F_GETLEASE" },
156 { F_NOTIFY, "F_NOTIFY" },
158 #ifdef F_DUPFD_CLOEXEC
159 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
164 static const struct xlat fdflags[] = {
166 { FD_CLOEXEC, "FD_CLOEXEC" },
173 static const struct xlat flockcmds[] = {
174 { LOCK_SH, "LOCK_SH" },
175 { LOCK_EX, "LOCK_EX" },
176 { LOCK_NB, "LOCK_NB" },
177 { LOCK_UN, "LOCK_UN" },
183 static const struct xlat lockfcmds[] = {
184 { F_RDLCK, "F_RDLCK" },
185 { F_WRLCK, "F_WRLCK" },
186 { F_UNLCK, "F_UNLCK" },
188 { F_EXLCK, "F_EXLCK" },
191 { F_SHLCK, "F_SHLCK" },
197 static const struct xlat notifyflags[] = {
199 { DN_ACCESS, "DN_ACCESS" },
202 { DN_MODIFY, "DN_MODIFY" },
205 { DN_CREATE, "DN_CREATE" },
208 { DN_DELETE, "DN_DELETE" },
211 { DN_RENAME, "DN_RENAME" },
214 { DN_ATTRIB, "DN_ATTRIB" },
217 { DN_MULTISHOT, "DN_MULTISHOT" },
223 static const struct xlat whence[] = {
224 { SEEK_SET, "SEEK_SET" },
225 { SEEK_CUR, "SEEK_CUR" },
226 { SEEK_END, "SEEK_END" },
230 #ifndef HAVE_LONG_LONG_OFF_T
233 printflock(struct tcb *tcp, long addr, int getlk)
237 #if SUPPORTED_PERSONALITIES > 1
238 if (personality_wordsize[current_personality] != sizeof(fl.l_start)) {
239 if (personality_wordsize[current_personality] == 4) {
240 /* 32-bit x86 app on x86_64 and similar cases */
244 int32_t l_start; /* off_t */
245 int32_t l_len; /* off_t */
246 int32_t l_pid; /* pid_t */
248 if (umove(tcp, addr, &fl32) < 0) {
252 fl.l_type = fl32.l_type;
253 fl.l_whence = fl32.l_whence;
254 fl.l_start = fl32.l_start;
255 fl.l_len = fl32.l_len;
256 fl.l_pid = fl32.l_pid;
258 /* let people know we have a problem here */
259 tprintf("{ <decode error: unsupported wordsize %d> }",
260 personality_wordsize[current_personality]);
266 if (umove(tcp, addr, &fl) < 0) {
272 printxval(lockfcmds, fl.l_type, "F_???");
273 tprints(", whence=");
274 printxval(whence, fl.l_whence, "SEEK_???");
275 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
277 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
283 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
286 printflock64(struct tcb *tcp, long addr, int getlk)
290 if (umove(tcp, addr, &fl) < 0) {
295 printxval(lockfcmds, fl.l_type, "F_???");
296 tprints(", whence=");
297 printxval(whence, fl.l_whence, "SEEK_???");
298 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
300 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
307 sys_fcntl(struct tcb *tcp)
310 printfd(tcp, tcp->u_arg[0]);
312 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
313 switch (tcp->u_arg[1]) {
316 printflags(fdflags, tcp->u_arg[2], "FD_???");
318 case F_SETOWN: case F_DUPFD:
319 #ifdef F_DUPFD_CLOEXEC
320 case F_DUPFD_CLOEXEC:
322 tprintf(", %ld", tcp->u_arg[2]);
326 tprint_open_modes(tcp->u_arg[2]);
328 case F_SETLK: case F_SETLKW:
333 printflock(tcp, tcp->u_arg[2], 0);
339 /* Linux glibc defines SETLK64 as SETLK,
340 even though the kernel has different values - as does Solaris. */
341 #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
344 #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
348 printflock64(tcp, tcp->u_arg[2], 0);
354 printflags(notifyflags, tcp->u_arg[2], "DN_???");
360 printxval(lockfcmds, tcp->u_arg[2], "F_???");
366 switch (tcp->u_arg[1]) {
368 #ifdef F_DUPFD_CLOEXEC
369 case F_DUPFD_CLOEXEC:
371 case F_SETFD: case F_SETFL:
372 case F_SETLK: case F_SETLKW:
373 case F_SETOWN: case F_GETOWN:
382 if (syserror(tcp) || tcp->u_rval == 0)
384 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
385 return RVAL_HEX|RVAL_STR;
389 tcp->auxstr = sprint_open_modes(tcp->u_rval);
390 return RVAL_HEX|RVAL_STR;
393 printflock(tcp, tcp->u_arg[2], 1);
396 #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
400 printflock64(tcp, tcp->u_arg[2], 1);
407 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
408 return RVAL_HEX|RVAL_STR;
411 tprintf(", %#lx", tcp->u_arg[2]);
421 sys_flock(struct tcb *tcp)
424 printfd(tcp, tcp->u_arg[0]);
426 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
433 sys_close(struct tcb *tcp)
436 printfd(tcp, tcp->u_arg[0]);
442 do_dup2(struct tcb *tcp, int flags_arg)
445 printfd(tcp, tcp->u_arg[0]);
447 printfd(tcp, tcp->u_arg[1]);
448 if (flags_arg >= 0) {
450 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
457 sys_dup2(struct tcb *tcp)
459 return do_dup2(tcp, -1);
463 sys_dup3(struct tcb *tcp)
465 return do_dup2(tcp, 2);
470 sys_getdtablesize(struct tcb *tcp)
477 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
480 unsigned nfds, fdsize;
486 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
487 if (args[0] > 1024*1024)
491 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
494 fds = malloc(fdsize);
499 for (i = 0; i < 3; i++) {
506 tprintf(", %#lx", arg);
509 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
514 for (j = 0, sep = ""; j < nfds; j++) {
515 if (FD_ISSET(j, fds)) {
525 printtv_bitness(tcp, args[4], bitness, 0);
528 static char outstr[1024];
530 #define end_outstr (outstr + sizeof(outstr))
538 tcp->auxstr = "Timeout";
542 fds = malloc(fdsize);
548 for (i = 0; i < 3; i++) {
552 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
554 for (j = 0; j < args[0]; j++) {
555 if (FD_ISSET(j, fds)) {
556 /* +2 chars needed at the end: ']',NUL */
557 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
559 outptr += sprintf(outptr, "%s%s [%u",
561 i == 0 ? "in" : i == 1 ? "out" : "except",
568 outptr += sprintf(outptr, " %u", j);
574 if (outptr != outstr)
580 /* This contains no useful information on SunOS. */
582 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
583 outptr += sprintf(outptr, "%sleft ", sep);
584 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
588 tcp->auxstr = outstr;
597 sys_oldselect(struct tcb *tcp)
601 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
605 return decode_select(tcp, args, BITNESS_CURRENT);
610 sys_osf_select(struct tcb *tcp)
612 long *args = tcp->u_arg;
613 return decode_select(tcp, args, BITNESS_32);
617 static const struct xlat epollctls[] = {
619 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
622 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
625 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
630 static const struct xlat epollevents[] = {
632 { EPOLLIN, "EPOLLIN" },
635 { EPOLLPRI, "EPOLLPRI" },
638 { EPOLLOUT, "EPOLLOUT" },
641 { EPOLLRDNORM, "EPOLLRDNORM" },
644 { EPOLLRDBAND, "EPOLLRDBAND" },
647 { EPOLLWRNORM, "EPOLLWRNORM" },
650 { EPOLLWRBAND, "EPOLLWRBAND" },
653 { EPOLLMSG, "EPOLLMSG" },
656 { EPOLLERR, "EPOLLERR" },
659 { EPOLLHUP, "EPOLLHUP" },
662 { EPOLLRDHUP, "EPOLLRDHUP" },
665 { EPOLLONESHOT, "EPOLLONESHOT" },
668 { EPOLLET, "EPOLLET" },
674 sys_epoll_create(struct tcb *tcp)
677 tprintf("%ld", tcp->u_arg[0]);
681 static const struct xlat epollflags[] = {
683 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
685 #ifdef EPOLL_NONBLOCK
686 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
692 sys_epoll_create1(struct tcb *tcp)
695 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
699 #ifdef HAVE_SYS_EPOLL_H
701 print_epoll_event(struct epoll_event *ev)
704 printflags(epollevents, ev->events, "EPOLL???");
705 /* We cannot know what format the program uses, so print u32 and u64
706 which will cover every value. */
707 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
708 ev->data.u32, ev->data.u64);
713 sys_epoll_ctl(struct tcb *tcp)
716 printfd(tcp, tcp->u_arg[0]);
718 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
720 printfd(tcp, tcp->u_arg[2]);
722 if (tcp->u_arg[3] == 0)
725 #ifdef HAVE_SYS_EPOLL_H
726 struct epoll_event ev;
727 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
728 print_epoll_event(&ev);
738 epoll_wait_common(struct tcb *tcp)
741 printfd(tcp, tcp->u_arg[0]);
745 tprintf("%lx", tcp->u_arg[1]);
746 else if (tcp->u_rval == 0)
749 #ifdef HAVE_SYS_EPOLL_H
750 struct epoll_event ev, *start, *cur, *end;
754 start = (struct epoll_event *) tcp->u_arg[1];
755 end = start + tcp->u_rval;
756 for (cur = start; cur < end; ++cur) {
759 if (umove(tcp, (long) cur, &ev) == 0)
760 print_epoll_event(&ev);
769 tprintf(" %#lx", (long) start);
774 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
779 sys_epoll_wait(struct tcb *tcp)
781 epoll_wait_common(tcp);
786 sys_epoll_pwait(struct tcb *tcp)
788 epoll_wait_common(tcp);
791 print_sigset(tcp, tcp->u_arg[4], 0);
797 sys_io_setup(struct tcb *tcp)
800 tprintf("%ld, ", tcp->u_arg[0]);
803 tprintf("0x%0lx", tcp->u_arg[1]);
805 unsigned long user_id;
806 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
807 tprintf("{%lu}", user_id);
816 sys_io_destroy(struct tcb *tcp)
819 tprintf("%lu", tcp->u_arg[0]);
826 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
830 iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
832 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
833 static const struct {
837 { "pread", SUB_COMMON },
838 { "pwrite", SUB_COMMON },
839 { "fsync", SUB_NONE },
840 { "fdsync", SUB_NONE },
842 { "poll", SUB_POLL },
843 { "noop", SUB_NONE },
844 { "preadv", SUB_VECTOR },
845 { "pwritev", SUB_VECTOR },
848 if (cmd < ARRAY_SIZE(cmds)) {
849 *sub = cmds[cmd].sub;
850 return cmds[cmd].name;
853 sprintf(buf, "%u /* SUB_??? */", cmd);
857 /* Not defined in libaio.h */
859 # define IOCB_RESFD (1 << 0)
863 print_common_flags(struct iocb *iocb)
865 if (iocb->u.c.flags & IOCB_RESFD)
866 tprintf("resfd=%d, ", iocb->u.c.resfd);
867 if (iocb->u.c.flags & ~IOCB_RESFD)
868 tprintf("flags=%x, ", iocb->u.c.flags);
871 #endif /* HAVE_LIBAIO_H */
874 sys_io_submit(struct tcb *tcp)
878 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
880 /* and if nr is negative? */
886 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
888 for (i = 0; i < nr; i++, iocbs++) {
896 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
897 umove(tcp, (unsigned long)iocbp, &iocb)) {
903 tprintf("data:%p, ", iocb.data);
905 tprintf("key:%u, ", iocb.key);
906 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
907 if (iocb.aio_reqprio)
908 tprintf("reqprio:%d, ", iocb.aio_reqprio);
909 tprintf("filedes:%d", iocb.aio_fildes);
912 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
914 printstr(tcp, (unsigned long)iocb.u.c.buf,
917 tprintf(", buf:%p", iocb.u.c.buf);
919 tprintf(", nbytes:%lu, offset:%llx",
922 print_common_flags(&iocb);
925 tprintf(", %llx, ", iocb.u.v.offset);
926 print_common_flags(&iocb);
927 tprint_iov(tcp, iocb.u.v.nr,
928 (unsigned long)iocb.u.v.vec,
929 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
932 tprintf(", %x", iocb.u.poll.events);
942 #warning "libaio-devel is not available => no io_submit decoding"
943 tprintf("%#lx", tcp->u_arg[2]);
951 sys_io_cancel(struct tcb *tcp)
957 tprintf("%lu, ", tcp->u_arg[0]);
959 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
960 tprintf("{%p, %u, %hu, %hu, %d}, ",
963 iocb.aio_reqprio, iocb.aio_fildes);
972 struct io_event event;
973 if (umove(tcp, tcp->u_arg[2], &event) == 0)
974 tprintf("{%p, %p, %ld, %ld}",
975 event.data, event.obj,
976 event.res, event.res2);
986 sys_io_getevents(struct tcb *tcp)
989 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
992 if (tcp->u_rval == 0) {
996 struct io_event *events = (void *)tcp->u_arg[3];
997 long i, nr = tcp->u_rval;
999 for (i = 0; i < nr; i++, events++) {
1000 struct io_event event;
1007 if (umove(tcp, (unsigned long)events, &event) != 0) {
1011 tprintf("{%p, %p, %ld, %ld}", event.data,
1012 event.obj, event.res, event.res2);
1020 print_timespec(tcp, tcp->u_arg[4]);
1026 sys_select(struct tcb *tcp)
1028 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1032 sys_pselect6(struct tcb *tcp)
1034 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1035 if (entering(tcp)) {
1040 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1041 tprintf(", %#lx", tcp->u_arg[5]);
1044 if (data.len < sizeof(long))
1045 tprintf("%#lx", (long)data.ss);
1047 print_sigset(tcp, (long)data.ss, 0);
1048 tprintf(", %lu}", data.len);
1055 do_eventfd(struct tcb *tcp, int flags_arg)
1057 if (entering(tcp)) {
1058 tprintf("%lu", tcp->u_arg[0]);
1059 if (flags_arg >= 0) {
1061 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1068 sys_eventfd(struct tcb *tcp)
1070 return do_eventfd(tcp, -1);
1074 sys_eventfd2(struct tcb *tcp)
1076 return do_eventfd(tcp, 1);