blob: b2eabc21378eeb9491b08bee3eb24f14b4f73a26 [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
112#ifdef F_FREESP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000113 XLAT(F_FREESP),
John Hughesbdf48f52001-03-06 15:08:09 +0000114#endif
115#ifdef F_GETLK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000116 XLAT(F_GETLK),
John Hughesbdf48f52001-03-06 15:08:09 +0000117#endif
118#ifdef F_SETLK64
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000119 XLAT(F_SETLK64),
John Hughesbdf48f52001-03-06 15:08:09 +0000120#endif
121#ifdef F_SETLKW64
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000122 XLAT(F_SETLKW64),
John Hughesbdf48f52001-03-06 15:08:09 +0000123#endif
124#ifdef F_FREESP64
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000125 XLAT(F_FREESP64),
John Hughesbdf48f52001-03-06 15:08:09 +0000126#endif
127#ifdef F_GETLK64
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000128 XLAT(F_GETLK64),
John Hughesbdf48f52001-03-06 15:08:09 +0000129#endif
130#ifdef F_SHARE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000131 XLAT(F_SHARE),
John Hughesbdf48f52001-03-06 15:08:09 +0000132#endif
133#ifdef F_UNSHARE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000134 XLAT(F_UNSHARE),
John Hughesbdf48f52001-03-06 15:08:09 +0000135#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000136#ifdef F_SETLEASE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000137 XLAT(F_SETLEASE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000138#endif
139#ifdef F_GETLEASE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000140 XLAT(F_GETLEASE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000141#endif
142#ifdef F_NOTIFY
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000143 XLAT(F_NOTIFY),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000144#endif
145#ifdef F_DUPFD_CLOEXEC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000146 XLAT(F_DUPFD_CLOEXEC),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000147#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000148 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149};
150
Roland McGrathd9f816f2004-09-04 03:39:20 +0000151static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000152#ifdef FD_CLOEXEC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000153 XLAT(FD_CLOEXEC),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000155 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000156};
157
158#ifdef LOCK_SH
159
Roland McGrathd9f816f2004-09-04 03:39:20 +0000160static const struct xlat flockcmds[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000161 XLAT(LOCK_SH),
162 XLAT(LOCK_EX),
163 XLAT(LOCK_NB),
164 XLAT(LOCK_UN),
Dmitry V. Levin59452732014-02-05 02:20:51 +0000165 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000166};
167
168#endif /* LOCK_SH */
169
Roland McGrathd9f816f2004-09-04 03:39:20 +0000170static const struct xlat lockfcmds[] = {
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000171 XLAT(F_RDLCK),
172 XLAT(F_WRLCK),
173 XLAT(F_UNLCK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174#ifdef F_EXLCK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000175 XLAT(F_EXLCK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000176#endif
177#ifdef F_SHLCK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000178 XLAT(F_SHLCK),
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000180 XLAT_END
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181};
182
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000183#ifdef F_NOTIFY
184static const struct xlat notifyflags[] = {
185#ifdef DN_ACCESS
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000186 XLAT(DN_ACCESS),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000187#endif
188#ifdef DN_MODIFY
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000189 XLAT(DN_MODIFY),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000190#endif
191#ifdef DN_CREATE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000192 XLAT(DN_CREATE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000193#endif
194#ifdef DN_DELETE
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000195 XLAT(DN_DELETE),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000196#endif
197#ifdef DN_RENAME
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000198 XLAT(DN_RENAME),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000199#endif
200#ifdef DN_ATTRIB
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000201 XLAT(DN_ATTRIB),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000202#endif
203#ifdef DN_MULTISHOT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000204 XLAT(DN_MULTISHOT),
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000205#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000206 XLAT_END
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000207};
208#endif
209
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100210static const struct xlat perf_event_open_flags[] = {
211#ifdef PERF_FLAG_FD_NO_GROUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000212 XLAT(PERF_FLAG_FD_NO_GROUP),
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100213#endif
214#ifdef PERF_FLAG_FD_OUTPUT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000215 XLAT(PERF_FLAG_FD_OUTPUT),
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100216#endif
217#ifdef PERF_FLAG_PID_CGROUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000218 XLAT(PERF_FLAG_PID_CGROUP),
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100219#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000220 XLAT_END
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100221};
222
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000223#if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK
224# define HAVE_F_SETLK64 1
225#else
226# define HAVE_F_SETLK64 0
227#endif
228
229#if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW
230# define HAVE_F_SETLKW64 1
231#else
232# define HAVE_F_SETLKW64 0
233#endif
234
235#if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK
236# define HAVE_F_GETLK64 1
237#else
238# define HAVE_F_GETLK64 0
239#endif
240
241#if defined(X32) || defined(F_FREESP64) || \
242 HAVE_F_SETLK64 || HAVE_F_SETLKW64 || HAVE_F_GETLK64
243
244#ifndef HAVE_STRUCT_FLOCK64
245struct flock64 {
246 short int l_type, l_whence;
247 int64_t l_start, l_len;
248 int l_pid;
249};
250#endif
251
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000252/* fcntl/lockf */
253static void
254printflock64(struct tcb *tcp, long addr, int getlk)
255{
256 struct flock64 fl;
257
258 if (umove(tcp, addr, &fl) < 0) {
259 tprints("{...}");
260 return;
261 }
262 tprints("{type=");
263 printxval(lockfcmds, fl.l_type, "F_???");
264 tprints(", whence=");
265 printxval(whence_codes, fl.l_whence, "SEEK_???");
266 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
267 if (getlk)
268 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
269 else
270 tprints("}");
271}
272#endif
273
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274/* fcntl/lockf */
275static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000276printflock(struct tcb *tcp, long addr, int getlk)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000277{
278 struct flock fl;
279
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000280#if SUPPORTED_PERSONALITIES > 1
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000281# ifdef X32
282 if (current_personality == 0) {
283 printflock64(tcp, addr, getlk);
284 return;
285 }
286# endif
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100287 if (current_wordsize != sizeof(fl.l_start)) {
288 if (current_wordsize == 4) {
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000289 /* 32-bit x86 app on x86_64 and similar cases */
290 struct {
291 short int l_type;
292 short int l_whence;
293 int32_t l_start; /* off_t */
294 int32_t l_len; /* off_t */
295 int32_t l_pid; /* pid_t */
296 } fl32;
297 if (umove(tcp, addr, &fl32) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200298 tprints("{...}");
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000299 return;
300 }
301 fl.l_type = fl32.l_type;
302 fl.l_whence = fl32.l_whence;
303 fl.l_start = fl32.l_start;
304 fl.l_len = fl32.l_len;
305 fl.l_pid = fl32.l_pid;
306 } else {
307 /* let people know we have a problem here */
Denys Vlasenko751acb32013-02-08 15:34:46 +0100308 tprintf("<decode error: unsupported wordsize %d>",
Denys Vlasenko9fd4f962012-03-19 09:36:42 +0100309 current_wordsize);
Denys Vlasenko7a862d72009-04-15 13:22:59 +0000310 return;
311 }
312 } else
313#endif
314 {
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000315 if (umove(tcp, addr, &fl) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200316 tprints("{...}");
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000317 return;
318 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200320 tprints("{type=");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000321 printxval(lockfcmds, fl.l_type, "F_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200322 tprints(", whence=");
Denys Vlasenko86738a22013-02-17 14:31:55 +0100323 printxval(whence_codes, fl.l_whence, "SEEK_???");
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000324#ifdef X32
325 tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len);
326#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000327 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000328#endif
Dmitry V. Levin0eeda2c2013-05-01 16:37:08 +0000329 if (getlk)
330 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
331 else
332 tprints("}");
333}
John Hughesbdf48f52001-03-06 15:08:09 +0000334
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000335int
336sys_fcntl(struct tcb *tcp)
337{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000338 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300339 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200340 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
342 switch (tcp->u_arg[1]) {
343 case F_SETFD:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200344 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000345 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000346 break;
347 case F_SETOWN: case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000348#ifdef F_DUPFD_CLOEXEC
349 case F_DUPFD_CLOEXEC:
350#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000351 tprintf(", %ld", tcp->u_arg[2]);
352 break;
353 case F_SETFL:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200354 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000355 tprint_open_modes(tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000356 break;
357 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000358#ifdef F_FREESP
359 case F_FREESP:
360#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200361 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000362 printflock(tcp, tcp->u_arg[2], 0);
363 break;
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000364#if defined(F_FREESP64) || HAVE_F_SETLK64 || HAVE_F_SETLKW64
John Hughesbdf48f52001-03-06 15:08:09 +0000365#ifdef F_FREESP64
366 case F_FREESP64:
367#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000368 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000369 even though the kernel has different values - as does Solaris. */
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000370#if HAVE_F_SETLK64
John Hughesbdf48f52001-03-06 15:08:09 +0000371 case F_SETLK64:
372#endif
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000373#if HAVE_F_SETLKW64
John Hughesbdf48f52001-03-06 15:08:09 +0000374 case F_SETLKW64:
375#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200376 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000377 printflock64(tcp, tcp->u_arg[2], 0);
378 break;
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000379#endif /* defined(F_FREESP64) || HAVE_F_SETLK64 || HAVE_F_SETLKW64 */
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000380#ifdef F_NOTIFY
381 case F_NOTIFY:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200382 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000383 printflags(notifyflags, tcp->u_arg[2], "DN_???");
384 break;
385#endif
386#ifdef F_SETLEASE
387 case F_SETLEASE:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200388 tprints(", ");
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000389 printxval(lockfcmds, tcp->u_arg[2], "F_???");
390 break;
391#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000392 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393 }
394 else {
395 switch (tcp->u_arg[1]) {
396 case F_DUPFD:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000397#ifdef F_DUPFD_CLOEXEC
398 case F_DUPFD_CLOEXEC:
399#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400 case F_SETFD: case F_SETFL:
401 case F_SETLK: case F_SETLKW:
402 case F_SETOWN: case F_GETOWN:
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000403#ifdef F_NOTIFY
404 case F_NOTIFY:
405#endif
406#ifdef F_SETLEASE
407 case F_SETLEASE:
408#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409 break;
410 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000411 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 return 0;
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000413 tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414 return RVAL_HEX|RVAL_STR;
415 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000416 if (syserror(tcp))
417 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000418 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000419 return RVAL_HEX|RVAL_STR;
420 case F_GETLK:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200421 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000422 printflock(tcp, tcp->u_arg[2], 1);
423 break;
Dmitry V. Levin594eb8f2013-11-12 21:49:03 +0000424#if HAVE_F_GETLK64
John Hughesbdf48f52001-03-06 15:08:09 +0000425 case F_GETLK64:
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200426 tprints(", ");
John Hughesbdf48f52001-03-06 15:08:09 +0000427 printflock64(tcp, tcp->u_arg[2], 1);
428 break;
429#endif
Denys Vlasenkoeedaac72009-03-10 20:41:58 +0000430#ifdef F_GETLEASE
431 case F_GETLEASE:
432 if (syserror(tcp))
433 return 0;
434 tcp->auxstr = xlookup(lockfcmds, tcp->u_rval);
435 return RVAL_HEX|RVAL_STR;
436#endif
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000437 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 tprintf(", %#lx", tcp->u_arg[2]);
439 break;
440 }
441 }
442 return 0;
443}
444
445#ifdef LOCK_SH
446
447int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000448sys_flock(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000449{
450 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300451 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200452 tprints(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000453 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000454 }
455 return 0;
456}
457#endif /* LOCK_SH */
458
459int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000460sys_close(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461{
462 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300463 printfd(tcp, tcp->u_arg[0]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464 }
465 return 0;
466}
467
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000468static int
469do_dup2(struct tcb *tcp, int flags_arg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470{
471 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300472 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200473 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300474 printfd(tcp, tcp->u_arg[1]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000475 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200476 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000477 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
478 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479 }
480 return 0;
481}
482
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000483int
484sys_dup2(struct tcb *tcp)
485{
486 return do_dup2(tcp, -1);
487}
488
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000489int
490sys_dup3(struct tcb *tcp)
491{
492 return do_dup2(tcp, 2);
493}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000494
Denys Vlasenko84703742012-02-25 02:38:52 +0100495#if defined(ALPHA)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000497sys_getdtablesize(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498{
499 return 0;
500}
Denys Vlasenko84703742012-02-25 02:38:52 +0100501#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000502
Dmitry V. Levinc2982b52013-11-05 23:00:22 +0000503static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000504decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505{
Denys Vlasenkoad5155a2011-09-01 18:18:04 +0200506 int i, j;
Denys Vlasenko1f65c3c2013-11-05 16:20:16 +0100507 int nfds, fdsize;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000508 fd_set *fds;
Dmitry V. Levin30145dd2010-09-06 22:08:24 +0000509 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000510 long arg;
511
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000512 /* Kernel truncates arg[0] to int, we do the same. */
513 nfds = (int) args[0];
514
515 /* Kernel rejects negative nfds, so we don't parse it either. */
516 if (nfds < 0) {
517 nfds = 0;
518 fds = NULL;
519 }
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200520 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000521 if (nfds > 1024*1024)
522 nfds = 1024*1024;
523
524 /*
525 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
Dr. David Alan Gilbert025f1082013-11-05 11:54:51 +0100526 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
527 */
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100528 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
Denys Vlasenko79a79ea2011-09-01 16:35:44 +0200529
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000530 if (entering(tcp)) {
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000531 tprintf("%d", (int) args[0]);
532
533 if (fdsize > 0) {
534 fds = malloc(fdsize);
535 if (!fds)
536 die_out_of_memory();
537 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000538 for (i = 0; i < 3; i++) {
539 arg = args[i+1];
540 if (arg == 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200541 tprints(", NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 continue;
543 }
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000544 if (!verbose(tcp) || !fds) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000545 tprintf(", %#lx", arg);
546 continue;
547 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000548 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200549 tprints(", [?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000550 continue;
551 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200552 tprints(", [");
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100553 for (j = 0, sep = "";; j++) {
554 j = next_set_bit(fds, j, nfds);
555 if (j < 0)
556 break;
557 tprints(sep);
558 printfd(tcp, j);
559 sep = " ";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000560 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200561 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000563 free(fds);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200564 tprints(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000565 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000566 }
Denys Vlasenko7b609d52011-06-22 14:32:43 +0200567 else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200568 static char outstr[1024];
569 char *outptr;
570#define end_outstr (outstr + sizeof(outstr))
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000571 int ready_fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000572
573 if (syserror(tcp))
574 return 0;
575
Dr. David Alan Gilbert025f1082013-11-05 11:54:51 +0100576 ready_fds = tcp->u_rval;
577 if (ready_fds == 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000578 tcp->auxstr = "Timeout";
579 return RVAL_STR;
580 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000581
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200582 fds = malloc(fdsize);
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200583 if (!fds)
584 die_out_of_memory();
Roland McGrathe85aaa42005-02-06 01:55:12 +0000585
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200586 outptr = outstr;
587 sep = "";
Dmitry V. Levinf3696b32013-11-05 22:46:43 +0000588 for (i = 0; i < 3 && ready_fds > 0; i++) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000589 int first = 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000590
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000591 arg = args[i+1];
Denys Vlasenko1d46ba52011-08-31 14:00:02 +0200592 if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000593 continue;
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100594 for (j = 0;; j++) {
595 j = next_set_bit(fds, j, nfds);
596 if (j < 0)
597 break;
598 /* +2 chars needed at the end: ']',NUL */
599 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
600 if (first) {
601 outptr += sprintf(outptr, "%s%s [%u",
602 sep,
603 i == 0 ? "in" : i == 1 ? "out" : "except",
604 j
605 );
606 first = 0;
607 sep = ", ";
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000608 }
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100609 else {
610 outptr += sprintf(outptr, " %u", j);
611 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000612 }
Denys Vlasenkob338f2d2013-11-09 20:40:31 +0100613 if (--ready_fds == 0)
614 break;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000615 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200616 if (outptr != outstr)
617 *outptr++ = ']';
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000618 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000619 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000620 /* This contains no useful information on SunOS. */
621 if (args[4]) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100622 if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200623 outptr += sprintf(outptr, "%sleft ", sep);
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100624 outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200625 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000626 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200627 *outptr = '\0';
Denys Vlasenko11617252011-09-01 11:27:37 +0200628 tcp->auxstr = outstr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000629 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200630#undef end_outstr
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000631 }
632 return 0;
633}
634
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000635int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000636sys_oldselect(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000637{
638 long args[5];
639
640 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200641 tprints("[...]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000642 return 0;
643 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000644 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000645}
646
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000647#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000648int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000649sys_osf_select(struct tcb *tcp)
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000650{
651 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000652 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000653}
654#endif
655
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000656static const struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000657#ifdef EPOLL_CTL_ADD
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000658 XLAT(EPOLL_CTL_ADD),
Roland McGrath63d6e542004-10-20 02:17:41 +0000659#endif
660#ifdef EPOLL_CTL_MOD
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000661 XLAT(EPOLL_CTL_MOD),
Roland McGrath63d6e542004-10-20 02:17:41 +0000662#endif
663#ifdef EPOLL_CTL_DEL
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000664 XLAT(EPOLL_CTL_DEL),
Roland McGrath63d6e542004-10-20 02:17:41 +0000665#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000666 XLAT_END
Roland McGrath93817bf2004-10-06 22:23:31 +0000667};
668
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000669static const struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000670#ifdef EPOLLIN
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000671 XLAT(EPOLLIN),
Roland McGrath63d6e542004-10-20 02:17:41 +0000672#endif
673#ifdef EPOLLPRI
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000674 XLAT(EPOLLPRI),
Roland McGrath63d6e542004-10-20 02:17:41 +0000675#endif
676#ifdef EPOLLOUT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000677 XLAT(EPOLLOUT),
Roland McGrath63d6e542004-10-20 02:17:41 +0000678#endif
679#ifdef EPOLLRDNORM
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000680 XLAT(EPOLLRDNORM),
Roland McGrath63d6e542004-10-20 02:17:41 +0000681#endif
682#ifdef EPOLLRDBAND
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000683 XLAT(EPOLLRDBAND),
Roland McGrath63d6e542004-10-20 02:17:41 +0000684#endif
685#ifdef EPOLLWRNORM
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000686 XLAT(EPOLLWRNORM),
Roland McGrath63d6e542004-10-20 02:17:41 +0000687#endif
688#ifdef EPOLLWRBAND
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000689 XLAT(EPOLLWRBAND),
Roland McGrath63d6e542004-10-20 02:17:41 +0000690#endif
691#ifdef EPOLLMSG
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000692 XLAT(EPOLLMSG),
Roland McGrath63d6e542004-10-20 02:17:41 +0000693#endif
694#ifdef EPOLLERR
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000695 XLAT(EPOLLERR),
Roland McGrath63d6e542004-10-20 02:17:41 +0000696#endif
697#ifdef EPOLLHUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000698 XLAT(EPOLLHUP),
Roland McGrath63d6e542004-10-20 02:17:41 +0000699#endif
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000700#ifdef EPOLLRDHUP
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000701 XLAT(EPOLLRDHUP),
Dmitry V. Levin5967c1a2011-10-11 15:55:40 +0000702#endif
Roland McGrath63d6e542004-10-20 02:17:41 +0000703#ifdef EPOLLONESHOT
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000704 XLAT(EPOLLONESHOT),
Roland McGrath63d6e542004-10-20 02:17:41 +0000705#endif
706#ifdef EPOLLET
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000707 XLAT(EPOLLET),
Roland McGrath63d6e542004-10-20 02:17:41 +0000708#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000709 XLAT_END
Roland McGrath93817bf2004-10-06 22:23:31 +0000710};
711
Denys Vlasenko72879c62012-02-27 14:18:02 +0100712/* Not aliased to printargs_ld: we want it to have a distinct address */
Roland McGrath93817bf2004-10-06 22:23:31 +0000713int
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000714sys_epoll_create(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000715{
Denys Vlasenko72879c62012-02-27 14:18:02 +0100716 return printargs_ld(tcp);
Roland McGrath93817bf2004-10-06 22:23:31 +0000717}
718
Mike Frysingeraed334c2011-10-13 22:33:45 -0400719static const struct xlat epollflags[] = {
720#ifdef EPOLL_CLOEXEC
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000721 XLAT(EPOLL_CLOEXEC),
Mike Frysingeraed334c2011-10-13 22:33:45 -0400722#endif
723#ifdef EPOLL_NONBLOCK
Dmitry V. Levinbce0cc62014-02-05 01:33:50 +0000724 XLAT(EPOLL_NONBLOCK),
Mike Frysingeraed334c2011-10-13 22:33:45 -0400725#endif
Dmitry V. Levin59452732014-02-05 02:20:51 +0000726 XLAT_END
Mike Frysingeraed334c2011-10-13 22:33:45 -0400727};
728
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000729int
730sys_epoll_create1(struct tcb *tcp)
731{
732 if (entering(tcp))
Mike Frysingeraed334c2011-10-13 22:33:45 -0400733 printflags(epollflags, tcp->u_arg[0], "EPOLL_???");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000734 return 0;
735}
736
Roland McGrath63d6e542004-10-20 02:17:41 +0000737#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000738static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000739print_epoll_event(struct epoll_event *ev)
Roland McGrath93817bf2004-10-06 22:23:31 +0000740{
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200741 tprints("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000742 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000743 /* We cannot know what format the program uses, so print u32 and u64
744 which will cover every value. */
745 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
746 ev->data.u32, ev->data.u64);
747}
Roland McGrath63d6e542004-10-20 02:17:41 +0000748#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000749
750int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000751sys_epoll_ctl(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000752{
753 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300754 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200755 tprints(", ");
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000756 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200757 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300758 printfd(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200759 tprints(", ");
Roland McGrath93817bf2004-10-06 22:23:31 +0000760 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200761 tprints("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000762 else {
763#ifdef HAVE_SYS_EPOLL_H
764 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000765 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000766 print_epoll_event(&ev);
767 else
768#endif
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200769 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000770 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000771 }
772 return 0;
773}
774
Roland McGrathf2400052007-08-02 01:13:26 +0000775static void
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000776epoll_wait_common(struct tcb *tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000777{
Dmitry V. Levin31382132011-03-04 05:08:02 +0300778 if (entering(tcp)) {
779 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200780 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300781 } else {
Roland McGrath93817bf2004-10-06 22:23:31 +0000782 if (syserror(tcp))
783 tprintf("%lx", tcp->u_arg[1]);
784 else if (tcp->u_rval == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200785 tprints("{}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000786 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000787#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000788 struct epoll_event ev, *start, *cur, *end;
789 int failed = 0;
790
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200791 tprints("{");
Roland McGrathaa524c82005-06-01 19:22:06 +0000792 start = (struct epoll_event *) tcp->u_arg[1];
793 end = start + tcp->u_rval;
794 for (cur = start; cur < end; ++cur) {
795 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200796 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000797 if (umove(tcp, (long) cur, &ev) == 0)
798 print_epoll_event(&ev);
799 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200800 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000801 failed = 1;
802 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000803 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000804 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200805 tprints("}");
Roland McGrathaa524c82005-06-01 19:22:06 +0000806 if (failed)
807 tprintf(" %#lx", (long) start);
808#else
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200809 tprints("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000810#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000811 }
Dmitry V. Levinc327d712011-10-11 16:05:57 +0000812 tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]);
Roland McGrath93817bf2004-10-06 22:23:31 +0000813 }
Roland McGrathf2400052007-08-02 01:13:26 +0000814}
815
816int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000817sys_epoll_wait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000818{
819 epoll_wait_common(tcp);
820 return 0;
821}
822
823int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000824sys_epoll_pwait(struct tcb *tcp)
Roland McGrathf2400052007-08-02 01:13:26 +0000825{
826 epoll_wait_common(tcp);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000827 if (exiting(tcp)) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200828 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200829 /* NB: kernel requires arg[5] == NSIG / 8 */
830 print_sigset_addr_len(tcp, tcp->u_arg[4], tcp->u_arg[5]);
831 tprintf(", %lu", tcp->u_arg[5]);
Dmitry V. Levin96764992010-04-06 23:54:18 +0000832 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000833 return 0;
834}
Roland McGrath37b9f842005-05-09 08:02:00 +0000835
836int
Denys Vlasenko30b5e5a2009-01-06 15:12:52 +0000837sys_select(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000838{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000839 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000840}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000841
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000842int
843sys_pselect6(struct tcb *tcp)
844{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000845 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +0000846 if (entering(tcp)) {
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200847 long r;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000848 struct {
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200849 unsigned long ptr;
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000850 unsigned long len;
851 } data;
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200852#if SUPPORTED_PERSONALITIES > 1 && SIZEOF_LONG > 4
853 if (current_wordsize == 4) {
854 struct {
855 uint32_t ptr;
856 uint32_t len;
857 } data32;
858 r = umove(tcp, tcp->u_arg[5], &data32);
859 data.ptr = data32.ptr;
860 data.len = data32.len;
861 } else
862#endif
863 r = umove(tcp, tcp->u_arg[5], &data);
864 if (r < 0)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000865 tprintf(", %#lx", tcp->u_arg[5]);
866 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200867 tprints(", {");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200868 /* NB: kernel requires data.len == NSIG / 8 */
Denys Vlasenko8a1ebbb2013-07-18 18:10:13 +0200869 print_sigset_addr_len(tcp, data.ptr, data.len);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000870 tprintf(", %lu}", data.len);
871 }
872 }
873 return rc;
874}
Roland McGrathe7c39672007-08-02 01:32:17 +0000875
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000876static int
877do_eventfd(struct tcb *tcp, int flags_arg)
Roland McGrathe7c39672007-08-02 01:32:17 +0000878{
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000879 if (entering(tcp)) {
Roland McGrathe7c39672007-08-02 01:32:17 +0000880 tprintf("%lu", tcp->u_arg[0]);
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000881 if (flags_arg >= 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200882 tprints(", ");
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000883 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
884 }
885 }
Roland McGrathe7c39672007-08-02 01:32:17 +0000886 return 0;
887}
Dmitry V. Levin4371b102008-11-10 22:53:02 +0000888
889int
890sys_eventfd(struct tcb *tcp)
891{
892 return do_eventfd(tcp, -1);
893}
894
895int
896sys_eventfd2(struct tcb *tcp)
897{
898 return do_eventfd(tcp, 1);
899}
Ben Noordhuis88eafd82013-02-04 00:04:57 +0100900
901int
902sys_perf_event_open(struct tcb *tcp)
903{
904 if (entering(tcp)) {
905 tprintf("%#lx, %d, %d, %d, ",
906 tcp->u_arg[0],
907 (int) tcp->u_arg[1],
908 (int) tcp->u_arg[2],
909 (int) tcp->u_arg[3]);
910 printflags(perf_event_open_flags, tcp->u_arg[4],
911 "PERF_FLAG_???");
912 }
913 return 0;
914}