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>
38 #include "xlat/fcntlcmds.h"
39 #include "xlat/fdflags.h"
40 #include "xlat/flockcmds.h"
41 #include "xlat/lockfcmds.h"
42 #include "xlat/notifyflags.h"
45 * Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined
46 * or not defined altogether.
48 #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
49 # define USE_PRINTFLOCK64 1
51 # define USE_PRINTFLOCK64 0
56 # ifndef HAVE_STRUCT_FLOCK64
58 short int l_type, l_whence;
59 int64_t l_start, l_len;
65 printflock64(struct tcb *tcp, long addr, int getlk)
69 if (umove_or_printaddr(tcp, addr, &fl))
72 printxval(lockfcmds, fl.l_type, "F_???");
74 printxval(whence_codes, fl.l_whence, "SEEK_???");
75 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
77 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
81 #endif /* USE_PRINTFLOCK64 */
84 printflock(struct tcb *tcp, long addr, int getlk)
88 #if SUPPORTED_PERSONALITIES > 1
90 # if SIZEOF_OFF_T > SIZEOF_LONG
91 current_personality != DEFAULT_PERSONALITY &&
93 current_wordsize != sizeof(fl.l_start)) {
94 if (current_wordsize == 4) {
95 /* 32-bit x86 app on x86_64 and similar cases */
99 int32_t l_start; /* off_t */
100 int32_t l_len; /* off_t */
101 int32_t l_pid; /* pid_t */
103 if (umove_or_printaddr(tcp, addr, &fl32))
105 fl.l_type = fl32.l_type;
106 fl.l_whence = fl32.l_whence;
107 fl.l_start = fl32.l_start;
108 fl.l_len = fl32.l_len;
109 fl.l_pid = fl32.l_pid;
111 /* let people know we have a problem here */
112 tprintf("<decode error: unsupported wordsize %d>",
118 if (umove_or_printaddr(tcp, addr, &fl))
121 printxval(lockfcmds, fl.l_type, "F_???");
122 tprints(", whence=");
123 printxval(whence_codes, fl.l_whence, "SEEK_???");
124 #if SIZEOF_OFF_T > SIZEOF_LONG
125 tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len);
127 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
130 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
138 printfd(tcp, tcp->u_arg[0]);
140 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
141 switch (tcp->u_arg[1]) {
144 printflags(fdflags, tcp->u_arg[2], "FD_???");
146 case F_SETOWN: case F_DUPFD:
147 #ifdef F_DUPFD_CLOEXEC
148 case F_DUPFD_CLOEXEC:
150 tprintf(", %ld", tcp->u_arg[2]);
154 tprint_open_modes(tcp->u_arg[2]);
156 case F_SETLK: case F_SETLKW:
158 printflock(tcp, tcp->u_arg[2], 0);
161 case F_SETLK64: case F_SETLKW64:
163 printflock64(tcp, tcp->u_arg[2], 0);
165 #endif /* USE_PRINTFLOCK64 */
169 printflags(notifyflags, tcp->u_arg[2], "DN_???");
175 printxval(lockfcmds, tcp->u_arg[2], "F_???");
180 switch (tcp->u_arg[1]) {
182 #ifdef F_DUPFD_CLOEXEC
183 case F_DUPFD_CLOEXEC:
185 case F_SETFD: case F_SETFL:
186 case F_SETLK: case F_SETLKW:
187 case F_SETOWN: case F_GETOWN:
196 if (syserror(tcp) || tcp->u_rval == 0)
198 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
199 return RVAL_HEX|RVAL_STR;
203 tcp->auxstr = sprint_open_modes(tcp->u_rval);
204 return RVAL_HEX|RVAL_STR;
207 printflock(tcp, tcp->u_arg[2], 1);
212 printflock64(tcp, tcp->u_arg[2], 1);
219 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
220 return RVAL_HEX|RVAL_STR;
223 tprintf(", %#lx", tcp->u_arg[2]);
234 printfd(tcp, tcp->u_arg[0]);
236 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
244 printfd(tcp, tcp->u_arg[0]);
251 printfd(tcp, tcp->u_arg[0]);
253 return RVAL_DECODED | RVAL_FD;
257 do_dup2(struct tcb *tcp, int flags_arg)
259 printfd(tcp, tcp->u_arg[0]);
261 printfd(tcp, tcp->u_arg[1]);
262 if (flags_arg >= 0) {
264 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
267 return RVAL_DECODED | RVAL_FD;
272 return do_dup2(tcp, -1);
277 return do_dup2(tcp, 2);
281 SYS_FUNC(getdtablesize)
288 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
296 /* Kernel truncates arg[0] to int, we do the same. */
297 nfds = (int) args[0];
299 /* Kernel rejects negative nfds, so we don't parse it either. */
303 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
304 if (nfds > 1024*1024)
308 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
309 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
311 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
314 tprintf("%d", (int) args[0]);
316 if (verbose(tcp) && fdsize > 0)
317 fds = malloc(fdsize);
318 for (i = 0; i < 3; i++) {
325 if (umoven_or_printaddr(tcp, arg, fdsize, fds))
328 for (j = 0, sep = "";; j++) {
329 j = next_set_bit(fds, j, nfds);
340 printtv_bitness(tcp, args[4], bitness, 0);
342 static char outstr[1024];
344 #define end_outstr (outstr + sizeof(outstr))
350 ready_fds = tcp->u_rval;
351 if (ready_fds == 0) {
352 tcp->auxstr = "Timeout";
356 fds = malloc(fdsize);
360 for (i = 0; i < 3 && ready_fds > 0; i++) {
364 if (!arg || !fds || umoven(tcp, arg, fdsize, fds) < 0)
367 j = next_set_bit(fds, j, nfds);
370 /* +2 chars needed at the end: ']',NUL */
371 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
373 outptr += sprintf(outptr, "%s%s [%u",
375 i == 0 ? "in" : i == 1 ? "out" : "except",
382 outptr += sprintf(outptr, " %u", j);
385 if (--ready_fds == 0)
388 if (outptr != outstr)
392 /* This contains no useful information on SunOS. */
394 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
395 outptr += sprintf(outptr, "%sleft ", sep);
396 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
400 tcp->auxstr = outstr;
410 #undef oldselect_args
412 # define oldselect_args long_args
414 unsigned int oldselect_args[5];
418 if (umove(tcp, tcp->u_arg[0], &oldselect_args) < 0) {
419 printaddr(tcp->u_arg[0]);
422 #ifndef oldselect_args
423 for (i = 0; i < 5; i++) {
424 long_args[i] = oldselect_args[i];
427 return decode_select(tcp, long_args, BITNESS_CURRENT);
428 #undef oldselect_args
434 return decode_select(tcp, tcp->u_arg, BITNESS_32);
438 #include "xlat/epollctls.h"
439 #include "xlat/epollevents.h"
440 #include "xlat/epollflags.h"
442 SYS_FUNC(epoll_create1)
444 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
449 #ifdef HAVE_SYS_EPOLL_H
451 print_epoll_event(struct epoll_event *ev)
454 printflags(epollevents, ev->events, "EPOLL???");
455 /* We cannot know what format the program uses, so print u32 and u64
456 which will cover every value. */
457 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
458 ev->data.u32, ev->data.u64);
464 struct epoll_event ev;
466 printfd(tcp, tcp->u_arg[0]);
468 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
470 printfd(tcp, tcp->u_arg[2]);
472 #ifdef HAVE_SYS_EPOLL_H
473 if (EPOLL_CTL_DEL == tcp->u_arg[1])
474 printaddr(tcp->u_arg[3]);
475 else if (!umove_or_printaddr(tcp, tcp->u_arg[3], &ev))
476 print_epoll_event(&ev);
478 printaddr(tcp->u_arg[3]);
485 print_epoll_event_array(struct tcb *tcp, const long addr, const long len)
487 #ifdef HAVE_SYS_EPOLL_H
488 struct epoll_event ev, *start, *cur, *end;
495 if (umove_or_printaddr(tcp, addr, &ev))
499 print_epoll_event(&ev);
501 start = (struct epoll_event *) addr;
503 for (cur = start + 1; cur < end; ++cur) {
505 if (umove_or_printaddr(tcp, (long) cur, &ev))
507 print_epoll_event(&ev);
516 epoll_wait_common(struct tcb *tcp)
519 printfd(tcp, tcp->u_arg[0]);
522 print_epoll_event_array(tcp, tcp->u_arg[1], tcp->u_rval);
523 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
529 epoll_wait_common(tcp);
533 SYS_FUNC(epoll_pwait)
535 epoll_wait_common(tcp);
538 /* NB: kernel requires arg[5] == NSIG / 8 */
539 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
540 tprintf(", %lu", tcp->u_arg[5]);
547 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
552 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
561 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
562 if (current_wordsize == 4) {
567 r = umove_or_printaddr(tcp, tcp->u_arg[5], &data32);
568 data.ptr = data32.ptr;
569 data.len = data32.len;
572 r = umove_or_printaddr(tcp, tcp->u_arg[5], &data);
575 /* NB: kernel requires data.len == NSIG / 8 */
576 print_sigset_addr_len(tcp, data.ptr, data.len);
577 tprintf(", %lu}", data.len);
584 do_eventfd(struct tcb *tcp, int flags_arg)
586 tprintf("%lu", tcp->u_arg[0]);
587 if (flags_arg >= 0) {
589 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
597 return do_eventfd(tcp, -1);
602 return do_eventfd(tcp, 1);