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 */
53 static const struct xlat fcntlcmds[] = {
54 { F_DUPFD, "F_DUPFD" },
55 { F_GETFD, "F_GETFD" },
56 { F_SETFD, "F_SETFD" },
57 { F_GETFL, "F_GETFL" },
58 { F_SETFL, "F_SETFL" },
59 { F_GETLK, "F_GETLK" },
60 { F_SETLK, "F_SETLK" },
61 { F_SETLKW, "F_SETLKW" },
62 { F_GETOWN, "F_GETOWN" },
63 { F_SETOWN, "F_SETOWN" },
65 { F_RSETLK, "F_RSETLK" },
68 { F_RSETLKW, "F_RSETLKW" },
71 { F_RGETLK, "F_RGETLK" },
77 { F_SETSIG, "F_SETSIG" },
80 { F_GETSIG, "F_GETSIG" },
83 { F_CHKFL, "F_CHKFL" },
86 { F_DUP2FD, "F_DUP2FD" },
89 { F_ALLOCSP, "F_ALLOCSP" },
92 { F_ISSTREAM, "F_ISSTREAM" },
98 { F_NPRIV, "F_NPRIV" },
101 { F_QUOTACL, "F_QUOTACL" },
104 { F_BLOCKS, "F_BLOCKS" },
107 { F_BLKSIZE, "F_BLKSIZE" },
110 { F_GETOWN, "F_GETOWN" },
113 { F_SETOWN, "F_SETOWN" },
116 { F_REVOKE, "F_REVOKE" },
119 { F_SETLK, "F_SETLK" },
122 { F_SETLKW, "F_SETLKW" },
125 { F_FREESP, "F_FREESP" },
128 { F_GETLK, "F_GETLK" },
131 { F_SETLK64, "F_SETLK64" },
134 { F_SETLKW64, "F_SETLKW64" },
137 { F_FREESP64, "F_FREESP64" },
140 { F_GETLK64, "F_GETLK64" },
143 { F_SHARE, "F_SHARE" },
146 { F_UNSHARE, "F_UNSHARE" },
149 { F_SETLEASE, "F_SETLEASE" },
152 { F_GETLEASE, "F_GETLEASE" },
155 { F_NOTIFY, "F_NOTIFY" },
157 #ifdef F_DUPFD_CLOEXEC
158 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
163 static const struct xlat fdflags[] = {
165 { FD_CLOEXEC, "FD_CLOEXEC" },
172 static const struct xlat flockcmds[] = {
173 { LOCK_SH, "LOCK_SH" },
174 { LOCK_EX, "LOCK_EX" },
175 { LOCK_NB, "LOCK_NB" },
176 { LOCK_UN, "LOCK_UN" },
182 static const struct xlat lockfcmds[] = {
183 { F_RDLCK, "F_RDLCK" },
184 { F_WRLCK, "F_WRLCK" },
185 { F_UNLCK, "F_UNLCK" },
187 { F_EXLCK, "F_EXLCK" },
190 { F_SHLCK, "F_SHLCK" },
196 static const struct xlat notifyflags[] = {
198 { DN_ACCESS, "DN_ACCESS" },
201 { DN_MODIFY, "DN_MODIFY" },
204 { DN_CREATE, "DN_CREATE" },
207 { DN_DELETE, "DN_DELETE" },
210 { DN_RENAME, "DN_RENAME" },
213 { DN_ATTRIB, "DN_ATTRIB" },
216 { DN_MULTISHOT, "DN_MULTISHOT" },
222 static const struct xlat whence[] = {
223 { SEEK_SET, "SEEK_SET" },
224 { SEEK_CUR, "SEEK_CUR" },
225 { SEEK_END, "SEEK_END" },
229 #ifndef HAVE_LONG_LONG_OFF_T
232 printflock(struct tcb *tcp, long addr, int getlk)
236 #if SUPPORTED_PERSONALITIES > 1
237 if (personality_wordsize[current_personality] != sizeof(fl.l_start)) {
238 if (personality_wordsize[current_personality] == 4) {
239 /* 32-bit x86 app on x86_64 and similar cases */
243 int32_t l_start; /* off_t */
244 int32_t l_len; /* off_t */
245 int32_t l_pid; /* pid_t */
247 if (umove(tcp, addr, &fl32) < 0) {
251 fl.l_type = fl32.l_type;
252 fl.l_whence = fl32.l_whence;
253 fl.l_start = fl32.l_start;
254 fl.l_len = fl32.l_len;
255 fl.l_pid = fl32.l_pid;
257 /* let people know we have a problem here */
258 tprintf("{ <decode error: unsupported wordsize %d> }",
259 personality_wordsize[current_personality]);
265 if (umove(tcp, addr, &fl) < 0) {
271 printxval(lockfcmds, fl.l_type, "F_???");
272 tprints(", whence=");
273 printxval(whence, fl.l_whence, "SEEK_???");
274 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
276 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
282 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
285 printflock64(struct tcb *tcp, long addr, int getlk)
289 if (umove(tcp, addr, &fl) < 0) {
294 printxval(lockfcmds, fl.l_type, "F_???");
295 tprints(", whence=");
296 printxval(whence, fl.l_whence, "SEEK_???");
297 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
299 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
306 sys_fcntl(struct tcb *tcp)
309 printfd(tcp, tcp->u_arg[0]);
311 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
312 switch (tcp->u_arg[1]) {
315 printflags(fdflags, tcp->u_arg[2], "FD_???");
317 case F_SETOWN: case F_DUPFD:
318 #ifdef F_DUPFD_CLOEXEC
319 case F_DUPFD_CLOEXEC:
321 tprintf(", %ld", tcp->u_arg[2]);
325 tprint_open_modes(tcp->u_arg[2]);
327 case F_SETLK: case F_SETLKW:
332 printflock(tcp, tcp->u_arg[2], 0);
338 /* Linux glibc defines SETLK64 as SETLK,
339 even though the kernel has different values - as does Solaris. */
340 #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
343 #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
347 printflock64(tcp, tcp->u_arg[2], 0);
353 printflags(notifyflags, tcp->u_arg[2], "DN_???");
359 printxval(lockfcmds, tcp->u_arg[2], "F_???");
365 switch (tcp->u_arg[1]) {
367 #ifdef F_DUPFD_CLOEXEC
368 case F_DUPFD_CLOEXEC:
370 case F_SETFD: case F_SETFL:
371 case F_SETLK: case F_SETLKW:
372 case F_SETOWN: case F_GETOWN:
381 if (syserror(tcp) || tcp->u_rval == 0)
383 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
384 return RVAL_HEX|RVAL_STR;
388 tcp->auxstr = sprint_open_modes(tcp->u_rval);
389 return RVAL_HEX|RVAL_STR;
392 printflock(tcp, tcp->u_arg[2], 1);
395 #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
399 printflock64(tcp, tcp->u_arg[2], 1);
406 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
407 return RVAL_HEX|RVAL_STR;
410 tprintf(", %#lx", tcp->u_arg[2]);
420 sys_flock(struct tcb *tcp)
423 printfd(tcp, tcp->u_arg[0]);
425 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
432 sys_close(struct tcb *tcp)
435 printfd(tcp, tcp->u_arg[0]);
441 do_dup2(struct tcb *tcp, int flags_arg)
444 printfd(tcp, tcp->u_arg[0]);
446 printfd(tcp, tcp->u_arg[1]);
447 if (flags_arg >= 0) {
449 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
456 sys_dup2(struct tcb *tcp)
458 return do_dup2(tcp, -1);
462 sys_dup3(struct tcb *tcp)
464 return do_dup2(tcp, 2);
469 sys_getdtablesize(struct tcb *tcp)
476 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
479 unsigned nfds, fdsize;
485 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
486 if (args[0] > 1024*1024)
490 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
493 fds = malloc(fdsize);
498 for (i = 0; i < 3; i++) {
505 tprintf(", %#lx", arg);
508 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
513 for (j = 0, sep = ""; j < nfds; j++) {
514 if (FD_ISSET(j, fds)) {
524 printtv_bitness(tcp, args[4], bitness, 0);
527 static char outstr[1024];
529 #define end_outstr (outstr + sizeof(outstr))
537 tcp->auxstr = "Timeout";
541 fds = malloc(fdsize);
547 for (i = 0; i < 3; i++) {
551 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
553 for (j = 0; j < args[0]; j++) {
554 if (FD_ISSET(j, fds)) {
555 /* +2 chars needed at the end: ']',NUL */
556 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
558 outptr += sprintf(outptr, "%s%s [%u",
560 i == 0 ? "in" : i == 1 ? "out" : "except",
567 outptr += sprintf(outptr, " %u", j);
573 if (outptr != outstr)
579 /* This contains no useful information on SunOS. */
581 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
582 outptr += sprintf(outptr, "%sleft ", sep);
583 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
587 tcp->auxstr = outstr;
595 sys_oldselect(struct tcb *tcp)
599 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
603 return decode_select(tcp, args, BITNESS_CURRENT);
608 sys_osf_select(struct tcb *tcp)
610 long *args = tcp->u_arg;
611 return decode_select(tcp, args, BITNESS_32);
615 static const struct xlat epollctls[] = {
617 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
620 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
623 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
628 static const struct xlat epollevents[] = {
630 { EPOLLIN, "EPOLLIN" },
633 { EPOLLPRI, "EPOLLPRI" },
636 { EPOLLOUT, "EPOLLOUT" },
639 { EPOLLRDNORM, "EPOLLRDNORM" },
642 { EPOLLRDBAND, "EPOLLRDBAND" },
645 { EPOLLWRNORM, "EPOLLWRNORM" },
648 { EPOLLWRBAND, "EPOLLWRBAND" },
651 { EPOLLMSG, "EPOLLMSG" },
654 { EPOLLERR, "EPOLLERR" },
657 { EPOLLHUP, "EPOLLHUP" },
660 { EPOLLRDHUP, "EPOLLRDHUP" },
663 { EPOLLONESHOT, "EPOLLONESHOT" },
666 { EPOLLET, "EPOLLET" },
671 /* Not aliased to printargs_ld: we want it to have a distinct address */
673 sys_epoll_create(struct tcb *tcp)
675 return printargs_ld(tcp);
678 static const struct xlat epollflags[] = {
680 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
682 #ifdef EPOLL_NONBLOCK
683 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
689 sys_epoll_create1(struct tcb *tcp)
692 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
696 #ifdef HAVE_SYS_EPOLL_H
698 print_epoll_event(struct epoll_event *ev)
701 printflags(epollevents, ev->events, "EPOLL???");
702 /* We cannot know what format the program uses, so print u32 and u64
703 which will cover every value. */
704 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
705 ev->data.u32, ev->data.u64);
710 sys_epoll_ctl(struct tcb *tcp)
713 printfd(tcp, tcp->u_arg[0]);
715 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
717 printfd(tcp, tcp->u_arg[2]);
719 if (tcp->u_arg[3] == 0)
722 #ifdef HAVE_SYS_EPOLL_H
723 struct epoll_event ev;
724 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
725 print_epoll_event(&ev);
735 epoll_wait_common(struct tcb *tcp)
738 printfd(tcp, tcp->u_arg[0]);
742 tprintf("%lx", tcp->u_arg[1]);
743 else if (tcp->u_rval == 0)
746 #ifdef HAVE_SYS_EPOLL_H
747 struct epoll_event ev, *start, *cur, *end;
751 start = (struct epoll_event *) tcp->u_arg[1];
752 end = start + tcp->u_rval;
753 for (cur = start; cur < end; ++cur) {
756 if (umove(tcp, (long) cur, &ev) == 0)
757 print_epoll_event(&ev);
766 tprintf(" %#lx", (long) start);
771 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
776 sys_epoll_wait(struct tcb *tcp)
778 epoll_wait_common(tcp);
783 sys_epoll_pwait(struct tcb *tcp)
785 epoll_wait_common(tcp);
788 print_sigset(tcp, tcp->u_arg[4], 0);
794 sys_io_setup(struct tcb *tcp)
797 tprintf("%ld, ", tcp->u_arg[0]);
800 tprintf("0x%0lx", tcp->u_arg[1]);
802 unsigned long user_id;
803 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
804 tprintf("{%lu}", user_id);
813 sys_io_destroy(struct tcb *tcp)
816 tprintf("%lu", tcp->u_arg[0]);
823 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
827 iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
829 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
830 static const struct {
834 { "pread", SUB_COMMON },
835 { "pwrite", SUB_COMMON },
836 { "fsync", SUB_NONE },
837 { "fdsync", SUB_NONE },
839 { "poll", SUB_POLL },
840 { "noop", SUB_NONE },
841 { "preadv", SUB_VECTOR },
842 { "pwritev", SUB_VECTOR },
845 if (cmd < ARRAY_SIZE(cmds)) {
846 *sub = cmds[cmd].sub;
847 return cmds[cmd].name;
850 sprintf(buf, "%u /* SUB_??? */", cmd);
854 /* Not defined in libaio.h */
856 # define IOCB_RESFD (1 << 0)
860 print_common_flags(struct iocb *iocb)
862 if (iocb->u.c.flags & IOCB_RESFD)
863 tprintf("resfd=%d, ", iocb->u.c.resfd);
864 if (iocb->u.c.flags & ~IOCB_RESFD)
865 tprintf("flags=%x, ", iocb->u.c.flags);
868 #endif /* HAVE_LIBAIO_H */
871 sys_io_submit(struct tcb *tcp)
875 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
877 /* and if nr is negative? */
883 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
885 for (i = 0; i < nr; i++, iocbs++) {
893 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
894 umove(tcp, (unsigned long)iocbp, &iocb)) {
900 tprintf("data:%p, ", iocb.data);
902 tprintf("key:%u, ", iocb.key);
903 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
904 if (iocb.aio_reqprio)
905 tprintf("reqprio:%d, ", iocb.aio_reqprio);
906 tprintf("filedes:%d", iocb.aio_fildes);
909 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
911 printstr(tcp, (unsigned long)iocb.u.c.buf,
914 tprintf(", buf:%p", iocb.u.c.buf);
916 tprintf(", nbytes:%lu, offset:%llx",
919 print_common_flags(&iocb);
922 tprintf(", %llx, ", iocb.u.v.offset);
923 print_common_flags(&iocb);
924 tprint_iov(tcp, iocb.u.v.nr,
925 (unsigned long)iocb.u.v.vec,
926 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
929 tprintf(", %x", iocb.u.poll.events);
939 #warning "libaio-devel is not available => no io_submit decoding"
940 tprintf("%#lx", tcp->u_arg[2]);
948 sys_io_cancel(struct tcb *tcp)
954 tprintf("%lu, ", tcp->u_arg[0]);
956 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
957 tprintf("{%p, %u, %hu, %hu, %d}, ",
960 iocb.aio_reqprio, iocb.aio_fildes);
969 struct io_event event;
970 if (umove(tcp, tcp->u_arg[2], &event) == 0)
971 tprintf("{%p, %p, %ld, %ld}",
972 event.data, event.obj,
973 event.res, event.res2);
983 sys_io_getevents(struct tcb *tcp)
986 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
989 if (tcp->u_rval == 0) {
993 struct io_event *events = (void *)tcp->u_arg[3];
994 long i, nr = tcp->u_rval;
996 for (i = 0; i < nr; i++, events++) {
997 struct io_event event;
1004 if (umove(tcp, (unsigned long)events, &event) != 0) {
1008 tprintf("{%p, %p, %ld, %ld}", event.data,
1009 event.obj, event.res, event.res2);
1017 print_timespec(tcp, tcp->u_arg[4]);
1023 sys_select(struct tcb *tcp)
1025 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1029 sys_pselect6(struct tcb *tcp)
1031 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1032 if (entering(tcp)) {
1037 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1038 tprintf(", %#lx", tcp->u_arg[5]);
1041 if (data.len < sizeof(long))
1042 tprintf("%#lx", (long)data.ss);
1044 print_sigset(tcp, (long)data.ss, 0);
1045 tprintf(", %lu}", data.len);
1052 do_eventfd(struct tcb *tcp, int flags_arg)
1054 if (entering(tcp)) {
1055 tprintf("%lu", tcp->u_arg[0]);
1056 if (flags_arg >= 0) {
1058 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1065 sys_eventfd(struct tcb *tcp)
1067 return do_eventfd(tcp, -1);
1071 sys_eventfd2(struct tcb *tcp)
1073 return do_eventfd(tcp, 1);