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_or_printaddr(tcp, addr, &fl))
76 printxval(lockfcmds, fl.l_type, "F_???");
78 printxval(whence_codes, fl.l_whence, "SEEK_???");
79 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
81 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
85 #endif /* USE_PRINTFLOCK64 */
88 printflock(struct tcb *tcp, long addr, int getlk)
92 #if SUPPORTED_PERSONALITIES > 1
94 # if SIZEOF_OFF_T > SIZEOF_LONG
95 current_personality != DEFAULT_PERSONALITY &&
97 current_wordsize != sizeof(fl.l_start)) {
98 if (current_wordsize == 4) {
99 /* 32-bit x86 app on x86_64 and similar cases */
103 int32_t l_start; /* off_t */
104 int32_t l_len; /* off_t */
105 int32_t l_pid; /* pid_t */
107 if (umove_or_printaddr(tcp, addr, &fl32))
109 fl.l_type = fl32.l_type;
110 fl.l_whence = fl32.l_whence;
111 fl.l_start = fl32.l_start;
112 fl.l_len = fl32.l_len;
113 fl.l_pid = fl32.l_pid;
115 /* let people know we have a problem here */
116 tprintf("<decode error: unsupported wordsize %d>",
122 if (umove_or_printaddr(tcp, addr, &fl))
125 printxval(lockfcmds, fl.l_type, "F_???");
126 tprints(", whence=");
127 printxval(whence_codes, fl.l_whence, "SEEK_???");
128 #if SIZEOF_OFF_T > SIZEOF_LONG
129 tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len);
131 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
134 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
142 printfd(tcp, tcp->u_arg[0]);
144 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
145 switch (tcp->u_arg[1]) {
148 printflags(fdflags, tcp->u_arg[2], "FD_???");
150 case F_SETOWN: case F_DUPFD:
151 #ifdef F_DUPFD_CLOEXEC
152 case F_DUPFD_CLOEXEC:
154 tprintf(", %ld", tcp->u_arg[2]);
158 tprint_open_modes(tcp->u_arg[2]);
160 case F_SETLK: case F_SETLKW:
162 printflock(tcp, tcp->u_arg[2], 0);
165 case F_SETLK64: case F_SETLKW64:
167 printflock64(tcp, tcp->u_arg[2], 0);
169 #endif /* USE_PRINTFLOCK64 */
173 printflags(notifyflags, tcp->u_arg[2], "DN_???");
179 printxval(lockfcmds, tcp->u_arg[2], "F_???");
185 switch (tcp->u_arg[1]) {
187 #ifdef F_DUPFD_CLOEXEC
188 case F_DUPFD_CLOEXEC:
190 case F_SETFD: case F_SETFL:
191 case F_SETLK: case F_SETLKW:
192 case F_SETOWN: case F_GETOWN:
201 if (syserror(tcp) || tcp->u_rval == 0)
203 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
204 return RVAL_HEX|RVAL_STR;
208 tcp->auxstr = sprint_open_modes(tcp->u_rval);
209 return RVAL_HEX|RVAL_STR;
212 printflock(tcp, tcp->u_arg[2], 1);
217 printflock64(tcp, tcp->u_arg[2], 1);
224 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
225 return RVAL_HEX|RVAL_STR;
228 tprintf(", %#lx", tcp->u_arg[2]);
240 printfd(tcp, tcp->u_arg[0]);
242 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
251 printfd(tcp, tcp->u_arg[0]);
259 printfd(tcp, tcp->u_arg[0]);
265 do_dup2(struct tcb *tcp, int flags_arg)
268 printfd(tcp, tcp->u_arg[0]);
270 printfd(tcp, tcp->u_arg[1]);
271 if (flags_arg >= 0) {
273 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
281 return do_dup2(tcp, -1);
286 return do_dup2(tcp, 2);
290 SYS_FUNC(getdtablesize)
297 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
305 /* Kernel truncates arg[0] to int, we do the same. */
306 nfds = (int) args[0];
308 /* Kernel rejects negative nfds, so we don't parse it either. */
312 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
313 if (nfds > 1024*1024)
317 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
318 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
320 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
323 tprintf("%d", (int) args[0]);
325 if (verbose(tcp) && fdsize > 0)
326 fds = malloc(fdsize);
327 for (i = 0; i < 3; i++) {
334 if (umoven_or_printaddr(tcp, arg, fdsize, fds))
337 for (j = 0, sep = "";; j++) {
338 j = next_set_bit(fds, j, nfds);
349 printtv_bitness(tcp, args[4], bitness, 0);
352 static char outstr[1024];
354 #define end_outstr (outstr + sizeof(outstr))
360 ready_fds = tcp->u_rval;
361 if (ready_fds == 0) {
362 tcp->auxstr = "Timeout";
366 fds = malloc(fdsize);
370 for (i = 0; i < 3 && ready_fds > 0; i++) {
374 if (!arg || !fds || umoven(tcp, arg, fdsize, fds) < 0)
377 j = next_set_bit(fds, j, nfds);
380 /* +2 chars needed at the end: ']',NUL */
381 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
383 outptr += sprintf(outptr, "%s%s [%u",
385 i == 0 ? "in" : i == 1 ? "out" : "except",
392 outptr += sprintf(outptr, " %u", j);
395 if (--ready_fds == 0)
398 if (outptr != outstr)
402 /* This contains no useful information on SunOS. */
404 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
405 outptr += sprintf(outptr, "%sleft ", sep);
406 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
410 tcp->auxstr = outstr;
421 if (umove(tcp, tcp->u_arg[0], &args) < 0) {
422 printaddr(tcp->u_arg[0]);
425 return decode_select(tcp, args, BITNESS_CURRENT);
431 return decode_select(tcp, tcp->u_arg, BITNESS_32);
435 #include "xlat/epollctls.h"
436 #include "xlat/epollevents.h"
437 #include "xlat/epollflags.h"
439 /* Not aliased to printargs_ld: we want it to have a distinct address */
440 SYS_FUNC(epoll_create)
442 return printargs_ld(tcp);
445 SYS_FUNC(epoll_create1)
448 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
452 #ifdef HAVE_SYS_EPOLL_H
454 print_epoll_event(struct epoll_event *ev)
457 printflags(epollevents, ev->events, "EPOLL???");
458 /* We cannot know what format the program uses, so print u32 and u64
459 which will cover every value. */
460 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
461 ev->data.u32, ev->data.u64);
468 struct epoll_event ev;
470 printfd(tcp, tcp->u_arg[0]);
472 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
474 printfd(tcp, tcp->u_arg[2]);
476 #ifdef HAVE_SYS_EPOLL_H
477 if (EPOLL_CTL_DEL == tcp->u_arg[1])
478 printaddr(tcp->u_arg[3]);
479 else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
480 print_epoll_event(&ev);
482 printaddr(tcp->u_arg[3]);
489 print_epoll_event_array(struct tcb *tcp, const long addr, const long len)
491 #ifdef HAVE_SYS_EPOLL_H
492 struct epoll_event ev, *start, *cur, *end;
499 if (umove_or_printaddr(tcp, addr, &ev))
503 print_epoll_event(&ev);
505 start = (struct epoll_event *) addr;
507 for (cur = start + 1; cur < end; ++cur) {
509 if (umove_or_printaddr(tcp, (long) cur, &ev))
511 print_epoll_event(&ev);
520 epoll_wait_common(struct tcb *tcp)
523 printfd(tcp, tcp->u_arg[0]);
526 print_epoll_event_array(tcp, tcp->u_arg[1], tcp->u_rval);
527 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
533 epoll_wait_common(tcp);
537 SYS_FUNC(epoll_pwait)
539 epoll_wait_common(tcp);
542 /* NB: kernel requires arg[5] == NSIG / 8 */
543 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
544 tprintf(", %lu", tcp->u_arg[5]);
551 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
556 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
565 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
566 if (current_wordsize == 4) {
571 r = umove_or_printaddr(tcp, tcp->u_arg[5], &data32);
572 data.ptr = data32.ptr;
573 data.len = data32.len;
576 r = umove_or_printaddr(tcp, tcp->u_arg[5], &data);
579 /* NB: kernel requires data.len == NSIG / 8 */
580 print_sigset_addr_len(tcp, data.ptr, data.len);
581 tprintf(", %lu}", data.len);
588 do_eventfd(struct tcb *tcp, int flags_arg)
591 tprintf("%lu", tcp->u_arg[0]);
592 if (flags_arg >= 0) {
594 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
602 return do_eventfd(tcp, -1);
607 return do_eventfd(tcp, 1);
610 SYS_FUNC(perf_event_open)
613 printaddr(tcp->u_arg[0]);
614 tprintf(", %d, %d, %d, ",
617 (int) tcp->u_arg[3]);
618 printflags(perf_event_open_flags, tcp->u_arg[4],