blob: 951ccf910940abfa602f8f81037b7f695adace1b [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.
29 *
30 * $Id$
31 */
32
33#include "defs.h"
34
35#include <fcntl.h>
36#include <sys/file.h>
Roland McGrath93817bf2004-10-06 22:23:31 +000037#ifdef LINUX
38#include <inttypes.h>
Roland McGrath63d6e542004-10-20 02:17:41 +000039#endif
40#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +000041#include <sys/epoll.h>
42#endif
Roland McGrath37b9f842005-05-09 08:02:00 +000043#ifdef HAVE_LIBAIO_H
44#include <libaio.h>
45#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046
John Hughes70623be2001-03-08 13:59:00 +000047#if HAVE_LONG_LONG_OFF_T
48/*
49 * Hacks for systems that have a long long off_t
50 */
John Hughesb8c9f772001-03-07 16:53:07 +000051#define flock64 flock /* Horrid hack */
52#define printflock printflock64 /* Horrider hack */
53#endif
54
55
Roland McGrathd9f816f2004-09-04 03:39:20 +000056static const struct xlat fcntlcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057 { F_DUPFD, "F_DUPFD" },
58 { F_GETFD, "F_GETFD" },
59 { F_SETFD, "F_SETFD" },
60 { F_GETFL, "F_GETFL" },
61 { F_SETFL, "F_SETFL" },
62 { F_GETLK, "F_GETLK" },
63 { F_SETLK, "F_SETLK" },
64 { F_SETLKW, "F_SETLKW" },
65 { F_GETOWN, "F_GETOWN" },
66 { F_SETOWN, "F_SETOWN" },
67#ifdef F_RSETLK
68 { F_RSETLK, "F_RSETLK" },
69#endif
70#ifdef F_RSETLKW
71 { F_RSETLKW, "F_RSETLKW" },
72#endif
73#ifdef F_RGETLK
74 { F_RGETLK, "F_RGETLK" },
75#endif
76#ifdef F_CNVT
77 { F_CNVT, "F_CNVT" },
78#endif
Wichert Akkerman5ae21ea2000-05-01 01:53:59 +000079#ifdef F_SETSIG
80 { F_SETSIG, "F_SETSIG" },
81#endif
82#ifdef F_GETSIG
83 { F_GETSIG, "F_GETSIG" },
84#endif
John Hughesbdf48f52001-03-06 15:08:09 +000085#ifdef F_CHKFL
86 { F_CHKFL, "F_CHKFL" },
87#endif
88#ifdef F_DUP2FD
89 { F_DUP2FD, "F_DUP2FD" },
90#endif
91#ifdef F_ALLOCSP
92 { F_ALLOCSP, "F_ALLOCSP" },
93#endif
94#ifdef F_ISSTREAM
95 { F_ISSTREAM, "F_ISSTREAM" },
96#endif
97#ifdef F_PRIV
98 { F_PRIV, "F_PRIV" },
99#endif
100#ifdef F_NPRIV
101 { F_NPRIV, "F_NPRIV" },
102#endif
103#ifdef F_QUOTACL
104 { F_QUOTACL, "F_QUOTACL" },
105#endif
106#ifdef F_BLOCKS
107 { F_BLOCKS, "F_BLOCKS" },
108#endif
109#ifdef F_BLKSIZE
110 { F_BLKSIZE, "F_BLKSIZE" },
111#endif
112#ifdef F_GETOWN
113 { F_GETOWN, "F_GETOWN" },
114#endif
115#ifdef F_SETOWN
116 { F_SETOWN, "F_SETOWN" },
117#endif
118#ifdef F_REVOKE
119 { F_REVOKE, "F_REVOKE" },
120#endif
121#ifdef F_SETLK
122 { F_SETLK, "F_SETLK" },
123#endif
124#ifdef F_SETLKW
125 { F_SETLKW, "F_SETLKW" },
126#endif
127#ifdef F_FREESP
128 { F_FREESP, "F_FREESP" },
129#endif
130#ifdef F_GETLK
131 { F_GETLK, "F_GETLK" },
132#endif
133#ifdef F_SETLK64
134 { F_SETLK64, "F_SETLK64" },
135#endif
136#ifdef F_SETLKW64
137 { F_SETLKW64, "F_SETLKW64" },
138#endif
139#ifdef F_FREESP64
140 { F_FREESP64, "F_FREESP64" },
141#endif
142#ifdef F_GETLK64
143 { F_GETLK64, "F_GETLK64" },
144#endif
145#ifdef F_SHARE
146 { F_SHARE, "F_SHARE" },
147#endif
148#ifdef F_UNSHARE
149 { F_UNSHARE, "F_UNSHARE" },
150#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000151 { 0, NULL },
152};
153
Roland McGrathd9f816f2004-09-04 03:39:20 +0000154static const struct xlat fdflags[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000155#ifdef FD_CLOEXEC
156 { FD_CLOEXEC, "FD_CLOEXEC" },
157#endif
158 { 0, NULL },
159};
160
161#ifdef LOCK_SH
162
Roland McGrathd9f816f2004-09-04 03:39:20 +0000163static const struct xlat flockcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000164 { LOCK_SH, "LOCK_SH" },
165 { LOCK_EX, "LOCK_EX" },
166 { LOCK_NB, "LOCK_NB" },
167 { LOCK_UN, "LOCK_UN" },
168 { 0, NULL },
169};
170
171#endif /* LOCK_SH */
172
Roland McGrathd9f816f2004-09-04 03:39:20 +0000173static const struct xlat lockfcmds[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174 { F_RDLCK, "F_RDLCK" },
175 { F_WRLCK, "F_WRLCK" },
176 { F_UNLCK, "F_UNLCK" },
177#ifdef F_EXLCK
178 { F_EXLCK, "F_EXLCK" },
179#endif
180#ifdef F_SHLCK
181 { F_SHLCK, "F_SHLCK" },
182#endif
183 { 0, NULL },
184};
185
Roland McGrathd9f816f2004-09-04 03:39:20 +0000186static const struct xlat whence[] = {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187 { SEEK_SET, "SEEK_SET" },
188 { SEEK_CUR, "SEEK_CUR" },
189 { SEEK_END, "SEEK_END" },
190 { 0, NULL },
191};
192
John Hughes70623be2001-03-08 13:59:00 +0000193#ifndef HAVE_LONG_LONG_OFF_T
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194/* fcntl/lockf */
195static void
196printflock(tcp, addr, getlk)
197struct tcb *tcp;
Wichert Akkerman8b1b40c2000-02-03 21:58:30 +0000198long addr;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000199int getlk;
200{
201 struct flock fl;
202
203 if (umove(tcp, addr, &fl) < 0) {
204 tprintf("{...}");
205 return;
206 }
207 tprintf("{type=");
208 printxval(lockfcmds, fl.l_type, "F_???");
209 tprintf(", whence=");
210 printxval(whence, fl.l_whence, "SEEK_???");
211 tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len);
212 if (getlk)
213 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
214 else
215 tprintf("}");
216}
John Hughesb8c9f772001-03-07 16:53:07 +0000217#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218
John Hughes70623be2001-03-08 13:59:00 +0000219#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000220/* fcntl/lockf */
221static void
222printflock64(tcp, addr, getlk)
223struct tcb *tcp;
Roland McGrath81634e42003-01-14 07:53:31 +0000224long addr;
John Hughesbdf48f52001-03-06 15:08:09 +0000225int getlk;
226{
227 struct flock64 fl;
228
229 if (umove(tcp, addr, &fl) < 0) {
230 tprintf("{...}");
231 return;
232 }
233 tprintf("{type=");
234 printxval(lockfcmds, fl.l_type, "F_???");
235 tprintf(", whence=");
236 printxval(whence, fl.l_whence, "SEEK_???");
Wichert Akkerman7b3346b2001-10-09 23:47:38 +0000237 tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len);
John Hughesbdf48f52001-03-06 15:08:09 +0000238 if (getlk)
239 tprintf(", pid=%lu}", (unsigned long) fl.l_pid);
240 else
241 tprintf("}");
242}
243#endif
244
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000245/*
246 * low bits of the open(2) flags define access mode,
247 * other bits are real flags.
248 */
249static const char *
250sprint_open_modes(mode_t flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000251{
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000252 extern const struct xlat open_access_modes[];
253 extern const struct xlat open_mode_flags[];
254 static char outstr[1024];
255 const char *str = xlookup(open_access_modes, flags & 3);
256 const char *sep = "";
257 const struct xlat *x;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000258
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000259 strcpy(outstr, "flags ");
260 if (str)
261 {
262 strcat(outstr, str);
263 flags &= ~3;
264 if (!flags)
265 return outstr;
266 strcat(outstr, "|");
267 }
268
269 for (x = open_mode_flags; x->str; x++)
270 {
271 if ((flags & x->val) == x->val)
272 {
273 sprintf(outstr + strlen(outstr),
274 "%s%s", sep, x->str);
275 sep = "|";
276 flags &= ~x->val;
277 }
278 }
279 if (flags)
280 sprintf(outstr + strlen(outstr), "%s%#x", sep, flags);
281 return outstr;
282}
283
284int
285sys_fcntl(struct tcb *tcp)
286{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287 if (entering(tcp)) {
288 tprintf("%ld, ", tcp->u_arg[0]);
289 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
290 switch (tcp->u_arg[1]) {
291 case F_SETFD:
292 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000293 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000294 break;
295 case F_SETOWN: case F_DUPFD:
296 tprintf(", %ld", tcp->u_arg[2]);
297 break;
298 case F_SETFL:
299 tprintf(", ");
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000300 tprint_open_modes(tcp, tcp->u_arg[2]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000301 break;
302 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000303#ifdef F_FREESP
304 case F_FREESP:
305#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000306 tprintf(", ");
307 printflock(tcp, tcp->u_arg[2], 0);
308 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000309#if _LFS64_LARGEFILE
310#ifdef F_FREESP64
311 case F_FREESP64:
312#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000313 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000314 even though the kernel has different values - as does Solaris. */
315#if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
316 case F_SETLK64:
317#endif
318#if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
319 case F_SETLKW64:
320#endif
321 tprintf(", ");
322 printflock64(tcp, tcp->u_arg[2], 0);
323 break;
324#endif
325 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000326 }
327 else {
328 switch (tcp->u_arg[1]) {
329 case F_DUPFD:
330 case F_SETFD: case F_SETFL:
331 case F_SETLK: case F_SETLKW:
332 case F_SETOWN: case F_GETOWN:
333 break;
334 case F_GETFD:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000335 if (syserror(tcp) || tcp->u_rval == 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000336 return 0;
Roland McGratha6c0d8c2007-11-01 21:46:22 +0000337 tcp->auxstr =
338 sprintflags("flags ", fdflags, tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000339 return RVAL_HEX|RVAL_STR;
340 case F_GETFL:
Dmitry V. Levin21a75342008-09-03 01:22:18 +0000341 if (syserror(tcp))
342 return 0;
Dmitry V. Levin9b5b67e2007-01-11 23:19:55 +0000343 tcp->auxstr = sprint_open_modes(tcp->u_rval);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000344 return RVAL_HEX|RVAL_STR;
345 case F_GETLK:
346 tprintf(", ");
347 printflock(tcp, tcp->u_arg[2], 1);
348 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000349#if _LFS64_LARGEFILE
350#if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
351 case F_GETLK64:
352#endif
353 tprintf(", ");
354 printflock64(tcp, tcp->u_arg[2], 1);
355 break;
356#endif
357 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000358 tprintf(", %#lx", tcp->u_arg[2]);
359 break;
360 }
361 }
362 return 0;
363}
364
365#ifdef LOCK_SH
366
367int
368sys_flock(tcp)
369struct tcb *tcp;
370{
371 if (entering(tcp)) {
372 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000373 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374 }
375 return 0;
376}
377#endif /* LOCK_SH */
378
379int
380sys_close(tcp)
381struct tcb *tcp;
382{
383 if (entering(tcp)) {
384 tprintf("%ld", tcp->u_arg[0]);
385 }
386 return 0;
387}
388
389int
390sys_dup(tcp)
391struct tcb *tcp;
392{
393 if (entering(tcp)) {
394 tprintf("%ld", tcp->u_arg[0]);
395 }
396 return 0;
397}
398
399int
400sys_dup2(tcp)
401struct tcb *tcp;
402{
403 if (entering(tcp)) {
404 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
405 }
406 return 0;
407}
408
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000409#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000410int
411sys_getdtablesize(tcp)
412struct tcb *tcp;
413{
414 return 0;
415}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000416#endif /* ALPHA || FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000417
418static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000419decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000420{
421 int i, j, nfds;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000422 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
423 & -sizeof(long));
424 fd_set *fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 static char outstr[1024];
426 char *sep;
427 long arg;
428
429 if (entering(tcp)) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000430 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000431 if (fds == NULL)
432 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000433 nfds = args[0];
434 tprintf("%d", nfds);
435 for (i = 0; i < 3; i++) {
436 arg = args[i+1];
437 if (arg == 0) {
438 tprintf(", NULL");
439 continue;
440 }
Roland McGrath46100d02005-06-01 18:55:42 +0000441 if (fds == NULL || !verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 tprintf(", %#lx", arg);
443 continue;
444 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000445 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000446 tprintf(", [?]");
447 continue;
448 }
449 tprintf(", [");
450 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000451 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000452 tprintf("%s%u", sep, j);
453 sep = " ";
454 }
455 }
456 tprintf("]");
457 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000458 free(fds);
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000459 tprintf(", ");
Roland McGrath6afc5652007-07-24 01:57:11 +0000460 printtv_bitness(tcp, args[4], bitness, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000461 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000462 else
463 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000464 unsigned int cumlen = 0;
465 char *sep = "";
466
467 if (syserror(tcp))
468 return 0;
469
470 if ((nfds = tcp->u_rval) == 0) {
471 tcp->auxstr = "Timeout";
472 return RVAL_STR;
473 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000474
475 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000476 if (fds == NULL)
477 fprintf(stderr, "out of memory\n");
Roland McGrathe85aaa42005-02-06 01:55:12 +0000478
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000479 outstr[0] = '\0';
480 for (i = 0; i < 3; i++) {
481 int first = 1;
482 char str[20];
483
484 tcp->auxstr = outstr;
485 arg = args[i+1];
Roland McGrath46100d02005-06-01 18:55:42 +0000486 if (fds == NULL || !arg ||
487 umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000488 continue;
489 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000490 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000491 if (first) {
492 sprintf(str, "%s%s [%u", sep,
493 i == 0 ? "in" :
494 i == 1 ? "out" :
495 "except", j);
496 first = 0;
497 sep = ", ";
498 }
499 else
500 sprintf(str, " %u", j);
501 cumlen += strlen(str);
502 if (cumlen < sizeof(outstr))
503 strcat(outstr, str);
504 nfds--;
505 }
506 }
507 if (cumlen)
508 strcat(outstr, "]");
509 if (nfds == 0)
510 break;
511 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000512 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000513#ifdef LINUX
514 /* This contains no useful information on SunOS. */
515 if (args[4]) {
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000516 char str[128];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000517
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000518 sprintf(str, "%sleft ", sep);
519 sprinttv(tcp, args[4], bitness, str + strlen(str));
520 if ((cumlen += strlen(str)) < sizeof(outstr))
521 strcat(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000522 }
523#endif /* LINUX */
524 return RVAL_STR;
525 }
526 return 0;
527}
528
529#ifdef LINUX
530
531int
532sys_oldselect(tcp)
533struct tcb *tcp;
534{
535 long args[5];
536
537 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
538 tprintf("[...]");
539 return 0;
540 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000541 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542}
543
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000544#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000545int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000546sys_osf_select(tcp)
547struct tcb *tcp;
548{
549 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000550 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000551}
552#endif
553
Roland McGrath93817bf2004-10-06 22:23:31 +0000554static struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000555#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000556 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000557#endif
558#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000559 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000560#endif
561#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000562 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000563#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000564 { 0, NULL }
565};
566
567static struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000568#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000569 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000570#endif
571#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000572 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000573#endif
574#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000575 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000576#endif
577#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000578 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000579#endif
580#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000581 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000582#endif
583#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000584 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000585#endif
586#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000587 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000588#endif
589#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000590 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000591#endif
592#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000593 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000594#endif
595#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000596 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000597#endif
598#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000599 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000600#endif
601#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000602 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000603#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000604 { 0, NULL }
605};
606
607int
608sys_epoll_create(tcp)
609struct tcb *tcp;
610{
611 if (entering(tcp))
612 tprintf("%ld", tcp->u_arg[0]);
613 return 0;
614}
615
Roland McGrath63d6e542004-10-20 02:17:41 +0000616#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000617static void
618print_epoll_event(ev)
619struct epoll_event *ev;
620{
621 tprintf("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000622 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000623 /* We cannot know what format the program uses, so print u32 and u64
624 which will cover every value. */
625 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
626 ev->data.u32, ev->data.u64);
627}
Roland McGrath63d6e542004-10-20 02:17:41 +0000628#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000629
630int
631sys_epoll_ctl(tcp)
632struct tcb *tcp;
633{
634 if (entering(tcp)) {
Roland McGrath93817bf2004-10-06 22:23:31 +0000635 tprintf("%ld, ", tcp->u_arg[0]);
636 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
637 tprintf(", %ld, ", tcp->u_arg[2]);
638 if (tcp->u_arg[3] == 0)
639 tprintf("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000640 else {
641#ifdef HAVE_SYS_EPOLL_H
642 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000643 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000644 print_epoll_event(&ev);
645 else
646#endif
647 tprintf("{...}");
648 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000649 }
650 return 0;
651}
652
Roland McGrathf2400052007-08-02 01:13:26 +0000653static void
654epoll_wait_common(tcp)
Roland McGrath93817bf2004-10-06 22:23:31 +0000655struct tcb *tcp;
656{
657 if (entering(tcp))
658 tprintf("%ld, ", tcp->u_arg[0]);
659 else {
660 if (syserror(tcp))
661 tprintf("%lx", tcp->u_arg[1]);
662 else if (tcp->u_rval == 0)
663 tprintf("{}");
664 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000665#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000666 struct epoll_event ev, *start, *cur, *end;
667 int failed = 0;
668
669 tprintf("{");
670 start = (struct epoll_event *) tcp->u_arg[1];
671 end = start + tcp->u_rval;
672 for (cur = start; cur < end; ++cur) {
673 if (cur > start)
674 tprintf(", ");
675 if (umove(tcp, (long) cur, &ev) == 0)
676 print_epoll_event(&ev);
677 else {
678 tprintf("?");
679 failed = 1;
680 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000681 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000682 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000683 tprintf("}");
684 if (failed)
685 tprintf(" %#lx", (long) start);
686#else
687 tprintf("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000688#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000689 }
690 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
691 }
Roland McGrathf2400052007-08-02 01:13:26 +0000692}
693
694int
695sys_epoll_wait(tcp)
696struct tcb *tcp;
697{
698 epoll_wait_common(tcp);
699 return 0;
700}
701
702int
703sys_epoll_pwait(tcp)
704struct tcb *tcp;
705{
706 epoll_wait_common(tcp);
707 if (exiting(tcp))
708 print_sigset(tcp, tcp->u_arg[4], 0);
Roland McGrath93817bf2004-10-06 22:23:31 +0000709 return 0;
710}
Roland McGrath37b9f842005-05-09 08:02:00 +0000711
712int
713sys_io_setup(tcp)
714struct tcb *tcp;
715{
716 if (entering(tcp))
717 tprintf("%ld, ", tcp->u_arg[0]);
718 else {
719 if (syserror(tcp))
720 tprintf("0x%0lx", tcp->u_arg[1]);
721 else {
722 unsigned long user_id;
723 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
724 tprintf("{%lu}", user_id);
725 else
726 tprintf("{...}");
727 }
728 }
729 return 0;
730}
731
732int
733sys_io_destroy(tcp)
734struct tcb *tcp;
735{
736 if (entering(tcp))
737 tprintf("%lu", tcp->u_arg[0]);
738 return 0;
739}
740
741int
742sys_io_submit(tcp)
743struct tcb *tcp;
744{
745 long nr;
746 if (entering(tcp)) {
747 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
748 nr = tcp->u_arg[1];
749 /* and if nr is negative? */
750 if (nr == 0)
751 tprintf("{}");
752 else {
753#ifdef HAVE_LIBAIO_H
754 long i;
755 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
756
757 for (i = 0; i < nr; i++, iocbs++) {
758 struct iocb iocb;
759 if (i == 0)
760 tprintf("{");
761 else
762 tprintf(", ");
763
764 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
765 umove(tcp, (unsigned long)iocbp, &iocb)) {
766 tprintf("{...}");
767 continue;
768 }
769 tprintf("{%p, %u, %hu, %hu, %d}",
770 iocb.data, iocb.key,
771 iocb.aio_lio_opcode,
772 iocb.aio_reqprio, iocb.aio_fildes);
773 }
774 if (i)
775 tprintf("}");
776#else
777 tprintf("{...}");
778#endif
779 }
780 }
781 return 0;
782}
783
784int
785sys_io_cancel(tcp)
786struct tcb *tcp;
787{
788 if (entering(tcp)) {
789#ifdef HAVE_LIBAIO_H
790 struct iocb iocb;
791#endif
792 tprintf("%lu, ", tcp->u_arg[0]);
793#ifdef HAVE_LIBAIO_H
794 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
795 tprintf("{%p, %u, %hu, %hu, %d}, ",
796 iocb.data, iocb.key,
797 iocb.aio_lio_opcode,
798 iocb.aio_reqprio, iocb.aio_fildes);
799 } else
800#endif
801 tprintf("{...}, ");
802 } else {
803 if (tcp->u_rval < 0)
804 tprintf("{...}");
805 else {
806#ifdef HAVE_LIBAIO_H
807 struct io_event event;
808 if (umove(tcp, tcp->u_arg[2], &event) == 0)
809 tprintf("{%p, %p, %ld, %ld}",
810 event.data, event.obj,
811 event.res, event.res2);
812 else
813#endif
814 tprintf("{...}");
815 }
816 }
817 return 0;
818}
819
820int
Roland McGrath6bc09da2007-11-01 21:50:54 +0000821sys_io_getevents(struct tcb * tcp)
Roland McGrath37b9f842005-05-09 08:02:00 +0000822{
823 if (entering(tcp)) {
824 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
825 tcp->u_arg[2]);
826 } else {
827 if (tcp->u_rval == 0) {
828 tprintf("{}");
829 } else {
830#ifdef HAVE_LIBAIO_H
831 struct io_event *events = (void *)tcp->u_arg[3];
832 long i, nr = tcp->u_rval;
833
834 for (i = 0; i < nr; i++, events++) {
835 struct io_event event;
836
837 if (i == 0)
838 tprintf("{");
839 else
840 tprintf(", ");
841
842 if (umove(tcp, (unsigned long)events, &event) != 0) {
843 tprintf("{...}");
844 continue;
845 }
846 tprintf("{%p, %p, %ld, %ld}", event.data,
847 event.obj, event.res, event.res2);
848 }
849 tprintf("}, ");
850#else
851 tprintf("{...}");
852#endif
853 }
854
Roland McGrath6bc09da2007-11-01 21:50:54 +0000855 print_timespec(tcp, tcp->u_arg[4]);
Roland McGrath37b9f842005-05-09 08:02:00 +0000856 }
857 return 0;
858}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000859#endif /* LINUX */
860
861int
862sys_select(tcp)
863struct tcb *tcp;
864{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000865 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000866}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000867
868#ifdef LINUX
869int
870sys_pselect6(struct tcb *tcp)
871{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000872 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Roland McGrathfe10aa72007-11-01 21:52:20 +0000873 if (entering(tcp)) {
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000874 struct {
875 void *ss;
876 unsigned long len;
877 } data;
878 if (umove(tcp, tcp->u_arg[5], &data) < 0)
879 tprintf(", %#lx", tcp->u_arg[5]);
880 else {
881 tprintf(", {");
Roland McGrathfe10aa72007-11-01 21:52:20 +0000882 if (data.len < sizeof(long))
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000883 tprintf("%#lx", (long)data.ss);
884 else
885 print_sigset(tcp, (long)data.ss, 0);
886 tprintf(", %lu}", data.len);
887 }
888 }
889 return rc;
890}
Roland McGrathe7c39672007-08-02 01:32:17 +0000891
892int
893sys_eventfd(tcp)
894struct tcb *tcp;
895{
896 if (entering(tcp))
897 tprintf("%lu", tcp->u_arg[0]);
898 return 0;
899}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000900#endif