blob: 0686bf4097077b8c95b20ec64ee147b93797f9eb [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
Ben Noordhuis88eafd82013-02-04 00:04:57 +010037#ifdef HAVE_LINUX_PERF_EVENT_H
38# include <linux/perf_event.h>
39#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040
Roland McGrathd9f816f2004-09-04 03:39:20 +000041static const struct xlat fcntlcmds[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000042 XLAT(F_DUPFD),
43 XLAT(F_GETFD),
44 XLAT(F_SETFD),
45 XLAT(F_GETFL),
46 XLAT(F_SETFL),
47 XLAT(F_GETLK),
48 XLAT(F_SETLK),
49 XLAT(F_SETLKW),
50 XLAT(F_GETOWN),
51 XLAT(F_SETOWN),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000052#ifdef F_RSETLK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000053 XLAT(F_RSETLK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000054#endif
55#ifdef F_RSETLKW
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000056 XLAT(F_RSETLKW),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057#endif
58#ifdef F_RGETLK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000059 XLAT(F_RGETLK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060#endif
61#ifdef F_CNVT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000062 XLAT(F_CNVT),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000063#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000064#ifdef F_SETSIG
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000065 XLAT(F_SETSIG),
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000066#endif
67#ifdef F_GETSIG
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000068 XLAT(F_GETSIG),
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000069#endif
John Hughesbdf48f52001-03-06 15:08:09 +000070#ifdef F_CHKFL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000071 XLAT(F_CHKFL),
John Hughesbdf48f52001-03-06 15:08:09 +000072#endif
73#ifdef F_DUP2FD
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000074 XLAT(F_DUP2FD),
John Hughesbdf48f52001-03-06 15:08:09 +000075#endif
76#ifdef F_ALLOCSP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000077 XLAT(F_ALLOCSP),
John Hughesbdf48f52001-03-06 15:08:09 +000078#endif
79#ifdef F_ISSTREAM
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000080 XLAT(F_ISSTREAM),
John Hughesbdf48f52001-03-06 15:08:09 +000081#endif
82#ifdef F_PRIV
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000083 XLAT(F_PRIV),
John Hughesbdf48f52001-03-06 15:08:09 +000084#endif
85#ifdef F_NPRIV
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000086 XLAT(F_NPRIV),
John Hughesbdf48f52001-03-06 15:08:09 +000087#endif
88#ifdef F_QUOTACL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000089 XLAT(F_QUOTACL),
John Hughesbdf48f52001-03-06 15:08:09 +000090#endif
91#ifdef F_BLOCKS
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000092 XLAT(F_BLOCKS),
John Hughesbdf48f52001-03-06 15:08:09 +000093#endif
94#ifdef F_BLKSIZE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000095 XLAT(F_BLKSIZE),
John Hughesbdf48f52001-03-06 15:08:09 +000096#endif
97#ifdef F_GETOWN
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +000098 XLAT(F_GETOWN),
John Hughesbdf48f52001-03-06 15:08:09 +000099#endif
100#ifdef F_SETOWN
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000101 XLAT(F_SETOWN),
John Hughesbdf48f52001-03-06 15:08:09 +0000102#endif
103#ifdef F_REVOKE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000104 XLAT(F_REVOKE),
John Hughesbdf48f52001-03-06 15:08:09 +0000105#endif
106#ifdef F_SETLK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000107 XLAT(F_SETLK),
John Hughesbdf48f52001-03-06 15:08:09 +0000108#endif
109#ifdef F_SETLKW
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000110 XLAT(F_SETLKW),
John Hughesbdf48f52001-03-06 15:08:09 +0000111#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000112#ifdef F_GETLK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000113 XLAT(F_GETLK),
John Hughesbdf48f52001-03-06 15:08:09 +0000114#endif
115#ifdef F_SETLK64
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000116 XLAT(F_SETLK64),
John Hughesbdf48f52001-03-06 15:08:09 +0000117#endif
118#ifdef F_SETLKW64
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000119 XLAT(F_SETLKW64),
John Hughesbdf48f52001-03-06 15:08:09 +0000120#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000121#ifdef F_GETLK64
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000122 XLAT(F_GETLK64),
John Hughesbdf48f52001-03-06 15:08:09 +0000123#endif
124#ifdef F_SHARE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000125 XLAT(F_SHARE),
John Hughesbdf48f52001-03-06 15:08:09 +0000126#endif
127#ifdef F_UNSHARE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000128 XLAT(F_UNSHARE),
John Hughesbdf48f52001-03-06 15:08:09 +0000129#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000130#ifdef F_SETLEASE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000131 XLAT(F_SETLEASE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000132#endif
133#ifdef F_GETLEASE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000134 XLAT(F_GETLEASE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000135#endif
136#ifdef F_NOTIFY
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000137 XLAT(F_NOTIFY),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000138#endif
139#ifdef F_DUPFD_CLOEXEC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000140 XLAT(F_DUPFD_CLOEXEC),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000141#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000142 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143};
144
Roland McGrathd9f816f2004-09-04 03:39:20 +0000145static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146#ifdef FD_CLOEXEC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000147 XLAT(FD_CLOEXEC),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000148#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000149 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150};
151
152#ifdef LOCK_SH
153
Roland McGrathd9f816f2004-09-04 03:39:20 +0000154static const struct xlat flockcmds[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000155 XLAT(LOCK_SH),
156 XLAT(LOCK_EX),
157 XLAT(LOCK_NB),
158 XLAT(LOCK_UN),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000159 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160};
161
162#endif /* LOCK_SH */
163
Roland McGrathd9f816f2004-09-04 03:39:20 +0000164static const struct xlat lockfcmds[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000165 XLAT(F_RDLCK),
166 XLAT(F_WRLCK),
167 XLAT(F_UNLCK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000168#ifdef F_EXLCK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000169 XLAT(F_EXLCK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170#endif
171#ifdef F_SHLCK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000172 XLAT(F_SHLCK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000174 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175};
176
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000177#ifdef F_NOTIFY
178static const struct xlat notifyflags[] = {
179#ifdef DN_ACCESS
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000180 XLAT(DN_ACCESS),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000181#endif
182#ifdef DN_MODIFY
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000183 XLAT(DN_MODIFY),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000184#endif
185#ifdef DN_CREATE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000186 XLAT(DN_CREATE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000187#endif
188#ifdef DN_DELETE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000189 XLAT(DN_DELETE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000190#endif
191#ifdef DN_RENAME
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000192 XLAT(DN_RENAME),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000193#endif
194#ifdef DN_ATTRIB
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000195 XLAT(DN_ATTRIB),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000196#endif
197#ifdef DN_MULTISHOT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000198 XLAT(DN_MULTISHOT),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000199#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000200 XLAT_END
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000201};
202#endif
203
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100204static const struct xlat perf_event_open_flags[] = {
205#ifdef PERF_FLAG_FD_NO_GROUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000206 XLAT(PERF_FLAG_FD_NO_GROUP),
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100207#endif
208#ifdef PERF_FLAG_FD_OUTPUT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000209 XLAT(PERF_FLAG_FD_OUTPUT),
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100210#endif
211#ifdef PERF_FLAG_PID_CGROUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000212 XLAT(PERF_FLAG_PID_CGROUP),
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100213#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000214 XLAT_END
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100215};
216
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000217/*
218 * Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined
219 * or not defined altogether.
220 */
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000221#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000222# define USE_PRINTFLOCK64 1
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000223#else
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000224# define USE_PRINTFLOCK64 0
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000225#endif
226
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000227#if USE_PRINTFLOCK64
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000228
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000229# ifndef HAVE_STRUCT_FLOCK64
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000230struct flock64 {
231 short int l_type, l_whence;
232 int64_t l_start, l_len;
233 int l_pid;
234};
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000235# endif
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000236
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000237static void
238printflock64(struct tcb *tcp, long addr, int getlk)
239{
240 struct flock64 fl;
241
242 if (umove(tcp, addr, &fl) < 0) {
243 tprints("{...}");
244 return;
245 }
246 tprints("{type=");
247 printxval(lockfcmds, fl.l_type, "F_???");
248 tprints(", whence=");
249 printxval(whence_codes, fl.l_whence, "SEEK_???");
250 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
251 if (getlk)
252 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
253 else
254 tprints("}");
255}
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000256#endif /* USE_PRINTFLOCK64 */
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000257
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000259printflock(struct tcb *tcp, long addr, int getlk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000260{
261 struct flock fl;
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000262 int r;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000263
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000264#if SUPPORTED_PERSONALITIES > 1
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000265 if (
266# if SIZEOF_OFF_T > SIZEOF_LONG
267 current_personality > 0 &&
268#endif
269 current_wordsize != sizeof(fl.l_start)) {
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100270 if (current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000271 /* 32-bit x86 app on x86_64 and similar cases */
272 struct {
273 short int l_type;
274 short int l_whence;
275 int32_t l_start; /* off_t */
276 int32_t l_len; /* off_t */
277 int32_t l_pid; /* pid_t */
278 } fl32;
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000279 r = umove(tcp, addr, &fl32);
280 if (r >= 0) {
281 fl.l_type = fl32.l_type;
282 fl.l_whence = fl32.l_whence;
283 fl.l_start = fl32.l_start;
284 fl.l_len = fl32.l_len;
285 fl.l_pid = fl32.l_pid;
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000286 }
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000287 } else {
288 /* let people know we have a problem here */
Denys Vlasenko751acb32013-02-08 15:34:46 +0100289 tprintf("<decode error: unsupported wordsize %d>",
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100290 current_wordsize);
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000291 return;
292 }
293 } else
294#endif
295 {
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000296 r = umove(tcp, addr, &fl);
297 }
298 if (r < 0) {
299 tprints("{...}");
300 return;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200302 tprints("{type=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000303 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200304 tprints(", whence=");
Denys Vlasenko86738a22013-02-17 14:31:55 +0100305 printxval(whence_codes, fl.l_whence, "SEEK_???");
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000306#if SIZEOF_OFF_T > SIZEOF_LONG
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000307 tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len);
308#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000309 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000310#endif
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000311 if (getlk)
312 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
313 else
314 tprints("}");
315}
John Hughesbdf48f52001-03-06 15:08:09 +0000316
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:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200340 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341 printflock(tcp, tcp->u_arg[2], 0);
342 break;
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000343#if USE_PRINTFLOCK64
344 case F_SETLK64: case F_SETLKW64:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200345 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000346 printflock64(tcp, tcp->u_arg[2], 0);
347 break;
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000348#endif /* USE_PRINTFLOCK64 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000349#ifdef F_NOTIFY
350 case F_NOTIFY:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200351 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000352 printflags(notifyflags, tcp->u_arg[2], "DN_???");
353 break;
354#endif
355#ifdef F_SETLEASE
356 case F_SETLEASE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200357 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000358 printxval(lockfcmds, tcp->u_arg[2], "F_???");
359 break;
360#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000361 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362 }
363 else {
364 switch (tcp->u_arg[1]) {
365 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000366#ifdef F_DUPFD_CLOEXEC
367 case F_DUPFD_CLOEXEC:
368#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000369 case F_SETFD: case F_SETFL:
370 case F_SETLK: case F_SETLKW:
371 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000372#ifdef F_NOTIFY
373 case F_NOTIFY:
374#endif
375#ifdef F_SETLEASE
376 case F_SETLEASE:
377#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378 break;
379 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000380 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000381 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000382 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000383 return RVAL_HEX|RVAL_STR;
384 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000385 if (syserror(tcp))
386 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000387 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000388 return RVAL_HEX|RVAL_STR;
389 case F_GETLK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200390 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000391 printflock(tcp, tcp->u_arg[2], 1);
392 break;
Dmitry V. Levin54cabef2014-03-03 23:09:47 +0000393#if USE_PRINTFLOCK64
John Hughesbdf48f52001-03-06 15:08:09 +0000394 case F_GETLK64:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200395 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000396 printflock64(tcp, tcp->u_arg[2], 1);
397 break;
398#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000399#ifdef F_GETLEASE
400 case F_GETLEASE:
401 if (syserror(tcp))
402 return 0;
403 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
404 return RVAL_HEX|RVAL_STR;
405#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000406 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000407 tprintf(", %#lx", tcp->u_arg[2]);
408 break;
409 }
410 }
411 return 0;
412}
413
414#ifdef LOCK_SH
415
416int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000417sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000418{
419 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300420 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200421 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000422 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000423 }
424 return 0;
425}
426#endif /* LOCK_SH */
427
428int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000429sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000430{
431 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300432 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433 }
434 return 0;
435}
436
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000437static int
438do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000439{
440 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300441 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200442 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300443 printfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000444 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200445 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000446 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
447 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448 }
449 return 0;
450}
451
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000452int
453sys_dup2(struct tcb *tcp)
454{
455 return do_dup2(tcp, -1);
456}
457
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000458int
459sys_dup3(struct tcb *tcp)
460{
461 return do_dup2(tcp, 2);
462}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000463
Denys Vlasenko84703742012-02-25 02:38:52 +0100464#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000465int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000466sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000467{
468 return 0;
469}
Denys Vlasenko84703742012-02-25 02:38:52 +0100470#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471
Dmitry V. Levinc2982b52013-11-05 23:00:22 +0000472static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000473decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474{
Denys Vlasenkoad5155a2011-09-01 18:18:04 +0200475 int i, j;
Denys Vlasenko1f65c3c2013-11-05 16:20:16 +0100476 int nfds, fdsize;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000477 fd_set *fds;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000478 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479 long arg;
480
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000481 /* Kernel truncates arg[0] to int, we do the same. */
482 nfds = (int) args[0];
483
484 /* Kernel rejects negative nfds, so we don't parse it either. */
485 if (nfds < 0) {
486 nfds = 0;
487 fds = NULL;
488 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200489 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000490 if (nfds > 1024*1024)
491 nfds = 1024*1024;
492
493 /*
494 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
Dr. David Alan Gilbert025f1082013-11-05 11:54:51 +0100495 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
496 */
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100497 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200498
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000499 if (entering(tcp)) {
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000500 tprintf("%d", (int) args[0]);
501
502 if (fdsize > 0) {
503 fds = malloc(fdsize);
504 if (!fds)
505 die_out_of_memory();
506 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000507 for (i = 0; i < 3; i++) {
508 arg = args[i+1];
509 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200510 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000511 continue;
512 }
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000513 if (!verbose(tcp) || !fds) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000514 tprintf(", %#lx", arg);
515 continue;
516 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000517 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200518 tprints(", [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000519 continue;
520 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200521 tprints(", [");
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100522 for (j = 0, sep = "";; j++) {
523 j = next_set_bit(fds, j, nfds);
524 if (j < 0)
525 break;
526 tprints(sep);
527 printfd(tcp, j);
528 sep = " ";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000529 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200530 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000531 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000532 free(fds);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200533 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000534 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000535 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200536 else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200537 static char outstr[1024];
538 char *outptr;
539#define end_outstr (outstr + sizeof(outstr))
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000540 int ready_fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000541
542 if (syserror(tcp))
543 return 0;
544
Dr. David Alan Gilbert025f1082013-11-05 11:54:51 +0100545 ready_fds = tcp->u_rval;
546 if (ready_fds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000547 tcp->auxstr = "Timeout";
548 return RVAL_STR;
549 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000550
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200551 fds = malloc(fdsize);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200552 if (!fds)
553 die_out_of_memory();
Roland McGrathe85aaa42005-02-06 01:55:12 +0000554
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200555 outptr = outstr;
556 sep = "";
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000557 for (i = 0; i < 3 && ready_fds > 0; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000558 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000559
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560 arg = args[i+1];
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200561 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 continue;
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100563 for (j = 0;; j++) {
564 j = next_set_bit(fds, j, nfds);
565 if (j < 0)
566 break;
567 /* +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 = ", ";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000577 }
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100578 else {
579 outptr += sprintf(outptr, " %u", j);
580 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000581 }
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100582 if (--ready_fds == 0)
583 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000584 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200585 if (outptr != outstr)
586 *outptr++ = ']';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000587 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000588 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589 /* This contains no useful information on SunOS. */
590 if (args[4]) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100591 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200592 outptr += sprintf(outptr, "%sleft ", sep);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100593 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200594 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000595 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200596 *outptr = '\0';
Denys Vlasenko11617252011-09-01 11:27:37 +0200597 tcp->auxstr = outstr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000598 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200599#undef end_outstr
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000600 }
601 return 0;
602}
603
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000604int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000605sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000606{
607 long args[5];
608
609 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200610 tprints("[...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000611 return 0;
612 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000613 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000614}
615
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000616#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000617int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000618sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000619{
620 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000621 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000622}
623#endif
624
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000625static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000626#ifdef EPOLL_CTL_ADD
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000627 XLAT(EPOLL_CTL_ADD),
Roland McGrath63d6e542004-10-20 02:17:41 +0000628#endif
629#ifdef EPOLL_CTL_MOD
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000630 XLAT(EPOLL_CTL_MOD),
Roland McGrath63d6e542004-10-20 02:17:41 +0000631#endif
632#ifdef EPOLL_CTL_DEL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000633 XLAT(EPOLL_CTL_DEL),
Roland McGrath63d6e542004-10-20 02:17:41 +0000634#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000635 XLAT_END
Roland McGrath93817bf2004-10-06 22:23:31 +0000636};
637
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000638static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000639#ifdef EPOLLIN
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000640 XLAT(EPOLLIN),
Roland McGrath63d6e542004-10-20 02:17:41 +0000641#endif
642#ifdef EPOLLPRI
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000643 XLAT(EPOLLPRI),
Roland McGrath63d6e542004-10-20 02:17:41 +0000644#endif
645#ifdef EPOLLOUT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000646 XLAT(EPOLLOUT),
Roland McGrath63d6e542004-10-20 02:17:41 +0000647#endif
648#ifdef EPOLLRDNORM
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000649 XLAT(EPOLLRDNORM),
Roland McGrath63d6e542004-10-20 02:17:41 +0000650#endif
651#ifdef EPOLLRDBAND
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000652 XLAT(EPOLLRDBAND),
Roland McGrath63d6e542004-10-20 02:17:41 +0000653#endif
654#ifdef EPOLLWRNORM
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000655 XLAT(EPOLLWRNORM),
Roland McGrath63d6e542004-10-20 02:17:41 +0000656#endif
657#ifdef EPOLLWRBAND
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000658 XLAT(EPOLLWRBAND),
Roland McGrath63d6e542004-10-20 02:17:41 +0000659#endif
660#ifdef EPOLLMSG
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000661 XLAT(EPOLLMSG),
Roland McGrath63d6e542004-10-20 02:17:41 +0000662#endif
663#ifdef EPOLLERR
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000664 XLAT(EPOLLERR),
Roland McGrath63d6e542004-10-20 02:17:41 +0000665#endif
666#ifdef EPOLLHUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000667 XLAT(EPOLLHUP),
Roland McGrath63d6e542004-10-20 02:17:41 +0000668#endif
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000669#ifdef EPOLLRDHUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000670 XLAT(EPOLLRDHUP),
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000671#endif
Roland McGrath63d6e542004-10-20 02:17:41 +0000672#ifdef EPOLLONESHOT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000673 XLAT(EPOLLONESHOT),
Roland McGrath63d6e542004-10-20 02:17:41 +0000674#endif
675#ifdef EPOLLET
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000676 XLAT(EPOLLET),
Roland McGrath63d6e542004-10-20 02:17:41 +0000677#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000678 XLAT_END
Roland McGrath93817bf2004-10-06 22:23:31 +0000679};
680
Denys Vlasenko72879c62012-02-27 14:18:02 +0100681/* Not aliased to printargs_ld: we want it to have a distinct address */
Roland McGrath93817bf2004-10-06 22:23:31 +0000682int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000683sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000684{
Denys Vlasenko72879c62012-02-27 14:18:02 +0100685 return printargs_ld(tcp);
Roland McGrath93817bf2004-10-06 22:23:31 +0000686}
687
Mike Frysingeraed334c2011-10-13 22:33:45 -0400688static const struct xlat epollflags[] = {
689#ifdef EPOLL_CLOEXEC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000690 XLAT(EPOLL_CLOEXEC),
Mike Frysingeraed334c2011-10-13 22:33:45 -0400691#endif
692#ifdef EPOLL_NONBLOCK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000693 XLAT(EPOLL_NONBLOCK),
Mike Frysingeraed334c2011-10-13 22:33:45 -0400694#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000695 XLAT_END
Mike Frysingeraed334c2011-10-13 22:33:45 -0400696};
697
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000698int
699sys_epoll_create1(struct tcb *tcp)
700{
701 if (entering(tcp))
Mike Frysingeraed334c2011-10-13 22:33:45 -0400702 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000703 return 0;
704}
705
Roland McGrath63d6e542004-10-20 02:17:41 +0000706#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000707static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000708print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000709{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200710 tprints("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000711 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000712 /* We cannot know what format the program uses, so print u32 and u64
713 which will cover every value. */
714 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
715 ev->data.u32, ev->data.u64);
716}
Roland McGrath63d6e542004-10-20 02:17:41 +0000717#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000718
719int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000720sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000721{
722 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300723 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200724 tprints(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000725 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200726 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300727 printfd(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200728 tprints(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000729 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200730 tprints("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000731 else {
732#ifdef HAVE_SYS_EPOLL_H
733 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000734 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000735 print_epoll_event(&ev);
736 else
737#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200738 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000739 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000740 }
741 return 0;
742}
743
Roland McGrathf2400052007-08-02 01:13:26 +0000744static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000745epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000746{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300747 if (entering(tcp)) {
748 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200749 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300750 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000751 if (syserror(tcp))
752 tprintf("%lx", tcp->u_arg[1]);
753 else if (tcp->u_rval == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200754 tprints("{}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000755 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000756#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000757 struct epoll_event ev, *start, *cur, *end;
758 int failed = 0;
759
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200760 tprints("{");
Roland McGrathaa524c82005-06-01 19:22:06 +0000761 start = (struct epoll_event *) tcp->u_arg[1];
762 end = start + tcp->u_rval;
763 for (cur = start; cur < end; ++cur) {
764 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200765 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000766 if (umove(tcp, (long) cur, &ev) == 0)
767 print_epoll_event(&ev);
768 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200769 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000770 failed = 1;
771 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000772 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000773 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200774 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000775 if (failed)
776 tprintf(" %#lx", (long) start);
777#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200778 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000779#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000780 }
Dmitry V. Levinc327d712011-10-11 16:05:57 +0000781 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
Roland McGrath93817bf2004-10-06 22:23:31 +0000782 }
Roland McGrathf2400052007-08-02 01:13:26 +0000783}
784
785int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000786sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000787{
788 epoll_wait_common(tcp);
789 return 0;
790}
791
792int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000793sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000794{
795 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000796 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200797 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200798 /* NB: kernel requires arg[5] == NSIG / 8 */
799 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
800 tprintf(", %lu", tcp->u_arg[5]);
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_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000807{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000808 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000809}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000810
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000811int
812sys_pselect6(struct tcb *tcp)
813{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000814 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +0000815 if (entering(tcp)) {
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200816 long r;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000817 struct {
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200818 unsigned long ptr;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000819 unsigned long len;
820 } data;
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200821#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
822 if (current_wordsize == 4) {
823 struct {
824 uint32_t ptr;
825 uint32_t len;
826 } data32;
827 r = umove(tcp, tcp->u_arg[5], &data32);
828 data.ptr = data32.ptr;
829 data.len = data32.len;
830 } else
831#endif
832 r = umove(tcp, tcp->u_arg[5], &data);
833 if (r < 0)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000834 tprintf(", %#lx", tcp->u_arg[5]);
835 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200836 tprints(", {");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200837 /* NB: kernel requires data.len == NSIG / 8 */
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200838 print_sigset_addr_len(tcp, data.ptr, data.len);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000839 tprintf(", %lu}", data.len);
840 }
841 }
842 return rc;
843}
Roland McGrathe7c39672007-08-02 01:32:17 +0000844
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000845static int
846do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +0000847{
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000848 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +0000849 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000850 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200851 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000852 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
853 }
854 }
Roland McGrathe7c39672007-08-02 01:32:17 +0000855 return 0;
856}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000857
858int
859sys_eventfd(struct tcb *tcp)
860{
861 return do_eventfd(tcp, -1);
862}
863
864int
865sys_eventfd2(struct tcb *tcp)
866{
867 return do_eventfd(tcp, 1);
868}
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100869
870int
871sys_perf_event_open(struct tcb *tcp)
872{
873 if (entering(tcp)) {
874 tprintf("%#lx, %d, %d, %d, ",
875 tcp->u_arg[0],
876 (int) tcp->u_arg[1],
877 (int) tcp->u_arg[2],
878 (int) tcp->u_arg[3]);
879 printflags(perf_event_open_flags, tcp->u_arg[4],
880 "PERF_FLAG_???");
881 }
882 return 0;
883}