blob: be327eb47e03b91ea897eefb969c091b745831c1 [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#include <inttypes.h>
Roland McGrath63d6e542004-10-20 02:17:41 +000038#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +000039#include <sys/epoll.h>
40#endif
Roland McGrath37b9f842005-05-09 08:02:00 +000041#ifdef HAVE_LIBAIO_H
42#include <libaio.h>
43#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000044
John Hughes70623be2001-03-08 13:59:00 +000045#if HAVE_LONG_LONG_OFF_T
46/*
47 * Hacks for systems that have a long long off_t
48 */
John Hughesb8c9f772001-03-07 16:53:07 +000049#define flock64 flock /* Horrid hack */
50#define printflock printflock64 /* Horrider hack */
51#endif
52
53
Roland McGrathd9f816f2004-09-04 03:39:20 +000054static const struct xlat fcntlcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000055 { F_DUPFD, "F_DUPFD" },
56 { F_GETFD, "F_GETFD" },
57 { F_SETFD, "F_SETFD" },
58 { F_GETFL, "F_GETFL" },
59 { F_SETFL, "F_SETFL" },
60 { F_GETLK, "F_GETLK" },
61 { F_SETLK, "F_SETLK" },
62 { F_SETLKW, "F_SETLKW" },
63 { F_GETOWN, "F_GETOWN" },
64 { F_SETOWN, "F_SETOWN" },
65#ifdef F_RSETLK
66 { F_RSETLK, "F_RSETLK" },
67#endif
68#ifdef F_RSETLKW
69 { F_RSETLKW, "F_RSETLKW" },
70#endif
71#ifdef F_RGETLK
72 { F_RGETLK, "F_RGETLK" },
73#endif
74#ifdef F_CNVT
75 { F_CNVT, "F_CNVT" },
76#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000077#ifdef F_SETSIG
78 { F_SETSIG, "F_SETSIG" },
79#endif
80#ifdef F_GETSIG
81 { F_GETSIG, "F_GETSIG" },
82#endif
John Hughesbdf48f52001-03-06 15:08:09 +000083#ifdef F_CHKFL
84 { F_CHKFL, "F_CHKFL" },
85#endif
86#ifdef F_DUP2FD
87 { F_DUP2FD, "F_DUP2FD" },
88#endif
89#ifdef F_ALLOCSP
90 { F_ALLOCSP, "F_ALLOCSP" },
91#endif
92#ifdef F_ISSTREAM
93 { F_ISSTREAM, "F_ISSTREAM" },
94#endif
95#ifdef F_PRIV
96 { F_PRIV, "F_PRIV" },
97#endif
98#ifdef F_NPRIV
99 { F_NPRIV, "F_NPRIV" },
100#endif
101#ifdef F_QUOTACL
102 { F_QUOTACL, "F_QUOTACL" },
103#endif
104#ifdef F_BLOCKS
105 { F_BLOCKS, "F_BLOCKS" },
106#endif
107#ifdef F_BLKSIZE
108 { F_BLKSIZE, "F_BLKSIZE" },
109#endif
110#ifdef F_GETOWN
111 { F_GETOWN, "F_GETOWN" },
112#endif
113#ifdef F_SETOWN
114 { F_SETOWN, "F_SETOWN" },
115#endif
116#ifdef F_REVOKE
117 { F_REVOKE, "F_REVOKE" },
118#endif
119#ifdef F_SETLK
120 { F_SETLK, "F_SETLK" },
121#endif
122#ifdef F_SETLKW
123 { F_SETLKW, "F_SETLKW" },
124#endif
125#ifdef F_FREESP
126 { F_FREESP, "F_FREESP" },
127#endif
128#ifdef F_GETLK
129 { F_GETLK, "F_GETLK" },
130#endif
131#ifdef F_SETLK64
132 { F_SETLK64, "F_SETLK64" },
133#endif
134#ifdef F_SETLKW64
135 { F_SETLKW64, "F_SETLKW64" },
136#endif
137#ifdef F_FREESP64
138 { F_FREESP64, "F_FREESP64" },
139#endif
140#ifdef F_GETLK64
141 { F_GETLK64, "F_GETLK64" },
142#endif
143#ifdef F_SHARE
144 { F_SHARE, "F_SHARE" },
145#endif
146#ifdef F_UNSHARE
147 { F_UNSHARE, "F_UNSHARE" },
148#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000149#ifdef F_SETLEASE
150 { F_SETLEASE, "F_SETLEASE" },
151#endif
152#ifdef F_GETLEASE
153 { F_GETLEASE, "F_GETLEASE" },
154#endif
155#ifdef F_NOTIFY
156 { F_NOTIFY, "F_NOTIFY" },
157#endif
158#ifdef F_DUPFD_CLOEXEC
159 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
160#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161 { 0, NULL },
162};
163
Roland McGrathd9f816f2004-09-04 03:39:20 +0000164static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165#ifdef FD_CLOEXEC
166 { FD_CLOEXEC, "FD_CLOEXEC" },
167#endif
168 { 0, NULL },
169};
170
171#ifdef LOCK_SH
172
Roland McGrathd9f816f2004-09-04 03:39:20 +0000173static const struct xlat flockcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174 { LOCK_SH, "LOCK_SH" },
175 { LOCK_EX, "LOCK_EX" },
176 { LOCK_NB, "LOCK_NB" },
177 { LOCK_UN, "LOCK_UN" },
178 { 0, NULL },
179};
180
181#endif /* LOCK_SH */
182
Roland McGrathd9f816f2004-09-04 03:39:20 +0000183static const struct xlat lockfcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000184 { F_RDLCK, "F_RDLCK" },
185 { F_WRLCK, "F_WRLCK" },
186 { F_UNLCK, "F_UNLCK" },
187#ifdef F_EXLCK
188 { F_EXLCK, "F_EXLCK" },
189#endif
190#ifdef F_SHLCK
191 { F_SHLCK, "F_SHLCK" },
192#endif
193 { 0, NULL },
194};
195
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000196#ifdef F_NOTIFY
197static const struct xlat notifyflags[] = {
198#ifdef DN_ACCESS
199 { DN_ACCESS, "DN_ACCESS" },
200#endif
201#ifdef DN_MODIFY
202 { DN_MODIFY, "DN_MODIFY" },
203#endif
204#ifdef DN_CREATE
205 { DN_CREATE, "DN_CREATE" },
206#endif
207#ifdef DN_DELETE
208 { DN_DELETE, "DN_DELETE" },
209#endif
210#ifdef DN_RENAME
211 { DN_RENAME, "DN_RENAME" },
212#endif
213#ifdef DN_ATTRIB
214 { DN_ATTRIB, "DN_ATTRIB" },
215#endif
216#ifdef DN_MULTISHOT
217 { DN_MULTISHOT, "DN_MULTISHOT" },
218#endif
219 { 0, NULL },
220};
221#endif
222
Roland McGrathd9f816f2004-09-04 03:39:20 +0000223static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224 { SEEK_SET, "SEEK_SET" },
225 { SEEK_CUR, "SEEK_CUR" },
226 { SEEK_END, "SEEK_END" },
227 { 0, NULL },
228};
229
John Hughes70623be2001-03-08 13:59:00 +0000230#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231/* fcntl/lockf */
232static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000233printflock(struct tcb *tcp, long addr, int getlk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000234{
235 struct flock fl;
236
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000237#if SUPPORTED_PERSONALITIES > 1
238 if (personality_wordsize[current_personality] != sizeof(fl.l_start)) {
239 if (personality_wordsize[current_personality] == 4) {
240 /* 32-bit x86 app on x86_64 and similar cases */
241 struct {
242 short int l_type;
243 short int l_whence;
244 int32_t l_start; /* off_t */
245 int32_t l_len; /* off_t */
246 int32_t l_pid; /* pid_t */
247 } fl32;
248 if (umove(tcp, addr, &fl32) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200249 tprints("{...}");
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000250 return;
251 }
252 fl.l_type = fl32.l_type;
253 fl.l_whence = fl32.l_whence;
254 fl.l_start = fl32.l_start;
255 fl.l_len = fl32.l_len;
256 fl.l_pid = fl32.l_pid;
257 } else {
258 /* let people know we have a problem here */
259 tprintf("{ <decode error: unsupported wordsize %d> }",
260 personality_wordsize[current_personality]);
261 return;
262 }
263 } else
264#endif
265 {
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000266 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200267 tprints("{...}");
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000268 return;
269 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200271 tprints("{type=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200273 tprints(", whence=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 printxval(whence, fl.l_whence, "SEEK_???");
275 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
276 if (getlk)
277 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
278 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200279 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280}
John Hughesb8c9f772001-03-07 16:53:07 +0000281#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282
John Hughes70623be2001-03-08 13:59:00 +0000283#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000284/* fcntl/lockf */
285static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000286printflock64(struct tcb *tcp, long addr, int getlk)
John Hughesbdf48f52001-03-06 15:08:09 +0000287{
288 struct flock64 fl;
289
290 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200291 tprints("{...}");
John Hughesbdf48f52001-03-06 15:08:09 +0000292 return;
293 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200294 tprints("{type=");
John Hughesbdf48f52001-03-06 15:08:09 +0000295 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200296 tprints(", whence=");
John Hughesbdf48f52001-03-06 15:08:09 +0000297 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000298 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000299 if (getlk)
300 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
301 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200302 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +0000303}
304#endif
305
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000306int
307sys_fcntl(struct tcb *tcp)
308{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300310 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200311 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
313 switch (tcp->u_arg[1]) {
314 case F_SETFD:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200315 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000316 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317 break;
318 case F_SETOWN: case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000319#ifdef F_DUPFD_CLOEXEC
320 case F_DUPFD_CLOEXEC:
321#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000322 tprintf(", %ld", tcp->u_arg[2]);
323 break;
324 case F_SETFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200325 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000326 tprint_open_modes(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 break;
328 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000329#ifdef F_FREESP
330 case F_FREESP:
331#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200332 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 printflock(tcp, tcp->u_arg[2], 0);
334 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000335#if _LFS64_LARGEFILE
336#ifdef F_FREESP64
337 case F_FREESP64:
338#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000339 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000340 even though the kernel has different values - as does Solaris. */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000341#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000342 case F_SETLK64:
343#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000344#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
John Hughesbdf48f52001-03-06 15:08:09 +0000345 case F_SETLKW64:
346#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200347 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000348 printflock64(tcp, tcp->u_arg[2], 0);
349 break;
350#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000351#ifdef F_NOTIFY
352 case F_NOTIFY:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200353 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000354 printflags(notifyflags, tcp->u_arg[2], "DN_???");
355 break;
356#endif
357#ifdef F_SETLEASE
358 case F_SETLEASE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200359 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000360 printxval(lockfcmds, tcp->u_arg[2], "F_???");
361 break;
362#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000363 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000364 }
365 else {
366 switch (tcp->u_arg[1]) {
367 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000368#ifdef F_DUPFD_CLOEXEC
369 case F_DUPFD_CLOEXEC:
370#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000371 case F_SETFD: case F_SETFL:
372 case F_SETLK: case F_SETLKW:
373 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000374#ifdef F_NOTIFY
375 case F_NOTIFY:
376#endif
377#ifdef F_SETLEASE
378 case F_SETLEASE:
379#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380 break;
381 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000382 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000384 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385 return RVAL_HEX|RVAL_STR;
386 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000387 if (syserror(tcp))
388 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000389 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000390 return RVAL_HEX|RVAL_STR;
391 case F_GETLK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200392 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393 printflock(tcp, tcp->u_arg[2], 1);
394 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000395#if _LFS64_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200396#if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000397 case F_GETLK64:
398#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200399 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000400 printflock64(tcp, tcp->u_arg[2], 1);
401 break;
402#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000403#ifdef F_GETLEASE
404 case F_GETLEASE:
405 if (syserror(tcp))
406 return 0;
407 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
408 return RVAL_HEX|RVAL_STR;
409#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000410 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000411 tprintf(", %#lx", tcp->u_arg[2]);
412 break;
413 }
414 }
415 return 0;
416}
417
418#ifdef LOCK_SH
419
420int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000421sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422{
423 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300424 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200425 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000426 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000427 }
428 return 0;
429}
430#endif /* LOCK_SH */
431
432int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000433sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000434{
435 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300436 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437 }
438 return 0;
439}
440
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000441static int
442do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000443{
444 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300445 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200446 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300447 printfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000448 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200449 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000450 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
451 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 }
453 return 0;
454}
455
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000456int
457sys_dup2(struct tcb *tcp)
458{
459 return do_dup2(tcp, -1);
460}
461
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000462int
463sys_dup3(struct tcb *tcp)
464{
465 return do_dup2(tcp, 2);
466}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000467
Denys Vlasenko84703742012-02-25 02:38:52 +0100468#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000470sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471{
472 return 0;
473}
Denys Vlasenko84703742012-02-25 02:38:52 +0100474#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000475
476static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000477decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478{
Denys Vlasenkoad5155a2011-09-01 18:18:04 +0200479 int i, j;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200480 unsigned nfds, fdsize;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000481 fd_set *fds;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000482 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000483 long arg;
484
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200485 fdsize = args[0];
486 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
487 if (args[0] > 1024*1024)
488 fdsize = 1024*1024;
489 if (args[0] < 0)
490 fdsize = 0;
491 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
492
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000493 if (entering(tcp)) {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200494 fds = malloc(fdsize);
495 if (!fds)
496 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497 nfds = args[0];
498 tprintf("%d", nfds);
499 for (i = 0; i < 3; i++) {
500 arg = args[i+1];
501 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200502 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000503 continue;
504 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200505 if (!verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506 tprintf(", %#lx", arg);
507 continue;
508 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000509 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200510 tprints(", [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511 continue;
512 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200513 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000515 if (FD_ISSET(j, fds)) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200516 tprints(sep);
Dmitry V. Levin31382132011-03-04 05:08:02 +0300517 printfd(tcp, j);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000518 sep = " ";
519 }
520 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000523 free(fds);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200524 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000525 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200527 else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200528 static char outstr[1024];
529 char *outptr;
530#define end_outstr (outstr + sizeof(outstr))
531 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532
533 if (syserror(tcp))
534 return 0;
535
Denys Vlasenko5d645812011-08-20 12:48:18 +0200536 nfds = tcp->u_rval;
537 if (nfds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 tcp->auxstr = "Timeout";
539 return RVAL_STR;
540 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000541
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200542 fds = malloc(fdsize);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200543 if (!fds)
544 die_out_of_memory();
Roland McGrathe85aaa42005-02-06 01:55:12 +0000545
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200546 outptr = outstr;
547 sep = "";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548 for (i = 0; i < 3; i++) {
549 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551 arg = args[i+1];
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200552 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000553 continue;
554 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000555 if (FD_ISSET(j, fds)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200556 /* +2 chars needed at the end: ']',NUL */
557 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
558 if (first) {
559 outptr += sprintf(outptr, "%s%s [%u",
560 sep,
561 i == 0 ? "in" : i == 1 ? "out" : "except",
562 j
563 );
564 first = 0;
565 sep = ", ";
566 }
567 else {
568 outptr += sprintf(outptr, " %u", j);
569 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 nfds--;
572 }
573 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200574 if (outptr != outstr)
575 *outptr++ = ']';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000576 if (nfds == 0)
577 break;
578 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000579 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580 /* This contains no useful information on SunOS. */
581 if (args[4]) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100582 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200583 outptr += sprintf(outptr, "%sleft ", sep);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100584 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200585 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200587 *outptr = '\0';
Denys Vlasenko11617252011-09-01 11:27:37 +0200588 tcp->auxstr = outstr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200590#undef end_outstr
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591 }
592 return 0;
593}
594
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595
596int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000597sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598{
599 long args[5];
600
601 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200602 tprints("[...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000603 return 0;
604 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000605 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606}
607
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000608#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000609int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000610sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000611{
612 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000613 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000614}
615#endif
616
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000617static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000618#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000619 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000620#endif
621#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000622 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000623#endif
624#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000625 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000626#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000627 { 0, NULL }
628};
629
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000630static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000631#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000632 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000633#endif
634#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000635 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000636#endif
637#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000638 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000639#endif
640#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000641 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000642#endif
643#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000644 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000645#endif
646#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000647 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000648#endif
649#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000650 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000651#endif
652#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000653 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000654#endif
655#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000656 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000657#endif
658#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000659 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000660#endif
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000661#ifdef EPOLLRDHUP
662 { EPOLLRDHUP, "EPOLLRDHUP" },
663#endif
Roland McGrath63d6e542004-10-20 02:17:41 +0000664#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000665 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000666#endif
667#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000668 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000669#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000670 { 0, NULL }
671};
672
673int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000674sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000675{
676 if (entering(tcp))
677 tprintf("%ld", tcp->u_arg[0]);
678 return 0;
679}
680
Mike Frysingeraed334c2011-10-13 22:33:45 -0400681static const struct xlat epollflags[] = {
682#ifdef EPOLL_CLOEXEC
683 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
684#endif
685#ifdef EPOLL_NONBLOCK
686 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
687#endif
688 { 0, NULL }
689};
690
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000691int
692sys_epoll_create1(struct tcb *tcp)
693{
694 if (entering(tcp))
Mike Frysingeraed334c2011-10-13 22:33:45 -0400695 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000696 return 0;
697}
698
Roland McGrath63d6e542004-10-20 02:17:41 +0000699#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000700static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000701print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000702{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200703 tprints("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000704 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000705 /* We cannot know what format the program uses, so print u32 and u64
706 which will cover every value. */
707 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
708 ev->data.u32, ev->data.u64);
709}
Roland McGrath63d6e542004-10-20 02:17:41 +0000710#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000711
712int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000713sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000714{
715 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300716 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200717 tprints(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000718 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200719 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300720 printfd(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200721 tprints(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000722 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200723 tprints("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000724 else {
725#ifdef HAVE_SYS_EPOLL_H
726 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000727 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000728 print_epoll_event(&ev);
729 else
730#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200731 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000732 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000733 }
734 return 0;
735}
736
Roland McGrathf2400052007-08-02 01:13:26 +0000737static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000738epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000739{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300740 if (entering(tcp)) {
741 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200742 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300743 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000744 if (syserror(tcp))
745 tprintf("%lx", tcp->u_arg[1]);
746 else if (tcp->u_rval == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200747 tprints("{}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000748 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000749#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000750 struct epoll_event ev, *start, *cur, *end;
751 int failed = 0;
752
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200753 tprints("{");
Roland McGrathaa524c82005-06-01 19:22:06 +0000754 start = (struct epoll_event *) tcp->u_arg[1];
755 end = start + tcp->u_rval;
756 for (cur = start; cur < end; ++cur) {
757 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200758 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000759 if (umove(tcp, (long) cur, &ev) == 0)
760 print_epoll_event(&ev);
761 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200762 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000763 failed = 1;
764 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000765 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000766 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200767 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000768 if (failed)
769 tprintf(" %#lx", (long) start);
770#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200771 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000772#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000773 }
Dmitry V. Levinc327d712011-10-11 16:05:57 +0000774 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
Roland McGrath93817bf2004-10-06 22:23:31 +0000775 }
Roland McGrathf2400052007-08-02 01:13:26 +0000776}
777
778int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000779sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000780{
781 epoll_wait_common(tcp);
782 return 0;
783}
784
785int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000786sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000787{
788 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000789 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200790 tprints(", ");
Roland McGrathf2400052007-08-02 01:13:26 +0000791 print_sigset(tcp, tcp->u_arg[4], 0);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000792 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000793 return 0;
794}
Roland McGrath37b9f842005-05-09 08:02:00 +0000795
796int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000797sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000798{
799 if (entering(tcp))
800 tprintf("%ld, ", tcp->u_arg[0]);
801 else {
802 if (syserror(tcp))
803 tprintf("0x%0lx", tcp->u_arg[1]);
804 else {
805 unsigned long user_id;
806 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
807 tprintf("{%lu}", user_id);
808 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200809 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000810 }
811 }
812 return 0;
813}
814
815int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000816sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000817{
818 if (entering(tcp))
819 tprintf("%lu", tcp->u_arg[0]);
820 return 0;
821}
822
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000823#ifdef HAVE_LIBAIO_H
824
Andi Kleendfcd7412011-06-13 22:05:44 +0000825enum iocb_sub {
826 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
827};
828
829static const char *
830iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
831{
Denys Vlasenko79992622011-08-19 19:44:17 +0200832 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
833 static const struct {
Andi Kleendfcd7412011-06-13 22:05:44 +0000834 const char *name;
835 enum iocb_sub sub;
836 } cmds[] = {
837 { "pread", SUB_COMMON },
838 { "pwrite", SUB_COMMON },
839 { "fsync", SUB_NONE },
840 { "fdsync", SUB_NONE },
841 { "op4", SUB_NONE },
842 { "poll", SUB_POLL },
843 { "noop", SUB_NONE },
844 { "preadv", SUB_VECTOR },
845 { "pwritev", SUB_VECTOR },
846 };
847
848 if (cmd < ARRAY_SIZE(cmds)) {
849 *sub = cmds[cmd].sub;
850 return cmds[cmd].name;
851 }
852 *sub = SUB_NONE;
Denys Vlasenko79992622011-08-19 19:44:17 +0200853 sprintf(buf, "%u /* SUB_??? */", cmd);
Andi Kleendfcd7412011-06-13 22:05:44 +0000854 return buf;
855}
856
857/* Not defined in libaio.h */
858#ifndef IOCB_RESFD
859# define IOCB_RESFD (1 << 0)
860#endif
861
862static void
863print_common_flags(struct iocb *iocb)
864{
865 if (iocb->u.c.flags & IOCB_RESFD)
866 tprintf("resfd=%d, ", iocb->u.c.resfd);
867 if (iocb->u.c.flags & ~IOCB_RESFD)
868 tprintf("flags=%x, ", iocb->u.c.flags);
869}
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000870
871#endif /* HAVE_LIBAIO_H */
872
Roland McGrath37b9f842005-05-09 08:02:00 +0000873int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000874sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000875{
876 long nr;
877 if (entering(tcp)) {
878 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
879 nr = tcp->u_arg[1];
880 /* and if nr is negative? */
881 if (nr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200882 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000883 else {
884#ifdef HAVE_LIBAIO_H
885 long i;
886 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
887
888 for (i = 0; i < nr; i++, iocbs++) {
Andi Kleendfcd7412011-06-13 22:05:44 +0000889 enum iocb_sub sub;
Roland McGrath37b9f842005-05-09 08:02:00 +0000890 struct iocb iocb;
891 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200892 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +0000893 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200894 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000895
896 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
897 umove(tcp, (unsigned long)iocbp, &iocb)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200898 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000899 continue;
900 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200901 tprints("{");
Andi Kleendfcd7412011-06-13 22:05:44 +0000902 if (iocb.data)
903 tprintf("data:%p, ", iocb.data);
904 if (iocb.key)
905 tprintf("key:%u, ", iocb.key);
906 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
907 if (iocb.aio_reqprio)
908 tprintf("reqprio:%d, ", iocb.aio_reqprio);
909 tprintf("filedes:%d", iocb.aio_fildes);
910 switch (sub) {
911 case SUB_COMMON:
912 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200913 tprints(", str:");
Andi Kleendfcd7412011-06-13 22:05:44 +0000914 printstr(tcp, (unsigned long)iocb.u.c.buf,
915 iocb.u.c.nbytes);
916 } else {
917 tprintf(", buf:%p", iocb.u.c.buf);
918 }
919 tprintf(", nbytes:%lu, offset:%llx",
920 iocb.u.c.nbytes,
921 iocb.u.c.offset);
922 print_common_flags(&iocb);
923 break;
924 case SUB_VECTOR:
925 tprintf(", %llx, ", iocb.u.v.offset);
926 print_common_flags(&iocb);
927 tprint_iov(tcp, iocb.u.v.nr,
928 (unsigned long)iocb.u.v.vec,
929 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
930 break;
931 case SUB_POLL:
932 tprintf(", %x", iocb.u.poll.events);
933 break;
934 case SUB_NONE:
935 break;
936 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200937 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000938 }
939 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200940 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000941#else
Andi Kleendfcd7412011-06-13 22:05:44 +0000942#warning "libaio-devel is not available => no io_submit decoding"
943 tprintf("%#lx", tcp->u_arg[2]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000944#endif
945 }
946 }
947 return 0;
948}
949
950int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000951sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000952{
953 if (entering(tcp)) {
954#ifdef HAVE_LIBAIO_H
955 struct iocb iocb;
956#endif
957 tprintf("%lu, ", tcp->u_arg[0]);
958#ifdef HAVE_LIBAIO_H
959 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
960 tprintf("{%p, %u, %hu, %hu, %d}, ",
961 iocb.data, iocb.key,
962 iocb.aio_lio_opcode,
963 iocb.aio_reqprio, iocb.aio_fildes);
964 } else
965#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200966 tprints("{...}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000967 } else {
968 if (tcp->u_rval < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200969 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000970 else {
971#ifdef HAVE_LIBAIO_H
972 struct io_event event;
973 if (umove(tcp, tcp->u_arg[2], &event) == 0)
974 tprintf("{%p, %p, %ld, %ld}",
975 event.data, event.obj,
976 event.res, event.res2);
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000977 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000978#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200979 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000980 }
981 }
982 return 0;
983}
984
985int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000986sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000987{
988 if (entering(tcp)) {
989 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
990 tcp->u_arg[2]);
991 } else {
992 if (tcp->u_rval == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200993 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000994 } else {
995#ifdef HAVE_LIBAIO_H
996 struct io_event *events = (void *)tcp->u_arg[3];
997 long i, nr = tcp->u_rval;
998
999 for (i = 0; i < nr; i++, events++) {
1000 struct io_event event;
1001
1002 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001003 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +00001004 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001005 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001006
1007 if (umove(tcp, (unsigned long)events, &event) != 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001008 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001009 continue;
1010 }
1011 tprintf("{%p, %p, %ld, %ld}", event.data,
1012 event.obj, event.res, event.res2);
1013 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001014 tprints("}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001015#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001016 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001017#endif
1018 }
1019
Roland McGrath6bc09da2007-11-01 21:50:54 +00001020 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +00001021 }
1022 return 0;
1023}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001024
1025int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +00001026sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001028 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001029}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001030
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001031int
1032sys_pselect6(struct tcb *tcp)
1033{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001034 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +00001035 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001036 struct {
1037 void *ss;
1038 unsigned long len;
1039 } data;
1040 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1041 tprintf(", %#lx", tcp->u_arg[5]);
1042 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001043 tprints(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +00001044 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001045 tprintf("%#lx", (long)data.ss);
1046 else
1047 print_sigset(tcp, (long)data.ss, 0);
1048 tprintf(", %lu}", data.len);
1049 }
1050 }
1051 return rc;
1052}
Roland McGrathe7c39672007-08-02 01:32:17 +00001053
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001054static int
1055do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +00001056{
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001057 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +00001058 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001059 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001060 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001061 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1062 }
1063 }
Roland McGrathe7c39672007-08-02 01:32:17 +00001064 return 0;
1065}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001066
1067int
1068sys_eventfd(struct tcb *tcp)
1069{
1070 return do_eventfd(tcp, -1);
1071}
1072
1073int
1074sys_eventfd2(struct tcb *tcp)
1075{
1076 return do_eventfd(tcp, 1);
1077}