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" },
154 static const struct xlat fdflags[] = {
156 { FD_CLOEXEC, "FD_CLOEXEC" },
163 static const struct xlat flockcmds[] = {
164 { LOCK_SH, "LOCK_SH" },
165 { LOCK_EX, "LOCK_EX" },
166 { LOCK_NB, "LOCK_NB" },
167 { LOCK_UN, "LOCK_UN" },
173 static const struct xlat lockfcmds[] = {
174 { F_RDLCK, "F_RDLCK" },
175 { F_WRLCK, "F_WRLCK" },
176 { F_UNLCK, "F_UNLCK" },
178 { F_EXLCK, "F_EXLCK" },
181 { F_SHLCK, "F_SHLCK" },
186 static const struct xlat whence[] = {
187 { SEEK_SET, "SEEK_SET" },
188 { SEEK_CUR, "SEEK_CUR" },
189 { SEEK_END, "SEEK_END" },
193 #ifndef HAVE_LONG_LONG_OFF_T
196 printflock(tcp, addr, getlk)
203 if (umove(tcp, addr, &fl) < 0) {
208 printxval(lockfcmds, fl.l_type, "F_???");
209 tprintf(", whence=");
210 printxval(whence, fl.l_whence, "SEEK_???");
211 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
213 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
219 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
222 printflock64(tcp, addr, getlk)
229 if (umove(tcp, addr, &fl) < 0) {
234 printxval(lockfcmds, fl.l_type, "F_???");
235 tprintf(", whence=");
236 printxval(whence, fl.l_whence, "SEEK_???");
237 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
239 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
246 sprintflags(xlat, flags)
247 const struct xlat *xlat;
250 static char outstr[1024];
253 strcpy(outstr, "flags ");
255 for (; xlat->str; xlat++) {
256 if ((flags & xlat->val) == xlat->val) {
257 sprintf(outstr + strlen(outstr),
258 "%s%s", sep, xlat->str);
264 sprintf(outstr + strlen(outstr),
265 "%s%#x", sep, flags);
273 extern const struct xlat openmodes[];
276 tprintf("%ld, ", tcp->u_arg[0]);
277 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
278 switch (tcp->u_arg[1]) {
281 if (printflags(fdflags, tcp->u_arg[2]) == 0)
284 case F_SETOWN: case F_DUPFD:
285 tprintf(", %ld", tcp->u_arg[2]);
289 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
292 case F_SETLK: case F_SETLKW:
297 printflock(tcp, tcp->u_arg[2], 0);
303 /* Linux glibc defines SETLK64 as SETLK,
304 even though the kernel has different values - as does Solaris. */
305 #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
308 #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
312 printflock64(tcp, tcp->u_arg[2], 0);
318 switch (tcp->u_arg[1]) {
320 case F_SETFD: case F_SETFL:
321 case F_SETLK: case F_SETLKW:
322 case F_SETOWN: case F_GETOWN:
325 if (tcp->u_rval == 0)
327 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
328 return RVAL_HEX|RVAL_STR;
330 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
331 return RVAL_HEX|RVAL_STR;
334 printflock(tcp, tcp->u_arg[2], 1);
337 #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
341 printflock64(tcp, tcp->u_arg[2], 1);
345 tprintf(", %#lx", tcp->u_arg[2]);
359 tprintf("%ld, ", tcp->u_arg[0]);
360 if (!printflags(flockcmds, tcp->u_arg[1]))
372 tprintf("%ld", tcp->u_arg[0]);
382 tprintf("%ld", tcp->u_arg[0]);
392 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
398 sys_getdtablesize(tcp)
405 decode_select(tcp, args, bitness)
411 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
421 static char outstr[1024];
426 fds = (fd_set *) malloc(fdsize);
428 tprintf("out of memory\n");
433 for (i = 0; i < 3; i++) {
440 tprintf(", %#lx", arg);
443 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
448 for (j = 0, sep = ""; j < nfds; j++) {
449 if (FD_ISSET(j, fds)) {
450 tprintf("%s%u", sep, j);
459 else if (!verbose(tcp))
460 tprintf(", %#lx", args[4]);
461 else if (umove(tcp, args[4], &tv) < 0)
466 tv32=(struct timeval32*)&tv;
467 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
470 tprintf(", {%lu, %lu}",
471 (long) tv.tv_sec, (long) tv.tv_usec);
476 unsigned int cumlen = 0;
482 if ((nfds = tcp->u_rval) == 0) {
483 tcp->auxstr = "Timeout";
487 fds = (fd_set *) malloc(fdsize);
489 tprintf("out of memory\n");
494 for (i = 0; i < 3; i++) {
498 tcp->auxstr = outstr;
500 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
502 for (j = 0; j < args[0]; j++) {
503 if (FD_ISSET(j, fds)) {
505 sprintf(str, "%s%s [%u", sep,
513 sprintf(str, " %u", j);
514 cumlen += strlen(str);
515 if (cumlen < sizeof(outstr))
527 /* This contains no useful information on SunOS. */
531 if (umove(tcp, args[4], &tv) >= 0) {
534 tv32=(struct timeval32*)&tv;
535 sprintf(str, "%sleft {%u, %u}", sep,
536 tv32->tv_sec, tv32->tv_usec);
539 sprintf(str, "%sleft {%lu, %lu}", sep,
540 (long) tv.tv_sec, (long) tv.tv_usec);
542 if ((cumlen += strlen(str)) < sizeof(outstr))
560 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
564 return decode_select(tcp, args, 0);
572 long *args = tcp->u_arg;
573 return decode_select(tcp, args, 1);
577 static struct xlat epollctls[] = {
579 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
582 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
585 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
590 static struct xlat epollevents[] = {
592 { EPOLLIN, "EPOLLIN" },
595 { EPOLLPRI, "EPOLLPRI" },
598 { EPOLLOUT, "EPOLLOUT" },
601 { EPOLLRDNORM, "EPOLLRDNORM" },
604 { EPOLLRDBAND, "EPOLLRDBAND" },
607 { EPOLLWRNORM, "EPOLLWRNORM" },
610 { EPOLLWRBAND, "EPOLLWRBAND" },
613 { EPOLLMSG, "EPOLLMSG" },
616 { EPOLLERR, "EPOLLERR" },
619 { EPOLLHUP, "EPOLLHUP" },
622 { EPOLLONESHOT, "EPOLLONESHOT" },
625 { EPOLLET, "EPOLLET" },
631 sys_epoll_create(tcp)
635 tprintf("%ld", tcp->u_arg[0]);
639 #ifdef HAVE_SYS_EPOLL_H
641 print_epoll_event(ev)
642 struct epoll_event *ev;
645 if (printflags(epollevents, ev->events) == 0)
647 /* We cannot know what format the program uses, so print u32 and u64
648 which will cover every value. */
649 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
650 ev->data.u32, ev->data.u64);
659 tprintf("%ld, ", tcp->u_arg[0]);
660 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
661 tprintf(", %ld, ", tcp->u_arg[2]);
662 if (tcp->u_arg[3] == 0)
665 #ifdef HAVE_SYS_EPOLL_H
666 struct epoll_event ev;
667 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
668 print_epoll_event(&ev);
682 tprintf("%ld, ", tcp->u_arg[0]);
685 tprintf("%lx", tcp->u_arg[1]);
686 else if (tcp->u_rval == 0)
689 #ifdef HAVE_SYS_EPOLL_H
690 struct epoll_event evs[tcp->u_rval];
691 if (umove(tcp, tcp->u_arg[1], evs) == 0) {
694 for (i = 0; i < tcp->u_rval; ++i) {
697 print_epoll_event(&evs[i]);
705 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
715 tprintf("%ld, ", tcp->u_arg[0]);
718 tprintf("0x%0lx", tcp->u_arg[1]);
720 unsigned long user_id;
721 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
722 tprintf("{%lu}", user_id);
735 tprintf("%lu", tcp->u_arg[0]);
745 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
747 /* and if nr is negative? */
753 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
755 for (i = 0; i < nr; i++, iocbs++) {
762 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
763 umove(tcp, (unsigned long)iocbp, &iocb)) {
767 tprintf("{%p, %u, %hu, %hu, %d}",
770 iocb.aio_reqprio, iocb.aio_fildes);
790 tprintf("%lu, ", tcp->u_arg[0]);
792 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
793 tprintf("{%p, %u, %hu, %hu, %d}, ",
796 iocb.aio_reqprio, iocb.aio_fildes);
805 struct io_event event;
806 if (umove(tcp, tcp->u_arg[2], &event) == 0)
807 tprintf("{%p, %p, %ld, %ld}",
808 event.data, event.obj,
809 event.res, event.res2);
819 sys_io_getevents(tcp)
823 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
826 if (tcp->u_rval == 0) {
830 struct io_event *events = (void *)tcp->u_arg[3];
831 long i, nr = tcp->u_rval;
833 for (i = 0; i < nr; i++, events++) {
834 struct io_event event;
841 if (umove(tcp, (unsigned long)events, &event) != 0) {
845 tprintf("{%p, %p, %ld, %ld}", event.data,
846 event.obj, event.res, event.res2);
854 if (tcp->u_arg[4] == 0)
858 if (umove(tcp, tcp->u_arg[4], &to) == 0)
859 tprintf("{%lu, %lu}", to.tv_sec, to.tv_nsec);
872 long *args = tcp->u_arg;
873 return decode_select(tcp, args, 0);