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 sys_dup(struct tcb *tcp)
272 printfd(tcp, tcp->u_arg[0]);
278 do_dup2(struct tcb *tcp, int flags_arg)
281 printfd(tcp, tcp->u_arg[0]);
283 printfd(tcp, tcp->u_arg[1]);
284 if (flags_arg >= 0) {
286 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
293 sys_dup2(struct tcb *tcp)
295 return do_dup2(tcp, -1);
299 sys_dup3(struct tcb *tcp)
301 return do_dup2(tcp, 2);
306 sys_getdtablesize(struct tcb *tcp)
313 decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
321 /* Kernel truncates arg[0] to int, we do the same. */
322 nfds = (int) args[0];
324 /* Kernel rejects negative nfds, so we don't parse it either. */
328 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
329 if (nfds > 1024*1024)
333 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
334 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
336 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
339 tprintf("%d", (int) args[0]);
341 if (verbose(tcp) && fdsize > 0) {
342 fds = malloc(fdsize);
346 for (i = 0; i < 3; i++) {
353 tprintf(", %#lx", arg);
356 if (umoven(tcp, arg, fdsize, fds) < 0) {
361 for (j = 0, sep = "";; j++) {
362 j = next_set_bit(fds, j, nfds);
373 printtv_bitness(tcp, args[4], bitness, 0);
376 static char outstr[1024];
378 #define end_outstr (outstr + sizeof(outstr))
384 ready_fds = tcp->u_rval;
385 if (ready_fds == 0) {
386 tcp->auxstr = "Timeout";
390 fds = malloc(fdsize);
396 for (i = 0; i < 3 && ready_fds > 0; i++) {
400 if (!arg || umoven(tcp, arg, fdsize, fds) < 0)
403 j = next_set_bit(fds, j, nfds);
406 /* +2 chars needed at the end: ']',NUL */
407 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
409 outptr += sprintf(outptr, "%s%s [%u",
411 i == 0 ? "in" : i == 1 ? "out" : "except",
418 outptr += sprintf(outptr, " %u", j);
421 if (--ready_fds == 0)
424 if (outptr != outstr)
428 /* This contains no useful information on SunOS. */
430 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
431 outptr += sprintf(outptr, "%sleft ", sep);
432 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
436 tcp->auxstr = outstr;
444 sys_oldselect(struct tcb *tcp)
448 if (umoven(tcp, tcp->u_arg[0], sizeof args, args) < 0) {
452 return decode_select(tcp, args, BITNESS_CURRENT);
457 sys_osf_select(struct tcb *tcp)
459 long *args = tcp->u_arg;
460 return decode_select(tcp, args, BITNESS_32);
464 #include "xlat/epollctls.h"
465 #include "xlat/epollevents.h"
466 #include "xlat/epollflags.h"
468 /* Not aliased to printargs_ld: we want it to have a distinct address */
470 sys_epoll_create(struct tcb *tcp)
472 return printargs_ld(tcp);
476 sys_epoll_create1(struct tcb *tcp)
479 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
483 #ifdef HAVE_SYS_EPOLL_H
485 print_epoll_event(struct epoll_event *ev)
488 printflags(epollevents, ev->events, "EPOLL???");
489 /* We cannot know what format the program uses, so print u32 and u64
490 which will cover every value. */
491 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
492 ev->data.u32, ev->data.u64);
497 sys_epoll_ctl(struct tcb *tcp)
500 printfd(tcp, tcp->u_arg[0]);
502 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
504 printfd(tcp, tcp->u_arg[2]);
506 if (tcp->u_arg[3] == 0)
509 #ifdef HAVE_SYS_EPOLL_H
510 struct epoll_event ev;
513 (tcp->u_arg[1] != EPOLL_CTL_DEL) &&
515 umove(tcp, tcp->u_arg[3], &ev) == 0)
516 print_epoll_event(&ev);
519 tprintf("%lx", tcp->u_arg[3]);
526 epoll_wait_common(struct tcb *tcp)
529 printfd(tcp, tcp->u_arg[0]);
533 tprintf("%lx", tcp->u_arg[1]);
534 else if (tcp->u_rval == 0)
537 #ifdef HAVE_SYS_EPOLL_H
538 struct epoll_event ev, *start, *cur, *end;
542 start = (struct epoll_event *) tcp->u_arg[1];
543 end = start + tcp->u_rval;
544 for (cur = start; cur < end; ++cur) {
547 if (umove(tcp, (long) cur, &ev) == 0)
548 print_epoll_event(&ev);
557 tprintf(" %#lx", (long) start);
562 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
567 sys_epoll_wait(struct tcb *tcp)
569 epoll_wait_common(tcp);
574 sys_epoll_pwait(struct tcb *tcp)
576 epoll_wait_common(tcp);
579 /* NB: kernel requires arg[5] == NSIG / 8 */
580 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
581 tprintf(", %lu", tcp->u_arg[5]);
587 sys_select(struct tcb *tcp)
589 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
593 sys_pselect6(struct tcb *tcp)
595 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
602 #if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
603 if (current_wordsize == 4) {
608 r = umove(tcp, tcp->u_arg[5], &data32);
609 data.ptr = data32.ptr;
610 data.len = data32.len;
613 r = umove(tcp, tcp->u_arg[5], &data);
615 tprintf(", %#lx", tcp->u_arg[5]);
618 /* NB: kernel requires data.len == NSIG / 8 */
619 print_sigset_addr_len(tcp, data.ptr, data.len);
620 tprintf(", %lu}", data.len);
627 do_eventfd(struct tcb *tcp, int flags_arg)
630 tprintf("%lu", tcp->u_arg[0]);
631 if (flags_arg >= 0) {
633 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
640 sys_eventfd(struct tcb *tcp)
642 return do_eventfd(tcp, -1);
646 sys_eventfd2(struct tcb *tcp)
648 return do_eventfd(tcp, 1);
652 sys_perf_event_open(struct tcb *tcp)
655 tprintf("%#lx, %d, %d, %d, ",
659 (int) tcp->u_arg[3]);
660 printflags(perf_event_open_flags, tcp->u_arg[4],