blob: b18951f621954a809f0d9de65e98dcb35bd9d908 [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040
John Hughes70623be2001-03-08 13:59:00 +000041#if HAVE_LONG_LONG_OFF_T
42/*
43 * Hacks for systems that have a long long off_t
44 */
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010045# define flock64 flock /* Horrid hack */
46# define printflock printflock64 /* Horrider hack */
John Hughesb8c9f772001-03-07 16:53:07 +000047#endif
48
Roland McGrathd9f816f2004-09-04 03:39:20 +000049static const struct xlat fcntlcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000050 { F_DUPFD, "F_DUPFD" },
51 { F_GETFD, "F_GETFD" },
52 { F_SETFD, "F_SETFD" },
53 { F_GETFL, "F_GETFL" },
54 { F_SETFL, "F_SETFL" },
55 { F_GETLK, "F_GETLK" },
56 { F_SETLK, "F_SETLK" },
57 { F_SETLKW, "F_SETLKW" },
58 { F_GETOWN, "F_GETOWN" },
59 { F_SETOWN, "F_SETOWN" },
60#ifdef F_RSETLK
61 { F_RSETLK, "F_RSETLK" },
62#endif
63#ifdef F_RSETLKW
64 { F_RSETLKW, "F_RSETLKW" },
65#endif
66#ifdef F_RGETLK
67 { F_RGETLK, "F_RGETLK" },
68#endif
69#ifdef F_CNVT
70 { F_CNVT, "F_CNVT" },
71#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000072#ifdef F_SETSIG
73 { F_SETSIG, "F_SETSIG" },
74#endif
75#ifdef F_GETSIG
76 { F_GETSIG, "F_GETSIG" },
77#endif
John Hughesbdf48f52001-03-06 15:08:09 +000078#ifdef F_CHKFL
79 { F_CHKFL, "F_CHKFL" },
80#endif
81#ifdef F_DUP2FD
82 { F_DUP2FD, "F_DUP2FD" },
83#endif
84#ifdef F_ALLOCSP
85 { F_ALLOCSP, "F_ALLOCSP" },
86#endif
87#ifdef F_ISSTREAM
88 { F_ISSTREAM, "F_ISSTREAM" },
89#endif
90#ifdef F_PRIV
91 { F_PRIV, "F_PRIV" },
92#endif
93#ifdef F_NPRIV
94 { F_NPRIV, "F_NPRIV" },
95#endif
96#ifdef F_QUOTACL
97 { F_QUOTACL, "F_QUOTACL" },
98#endif
99#ifdef F_BLOCKS
100 { F_BLOCKS, "F_BLOCKS" },
101#endif
102#ifdef F_BLKSIZE
103 { F_BLKSIZE, "F_BLKSIZE" },
104#endif
105#ifdef F_GETOWN
106 { F_GETOWN, "F_GETOWN" },
107#endif
108#ifdef F_SETOWN
109 { F_SETOWN, "F_SETOWN" },
110#endif
111#ifdef F_REVOKE
112 { F_REVOKE, "F_REVOKE" },
113#endif
114#ifdef F_SETLK
115 { F_SETLK, "F_SETLK" },
116#endif
117#ifdef F_SETLKW
118 { F_SETLKW, "F_SETLKW" },
119#endif
120#ifdef F_FREESP
121 { F_FREESP, "F_FREESP" },
122#endif
123#ifdef F_GETLK
124 { F_GETLK, "F_GETLK" },
125#endif
126#ifdef F_SETLK64
127 { F_SETLK64, "F_SETLK64" },
128#endif
129#ifdef F_SETLKW64
130 { F_SETLKW64, "F_SETLKW64" },
131#endif
132#ifdef F_FREESP64
133 { F_FREESP64, "F_FREESP64" },
134#endif
135#ifdef F_GETLK64
136 { F_GETLK64, "F_GETLK64" },
137#endif
138#ifdef F_SHARE
139 { F_SHARE, "F_SHARE" },
140#endif
141#ifdef F_UNSHARE
142 { F_UNSHARE, "F_UNSHARE" },
143#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000144#ifdef F_SETLEASE
145 { F_SETLEASE, "F_SETLEASE" },
146#endif
147#ifdef F_GETLEASE
148 { F_GETLEASE, "F_GETLEASE" },
149#endif
150#ifdef F_NOTIFY
151 { F_NOTIFY, "F_NOTIFY" },
152#endif
153#ifdef F_DUPFD_CLOEXEC
154 { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"},
155#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156 { 0, NULL },
157};
158
Roland McGrathd9f816f2004-09-04 03:39:20 +0000159static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160#ifdef FD_CLOEXEC
161 { FD_CLOEXEC, "FD_CLOEXEC" },
162#endif
163 { 0, NULL },
164};
165
166#ifdef LOCK_SH
167
Roland McGrathd9f816f2004-09-04 03:39:20 +0000168static const struct xlat flockcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000169 { LOCK_SH, "LOCK_SH" },
170 { LOCK_EX, "LOCK_EX" },
171 { LOCK_NB, "LOCK_NB" },
172 { LOCK_UN, "LOCK_UN" },
173 { 0, NULL },
174};
175
176#endif /* LOCK_SH */
177
Roland McGrathd9f816f2004-09-04 03:39:20 +0000178static const struct xlat lockfcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179 { F_RDLCK, "F_RDLCK" },
180 { F_WRLCK, "F_WRLCK" },
181 { F_UNLCK, "F_UNLCK" },
182#ifdef F_EXLCK
183 { F_EXLCK, "F_EXLCK" },
184#endif
185#ifdef F_SHLCK
186 { F_SHLCK, "F_SHLCK" },
187#endif
188 { 0, NULL },
189};
190
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000191#ifdef F_NOTIFY
192static const struct xlat notifyflags[] = {
193#ifdef DN_ACCESS
194 { DN_ACCESS, "DN_ACCESS" },
195#endif
196#ifdef DN_MODIFY
197 { DN_MODIFY, "DN_MODIFY" },
198#endif
199#ifdef DN_CREATE
200 { DN_CREATE, "DN_CREATE" },
201#endif
202#ifdef DN_DELETE
203 { DN_DELETE, "DN_DELETE" },
204#endif
205#ifdef DN_RENAME
206 { DN_RENAME, "DN_RENAME" },
207#endif
208#ifdef DN_ATTRIB
209 { DN_ATTRIB, "DN_ATTRIB" },
210#endif
211#ifdef DN_MULTISHOT
212 { DN_MULTISHOT, "DN_MULTISHOT" },
213#endif
214 { 0, NULL },
215};
216#endif
217
Roland McGrathd9f816f2004-09-04 03:39:20 +0000218static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000219 { SEEK_SET, "SEEK_SET" },
220 { SEEK_CUR, "SEEK_CUR" },
221 { SEEK_END, "SEEK_END" },
222 { 0, NULL },
223};
224
John Hughes70623be2001-03-08 13:59:00 +0000225#ifndef HAVE_LONG_LONG_OFF_T
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
233 if (personality_wordsize[current_personality] != sizeof(fl.l_start)) {
234 if (personality_wordsize[current_personality] == 4) {
235 /* 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 */
254 tprintf("{ <decode error: unsupported wordsize %d> }",
255 personality_wordsize[current_personality]);
256 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=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269 printxval(whence, fl.l_whence, "SEEK_???");
270 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}
John Hughesb8c9f772001-03-07 16:53:07 +0000276#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277
John Hughes70623be2001-03-08 13:59:00 +0000278#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000279/* fcntl/lockf */
280static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000281printflock64(struct tcb *tcp, long addr, int getlk)
John Hughesbdf48f52001-03-06 15:08:09 +0000282{
283 struct flock64 fl;
284
285 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200286 tprints("{...}");
John Hughesbdf48f52001-03-06 15:08:09 +0000287 return;
288 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200289 tprints("{type=");
John Hughesbdf48f52001-03-06 15:08:09 +0000290 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200291 tprints(", whence=");
John Hughesbdf48f52001-03-06 15:08:09 +0000292 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000293 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000294 if (getlk)
295 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
296 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200297 tprints("}");
John Hughesbdf48f52001-03-06 15:08:09 +0000298}
299#endif
300
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000301int
302sys_fcntl(struct tcb *tcp)
303{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000304 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300305 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200306 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000307 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
308 switch (tcp->u_arg[1]) {
309 case F_SETFD:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200310 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000311 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312 break;
313 case F_SETOWN: case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000314#ifdef F_DUPFD_CLOEXEC
315 case F_DUPFD_CLOEXEC:
316#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000317 tprintf(", %ld", tcp->u_arg[2]);
318 break;
319 case F_SETFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200320 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000321 tprint_open_modes(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000322 break;
323 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000324#ifdef F_FREESP
325 case F_FREESP:
326#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200327 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000328 printflock(tcp, tcp->u_arg[2], 0);
329 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000330#if _LFS64_LARGEFILE
331#ifdef F_FREESP64
332 case F_FREESP64:
333#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000334 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000335 even though the kernel has different values - as does Solaris. */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000336#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000337 case F_SETLK64:
338#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000339#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
John Hughesbdf48f52001-03-06 15:08:09 +0000340 case F_SETLKW64:
341#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200342 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000343 printflock64(tcp, tcp->u_arg[2], 0);
344 break;
345#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000346#ifdef F_NOTIFY
347 case F_NOTIFY:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200348 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000349 printflags(notifyflags, tcp->u_arg[2], "DN_???");
350 break;
351#endif
352#ifdef F_SETLEASE
353 case F_SETLEASE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000355 printxval(lockfcmds, tcp->u_arg[2], "F_???");
356 break;
357#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000358 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000359 }
360 else {
361 switch (tcp->u_arg[1]) {
362 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000363#ifdef F_DUPFD_CLOEXEC
364 case F_DUPFD_CLOEXEC:
365#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000366 case F_SETFD: case F_SETFL:
367 case F_SETLK: case F_SETLKW:
368 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000369#ifdef F_NOTIFY
370 case F_NOTIFY:
371#endif
372#ifdef F_SETLEASE
373 case F_SETLEASE:
374#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000375 break;
376 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000377 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000379 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000380 return RVAL_HEX|RVAL_STR;
381 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000382 if (syserror(tcp))
383 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000384 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000385 return RVAL_HEX|RVAL_STR;
386 case F_GETLK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200387 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000388 printflock(tcp, tcp->u_arg[2], 1);
389 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000390#if _LFS64_LARGEFILE
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200391#if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
John Hughesbdf48f52001-03-06 15:08:09 +0000392 case F_GETLK64:
393#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200394 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000395 printflock64(tcp, tcp->u_arg[2], 1);
396 break;
397#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000398#ifdef F_GETLEASE
399 case F_GETLEASE:
400 if (syserror(tcp))
401 return 0;
402 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
403 return RVAL_HEX|RVAL_STR;
404#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000405 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 tprintf(", %#lx", tcp->u_arg[2]);
407 break;
408 }
409 }
410 return 0;
411}
412
413#ifdef LOCK_SH
414
415int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000416sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417{
418 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300419 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200420 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000421 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 }
423 return 0;
424}
425#endif /* LOCK_SH */
426
427int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000428sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429{
430 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300431 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000432 }
433 return 0;
434}
435
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000436static int
437do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438{
439 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300440 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200441 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300442 printfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000443 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200444 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000445 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
446 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 }
448 return 0;
449}
450
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000451int
452sys_dup2(struct tcb *tcp)
453{
454 return do_dup2(tcp, -1);
455}
456
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000457int
458sys_dup3(struct tcb *tcp)
459{
460 return do_dup2(tcp, 2);
461}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000462
Denys Vlasenko84703742012-02-25 02:38:52 +0100463#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000465sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000466{
467 return 0;
468}
Denys Vlasenko84703742012-02-25 02:38:52 +0100469#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470
471static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000472decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000473{
Denys Vlasenkoad5155a2011-09-01 18:18:04 +0200474 int i, j;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200475 unsigned nfds, fdsize;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000476 fd_set *fds;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000477 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000478 long arg;
479
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200480 fdsize = args[0];
481 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
482 if (args[0] > 1024*1024)
483 fdsize = 1024*1024;
484 if (args[0] < 0)
485 fdsize = 0;
486 fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long);
487
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488 if (entering(tcp)) {
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200489 fds = malloc(fdsize);
490 if (!fds)
491 die_out_of_memory();
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000492 nfds = args[0];
493 tprintf("%d", nfds);
494 for (i = 0; i < 3; i++) {
495 arg = args[i+1];
496 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200497 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498 continue;
499 }
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200500 if (!verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 tprintf(", %#lx", arg);
502 continue;
503 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000504 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200505 tprints(", [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000506 continue;
507 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200508 tprints(", [");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000509 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000510 if (FD_ISSET(j, fds)) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200511 tprints(sep);
Dmitry V. Levin31382132011-03-04 05:08:02 +0300512 printfd(tcp, j);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513 sep = " ";
514 }
515 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200516 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000518 free(fds);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200519 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000520 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000521 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200522 else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200523 static char outstr[1024];
524 char *outptr;
525#define end_outstr (outstr + sizeof(outstr))
526 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527
528 if (syserror(tcp))
529 return 0;
530
Denys Vlasenko5d645812011-08-20 12:48:18 +0200531 nfds = tcp->u_rval;
532 if (nfds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000533 tcp->auxstr = "Timeout";
534 return RVAL_STR;
535 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000536
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200537 fds = malloc(fdsize);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200538 if (!fds)
539 die_out_of_memory();
Roland McGrathe85aaa42005-02-06 01:55:12 +0000540
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200541 outptr = outstr;
542 sep = "";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000543 for (i = 0; i < 3; i++) {
544 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000546 arg = args[i+1];
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200547 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000548 continue;
549 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000550 if (FD_ISSET(j, fds)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200551 /* +2 chars needed at the end: ']',NUL */
552 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
553 if (first) {
554 outptr += sprintf(outptr, "%s%s [%u",
555 sep,
556 i == 0 ? "in" : i == 1 ? "out" : "except",
557 j
558 );
559 first = 0;
560 sep = ", ";
561 }
562 else {
563 outptr += sprintf(outptr, " %u", j);
564 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000565 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 nfds--;
567 }
568 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200569 if (outptr != outstr)
570 *outptr++ = ']';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000571 if (nfds == 0)
572 break;
573 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000574 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000575 /* This contains no useful information on SunOS. */
576 if (args[4]) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100577 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200578 outptr += sprintf(outptr, "%sleft ", sep);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100579 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200580 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200582 *outptr = '\0';
Denys Vlasenko11617252011-09-01 11:27:37 +0200583 tcp->auxstr = outstr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200585#undef end_outstr
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000586 }
587 return 0;
588}
589
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000591sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000592{
593 long args[5];
594
595 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200596 tprints("[...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000597 return 0;
598 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000599 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600}
601
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000602#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000603int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000604sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000605{
606 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000607 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000608}
609#endif
610
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000611static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000612#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000613 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000614#endif
615#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000616 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000617#endif
618#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000619 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000620#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000621 { 0, NULL }
622};
623
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000624static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000625#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000626 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000627#endif
628#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000629 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000630#endif
631#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000632 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000633#endif
634#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000635 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000636#endif
637#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000638 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000639#endif
640#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000641 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000642#endif
643#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000644 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000645#endif
646#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000647 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000648#endif
649#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000650 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000651#endif
652#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000653 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000654#endif
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000655#ifdef EPOLLRDHUP
656 { EPOLLRDHUP, "EPOLLRDHUP" },
657#endif
Roland McGrath63d6e542004-10-20 02:17:41 +0000658#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000659 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000660#endif
661#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000662 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000663#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000664 { 0, NULL }
665};
666
Denys Vlasenko72879c62012-02-27 14:18:02 +0100667/* Not aliased to printargs_ld: we want it to have a distinct address */
Roland McGrath93817bf2004-10-06 22:23:31 +0000668int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000669sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000670{
Denys Vlasenko72879c62012-02-27 14:18:02 +0100671 return printargs_ld(tcp);
Roland McGrath93817bf2004-10-06 22:23:31 +0000672}
673
Mike Frysingeraed334c2011-10-13 22:33:45 -0400674static const struct xlat epollflags[] = {
675#ifdef EPOLL_CLOEXEC
676 { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" },
677#endif
678#ifdef EPOLL_NONBLOCK
679 { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" },
680#endif
681 { 0, NULL }
682};
683
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000684int
685sys_epoll_create1(struct tcb *tcp)
686{
687 if (entering(tcp))
Mike Frysingeraed334c2011-10-13 22:33:45 -0400688 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000689 return 0;
690}
691
Roland McGrath63d6e542004-10-20 02:17:41 +0000692#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000693static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000694print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000695{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200696 tprints("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000697 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000698 /* We cannot know what format the program uses, so print u32 and u64
699 which will cover every value. */
700 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
701 ev->data.u32, ev->data.u64);
702}
Roland McGrath63d6e542004-10-20 02:17:41 +0000703#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000704
705int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000706sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000707{
708 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300709 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200710 tprints(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000711 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200712 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300713 printfd(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200714 tprints(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000715 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200716 tprints("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000717 else {
718#ifdef HAVE_SYS_EPOLL_H
719 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000720 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000721 print_epoll_event(&ev);
722 else
723#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200724 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000725 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000726 }
727 return 0;
728}
729
Roland McGrathf2400052007-08-02 01:13:26 +0000730static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000731epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000732{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300733 if (entering(tcp)) {
734 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200735 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300736 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000737 if (syserror(tcp))
738 tprintf("%lx", tcp->u_arg[1]);
739 else if (tcp->u_rval == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200740 tprints("{}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000741 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000742#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000743 struct epoll_event ev, *start, *cur, *end;
744 int failed = 0;
745
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200746 tprints("{");
Roland McGrathaa524c82005-06-01 19:22:06 +0000747 start = (struct epoll_event *) tcp->u_arg[1];
748 end = start + tcp->u_rval;
749 for (cur = start; cur < end; ++cur) {
750 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200751 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000752 if (umove(tcp, (long) cur, &ev) == 0)
753 print_epoll_event(&ev);
754 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200755 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000756 failed = 1;
757 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000758 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000759 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200760 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000761 if (failed)
762 tprintf(" %#lx", (long) start);
763#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200764 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000765#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000766 }
Dmitry V. Levinc327d712011-10-11 16:05:57 +0000767 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
Roland McGrath93817bf2004-10-06 22:23:31 +0000768 }
Roland McGrathf2400052007-08-02 01:13:26 +0000769}
770
771int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000772sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000773{
774 epoll_wait_common(tcp);
775 return 0;
776}
777
778int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000779sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000780{
781 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000782 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200783 tprints(", ");
Roland McGrathf2400052007-08-02 01:13:26 +0000784 print_sigset(tcp, tcp->u_arg[4], 0);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000785 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000786 return 0;
787}
Roland McGrath37b9f842005-05-09 08:02:00 +0000788
789int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000790sys_io_setup(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000791{
792 if (entering(tcp))
793 tprintf("%ld, ", tcp->u_arg[0]);
794 else {
795 if (syserror(tcp))
796 tprintf("0x%0lx", tcp->u_arg[1]);
797 else {
798 unsigned long user_id;
799 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
800 tprintf("{%lu}", user_id);
801 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200802 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000803 }
804 }
805 return 0;
806}
807
808int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000809sys_io_destroy(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000810{
811 if (entering(tcp))
812 tprintf("%lu", tcp->u_arg[0]);
813 return 0;
814}
815
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000816#ifdef HAVE_LIBAIO_H
817
Andi Kleendfcd7412011-06-13 22:05:44 +0000818enum iocb_sub {
819 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
820};
821
822static const char *
823iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub)
824{
Denys Vlasenko79992622011-08-19 19:44:17 +0200825 static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3];
826 static const struct {
Andi Kleendfcd7412011-06-13 22:05:44 +0000827 const char *name;
828 enum iocb_sub sub;
829 } cmds[] = {
830 { "pread", SUB_COMMON },
831 { "pwrite", SUB_COMMON },
832 { "fsync", SUB_NONE },
833 { "fdsync", SUB_NONE },
834 { "op4", SUB_NONE },
835 { "poll", SUB_POLL },
836 { "noop", SUB_NONE },
837 { "preadv", SUB_VECTOR },
838 { "pwritev", SUB_VECTOR },
839 };
840
841 if (cmd < ARRAY_SIZE(cmds)) {
842 *sub = cmds[cmd].sub;
843 return cmds[cmd].name;
844 }
845 *sub = SUB_NONE;
Denys Vlasenko79992622011-08-19 19:44:17 +0200846 sprintf(buf, "%u /* SUB_??? */", cmd);
Andi Kleendfcd7412011-06-13 22:05:44 +0000847 return buf;
848}
849
850/* Not defined in libaio.h */
851#ifndef IOCB_RESFD
852# define IOCB_RESFD (1 << 0)
853#endif
854
855static void
856print_common_flags(struct iocb *iocb)
857{
858 if (iocb->u.c.flags & IOCB_RESFD)
859 tprintf("resfd=%d, ", iocb->u.c.resfd);
860 if (iocb->u.c.flags & ~IOCB_RESFD)
861 tprintf("flags=%x, ", iocb->u.c.flags);
862}
Dmitry V. Levin081e72f2011-06-21 15:11:57 +0000863
864#endif /* HAVE_LIBAIO_H */
865
Roland McGrath37b9f842005-05-09 08:02:00 +0000866int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000867sys_io_submit(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000868{
869 long nr;
870 if (entering(tcp)) {
871 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
872 nr = tcp->u_arg[1];
873 /* and if nr is negative? */
874 if (nr == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200875 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000876 else {
877#ifdef HAVE_LIBAIO_H
878 long i;
879 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
880
881 for (i = 0; i < nr; i++, iocbs++) {
Andi Kleendfcd7412011-06-13 22:05:44 +0000882 enum iocb_sub sub;
Roland McGrath37b9f842005-05-09 08:02:00 +0000883 struct iocb iocb;
884 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200885 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +0000886 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200887 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000888
889 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
890 umove(tcp, (unsigned long)iocbp, &iocb)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200891 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000892 continue;
893 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200894 tprints("{");
Andi Kleendfcd7412011-06-13 22:05:44 +0000895 if (iocb.data)
896 tprintf("data:%p, ", iocb.data);
897 if (iocb.key)
898 tprintf("key:%u, ", iocb.key);
899 tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub));
900 if (iocb.aio_reqprio)
901 tprintf("reqprio:%d, ", iocb.aio_reqprio);
902 tprintf("filedes:%d", iocb.aio_fildes);
903 switch (sub) {
904 case SUB_COMMON:
905 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200906 tprints(", str:");
Andi Kleendfcd7412011-06-13 22:05:44 +0000907 printstr(tcp, (unsigned long)iocb.u.c.buf,
908 iocb.u.c.nbytes);
909 } else {
910 tprintf(", buf:%p", iocb.u.c.buf);
911 }
912 tprintf(", nbytes:%lu, offset:%llx",
913 iocb.u.c.nbytes,
914 iocb.u.c.offset);
915 print_common_flags(&iocb);
916 break;
917 case SUB_VECTOR:
918 tprintf(", %llx, ", iocb.u.v.offset);
919 print_common_flags(&iocb);
920 tprint_iov(tcp, iocb.u.v.nr,
921 (unsigned long)iocb.u.v.vec,
922 iocb.aio_lio_opcode == IO_CMD_PWRITEV);
923 break;
924 case SUB_POLL:
925 tprintf(", %x", iocb.u.poll.events);
926 break;
927 case SUB_NONE:
928 break;
929 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200930 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000931 }
932 if (i)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200933 tprints("}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000934#else
Andi Kleendfcd7412011-06-13 22:05:44 +0000935#warning "libaio-devel is not available => no io_submit decoding"
936 tprintf("%#lx", tcp->u_arg[2]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000937#endif
938 }
939 }
940 return 0;
941}
942
943int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000944sys_io_cancel(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000945{
946 if (entering(tcp)) {
947#ifdef HAVE_LIBAIO_H
948 struct iocb iocb;
949#endif
950 tprintf("%lu, ", tcp->u_arg[0]);
951#ifdef HAVE_LIBAIO_H
952 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
953 tprintf("{%p, %u, %hu, %hu, %d}, ",
954 iocb.data, iocb.key,
955 iocb.aio_lio_opcode,
956 iocb.aio_reqprio, iocb.aio_fildes);
957 } else
958#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200959 tprints("{...}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000960 } else {
961 if (tcp->u_rval < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200962 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000963 else {
964#ifdef HAVE_LIBAIO_H
965 struct io_event event;
966 if (umove(tcp, tcp->u_arg[2], &event) == 0)
967 tprintf("{%p, %p, %ld, %ld}",
968 event.data, event.obj,
969 event.res, event.res2);
Dmitry V. Levin414fe7d2009-07-08 11:21:17 +0000970 else
Roland McGrath37b9f842005-05-09 08:02:00 +0000971#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200972 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000973 }
974 }
975 return 0;
976}
977
978int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000979sys_io_getevents(struct tcb *tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000980{
981 if (entering(tcp)) {
982 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
983 tcp->u_arg[2]);
984 } else {
985 if (tcp->u_rval == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200986 tprints("{}");
Roland McGrath37b9f842005-05-09 08:02:00 +0000987 } else {
988#ifdef HAVE_LIBAIO_H
989 struct io_event *events = (void *)tcp->u_arg[3];
990 long i, nr = tcp->u_rval;
991
992 for (i = 0; i < nr; i++, events++) {
993 struct io_event event;
994
995 if (i == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200996 tprints("{");
Roland McGrath37b9f842005-05-09 08:02:00 +0000997 else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200998 tprints(", ");
Roland McGrath37b9f842005-05-09 08:02:00 +0000999
1000 if (umove(tcp, (unsigned long)events, &event) != 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001001 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001002 continue;
1003 }
1004 tprintf("{%p, %p, %ld, %ld}", event.data,
1005 event.obj, event.res, event.res2);
1006 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001007 tprints("}, ");
Roland McGrath37b9f842005-05-09 08:02:00 +00001008#else
Denys Vlasenkob237b1b2012-02-27 13:56:59 +01001009 tprints("{...}");
Roland McGrath37b9f842005-05-09 08:02:00 +00001010#endif
1011 }
1012
Roland McGrath6bc09da2007-11-01 21:50:54 +00001013 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +00001014 }
1015 return 0;
1016}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001017
1018int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +00001019sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001020{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001021 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001022}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001023
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001024int
1025sys_pselect6(struct tcb *tcp)
1026{
Dmitry V. Levina7945a32006-12-13 17:10:11 +00001027 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +00001028 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001029 struct {
1030 void *ss;
1031 unsigned long len;
1032 } data;
1033 if (umove(tcp, tcp->u_arg[5], &data) < 0)
1034 tprintf(", %#lx", tcp->u_arg[5]);
1035 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001036 tprints(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +00001037 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +00001038 tprintf("%#lx", (long)data.ss);
1039 else
1040 print_sigset(tcp, (long)data.ss, 0);
1041 tprintf(", %lu}", data.len);
1042 }
1043 }
1044 return rc;
1045}
Roland McGrathe7c39672007-08-02 01:32:17 +00001046
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001047static int
1048do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +00001049{
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001050 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +00001051 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001052 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +02001053 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001054 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
1055 }
1056 }
Roland McGrathe7c39672007-08-02 01:32:17 +00001057 return 0;
1058}
Dmitry V. Levin4371b102008-11-10 22:53:02 +00001059
1060int
1061sys_eventfd(struct tcb *tcp)
1062{
1063 return do_eventfd(tcp, -1);
1064}
1065
1066int
1067sys_eventfd2(struct tcb *tcp)
1068{
1069 return do_eventfd(tcp, 1);
1070}