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.
34 #ifdef HAVE_SYS_EPOLL_H
35 # include <sys/epoll.h>
37 #ifdef HAVE_LINUX_PERF_EVENT_H
38 # include <linux/perf_event.h>
41 #include "xlat/fcntlcmds.h"
42 #include "xlat/fdflags.h"
43 #include "xlat/flockcmds.h"
44 #include "xlat/lockfcmds.h"
45 #include "xlat/notifyflags.h"
46 #include "xlat/perf_event_open_flags.h"
49 * Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined
50 * or not defined altogether.
52 #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
53 # define USE_PRINTFLOCK64 1
55 # define USE_PRINTFLOCK64 0
60 # ifndef HAVE_STRUCT_FLOCK64
62 short int l_type, l_whence;
63 int64_t l_start, l_len;
69 printflock64(struct tcb *tcp, long addr, int getlk)
73 if (umove(tcp, addr, &fl) < 0) {
78 printxval(lockfcmds, fl.l_type, "F_???");
80 printxval(whence_codes, fl.l_whence, "SEEK_???");
81 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
83 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
87 #endif /* USE_PRINTFLOCK64 */
90 printflock(struct tcb *tcp, long addr, int getlk)
95 #if SUPPORTED_PERSONALITIES > 1
97 # if SIZEOF_OFF_T > SIZEOF_LONG
98 current_personality > 0 &&
100 current_wordsize != sizeof(fl.l_start)) {
101 if (current_wordsize == 4) {
102 /* 32-bit x86 app on x86_64 and similar cases */
106 int32_t l_start; /* off_t */
107 int32_t l_len; /* off_t */
108 int32_t l_pid; /* pid_t */
110 r = umove(tcp, addr, &fl32);
112 fl.l_type = fl32.l_type;
113 fl.l_whence = fl32.l_whence;
114 fl.l_start = fl32.l_start;
115 fl.l_len = fl32.l_len;
116 fl.l_pid = fl32.l_pid;
119 /* let people know we have a problem here */
120 tprintf("<decode error: unsupported wordsize %d>",
127 r = umove(tcp, addr, &fl);
134 printxval(lockfcmds, fl.l_type, "F_???");
135 tprints(", whence=");
136 printxval(whence_codes, fl.l_whence, "SEEK_???");
137 #if SIZEOF_OFF_T > SIZEOF_LONG
138 tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len);
140 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
143 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
149 sys_fcntl(struct tcb *tcp)
152 printfd(tcp, tcp->u_arg[0]);
154 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
155 switch (tcp->u_arg[1]) {
158 printflags(fdflags, tcp->u_arg[2], "FD_???");
160 case F_SETOWN: case F_DUPFD:
161 #ifdef F_DUPFD_CLOEXEC
162 case F_DUPFD_CLOEXEC:
164 tprintf(", %ld", tcp->u_arg[2]);
168 tprint_open_modes(tcp->u_arg[2]);
170 case F_SETLK: case F_SETLKW:
172 printflock(tcp, tcp->u_arg[2], 0);
175 case F_SETLK64: case F_SETLKW64:
177 printflock64(tcp, tcp->u_arg[2], 0);
179 #endif /* USE_PRINTFLOCK64 */
183 printflags(notifyflags, tcp->u_arg[2], "DN_???");
189 printxval(lockfcmds, tcp->u_arg[2], "F_???");
195 switch (tcp->u_arg[1]) {
197 #ifdef F_DUPFD_CLOEXEC
198 case F_DUPFD_CLOEXEC:
200 case F_SETFD: case F_SETFL:
201 case F_SETLK: case F_SETLKW:
202 case F_SETOWN: case F_GETOWN:
211 if (syserror(tcp) || tcp->u_rval == 0)
213 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
214 return RVAL_HEX|RVAL_STR;
218 tcp->auxstr = sprint_open_modes(tcp->u_rval);
219 return RVAL_HEX|RVAL_STR;
222 printflock(tcp, tcp->u_arg[2], 1);
227 printflock64(tcp, tcp->u_arg[2], 1);
234 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
235 return RVAL_HEX|RVAL_STR;
238 tprintf(", %#lx", tcp->u_arg[2]);
248 sys_flock(struct tcb *tcp)
251 printfd(tcp, tcp->u_arg[0]);
253 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
260 sys_close(struct tcb *tcp)
263 printfd(tcp, tcp->u_arg[0]);
269 do_dup2(struct tcb *tcp, int flags_arg)
272 printfd(tcp, tcp->u_arg[0]);
274 printfd(tcp, tcp->u_arg[1]);
275 if (flags_arg >= 0) {
277 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
284 sys_dup2(struct tcb *tcp)
286 return do_dup2(tcp, -1);
290 sys_dup3(struct tcb *tcp)
292 return do_dup2(tcp, 2);
297 sys_getdtablesize(struct tcb *tcp)
304 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
312 /* Kernel truncates arg[0] to int, we do the same. */
313 nfds = (int) args[0];
315 /* Kernel rejects negative nfds, so we don't parse it either. */
320 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
321 if (nfds > 1024*1024)
325 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
326 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
328 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
331 tprintf("%d", (int) args[0]);
334 fds = malloc(fdsize);
338 for (i = 0; i < 3; i++) {
344 if (!verbose(tcp) || !fds) {
345 tprintf(", %#lx", arg);
348 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
353 for (j = 0, sep = "";; j++) {
354 j = next_set_bit(fds, j, nfds);
365 printtv_bitness(tcp, args[4], bitness, 0);
368 static char outstr[1024];
370 #define end_outstr (outstr + sizeof(outstr))
376 ready_fds = tcp->u_rval;
377 if (ready_fds == 0) {
378 tcp->auxstr = "Timeout";
382 fds = malloc(fdsize);
388 for (i = 0; i < 3 && ready_fds > 0; i++) {
392 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
395 j = next_set_bit(fds, j, nfds);
398 /* +2 chars needed at the end: ']',NUL */
399 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
401 outptr += sprintf(outptr, "%s%s [%u",
403 i == 0 ? "in" : i == 1 ? "out" : "except",
410 outptr += sprintf(outptr, " %u", j);
413 if (--ready_fds == 0)
416 if (outptr != outstr)
420 /* This contains no useful information on SunOS. */
422 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
423 outptr += sprintf(outptr, "%sleft ", sep);
424 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
428 tcp->auxstr = outstr;
436 sys_oldselect(struct tcb *tcp)
440 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
444 return decode_select(tcp, args, BITNESS_CURRENT);
449 sys_osf_select(struct tcb *tcp)
451 long *args = tcp->u_arg;
452 return decode_select(tcp, args, BITNESS_32);
456 #include "xlat/epollctls.h"
457 #include "xlat/epollevents.h"
458 #include "xlat/epollflags.h"
460 /* Not aliased to printargs_ld: we want it to have a distinct address */
462 sys_epoll_create(struct tcb *tcp)
464 return printargs_ld(tcp);
468 sys_epoll_create1(struct tcb *tcp)
471 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
475 #ifdef HAVE_SYS_EPOLL_H
477 print_epoll_event(struct epoll_event *ev)
480 printflags(epollevents, ev->events, "EPOLL???");
481 /* We cannot know what format the program uses, so print u32 and u64
482 which will cover every value. */
483 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
484 ev->data.u32, ev->data.u64);
489 sys_epoll_ctl(struct tcb *tcp)
492 printfd(tcp, tcp->u_arg[0]);
494 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
496 printfd(tcp, tcp->u_arg[2]);
498 if (tcp->u_arg[3] == 0)
501 #ifdef HAVE_SYS_EPOLL_H
502 struct epoll_event ev;
505 (tcp->u_arg[1] != EPOLL_CTL_DEL) &&
507 umove(tcp, tcp->u_arg[3], &ev) == 0)
508 print_epoll_event(&ev);
511 tprintf("%lx", tcp->u_arg[3]);
518 epoll_wait_common(struct tcb *tcp)
521 printfd(tcp, tcp->u_arg[0]);
525 tprintf("%lx", tcp->u_arg[1]);
526 else if (tcp->u_rval == 0)
529 #ifdef HAVE_SYS_EPOLL_H
530 struct epoll_event ev, *start, *cur, *end;
534 start = (struct epoll_event *) tcp->u_arg[1];
535 end = start + tcp->u_rval;
536 for (cur = start; cur < end; ++cur) {
539 if (umove(tcp, (long) cur, &ev) == 0)
540 print_epoll_event(&ev);
549 tprintf(" %#lx", (long) start);
554 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
559 sys_epoll_wait(struct tcb *tcp)
561 epoll_wait_common(tcp);
566 sys_epoll_pwait(struct tcb *tcp)
568 epoll_wait_common(tcp);
571 /* NB: kernel requires arg[5] == NSIG / 8 */
572 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
573 tprintf(", %lu", tcp->u_arg[5]);
579 sys_select(struct tcb *tcp)
581 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
585 sys_pselect6(struct tcb *tcp)
587 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
594 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
595 if (current_wordsize == 4) {
600 r = umove(tcp, tcp->u_arg[5], &data32);
601 data.ptr = data32.ptr;
602 data.len = data32.len;
605 r = umove(tcp, tcp->u_arg[5], &data);
607 tprintf(", %#lx", tcp->u_arg[5]);
610 /* NB: kernel requires data.len == NSIG / 8 */
611 print_sigset_addr_len(tcp, data.ptr, data.len);
612 tprintf(", %lu}", data.len);
619 do_eventfd(struct tcb *tcp, int flags_arg)
622 tprintf("%lu", tcp->u_arg[0]);
623 if (flags_arg >= 0) {
625 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
632 sys_eventfd(struct tcb *tcp)
634 return do_eventfd(tcp, -1);
638 sys_eventfd2(struct tcb *tcp)
640 return do_eventfd(tcp, 1);
644 sys_perf_event_open(struct tcb *tcp)
647 tprintf("%#lx, %d, %d, %d, ",
651 (int) tcp->u_arg[3]);
652 printflags(perf_event_open_flags, tcp->u_arg[4],