blob: 6e864b2734f10c87a0158a5ad4ca99f0f1a8b30a [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
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000245static char *
246sprintflags(xlat, flags)
Roland McGrathd9f816f2004-09-04 03:39:20 +0000247const struct xlat *xlat;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000248int flags;
249{
250 static char outstr[1024];
251 char *sep;
252
253 strcpy(outstr, "flags ");
254 sep = "";
255 for (; xlat->str; xlat++) {
256 if ((flags & xlat->val) == xlat->val) {
257 sprintf(outstr + strlen(outstr),
258 "%s%s", sep, xlat->str);
259 sep = "|";
260 flags &= ~xlat->val;
261 }
262 }
263 if (flags)
264 sprintf(outstr + strlen(outstr),
265 "%s%#x", sep, flags);
266 return outstr;
267}
268
269int
270sys_fcntl(tcp)
271struct tcb *tcp;
272{
Roland McGrathd9f816f2004-09-04 03:39:20 +0000273 extern const struct xlat openmodes[];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000274
275 if (entering(tcp)) {
276 tprintf("%ld, ", tcp->u_arg[0]);
277 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
278 switch (tcp->u_arg[1]) {
279 case F_SETFD:
280 tprintf(", ");
281 if (printflags(fdflags, tcp->u_arg[2]) == 0)
282 tprintf("0");
283 break;
284 case F_SETOWN: case F_DUPFD:
285 tprintf(", %ld", tcp->u_arg[2]);
286 break;
287 case F_SETFL:
288 tprintf(", ");
289 if (printflags(openmodes, tcp->u_arg[2] + 1) == 0)
290 tprintf("0");
291 break;
292 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000293#ifdef F_FREESP
294 case F_FREESP:
295#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000296 tprintf(", ");
297 printflock(tcp, tcp->u_arg[2], 0);
298 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000299#if _LFS64_LARGEFILE
300#ifdef F_FREESP64
301 case F_FREESP64:
302#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000303 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000304 even though the kernel has different values - as does Solaris. */
305#if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
306 case F_SETLK64:
307#endif
308#if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
309 case F_SETLKW64:
310#endif
311 tprintf(", ");
312 printflock64(tcp, tcp->u_arg[2], 0);
313 break;
314#endif
315 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000316 }
317 else {
318 switch (tcp->u_arg[1]) {
319 case F_DUPFD:
320 case F_SETFD: case F_SETFL:
321 case F_SETLK: case F_SETLKW:
322 case F_SETOWN: case F_GETOWN:
323 break;
324 case F_GETFD:
325 if (tcp->u_rval == 0)
326 return 0;
327 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
328 return RVAL_HEX|RVAL_STR;
329 case F_GETFL:
330 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
331 return RVAL_HEX|RVAL_STR;
332 case F_GETLK:
333 tprintf(", ");
334 printflock(tcp, tcp->u_arg[2], 1);
335 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000336#if _LFS64_LARGEFILE
337#if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
338 case F_GETLK64:
339#endif
340 tprintf(", ");
341 printflock64(tcp, tcp->u_arg[2], 1);
342 break;
343#endif
344 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000345 tprintf(", %#lx", tcp->u_arg[2]);
346 break;
347 }
348 }
349 return 0;
350}
351
352#ifdef LOCK_SH
353
354int
355sys_flock(tcp)
356struct tcb *tcp;
357{
358 if (entering(tcp)) {
359 tprintf("%ld, ", tcp->u_arg[0]);
360 if (!printflags(flockcmds, tcp->u_arg[1]))
361 tprintf("LOCK_???");
362 }
363 return 0;
364}
365#endif /* LOCK_SH */
366
367int
368sys_close(tcp)
369struct tcb *tcp;
370{
371 if (entering(tcp)) {
372 tprintf("%ld", tcp->u_arg[0]);
373 }
374 return 0;
375}
376
377int
378sys_dup(tcp)
379struct tcb *tcp;
380{
381 if (entering(tcp)) {
382 tprintf("%ld", tcp->u_arg[0]);
383 }
384 return 0;
385}
386
387int
388sys_dup2(tcp)
389struct tcb *tcp;
390{
391 if (entering(tcp)) {
392 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
393 }
394 return 0;
395}
396
397int
398sys_getdtablesize(tcp)
399struct tcb *tcp;
400{
401 return 0;
402}
403
404static int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000405decode_select(tcp, args, bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406struct tcb *tcp;
407long *args;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000408int bitness;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000409{
410 int i, j, nfds;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000411 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
412 & -sizeof(long));
413 fd_set *fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000414 struct timeval tv;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000415#ifdef ALPHA
416 struct timeval32 {
417 unsigned tv_sec;
418 unsigned tv_usec;
419 } *tv32;
420#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000421 static char outstr[1024];
422 char *sep;
423 long arg;
424
425 if (entering(tcp)) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000426 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000427 if (fds == NULL)
428 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429 nfds = args[0];
430 tprintf("%d", nfds);
431 for (i = 0; i < 3; i++) {
432 arg = args[i+1];
433 if (arg == 0) {
434 tprintf(", NULL");
435 continue;
436 }
Roland McGrath46100d02005-06-01 18:55:42 +0000437 if (fds == NULL || !verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000438 tprintf(", %#lx", arg);
439 continue;
440 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000441 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000442 tprintf(", [?]");
443 continue;
444 }
445 tprintf(", [");
446 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000447 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000448 tprintf("%s%u", sep, j);
449 sep = " ";
450 }
451 }
452 tprintf("]");
453 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000454 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000455 if (!args[4])
456 tprintf(", NULL");
457 else if (!verbose(tcp))
458 tprintf(", %#lx", args[4]);
459 else if (umove(tcp, args[4], &tv) < 0)
460 tprintf(", {...}");
461 else {
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000462#ifdef ALPHA
463 if (bitness) {
464 tv32=(struct timeval32*)&tv;
Wichert Akkerman221f54f1999-11-18 17:26:45 +0000465 tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000466 } else
467#endif
468 tprintf(", {%lu, %lu}",
469 (long) tv.tv_sec, (long) tv.tv_usec);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000470 }
471 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000472 else
473 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474 unsigned int cumlen = 0;
475 char *sep = "";
476
477 if (syserror(tcp))
478 return 0;
479
480 if ((nfds = tcp->u_rval) == 0) {
481 tcp->auxstr = "Timeout";
482 return RVAL_STR;
483 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000484
485 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000486 if (fds == NULL)
487 fprintf(stderr, "out of memory\n");
Roland McGrathe85aaa42005-02-06 01:55:12 +0000488
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000489 outstr[0] = '\0';
490 for (i = 0; i < 3; i++) {
491 int first = 1;
492 char str[20];
493
494 tcp->auxstr = outstr;
495 arg = args[i+1];
Roland McGrath46100d02005-06-01 18:55:42 +0000496 if (fds == NULL || !arg ||
497 umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000498 continue;
499 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000500 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000501 if (first) {
502 sprintf(str, "%s%s [%u", sep,
503 i == 0 ? "in" :
504 i == 1 ? "out" :
505 "except", j);
506 first = 0;
507 sep = ", ";
508 }
509 else
510 sprintf(str, " %u", j);
511 cumlen += strlen(str);
512 if (cumlen < sizeof(outstr))
513 strcat(outstr, str);
514 nfds--;
515 }
516 }
517 if (cumlen)
518 strcat(outstr, "]");
519 if (nfds == 0)
520 break;
521 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000522 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000523#ifdef LINUX
524 /* This contains no useful information on SunOS. */
525 if (args[4]) {
Roland McGrath183df962005-03-23 03:18:59 +0000526 char str[64];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000527
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000528 if (umove(tcp, args[4], &tv) >= 0) {
529#ifdef ALPHA
530 if (bitness) {
531 tv32=(struct timeval32*)&tv;
532 sprintf(str, "%sleft {%u, %u}", sep,
533 tv32->tv_sec, tv32->tv_usec);
534 } else
535#endif
536 sprintf(str, "%sleft {%lu, %lu}", sep,
537 (long) tv.tv_sec, (long) tv.tv_usec);
538
539 if ((cumlen += strlen(str)) < sizeof(outstr))
540 strcat(outstr, str);
541 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000542 }
543#endif /* LINUX */
544 return RVAL_STR;
545 }
546 return 0;
547}
548
549#ifdef LINUX
550
551int
552sys_oldselect(tcp)
553struct tcb *tcp;
554{
555 long args[5];
556
557 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
558 tprintf("[...]");
559 return 0;
560 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000561 return decode_select(tcp, args, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000562}
563
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000564#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000565int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000566sys_osf_select(tcp)
567struct tcb *tcp;
568{
569 long *args = tcp->u_arg;
570 return decode_select(tcp, args, 1);
571}
572#endif
573
Roland McGrath93817bf2004-10-06 22:23:31 +0000574static struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000575#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000576 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000577#endif
578#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000579 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000580#endif
581#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000582 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000583#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000584 { 0, NULL }
585};
586
587static struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000588#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000589 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000590#endif
591#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000592 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000593#endif
594#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000595 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000596#endif
597#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000598 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000599#endif
600#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000601 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000602#endif
603#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000604 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000605#endif
606#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000607 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000608#endif
609#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000610 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000611#endif
612#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000613 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000614#endif
615#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000616 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000617#endif
618#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000619 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000620#endif
621#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000622 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000623#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000624 { 0, NULL }
625};
626
627int
628sys_epoll_create(tcp)
629struct tcb *tcp;
630{
631 if (entering(tcp))
632 tprintf("%ld", tcp->u_arg[0]);
633 return 0;
634}
635
Roland McGrath63d6e542004-10-20 02:17:41 +0000636#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000637static void
638print_epoll_event(ev)
639struct epoll_event *ev;
640{
641 tprintf("{");
642 if (printflags(epollevents, ev->events) == 0)
643 tprintf("0");
644 /* We cannot know what format the program uses, so print u32 and u64
645 which will cover every value. */
646 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
647 ev->data.u32, ev->data.u64);
648}
Roland McGrath63d6e542004-10-20 02:17:41 +0000649#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000650
651int
652sys_epoll_ctl(tcp)
653struct tcb *tcp;
654{
655 if (entering(tcp)) {
Roland McGrath93817bf2004-10-06 22:23:31 +0000656 tprintf("%ld, ", tcp->u_arg[0]);
657 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
658 tprintf(", %ld, ", tcp->u_arg[2]);
659 if (tcp->u_arg[3] == 0)
660 tprintf("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000661 else {
662#ifdef HAVE_SYS_EPOLL_H
663 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000664 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000665 print_epoll_event(&ev);
666 else
667#endif
668 tprintf("{...}");
669 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000670 }
671 return 0;
672}
673
674int
675sys_epoll_wait(tcp)
676struct tcb *tcp;
677{
678 if (entering(tcp))
679 tprintf("%ld, ", tcp->u_arg[0]);
680 else {
681 if (syserror(tcp))
682 tprintf("%lx", tcp->u_arg[1]);
683 else if (tcp->u_rval == 0)
684 tprintf("{}");
685 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000686#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000687 struct epoll_event evs[tcp->u_rval];
Roland McGrath63d6e542004-10-20 02:17:41 +0000688 if (umove(tcp, tcp->u_arg[1], evs) == 0) {
Roland McGrath93817bf2004-10-06 22:23:31 +0000689 unsigned long i;
690 tprintf("{");
691 for (i = 0; i < tcp->u_rval; ++i) {
692 if (i > 0)
693 tprintf(", ");
694 print_epoll_event(&evs[i]);
695 }
696 tprintf("}");
697 }
Roland McGrath63d6e542004-10-20 02:17:41 +0000698 else
699#endif
700 tprintf("{...}");
Roland McGrath93817bf2004-10-06 22:23:31 +0000701 }
702 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
703 }
704 return 0;
705}
Roland McGrath37b9f842005-05-09 08:02:00 +0000706
707int
708sys_io_setup(tcp)
709struct tcb *tcp;
710{
711 if (entering(tcp))
712 tprintf("%ld, ", tcp->u_arg[0]);
713 else {
714 if (syserror(tcp))
715 tprintf("0x%0lx", tcp->u_arg[1]);
716 else {
717 unsigned long user_id;
718 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
719 tprintf("{%lu}", user_id);
720 else
721 tprintf("{...}");
722 }
723 }
724 return 0;
725}
726
727int
728sys_io_destroy(tcp)
729struct tcb *tcp;
730{
731 if (entering(tcp))
732 tprintf("%lu", tcp->u_arg[0]);
733 return 0;
734}
735
736int
737sys_io_submit(tcp)
738struct tcb *tcp;
739{
740 long nr;
741 if (entering(tcp)) {
742 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
743 nr = tcp->u_arg[1];
744 /* and if nr is negative? */
745 if (nr == 0)
746 tprintf("{}");
747 else {
748#ifdef HAVE_LIBAIO_H
749 long i;
750 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
751
752 for (i = 0; i < nr; i++, iocbs++) {
753 struct iocb iocb;
754 if (i == 0)
755 tprintf("{");
756 else
757 tprintf(", ");
758
759 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
760 umove(tcp, (unsigned long)iocbp, &iocb)) {
761 tprintf("{...}");
762 continue;
763 }
764 tprintf("{%p, %u, %hu, %hu, %d}",
765 iocb.data, iocb.key,
766 iocb.aio_lio_opcode,
767 iocb.aio_reqprio, iocb.aio_fildes);
768 }
769 if (i)
770 tprintf("}");
771#else
772 tprintf("{...}");
773#endif
774 }
775 }
776 return 0;
777}
778
779int
780sys_io_cancel(tcp)
781struct tcb *tcp;
782{
783 if (entering(tcp)) {
784#ifdef HAVE_LIBAIO_H
785 struct iocb iocb;
786#endif
787 tprintf("%lu, ", tcp->u_arg[0]);
788#ifdef HAVE_LIBAIO_H
789 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
790 tprintf("{%p, %u, %hu, %hu, %d}, ",
791 iocb.data, iocb.key,
792 iocb.aio_lio_opcode,
793 iocb.aio_reqprio, iocb.aio_fildes);
794 } else
795#endif
796 tprintf("{...}, ");
797 } else {
798 if (tcp->u_rval < 0)
799 tprintf("{...}");
800 else {
801#ifdef HAVE_LIBAIO_H
802 struct io_event event;
803 if (umove(tcp, tcp->u_arg[2], &event) == 0)
804 tprintf("{%p, %p, %ld, %ld}",
805 event.data, event.obj,
806 event.res, event.res2);
807 else
808#endif
809 tprintf("{...}");
810 }
811 }
812 return 0;
813}
814
815int
816sys_io_getevents(tcp)
817struct tcb *tcp;
818{
819 if (entering(tcp)) {
820 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
821 tcp->u_arg[2]);
822 } else {
823 if (tcp->u_rval == 0) {
824 tprintf("{}");
825 } else {
826#ifdef HAVE_LIBAIO_H
827 struct io_event *events = (void *)tcp->u_arg[3];
828 long i, nr = tcp->u_rval;
829
830 for (i = 0; i < nr; i++, events++) {
831 struct io_event event;
832
833 if (i == 0)
834 tprintf("{");
835 else
836 tprintf(", ");
837
838 if (umove(tcp, (unsigned long)events, &event) != 0) {
839 tprintf("{...}");
840 continue;
841 }
842 tprintf("{%p, %p, %ld, %ld}", event.data,
843 event.obj, event.res, event.res2);
844 }
845 tprintf("}, ");
846#else
847 tprintf("{...}");
848#endif
849 }
850
851 if (tcp->u_arg[4] == 0)
852 tprintf("NULL");
853 else {
854 struct timespec to;
855 if (umove(tcp, tcp->u_arg[4], &to) == 0)
856 tprintf("{%lu, %lu}", to.tv_sec, to.tv_nsec);
857 else
858 tprintf("{...}");
859 }
860 }
861 return 0;
862}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000863#endif /* LINUX */
864
865int
866sys_select(tcp)
867struct tcb *tcp;
868{
869 long *args = tcp->u_arg;
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000870 return decode_select(tcp, args, 0);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000871}