blob: 4276a8148c0597324484e72259a13f4b21ffe2a4 [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 Vlasenko7a862d72009-04-15 13:22:59 +0000239#if SUPPORTED_PERSONALITIES > 1
240 if (personality_wordsize[current_personality] != sizeof(fl.l_start)) {
241 if (personality_wordsize[current_personality] == 4) {
242 /* 32-bit x86 app on x86_64 and similar cases */
243 struct {
244 short int l_type;
245 short int l_whence;
246 int32_t l_start; /* off_t */
247 int32_t l_len; /* off_t */
248 int32_t l_pid; /* pid_t */
249 } fl32;
250 if (umove(tcp, addr, &fl32) < 0) {
251 tprintf("{...}");
252 return;
253 }
254 fl.l_type = fl32.l_type;
255 fl.l_whence = fl32.l_whence;
256 fl.l_start = fl32.l_start;
257 fl.l_len = fl32.l_len;
258 fl.l_pid = fl32.l_pid;
259 } else {
260 /* let people know we have a problem here */
261 tprintf("{ <decode error: unsupported wordsize %d> }",
262 personality_wordsize[current_personality]);
263 return;
264 }
265 } else
266#endif
267 {
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000268 if (umove(tcp, addr, &fl) < 0) {
269 tprintf("{...}");
270 return;
271 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 }
273 tprintf("{type=");
274 printxval(lockfcmds, fl.l_type, "F_???");
275 tprintf(", whence=");
276 printxval(whence, fl.l_whence, "SEEK_???");
277 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
278 if (getlk)
279 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
280 else
281 tprintf("}");
282}
John Hughesb8c9f772001-03-07 16:53:07 +0000283#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000284
John Hughes70623be2001-03-08 13:59:00 +0000285#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000286/* fcntl/lockf */
287static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000288printflock64(struct tcb *tcp, long addr, int getlk)
John Hughesbdf48f52001-03-06 15:08:09 +0000289{
290 struct flock64 fl;
291
292 if (umove(tcp, addr, &fl) < 0) {
293 tprintf("{...}");
294 return;
295 }
296 tprintf("{type=");
297 printxval(lockfcmds, fl.l_type, "F_???");
298 tprintf(", whence=");
299 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000300 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000301 if (getlk)
302 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
303 else
304 tprintf("}");
305}
306#endif
307
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000308int
309sys_fcntl(struct tcb *tcp)
310{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300312 printfd(tcp, tcp->u_arg[0]);
313 tprintf(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000314 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
315 switch (tcp->u_arg[1]) {
316 case F_SETFD:
317 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000318 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 break;
320 case F_SETOWN: case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000321#ifdef F_DUPFD_CLOEXEC
322 case F_DUPFD_CLOEXEC:
323#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000324 tprintf(", %ld", tcp->u_arg[2]);
325 break;
326 case F_SETFL:
327 tprintf(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000328 tprint_open_modes(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000329 break;
330 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000331#ifdef F_FREESP
332 case F_FREESP:
333#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000334 tprintf(", ");
335 printflock(tcp, tcp->u_arg[2], 0);
336 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000337#if _LFS64_LARGEFILE
338#ifdef F_FREESP64
339 case F_FREESP64:
340#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000341 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000342 even though the kernel has different values - as does Solaris. */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000343#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000344 case F_SETLK64:
345#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000346#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
John Hughesbdf48f52001-03-06 15:08:09 +0000347 case F_SETLKW64:
348#endif
349 tprintf(", ");
350 printflock64(tcp, tcp->u_arg[2], 0);
351 break;
352#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000353#ifdef F_NOTIFY
354 case F_NOTIFY:
355 tprintf(", ");
356 printflags(notifyflags, tcp->u_arg[2], "DN_???");
357 break;
358#endif
359#ifdef F_SETLEASE
360 case F_SETLEASE:
361 tprintf(", ");
362 printxval(lockfcmds, tcp->u_arg[2], "F_???");
363 break;
364#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000365 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 }
367 else {
368 switch (tcp->u_arg[1]) {
369 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000370#ifdef F_DUPFD_CLOEXEC
371 case F_DUPFD_CLOEXEC:
372#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373 case F_SETFD: case F_SETFL:
374 case F_SETLK: case F_SETLKW:
375 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000376#ifdef F_NOTIFY
377 case F_NOTIFY:
378#endif
379#ifdef F_SETLEASE
380 case F_SETLEASE:
381#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000382 break;
383 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000384 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000386 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387 return RVAL_HEX|RVAL_STR;
388 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000389 if (syserror(tcp))
390 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000391 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392 return RVAL_HEX|RVAL_STR;
393 case F_GETLK:
394 tprintf(", ");
395 printflock(tcp, tcp->u_arg[2], 1);
396 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000397#if _LFS64_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200398#if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000399 case F_GETLK64:
400#endif
401 tprintf(", ");
402 printflock64(tcp, tcp->u_arg[2], 1);
403 break;
404#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000405#ifdef F_GETLEASE
406 case F_GETLEASE:
407 if (syserror(tcp))
408 return 0;
409 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
410 return RVAL_HEX|RVAL_STR;
411#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000412 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000413 tprintf(", %#lx", tcp->u_arg[2]);
414 break;
415 }
416 }
417 return 0;
418}
419
420#ifdef LOCK_SH
421
422int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000423sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000424{
425 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300426 printfd(tcp, tcp->u_arg[0]);
427 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000428 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429 }
430 return 0;
431}
432#endif /* LOCK_SH */
433
434int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000435sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000436{
437 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300438 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439 }
440 return 0;
441}
442
443int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000444sys_dup(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000445{
446 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300447 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448 }
449 return 0;
450}
451
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000452static int
453do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454{
455 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300456 printfd(tcp, tcp->u_arg[0]);
457 tprintf(", ");
458 printfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000459 if (flags_arg >= 0) {
460 tprintf(", ");
461 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
462 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463 }
464 return 0;
465}
466
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000467int
468sys_dup2(struct tcb *tcp)
469{
470 return do_dup2(tcp, -1);
471}
472
473#ifdef LINUX
474int
475sys_dup3(struct tcb *tcp)
476{
477 return do_dup2(tcp, 2);
478}
479#endif
480
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000481#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000483sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000484{
485 return 0;
486}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000487#endif /* ALPHA || FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488
489static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000490decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491{
492 int i, j, nfds;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000493 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
494 & -sizeof(long));
495 fd_set *fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496 static char outstr[1024];
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000497 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498 long arg;
499
500 if (entering(tcp)) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000501 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000502 if (fds == NULL)
503 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504 nfds = args[0];
505 tprintf("%d", nfds);
506 for (i = 0; i < 3; i++) {
507 arg = args[i+1];
508 if (arg == 0) {
509 tprintf(", NULL");
510 continue;
511 }
Roland McGrath46100d02005-06-01 18:55:42 +0000512 if (fds == NULL || !verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513 tprintf(", %#lx", arg);
514 continue;
515 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000516 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 tprintf(", [?]");
518 continue;
519 }
520 tprintf(", [");
521 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000522 if (FD_ISSET(j, fds)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300523 tprintf("%s", sep);
524 printfd(tcp, j);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 sep = " ";
526 }
527 }
528 tprintf("]");
529 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000530 free(fds);
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000531 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000532 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200534 else {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535 unsigned int cumlen = 0;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000536 const char *sep = "";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537
538 if (syserror(tcp))
539 return 0;
540
Denys Vlasenko5d645812011-08-20 12:48:18 +0200541 nfds = tcp->u_rval;
542 if (nfds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 tcp->auxstr = "Timeout";
544 return RVAL_STR;
545 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000546
547 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000548 if (fds == NULL)
549 fprintf(stderr, "out of memory\n");
Roland McGrathe85aaa42005-02-06 01:55:12 +0000550
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551 outstr[0] = '\0';
552 for (i = 0; i < 3; i++) {
553 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000554
555 tcp->auxstr = outstr;
556 arg = args[i+1];
Roland McGrath46100d02005-06-01 18:55:42 +0000557 if (fds == NULL || !arg ||
558 umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 continue;
560 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000561 if (FD_ISSET(j, fds)) {
Dmitry V. Levin6e633752010-04-06 23:50:49 +0000562 char str[11 + 3 * sizeof(int)];
563
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 if (first) {
565 sprintf(str, "%s%s [%u", sep,
566 i == 0 ? "in" :
567 i == 1 ? "out" :
568 "except", j);
569 first = 0;
570 sep = ", ";
571 }
572 else
573 sprintf(str, " %u", j);
574 cumlen += strlen(str);
575 if (cumlen < sizeof(outstr))
576 strcat(outstr, str);
577 nfds--;
578 }
579 }
580 if (cumlen)
581 strcat(outstr, "]");
582 if (nfds == 0)
583 break;
584 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000585 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586#ifdef LINUX
587 /* This contains no useful information on SunOS. */
588 if (args[4]) {
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000589 char str[128];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000591 sprintf(str, "%sleft ", sep);
592 sprinttv(tcp, args[4], bitness, str + strlen(str));
593 if ((cumlen += strlen(str)) < sizeof(outstr))
594 strcat(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595 }
596#endif /* LINUX */
597 return RVAL_STR;
598 }
599 return 0;
600}
601
602#ifdef LINUX
603
604int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000605sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606{
607 long args[5];
608
609 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
610 tprintf("[...]");
611 return 0;
612 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000613 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614}
615
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000616#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000617int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000618sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000619{
620 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000621 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000622}
623#endif
624
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000625static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000626#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000627 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000628#endif
629#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000630 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000631#endif
632#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000633 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000634#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000635 { 0, NULL }
636};
637
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000638static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000639#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000640 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000641#endif
642#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000643 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000644#endif
645#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000646 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000647#endif
648#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000649 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000650#endif
651#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000652 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000653#endif
654#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000655 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000656#endif
657#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000658 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000659#endif
660#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000661 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000662#endif
663#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000664 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000665#endif
666#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000667 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000668#endif
669#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000670 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000671#endif
672#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000673 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000674#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000675 { 0, NULL }
676};
677
678int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000679sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000680{
681 if (entering(tcp))
682 tprintf("%ld", tcp->u_arg[0]);
683 return 0;
684}
685
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000686int
687sys_epoll_create1(struct tcb *tcp)
688{
689 if (entering(tcp))
690 printflags(open_mode_flags, tcp->u_arg[0], "O_???");
691 return 0;
692}
693
Roland McGrath63d6e542004-10-20 02:17:41 +0000694#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000695static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000696print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000697{
698 tprintf("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000699 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000700 /* We cannot know what format the program uses, so print u32 and u64
701 which will cover every value. */
702 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
703 ev->data.u32, ev->data.u64);
704}
Roland McGrath63d6e542004-10-20 02:17:41 +0000705#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000706
707int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000708sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000709{
710 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300711 printfd(tcp, tcp->u_arg[0]);
712 tprintf(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000713 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300714 tprintf(", ");
715 printfd(tcp, tcp->u_arg[2]);
716 tprintf(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000717 if (tcp->u_arg[3] == 0)
718 tprintf("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000719 else {
720#ifdef HAVE_SYS_EPOLL_H
721 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000722 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000723 print_epoll_event(&ev);
724 else
725#endif
726 tprintf("{...}");
727 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000728 }
729 return 0;
730}
731
Roland McGrathf2400052007-08-02 01:13:26 +0000732static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000733epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000734{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300735 if (entering(tcp)) {
736 printfd(tcp, tcp->u_arg[0]);
737 tprintf(", ");
738 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000739 if (syserror(tcp))
740 tprintf("%lx", tcp->u_arg[1]);
741 else if (tcp->u_rval == 0)
742 tprintf("{}");
743 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000744#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000745 struct epoll_event ev, *start, *cur, *end;
746 int failed = 0;
747
748 tprintf("{");
749 start = (struct epoll_event *) tcp->u_arg[1];
750 end = start + tcp->u_rval;
751 for (cur = start; cur < end; ++cur) {
752 if (cur > start)
753 tprintf(", ");
754 if (umove(tcp, (long) cur, &ev) == 0)
755 print_epoll_event(&ev);
756 else {
757 tprintf("?");
758 failed = 1;
759 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000760 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000761 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000762 tprintf("}");
763 if (failed)
764 tprintf(" %#lx", (long) start);
765#else
766 tprintf("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000767#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000768 }
769 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
770 }
Roland McGrathf2400052007-08-02 01:13:26 +0000771}
772
773int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000774sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000775{
776 epoll_wait_common(tcp);
777 return 0;
778}
779
780int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000781sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000782{
783 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000784 if (exiting(tcp)) {
785 tprintf(", ");
Roland McGrathf2400052007-08-02 01:13:26 +0000786 print_sigset(tcp, tcp->u_arg[4], 0);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000787 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000788 return 0;
789}
Roland McGrath37b9f842005-05-09 08:02:00 +0000790
791int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000792sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000793{
794 if (entering(tcp))
795 tprintf("%ld, ", tcp->u_arg[0]);
796 else {
797 if (syserror(tcp))
798 tprintf("0x%0lx", tcp->u_arg[1]);
799 else {
800 unsigned long user_id;
801 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
802 tprintf("{%lu}", user_id);
803 else
804 tprintf("{...}");
805 }
806 }
807 return 0;
808}
809
810int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000811sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000812{
813 if (entering(tcp))
814 tprintf("%lu", tcp->u_arg[0]);
815 return 0;
816}
817
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000818#ifdef HAVE_LIBAIO_H
819
Andi Kleendfcd7412011-06-13 22:05:44 +0000820enum iocb_sub {
821 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
822};
823
824static const char *
825iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
826{
Denys Vlasenko79992622011-08-19 19:44:17 +0200827 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
828 static const struct {
Andi Kleendfcd7412011-06-13 22:05:44 +0000829 const char *name;
830 enum iocb_sub sub;
831 } cmds[] = {
832 { "pread", SUB_COMMON },
833 { "pwrite", SUB_COMMON },
834 { "fsync", SUB_NONE },
835 { "fdsync", SUB_NONE },
836 { "op4", SUB_NONE },
837 { "poll", SUB_POLL },
838 { "noop", SUB_NONE },
839 { "preadv", SUB_VECTOR },
840 { "pwritev", SUB_VECTOR },
841 };
842
843 if (cmd < ARRAY_SIZE(cmds)) {
844 *sub = cmds[cmd].sub;
845 return cmds[cmd].name;
846 }
847 *sub = SUB_NONE;
Denys Vlasenko79992622011-08-19 19:44:17 +0200848 sprintf(buf, "%u /* SUB_??? */", cmd);
Andi Kleendfcd7412011-06-13 22:05:44 +0000849 return buf;
850}
851
852/* Not defined in libaio.h */
853#ifndef IOCB_RESFD
854# define IOCB_RESFD (1 << 0)
855#endif
856
857static void
858print_common_flags(struct iocb *iocb)
859{
860 if (iocb->u.c.flags & IOCB_RESFD)
861 tprintf("resfd=%d, ", iocb->u.c.resfd);
862 if (iocb->u.c.flags & ~IOCB_RESFD)
863 tprintf("flags=%x, ", iocb->u.c.flags);
864}
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000865
866#endif /* HAVE_LIBAIO_H */
867
Roland McGrath37b9f842005-05-09 08:02:00 +0000868int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000869sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000870{
871 long nr;
872 if (entering(tcp)) {
873 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
874 nr = tcp->u_arg[1];
875 /* and if nr is negative? */
876 if (nr == 0)
877 tprintf("{}");
878 else {
879#ifdef HAVE_LIBAIO_H
880 long i;
881 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
882
883 for (i = 0; i < nr; i++, iocbs++) {
Andi Kleendfcd7412011-06-13 22:05:44 +0000884 enum iocb_sub sub;
Roland McGrath37b9f842005-05-09 08:02:00 +0000885 struct iocb iocb;
886 if (i == 0)
887 tprintf("{");
888 else
889 tprintf(", ");
890
891 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
892 umove(tcp, (unsigned long)iocbp, &iocb)) {
893 tprintf("{...}");
894 continue;
895 }
Andi Kleendfcd7412011-06-13 22:05:44 +0000896 tprintf("{");
897 if (iocb.data)
898 tprintf("data:%p, ", iocb.data);
899 if (iocb.key)
900 tprintf("key:%u, ", iocb.key);
901 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
902 if (iocb.aio_reqprio)
903 tprintf("reqprio:%d, ", iocb.aio_reqprio);
904 tprintf("filedes:%d", iocb.aio_fildes);
905 switch (sub) {
906 case SUB_COMMON:
907 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
908 tprintf(", str:");
909 printstr(tcp, (unsigned long)iocb.u.c.buf,
910 iocb.u.c.nbytes);
911 } else {
912 tprintf(", buf:%p", iocb.u.c.buf);
913 }
914 tprintf(", nbytes:%lu, offset:%llx",
915 iocb.u.c.nbytes,
916 iocb.u.c.offset);
917 print_common_flags(&iocb);
918 break;
919 case SUB_VECTOR:
920 tprintf(", %llx, ", iocb.u.v.offset);
921 print_common_flags(&iocb);
922 tprint_iov(tcp, iocb.u.v.nr,
923 (unsigned long)iocb.u.v.vec,
924 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
925 break;
926 case SUB_POLL:
927 tprintf(", %x", iocb.u.poll.events);
928 break;
929 case SUB_NONE:
930 break;
931 }
932 tprintf("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000933 }
934 if (i)
935 tprintf("}");
936#else
Andi Kleendfcd7412011-06-13 22:05:44 +0000937#warning "libaio-devel is not available => no io_submit decoding"
938 tprintf("%#lx", tcp->u_arg[2]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000939#endif
940 }
941 }
942 return 0;
943}
944
945int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000946sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000947{
948 if (entering(tcp)) {
949#ifdef HAVE_LIBAIO_H
950 struct iocb iocb;
951#endif
952 tprintf("%lu, ", tcp->u_arg[0]);
953#ifdef HAVE_LIBAIO_H
954 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
955 tprintf("{%p, %u, %hu, %hu, %d}, ",
956 iocb.data, iocb.key,
957 iocb.aio_lio_opcode,
958 iocb.aio_reqprio, iocb.aio_fildes);
959 } else
960#endif
961 tprintf("{...}, ");
962 } else {
963 if (tcp->u_rval < 0)
964 tprintf("{...}");
965 else {
966#ifdef HAVE_LIBAIO_H
967 struct io_event event;
968 if (umove(tcp, tcp->u_arg[2], &event) == 0)
969 tprintf("{%p, %p, %ld, %ld}",
970 event.data, event.obj,
971 event.res, event.res2);
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000972 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000973#endif
974 tprintf("{...}");
975 }
976 }
977 return 0;
978}
979
980int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000981sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000982{
983 if (entering(tcp)) {
984 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
985 tcp->u_arg[2]);
986 } else {
987 if (tcp->u_rval == 0) {
988 tprintf("{}");
989 } else {
990#ifdef HAVE_LIBAIO_H
991 struct io_event *events = (void *)tcp->u_arg[3];
992 long i, nr = tcp->u_rval;
993
994 for (i = 0; i < nr; i++, events++) {
995 struct io_event event;
996
997 if (i == 0)
998 tprintf("{");
999 else
1000 tprintf(", ");
1001
1002 if (umove(tcp, (unsigned long)events, &event) != 0) {
1003 tprintf("{...}");
1004 continue;
1005 }
1006 tprintf("{%p, %p, %ld, %ld}", event.data,
1007 event.obj, event.res, event.res2);
1008 }
1009 tprintf("}, ");
1010#else
1011 tprintf("{...}");
1012#endif
1013 }
1014
Roland McGrath6bc09da2007-11-01 21:50:54 +00001015 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +00001016 }
1017 return 0;
1018}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001019#endif /* LINUX */
1020
1021int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +00001022sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001023{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001024 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001025}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001026
1027#ifdef LINUX
1028int
1029sys_pselect6(struct tcb *tcp)
1030{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001031 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +00001032 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001033 struct {
1034 void *ss;
1035 unsigned long len;
1036 } data;
1037 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1038 tprintf(", %#lx", tcp->u_arg[5]);
1039 else {
1040 tprintf(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +00001041 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001042 tprintf("%#lx", (long)data.ss);
1043 else
1044 print_sigset(tcp, (long)data.ss, 0);
1045 tprintf(", %lu}", data.len);
1046 }
1047 }
1048 return rc;
1049}
Roland McGrathe7c39672007-08-02 01:32:17 +00001050
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001051static int
1052do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +00001053{
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001054 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +00001055 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001056 if (flags_arg >= 0) {
1057 tprintf(", ");
1058 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1059 }
1060 }
Roland McGrathe7c39672007-08-02 01:32:17 +00001061 return 0;
1062}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001063
1064int
1065sys_eventfd(struct tcb *tcp)
1066{
1067 return do_eventfd(tcp, -1);
1068}
1069
1070int
1071sys_eventfd2(struct tcb *tcp)
1072{
1073 return do_eventfd(tcp, 1);
1074}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001075#endif