blob: 379950b028f54e4f20a75adf322700551594f33a [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
196printflock(tcp, addr, getlk)
197struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000198long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199int getlk;
200{
201 struct flock fl;
202
203 if (umove(tcp, addr, &fl) < 0) {
204 tprintf("{...}");
205 return;
206 }
207 tprintf("{type=");
208 printxval(lockfcmds, fl.l_type, "F_???");
209 tprintf(", whence=");
210 printxval(whence, fl.l_whence, "SEEK_???");
211 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
212 if (getlk)
213 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
214 else
215 tprintf("}");
216}
John Hughesb8c9f772001-03-07 16:53:07 +0000217#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218
John Hughes70623be2001-03-08 13:59:00 +0000219#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000220/* fcntl/lockf */
221static void
222printflock64(tcp, addr, getlk)
223struct tcb *tcp;
Roland McGrath81634e42003-01-14 07:53:31 +0000224long addr;
John Hughesbdf48f52001-03-06 15:08:09 +0000225int getlk;
226{
227 struct flock64 fl;
228
229 if (umove(tcp, addr, &fl) < 0) {
230 tprintf("{...}");
231 return;
232 }
233 tprintf("{type=");
234 printxval(lockfcmds, fl.l_type, "F_???");
235 tprintf(", whence=");
236 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000237 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000238 if (getlk)
239 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
240 else
241 tprintf("}");
242}
243#endif
244
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000245extern const struct xlat open_mode_flags[];
246
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000247/*
248 * low bits of the open(2) flags define access mode,
249 * other bits are real flags.
250 */
251static const char *
252sprint_open_modes(mode_t flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000253{
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000254 extern const struct xlat open_access_modes[];
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000255 static char outstr[1024];
256 const char *str = xlookup(open_access_modes, flags & 3);
257 const char *sep = "";
258 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000259
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000260 strcpy(outstr, "flags ");
261 if (str)
262 {
263 strcat(outstr, str);
264 flags &= ~3;
265 if (!flags)
266 return outstr;
267 strcat(outstr, "|");
268 }
269
270 for (x = open_mode_flags; x->str; x++)
271 {
272 if ((flags & x->val) == x->val)
273 {
274 sprintf(outstr + strlen(outstr),
275 "%s%s", sep, x->str);
276 sep = "|";
277 flags &= ~x->val;
278 }
279 }
280 if (flags)
281 sprintf(outstr + strlen(outstr), "%s%#x", sep, flags);
282 return outstr;
283}
284
285int
286sys_fcntl(struct tcb *tcp)
287{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000288 if (entering(tcp)) {
289 tprintf("%ld, ", tcp->u_arg[0]);
290 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
291 switch (tcp->u_arg[1]) {
292 case F_SETFD:
293 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000294 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000295 break;
296 case F_SETOWN: case F_DUPFD:
297 tprintf(", %ld", tcp->u_arg[2]);
298 break;
299 case F_SETFL:
300 tprintf(", ");
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000301 tprint_open_modes(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000302 break;
303 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000304#ifdef F_FREESP
305 case F_FREESP:
306#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000307 tprintf(", ");
308 printflock(tcp, tcp->u_arg[2], 0);
309 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000310#if _LFS64_LARGEFILE
311#ifdef F_FREESP64
312 case F_FREESP64:
313#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000314 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000315 even though the kernel has different values - as does Solaris. */
316#if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
317 case F_SETLK64:
318#endif
319#if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
320 case F_SETLKW64:
321#endif
322 tprintf(", ");
323 printflock64(tcp, tcp->u_arg[2], 0);
324 break;
325#endif
326 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 }
328 else {
329 switch (tcp->u_arg[1]) {
330 case F_DUPFD:
331 case F_SETFD: case F_SETFL:
332 case F_SETLK: case F_SETLKW:
333 case F_SETOWN: case F_GETOWN:
334 break;
335 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000336 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 return 0;
Roland McGratha6c0d8c2007-11-01 21:46:22 +0000338 tcp->auxstr =
339 sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340 return RVAL_HEX|RVAL_STR;
341 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000342 if (syserror(tcp))
343 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000344 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345 return RVAL_HEX|RVAL_STR;
346 case F_GETLK:
347 tprintf(", ");
348 printflock(tcp, tcp->u_arg[2], 1);
349 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000350#if _LFS64_LARGEFILE
351#if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
352 case F_GETLK64:
353#endif
354 tprintf(", ");
355 printflock64(tcp, tcp->u_arg[2], 1);
356 break;
357#endif
358 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000359 tprintf(", %#lx", tcp->u_arg[2]);
360 break;
361 }
362 }
363 return 0;
364}
365
366#ifdef LOCK_SH
367
368int
369sys_flock(tcp)
370struct tcb *tcp;
371{
372 if (entering(tcp)) {
373 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000374 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375 }
376 return 0;
377}
378#endif /* LOCK_SH */
379
380int
381sys_close(tcp)
382struct tcb *tcp;
383{
384 if (entering(tcp)) {
385 tprintf("%ld", tcp->u_arg[0]);
386 }
387 return 0;
388}
389
390int
391sys_dup(tcp)
392struct tcb *tcp;
393{
394 if (entering(tcp)) {
395 tprintf("%ld", tcp->u_arg[0]);
396 }
397 return 0;
398}
399
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000400static int
401do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000402{
403 if (entering(tcp)) {
404 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000405 if (flags_arg >= 0) {
406 tprintf(", ");
407 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
408 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409 }
410 return 0;
411}
412
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000413int
414sys_dup2(struct tcb *tcp)
415{
416 return do_dup2(tcp, -1);
417}
418
419#ifdef LINUX
420int
421sys_dup3(struct tcb *tcp)
422{
423 return do_dup2(tcp, 2);
424}
425#endif
426
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000427#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428int
429sys_getdtablesize(tcp)
430struct tcb *tcp;
431{
432 return 0;
433}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000434#endif /* ALPHA || FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435
436static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000437decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438{
439 int i, j, nfds;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000440 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
441 & -sizeof(long));
442 fd_set *fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000443 static char outstr[1024];
444 char *sep;
445 long arg;
446
447 if (entering(tcp)) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000448 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000449 if (fds == NULL)
450 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000451 nfds = args[0];
452 tprintf("%d", nfds);
453 for (i = 0; i < 3; i++) {
454 arg = args[i+1];
455 if (arg == 0) {
456 tprintf(", NULL");
457 continue;
458 }
Roland McGrath46100d02005-06-01 18:55:42 +0000459 if (fds == NULL || !verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000460 tprintf(", %#lx", arg);
461 continue;
462 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000463 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464 tprintf(", [?]");
465 continue;
466 }
467 tprintf(", [");
468 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000469 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470 tprintf("%s%u", sep, j);
471 sep = " ";
472 }
473 }
474 tprintf("]");
475 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000476 free(fds);
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000477 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000478 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000480 else
481 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482 unsigned int cumlen = 0;
483 char *sep = "";
484
485 if (syserror(tcp))
486 return 0;
487
488 if ((nfds = tcp->u_rval) == 0) {
489 tcp->auxstr = "Timeout";
490 return RVAL_STR;
491 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000492
493 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000494 if (fds == NULL)
495 fprintf(stderr, "out of memory\n");
Roland McGrathe85aaa42005-02-06 01:55:12 +0000496
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497 outstr[0] = '\0';
498 for (i = 0; i < 3; i++) {
499 int first = 1;
500 char str[20];
501
502 tcp->auxstr = outstr;
503 arg = args[i+1];
Roland McGrath46100d02005-06-01 18:55:42 +0000504 if (fds == NULL || !arg ||
505 umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506 continue;
507 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000508 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 if (first) {
510 sprintf(str, "%s%s [%u", sep,
511 i == 0 ? "in" :
512 i == 1 ? "out" :
513 "except", j);
514 first = 0;
515 sep = ", ";
516 }
517 else
518 sprintf(str, " %u", j);
519 cumlen += strlen(str);
520 if (cumlen < sizeof(outstr))
521 strcat(outstr, str);
522 nfds--;
523 }
524 }
525 if (cumlen)
526 strcat(outstr, "]");
527 if (nfds == 0)
528 break;
529 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000530 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531#ifdef LINUX
532 /* This contains no useful information on SunOS. */
533 if (args[4]) {
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000534 char str[128];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000536 sprintf(str, "%sleft ", sep);
537 sprinttv(tcp, args[4], bitness, str + strlen(str));
538 if ((cumlen += strlen(str)) < sizeof(outstr))
539 strcat(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000540 }
541#endif /* LINUX */
542 return RVAL_STR;
543 }
544 return 0;
545}
546
547#ifdef LINUX
548
549int
550sys_oldselect(tcp)
551struct tcb *tcp;
552{
553 long args[5];
554
555 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
556 tprintf("[...]");
557 return 0;
558 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000559 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560}
561
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000562#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000563int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000564sys_osf_select(tcp)
565struct tcb *tcp;
566{
567 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000568 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000569}
570#endif
571
Roland McGrath93817bf2004-10-06 22:23:31 +0000572static struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000573#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000574 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000575#endif
576#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000577 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000578#endif
579#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000580 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000581#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000582 { 0, NULL }
583};
584
585static struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000586#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000587 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000588#endif
589#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000590 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000591#endif
592#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000593 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000594#endif
595#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000596 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000597#endif
598#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000599 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000600#endif
601#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000602 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000603#endif
604#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000605 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000606#endif
607#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000608 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000609#endif
610#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000611 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000612#endif
613#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000614 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000615#endif
616#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000617 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000618#endif
619#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000620 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000621#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000622 { 0, NULL }
623};
624
625int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000626sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000627{
628 if (entering(tcp))
629 tprintf("%ld", tcp->u_arg[0]);
630 return 0;
631}
632
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000633int
634sys_epoll_create1(struct tcb *tcp)
635{
636 if (entering(tcp))
637 printflags(open_mode_flags, tcp->u_arg[0], "O_???");
638 return 0;
639}
640
Roland McGrath63d6e542004-10-20 02:17:41 +0000641#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000642static void
643print_epoll_event(ev)
644struct epoll_event *ev;
645{
646 tprintf("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000647 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000648 /* We cannot know what format the program uses, so print u32 and u64
649 which will cover every value. */
650 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
651 ev->data.u32, ev->data.u64);
652}
Roland McGrath63d6e542004-10-20 02:17:41 +0000653#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000654
655int
656sys_epoll_ctl(tcp)
657struct tcb *tcp;
658{
659 if (entering(tcp)) {
Roland McGrath93817bf2004-10-06 22:23:31 +0000660 tprintf("%ld, ", tcp->u_arg[0]);
661 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
662 tprintf(", %ld, ", tcp->u_arg[2]);
663 if (tcp->u_arg[3] == 0)
664 tprintf("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000665 else {
666#ifdef HAVE_SYS_EPOLL_H
667 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000668 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000669 print_epoll_event(&ev);
670 else
671#endif
672 tprintf("{...}");
673 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000674 }
675 return 0;
676}
677
Roland McGrathf2400052007-08-02 01:13:26 +0000678static void
679epoll_wait_common(tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000680struct tcb *tcp;
681{
682 if (entering(tcp))
683 tprintf("%ld, ", tcp->u_arg[0]);
684 else {
685 if (syserror(tcp))
686 tprintf("%lx", tcp->u_arg[1]);
687 else if (tcp->u_rval == 0)
688 tprintf("{}");
689 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000690#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000691 struct epoll_event ev, *start, *cur, *end;
692 int failed = 0;
693
694 tprintf("{");
695 start = (struct epoll_event *) tcp->u_arg[1];
696 end = start + tcp->u_rval;
697 for (cur = start; cur < end; ++cur) {
698 if (cur > start)
699 tprintf(", ");
700 if (umove(tcp, (long) cur, &ev) == 0)
701 print_epoll_event(&ev);
702 else {
703 tprintf("?");
704 failed = 1;
705 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000706 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000707 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000708 tprintf("}");
709 if (failed)
710 tprintf(" %#lx", (long) start);
711#else
712 tprintf("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000713#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000714 }
715 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
716 }
Roland McGrathf2400052007-08-02 01:13:26 +0000717}
718
719int
720sys_epoll_wait(tcp)
721struct tcb *tcp;
722{
723 epoll_wait_common(tcp);
724 return 0;
725}
726
727int
728sys_epoll_pwait(tcp)
729struct tcb *tcp;
730{
731 epoll_wait_common(tcp);
732 if (exiting(tcp))
733 print_sigset(tcp, tcp->u_arg[4], 0);
Roland McGrath93817bf2004-10-06 22:23:31 +0000734 return 0;
735}
Roland McGrath37b9f842005-05-09 08:02:00 +0000736
737int
738sys_io_setup(tcp)
739struct tcb *tcp;
740{
741 if (entering(tcp))
742 tprintf("%ld, ", tcp->u_arg[0]);
743 else {
744 if (syserror(tcp))
745 tprintf("0x%0lx", tcp->u_arg[1]);
746 else {
747 unsigned long user_id;
748 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
749 tprintf("{%lu}", user_id);
750 else
751 tprintf("{...}");
752 }
753 }
754 return 0;
755}
756
757int
758sys_io_destroy(tcp)
759struct tcb *tcp;
760{
761 if (entering(tcp))
762 tprintf("%lu", tcp->u_arg[0]);
763 return 0;
764}
765
766int
767sys_io_submit(tcp)
768struct tcb *tcp;
769{
770 long nr;
771 if (entering(tcp)) {
772 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
773 nr = tcp->u_arg[1];
774 /* and if nr is negative? */
775 if (nr == 0)
776 tprintf("{}");
777 else {
778#ifdef HAVE_LIBAIO_H
779 long i;
780 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
781
782 for (i = 0; i < nr; i++, iocbs++) {
783 struct iocb iocb;
784 if (i == 0)
785 tprintf("{");
786 else
787 tprintf(", ");
788
789 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
790 umove(tcp, (unsigned long)iocbp, &iocb)) {
791 tprintf("{...}");
792 continue;
793 }
794 tprintf("{%p, %u, %hu, %hu, %d}",
795 iocb.data, iocb.key,
796 iocb.aio_lio_opcode,
797 iocb.aio_reqprio, iocb.aio_fildes);
798 }
799 if (i)
800 tprintf("}");
801#else
802 tprintf("{...}");
803#endif
804 }
805 }
806 return 0;
807}
808
809int
810sys_io_cancel(tcp)
811struct tcb *tcp;
812{
813 if (entering(tcp)) {
814#ifdef HAVE_LIBAIO_H
815 struct iocb iocb;
816#endif
817 tprintf("%lu, ", tcp->u_arg[0]);
818#ifdef HAVE_LIBAIO_H
819 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
820 tprintf("{%p, %u, %hu, %hu, %d}, ",
821 iocb.data, iocb.key,
822 iocb.aio_lio_opcode,
823 iocb.aio_reqprio, iocb.aio_fildes);
824 } else
825#endif
826 tprintf("{...}, ");
827 } else {
828 if (tcp->u_rval < 0)
829 tprintf("{...}");
830 else {
831#ifdef HAVE_LIBAIO_H
832 struct io_event event;
833 if (umove(tcp, tcp->u_arg[2], &event) == 0)
834 tprintf("{%p, %p, %ld, %ld}",
835 event.data, event.obj,
836 event.res, event.res2);
837 else
838#endif
839 tprintf("{...}");
840 }
841 }
842 return 0;
843}
844
845int
Roland McGrath6bc09da2007-11-01 21:50:54 +0000846sys_io_getevents(struct tcb * tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000847{
848 if (entering(tcp)) {
849 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
850 tcp->u_arg[2]);
851 } else {
852 if (tcp->u_rval == 0) {
853 tprintf("{}");
854 } else {
855#ifdef HAVE_LIBAIO_H
856 struct io_event *events = (void *)tcp->u_arg[3];
857 long i, nr = tcp->u_rval;
858
859 for (i = 0; i < nr; i++, events++) {
860 struct io_event event;
861
862 if (i == 0)
863 tprintf("{");
864 else
865 tprintf(", ");
866
867 if (umove(tcp, (unsigned long)events, &event) != 0) {
868 tprintf("{...}");
869 continue;
870 }
871 tprintf("{%p, %p, %ld, %ld}", event.data,
872 event.obj, event.res, event.res2);
873 }
874 tprintf("}, ");
875#else
876 tprintf("{...}");
877#endif
878 }
879
Roland McGrath6bc09da2007-11-01 21:50:54 +0000880 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000881 }
882 return 0;
883}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000884#endif /* LINUX */
885
886int
887sys_select(tcp)
888struct tcb *tcp;
889{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000890 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000891}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000892
893#ifdef LINUX
894int
895sys_pselect6(struct tcb *tcp)
896{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000897 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +0000898 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000899 struct {
900 void *ss;
901 unsigned long len;
902 } data;
903 if (umove(tcp, tcp->u_arg[5], &data) < 0)
904 tprintf(", %#lx", tcp->u_arg[5]);
905 else {
906 tprintf(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +0000907 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000908 tprintf("%#lx", (long)data.ss);
909 else
910 print_sigset(tcp, (long)data.ss, 0);
911 tprintf(", %lu}", data.len);
912 }
913 }
914 return rc;
915}
Roland McGrathe7c39672007-08-02 01:32:17 +0000916
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000917static int
918do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +0000919{
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000920 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +0000921 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000922 if (flags_arg >= 0) {
923 tprintf(", ");
924 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
925 }
926 }
Roland McGrathe7c39672007-08-02 01:32:17 +0000927 return 0;
928}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000929
930int
931sys_eventfd(struct tcb *tcp)
932{
933 return do_eventfd(tcp, -1);
934}
935
936int
937sys_eventfd2(struct tcb *tcp)
938{
939 return do_eventfd(tcp, 1);
940}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000941#endif