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.
40 #ifdef HAVE_SYS_EPOLL_H
41 #include <sys/epoll.h>
47 #if HAVE_LONG_LONG_OFF_T
49 * Hacks for systems that have a long long off_t
51 #define flock64 flock /* Horrid hack */
52 #define printflock printflock64 /* Horrider hack */
56 static const struct xlat fcntlcmds[] = {
57 { F_DUPFD, "F_DUPFD" },
58 { F_GETFD, "F_GETFD" },
59 { F_SETFD, "F_SETFD" },
60 { F_GETFL, "F_GETFL" },
61 { F_SETFL, "F_SETFL" },
62 { F_GETLK, "F_GETLK" },
63 { F_SETLK, "F_SETLK" },
64 { F_SETLKW, "F_SETLKW" },
65 { F_GETOWN, "F_GETOWN" },
66 { F_SETOWN, "F_SETOWN" },
68 { F_RSETLK, "F_RSETLK" },
71 { F_RSETLKW, "F_RSETLKW" },
74 { F_RGETLK, "F_RGETLK" },
80 { F_SETSIG, "F_SETSIG" },
83 { F_GETSIG, "F_GETSIG" },
86 { F_CHKFL, "F_CHKFL" },
89 { F_DUP2FD, "F_DUP2FD" },
92 { F_ALLOCSP, "F_ALLOCSP" },
95 { F_ISSTREAM, "F_ISSTREAM" },
101 { F_NPRIV, "F_NPRIV" },
104 { F_QUOTACL, "F_QUOTACL" },
107 { F_BLOCKS, "F_BLOCKS" },
110 { F_BLKSIZE, "F_BLKSIZE" },
113 { F_GETOWN, "F_GETOWN" },
116 { F_SETOWN, "F_SETOWN" },
119 { F_REVOKE, "F_REVOKE" },
122 { F_SETLK, "F_SETLK" },
125 { F_SETLKW, "F_SETLKW" },
128 { F_FREESP, "F_FREESP" },
131 { F_GETLK, "F_GETLK" },
134 { F_SETLK64, "F_SETLK64" },
137 { F_SETLKW64, "F_SETLKW64" },
140 { F_FREESP64, "F_FREESP64" },
143 { F_GETLK64, "F_GETLK64" },
146 { F_SHARE, "F_SHARE" },
149 { F_UNSHARE, "F_UNSHARE" },
152 { F_SETLEASE, "F_SETLEASE" },
155 { F_GETLEASE, "F_GETLEASE" },
158 { F_NOTIFY, "F_NOTIFY" },
160 #ifdef F_DUPFD_CLOEXEC
161 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
166 static const struct xlat fdflags[] = {
168 { FD_CLOEXEC, "FD_CLOEXEC" },
175 static const struct xlat flockcmds[] = {
176 { LOCK_SH, "LOCK_SH" },
177 { LOCK_EX, "LOCK_EX" },
178 { LOCK_NB, "LOCK_NB" },
179 { LOCK_UN, "LOCK_UN" },
185 static const struct xlat lockfcmds[] = {
186 { F_RDLCK, "F_RDLCK" },
187 { F_WRLCK, "F_WRLCK" },
188 { F_UNLCK, "F_UNLCK" },
190 { F_EXLCK, "F_EXLCK" },
193 { F_SHLCK, "F_SHLCK" },
199 static const struct xlat notifyflags[] = {
201 { DN_ACCESS, "DN_ACCESS" },
204 { DN_MODIFY, "DN_MODIFY" },
207 { DN_CREATE, "DN_CREATE" },
210 { DN_DELETE, "DN_DELETE" },
213 { DN_RENAME, "DN_RENAME" },
216 { DN_ATTRIB, "DN_ATTRIB" },
219 { DN_MULTISHOT, "DN_MULTISHOT" },
225 static const struct xlat whence[] = {
226 { SEEK_SET, "SEEK_SET" },
227 { SEEK_CUR, "SEEK_CUR" },
228 { SEEK_END, "SEEK_END" },
232 #ifndef HAVE_LONG_LONG_OFF_T
235 printflock(struct tcb *tcp, long addr, int getlk)
239 #if SUPPORTED_PERSONALITIES > 1
240 if (personality_wordsize[current_personality] != sizeof(fl.l_start)) {
241 if (personality_wordsize[current_personality] == 4) {
242 /* 32-bit x86 app on x86_64 and similar cases */
246 int32_t l_start; /* off_t */
247 int32_t l_len; /* off_t */
248 int32_t l_pid; /* pid_t */
250 if (umove(tcp, addr, &fl32) < 0) {
254 fl.l_type = fl32.l_type;
255 fl.l_whence = fl32.l_whence;
256 fl.l_start = fl32.l_start;
257 fl.l_len = fl32.l_len;
258 fl.l_pid = fl32.l_pid;
260 /* let people know we have a problem here */
261 tprintf("{ <decode error: unsupported wordsize %d> }",
262 personality_wordsize[current_personality]);
268 if (umove(tcp, addr, &fl) < 0) {
274 printxval(lockfcmds, fl.l_type, "F_???");
275 tprints(", whence=");
276 printxval(whence, fl.l_whence, "SEEK_???");
277 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
279 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
285 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
288 printflock64(struct tcb *tcp, long addr, int getlk)
292 if (umove(tcp, addr, &fl) < 0) {
297 printxval(lockfcmds, fl.l_type, "F_???");
298 tprints(", whence=");
299 printxval(whence, fl.l_whence, "SEEK_???");
300 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
302 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
309 sys_fcntl(struct tcb *tcp)
312 printfd(tcp, tcp->u_arg[0]);
314 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
315 switch (tcp->u_arg[1]) {
318 printflags(fdflags, tcp->u_arg[2], "FD_???");
320 case F_SETOWN: case F_DUPFD:
321 #ifdef F_DUPFD_CLOEXEC
322 case F_DUPFD_CLOEXEC:
324 tprintf(", %ld", tcp->u_arg[2]);
328 tprint_open_modes(tcp->u_arg[2]);
330 case F_SETLK: case F_SETLKW:
335 printflock(tcp, tcp->u_arg[2], 0);
341 /* Linux glibc defines SETLK64 as SETLK,
342 even though the kernel has different values - as does Solaris. */
343 #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
346 #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
350 printflock64(tcp, tcp->u_arg[2], 0);
356 printflags(notifyflags, tcp->u_arg[2], "DN_???");
362 printxval(lockfcmds, tcp->u_arg[2], "F_???");
368 switch (tcp->u_arg[1]) {
370 #ifdef F_DUPFD_CLOEXEC
371 case F_DUPFD_CLOEXEC:
373 case F_SETFD: case F_SETFL:
374 case F_SETLK: case F_SETLKW:
375 case F_SETOWN: case F_GETOWN:
384 if (syserror(tcp) || tcp->u_rval == 0)
386 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
387 return RVAL_HEX|RVAL_STR;
391 tcp->auxstr = sprint_open_modes(tcp->u_rval);
392 return RVAL_HEX|RVAL_STR;
395 printflock(tcp, tcp->u_arg[2], 1);
398 #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
402 printflock64(tcp, tcp->u_arg[2], 1);
409 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
410 return RVAL_HEX|RVAL_STR;
413 tprintf(", %#lx", tcp->u_arg[2]);
423 sys_flock(struct tcb *tcp)
426 printfd(tcp, tcp->u_arg[0]);
428 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
435 sys_close(struct tcb *tcp)
438 printfd(tcp, tcp->u_arg[0]);
444 sys_dup(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);
475 sys_dup3(struct tcb *tcp)
477 return do_dup2(tcp, 2);
481 #if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
483 sys_getdtablesize(struct tcb *tcp)
487 #endif /* ALPHA || FREEBSD || SUNOS4 */
490 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
493 unsigned nfds, fdsize;
499 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
500 if (args[0] > 1024*1024)
504 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
507 fds = malloc(fdsize);
512 for (i = 0; i < 3; i++) {
519 tprintf(", %#lx", arg);
522 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
527 for (j = 0, sep = ""; j < nfds; j++) {
528 if (FD_ISSET(j, fds)) {
538 printtv_bitness(tcp, args[4], bitness, 0);
541 static char outstr[1024];
543 #define end_outstr (outstr + sizeof(outstr))
551 tcp->auxstr = "Timeout";
555 fds = malloc(fdsize);
561 for (i = 0; i < 3; i++) {
565 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
567 for (j = 0; j < args[0]; j++) {
568 if (FD_ISSET(j, fds)) {
569 /* +2 chars needed at the end: ']',NUL */
570 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
572 outptr += sprintf(outptr, "%s%s [%u",
574 i == 0 ? "in" : i == 1 ? "out" : "except",
581 outptr += sprintf(outptr, " %u", j);
587 if (outptr != outstr)
594 /* This contains no useful information on SunOS. */
596 if (outptr < end_outstr - 128) {
597 outptr += sprintf(outptr, "%sleft ", sep);
598 outptr = sprinttv(tcp, args[4], bitness, outptr);
603 tcp->auxstr = outstr;
613 sys_oldselect(struct tcb *tcp)
617 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
621 return decode_select(tcp, args, BITNESS_CURRENT);
626 sys_osf_select(struct tcb *tcp)
628 long *args = tcp->u_arg;
629 return decode_select(tcp, args, BITNESS_32);
633 static const struct xlat epollctls[] = {
635 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
638 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
641 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
646 static const struct xlat epollevents[] = {
648 { EPOLLIN, "EPOLLIN" },
651 { EPOLLPRI, "EPOLLPRI" },
654 { EPOLLOUT, "EPOLLOUT" },
657 { EPOLLRDNORM, "EPOLLRDNORM" },
660 { EPOLLRDBAND, "EPOLLRDBAND" },
663 { EPOLLWRNORM, "EPOLLWRNORM" },
666 { EPOLLWRBAND, "EPOLLWRBAND" },
669 { EPOLLMSG, "EPOLLMSG" },
672 { EPOLLERR, "EPOLLERR" },
675 { EPOLLHUP, "EPOLLHUP" },
678 { EPOLLRDHUP, "EPOLLRDHUP" },
681 { EPOLLONESHOT, "EPOLLONESHOT" },
684 { EPOLLET, "EPOLLET" },
690 sys_epoll_create(struct tcb *tcp)
693 tprintf("%ld", tcp->u_arg[0]);
697 static const struct xlat epollflags[] = {
699 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
701 #ifdef EPOLL_NONBLOCK
702 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
708 sys_epoll_create1(struct tcb *tcp)
711 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
715 #ifdef HAVE_SYS_EPOLL_H
717 print_epoll_event(struct epoll_event *ev)
720 printflags(epollevents, ev->events, "EPOLL???");
721 /* We cannot know what format the program uses, so print u32 and u64
722 which will cover every value. */
723 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
724 ev->data.u32, ev->data.u64);
729 sys_epoll_ctl(struct tcb *tcp)
732 printfd(tcp, tcp->u_arg[0]);
734 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
736 printfd(tcp, tcp->u_arg[2]);
738 if (tcp->u_arg[3] == 0)
741 #ifdef HAVE_SYS_EPOLL_H
742 struct epoll_event ev;
743 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
744 print_epoll_event(&ev);
754 epoll_wait_common(struct tcb *tcp)
757 printfd(tcp, tcp->u_arg[0]);
761 tprintf("%lx", tcp->u_arg[1]);
762 else if (tcp->u_rval == 0)
765 #ifdef HAVE_SYS_EPOLL_H
766 struct epoll_event ev, *start, *cur, *end;
770 start = (struct epoll_event *) tcp->u_arg[1];
771 end = start + tcp->u_rval;
772 for (cur = start; cur < end; ++cur) {
775 if (umove(tcp, (long) cur, &ev) == 0)
776 print_epoll_event(&ev);
785 tprintf(" %#lx", (long) start);
790 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
795 sys_epoll_wait(struct tcb *tcp)
797 epoll_wait_common(tcp);
802 sys_epoll_pwait(struct tcb *tcp)
804 epoll_wait_common(tcp);
807 print_sigset(tcp, tcp->u_arg[4], 0);
813 sys_io_setup(struct tcb *tcp)
816 tprintf("%ld, ", tcp->u_arg[0]);
819 tprintf("0x%0lx", tcp->u_arg[1]);
821 unsigned long user_id;
822 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
823 tprintf("{%lu}", user_id);
832 sys_io_destroy(struct tcb *tcp)
835 tprintf("%lu", tcp->u_arg[0]);
842 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
846 iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
848 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
849 static const struct {
853 { "pread", SUB_COMMON },
854 { "pwrite", SUB_COMMON },
855 { "fsync", SUB_NONE },
856 { "fdsync", SUB_NONE },
858 { "poll", SUB_POLL },
859 { "noop", SUB_NONE },
860 { "preadv", SUB_VECTOR },
861 { "pwritev", SUB_VECTOR },
864 if (cmd < ARRAY_SIZE(cmds)) {
865 *sub = cmds[cmd].sub;
866 return cmds[cmd].name;
869 sprintf(buf, "%u /* SUB_??? */", cmd);
873 /* Not defined in libaio.h */
875 # define IOCB_RESFD (1 << 0)
879 print_common_flags(struct iocb *iocb)
881 if (iocb->u.c.flags & IOCB_RESFD)
882 tprintf("resfd=%d, ", iocb->u.c.resfd);
883 if (iocb->u.c.flags & ~IOCB_RESFD)
884 tprintf("flags=%x, ", iocb->u.c.flags);
887 #endif /* HAVE_LIBAIO_H */
890 sys_io_submit(struct tcb *tcp)
894 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
896 /* and if nr is negative? */
902 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
904 for (i = 0; i < nr; i++, iocbs++) {
912 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
913 umove(tcp, (unsigned long)iocbp, &iocb)) {
919 tprintf("data:%p, ", iocb.data);
921 tprintf("key:%u, ", iocb.key);
922 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
923 if (iocb.aio_reqprio)
924 tprintf("reqprio:%d, ", iocb.aio_reqprio);
925 tprintf("filedes:%d", iocb.aio_fildes);
928 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
930 printstr(tcp, (unsigned long)iocb.u.c.buf,
933 tprintf(", buf:%p", iocb.u.c.buf);
935 tprintf(", nbytes:%lu, offset:%llx",
938 print_common_flags(&iocb);
941 tprintf(", %llx, ", iocb.u.v.offset);
942 print_common_flags(&iocb);
943 tprint_iov(tcp, iocb.u.v.nr,
944 (unsigned long)iocb.u.v.vec,
945 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
948 tprintf(", %x", iocb.u.poll.events);
958 #warning "libaio-devel is not available => no io_submit decoding"
959 tprintf("%#lx", tcp->u_arg[2]);
967 sys_io_cancel(struct tcb *tcp)
973 tprintf("%lu, ", tcp->u_arg[0]);
975 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
976 tprintf("{%p, %u, %hu, %hu, %d}, ",
979 iocb.aio_reqprio, iocb.aio_fildes);
988 struct io_event event;
989 if (umove(tcp, tcp->u_arg[2], &event) == 0)
990 tprintf("{%p, %p, %ld, %ld}",
991 event.data, event.obj,
992 event.res, event.res2);
1002 sys_io_getevents(struct tcb *tcp)
1004 if (entering(tcp)) {
1005 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
1008 if (tcp->u_rval == 0) {
1011 #ifdef HAVE_LIBAIO_H
1012 struct io_event *events = (void *)tcp->u_arg[3];
1013 long i, nr = tcp->u_rval;
1015 for (i = 0; i < nr; i++, events++) {
1016 struct io_event event;
1023 if (umove(tcp, (unsigned long)events, &event) != 0) {
1027 tprintf("{%p, %p, %ld, %ld}", event.data,
1028 event.obj, event.res, event.res2);
1036 print_timespec(tcp, tcp->u_arg[4]);
1043 sys_select(struct tcb *tcp)
1045 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1050 sys_pselect6(struct tcb *tcp)
1052 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
1053 if (entering(tcp)) {
1058 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1059 tprintf(", %#lx", tcp->u_arg[5]);
1062 if (data.len < sizeof(long))
1063 tprintf("%#lx", (long)data.ss);
1065 print_sigset(tcp, (long)data.ss, 0);
1066 tprintf(", %lu}", data.len);
1073 do_eventfd(struct tcb *tcp, int flags_arg)
1075 if (entering(tcp)) {
1076 tprintf("%lu", tcp->u_arg[0]);
1077 if (flags_arg >= 0) {
1079 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1086 sys_eventfd(struct tcb *tcp)
1088 return do_eventfd(tcp, -1);
1092 sys_eventfd2(struct tcb *tcp)
1094 return do_eventfd(tcp, 1);