blob: cd2c85724d7694e3d4a7fded98abe450c8972834 [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <fcntl.h>
33#include <sys/file.h>
Roland McGrath63d6e542004-10-20 02:17:41 +000034#ifdef HAVE_SYS_EPOLL_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010035# include <sys/epoll.h>
Roland McGrath93817bf2004-10-06 22:23:31 +000036#endif
Roland McGrath37b9f842005-05-09 08:02:00 +000037#ifdef HAVE_LIBAIO_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010038# include <libaio.h>
Roland McGrath37b9f842005-05-09 08:02:00 +000039#endif
Ben Noordhuis88eafd82013-02-04 00:04:57 +010040#ifdef HAVE_LINUX_PERF_EVENT_H
41# include <linux/perf_event.h>
42#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043
Roland McGrathd9f816f2004-09-04 03:39:20 +000044static const struct xlat fcntlcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000045 { F_DUPFD, "F_DUPFD" },
46 { F_GETFD, "F_GETFD" },
47 { F_SETFD, "F_SETFD" },
48 { F_GETFL, "F_GETFL" },
49 { F_SETFL, "F_SETFL" },
50 { F_GETLK, "F_GETLK" },
51 { F_SETLK, "F_SETLK" },
52 { F_SETLKW, "F_SETLKW" },
53 { F_GETOWN, "F_GETOWN" },
54 { F_SETOWN, "F_SETOWN" },
55#ifdef F_RSETLK
56 { F_RSETLK, "F_RSETLK" },
57#endif
58#ifdef F_RSETLKW
59 { F_RSETLKW, "F_RSETLKW" },
60#endif
61#ifdef F_RGETLK
62 { F_RGETLK, "F_RGETLK" },
63#endif
64#ifdef F_CNVT
65 { F_CNVT, "F_CNVT" },
66#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000067#ifdef F_SETSIG
68 { F_SETSIG, "F_SETSIG" },
69#endif
70#ifdef F_GETSIG
71 { F_GETSIG, "F_GETSIG" },
72#endif
John Hughesbdf48f52001-03-06 15:08:09 +000073#ifdef F_CHKFL
74 { F_CHKFL, "F_CHKFL" },
75#endif
76#ifdef F_DUP2FD
77 { F_DUP2FD, "F_DUP2FD" },
78#endif
79#ifdef F_ALLOCSP
80 { F_ALLOCSP, "F_ALLOCSP" },
81#endif
82#ifdef F_ISSTREAM
83 { F_ISSTREAM, "F_ISSTREAM" },
84#endif
85#ifdef F_PRIV
86 { F_PRIV, "F_PRIV" },
87#endif
88#ifdef F_NPRIV
89 { F_NPRIV, "F_NPRIV" },
90#endif
91#ifdef F_QUOTACL
92 { F_QUOTACL, "F_QUOTACL" },
93#endif
94#ifdef F_BLOCKS
95 { F_BLOCKS, "F_BLOCKS" },
96#endif
97#ifdef F_BLKSIZE
98 { F_BLKSIZE, "F_BLKSIZE" },
99#endif
100#ifdef F_GETOWN
101 { F_GETOWN, "F_GETOWN" },
102#endif
103#ifdef F_SETOWN
104 { F_SETOWN, "F_SETOWN" },
105#endif
106#ifdef F_REVOKE
107 { F_REVOKE, "F_REVOKE" },
108#endif
109#ifdef F_SETLK
110 { F_SETLK, "F_SETLK" },
111#endif
112#ifdef F_SETLKW
113 { F_SETLKW, "F_SETLKW" },
114#endif
115#ifdef F_FREESP
116 { F_FREESP, "F_FREESP" },
117#endif
118#ifdef F_GETLK
119 { F_GETLK, "F_GETLK" },
120#endif
121#ifdef F_SETLK64
122 { F_SETLK64, "F_SETLK64" },
123#endif
124#ifdef F_SETLKW64
125 { F_SETLKW64, "F_SETLKW64" },
126#endif
127#ifdef F_FREESP64
128 { F_FREESP64, "F_FREESP64" },
129#endif
130#ifdef F_GETLK64
131 { F_GETLK64, "F_GETLK64" },
132#endif
133#ifdef F_SHARE
134 { F_SHARE, "F_SHARE" },
135#endif
136#ifdef F_UNSHARE
137 { F_UNSHARE, "F_UNSHARE" },
138#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000139#ifdef F_SETLEASE
140 { F_SETLEASE, "F_SETLEASE" },
141#endif
142#ifdef F_GETLEASE
143 { F_GETLEASE, "F_GETLEASE" },
144#endif
145#ifdef F_NOTIFY
146 { F_NOTIFY, "F_NOTIFY" },
147#endif
148#ifdef F_DUPFD_CLOEXEC
149 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
150#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151 { 0, NULL },
152};
153
Roland McGrathd9f816f2004-09-04 03:39:20 +0000154static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#ifdef FD_CLOEXEC
156 { FD_CLOEXEC, "FD_CLOEXEC" },
157#endif
158 { 0, NULL },
159};
160
161#ifdef LOCK_SH
162
Roland McGrathd9f816f2004-09-04 03:39:20 +0000163static const struct xlat flockcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164 { LOCK_SH, "LOCK_SH" },
165 { LOCK_EX, "LOCK_EX" },
166 { LOCK_NB, "LOCK_NB" },
167 { LOCK_UN, "LOCK_UN" },
168 { 0, NULL },
169};
170
171#endif /* LOCK_SH */
172
Roland McGrathd9f816f2004-09-04 03:39:20 +0000173static const struct xlat lockfcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174 { F_RDLCK, "F_RDLCK" },
175 { F_WRLCK, "F_WRLCK" },
176 { F_UNLCK, "F_UNLCK" },
177#ifdef F_EXLCK
178 { F_EXLCK, "F_EXLCK" },
179#endif
180#ifdef F_SHLCK
181 { F_SHLCK, "F_SHLCK" },
182#endif
183 { 0, NULL },
184};
185
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000186#ifdef F_NOTIFY
187static const struct xlat notifyflags[] = {
188#ifdef DN_ACCESS
189 { DN_ACCESS, "DN_ACCESS" },
190#endif
191#ifdef DN_MODIFY
192 { DN_MODIFY, "DN_MODIFY" },
193#endif
194#ifdef DN_CREATE
195 { DN_CREATE, "DN_CREATE" },
196#endif
197#ifdef DN_DELETE
198 { DN_DELETE, "DN_DELETE" },
199#endif
200#ifdef DN_RENAME
201 { DN_RENAME, "DN_RENAME" },
202#endif
203#ifdef DN_ATTRIB
204 { DN_ATTRIB, "DN_ATTRIB" },
205#endif
206#ifdef DN_MULTISHOT
207 { DN_MULTISHOT, "DN_MULTISHOT" },
208#endif
209 { 0, NULL },
210};
211#endif
212
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100213static const struct xlat perf_event_open_flags[] = {
214#ifdef PERF_FLAG_FD_NO_GROUP
215 { PERF_FLAG_FD_NO_GROUP, "PERF_FLAG_FD_NO_GROUP" },
216#endif
217#ifdef PERF_FLAG_FD_OUTPUT
218 { PERF_FLAG_FD_OUTPUT, "PERF_FLAG_FD_OUTPUT" },
219#endif
220#ifdef PERF_FLAG_PID_CGROUP
221 { PERF_FLAG_PID_CGROUP, "PERF_FLAG_PID_CGROUP" },
222#endif
223 { 0, NULL },
224};
225
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000226/* fcntl/lockf */
227static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000228printflock(struct tcb *tcp, long addr, int getlk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000229{
230 struct flock fl;
231
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000232#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100233 if (current_wordsize != sizeof(fl.l_start)) {
234 if (current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000235 /* 32-bit x86 app on x86_64 and similar cases */
236 struct {
237 short int l_type;
238 short int l_whence;
239 int32_t l_start; /* off_t */
240 int32_t l_len; /* off_t */
241 int32_t l_pid; /* pid_t */
242 } fl32;
243 if (umove(tcp, addr, &fl32) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200244 tprints("{...}");
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000245 return;
246 }
247 fl.l_type = fl32.l_type;
248 fl.l_whence = fl32.l_whence;
249 fl.l_start = fl32.l_start;
250 fl.l_len = fl32.l_len;
251 fl.l_pid = fl32.l_pid;
252 } else {
253 /* let people know we have a problem here */
Denys Vlasenko751acb32013-02-08 15:34:46 +0100254 tprintf("<decode error: unsupported wordsize %d>",
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100255 current_wordsize);
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000256 return;
257 }
258 } else
259#endif
260 {
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000261 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200262 tprints("{...}");
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000263 return;
264 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000265 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200266 tprints("{type=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000267 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200268 tprints(", whence=");
Denys Vlasenko86738a22013-02-17 14:31:55 +0100269 printxval(whence_codes, fl.l_whence, "SEEK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000270 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
271 if (getlk)
272 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
273 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200274 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000275}
276
Denys Vlasenko8435d672013-02-18 15:47:57 +0100277#if _LFS64_LARGEFILE
John Hughesbdf48f52001-03-06 15:08:09 +0000278/* fcntl/lockf */
279static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000280printflock64(struct tcb *tcp, long addr, int getlk)
John Hughesbdf48f52001-03-06 15:08:09 +0000281{
282 struct flock64 fl;
283
284 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200285 tprints("{...}");
John Hughesbdf48f52001-03-06 15:08:09 +0000286 return;
287 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200288 tprints("{type=");
John Hughesbdf48f52001-03-06 15:08:09 +0000289 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200290 tprints(", whence=");
Denys Vlasenko86738a22013-02-17 14:31:55 +0100291 printxval(whence_codes, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000292 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000293 if (getlk)
294 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
295 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200296 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +0000297}
298#endif
299
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000300int
301sys_fcntl(struct tcb *tcp)
302{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300304 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200305 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
307 switch (tcp->u_arg[1]) {
308 case F_SETFD:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200309 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000310 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000311 break;
312 case F_SETOWN: case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000313#ifdef F_DUPFD_CLOEXEC
314 case F_DUPFD_CLOEXEC:
315#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316 tprintf(", %ld", tcp->u_arg[2]);
317 break;
318 case F_SETFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200319 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000320 tprint_open_modes(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 break;
322 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000323#ifdef F_FREESP
324 case F_FREESP:
325#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200326 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 printflock(tcp, tcp->u_arg[2], 0);
328 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000329#if _LFS64_LARGEFILE
330#ifdef F_FREESP64
331 case F_FREESP64:
332#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000333 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000334 even though the kernel has different values - as does Solaris. */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000335#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000336 case F_SETLK64:
337#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000338#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
John Hughesbdf48f52001-03-06 15:08:09 +0000339 case F_SETLKW64:
340#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200341 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000342 printflock64(tcp, tcp->u_arg[2], 0);
343 break;
344#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000345#ifdef F_NOTIFY
346 case F_NOTIFY:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200347 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000348 printflags(notifyflags, tcp->u_arg[2], "DN_???");
349 break;
350#endif
351#ifdef F_SETLEASE
352 case F_SETLEASE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200353 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000354 printxval(lockfcmds, tcp->u_arg[2], "F_???");
355 break;
356#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000357 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 }
359 else {
360 switch (tcp->u_arg[1]) {
361 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000362#ifdef F_DUPFD_CLOEXEC
363 case F_DUPFD_CLOEXEC:
364#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000365 case F_SETFD: case F_SETFL:
366 case F_SETLK: case F_SETLKW:
367 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000368#ifdef F_NOTIFY
369 case F_NOTIFY:
370#endif
371#ifdef F_SETLEASE
372 case F_SETLEASE:
373#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374 break;
375 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000376 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000377 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000378 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000379 return RVAL_HEX|RVAL_STR;
380 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000381 if (syserror(tcp))
382 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000383 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000384 return RVAL_HEX|RVAL_STR;
385 case F_GETLK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200386 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000387 printflock(tcp, tcp->u_arg[2], 1);
388 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000389#if _LFS64_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200390#if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000391 case F_GETLK64:
392#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200393 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000394 printflock64(tcp, tcp->u_arg[2], 1);
395 break;
396#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000397#ifdef F_GETLEASE
398 case F_GETLEASE:
399 if (syserror(tcp))
400 return 0;
401 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
402 return RVAL_HEX|RVAL_STR;
403#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000404 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000405 tprintf(", %#lx", tcp->u_arg[2]);
406 break;
407 }
408 }
409 return 0;
410}
411
412#ifdef LOCK_SH
413
414int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000415sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000416{
417 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300418 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200419 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000420 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421 }
422 return 0;
423}
424#endif /* LOCK_SH */
425
426int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000427sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000428{
429 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300430 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000431 }
432 return 0;
433}
434
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000435static int
436do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000437{
438 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300439 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200440 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300441 printfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000442 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200443 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000444 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
445 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446 }
447 return 0;
448}
449
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000450int
451sys_dup2(struct tcb *tcp)
452{
453 return do_dup2(tcp, -1);
454}
455
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000456int
457sys_dup3(struct tcb *tcp)
458{
459 return do_dup2(tcp, 2);
460}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000461
Denys Vlasenko84703742012-02-25 02:38:52 +0100462#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000463int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000464sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465{
466 return 0;
467}
Denys Vlasenko84703742012-02-25 02:38:52 +0100468#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000469
470static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000471decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000472{
Denys Vlasenkoad5155a2011-09-01 18:18:04 +0200473 int i, j;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200474 unsigned nfds, fdsize;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000475 fd_set *fds;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000476 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000477 long arg;
478
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200479 fdsize = args[0];
480 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
481 if (args[0] > 1024*1024)
482 fdsize = 1024*1024;
483 if (args[0] < 0)
484 fdsize = 0;
485 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
486
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000487 if (entering(tcp)) {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200488 fds = malloc(fdsize);
489 if (!fds)
490 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491 nfds = args[0];
492 tprintf("%d", nfds);
493 for (i = 0; i < 3; i++) {
494 arg = args[i+1];
495 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200496 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000497 continue;
498 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200499 if (!verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500 tprintf(", %#lx", arg);
501 continue;
502 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000503 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200504 tprints(", [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505 continue;
506 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200507 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000509 if (FD_ISSET(j, fds)) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200510 tprints(sep);
Dmitry V. Levin31382132011-03-04 05:08:02 +0300511 printfd(tcp, j);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000512 sep = " ";
513 }
514 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200515 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000516 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000517 free(fds);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200518 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000519 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000520 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200521 else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200522 static char outstr[1024];
523 char *outptr;
524#define end_outstr (outstr + sizeof(outstr))
525 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000526
527 if (syserror(tcp))
528 return 0;
529
Denys Vlasenko5d645812011-08-20 12:48:18 +0200530 nfds = tcp->u_rval;
531 if (nfds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000532 tcp->auxstr = "Timeout";
533 return RVAL_STR;
534 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000535
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200536 fds = malloc(fdsize);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200537 if (!fds)
538 die_out_of_memory();
Roland McGrathe85aaa42005-02-06 01:55:12 +0000539
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200540 outptr = outstr;
541 sep = "";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 for (i = 0; i < 3; i++) {
543 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000544
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545 arg = args[i+1];
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200546 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547 continue;
548 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000549 if (FD_ISSET(j, fds)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200550 /* +2 chars needed at the end: ']',NUL */
551 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
552 if (first) {
553 outptr += sprintf(outptr, "%s%s [%u",
554 sep,
555 i == 0 ? "in" : i == 1 ? "out" : "except",
556 j
557 );
558 first = 0;
559 sep = ", ";
560 }
561 else {
562 outptr += sprintf(outptr, " %u", j);
563 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565 nfds--;
566 }
567 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200568 if (outptr != outstr)
569 *outptr++ = ']';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000570 if (nfds == 0)
571 break;
572 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000573 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000574 /* This contains no useful information on SunOS. */
575 if (args[4]) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100576 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200577 outptr += sprintf(outptr, "%sleft ", sep);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100578 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200579 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000580 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200581 *outptr = '\0';
Denys Vlasenko11617252011-09-01 11:27:37 +0200582 tcp->auxstr = outstr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000583 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200584#undef end_outstr
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000585 }
586 return 0;
587}
588
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000590sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591{
592 long args[5];
593
594 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200595 tprints("[...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000596 return 0;
597 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000598 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000599}
600
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000601#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000602int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000603sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000604{
605 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000606 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000607}
608#endif
609
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000610static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000611#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000612 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000613#endif
614#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000615 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000616#endif
617#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000618 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000619#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000620 { 0, NULL }
621};
622
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000623static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000624#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000625 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000626#endif
627#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000628 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000629#endif
630#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000631 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000632#endif
633#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000634 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000635#endif
636#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000637 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000638#endif
639#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000640 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000641#endif
642#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000643 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000644#endif
645#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000646 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000647#endif
648#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000649 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000650#endif
651#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000652 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000653#endif
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000654#ifdef EPOLLRDHUP
655 { EPOLLRDHUP, "EPOLLRDHUP" },
656#endif
Roland McGrath63d6e542004-10-20 02:17:41 +0000657#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000658 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000659#endif
660#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000661 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000662#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000663 { 0, NULL }
664};
665
Denys Vlasenko72879c62012-02-27 14:18:02 +0100666/* Not aliased to printargs_ld: we want it to have a distinct address */
Roland McGrath93817bf2004-10-06 22:23:31 +0000667int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000668sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000669{
Denys Vlasenko72879c62012-02-27 14:18:02 +0100670 return printargs_ld(tcp);
Roland McGrath93817bf2004-10-06 22:23:31 +0000671}
672
Mike Frysingeraed334c2011-10-13 22:33:45 -0400673static const struct xlat epollflags[] = {
674#ifdef EPOLL_CLOEXEC
675 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
676#endif
677#ifdef EPOLL_NONBLOCK
678 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
679#endif
680 { 0, NULL }
681};
682
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000683int
684sys_epoll_create1(struct tcb *tcp)
685{
686 if (entering(tcp))
Mike Frysingeraed334c2011-10-13 22:33:45 -0400687 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000688 return 0;
689}
690
Roland McGrath63d6e542004-10-20 02:17:41 +0000691#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000692static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000693print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000694{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200695 tprints("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000696 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000697 /* We cannot know what format the program uses, so print u32 and u64
698 which will cover every value. */
699 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
700 ev->data.u32, ev->data.u64);
701}
Roland McGrath63d6e542004-10-20 02:17:41 +0000702#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000703
704int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000705sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000706{
707 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300708 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200709 tprints(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000710 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200711 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300712 printfd(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200713 tprints(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000714 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200715 tprints("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000716 else {
717#ifdef HAVE_SYS_EPOLL_H
718 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000719 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000720 print_epoll_event(&ev);
721 else
722#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200723 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000724 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000725 }
726 return 0;
727}
728
Roland McGrathf2400052007-08-02 01:13:26 +0000729static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000730epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000731{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300732 if (entering(tcp)) {
733 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200734 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300735 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000736 if (syserror(tcp))
737 tprintf("%lx", tcp->u_arg[1]);
738 else if (tcp->u_rval == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200739 tprints("{}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000740 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000741#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000742 struct epoll_event ev, *start, *cur, *end;
743 int failed = 0;
744
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200745 tprints("{");
Roland McGrathaa524c82005-06-01 19:22:06 +0000746 start = (struct epoll_event *) tcp->u_arg[1];
747 end = start + tcp->u_rval;
748 for (cur = start; cur < end; ++cur) {
749 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200750 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000751 if (umove(tcp, (long) cur, &ev) == 0)
752 print_epoll_event(&ev);
753 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200754 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000755 failed = 1;
756 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000757 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000758 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200759 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000760 if (failed)
761 tprintf(" %#lx", (long) start);
762#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200763 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000764#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000765 }
Dmitry V. Levinc327d712011-10-11 16:05:57 +0000766 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
Roland McGrath93817bf2004-10-06 22:23:31 +0000767 }
Roland McGrathf2400052007-08-02 01:13:26 +0000768}
769
770int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000771sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000772{
773 epoll_wait_common(tcp);
774 return 0;
775}
776
777int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000778sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000779{
780 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000781 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200782 tprints(", ");
Roland McGrathf2400052007-08-02 01:13:26 +0000783 print_sigset(tcp, tcp->u_arg[4], 0);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000784 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000785 return 0;
786}
Roland McGrath37b9f842005-05-09 08:02:00 +0000787
788int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000789sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000790{
791 if (entering(tcp))
792 tprintf("%ld, ", tcp->u_arg[0]);
793 else {
794 if (syserror(tcp))
795 tprintf("0x%0lx", tcp->u_arg[1]);
796 else {
797 unsigned long user_id;
798 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
799 tprintf("{%lu}", user_id);
800 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200801 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000802 }
803 }
804 return 0;
805}
806
807int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000808sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000809{
810 if (entering(tcp))
811 tprintf("%lu", tcp->u_arg[0]);
812 return 0;
813}
814
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000815#ifdef HAVE_LIBAIO_H
816
Andi Kleendfcd7412011-06-13 22:05:44 +0000817enum iocb_sub {
818 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
819};
820
821static const char *
822iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
823{
Denys Vlasenko79992622011-08-19 19:44:17 +0200824 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
825 static const struct {
Andi Kleendfcd7412011-06-13 22:05:44 +0000826 const char *name;
827 enum iocb_sub sub;
828 } cmds[] = {
829 { "pread", SUB_COMMON },
830 { "pwrite", SUB_COMMON },
831 { "fsync", SUB_NONE },
832 { "fdsync", SUB_NONE },
833 { "op4", SUB_NONE },
834 { "poll", SUB_POLL },
835 { "noop", SUB_NONE },
836 { "preadv", SUB_VECTOR },
837 { "pwritev", SUB_VECTOR },
838 };
839
840 if (cmd < ARRAY_SIZE(cmds)) {
841 *sub = cmds[cmd].sub;
842 return cmds[cmd].name;
843 }
844 *sub = SUB_NONE;
Denys Vlasenko79992622011-08-19 19:44:17 +0200845 sprintf(buf, "%u /* SUB_??? */", cmd);
Andi Kleendfcd7412011-06-13 22:05:44 +0000846 return buf;
847}
848
849/* Not defined in libaio.h */
850#ifndef IOCB_RESFD
851# define IOCB_RESFD (1 << 0)
852#endif
853
854static void
855print_common_flags(struct iocb *iocb)
856{
Dmitry V. Levin3b211d82013-03-18 23:28:29 +0000857#if HAVE_STRUCT_IOCB_U_C_FLAGS
Andi Kleendfcd7412011-06-13 22:05:44 +0000858 if (iocb->u.c.flags & IOCB_RESFD)
Dmitry V. Levinc108ba22013-03-18 22:58:28 +0000859 tprintf(", resfd=%d", iocb->u.c.resfd);
Andi Kleendfcd7412011-06-13 22:05:44 +0000860 if (iocb->u.c.flags & ~IOCB_RESFD)
Dmitry V. Levinc108ba22013-03-18 22:58:28 +0000861 tprintf(", flags=%x", iocb->u.c.flags);
Dmitry V. Levin3b211d82013-03-18 23:28:29 +0000862#else
863# warning "libaio.h is too old => limited io_submit decoding"
864#endif
Andi Kleendfcd7412011-06-13 22:05:44 +0000865}
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000866
867#endif /* HAVE_LIBAIO_H */
868
Roland McGrath37b9f842005-05-09 08:02:00 +0000869int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000870sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000871{
872 long nr;
873 if (entering(tcp)) {
874 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
875 nr = tcp->u_arg[1];
876 /* and if nr is negative? */
877 if (nr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200878 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000879 else {
880#ifdef HAVE_LIBAIO_H
881 long i;
882 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
883
884 for (i = 0; i < nr; i++, iocbs++) {
Andi Kleendfcd7412011-06-13 22:05:44 +0000885 enum iocb_sub sub;
Roland McGrath37b9f842005-05-09 08:02:00 +0000886 struct iocb iocb;
887 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200888 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +0000889 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200890 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000891
892 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
893 umove(tcp, (unsigned long)iocbp, &iocb)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200894 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000895 continue;
896 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200897 tprints("{");
Andi Kleendfcd7412011-06-13 22:05:44 +0000898 if (iocb.data)
899 tprintf("data:%p, ", iocb.data);
900 if (iocb.key)
901 tprintf("key:%u, ", iocb.key);
902 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
903 if (iocb.aio_reqprio)
904 tprintf("reqprio:%d, ", iocb.aio_reqprio);
905 tprintf("filedes:%d", iocb.aio_fildes);
906 switch (sub) {
907 case SUB_COMMON:
Dmitry V. Levin3b211d82013-03-18 23:28:29 +0000908#if HAVE_DECL_IO_CMD_PWRITE
Andi Kleendfcd7412011-06-13 22:05:44 +0000909 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200910 tprints(", str:");
Andi Kleendfcd7412011-06-13 22:05:44 +0000911 printstr(tcp, (unsigned long)iocb.u.c.buf,
912 iocb.u.c.nbytes);
Dmitry V. Levin3b211d82013-03-18 23:28:29 +0000913 } else
914#endif
Andi Kleendfcd7412011-06-13 22:05:44 +0000915 tprintf(", buf:%p", iocb.u.c.buf);
Zev Weiss72cdefb2013-03-30 19:19:50 -0500916 tprintf(", nbytes:%lu, offset:%lld",
Andi Kleendfcd7412011-06-13 22:05:44 +0000917 iocb.u.c.nbytes,
918 iocb.u.c.offset);
919 print_common_flags(&iocb);
920 break;
921 case SUB_VECTOR:
Zev Weiss72cdefb2013-03-30 19:19:50 -0500922 tprintf(", %lld", iocb.u.v.offset);
Andi Kleendfcd7412011-06-13 22:05:44 +0000923 print_common_flags(&iocb);
Dmitry V. Levinc108ba22013-03-18 22:58:28 +0000924 tprints(", ");
Andi Kleendfcd7412011-06-13 22:05:44 +0000925 tprint_iov(tcp, iocb.u.v.nr,
926 (unsigned long)iocb.u.v.vec,
Dmitry V. Levin3b211d82013-03-18 23:28:29 +0000927#if HAVE_DECL_IO_CMD_PWRITEV
928 iocb.aio_lio_opcode == IO_CMD_PWRITEV
929#else
930 0
931#endif
932 );
Andi Kleendfcd7412011-06-13 22:05:44 +0000933 break;
934 case SUB_POLL:
935 tprintf(", %x", iocb.u.poll.events);
936 break;
937 case SUB_NONE:
938 break;
939 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200940 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000941 }
942 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200943 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000944#else
Dmitry V. Levin3b211d82013-03-18 23:28:29 +0000945#warning "libaio.h is not available => no io_submit decoding"
Andi Kleendfcd7412011-06-13 22:05:44 +0000946 tprintf("%#lx", tcp->u_arg[2]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000947#endif
948 }
949 }
950 return 0;
951}
952
953int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000954sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000955{
956 if (entering(tcp)) {
957#ifdef HAVE_LIBAIO_H
958 struct iocb iocb;
959#endif
960 tprintf("%lu, ", tcp->u_arg[0]);
961#ifdef HAVE_LIBAIO_H
962 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
Denys Vlasenko61d62cf2012-04-16 18:12:27 +0200963 tprintf("{%p, %u, %u, %u, %d}, ",
Roland McGrath37b9f842005-05-09 08:02:00 +0000964 iocb.data, iocb.key,
Denys Vlasenko61d62cf2012-04-16 18:12:27 +0200965 (unsigned)iocb.aio_lio_opcode,
966 (unsigned)iocb.aio_reqprio, iocb.aio_fildes);
Roland McGrath37b9f842005-05-09 08:02:00 +0000967 } else
968#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200969 tprints("{...}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000970 } else {
971 if (tcp->u_rval < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200972 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000973 else {
974#ifdef HAVE_LIBAIO_H
975 struct io_event event;
976 if (umove(tcp, tcp->u_arg[2], &event) == 0)
977 tprintf("{%p, %p, %ld, %ld}",
978 event.data, event.obj,
979 event.res, event.res2);
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000980 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000981#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200982 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000983 }
984 }
985 return 0;
986}
987
988int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000989sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000990{
991 if (entering(tcp)) {
992 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
993 tcp->u_arg[2]);
994 } else {
995 if (tcp->u_rval == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200996 tprints("{}");
Denys Vlasenko3e3490a2012-03-17 01:27:37 +0100997 } else {
Roland McGrath37b9f842005-05-09 08:02:00 +0000998#ifdef HAVE_LIBAIO_H
999 struct io_event *events = (void *)tcp->u_arg[3];
1000 long i, nr = tcp->u_rval;
1001
1002 for (i = 0; i < nr; i++, events++) {
1003 struct io_event event;
1004
1005 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001006 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +00001007 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001008 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001009
1010 if (umove(tcp, (unsigned long)events, &event) != 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001011 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001012 continue;
1013 }
1014 tprintf("{%p, %p, %ld, %ld}", event.data,
1015 event.obj, event.res, event.res2);
1016 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001017 tprints("}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001018#else
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001019 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001020#endif
1021 }
1022
Roland McGrath6bc09da2007-11-01 21:50:54 +00001023 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +00001024 }
1025 return 0;
1026}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001027
1028int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +00001029sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001030{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001031 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001032}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001033
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001034int
1035sys_pselect6(struct tcb *tcp)
1036{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001037 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +00001038 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001039 struct {
1040 void *ss;
1041 unsigned long len;
1042 } data;
1043 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1044 tprintf(", %#lx", tcp->u_arg[5]);
1045 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001046 tprints(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +00001047 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001048 tprintf("%#lx", (long)data.ss);
1049 else
1050 print_sigset(tcp, (long)data.ss, 0);
1051 tprintf(", %lu}", data.len);
1052 }
1053 }
1054 return rc;
1055}
Roland McGrathe7c39672007-08-02 01:32:17 +00001056
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001057static int
1058do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +00001059{
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001060 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +00001061 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001062 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001063 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001064 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1065 }
1066 }
Roland McGrathe7c39672007-08-02 01:32:17 +00001067 return 0;
1068}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001069
1070int
1071sys_eventfd(struct tcb *tcp)
1072{
1073 return do_eventfd(tcp, -1);
1074}
1075
1076int
1077sys_eventfd2(struct tcb *tcp)
1078{
1079 return do_eventfd(tcp, 1);
1080}
Ben Noordhuis88eafd82013-02-04 00:04:57 +01001081
1082int
1083sys_perf_event_open(struct tcb *tcp)
1084{
1085 if (entering(tcp)) {
1086 tprintf("%#lx, %d, %d, %d, ",
1087 tcp->u_arg[0],
1088 (int) tcp->u_arg[1],
1089 (int) tcp->u_arg[2],
1090 (int) tcp->u_arg[3]);
1091 printflags(perf_event_open_flags, tcp->u_arg[4],
1092 "PERF_FLAG_???");
1093 }
1094 return 0;
1095}