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>
44 #if HAVE_LONG_LONG_OFF_T
46 * Hacks for systems that have a long long off_t
48 #define flock64 flock /* Horrid hack */
49 #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" },
151 static const struct xlat fdflags[] = {
153 { FD_CLOEXEC, "FD_CLOEXEC" },
160 static const struct xlat flockcmds[] = {
161 { LOCK_SH, "LOCK_SH" },
162 { LOCK_EX, "LOCK_EX" },
163 { LOCK_NB, "LOCK_NB" },
164 { LOCK_UN, "LOCK_UN" },
170 static const struct xlat lockfcmds[] = {
171 { F_RDLCK, "F_RDLCK" },
172 { F_WRLCK, "F_WRLCK" },
173 { F_UNLCK, "F_UNLCK" },
175 { F_EXLCK, "F_EXLCK" },
178 { F_SHLCK, "F_SHLCK" },
183 static const struct xlat whence[] = {
184 { SEEK_SET, "SEEK_SET" },
185 { SEEK_CUR, "SEEK_CUR" },
186 { SEEK_END, "SEEK_END" },
190 #ifndef HAVE_LONG_LONG_OFF_T
193 printflock(tcp, addr, getlk)
200 if (umove(tcp, addr, &fl) < 0) {
205 printxval(lockfcmds, fl.l_type, "F_???");
206 tprintf(", whence=");
207 printxval(whence, fl.l_whence, "SEEK_???");
208 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
210 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
216 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
219 printflock64(tcp, addr, getlk)
226 if (umove(tcp, addr, &fl) < 0) {
231 printxval(lockfcmds, fl.l_type, "F_???");
232 tprintf(", whence=");
233 printxval(whence, fl.l_whence, "SEEK_???");
234 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
236 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
243 sprintflags(xlat, flags)
244 const struct xlat *xlat;
247 static char outstr[1024];
250 strcpy(outstr, "flags ");
252 for (; xlat->str; xlat++) {
253 if ((flags & xlat->val) == xlat->val) {
254 sprintf(outstr + strlen(outstr),
255 "%s%s", sep, xlat->str);
261 sprintf(outstr + strlen(outstr),
262 "%s%#x", sep, flags);
270 extern const struct xlat openmodes[];
273 tprintf("%ld, ", tcp->u_arg[0]);
274 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
275 switch (tcp->u_arg[1]) {
278 if (printflags(fdflags, tcp->u_arg[2]) == 0)
281 case F_SETOWN: case F_DUPFD:
282 tprintf(", %ld", tcp->u_arg[2]);
286 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
289 case F_SETLK: case F_SETLKW:
294 printflock(tcp, tcp->u_arg[2], 0);
300 /* Linux glibc defines SETLK64 as SETLK,
301 even though the kernel has different values - as does Solaris. */
302 #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
305 #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
309 printflock64(tcp, tcp->u_arg[2], 0);
315 switch (tcp->u_arg[1]) {
317 case F_SETFD: case F_SETFL:
318 case F_SETLK: case F_SETLKW:
319 case F_SETOWN: case F_GETOWN:
322 if (tcp->u_rval == 0)
324 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
325 return RVAL_HEX|RVAL_STR;
327 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
328 return RVAL_HEX|RVAL_STR;
331 printflock(tcp, tcp->u_arg[2], 1);
334 #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
338 printflock64(tcp, tcp->u_arg[2], 1);
342 tprintf(", %#lx", tcp->u_arg[2]);
356 tprintf("%ld, ", tcp->u_arg[0]);
357 if (!printflags(flockcmds, tcp->u_arg[1]))
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 tprintf("out of memory\n");
430 for (i = 0; i < 3; i++) {
437 tprintf(", %#lx", arg);
440 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
445 for (j = 0, sep = ""; j < nfds; j++) {
446 if (FD_ISSET(j, fds)) {
447 tprintf("%s%u", sep, j);
456 else if (!verbose(tcp))
457 tprintf(", %#lx", args[4]);
458 else if (umove(tcp, args[4], &tv) < 0)
463 tv32=(struct timeval32*)&tv;
464 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
467 tprintf(", {%lu, %lu}",
468 (long) tv.tv_sec, (long) tv.tv_usec);
473 unsigned int cumlen = 0;
479 if ((nfds = tcp->u_rval) == 0) {
480 tcp->auxstr = "Timeout";
484 fds = (fd_set *) malloc(fdsize);
486 tprintf("out of memory\n");
491 for (i = 0; i < 3; i++) {
495 tcp->auxstr = outstr;
497 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
499 for (j = 0; j < args[0]; j++) {
500 if (FD_ISSET(j, fds)) {
502 sprintf(str, "%s%s [%u", sep,
510 sprintf(str, " %u", j);
511 cumlen += strlen(str);
512 if (cumlen < sizeof(outstr))
524 /* This contains no useful information on SunOS. */
528 if (umove(tcp, args[4], &tv) >= 0) {
531 tv32=(struct timeval32*)&tv;
532 sprintf(str, "%sleft {%u, %u}", sep,
533 tv32->tv_sec, tv32->tv_usec);
536 sprintf(str, "%sleft {%lu, %lu}", sep,
537 (long) tv.tv_sec, (long) tv.tv_usec);
539 if ((cumlen += strlen(str)) < sizeof(outstr))
557 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
561 return decode_select(tcp, args, 0);
569 long *args = tcp->u_arg;
570 return decode_select(tcp, args, 1);
574 static struct xlat epollctls[] = {
576 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
579 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
582 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
587 static struct xlat epollevents[] = {
589 { EPOLLIN, "EPOLLIN" },
592 { EPOLLPRI, "EPOLLPRI" },
595 { EPOLLOUT, "EPOLLOUT" },
598 { EPOLLRDNORM, "EPOLLRDNORM" },
601 { EPOLLRDBAND, "EPOLLRDBAND" },
604 { EPOLLWRNORM, "EPOLLWRNORM" },
607 { EPOLLWRBAND, "EPOLLWRBAND" },
610 { EPOLLMSG, "EPOLLMSG" },
613 { EPOLLERR, "EPOLLERR" },
616 { EPOLLHUP, "EPOLLHUP" },
619 { EPOLLONESHOT, "EPOLLONESHOT" },
622 { EPOLLET, "EPOLLET" },
628 sys_epoll_create(tcp)
632 tprintf("%ld", tcp->u_arg[0]);
636 #ifdef HAVE_SYS_EPOLL_H
638 print_epoll_event(ev)
639 struct epoll_event *ev;
642 if (printflags(epollevents, ev->events) == 0)
644 /* We cannot know what format the program uses, so print u32 and u64
645 which will cover every value. */
646 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
647 ev->data.u32, ev->data.u64);
656 tprintf("%ld, ", tcp->u_arg[0]);
657 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
658 tprintf(", %ld, ", tcp->u_arg[2]);
659 if (tcp->u_arg[3] == 0)
662 #ifdef HAVE_SYS_EPOLL_H
663 struct epoll_event ev;
664 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
665 print_epoll_event(&ev);
679 tprintf("%ld, ", tcp->u_arg[0]);
682 tprintf("%lx", tcp->u_arg[1]);
683 else if (tcp->u_rval == 0)
686 #ifdef HAVE_SYS_EPOLL_H
687 struct epoll_event evs[tcp->u_rval];
688 if (umove(tcp, tcp->u_arg[1], evs) == 0) {
691 for (i = 0; i < tcp->u_rval; ++i) {
694 print_epoll_event(&evs[i]);
702 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
712 long *args = tcp->u_arg;
713 return decode_select(tcp, args, 0);