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 printflags(fdflags, tcp->u_arg[2], "FD_???");
283 case F_SETOWN: case F_DUPFD:
284 tprintf(", %ld", tcp->u_arg[2]);
288 printflags(openmodes, tcp->u_arg[2] + 1, "O_???");
290 case F_SETLK: case F_SETLKW:
295 printflock(tcp, tcp->u_arg[2], 0);
301 /* Linux glibc defines SETLK64 as SETLK,
302 even though the kernel has different values - as does Solaris. */
303 #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
306 #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
310 printflock64(tcp, tcp->u_arg[2], 0);
316 switch (tcp->u_arg[1]) {
318 case F_SETFD: case F_SETFL:
319 case F_SETLK: case F_SETLKW:
320 case F_SETOWN: case F_GETOWN:
323 if (tcp->u_rval == 0)
325 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
326 return RVAL_HEX|RVAL_STR;
328 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
329 return RVAL_HEX|RVAL_STR;
332 printflock(tcp, tcp->u_arg[2], 1);
335 #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
339 printflock64(tcp, tcp->u_arg[2], 1);
343 tprintf(", %#lx", tcp->u_arg[2]);
357 tprintf("%ld, ", tcp->u_arg[0]);
358 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
369 tprintf("%ld", tcp->u_arg[0]);
379 tprintf("%ld", tcp->u_arg[0]);
389 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
395 sys_getdtablesize(tcp)
402 decode_select(tcp, args, bitness)
408 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
418 static char outstr[1024];
423 fds = (fd_set *) malloc(fdsize);
425 fprintf(stderr, "out of memory\n");
428 for (i = 0; i < 3; i++) {
434 if (fds == NULL || !verbose(tcp)) {
435 tprintf(", %#lx", arg);
438 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
443 for (j = 0, sep = ""; j < nfds; j++) {
444 if (FD_ISSET(j, fds)) {
445 tprintf("%s%u", sep, j);
454 else if (!verbose(tcp))
455 tprintf(", %#lx", args[4]);
456 else if (umove(tcp, args[4], &tv) < 0)
461 tv32=(struct timeval32*)&tv;
462 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
465 tprintf(", {%lu, %lu}",
466 (long) tv.tv_sec, (long) tv.tv_usec);
471 unsigned int cumlen = 0;
477 if ((nfds = tcp->u_rval) == 0) {
478 tcp->auxstr = "Timeout";
482 fds = (fd_set *) malloc(fdsize);
484 fprintf(stderr, "out of memory\n");
487 for (i = 0; i < 3; i++) {
491 tcp->auxstr = outstr;
493 if (fds == NULL || !arg ||
494 umoven(tcp, arg, fdsize, (char *) fds) < 0)
496 for (j = 0; j < args[0]; j++) {
497 if (FD_ISSET(j, fds)) {
499 sprintf(str, "%s%s [%u", sep,
507 sprintf(str, " %u", j);
508 cumlen += strlen(str);
509 if (cumlen < sizeof(outstr))
521 /* This contains no useful information on SunOS. */
525 if (umove(tcp, args[4], &tv) >= 0) {
528 tv32=(struct timeval32*)&tv;
529 sprintf(str, "%sleft {%u, %u}", sep,
530 tv32->tv_sec, tv32->tv_usec);
533 sprintf(str, "%sleft {%lu, %lu}", sep,
534 (long) tv.tv_sec, (long) tv.tv_usec);
536 if ((cumlen += strlen(str)) < sizeof(outstr))
554 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
558 return decode_select(tcp, args, 0);
566 long *args = tcp->u_arg;
567 return decode_select(tcp, args, 1);
571 static struct xlat epollctls[] = {
573 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
576 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
579 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
584 static struct xlat epollevents[] = {
586 { EPOLLIN, "EPOLLIN" },
589 { EPOLLPRI, "EPOLLPRI" },
592 { EPOLLOUT, "EPOLLOUT" },
595 { EPOLLRDNORM, "EPOLLRDNORM" },
598 { EPOLLRDBAND, "EPOLLRDBAND" },
601 { EPOLLWRNORM, "EPOLLWRNORM" },
604 { EPOLLWRBAND, "EPOLLWRBAND" },
607 { EPOLLMSG, "EPOLLMSG" },
610 { EPOLLERR, "EPOLLERR" },
613 { EPOLLHUP, "EPOLLHUP" },
616 { EPOLLONESHOT, "EPOLLONESHOT" },
619 { EPOLLET, "EPOLLET" },
625 sys_epoll_create(tcp)
629 tprintf("%ld", tcp->u_arg[0]);
633 #ifdef HAVE_SYS_EPOLL_H
635 print_epoll_event(ev)
636 struct epoll_event *ev;
639 printflags(epollevents, ev->events, "EPOLL???");
640 /* We cannot know what format the program uses, so print u32 and u64
641 which will cover every value. */
642 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
643 ev->data.u32, ev->data.u64);
652 tprintf("%ld, ", tcp->u_arg[0]);
653 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
654 tprintf(", %ld, ", tcp->u_arg[2]);
655 if (tcp->u_arg[3] == 0)
658 #ifdef HAVE_SYS_EPOLL_H
659 struct epoll_event ev;
660 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
661 print_epoll_event(&ev);
675 tprintf("%ld, ", tcp->u_arg[0]);
678 tprintf("%lx", tcp->u_arg[1]);
679 else if (tcp->u_rval == 0)
682 #ifdef HAVE_SYS_EPOLL_H
683 struct epoll_event ev, *start, *cur, *end;
687 start = (struct epoll_event *) tcp->u_arg[1];
688 end = start + tcp->u_rval;
689 for (cur = start; cur < end; ++cur) {
692 if (umove(tcp, (long) cur, &ev) == 0)
693 print_epoll_event(&ev);
702 tprintf(" %#lx", (long) start);
707 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
717 tprintf("%ld, ", tcp->u_arg[0]);
720 tprintf("0x%0lx", tcp->u_arg[1]);
722 unsigned long user_id;
723 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
724 tprintf("{%lu}", user_id);
737 tprintf("%lu", tcp->u_arg[0]);
747 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
749 /* and if nr is negative? */
755 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
757 for (i = 0; i < nr; i++, iocbs++) {
764 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
765 umove(tcp, (unsigned long)iocbp, &iocb)) {
769 tprintf("{%p, %u, %hu, %hu, %d}",
772 iocb.aio_reqprio, iocb.aio_fildes);
792 tprintf("%lu, ", tcp->u_arg[0]);
794 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
795 tprintf("{%p, %u, %hu, %hu, %d}, ",
798 iocb.aio_reqprio, iocb.aio_fildes);
807 struct io_event event;
808 if (umove(tcp, tcp->u_arg[2], &event) == 0)
809 tprintf("{%p, %p, %ld, %ld}",
810 event.data, event.obj,
811 event.res, event.res2);
821 sys_io_getevents(tcp)
825 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
828 if (tcp->u_rval == 0) {
832 struct io_event *events = (void *)tcp->u_arg[3];
833 long i, nr = tcp->u_rval;
835 for (i = 0; i < nr; i++, events++) {
836 struct io_event event;
843 if (umove(tcp, (unsigned long)events, &event) != 0) {
847 tprintf("{%p, %p, %ld, %ld}", event.data,
848 event.obj, event.res, event.res2);
856 if (tcp->u_arg[4] == 0)
860 if (umove(tcp, tcp->u_arg[4], &to) == 0)
861 tprintf("{%lu, %lu}", to.tv_sec, to.tv_nsec);
874 long *args = tcp->u_arg;
875 return decode_select(tcp, args, 0);