blob: cd6259a173fc12a870980c95ed502f3578f92e5b [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
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>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
18 *
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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <fcntl.h>
36#include <sys/file.h>
Roland McGrath93817bf2004-10-06 22:23:31 +000037#ifdef LINUX
38#include <inttypes.h>
Roland McGrath63d6e542004-10-20 02:17:41 +000039#endif
40#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +000041#include <sys/epoll.h>
42#endif
Roland McGrath37b9f842005-05-09 08:02:00 +000043#ifdef HAVE_LIBAIO_H
44#include <libaio.h>
45#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046
John Hughes70623be2001-03-08 13:59:00 +000047#if HAVE_LONG_LONG_OFF_T
48/*
49 * Hacks for systems that have a long long off_t
50 */
John Hughesb8c9f772001-03-07 16:53:07 +000051#define flock64 flock /* Horrid hack */
52#define printflock printflock64 /* Horrider hack */
53#endif
54
55
Roland McGrathd9f816f2004-09-04 03:39:20 +000056static const struct xlat fcntlcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057 { F_DUPFD, "F_DUPFD" },
58 { F_GETFD, "F_GETFD" },
59 { F_SETFD, "F_SETFD" },
60 { F_GETFL, "F_GETFL" },
61 { F_SETFL, "F_SETFL" },
62 { F_GETLK, "F_GETLK" },
63 { F_SETLK, "F_SETLK" },
64 { F_SETLKW, "F_SETLKW" },
65 { F_GETOWN, "F_GETOWN" },
66 { F_SETOWN, "F_SETOWN" },
67#ifdef F_RSETLK
68 { F_RSETLK, "F_RSETLK" },
69#endif
70#ifdef F_RSETLKW
71 { F_RSETLKW, "F_RSETLKW" },
72#endif
73#ifdef F_RGETLK
74 { F_RGETLK, "F_RGETLK" },
75#endif
76#ifdef F_CNVT
77 { F_CNVT, "F_CNVT" },
78#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000079#ifdef F_SETSIG
80 { F_SETSIG, "F_SETSIG" },
81#endif
82#ifdef F_GETSIG
83 { F_GETSIG, "F_GETSIG" },
84#endif
John Hughesbdf48f52001-03-06 15:08:09 +000085#ifdef F_CHKFL
86 { F_CHKFL, "F_CHKFL" },
87#endif
88#ifdef F_DUP2FD
89 { F_DUP2FD, "F_DUP2FD" },
90#endif
91#ifdef F_ALLOCSP
92 { F_ALLOCSP, "F_ALLOCSP" },
93#endif
94#ifdef F_ISSTREAM
95 { F_ISSTREAM, "F_ISSTREAM" },
96#endif
97#ifdef F_PRIV
98 { F_PRIV, "F_PRIV" },
99#endif
100#ifdef F_NPRIV
101 { F_NPRIV, "F_NPRIV" },
102#endif
103#ifdef F_QUOTACL
104 { F_QUOTACL, "F_QUOTACL" },
105#endif
106#ifdef F_BLOCKS
107 { F_BLOCKS, "F_BLOCKS" },
108#endif
109#ifdef F_BLKSIZE
110 { F_BLKSIZE, "F_BLKSIZE" },
111#endif
112#ifdef F_GETOWN
113 { F_GETOWN, "F_GETOWN" },
114#endif
115#ifdef F_SETOWN
116 { F_SETOWN, "F_SETOWN" },
117#endif
118#ifdef F_REVOKE
119 { F_REVOKE, "F_REVOKE" },
120#endif
121#ifdef F_SETLK
122 { F_SETLK, "F_SETLK" },
123#endif
124#ifdef F_SETLKW
125 { F_SETLKW, "F_SETLKW" },
126#endif
127#ifdef F_FREESP
128 { F_FREESP, "F_FREESP" },
129#endif
130#ifdef F_GETLK
131 { F_GETLK, "F_GETLK" },
132#endif
133#ifdef F_SETLK64
134 { F_SETLK64, "F_SETLK64" },
135#endif
136#ifdef F_SETLKW64
137 { F_SETLKW64, "F_SETLKW64" },
138#endif
139#ifdef F_FREESP64
140 { F_FREESP64, "F_FREESP64" },
141#endif
142#ifdef F_GETLK64
143 { F_GETLK64, "F_GETLK64" },
144#endif
145#ifdef F_SHARE
146 { F_SHARE, "F_SHARE" },
147#endif
148#ifdef F_UNSHARE
149 { F_UNSHARE, "F_UNSHARE" },
150#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151 { 0, NULL },
152};
153
Roland McGrathd9f816f2004-09-04 03:39:20 +0000154static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#ifdef FD_CLOEXEC
156 { FD_CLOEXEC, "FD_CLOEXEC" },
157#endif
158 { 0, NULL },
159};
160
161#ifdef LOCK_SH
162
Roland McGrathd9f816f2004-09-04 03:39:20 +0000163static const struct xlat flockcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164 { LOCK_SH, "LOCK_SH" },
165 { LOCK_EX, "LOCK_EX" },
166 { LOCK_NB, "LOCK_NB" },
167 { LOCK_UN, "LOCK_UN" },
168 { 0, NULL },
169};
170
171#endif /* LOCK_SH */
172
Roland McGrathd9f816f2004-09-04 03:39:20 +0000173static const struct xlat lockfcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174 { F_RDLCK, "F_RDLCK" },
175 { F_WRLCK, "F_WRLCK" },
176 { F_UNLCK, "F_UNLCK" },
177#ifdef F_EXLCK
178 { F_EXLCK, "F_EXLCK" },
179#endif
180#ifdef F_SHLCK
181 { F_SHLCK, "F_SHLCK" },
182#endif
183 { 0, NULL },
184};
185
Roland McGrathd9f816f2004-09-04 03:39:20 +0000186static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187 { SEEK_SET, "SEEK_SET" },
188 { SEEK_CUR, "SEEK_CUR" },
189 { SEEK_END, "SEEK_END" },
190 { 0, NULL },
191};
192
John Hughes70623be2001-03-08 13:59:00 +0000193#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194/* fcntl/lockf */
195static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000196printflock(struct tcb *tcp, long addr, int getlk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197{
198 struct flock fl;
199
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000200 if (personality_wordsize[current_personality] == sizeof(fl.l_start)) {
201 if (umove(tcp, addr, &fl) < 0) {
202 tprintf("{...}");
203 return;
204 }
205 } else if (personality_wordsize[current_personality] == 4) {
206 /* 32-bit x86 app on x86_64 and similar cases */
207 struct {
208 short int l_type;
209 short int l_whence;
210 int32_t l_start; /* off_t */
211 int32_t l_len; /* off_t */
212 int32_t l_pid; /* pid_t */
213 } fl32;
214 if (umove(tcp, addr, &fl32) < 0) {
215 tprintf("{...}");
216 return;
217 }
218 fl.l_type = fl32.l_type;
219 fl.l_whence = fl32.l_whence;
220 fl.l_start = fl32.l_start;
221 fl.l_len = fl32.l_len;
222 fl.l_pid = fl32.l_pid;
223 } else {
224 /* let people know we have a problem here */
225 tprintf("{ <decode error: unsupported wordsize %d> }",
226 personality_wordsize[current_personality]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000227 return;
228 }
229 tprintf("{type=");
230 printxval(lockfcmds, fl.l_type, "F_???");
231 tprintf(", whence=");
232 printxval(whence, fl.l_whence, "SEEK_???");
233 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
234 if (getlk)
235 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
236 else
237 tprintf("}");
238}
John Hughesb8c9f772001-03-07 16:53:07 +0000239#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000240
John Hughes70623be2001-03-08 13:59:00 +0000241#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000242/* fcntl/lockf */
243static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000244printflock64(struct tcb *tcp, long addr, int getlk)
John Hughesbdf48f52001-03-06 15:08:09 +0000245{
246 struct flock64 fl;
247
248 if (umove(tcp, addr, &fl) < 0) {
249 tprintf("{...}");
250 return;
251 }
252 tprintf("{type=");
253 printxval(lockfcmds, fl.l_type, "F_???");
254 tprintf(", whence=");
255 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000256 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000257 if (getlk)
258 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
259 else
260 tprintf("}");
261}
262#endif
263
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000264/*
265 * low bits of the open(2) flags define access mode,
266 * other bits are real flags.
267 */
268static const char *
269sprint_open_modes(mode_t flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270{
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000271 static char outstr[1024];
272 const char *str = xlookup(open_access_modes, flags & 3);
273 const char *sep = "";
274 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000276 strcpy(outstr, "flags ");
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000277 if (str) {
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000278 strcat(outstr, str);
279 flags &= ~3;
280 if (!flags)
281 return outstr;
282 strcat(outstr, "|");
283 }
284
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000285 for (x = open_mode_flags; x->str; x++) {
286 if ((flags & x->val) == x->val) {
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000287 sprintf(outstr + strlen(outstr),
288 "%s%s", sep, x->str);
289 sep = "|";
290 flags &= ~x->val;
291 }
292 }
293 if (flags)
294 sprintf(outstr + strlen(outstr), "%s%#x", sep, flags);
295 return outstr;
296}
297
298int
299sys_fcntl(struct tcb *tcp)
300{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301 if (entering(tcp)) {
302 tprintf("%ld, ", tcp->u_arg[0]);
303 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
304 switch (tcp->u_arg[1]) {
305 case F_SETFD:
306 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000307 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000308 break;
309 case F_SETOWN: case F_DUPFD:
310 tprintf(", %ld", tcp->u_arg[2]);
311 break;
312 case F_SETFL:
313 tprintf(", ");
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000314 tprint_open_modes(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000315 break;
316 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000317#ifdef F_FREESP
318 case F_FREESP:
319#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320 tprintf(", ");
321 printflock(tcp, tcp->u_arg[2], 0);
322 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000323#if _LFS64_LARGEFILE
324#ifdef F_FREESP64
325 case F_FREESP64:
326#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000327 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000328 even though the kernel has different values - as does Solaris. */
329#if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
330 case F_SETLK64:
331#endif
332#if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
333 case F_SETLKW64:
334#endif
335 tprintf(", ");
336 printflock64(tcp, tcp->u_arg[2], 0);
337 break;
338#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000339 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340 }
341 else {
342 switch (tcp->u_arg[1]) {
343 case F_DUPFD:
344 case F_SETFD: case F_SETFL:
345 case F_SETLK: case F_SETLKW:
346 case F_SETOWN: case F_GETOWN:
347 break;
348 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000349 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000350 return 0;
Roland McGratha6c0d8c2007-11-01 21:46:22 +0000351 tcp->auxstr =
352 sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000353 return RVAL_HEX|RVAL_STR;
354 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000355 if (syserror(tcp))
356 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000357 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 return RVAL_HEX|RVAL_STR;
359 case F_GETLK:
360 tprintf(", ");
361 printflock(tcp, tcp->u_arg[2], 1);
362 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000363#if _LFS64_LARGEFILE
364#if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
365 case F_GETLK64:
366#endif
367 tprintf(", ");
368 printflock64(tcp, tcp->u_arg[2], 1);
369 break;
370#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000371 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000372 tprintf(", %#lx", tcp->u_arg[2]);
373 break;
374 }
375 }
376 return 0;
377}
378
379#ifdef LOCK_SH
380
381int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000382sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383{
384 if (entering(tcp)) {
385 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000386 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387 }
388 return 0;
389}
390#endif /* LOCK_SH */
391
392int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000393sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394{
395 if (entering(tcp)) {
396 tprintf("%ld", tcp->u_arg[0]);
397 }
398 return 0;
399}
400
401int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000402sys_dup(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403{
404 if (entering(tcp)) {
405 tprintf("%ld", tcp->u_arg[0]);
406 }
407 return 0;
408}
409
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000410static int
411do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412{
413 if (entering(tcp)) {
414 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000415 if (flags_arg >= 0) {
416 tprintf(", ");
417 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
418 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419 }
420 return 0;
421}
422
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000423int
424sys_dup2(struct tcb *tcp)
425{
426 return do_dup2(tcp, -1);
427}
428
429#ifdef LINUX
430int
431sys_dup3(struct tcb *tcp)
432{
433 return do_dup2(tcp, 2);
434}
435#endif
436
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000437#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000439sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000440{
441 return 0;
442}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000443#endif /* ALPHA || FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444
445static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000446decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447{
448 int i, j, nfds;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000449 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
450 & -sizeof(long));
451 fd_set *fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 static char outstr[1024];
453 char *sep;
454 long arg;
455
456 if (entering(tcp)) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000457 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000458 if (fds == NULL)
459 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 nfds = args[0];
461 tprintf("%d", nfds);
462 for (i = 0; i < 3; i++) {
463 arg = args[i+1];
464 if (arg == 0) {
465 tprintf(", NULL");
466 continue;
467 }
Roland McGrath46100d02005-06-01 18:55:42 +0000468 if (fds == NULL || !verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469 tprintf(", %#lx", arg);
470 continue;
471 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000472 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473 tprintf(", [?]");
474 continue;
475 }
476 tprintf(", [");
477 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000478 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479 tprintf("%s%u", sep, j);
480 sep = " ";
481 }
482 }
483 tprintf("]");
484 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000485 free(fds);
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000486 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000487 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000489 else
490 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491 unsigned int cumlen = 0;
492 char *sep = "";
493
494 if (syserror(tcp))
495 return 0;
496
497 if ((nfds = tcp->u_rval) == 0) {
498 tcp->auxstr = "Timeout";
499 return RVAL_STR;
500 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000501
502 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000503 if (fds == NULL)
504 fprintf(stderr, "out of memory\n");
Roland McGrathe85aaa42005-02-06 01:55:12 +0000505
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506 outstr[0] = '\0';
507 for (i = 0; i < 3; i++) {
508 int first = 1;
509 char str[20];
510
511 tcp->auxstr = outstr;
512 arg = args[i+1];
Roland McGrath46100d02005-06-01 18:55:42 +0000513 if (fds == NULL || !arg ||
514 umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000515 continue;
516 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000517 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518 if (first) {
519 sprintf(str, "%s%s [%u", sep,
520 i == 0 ? "in" :
521 i == 1 ? "out" :
522 "except", j);
523 first = 0;
524 sep = ", ";
525 }
526 else
527 sprintf(str, " %u", j);
528 cumlen += strlen(str);
529 if (cumlen < sizeof(outstr))
530 strcat(outstr, str);
531 nfds--;
532 }
533 }
534 if (cumlen)
535 strcat(outstr, "]");
536 if (nfds == 0)
537 break;
538 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000539 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540#ifdef LINUX
541 /* This contains no useful information on SunOS. */
542 if (args[4]) {
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000543 char str[128];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000545 sprintf(str, "%sleft ", sep);
546 sprinttv(tcp, args[4], bitness, str + strlen(str));
547 if ((cumlen += strlen(str)) < sizeof(outstr))
548 strcat(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549 }
550#endif /* LINUX */
551 return RVAL_STR;
552 }
553 return 0;
554}
555
556#ifdef LINUX
557
558int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000559sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560{
561 long args[5];
562
563 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
564 tprintf("[...]");
565 return 0;
566 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000567 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000568}
569
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000570#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000571int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000572sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000573{
574 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000575 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000576}
577#endif
578
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000579static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000580#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000581 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000582#endif
583#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000584 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000585#endif
586#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000587 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000588#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000589 { 0, NULL }
590};
591
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000592static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000593#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000594 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000595#endif
596#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000597 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000598#endif
599#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000600 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000601#endif
602#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000603 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000604#endif
605#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000606 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000607#endif
608#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000609 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000610#endif
611#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000612 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000613#endif
614#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000615 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000616#endif
617#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000618 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000619#endif
620#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000621 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000622#endif
623#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000624 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000625#endif
626#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000627 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000628#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000629 { 0, NULL }
630};
631
632int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000633sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000634{
635 if (entering(tcp))
636 tprintf("%ld", tcp->u_arg[0]);
637 return 0;
638}
639
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000640int
641sys_epoll_create1(struct tcb *tcp)
642{
643 if (entering(tcp))
644 printflags(open_mode_flags, tcp->u_arg[0], "O_???");
645 return 0;
646}
647
Roland McGrath63d6e542004-10-20 02:17:41 +0000648#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000649static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000650print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000651{
652 tprintf("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000653 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000654 /* We cannot know what format the program uses, so print u32 and u64
655 which will cover every value. */
656 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
657 ev->data.u32, ev->data.u64);
658}
Roland McGrath63d6e542004-10-20 02:17:41 +0000659#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000660
661int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000662sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000663{
664 if (entering(tcp)) {
Roland McGrath93817bf2004-10-06 22:23:31 +0000665 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000666 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000667 tprintf(", %ld, ", tcp->u_arg[2]);
668 if (tcp->u_arg[3] == 0)
669 tprintf("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000670 else {
671#ifdef HAVE_SYS_EPOLL_H
672 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000673 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000674 print_epoll_event(&ev);
675 else
676#endif
677 tprintf("{...}");
678 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000679 }
680 return 0;
681}
682
Roland McGrathf2400052007-08-02 01:13:26 +0000683static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000684epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000685{
686 if (entering(tcp))
687 tprintf("%ld, ", tcp->u_arg[0]);
688 else {
689 if (syserror(tcp))
690 tprintf("%lx", tcp->u_arg[1]);
691 else if (tcp->u_rval == 0)
692 tprintf("{}");
693 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000694#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000695 struct epoll_event ev, *start, *cur, *end;
696 int failed = 0;
697
698 tprintf("{");
699 start = (struct epoll_event *) tcp->u_arg[1];
700 end = start + tcp->u_rval;
701 for (cur = start; cur < end; ++cur) {
702 if (cur > start)
703 tprintf(", ");
704 if (umove(tcp, (long) cur, &ev) == 0)
705 print_epoll_event(&ev);
706 else {
707 tprintf("?");
708 failed = 1;
709 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000710 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000711 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000712 tprintf("}");
713 if (failed)
714 tprintf(" %#lx", (long) start);
715#else
716 tprintf("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000717#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000718 }
719 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
720 }
Roland McGrathf2400052007-08-02 01:13:26 +0000721}
722
723int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000724sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000725{
726 epoll_wait_common(tcp);
727 return 0;
728}
729
730int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000731sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000732{
733 epoll_wait_common(tcp);
734 if (exiting(tcp))
735 print_sigset(tcp, tcp->u_arg[4], 0);
Roland McGrath93817bf2004-10-06 22:23:31 +0000736 return 0;
737}
Roland McGrath37b9f842005-05-09 08:02:00 +0000738
739int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000740sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000741{
742 if (entering(tcp))
743 tprintf("%ld, ", tcp->u_arg[0]);
744 else {
745 if (syserror(tcp))
746 tprintf("0x%0lx", tcp->u_arg[1]);
747 else {
748 unsigned long user_id;
749 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
750 tprintf("{%lu}", user_id);
751 else
752 tprintf("{...}");
753 }
754 }
755 return 0;
756}
757
758int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000759sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000760{
761 if (entering(tcp))
762 tprintf("%lu", tcp->u_arg[0]);
763 return 0;
764}
765
766int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000767sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000768{
769 long nr;
770 if (entering(tcp)) {
771 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
772 nr = tcp->u_arg[1];
773 /* and if nr is negative? */
774 if (nr == 0)
775 tprintf("{}");
776 else {
777#ifdef HAVE_LIBAIO_H
778 long i;
779 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
780
781 for (i = 0; i < nr; i++, iocbs++) {
782 struct iocb iocb;
783 if (i == 0)
784 tprintf("{");
785 else
786 tprintf(", ");
787
788 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
789 umove(tcp, (unsigned long)iocbp, &iocb)) {
790 tprintf("{...}");
791 continue;
792 }
793 tprintf("{%p, %u, %hu, %hu, %d}",
794 iocb.data, iocb.key,
795 iocb.aio_lio_opcode,
796 iocb.aio_reqprio, iocb.aio_fildes);
797 }
798 if (i)
799 tprintf("}");
800#else
801 tprintf("{...}");
802#endif
803 }
804 }
805 return 0;
806}
807
808int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000809sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000810{
811 if (entering(tcp)) {
812#ifdef HAVE_LIBAIO_H
813 struct iocb iocb;
814#endif
815 tprintf("%lu, ", tcp->u_arg[0]);
816#ifdef HAVE_LIBAIO_H
817 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
818 tprintf("{%p, %u, %hu, %hu, %d}, ",
819 iocb.data, iocb.key,
820 iocb.aio_lio_opcode,
821 iocb.aio_reqprio, iocb.aio_fildes);
822 } else
823#endif
824 tprintf("{...}, ");
825 } else {
826 if (tcp->u_rval < 0)
827 tprintf("{...}");
828 else {
829#ifdef HAVE_LIBAIO_H
830 struct io_event event;
831 if (umove(tcp, tcp->u_arg[2], &event) == 0)
832 tprintf("{%p, %p, %ld, %ld}",
833 event.data, event.obj,
834 event.res, event.res2);
Denys Vlasenkob1efe532008-12-23 16:14:42 +0000835 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000836#endif
837 tprintf("{...}");
838 }
839 }
840 return 0;
841}
842
843int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000844sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000845{
846 if (entering(tcp)) {
847 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
848 tcp->u_arg[2]);
849 } else {
850 if (tcp->u_rval == 0) {
851 tprintf("{}");
852 } else {
853#ifdef HAVE_LIBAIO_H
854 struct io_event *events = (void *)tcp->u_arg[3];
855 long i, nr = tcp->u_rval;
856
857 for (i = 0; i < nr; i++, events++) {
858 struct io_event event;
859
860 if (i == 0)
861 tprintf("{");
862 else
863 tprintf(", ");
864
865 if (umove(tcp, (unsigned long)events, &event) != 0) {
866 tprintf("{...}");
867 continue;
868 }
869 tprintf("{%p, %p, %ld, %ld}", event.data,
870 event.obj, event.res, event.res2);
871 }
872 tprintf("}, ");
873#else
874 tprintf("{...}");
875#endif
876 }
877
Roland McGrath6bc09da2007-11-01 21:50:54 +0000878 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000879 }
880 return 0;
881}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000882#endif /* LINUX */
883
884int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000885sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000886{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000887 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000888}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000889
890#ifdef LINUX
891int
892sys_pselect6(struct tcb *tcp)
893{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000894 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +0000895 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000896 struct {
897 void *ss;
898 unsigned long len;
899 } data;
900 if (umove(tcp, tcp->u_arg[5], &data) < 0)
901 tprintf(", %#lx", tcp->u_arg[5]);
902 else {
903 tprintf(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +0000904 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000905 tprintf("%#lx", (long)data.ss);
906 else
907 print_sigset(tcp, (long)data.ss, 0);
908 tprintf(", %lu}", data.len);
909 }
910 }
911 return rc;
912}
Roland McGrathe7c39672007-08-02 01:32:17 +0000913
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000914static int
915do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +0000916{
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000917 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +0000918 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000919 if (flags_arg >= 0) {
920 tprintf(", ");
921 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
922 }
923 }
Roland McGrathe7c39672007-08-02 01:32:17 +0000924 return 0;
925}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000926
927int
928sys_eventfd(struct tcb *tcp)
929{
930 return do_eventfd(tcp, -1);
931}
932
933int
934sys_eventfd2(struct tcb *tcp)
935{
936 return do_eventfd(tcp, 1);
937}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000938#endif