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 * low bits of the open(2) flags define access mode,
247 * other bits are real flags.
250 sprint_open_modes(mode_t flags)
252 extern const struct xlat open_access_modes[];
253 extern const struct xlat open_mode_flags[];
254 static char outstr[1024];
255 const char *str = xlookup(open_access_modes, flags & 3);
256 const char *sep = "";
257 const struct xlat *x;
259 strcpy(outstr, "flags ");
269 for (x = open_mode_flags; x->str; x++)
271 if ((flags & x->val) == x->val)
273 sprintf(outstr + strlen(outstr),
274 "%s%s", sep, x->str);
280 sprintf(outstr + strlen(outstr), "%s%#x", sep, flags);
285 sys_fcntl(struct tcb *tcp)
288 tprintf("%ld, ", tcp->u_arg[0]);
289 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
290 switch (tcp->u_arg[1]) {
293 printflags(fdflags, tcp->u_arg[2], "FD_???");
295 case F_SETOWN: case F_DUPFD:
296 tprintf(", %ld", tcp->u_arg[2]);
300 tprint_open_modes(tcp, tcp->u_arg[2]);
302 case F_SETLK: case F_SETLKW:
307 printflock(tcp, tcp->u_arg[2], 0);
313 /* Linux glibc defines SETLK64 as SETLK,
314 even though the kernel has different values - as does Solaris. */
315 #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
318 #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
322 printflock64(tcp, tcp->u_arg[2], 0);
328 switch (tcp->u_arg[1]) {
330 case F_SETFD: case F_SETFL:
331 case F_SETLK: case F_SETLKW:
332 case F_SETOWN: case F_GETOWN:
335 if (tcp->u_rval == 0)
338 sprintflags("flags ", fdflags, tcp->u_rval);
339 return RVAL_HEX|RVAL_STR;
341 tcp->auxstr = sprint_open_modes(tcp->u_rval);
342 return RVAL_HEX|RVAL_STR;
345 printflock(tcp, tcp->u_arg[2], 1);
348 #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
352 printflock64(tcp, tcp->u_arg[2], 1);
356 tprintf(", %#lx", tcp->u_arg[2]);
370 tprintf("%ld, ", tcp->u_arg[0]);
371 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
382 tprintf("%ld", tcp->u_arg[0]);
392 tprintf("%ld", tcp->u_arg[0]);
402 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
407 #if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
409 sys_getdtablesize(tcp)
414 #endif /* ALPHA || FREEBSD || SUNOS4 */
417 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
420 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
423 static char outstr[1024];
428 fds = (fd_set *) malloc(fdsize);
430 fprintf(stderr, "out of memory\n");
433 for (i = 0; i < 3; i++) {
439 if (fds == NULL || !verbose(tcp)) {
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);
458 printtv_bitness(tcp, args[4], bitness, 0);
462 unsigned int cumlen = 0;
468 if ((nfds = tcp->u_rval) == 0) {
469 tcp->auxstr = "Timeout";
473 fds = (fd_set *) malloc(fdsize);
475 fprintf(stderr, "out of memory\n");
478 for (i = 0; i < 3; i++) {
482 tcp->auxstr = outstr;
484 if (fds == NULL || !arg ||
485 umoven(tcp, arg, fdsize, (char *) fds) < 0)
487 for (j = 0; j < args[0]; j++) {
488 if (FD_ISSET(j, fds)) {
490 sprintf(str, "%s%s [%u", sep,
498 sprintf(str, " %u", j);
499 cumlen += strlen(str);
500 if (cumlen < sizeof(outstr))
512 /* This contains no useful information on SunOS. */
516 sprintf(str, "%sleft ", sep);
517 sprinttv(tcp, args[4], bitness, str + strlen(str));
518 if ((cumlen += strlen(str)) < sizeof(outstr))
535 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
539 return decode_select(tcp, args, BITNESS_CURRENT);
547 long *args = tcp->u_arg;
548 return decode_select(tcp, args, BITNESS_32);
552 static struct xlat epollctls[] = {
554 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
557 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
560 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
565 static struct xlat epollevents[] = {
567 { EPOLLIN, "EPOLLIN" },
570 { EPOLLPRI, "EPOLLPRI" },
573 { EPOLLOUT, "EPOLLOUT" },
576 { EPOLLRDNORM, "EPOLLRDNORM" },
579 { EPOLLRDBAND, "EPOLLRDBAND" },
582 { EPOLLWRNORM, "EPOLLWRNORM" },
585 { EPOLLWRBAND, "EPOLLWRBAND" },
588 { EPOLLMSG, "EPOLLMSG" },
591 { EPOLLERR, "EPOLLERR" },
594 { EPOLLHUP, "EPOLLHUP" },
597 { EPOLLONESHOT, "EPOLLONESHOT" },
600 { EPOLLET, "EPOLLET" },
606 sys_epoll_create(tcp)
610 tprintf("%ld", tcp->u_arg[0]);
614 #ifdef HAVE_SYS_EPOLL_H
616 print_epoll_event(ev)
617 struct epoll_event *ev;
620 printflags(epollevents, ev->events, "EPOLL???");
621 /* We cannot know what format the program uses, so print u32 and u64
622 which will cover every value. */
623 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
624 ev->data.u32, ev->data.u64);
633 tprintf("%ld, ", tcp->u_arg[0]);
634 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
635 tprintf(", %ld, ", tcp->u_arg[2]);
636 if (tcp->u_arg[3] == 0)
639 #ifdef HAVE_SYS_EPOLL_H
640 struct epoll_event ev;
641 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
642 print_epoll_event(&ev);
652 epoll_wait_common(tcp)
656 tprintf("%ld, ", tcp->u_arg[0]);
659 tprintf("%lx", tcp->u_arg[1]);
660 else if (tcp->u_rval == 0)
663 #ifdef HAVE_SYS_EPOLL_H
664 struct epoll_event ev, *start, *cur, *end;
668 start = (struct epoll_event *) tcp->u_arg[1];
669 end = start + tcp->u_rval;
670 for (cur = start; cur < end; ++cur) {
673 if (umove(tcp, (long) cur, &ev) == 0)
674 print_epoll_event(&ev);
683 tprintf(" %#lx", (long) start);
688 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
696 epoll_wait_common(tcp);
704 epoll_wait_common(tcp);
706 print_sigset(tcp, tcp->u_arg[4], 0);
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(struct tcb * tcp)
822 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
825 if (tcp->u_rval == 0) {
829 struct io_event *events = (void *)tcp->u_arg[3];
830 long i, nr = tcp->u_rval;
832 for (i = 0; i < nr; i++, events++) {
833 struct io_event event;
840 if (umove(tcp, (unsigned long)events, &event) != 0) {
844 tprintf("{%p, %p, %ld, %ld}", event.data,
845 event.obj, event.res, event.res2);
853 print_timespec(tcp, tcp->u_arg[4]);
863 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
868 sys_pselect6(struct tcb *tcp)
870 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
876 if (umove(tcp, tcp->u_arg[5], &data) < 0)
877 tprintf(", %#lx", tcp->u_arg[5]);
880 if (data.len < sizeof(sigset_t))
881 tprintf("%#lx", (long)data.ss);
883 print_sigset(tcp, (long)data.ss, 0);
884 tprintf(", %lu}", data.len);
895 tprintf("%lu", tcp->u_arg[0]);