blob: 9870e9cb5a8e24b8c727be6610ea3cf15fde5c82 [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
John Hughes70623be2001-03-08 13:59:00 +000044#if HAVE_LONG_LONG_OFF_T
45/*
46 * Hacks for systems that have a long long off_t
47 */
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010048# define flock64 flock /* Horrid hack */
49# define printflock printflock64 /* Horrider hack */
John Hughesb8c9f772001-03-07 16:53:07 +000050#endif
51
Roland McGrathd9f816f2004-09-04 03:39:20 +000052static const struct xlat fcntlcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053 { F_DUPFD, "F_DUPFD" },
54 { F_GETFD, "F_GETFD" },
55 { F_SETFD, "F_SETFD" },
56 { F_GETFL, "F_GETFL" },
57 { F_SETFL, "F_SETFL" },
58 { F_GETLK, "F_GETLK" },
59 { F_SETLK, "F_SETLK" },
60 { F_SETLKW, "F_SETLKW" },
61 { F_GETOWN, "F_GETOWN" },
62 { F_SETOWN, "F_SETOWN" },
63#ifdef F_RSETLK
64 { F_RSETLK, "F_RSETLK" },
65#endif
66#ifdef F_RSETLKW
67 { F_RSETLKW, "F_RSETLKW" },
68#endif
69#ifdef F_RGETLK
70 { F_RGETLK, "F_RGETLK" },
71#endif
72#ifdef F_CNVT
73 { F_CNVT, "F_CNVT" },
74#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000075#ifdef F_SETSIG
76 { F_SETSIG, "F_SETSIG" },
77#endif
78#ifdef F_GETSIG
79 { F_GETSIG, "F_GETSIG" },
80#endif
John Hughesbdf48f52001-03-06 15:08:09 +000081#ifdef F_CHKFL
82 { F_CHKFL, "F_CHKFL" },
83#endif
84#ifdef F_DUP2FD
85 { F_DUP2FD, "F_DUP2FD" },
86#endif
87#ifdef F_ALLOCSP
88 { F_ALLOCSP, "F_ALLOCSP" },
89#endif
90#ifdef F_ISSTREAM
91 { F_ISSTREAM, "F_ISSTREAM" },
92#endif
93#ifdef F_PRIV
94 { F_PRIV, "F_PRIV" },
95#endif
96#ifdef F_NPRIV
97 { F_NPRIV, "F_NPRIV" },
98#endif
99#ifdef F_QUOTACL
100 { F_QUOTACL, "F_QUOTACL" },
101#endif
102#ifdef F_BLOCKS
103 { F_BLOCKS, "F_BLOCKS" },
104#endif
105#ifdef F_BLKSIZE
106 { F_BLKSIZE, "F_BLKSIZE" },
107#endif
108#ifdef F_GETOWN
109 { F_GETOWN, "F_GETOWN" },
110#endif
111#ifdef F_SETOWN
112 { F_SETOWN, "F_SETOWN" },
113#endif
114#ifdef F_REVOKE
115 { F_REVOKE, "F_REVOKE" },
116#endif
117#ifdef F_SETLK
118 { F_SETLK, "F_SETLK" },
119#endif
120#ifdef F_SETLKW
121 { F_SETLKW, "F_SETLKW" },
122#endif
123#ifdef F_FREESP
124 { F_FREESP, "F_FREESP" },
125#endif
126#ifdef F_GETLK
127 { F_GETLK, "F_GETLK" },
128#endif
129#ifdef F_SETLK64
130 { F_SETLK64, "F_SETLK64" },
131#endif
132#ifdef F_SETLKW64
133 { F_SETLKW64, "F_SETLKW64" },
134#endif
135#ifdef F_FREESP64
136 { F_FREESP64, "F_FREESP64" },
137#endif
138#ifdef F_GETLK64
139 { F_GETLK64, "F_GETLK64" },
140#endif
141#ifdef F_SHARE
142 { F_SHARE, "F_SHARE" },
143#endif
144#ifdef F_UNSHARE
145 { F_UNSHARE, "F_UNSHARE" },
146#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000147#ifdef F_SETLEASE
148 { F_SETLEASE, "F_SETLEASE" },
149#endif
150#ifdef F_GETLEASE
151 { F_GETLEASE, "F_GETLEASE" },
152#endif
153#ifdef F_NOTIFY
154 { F_NOTIFY, "F_NOTIFY" },
155#endif
156#ifdef F_DUPFD_CLOEXEC
157 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
158#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000159 { 0, NULL },
160};
161
Roland McGrathd9f816f2004-09-04 03:39:20 +0000162static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163#ifdef FD_CLOEXEC
164 { FD_CLOEXEC, "FD_CLOEXEC" },
165#endif
166 { 0, NULL },
167};
168
169#ifdef LOCK_SH
170
Roland McGrathd9f816f2004-09-04 03:39:20 +0000171static const struct xlat flockcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172 { LOCK_SH, "LOCK_SH" },
173 { LOCK_EX, "LOCK_EX" },
174 { LOCK_NB, "LOCK_NB" },
175 { LOCK_UN, "LOCK_UN" },
176 { 0, NULL },
177};
178
179#endif /* LOCK_SH */
180
Roland McGrathd9f816f2004-09-04 03:39:20 +0000181static const struct xlat lockfcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 { F_RDLCK, "F_RDLCK" },
183 { F_WRLCK, "F_WRLCK" },
184 { F_UNLCK, "F_UNLCK" },
185#ifdef F_EXLCK
186 { F_EXLCK, "F_EXLCK" },
187#endif
188#ifdef F_SHLCK
189 { F_SHLCK, "F_SHLCK" },
190#endif
191 { 0, NULL },
192};
193
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000194#ifdef F_NOTIFY
195static const struct xlat notifyflags[] = {
196#ifdef DN_ACCESS
197 { DN_ACCESS, "DN_ACCESS" },
198#endif
199#ifdef DN_MODIFY
200 { DN_MODIFY, "DN_MODIFY" },
201#endif
202#ifdef DN_CREATE
203 { DN_CREATE, "DN_CREATE" },
204#endif
205#ifdef DN_DELETE
206 { DN_DELETE, "DN_DELETE" },
207#endif
208#ifdef DN_RENAME
209 { DN_RENAME, "DN_RENAME" },
210#endif
211#ifdef DN_ATTRIB
212 { DN_ATTRIB, "DN_ATTRIB" },
213#endif
214#ifdef DN_MULTISHOT
215 { DN_MULTISHOT, "DN_MULTISHOT" },
216#endif
217 { 0, NULL },
218};
219#endif
220
Roland McGrathd9f816f2004-09-04 03:39:20 +0000221static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000222 { SEEK_SET, "SEEK_SET" },
223 { SEEK_CUR, "SEEK_CUR" },
224 { SEEK_END, "SEEK_END" },
225 { 0, NULL },
226};
227
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100228static const struct xlat perf_event_open_flags[] = {
229#ifdef PERF_FLAG_FD_NO_GROUP
230 { PERF_FLAG_FD_NO_GROUP, "PERF_FLAG_FD_NO_GROUP" },
231#endif
232#ifdef PERF_FLAG_FD_OUTPUT
233 { PERF_FLAG_FD_OUTPUT, "PERF_FLAG_FD_OUTPUT" },
234#endif
235#ifdef PERF_FLAG_PID_CGROUP
236 { PERF_FLAG_PID_CGROUP, "PERF_FLAG_PID_CGROUP" },
237#endif
238 { 0, NULL },
239};
240
John Hughes70623be2001-03-08 13:59:00 +0000241#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000242/* fcntl/lockf */
243static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000244printflock(struct tcb *tcp, long addr, int getlk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000245{
246 struct flock fl;
247
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000248#if SUPPORTED_PERSONALITIES > 1
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100249 if (current_wordsize != sizeof(fl.l_start)) {
250 if (current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000251 /* 32-bit x86 app on x86_64 and similar cases */
252 struct {
253 short int l_type;
254 short int l_whence;
255 int32_t l_start; /* off_t */
256 int32_t l_len; /* off_t */
257 int32_t l_pid; /* pid_t */
258 } fl32;
259 if (umove(tcp, addr, &fl32) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200260 tprints("{...}");
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000261 return;
262 }
263 fl.l_type = fl32.l_type;
264 fl.l_whence = fl32.l_whence;
265 fl.l_start = fl32.l_start;
266 fl.l_len = fl32.l_len;
267 fl.l_pid = fl32.l_pid;
268 } else {
269 /* let people know we have a problem here */
Denys Vlasenko751acb32013-02-08 15:34:46 +0100270 tprintf("<decode error: unsupported wordsize %d>",
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100271 current_wordsize);
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000272 return;
273 }
274 } else
275#endif
276 {
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000277 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200278 tprints("{...}");
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000279 return;
280 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000281 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200282 tprints("{type=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000283 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200284 tprints(", whence=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000285 printxval(whence, fl.l_whence, "SEEK_???");
286 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
287 if (getlk)
288 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
289 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200290 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000291}
John Hughesb8c9f772001-03-07 16:53:07 +0000292#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000293
John Hughes70623be2001-03-08 13:59:00 +0000294#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000295/* fcntl/lockf */
296static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000297printflock64(struct tcb *tcp, long addr, int getlk)
John Hughesbdf48f52001-03-06 15:08:09 +0000298{
299 struct flock64 fl;
300
301 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200302 tprints("{...}");
John Hughesbdf48f52001-03-06 15:08:09 +0000303 return;
304 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200305 tprints("{type=");
John Hughesbdf48f52001-03-06 15:08:09 +0000306 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200307 tprints(", whence=");
John Hughesbdf48f52001-03-06 15:08:09 +0000308 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000309 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000310 if (getlk)
311 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
312 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200313 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +0000314}
315#endif
316
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000317int
318sys_fcntl(struct tcb *tcp)
319{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000320 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300321 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200322 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000323 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
324 switch (tcp->u_arg[1]) {
325 case F_SETFD:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200326 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000327 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328 break;
329 case F_SETOWN: case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000330#ifdef F_DUPFD_CLOEXEC
331 case F_DUPFD_CLOEXEC:
332#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000333 tprintf(", %ld", tcp->u_arg[2]);
334 break;
335 case F_SETFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200336 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000337 tprint_open_modes(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 break;
339 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000340#ifdef F_FREESP
341 case F_FREESP:
342#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200343 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344 printflock(tcp, tcp->u_arg[2], 0);
345 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000346#if _LFS64_LARGEFILE
347#ifdef F_FREESP64
348 case F_FREESP64:
349#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000350 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000351 even though the kernel has different values - as does Solaris. */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000352#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000353 case F_SETLK64:
354#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000355#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
John Hughesbdf48f52001-03-06 15:08:09 +0000356 case F_SETLKW64:
357#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200358 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000359 printflock64(tcp, tcp->u_arg[2], 0);
360 break;
361#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000362#ifdef F_NOTIFY
363 case F_NOTIFY:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200364 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000365 printflags(notifyflags, tcp->u_arg[2], "DN_???");
366 break;
367#endif
368#ifdef F_SETLEASE
369 case F_SETLEASE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200370 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000371 printxval(lockfcmds, tcp->u_arg[2], "F_???");
372 break;
373#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000374 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375 }
376 else {
377 switch (tcp->u_arg[1]) {
378 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000379#ifdef F_DUPFD_CLOEXEC
380 case F_DUPFD_CLOEXEC:
381#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000382 case F_SETFD: case F_SETFL:
383 case F_SETLK: case F_SETLKW:
384 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000385#ifdef F_NOTIFY
386 case F_NOTIFY:
387#endif
388#ifdef F_SETLEASE
389 case F_SETLEASE:
390#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391 break;
392 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000393 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000395 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000396 return RVAL_HEX|RVAL_STR;
397 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000398 if (syserror(tcp))
399 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000400 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000401 return RVAL_HEX|RVAL_STR;
402 case F_GETLK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200403 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000404 printflock(tcp, tcp->u_arg[2], 1);
405 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000406#if _LFS64_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200407#if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000408 case F_GETLK64:
409#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200410 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000411 printflock64(tcp, tcp->u_arg[2], 1);
412 break;
413#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000414#ifdef F_GETLEASE
415 case F_GETLEASE:
416 if (syserror(tcp))
417 return 0;
418 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
419 return RVAL_HEX|RVAL_STR;
420#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000421 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 tprintf(", %#lx", tcp->u_arg[2]);
423 break;
424 }
425 }
426 return 0;
427}
428
429#ifdef LOCK_SH
430
431int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000432sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433{
434 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300435 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200436 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000437 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 }
439 return 0;
440}
441#endif /* LOCK_SH */
442
443int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000444sys_close(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
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000473int
474sys_dup3(struct tcb *tcp)
475{
476 return do_dup2(tcp, 2);
477}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000478
Denys Vlasenko84703742012-02-25 02:38:52 +0100479#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000480int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000481sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000482{
483 return 0;
484}
Denys Vlasenko84703742012-02-25 02:38:52 +0100485#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000486
487static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000488decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489{
Denys Vlasenkoad5155a2011-09-01 18:18:04 +0200490 int i, j;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200491 unsigned nfds, fdsize;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000492 fd_set *fds;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000493 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000494 long arg;
495
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200496 fdsize = args[0];
497 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
498 if (args[0] > 1024*1024)
499 fdsize = 1024*1024;
500 if (args[0] < 0)
501 fdsize = 0;
502 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
503
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000504 if (entering(tcp)) {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200505 fds = malloc(fdsize);
506 if (!fds)
507 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000508 nfds = args[0];
509 tprintf("%d", nfds);
510 for (i = 0; i < 3; i++) {
511 arg = args[i+1];
512 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200513 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 continue;
515 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200516 if (!verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 tprintf(", %#lx", arg);
518 continue;
519 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000520 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints(", [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 continue;
523 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200524 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000526 if (FD_ISSET(j, fds)) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200527 tprints(sep);
Dmitry V. Levin31382132011-03-04 05:08:02 +0300528 printfd(tcp, j);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 sep = " ";
530 }
531 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200532 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000534 free(fds);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200535 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000536 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000537 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200538 else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200539 static char outstr[1024];
540 char *outptr;
541#define end_outstr (outstr + sizeof(outstr))
542 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543
544 if (syserror(tcp))
545 return 0;
546
Denys Vlasenko5d645812011-08-20 12:48:18 +0200547 nfds = tcp->u_rval;
548 if (nfds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000549 tcp->auxstr = "Timeout";
550 return RVAL_STR;
551 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000552
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200553 fds = malloc(fdsize);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200554 if (!fds)
555 die_out_of_memory();
Roland McGrathe85aaa42005-02-06 01:55:12 +0000556
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200557 outptr = outstr;
558 sep = "";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559 for (i = 0; i < 3; i++) {
560 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000561
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 arg = args[i+1];
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200563 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000564 continue;
565 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000566 if (FD_ISSET(j, fds)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200567 /* +2 chars needed at the end: ']',NUL */
568 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
569 if (first) {
570 outptr += sprintf(outptr, "%s%s [%u",
571 sep,
572 i == 0 ? "in" : i == 1 ? "out" : "except",
573 j
574 );
575 first = 0;
576 sep = ", ";
577 }
578 else {
579 outptr += sprintf(outptr, " %u", j);
580 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000582 nfds--;
583 }
584 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200585 if (outptr != outstr)
586 *outptr++ = ']';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000587 if (nfds == 0)
588 break;
589 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000590 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591 /* This contains no useful information on SunOS. */
592 if (args[4]) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100593 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200594 outptr += sprintf(outptr, "%sleft ", sep);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100595 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200596 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200598 *outptr = '\0';
Denys Vlasenko11617252011-09-01 11:27:37 +0200599 tcp->auxstr = outstr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200601#undef end_outstr
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000602 }
603 return 0;
604}
605
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000607sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608{
609 long args[5];
610
611 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200612 tprints("[...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000613 return 0;
614 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000615 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000616}
617
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000618#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000619int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000620sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000621{
622 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000623 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000624}
625#endif
626
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000627static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000628#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000629 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000630#endif
631#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000632 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000633#endif
634#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000635 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000636#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000637 { 0, NULL }
638};
639
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000640static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000641#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000642 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000643#endif
644#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000645 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000646#endif
647#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000648 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000649#endif
650#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000651 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000652#endif
653#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000654 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000655#endif
656#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000657 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000658#endif
659#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000660 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000661#endif
662#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000663 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000664#endif
665#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000666 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000667#endif
668#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000669 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000670#endif
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000671#ifdef EPOLLRDHUP
672 { EPOLLRDHUP, "EPOLLRDHUP" },
673#endif
Roland McGrath63d6e542004-10-20 02:17:41 +0000674#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000675 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000676#endif
677#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000678 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000679#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000680 { 0, NULL }
681};
682
Denys Vlasenko72879c62012-02-27 14:18:02 +0100683/* Not aliased to printargs_ld: we want it to have a distinct address */
Roland McGrath93817bf2004-10-06 22:23:31 +0000684int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000685sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000686{
Denys Vlasenko72879c62012-02-27 14:18:02 +0100687 return printargs_ld(tcp);
Roland McGrath93817bf2004-10-06 22:23:31 +0000688}
689
Mike Frysingeraed334c2011-10-13 22:33:45 -0400690static const struct xlat epollflags[] = {
691#ifdef EPOLL_CLOEXEC
692 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
693#endif
694#ifdef EPOLL_NONBLOCK
695 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
696#endif
697 { 0, NULL }
698};
699
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000700int
701sys_epoll_create1(struct tcb *tcp)
702{
703 if (entering(tcp))
Mike Frysingeraed334c2011-10-13 22:33:45 -0400704 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000705 return 0;
706}
707
Roland McGrath63d6e542004-10-20 02:17:41 +0000708#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000709static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000710print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000711{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200712 tprints("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000713 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000714 /* We cannot know what format the program uses, so print u32 and u64
715 which will cover every value. */
716 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
717 ev->data.u32, ev->data.u64);
718}
Roland McGrath63d6e542004-10-20 02:17:41 +0000719#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000720
721int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000722sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000723{
724 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300725 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200726 tprints(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000727 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200728 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300729 printfd(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200730 tprints(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000731 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200732 tprints("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000733 else {
734#ifdef HAVE_SYS_EPOLL_H
735 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000736 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000737 print_epoll_event(&ev);
738 else
739#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200740 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000741 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000742 }
743 return 0;
744}
745
Roland McGrathf2400052007-08-02 01:13:26 +0000746static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000747epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000748{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300749 if (entering(tcp)) {
750 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200751 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300752 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000753 if (syserror(tcp))
754 tprintf("%lx", tcp->u_arg[1]);
755 else if (tcp->u_rval == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200756 tprints("{}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000757 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000758#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000759 struct epoll_event ev, *start, *cur, *end;
760 int failed = 0;
761
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200762 tprints("{");
Roland McGrathaa524c82005-06-01 19:22:06 +0000763 start = (struct epoll_event *) tcp->u_arg[1];
764 end = start + tcp->u_rval;
765 for (cur = start; cur < end; ++cur) {
766 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200767 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000768 if (umove(tcp, (long) cur, &ev) == 0)
769 print_epoll_event(&ev);
770 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200771 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000772 failed = 1;
773 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000774 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000775 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200776 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000777 if (failed)
778 tprintf(" %#lx", (long) start);
779#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200780 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000781#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000782 }
Dmitry V. Levinc327d712011-10-11 16:05:57 +0000783 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
Roland McGrath93817bf2004-10-06 22:23:31 +0000784 }
Roland McGrathf2400052007-08-02 01:13:26 +0000785}
786
787int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000788sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000789{
790 epoll_wait_common(tcp);
791 return 0;
792}
793
794int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000795sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000796{
797 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000798 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200799 tprints(", ");
Roland McGrathf2400052007-08-02 01:13:26 +0000800 print_sigset(tcp, tcp->u_arg[4], 0);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000801 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000802 return 0;
803}
Roland McGrath37b9f842005-05-09 08:02:00 +0000804
805int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000806sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000807{
808 if (entering(tcp))
809 tprintf("%ld, ", tcp->u_arg[0]);
810 else {
811 if (syserror(tcp))
812 tprintf("0x%0lx", tcp->u_arg[1]);
813 else {
814 unsigned long user_id;
815 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
816 tprintf("{%lu}", user_id);
817 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200818 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000819 }
820 }
821 return 0;
822}
823
824int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000825sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000826{
827 if (entering(tcp))
828 tprintf("%lu", tcp->u_arg[0]);
829 return 0;
830}
831
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000832#ifdef HAVE_LIBAIO_H
833
Andi Kleendfcd7412011-06-13 22:05:44 +0000834enum iocb_sub {
835 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
836};
837
838static const char *
839iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
840{
Denys Vlasenko79992622011-08-19 19:44:17 +0200841 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
842 static const struct {
Andi Kleendfcd7412011-06-13 22:05:44 +0000843 const char *name;
844 enum iocb_sub sub;
845 } cmds[] = {
846 { "pread", SUB_COMMON },
847 { "pwrite", SUB_COMMON },
848 { "fsync", SUB_NONE },
849 { "fdsync", SUB_NONE },
850 { "op4", SUB_NONE },
851 { "poll", SUB_POLL },
852 { "noop", SUB_NONE },
853 { "preadv", SUB_VECTOR },
854 { "pwritev", SUB_VECTOR },
855 };
856
857 if (cmd < ARRAY_SIZE(cmds)) {
858 *sub = cmds[cmd].sub;
859 return cmds[cmd].name;
860 }
861 *sub = SUB_NONE;
Denys Vlasenko79992622011-08-19 19:44:17 +0200862 sprintf(buf, "%u /* SUB_??? */", cmd);
Andi Kleendfcd7412011-06-13 22:05:44 +0000863 return buf;
864}
865
866/* Not defined in libaio.h */
867#ifndef IOCB_RESFD
868# define IOCB_RESFD (1 << 0)
869#endif
870
871static void
872print_common_flags(struct iocb *iocb)
873{
874 if (iocb->u.c.flags & IOCB_RESFD)
875 tprintf("resfd=%d, ", iocb->u.c.resfd);
876 if (iocb->u.c.flags & ~IOCB_RESFD)
877 tprintf("flags=%x, ", iocb->u.c.flags);
878}
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000879
880#endif /* HAVE_LIBAIO_H */
881
Roland McGrath37b9f842005-05-09 08:02:00 +0000882int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000883sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000884{
885 long nr;
886 if (entering(tcp)) {
887 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
888 nr = tcp->u_arg[1];
889 /* and if nr is negative? */
890 if (nr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200891 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000892 else {
893#ifdef HAVE_LIBAIO_H
894 long i;
895 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
896
897 for (i = 0; i < nr; i++, iocbs++) {
Andi Kleendfcd7412011-06-13 22:05:44 +0000898 enum iocb_sub sub;
Roland McGrath37b9f842005-05-09 08:02:00 +0000899 struct iocb iocb;
900 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200901 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +0000902 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200903 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000904
905 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
906 umove(tcp, (unsigned long)iocbp, &iocb)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200907 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000908 continue;
909 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200910 tprints("{");
Andi Kleendfcd7412011-06-13 22:05:44 +0000911 if (iocb.data)
912 tprintf("data:%p, ", iocb.data);
913 if (iocb.key)
914 tprintf("key:%u, ", iocb.key);
915 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
916 if (iocb.aio_reqprio)
917 tprintf("reqprio:%d, ", iocb.aio_reqprio);
918 tprintf("filedes:%d", iocb.aio_fildes);
919 switch (sub) {
920 case SUB_COMMON:
921 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200922 tprints(", str:");
Andi Kleendfcd7412011-06-13 22:05:44 +0000923 printstr(tcp, (unsigned long)iocb.u.c.buf,
924 iocb.u.c.nbytes);
925 } else {
926 tprintf(", buf:%p", iocb.u.c.buf);
927 }
928 tprintf(", nbytes:%lu, offset:%llx",
929 iocb.u.c.nbytes,
930 iocb.u.c.offset);
931 print_common_flags(&iocb);
932 break;
933 case SUB_VECTOR:
934 tprintf(", %llx, ", iocb.u.v.offset);
935 print_common_flags(&iocb);
936 tprint_iov(tcp, iocb.u.v.nr,
937 (unsigned long)iocb.u.v.vec,
938 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
939 break;
940 case SUB_POLL:
941 tprintf(", %x", iocb.u.poll.events);
942 break;
943 case SUB_NONE:
944 break;
945 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200946 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000947 }
948 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200949 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000950#else
Andi Kleendfcd7412011-06-13 22:05:44 +0000951#warning "libaio-devel is not available => no io_submit decoding"
952 tprintf("%#lx", tcp->u_arg[2]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000953#endif
954 }
955 }
956 return 0;
957}
958
959int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000960sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000961{
962 if (entering(tcp)) {
963#ifdef HAVE_LIBAIO_H
964 struct iocb iocb;
965#endif
966 tprintf("%lu, ", tcp->u_arg[0]);
967#ifdef HAVE_LIBAIO_H
968 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
Denys Vlasenko61d62cf2012-04-16 18:12:27 +0200969 tprintf("{%p, %u, %u, %u, %d}, ",
Roland McGrath37b9f842005-05-09 08:02:00 +0000970 iocb.data, iocb.key,
Denys Vlasenko61d62cf2012-04-16 18:12:27 +0200971 (unsigned)iocb.aio_lio_opcode,
972 (unsigned)iocb.aio_reqprio, iocb.aio_fildes);
Roland McGrath37b9f842005-05-09 08:02:00 +0000973 } else
974#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200975 tprints("{...}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000976 } else {
977 if (tcp->u_rval < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200978 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000979 else {
980#ifdef HAVE_LIBAIO_H
981 struct io_event event;
982 if (umove(tcp, tcp->u_arg[2], &event) == 0)
983 tprintf("{%p, %p, %ld, %ld}",
984 event.data, event.obj,
985 event.res, event.res2);
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000986 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000987#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200988 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000989 }
990 }
991 return 0;
992}
993
994int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000995sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000996{
997 if (entering(tcp)) {
998 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
999 tcp->u_arg[2]);
1000 } else {
1001 if (tcp->u_rval == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001002 tprints("{}");
Denys Vlasenko3e3490a2012-03-17 01:27:37 +01001003 } else {
Roland McGrath37b9f842005-05-09 08:02:00 +00001004#ifdef HAVE_LIBAIO_H
1005 struct io_event *events = (void *)tcp->u_arg[3];
1006 long i, nr = tcp->u_rval;
1007
1008 for (i = 0; i < nr; i++, events++) {
1009 struct io_event event;
1010
1011 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001012 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +00001013 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001014 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001015
1016 if (umove(tcp, (unsigned long)events, &event) != 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001017 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001018 continue;
1019 }
1020 tprintf("{%p, %p, %ld, %ld}", event.data,
1021 event.obj, event.res, event.res2);
1022 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001023 tprints("}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001024#else
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001025 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001026#endif
1027 }
1028
Roland McGrath6bc09da2007-11-01 21:50:54 +00001029 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +00001030 }
1031 return 0;
1032}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001033
1034int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +00001035sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001036{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001037 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001038}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001039
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001040int
1041sys_pselect6(struct tcb *tcp)
1042{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001043 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +00001044 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001045 struct {
1046 void *ss;
1047 unsigned long len;
1048 } data;
1049 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1050 tprintf(", %#lx", tcp->u_arg[5]);
1051 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001052 tprints(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +00001053 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001054 tprintf("%#lx", (long)data.ss);
1055 else
1056 print_sigset(tcp, (long)data.ss, 0);
1057 tprintf(", %lu}", data.len);
1058 }
1059 }
1060 return rc;
1061}
Roland McGrathe7c39672007-08-02 01:32:17 +00001062
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001063static int
1064do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +00001065{
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001066 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +00001067 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001068 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001069 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001070 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1071 }
1072 }
Roland McGrathe7c39672007-08-02 01:32:17 +00001073 return 0;
1074}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001075
1076int
1077sys_eventfd(struct tcb *tcp)
1078{
1079 return do_eventfd(tcp, -1);
1080}
1081
1082int
1083sys_eventfd2(struct tcb *tcp)
1084{
1085 return do_eventfd(tcp, 1);
1086}
Ben Noordhuis88eafd82013-02-04 00:04:57 +01001087
1088int
1089sys_perf_event_open(struct tcb *tcp)
1090{
1091 if (entering(tcp)) {
1092 tprintf("%#lx, %d, %d, %d, ",
1093 tcp->u_arg[0],
1094 (int) tcp->u_arg[1],
1095 (int) tcp->u_arg[2],
1096 (int) tcp->u_arg[3]);
1097 printflags(perf_event_open_flags, tcp->u_arg[4],
1098 "PERF_FLAG_???");
1099 }
1100 return 0;
1101}