blob: 3aae9908472037c3ca75ade6dd1412324d04db3c [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
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000151#ifdef F_SETLEASE
152 { F_SETLEASE, "F_SETLEASE" },
153#endif
154#ifdef F_GETLEASE
155 { F_GETLEASE, "F_GETLEASE" },
156#endif
157#ifdef F_NOTIFY
158 { F_NOTIFY, "F_NOTIFY" },
159#endif
160#ifdef F_DUPFD_CLOEXEC
161 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
162#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163 { 0, NULL },
164};
165
Roland McGrathd9f816f2004-09-04 03:39:20 +0000166static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167#ifdef FD_CLOEXEC
168 { FD_CLOEXEC, "FD_CLOEXEC" },
169#endif
170 { 0, NULL },
171};
172
173#ifdef LOCK_SH
174
Roland McGrathd9f816f2004-09-04 03:39:20 +0000175static const struct xlat flockcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176 { LOCK_SH, "LOCK_SH" },
177 { LOCK_EX, "LOCK_EX" },
178 { LOCK_NB, "LOCK_NB" },
179 { LOCK_UN, "LOCK_UN" },
180 { 0, NULL },
181};
182
183#endif /* LOCK_SH */
184
Roland McGrathd9f816f2004-09-04 03:39:20 +0000185static const struct xlat lockfcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 { F_RDLCK, "F_RDLCK" },
187 { F_WRLCK, "F_WRLCK" },
188 { F_UNLCK, "F_UNLCK" },
189#ifdef F_EXLCK
190 { F_EXLCK, "F_EXLCK" },
191#endif
192#ifdef F_SHLCK
193 { F_SHLCK, "F_SHLCK" },
194#endif
195 { 0, NULL },
196};
197
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000198#ifdef F_NOTIFY
199static const struct xlat notifyflags[] = {
200#ifdef DN_ACCESS
201 { DN_ACCESS, "DN_ACCESS" },
202#endif
203#ifdef DN_MODIFY
204 { DN_MODIFY, "DN_MODIFY" },
205#endif
206#ifdef DN_CREATE
207 { DN_CREATE, "DN_CREATE" },
208#endif
209#ifdef DN_DELETE
210 { DN_DELETE, "DN_DELETE" },
211#endif
212#ifdef DN_RENAME
213 { DN_RENAME, "DN_RENAME" },
214#endif
215#ifdef DN_ATTRIB
216 { DN_ATTRIB, "DN_ATTRIB" },
217#endif
218#ifdef DN_MULTISHOT
219 { DN_MULTISHOT, "DN_MULTISHOT" },
220#endif
221 { 0, NULL },
222};
223#endif
224
Roland McGrathd9f816f2004-09-04 03:39:20 +0000225static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226 { SEEK_SET, "SEEK_SET" },
227 { SEEK_CUR, "SEEK_CUR" },
228 { SEEK_END, "SEEK_END" },
229 { 0, NULL },
230};
231
John Hughes70623be2001-03-08 13:59:00 +0000232#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000233/* fcntl/lockf */
234static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000235printflock(struct tcb *tcp, long addr, int getlk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236{
237 struct flock fl;
238
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000239 if (personality_wordsize[current_personality] == sizeof(fl.l_start)) {
240 if (umove(tcp, addr, &fl) < 0) {
241 tprintf("{...}");
242 return;
243 }
244 } else if (personality_wordsize[current_personality] == 4) {
245 /* 32-bit x86 app on x86_64 and similar cases */
246 struct {
247 short int l_type;
248 short int l_whence;
249 int32_t l_start; /* off_t */
250 int32_t l_len; /* off_t */
251 int32_t l_pid; /* pid_t */
252 } fl32;
253 if (umove(tcp, addr, &fl32) < 0) {
254 tprintf("{...}");
255 return;
256 }
257 fl.l_type = fl32.l_type;
258 fl.l_whence = fl32.l_whence;
259 fl.l_start = fl32.l_start;
260 fl.l_len = fl32.l_len;
261 fl.l_pid = fl32.l_pid;
262 } else {
263 /* let people know we have a problem here */
264 tprintf("{ <decode error: unsupported wordsize %d> }",
265 personality_wordsize[current_personality]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266 return;
267 }
268 tprintf("{type=");
269 printxval(lockfcmds, fl.l_type, "F_???");
270 tprintf(", whence=");
271 printxval(whence, fl.l_whence, "SEEK_???");
272 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
273 if (getlk)
274 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
275 else
276 tprintf("}");
277}
John Hughesb8c9f772001-03-07 16:53:07 +0000278#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279
John Hughes70623be2001-03-08 13:59:00 +0000280#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000281/* fcntl/lockf */
282static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000283printflock64(struct tcb *tcp, long addr, int getlk)
John Hughesbdf48f52001-03-06 15:08:09 +0000284{
285 struct flock64 fl;
286
287 if (umove(tcp, addr, &fl) < 0) {
288 tprintf("{...}");
289 return;
290 }
291 tprintf("{type=");
292 printxval(lockfcmds, fl.l_type, "F_???");
293 tprintf(", whence=");
294 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000295 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000296 if (getlk)
297 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
298 else
299 tprintf("}");
300}
301#endif
302
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000303int
304sys_fcntl(struct tcb *tcp)
305{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306 if (entering(tcp)) {
307 tprintf("%ld, ", tcp->u_arg[0]);
308 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
309 switch (tcp->u_arg[1]) {
310 case F_SETFD:
311 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000312 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000313 break;
314 case F_SETOWN: case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000315#ifdef F_DUPFD_CLOEXEC
316 case F_DUPFD_CLOEXEC:
317#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000318 tprintf(", %ld", tcp->u_arg[2]);
319 break;
320 case F_SETFL:
321 tprintf(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000322 tprint_open_modes(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323 break;
324 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000325#ifdef F_FREESP
326 case F_FREESP:
327#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328 tprintf(", ");
329 printflock(tcp, tcp->u_arg[2], 0);
330 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000331#if _LFS64_LARGEFILE
332#ifdef F_FREESP64
333 case F_FREESP64:
334#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000335 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000336 even though the kernel has different values - as does Solaris. */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000337#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000338 case F_SETLK64:
339#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000340#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
John Hughesbdf48f52001-03-06 15:08:09 +0000341 case F_SETLKW64:
342#endif
343 tprintf(", ");
344 printflock64(tcp, tcp->u_arg[2], 0);
345 break;
346#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000347#ifdef F_NOTIFY
348 case F_NOTIFY:
349 tprintf(", ");
350 printflags(notifyflags, tcp->u_arg[2], "DN_???");
351 break;
352#endif
353#ifdef F_SETLEASE
354 case F_SETLEASE:
355 tprintf(", ");
356 printxval(lockfcmds, tcp->u_arg[2], "F_???");
357 break;
358#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000359 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360 }
361 else {
362 switch (tcp->u_arg[1]) {
363 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000364#ifdef F_DUPFD_CLOEXEC
365 case F_DUPFD_CLOEXEC:
366#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000367 case F_SETFD: case F_SETFL:
368 case F_SETLK: case F_SETLKW:
369 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000370#ifdef F_NOTIFY
371 case F_NOTIFY:
372#endif
373#ifdef F_SETLEASE
374 case F_SETLEASE:
375#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376 break;
377 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000378 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000380 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381 return RVAL_HEX|RVAL_STR;
382 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000383 if (syserror(tcp))
384 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000385 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000386 return RVAL_HEX|RVAL_STR;
387 case F_GETLK:
388 tprintf(", ");
389 printflock(tcp, tcp->u_arg[2], 1);
390 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000391#if _LFS64_LARGEFILE
392#if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
393 case F_GETLK64:
394#endif
395 tprintf(", ");
396 printflock64(tcp, tcp->u_arg[2], 1);
397 break;
398#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000399#ifdef F_GETLEASE
400 case F_GETLEASE:
401 if (syserror(tcp))
402 return 0;
403 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
404 return RVAL_HEX|RVAL_STR;
405#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000406 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407 tprintf(", %#lx", tcp->u_arg[2]);
408 break;
409 }
410 }
411 return 0;
412}
413
414#ifdef LOCK_SH
415
416int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000417sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418{
419 if (entering(tcp)) {
420 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000421 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 }
423 return 0;
424}
425#endif /* LOCK_SH */
426
427int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000428sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429{
430 if (entering(tcp)) {
431 tprintf("%ld", tcp->u_arg[0]);
432 }
433 return 0;
434}
435
436int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000437sys_dup(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438{
439 if (entering(tcp)) {
440 tprintf("%ld", tcp->u_arg[0]);
441 }
442 return 0;
443}
444
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000445static int
446do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447{
448 if (entering(tcp)) {
449 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000450 if (flags_arg >= 0) {
451 tprintf(", ");
452 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
453 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454 }
455 return 0;
456}
457
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000458int
459sys_dup2(struct tcb *tcp)
460{
461 return do_dup2(tcp, -1);
462}
463
464#ifdef LINUX
465int
466sys_dup3(struct tcb *tcp)
467{
468 return do_dup2(tcp, 2);
469}
470#endif
471
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000472#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000474sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475{
476 return 0;
477}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000478#endif /* ALPHA || FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479
480static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000481decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482{
483 int i, j, nfds;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000484 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
485 & -sizeof(long));
486 fd_set *fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487 static char outstr[1024];
488 char *sep;
489 long arg;
490
491 if (entering(tcp)) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000492 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000493 if (fds == NULL)
494 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000495 nfds = args[0];
496 tprintf("%d", nfds);
497 for (i = 0; i < 3; i++) {
498 arg = args[i+1];
499 if (arg == 0) {
500 tprintf(", NULL");
501 continue;
502 }
Roland McGrath46100d02005-06-01 18:55:42 +0000503 if (fds == NULL || !verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504 tprintf(", %#lx", arg);
505 continue;
506 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000507 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508 tprintf(", [?]");
509 continue;
510 }
511 tprintf(", [");
512 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000513 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 tprintf("%s%u", sep, j);
515 sep = " ";
516 }
517 }
518 tprintf("]");
519 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000520 free(fds);
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000521 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000522 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000524 else
525 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526 unsigned int cumlen = 0;
527 char *sep = "";
528
529 if (syserror(tcp))
530 return 0;
531
532 if ((nfds = tcp->u_rval) == 0) {
533 tcp->auxstr = "Timeout";
534 return RVAL_STR;
535 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000536
537 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000538 if (fds == NULL)
539 fprintf(stderr, "out of memory\n");
Roland McGrathe85aaa42005-02-06 01:55:12 +0000540
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541 outstr[0] = '\0';
542 for (i = 0; i < 3; i++) {
543 int first = 1;
544 char str[20];
545
546 tcp->auxstr = outstr;
547 arg = args[i+1];
Roland McGrath46100d02005-06-01 18:55:42 +0000548 if (fds == NULL || !arg ||
549 umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 continue;
551 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000552 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553 if (first) {
554 sprintf(str, "%s%s [%u", sep,
555 i == 0 ? "in" :
556 i == 1 ? "out" :
557 "except", j);
558 first = 0;
559 sep = ", ";
560 }
561 else
562 sprintf(str, " %u", j);
563 cumlen += strlen(str);
564 if (cumlen < sizeof(outstr))
565 strcat(outstr, str);
566 nfds--;
567 }
568 }
569 if (cumlen)
570 strcat(outstr, "]");
571 if (nfds == 0)
572 break;
573 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000574 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575#ifdef LINUX
576 /* This contains no useful information on SunOS. */
577 if (args[4]) {
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000578 char str[128];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000579
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000580 sprintf(str, "%sleft ", sep);
581 sprinttv(tcp, args[4], bitness, str + strlen(str));
582 if ((cumlen += strlen(str)) < sizeof(outstr))
583 strcat(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584 }
585#endif /* LINUX */
586 return RVAL_STR;
587 }
588 return 0;
589}
590
591#ifdef LINUX
592
593int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000594sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595{
596 long args[5];
597
598 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
599 tprintf("[...]");
600 return 0;
601 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000602 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603}
604
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000605#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000606int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000607sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000608{
609 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000610 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000611}
612#endif
613
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000614static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000615#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000616 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000617#endif
618#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000619 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000620#endif
621#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000622 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000623#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000624 { 0, NULL }
625};
626
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000627static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000628#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000629 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000630#endif
631#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000632 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000633#endif
634#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000635 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000636#endif
637#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000638 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000639#endif
640#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000641 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000642#endif
643#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000644 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000645#endif
646#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000647 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000648#endif
649#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000650 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000651#endif
652#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000653 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000654#endif
655#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000656 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000657#endif
658#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000659 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000660#endif
661#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000662 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000663#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000664 { 0, NULL }
665};
666
667int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000668sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000669{
670 if (entering(tcp))
671 tprintf("%ld", tcp->u_arg[0]);
672 return 0;
673}
674
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000675int
676sys_epoll_create1(struct tcb *tcp)
677{
678 if (entering(tcp))
679 printflags(open_mode_flags, tcp->u_arg[0], "O_???");
680 return 0;
681}
682
Roland McGrath63d6e542004-10-20 02:17:41 +0000683#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000684static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000685print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000686{
687 tprintf("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000688 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000689 /* We cannot know what format the program uses, so print u32 and u64
690 which will cover every value. */
691 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
692 ev->data.u32, ev->data.u64);
693}
Roland McGrath63d6e542004-10-20 02:17:41 +0000694#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000695
696int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000697sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000698{
699 if (entering(tcp)) {
Roland McGrath93817bf2004-10-06 22:23:31 +0000700 tprintf("%ld, ", tcp->u_arg[0]);
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000701 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000702 tprintf(", %ld, ", tcp->u_arg[2]);
703 if (tcp->u_arg[3] == 0)
704 tprintf("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000705 else {
706#ifdef HAVE_SYS_EPOLL_H
707 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000708 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000709 print_epoll_event(&ev);
710 else
711#endif
712 tprintf("{...}");
713 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000714 }
715 return 0;
716}
717
Roland McGrathf2400052007-08-02 01:13:26 +0000718static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000719epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000720{
721 if (entering(tcp))
722 tprintf("%ld, ", tcp->u_arg[0]);
723 else {
724 if (syserror(tcp))
725 tprintf("%lx", tcp->u_arg[1]);
726 else if (tcp->u_rval == 0)
727 tprintf("{}");
728 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000729#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000730 struct epoll_event ev, *start, *cur, *end;
731 int failed = 0;
732
733 tprintf("{");
734 start = (struct epoll_event *) tcp->u_arg[1];
735 end = start + tcp->u_rval;
736 for (cur = start; cur < end; ++cur) {
737 if (cur > start)
738 tprintf(", ");
739 if (umove(tcp, (long) cur, &ev) == 0)
740 print_epoll_event(&ev);
741 else {
742 tprintf("?");
743 failed = 1;
744 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000745 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000746 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000747 tprintf("}");
748 if (failed)
749 tprintf(" %#lx", (long) start);
750#else
751 tprintf("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000752#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000753 }
754 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
755 }
Roland McGrathf2400052007-08-02 01:13:26 +0000756}
757
758int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000759sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000760{
761 epoll_wait_common(tcp);
762 return 0;
763}
764
765int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000766sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000767{
768 epoll_wait_common(tcp);
769 if (exiting(tcp))
770 print_sigset(tcp, tcp->u_arg[4], 0);
Roland McGrath93817bf2004-10-06 22:23:31 +0000771 return 0;
772}
Roland McGrath37b9f842005-05-09 08:02:00 +0000773
774int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000775sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000776{
777 if (entering(tcp))
778 tprintf("%ld, ", tcp->u_arg[0]);
779 else {
780 if (syserror(tcp))
781 tprintf("0x%0lx", tcp->u_arg[1]);
782 else {
783 unsigned long user_id;
784 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
785 tprintf("{%lu}", user_id);
786 else
787 tprintf("{...}");
788 }
789 }
790 return 0;
791}
792
793int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000794sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000795{
796 if (entering(tcp))
797 tprintf("%lu", tcp->u_arg[0]);
798 return 0;
799}
800
801int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000802sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000803{
804 long nr;
805 if (entering(tcp)) {
806 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
807 nr = tcp->u_arg[1];
808 /* and if nr is negative? */
809 if (nr == 0)
810 tprintf("{}");
811 else {
812#ifdef HAVE_LIBAIO_H
813 long i;
814 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
815
816 for (i = 0; i < nr; i++, iocbs++) {
817 struct iocb iocb;
818 if (i == 0)
819 tprintf("{");
820 else
821 tprintf(", ");
822
823 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
824 umove(tcp, (unsigned long)iocbp, &iocb)) {
825 tprintf("{...}");
826 continue;
827 }
828 tprintf("{%p, %u, %hu, %hu, %d}",
829 iocb.data, iocb.key,
830 iocb.aio_lio_opcode,
831 iocb.aio_reqprio, iocb.aio_fildes);
832 }
833 if (i)
834 tprintf("}");
835#else
836 tprintf("{...}");
837#endif
838 }
839 }
840 return 0;
841}
842
843int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000844sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000845{
846 if (entering(tcp)) {
847#ifdef HAVE_LIBAIO_H
848 struct iocb iocb;
849#endif
850 tprintf("%lu, ", tcp->u_arg[0]);
851#ifdef HAVE_LIBAIO_H
852 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
853 tprintf("{%p, %u, %hu, %hu, %d}, ",
854 iocb.data, iocb.key,
855 iocb.aio_lio_opcode,
856 iocb.aio_reqprio, iocb.aio_fildes);
857 } else
858#endif
859 tprintf("{...}, ");
860 } else {
861 if (tcp->u_rval < 0)
862 tprintf("{...}");
863 else {
864#ifdef HAVE_LIBAIO_H
865 struct io_event event;
866 if (umove(tcp, tcp->u_arg[2], &event) == 0)
867 tprintf("{%p, %p, %ld, %ld}",
868 event.data, event.obj,
869 event.res, event.res2);
Denys Vlasenkob1efe532008-12-23 16:14:42 +0000870 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000871#endif
872 tprintf("{...}");
873 }
874 }
875 return 0;
876}
877
878int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000879sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000880{
881 if (entering(tcp)) {
882 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
883 tcp->u_arg[2]);
884 } else {
885 if (tcp->u_rval == 0) {
886 tprintf("{}");
887 } else {
888#ifdef HAVE_LIBAIO_H
889 struct io_event *events = (void *)tcp->u_arg[3];
890 long i, nr = tcp->u_rval;
891
892 for (i = 0; i < nr; i++, events++) {
893 struct io_event event;
894
895 if (i == 0)
896 tprintf("{");
897 else
898 tprintf(", ");
899
900 if (umove(tcp, (unsigned long)events, &event) != 0) {
901 tprintf("{...}");
902 continue;
903 }
904 tprintf("{%p, %p, %ld, %ld}", event.data,
905 event.obj, event.res, event.res2);
906 }
907 tprintf("}, ");
908#else
909 tprintf("{...}");
910#endif
911 }
912
Roland McGrath6bc09da2007-11-01 21:50:54 +0000913 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000914 }
915 return 0;
916}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000917#endif /* LINUX */
918
919int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000920sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000921{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000922 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000923}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000924
925#ifdef LINUX
926int
927sys_pselect6(struct tcb *tcp)
928{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000929 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +0000930 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000931 struct {
932 void *ss;
933 unsigned long len;
934 } data;
935 if (umove(tcp, tcp->u_arg[5], &data) < 0)
936 tprintf(", %#lx", tcp->u_arg[5]);
937 else {
938 tprintf(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +0000939 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000940 tprintf("%#lx", (long)data.ss);
941 else
942 print_sigset(tcp, (long)data.ss, 0);
943 tprintf(", %lu}", data.len);
944 }
945 }
946 return rc;
947}
Roland McGrathe7c39672007-08-02 01:32:17 +0000948
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000949static int
950do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +0000951{
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000952 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +0000953 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000954 if (flags_arg >= 0) {
955 tprintf(", ");
956 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
957 }
958 }
Roland McGrathe7c39672007-08-02 01:32:17 +0000959 return 0;
960}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000961
962int
963sys_eventfd(struct tcb *tcp)
964{
965 return do_eventfd(tcp, -1);
966}
967
968int
969sys_eventfd2(struct tcb *tcp)
970{
971 return do_eventfd(tcp, 1);
972}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000973#endif