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);
151 printfd(tcp, tcp->u_arg[0]);
153 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
154 switch (tcp->u_arg[1]) {
157 printflags(fdflags, tcp->u_arg[2], "FD_???");
159 case F_SETOWN: case F_DUPFD:
160 #ifdef F_DUPFD_CLOEXEC
161 case F_DUPFD_CLOEXEC:
163 tprintf(", %ld", tcp->u_arg[2]);
167 tprint_open_modes(tcp->u_arg[2]);
169 case F_SETLK: case F_SETLKW:
171 printflock(tcp, tcp->u_arg[2], 0);
174 case F_SETLK64: case F_SETLKW64:
176 printflock64(tcp, tcp->u_arg[2], 0);
178 #endif /* USE_PRINTFLOCK64 */
182 printflags(notifyflags, tcp->u_arg[2], "DN_???");
188 printxval(lockfcmds, tcp->u_arg[2], "F_???");
194 switch (tcp->u_arg[1]) {
196 #ifdef F_DUPFD_CLOEXEC
197 case F_DUPFD_CLOEXEC:
199 case F_SETFD: case F_SETFL:
200 case F_SETLK: case F_SETLKW:
201 case F_SETOWN: case F_GETOWN:
210 if (syserror(tcp) || tcp->u_rval == 0)
212 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
213 return RVAL_HEX|RVAL_STR;
217 tcp->auxstr = sprint_open_modes(tcp->u_rval);
218 return RVAL_HEX|RVAL_STR;
221 printflock(tcp, tcp->u_arg[2], 1);
226 printflock64(tcp, tcp->u_arg[2], 1);
233 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
234 return RVAL_HEX|RVAL_STR;
237 tprintf(", %#lx", tcp->u_arg[2]);
249 printfd(tcp, tcp->u_arg[0]);
251 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
260 printfd(tcp, tcp->u_arg[0]);
268 printfd(tcp, tcp->u_arg[0]);
274 do_dup2(struct tcb *tcp, int flags_arg)
277 printfd(tcp, tcp->u_arg[0]);
279 printfd(tcp, tcp->u_arg[1]);
280 if (flags_arg >= 0) {
282 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
290 return do_dup2(tcp, -1);
295 return do_dup2(tcp, 2);
299 SYS_FUNC(getdtablesize)
306 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
314 /* Kernel truncates arg[0] to int, we do the same. */
315 nfds = (int) args[0];
317 /* Kernel rejects negative nfds, so we don't parse it either. */
321 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
322 if (nfds > 1024*1024)
326 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
327 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
329 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
332 tprintf("%d", (int) args[0]);
334 if (verbose(tcp) && fdsize > 0)
335 fds = xmalloc(fdsize);
336 for (i = 0; i < 3; i++) {
343 tprintf(", %#lx", arg);
346 if (umoven(tcp, arg, fdsize, fds) < 0) {
351 for (j = 0, sep = "";; j++) {
352 j = next_set_bit(fds, j, nfds);
363 printtv_bitness(tcp, args[4], bitness, 0);
366 static char outstr[1024];
368 #define end_outstr (outstr + sizeof(outstr))
374 ready_fds = tcp->u_rval;
375 if (ready_fds == 0) {
376 tcp->auxstr = "Timeout";
380 fds = xmalloc(fdsize);
384 for (i = 0; i < 3 && ready_fds > 0; i++) {
388 if (!arg || umoven(tcp, arg, fdsize, fds) < 0)
391 j = next_set_bit(fds, j, nfds);
394 /* +2 chars needed at the end: ']',NUL */
395 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
397 outptr += sprintf(outptr, "%s%s [%u",
399 i == 0 ? "in" : i == 1 ? "out" : "except",
406 outptr += sprintf(outptr, " %u", j);
409 if (--ready_fds == 0)
412 if (outptr != outstr)
416 /* This contains no useful information on SunOS. */
418 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
419 outptr += sprintf(outptr, "%sleft ", sep);
420 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
424 tcp->auxstr = outstr;
435 if (umoven(tcp, tcp->u_arg[0], sizeof args, args) < 0) {
439 return decode_select(tcp, args, BITNESS_CURRENT);
445 long *args = tcp->u_arg;
446 return decode_select(tcp, args, BITNESS_32);
450 #include "xlat/epollctls.h"
451 #include "xlat/epollevents.h"
452 #include "xlat/epollflags.h"
454 /* Not aliased to printargs_ld: we want it to have a distinct address */
455 SYS_FUNC(epoll_create)
457 return printargs_ld(tcp);
460 SYS_FUNC(epoll_create1)
463 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
467 #ifdef HAVE_SYS_EPOLL_H
469 print_epoll_event(struct epoll_event *ev)
472 printflags(epollevents, ev->events, "EPOLL???");
473 /* We cannot know what format the program uses, so print u32 and u64
474 which will cover every value. */
475 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
476 ev->data.u32, ev->data.u64);
483 printfd(tcp, tcp->u_arg[0]);
485 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
487 printfd(tcp, tcp->u_arg[2]);
489 if (tcp->u_arg[3] == 0)
492 #ifdef HAVE_SYS_EPOLL_H
493 struct epoll_event ev;
496 (tcp->u_arg[1] != EPOLL_CTL_DEL) &&
498 umove(tcp, tcp->u_arg[3], &ev) == 0)
499 print_epoll_event(&ev);
502 tprintf("%lx", tcp->u_arg[3]);
509 epoll_wait_common(struct tcb *tcp)
512 printfd(tcp, tcp->u_arg[0]);
516 tprintf("%lx", tcp->u_arg[1]);
517 else if (tcp->u_rval == 0)
520 #ifdef HAVE_SYS_EPOLL_H
521 struct epoll_event ev, *start, *cur, *end;
525 start = (struct epoll_event *) tcp->u_arg[1];
526 end = start + tcp->u_rval;
527 for (cur = start; cur < end; ++cur) {
530 if (umove(tcp, (long) cur, &ev) == 0)
531 print_epoll_event(&ev);
540 tprintf(" %#lx", (long) start);
545 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
551 epoll_wait_common(tcp);
555 SYS_FUNC(epoll_pwait)
557 epoll_wait_common(tcp);
560 /* NB: kernel requires arg[5] == NSIG / 8 */
561 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
562 tprintf(", %lu", tcp->u_arg[5]);
569 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
574 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
581 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
582 if (current_wordsize == 4) {
587 r = umove(tcp, tcp->u_arg[5], &data32);
588 data.ptr = data32.ptr;
589 data.len = data32.len;
592 r = umove(tcp, tcp->u_arg[5], &data);
594 tprintf(", %#lx", tcp->u_arg[5]);
597 /* NB: kernel requires data.len == NSIG / 8 */
598 print_sigset_addr_len(tcp, data.ptr, data.len);
599 tprintf(", %lu}", data.len);
606 do_eventfd(struct tcb *tcp, int flags_arg)
609 tprintf("%lu", tcp->u_arg[0]);
610 if (flags_arg >= 0) {
612 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
620 return do_eventfd(tcp, -1);
625 return do_eventfd(tcp, 1);
628 SYS_FUNC(perf_event_open)
631 tprintf("%#lx, %d, %d, %d, ",
635 (int) tcp->u_arg[3]);
636 printflags(perf_event_open_flags, tcp->u_arg[4],