blob: 29f8a95e3afe631dcc0c02e0f20c9d314f4f0af6 [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. Levinab9008b2007-01-11 22:05:04 +0000245static const char *
246sprintflags(const struct xlat *xlat, int flags)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247{
248 static char outstr[1024];
Dmitry V. Levinab9008b2007-01-11 22:05:04 +0000249 const char *sep;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000250
251 strcpy(outstr, "flags ");
252 sep = "";
253 for (; xlat->str; xlat++) {
254 if ((flags & xlat->val) == xlat->val) {
255 sprintf(outstr + strlen(outstr),
256 "%s%s", sep, xlat->str);
257 sep = "|";
258 flags &= ~xlat->val;
259 }
260 }
261 if (flags)
262 sprintf(outstr + strlen(outstr),
263 "%s%#x", sep, flags);
264 return outstr;
265}
266
267int
268sys_fcntl(tcp)
269struct tcb *tcp;
270{
Roland McGrathd9f816f2004-09-04 03:39:20 +0000271 extern const struct xlat openmodes[];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000272
273 if (entering(tcp)) {
274 tprintf("%ld, ", tcp->u_arg[0]);
275 printxval(fcntlcmds, tcp->u_arg[1], "F_???");
276 switch (tcp->u_arg[1]) {
277 case F_SETFD:
278 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000279 printflags(fdflags, tcp->u_arg[2], "FD_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000280 break;
281 case F_SETOWN: case F_DUPFD:
282 tprintf(", %ld", tcp->u_arg[2]);
283 break;
284 case F_SETFL:
285 tprintf(", ");
Roland McGrathb2dee132005-06-01 19:02:36 +0000286 printflags(openmodes, tcp->u_arg[2] + 1, "O_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000287 break;
288 case F_SETLK: case F_SETLKW:
John Hughesbdf48f52001-03-06 15:08:09 +0000289#ifdef F_FREESP
290 case F_FREESP:
291#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000292 tprintf(", ");
293 printflock(tcp, tcp->u_arg[2], 0);
294 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000295#if _LFS64_LARGEFILE
296#ifdef F_FREESP64
297 case F_FREESP64:
298#endif
Roland McGrathe948faf2002-12-15 23:58:18 +0000299 /* Linux glibc defines SETLK64 as SETLK,
John Hughesbdf48f52001-03-06 15:08:09 +0000300 even though the kernel has different values - as does Solaris. */
301#if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK
302 case F_SETLK64:
303#endif
304#if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW
305 case F_SETLKW64:
306#endif
307 tprintf(", ");
308 printflock64(tcp, tcp->u_arg[2], 0);
309 break;
310#endif
311 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000312 }
313 else {
314 switch (tcp->u_arg[1]) {
315 case F_DUPFD:
316 case F_SETFD: case F_SETFL:
317 case F_SETLK: case F_SETLKW:
318 case F_SETOWN: case F_GETOWN:
319 break;
320 case F_GETFD:
321 if (tcp->u_rval == 0)
322 return 0;
323 tcp->auxstr = sprintflags(fdflags, tcp->u_rval);
324 return RVAL_HEX|RVAL_STR;
325 case F_GETFL:
326 tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1);
327 return RVAL_HEX|RVAL_STR;
328 case F_GETLK:
329 tprintf(", ");
330 printflock(tcp, tcp->u_arg[2], 1);
331 break;
John Hughesbdf48f52001-03-06 15:08:09 +0000332#if _LFS64_LARGEFILE
333#if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK
334 case F_GETLK64:
335#endif
336 tprintf(", ");
337 printflock64(tcp, tcp->u_arg[2], 1);
338 break;
339#endif
340 default:
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000341 tprintf(", %#lx", tcp->u_arg[2]);
342 break;
343 }
344 }
345 return 0;
346}
347
348#ifdef LOCK_SH
349
350int
351sys_flock(tcp)
352struct tcb *tcp;
353{
354 if (entering(tcp)) {
355 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrathb2dee132005-06-01 19:02:36 +0000356 printflags(flockcmds, tcp->u_arg[1], "LOCK_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000357 }
358 return 0;
359}
360#endif /* LOCK_SH */
361
362int
363sys_close(tcp)
364struct tcb *tcp;
365{
366 if (entering(tcp)) {
367 tprintf("%ld", tcp->u_arg[0]);
368 }
369 return 0;
370}
371
372int
373sys_dup(tcp)
374struct tcb *tcp;
375{
376 if (entering(tcp)) {
377 tprintf("%ld", tcp->u_arg[0]);
378 }
379 return 0;
380}
381
382int
383sys_dup2(tcp)
384struct tcb *tcp;
385{
386 if (entering(tcp)) {
387 tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]);
388 }
389 return 0;
390}
391
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000392#if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000393int
394sys_getdtablesize(tcp)
395struct tcb *tcp;
396{
397 return 0;
398}
Dmitry V. Levinb9fe0112006-12-13 16:59:44 +0000399#endif /* ALPHA || FREEBSD || SUNOS4 */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000400
401static int
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000402decode_select(struct tcb *tcp, long *args, enum bitness_t bitness)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000403{
404 int i, j, nfds;
Roland McGrathe85aaa42005-02-06 01:55:12 +0000405 unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1)
406 & -sizeof(long));
407 fd_set *fds;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000408 static char outstr[1024];
409 char *sep;
410 long arg;
411
412 if (entering(tcp)) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000413 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000414 if (fds == NULL)
415 fprintf(stderr, "out of memory\n");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000416 nfds = args[0];
417 tprintf("%d", nfds);
418 for (i = 0; i < 3; i++) {
419 arg = args[i+1];
420 if (arg == 0) {
421 tprintf(", NULL");
422 continue;
423 }
Roland McGrath46100d02005-06-01 18:55:42 +0000424 if (fds == NULL || !verbose(tcp)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000425 tprintf(", %#lx", arg);
426 continue;
427 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000428 if (umoven(tcp, arg, fdsize, (char *) fds) < 0) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000429 tprintf(", [?]");
430 continue;
431 }
432 tprintf(", [");
433 for (j = 0, sep = ""; j < nfds; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000434 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000435 tprintf("%s%u", sep, j);
436 sep = " ";
437 }
438 }
439 tprintf("]");
440 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000441 free(fds);
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000442 tprintf(", ");
443 printtv_bitness(tcp, args[4], bitness);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000444 }
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000445 else
446 {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000447 unsigned int cumlen = 0;
448 char *sep = "";
449
450 if (syserror(tcp))
451 return 0;
452
453 if ((nfds = tcp->u_rval) == 0) {
454 tcp->auxstr = "Timeout";
455 return RVAL_STR;
456 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000457
458 fds = (fd_set *) malloc(fdsize);
Roland McGrath46100d02005-06-01 18:55:42 +0000459 if (fds == NULL)
460 fprintf(stderr, "out of memory\n");
Roland McGrathe85aaa42005-02-06 01:55:12 +0000461
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000462 outstr[0] = '\0';
463 for (i = 0; i < 3; i++) {
464 int first = 1;
465 char str[20];
466
467 tcp->auxstr = outstr;
468 arg = args[i+1];
Roland McGrath46100d02005-06-01 18:55:42 +0000469 if (fds == NULL || !arg ||
470 umoven(tcp, arg, fdsize, (char *) fds) < 0)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000471 continue;
472 for (j = 0; j < args[0]; j++) {
Roland McGrathe85aaa42005-02-06 01:55:12 +0000473 if (FD_ISSET(j, fds)) {
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000474 if (first) {
475 sprintf(str, "%s%s [%u", sep,
476 i == 0 ? "in" :
477 i == 1 ? "out" :
478 "except", j);
479 first = 0;
480 sep = ", ";
481 }
482 else
483 sprintf(str, " %u", j);
484 cumlen += strlen(str);
485 if (cumlen < sizeof(outstr))
486 strcat(outstr, str);
487 nfds--;
488 }
489 }
490 if (cumlen)
491 strcat(outstr, "]");
492 if (nfds == 0)
493 break;
494 }
Roland McGrathe85aaa42005-02-06 01:55:12 +0000495 free(fds);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000496#ifdef LINUX
497 /* This contains no useful information on SunOS. */
498 if (args[4]) {
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000499 char str[128];
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000500
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000501 sprintf(str, "%sleft ", sep);
502 sprinttv(tcp, args[4], bitness, str + strlen(str));
503 if ((cumlen += strlen(str)) < sizeof(outstr))
504 strcat(outstr, str);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000505 }
506#endif /* LINUX */
507 return RVAL_STR;
508 }
509 return 0;
510}
511
512#ifdef LINUX
513
514int
515sys_oldselect(tcp)
516struct tcb *tcp;
517{
518 long args[5];
519
520 if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) {
521 tprintf("[...]");
522 return 0;
523 }
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000524 return decode_select(tcp, args, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000525}
526
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000527#ifdef ALPHA
Roland McGrathe948faf2002-12-15 23:58:18 +0000528int
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000529sys_osf_select(tcp)
530struct tcb *tcp;
531{
532 long *args = tcp->u_arg;
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000533 return decode_select(tcp, args, BITNESS_32);
Wichert Akkermanf5eeabb1999-11-18 17:09:47 +0000534}
535#endif
536
Roland McGrath93817bf2004-10-06 22:23:31 +0000537static struct xlat epollctls[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000538#ifdef EPOLL_CTL_ADD
Roland McGrath93817bf2004-10-06 22:23:31 +0000539 { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000540#endif
541#ifdef EPOLL_CTL_MOD
Roland McGrath93817bf2004-10-06 22:23:31 +0000542 { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000543#endif
544#ifdef EPOLL_CTL_DEL
Roland McGrath93817bf2004-10-06 22:23:31 +0000545 { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000546#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000547 { 0, NULL }
548};
549
550static struct xlat epollevents[] = {
Roland McGrath63d6e542004-10-20 02:17:41 +0000551#ifdef EPOLLIN
Roland McGrath93817bf2004-10-06 22:23:31 +0000552 { EPOLLIN, "EPOLLIN" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000553#endif
554#ifdef EPOLLPRI
Roland McGrath93817bf2004-10-06 22:23:31 +0000555 { EPOLLPRI, "EPOLLPRI" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000556#endif
557#ifdef EPOLLOUT
Roland McGrath93817bf2004-10-06 22:23:31 +0000558 { EPOLLOUT, "EPOLLOUT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000559#endif
560#ifdef EPOLLRDNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000561 { EPOLLRDNORM, "EPOLLRDNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000562#endif
563#ifdef EPOLLRDBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000564 { EPOLLRDBAND, "EPOLLRDBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000565#endif
566#ifdef EPOLLWRNORM
Roland McGrath93817bf2004-10-06 22:23:31 +0000567 { EPOLLWRNORM, "EPOLLWRNORM" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000568#endif
569#ifdef EPOLLWRBAND
Roland McGrath93817bf2004-10-06 22:23:31 +0000570 { EPOLLWRBAND, "EPOLLWRBAND" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000571#endif
572#ifdef EPOLLMSG
Roland McGrath93817bf2004-10-06 22:23:31 +0000573 { EPOLLMSG, "EPOLLMSG" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000574#endif
575#ifdef EPOLLERR
Roland McGrath93817bf2004-10-06 22:23:31 +0000576 { EPOLLERR, "EPOLLERR" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000577#endif
578#ifdef EPOLLHUP
Roland McGrath93817bf2004-10-06 22:23:31 +0000579 { EPOLLHUP, "EPOLLHUP" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000580#endif
581#ifdef EPOLLONESHOT
Roland McGrath93817bf2004-10-06 22:23:31 +0000582 { EPOLLONESHOT, "EPOLLONESHOT" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000583#endif
584#ifdef EPOLLET
Roland McGrath93817bf2004-10-06 22:23:31 +0000585 { EPOLLET, "EPOLLET" },
Roland McGrath63d6e542004-10-20 02:17:41 +0000586#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000587 { 0, NULL }
588};
589
590int
591sys_epoll_create(tcp)
592struct tcb *tcp;
593{
594 if (entering(tcp))
595 tprintf("%ld", tcp->u_arg[0]);
596 return 0;
597}
598
Roland McGrath63d6e542004-10-20 02:17:41 +0000599#ifdef HAVE_SYS_EPOLL_H
Roland McGrath93817bf2004-10-06 22:23:31 +0000600static void
601print_epoll_event(ev)
602struct epoll_event *ev;
603{
604 tprintf("{");
Roland McGrathb2dee132005-06-01 19:02:36 +0000605 printflags(epollevents, ev->events, "EPOLL???");
Roland McGrath93817bf2004-10-06 22:23:31 +0000606 /* We cannot know what format the program uses, so print u32 and u64
607 which will cover every value. */
608 tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}",
609 ev->data.u32, ev->data.u64);
610}
Roland McGrath63d6e542004-10-20 02:17:41 +0000611#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000612
613int
614sys_epoll_ctl(tcp)
615struct tcb *tcp;
616{
617 if (entering(tcp)) {
Roland McGrath93817bf2004-10-06 22:23:31 +0000618 tprintf("%ld, ", tcp->u_arg[0]);
619 printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???");
620 tprintf(", %ld, ", tcp->u_arg[2]);
621 if (tcp->u_arg[3] == 0)
622 tprintf("NULL");
Roland McGrath63d6e542004-10-20 02:17:41 +0000623 else {
624#ifdef HAVE_SYS_EPOLL_H
625 struct epoll_event ev;
Roland McGrath6e52d232004-10-20 02:17:41 +0000626 if (umove(tcp, tcp->u_arg[3], &ev) == 0)
Roland McGrath63d6e542004-10-20 02:17:41 +0000627 print_epoll_event(&ev);
628 else
629#endif
630 tprintf("{...}");
631 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000632 }
633 return 0;
634}
635
636int
637sys_epoll_wait(tcp)
638struct tcb *tcp;
639{
640 if (entering(tcp))
641 tprintf("%ld, ", tcp->u_arg[0]);
642 else {
643 if (syserror(tcp))
644 tprintf("%lx", tcp->u_arg[1]);
645 else if (tcp->u_rval == 0)
646 tprintf("{}");
647 else {
Roland McGrath63d6e542004-10-20 02:17:41 +0000648#ifdef HAVE_SYS_EPOLL_H
Roland McGrathaa524c82005-06-01 19:22:06 +0000649 struct epoll_event ev, *start, *cur, *end;
650 int failed = 0;
651
652 tprintf("{");
653 start = (struct epoll_event *) tcp->u_arg[1];
654 end = start + tcp->u_rval;
655 for (cur = start; cur < end; ++cur) {
656 if (cur > start)
657 tprintf(", ");
658 if (umove(tcp, (long) cur, &ev) == 0)
659 print_epoll_event(&ev);
660 else {
661 tprintf("?");
662 failed = 1;
663 break;
Roland McGrath93817bf2004-10-06 22:23:31 +0000664 }
Roland McGrath93817bf2004-10-06 22:23:31 +0000665 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000666 tprintf("}");
667 if (failed)
668 tprintf(" %#lx", (long) start);
669#else
670 tprintf("{...}");
Roland McGrath63d6e542004-10-20 02:17:41 +0000671#endif
Roland McGrath93817bf2004-10-06 22:23:31 +0000672 }
673 tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]);
674 }
675 return 0;
676}
Roland McGrath37b9f842005-05-09 08:02:00 +0000677
678int
679sys_io_setup(tcp)
680struct tcb *tcp;
681{
682 if (entering(tcp))
683 tprintf("%ld, ", tcp->u_arg[0]);
684 else {
685 if (syserror(tcp))
686 tprintf("0x%0lx", tcp->u_arg[1]);
687 else {
688 unsigned long user_id;
689 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
690 tprintf("{%lu}", user_id);
691 else
692 tprintf("{...}");
693 }
694 }
695 return 0;
696}
697
698int
699sys_io_destroy(tcp)
700struct tcb *tcp;
701{
702 if (entering(tcp))
703 tprintf("%lu", tcp->u_arg[0]);
704 return 0;
705}
706
707int
708sys_io_submit(tcp)
709struct tcb *tcp;
710{
711 long nr;
712 if (entering(tcp)) {
713 tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
714 nr = tcp->u_arg[1];
715 /* and if nr is negative? */
716 if (nr == 0)
717 tprintf("{}");
718 else {
719#ifdef HAVE_LIBAIO_H
720 long i;
721 struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2];
722
723 for (i = 0; i < nr; i++, iocbs++) {
724 struct iocb iocb;
725 if (i == 0)
726 tprintf("{");
727 else
728 tprintf(", ");
729
730 if (umove(tcp, (unsigned long)iocbs, &iocbp) ||
731 umove(tcp, (unsigned long)iocbp, &iocb)) {
732 tprintf("{...}");
733 continue;
734 }
735 tprintf("{%p, %u, %hu, %hu, %d}",
736 iocb.data, iocb.key,
737 iocb.aio_lio_opcode,
738 iocb.aio_reqprio, iocb.aio_fildes);
739 }
740 if (i)
741 tprintf("}");
742#else
743 tprintf("{...}");
744#endif
745 }
746 }
747 return 0;
748}
749
750int
751sys_io_cancel(tcp)
752struct tcb *tcp;
753{
754 if (entering(tcp)) {
755#ifdef HAVE_LIBAIO_H
756 struct iocb iocb;
757#endif
758 tprintf("%lu, ", tcp->u_arg[0]);
759#ifdef HAVE_LIBAIO_H
760 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
761 tprintf("{%p, %u, %hu, %hu, %d}, ",
762 iocb.data, iocb.key,
763 iocb.aio_lio_opcode,
764 iocb.aio_reqprio, iocb.aio_fildes);
765 } else
766#endif
767 tprintf("{...}, ");
768 } else {
769 if (tcp->u_rval < 0)
770 tprintf("{...}");
771 else {
772#ifdef HAVE_LIBAIO_H
773 struct io_event event;
774 if (umove(tcp, tcp->u_arg[2], &event) == 0)
775 tprintf("{%p, %p, %ld, %ld}",
776 event.data, event.obj,
777 event.res, event.res2);
778 else
779#endif
780 tprintf("{...}");
781 }
782 }
783 return 0;
784}
785
786int
787sys_io_getevents(tcp)
788struct tcb *tcp;
789{
790 if (entering(tcp)) {
791 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
792 tcp->u_arg[2]);
793 } else {
794 if (tcp->u_rval == 0) {
795 tprintf("{}");
796 } else {
797#ifdef HAVE_LIBAIO_H
798 struct io_event *events = (void *)tcp->u_arg[3];
799 long i, nr = tcp->u_rval;
800
801 for (i = 0; i < nr; i++, events++) {
802 struct io_event event;
803
804 if (i == 0)
805 tprintf("{");
806 else
807 tprintf(", ");
808
809 if (umove(tcp, (unsigned long)events, &event) != 0) {
810 tprintf("{...}");
811 continue;
812 }
813 tprintf("{%p, %p, %ld, %ld}", event.data,
814 event.obj, event.res, event.res2);
815 }
816 tprintf("}, ");
817#else
818 tprintf("{...}");
819#endif
820 }
821
822 if (tcp->u_arg[4] == 0)
823 tprintf("NULL");
824 else {
825 struct timespec to;
826 if (umove(tcp, tcp->u_arg[4], &to) == 0)
827 tprintf("{%lu, %lu}", to.tv_sec, to.tv_nsec);
828 else
829 tprintf("{...}");
830 }
831 }
832 return 0;
833}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000834#endif /* LINUX */
835
836int
837sys_select(tcp)
838struct tcb *tcp;
839{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000840 return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000841}
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000842
843#ifdef LINUX
844int
845sys_pselect6(struct tcb *tcp)
846{
Dmitry V. Levina7945a32006-12-13 17:10:11 +0000847 int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000848 if (exiting(tcp)) {
849 struct {
850 void *ss;
851 unsigned long len;
852 } data;
853 if (umove(tcp, tcp->u_arg[5], &data) < 0)
854 tprintf(", %#lx", tcp->u_arg[5]);
855 else {
856 tprintf(", {");
857 if (data.len < sizeof(sigset_t))
858 tprintf("%#lx", (long)data.ss);
859 else
860 print_sigset(tcp, (long)data.ss, 0);
861 tprintf(", %lu}", data.len);
862 }
863 }
864 return rc;
865}
866#endif