blob: ee9aacc631e9db752e28b973a83c68174b1dd463 [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) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200251 tprints("{...}");
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000252 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) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200269 tprints("{...}");
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000270 return;
271 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200273 tprints("{type=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200275 tprints(", whence=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000276 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
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200281 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000282}
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) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200293 tprints("{...}");
John Hughesbdf48f52001-03-06 15:08:09 +0000294 return;
295 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200296 tprints("{type=");
John Hughesbdf48f52001-03-06 15:08:09 +0000297 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200298 tprints(", whence=");
John Hughesbdf48f52001-03-06 15:08:09 +0000299 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
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200304 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +0000305}
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]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200313 tprints(", ");
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:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200317 tprints(", ");
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:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200327 tprints(", ");
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
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200334 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000335 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
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200349 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000350 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:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200355 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000356 printflags(notifyflags, tcp->u_arg[2], "DN_???");
357 break;
358#endif
359#ifdef F_SETLEASE
360 case F_SETLEASE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200361 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000362 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:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200394 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000395 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
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200401 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000402 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]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200427 tprints(", ");
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]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200457 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300458 printfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000459 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200460 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000461 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{
Denys Vlasenkoad5155a2011-09-01 18:18:04 +0200492 int i, j;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200493 unsigned nfds, fdsize;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000494 fd_set *fds;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000495 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496 long arg;
497
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200498 fdsize = args[0];
499 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
500 if (args[0] > 1024*1024)
501 fdsize = 1024*1024;
502 if (args[0] < 0)
503 fdsize = 0;
504 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
505
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506 if (entering(tcp)) {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200507 fds = malloc(fdsize);
508 if (!fds)
509 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000510 nfds = args[0];
511 tprintf("%d", nfds);
512 for (i = 0; i < 3; i++) {
513 arg = args[i+1];
514 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200515 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 continue;
517 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200518 if (!verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519 tprintf(", %#lx", arg);
520 continue;
521 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000522 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200523 tprints(", [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000524 continue;
525 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200526 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000528 if (FD_ISSET(j, fds)) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200529 tprints(sep);
Dmitry V. Levin31382132011-03-04 05:08:02 +0300530 printfd(tcp, j);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 sep = " ";
532 }
533 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200534 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000536 free(fds);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200537 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000538 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000539 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200540 else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200541 static char outstr[1024];
542 char *outptr;
543#define end_outstr (outstr + sizeof(outstr))
544 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545
546 if (syserror(tcp))
547 return 0;
548
Denys Vlasenko5d645812011-08-20 12:48:18 +0200549 nfds = tcp->u_rval;
550 if (nfds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000551 tcp->auxstr = "Timeout";
552 return RVAL_STR;
553 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000554
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200555 fds = malloc(fdsize);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200556 if (!fds)
557 die_out_of_memory();
Roland McGrathe85aaa42005-02-06 01:55:12 +0000558
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200559 outptr = outstr;
560 sep = "";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561 for (i = 0; i < 3; i++) {
562 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000563
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 arg = args[i+1];
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200565 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 continue;
567 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000568 if (FD_ISSET(j, fds)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200569 /* +2 chars needed at the end: ']',NUL */
570 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
571 if (first) {
572 outptr += sprintf(outptr, "%s%s [%u",
573 sep,
574 i == 0 ? "in" : i == 1 ? "out" : "except",
575 j
576 );
577 first = 0;
578 sep = ", ";
579 }
580 else {
581 outptr += sprintf(outptr, " %u", j);
582 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584 nfds--;
585 }
586 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200587 if (outptr != outstr)
588 *outptr++ = ']';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589 if (nfds == 0)
590 break;
591 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000592 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593#ifdef LINUX
594 /* This contains no useful information on SunOS. */
595 if (args[4]) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200596 if (outptr < end_outstr - 128) {
597 outptr += sprintf(outptr, "%sleft ", sep);
598 outptr = sprinttv(tcp, args[4], bitness, outptr);
599 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 }
601#endif /* LINUX */
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200602 *outptr = '\0';
Denys Vlasenko11617252011-09-01 11:27:37 +0200603 tcp->auxstr = outstr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200605#undef end_outstr
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606 }
607 return 0;
608}
609
610#ifdef LINUX
611
612int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000613sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614{
615 long args[5];
616
617 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200618 tprints("[...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000619 return 0;
620 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000621 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000622}
623
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000624#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000625int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000626sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000627{
628 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000629 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000630}
631#endif
632
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000633static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000634#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000635 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000636#endif
637#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000638 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000639#endif
640#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000641 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000642#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000643 { 0, NULL }
644};
645
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000646static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000647#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000648 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000649#endif
650#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000651 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000652#endif
653#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000654 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000655#endif
656#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000657 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000658#endif
659#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000660 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000661#endif
662#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000663 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000664#endif
665#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000666 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000667#endif
668#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000669 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000670#endif
671#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000672 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000673#endif
674#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000675 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000676#endif
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000677#ifdef EPOLLRDHUP
678 { EPOLLRDHUP, "EPOLLRDHUP" },
679#endif
Roland McGrath63d6e542004-10-20 02:17:41 +0000680#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000681 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000682#endif
683#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000684 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000685#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000686 { 0, NULL }
687};
688
689int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000690sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000691{
692 if (entering(tcp))
693 tprintf("%ld", tcp->u_arg[0]);
694 return 0;
695}
696
Mike Frysingeraed334c2011-10-13 22:33:45 -0400697static const struct xlat epollflags[] = {
698#ifdef EPOLL_CLOEXEC
699 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
700#endif
701#ifdef EPOLL_NONBLOCK
702 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
703#endif
704 { 0, NULL }
705};
706
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000707int
708sys_epoll_create1(struct tcb *tcp)
709{
710 if (entering(tcp))
Mike Frysingeraed334c2011-10-13 22:33:45 -0400711 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000712 return 0;
713}
714
Roland McGrath63d6e542004-10-20 02:17:41 +0000715#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000716static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000717print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000718{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200719 tprints("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000720 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000721 /* We cannot know what format the program uses, so print u32 and u64
722 which will cover every value. */
723 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
724 ev->data.u32, ev->data.u64);
725}
Roland McGrath63d6e542004-10-20 02:17:41 +0000726#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000727
728int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000729sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000730{
731 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300732 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200733 tprints(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000734 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200735 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300736 printfd(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200737 tprints(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000738 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200739 tprints("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000740 else {
741#ifdef HAVE_SYS_EPOLL_H
742 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000743 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000744 print_epoll_event(&ev);
745 else
746#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200747 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000748 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000749 }
750 return 0;
751}
752
Roland McGrathf2400052007-08-02 01:13:26 +0000753static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000754epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000755{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300756 if (entering(tcp)) {
757 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200758 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300759 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000760 if (syserror(tcp))
761 tprintf("%lx", tcp->u_arg[1]);
762 else if (tcp->u_rval == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200763 tprints("{}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000764 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000765#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000766 struct epoll_event ev, *start, *cur, *end;
767 int failed = 0;
768
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200769 tprints("{");
Roland McGrathaa524c82005-06-01 19:22:06 +0000770 start = (struct epoll_event *) tcp->u_arg[1];
771 end = start + tcp->u_rval;
772 for (cur = start; cur < end; ++cur) {
773 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200774 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000775 if (umove(tcp, (long) cur, &ev) == 0)
776 print_epoll_event(&ev);
777 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200778 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000779 failed = 1;
780 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000781 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000782 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200783 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000784 if (failed)
785 tprintf(" %#lx", (long) start);
786#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200787 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000788#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000789 }
Dmitry V. Levinc327d712011-10-11 16:05:57 +0000790 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
Roland McGrath93817bf2004-10-06 22:23:31 +0000791 }
Roland McGrathf2400052007-08-02 01:13:26 +0000792}
793
794int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000795sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000796{
797 epoll_wait_common(tcp);
798 return 0;
799}
800
801int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000802sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000803{
804 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000805 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200806 tprints(", ");
Roland McGrathf2400052007-08-02 01:13:26 +0000807 print_sigset(tcp, tcp->u_arg[4], 0);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000808 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000809 return 0;
810}
Roland McGrath37b9f842005-05-09 08:02:00 +0000811
812int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000813sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000814{
815 if (entering(tcp))
816 tprintf("%ld, ", tcp->u_arg[0]);
817 else {
818 if (syserror(tcp))
819 tprintf("0x%0lx", tcp->u_arg[1]);
820 else {
821 unsigned long user_id;
822 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
823 tprintf("{%lu}", user_id);
824 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200825 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000826 }
827 }
828 return 0;
829}
830
831int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000832sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000833{
834 if (entering(tcp))
835 tprintf("%lu", tcp->u_arg[0]);
836 return 0;
837}
838
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000839#ifdef HAVE_LIBAIO_H
840
Andi Kleendfcd7412011-06-13 22:05:44 +0000841enum iocb_sub {
842 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
843};
844
845static const char *
846iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
847{
Denys Vlasenko79992622011-08-19 19:44:17 +0200848 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
849 static const struct {
Andi Kleendfcd7412011-06-13 22:05:44 +0000850 const char *name;
851 enum iocb_sub sub;
852 } cmds[] = {
853 { "pread", SUB_COMMON },
854 { "pwrite", SUB_COMMON },
855 { "fsync", SUB_NONE },
856 { "fdsync", SUB_NONE },
857 { "op4", SUB_NONE },
858 { "poll", SUB_POLL },
859 { "noop", SUB_NONE },
860 { "preadv", SUB_VECTOR },
861 { "pwritev", SUB_VECTOR },
862 };
863
864 if (cmd < ARRAY_SIZE(cmds)) {
865 *sub = cmds[cmd].sub;
866 return cmds[cmd].name;
867 }
868 *sub = SUB_NONE;
Denys Vlasenko79992622011-08-19 19:44:17 +0200869 sprintf(buf, "%u /* SUB_??? */", cmd);
Andi Kleendfcd7412011-06-13 22:05:44 +0000870 return buf;
871}
872
873/* Not defined in libaio.h */
874#ifndef IOCB_RESFD
875# define IOCB_RESFD (1 << 0)
876#endif
877
878static void
879print_common_flags(struct iocb *iocb)
880{
881 if (iocb->u.c.flags & IOCB_RESFD)
882 tprintf("resfd=%d, ", iocb->u.c.resfd);
883 if (iocb->u.c.flags & ~IOCB_RESFD)
884 tprintf("flags=%x, ", iocb->u.c.flags);
885}
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000886
887#endif /* HAVE_LIBAIO_H */
888
Roland McGrath37b9f842005-05-09 08:02:00 +0000889int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000890sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000891{
892 long nr;
893 if (entering(tcp)) {
894 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
895 nr = tcp->u_arg[1];
896 /* and if nr is negative? */
897 if (nr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200898 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000899 else {
900#ifdef HAVE_LIBAIO_H
901 long i;
902 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
903
904 for (i = 0; i < nr; i++, iocbs++) {
Andi Kleendfcd7412011-06-13 22:05:44 +0000905 enum iocb_sub sub;
Roland McGrath37b9f842005-05-09 08:02:00 +0000906 struct iocb iocb;
907 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200908 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +0000909 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200910 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000911
912 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
913 umove(tcp, (unsigned long)iocbp, &iocb)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200914 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000915 continue;
916 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200917 tprints("{");
Andi Kleendfcd7412011-06-13 22:05:44 +0000918 if (iocb.data)
919 tprintf("data:%p, ", iocb.data);
920 if (iocb.key)
921 tprintf("key:%u, ", iocb.key);
922 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
923 if (iocb.aio_reqprio)
924 tprintf("reqprio:%d, ", iocb.aio_reqprio);
925 tprintf("filedes:%d", iocb.aio_fildes);
926 switch (sub) {
927 case SUB_COMMON:
928 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200929 tprints(", str:");
Andi Kleendfcd7412011-06-13 22:05:44 +0000930 printstr(tcp, (unsigned long)iocb.u.c.buf,
931 iocb.u.c.nbytes);
932 } else {
933 tprintf(", buf:%p", iocb.u.c.buf);
934 }
935 tprintf(", nbytes:%lu, offset:%llx",
936 iocb.u.c.nbytes,
937 iocb.u.c.offset);
938 print_common_flags(&iocb);
939 break;
940 case SUB_VECTOR:
941 tprintf(", %llx, ", iocb.u.v.offset);
942 print_common_flags(&iocb);
943 tprint_iov(tcp, iocb.u.v.nr,
944 (unsigned long)iocb.u.v.vec,
945 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
946 break;
947 case SUB_POLL:
948 tprintf(", %x", iocb.u.poll.events);
949 break;
950 case SUB_NONE:
951 break;
952 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200953 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000954 }
955 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200956 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000957#else
Andi Kleendfcd7412011-06-13 22:05:44 +0000958#warning "libaio-devel is not available => no io_submit decoding"
959 tprintf("%#lx", tcp->u_arg[2]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000960#endif
961 }
962 }
963 return 0;
964}
965
966int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000967sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000968{
969 if (entering(tcp)) {
970#ifdef HAVE_LIBAIO_H
971 struct iocb iocb;
972#endif
973 tprintf("%lu, ", tcp->u_arg[0]);
974#ifdef HAVE_LIBAIO_H
975 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
976 tprintf("{%p, %u, %hu, %hu, %d}, ",
977 iocb.data, iocb.key,
978 iocb.aio_lio_opcode,
979 iocb.aio_reqprio, iocb.aio_fildes);
980 } else
981#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200982 tprints("{...}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000983 } else {
984 if (tcp->u_rval < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200985 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000986 else {
987#ifdef HAVE_LIBAIO_H
988 struct io_event event;
989 if (umove(tcp, tcp->u_arg[2], &event) == 0)
990 tprintf("{%p, %p, %ld, %ld}",
991 event.data, event.obj,
992 event.res, event.res2);
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000993 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000994#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200995 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000996 }
997 }
998 return 0;
999}
1000
1001int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +00001002sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +00001003{
1004 if (entering(tcp)) {
1005 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
1006 tcp->u_arg[2]);
1007 } else {
1008 if (tcp->u_rval == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001009 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001010 } else {
1011#ifdef HAVE_LIBAIO_H
1012 struct io_event *events = (void *)tcp->u_arg[3];
1013 long i, nr = tcp->u_rval;
1014
1015 for (i = 0; i < nr; i++, events++) {
1016 struct io_event event;
1017
1018 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001019 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +00001020 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001021 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001022
1023 if (umove(tcp, (unsigned long)events, &event) != 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001024 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001025 continue;
1026 }
1027 tprintf("{%p, %p, %ld, %ld}", event.data,
1028 event.obj, event.res, event.res2);
1029 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001030 tprints("}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001031#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001032 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001033#endif
1034 }
1035
Roland McGrath6bc09da2007-11-01 21:50:54 +00001036 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +00001037 }
1038 return 0;
1039}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001040#endif /* LINUX */
1041
1042int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +00001043sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001044{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001045 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001046}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001047
1048#ifdef LINUX
1049int
1050sys_pselect6(struct tcb *tcp)
1051{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001052 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +00001053 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001054 struct {
1055 void *ss;
1056 unsigned long len;
1057 } data;
1058 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1059 tprintf(", %#lx", tcp->u_arg[5]);
1060 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001061 tprints(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +00001062 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001063 tprintf("%#lx", (long)data.ss);
1064 else
1065 print_sigset(tcp, (long)data.ss, 0);
1066 tprintf(", %lu}", data.len);
1067 }
1068 }
1069 return rc;
1070}
Roland McGrathe7c39672007-08-02 01:32:17 +00001071
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001072static int
1073do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +00001074{
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001075 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +00001076 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001077 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001078 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001079 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1080 }
1081 }
Roland McGrathe7c39672007-08-02 01:32:17 +00001082 return 0;
1083}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001084
1085int
1086sys_eventfd(struct tcb *tcp)
1087{
1088 return do_eventfd(tcp, -1);
1089}
1090
1091int
1092sys_eventfd2(struct tcb *tcp)
1093{
1094 return do_eventfd(tcp, 1);
1095}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001096#endif