Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1 | /* |
| 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 Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 6 | * 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 McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 37 | #ifdef LINUX |
| 38 | #include <inttypes.h> |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 39 | #endif |
| 40 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 41 | #include <sys/epoll.h> |
| 42 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 43 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 44 | #if HAVE_LONG_LONG_OFF_T |
| 45 | /* |
| 46 | * Hacks for systems that have a long long off_t |
| 47 | */ |
John Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 48 | #define flock64 flock /* Horrid hack */ |
| 49 | #define printflock printflock64 /* Horrider hack */ |
| 50 | #endif |
| 51 | |
| 52 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 53 | static const struct xlat fcntlcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 54 | { F_DUPFD, "F_DUPFD" }, |
| 55 | { F_GETFD, "F_GETFD" }, |
| 56 | { F_SETFD, "F_SETFD" }, |
| 57 | { F_GETFL, "F_GETFL" }, |
| 58 | { F_SETFL, "F_SETFL" }, |
| 59 | { F_GETLK, "F_GETLK" }, |
| 60 | { F_SETLK, "F_SETLK" }, |
| 61 | { F_SETLKW, "F_SETLKW" }, |
| 62 | { F_GETOWN, "F_GETOWN" }, |
| 63 | { F_SETOWN, "F_SETOWN" }, |
| 64 | #ifdef F_RSETLK |
| 65 | { F_RSETLK, "F_RSETLK" }, |
| 66 | #endif |
| 67 | #ifdef F_RSETLKW |
| 68 | { F_RSETLKW, "F_RSETLKW" }, |
| 69 | #endif |
| 70 | #ifdef F_RGETLK |
| 71 | { F_RGETLK, "F_RGETLK" }, |
| 72 | #endif |
| 73 | #ifdef F_CNVT |
| 74 | { F_CNVT, "F_CNVT" }, |
| 75 | #endif |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 76 | #ifdef F_SETSIG |
| 77 | { F_SETSIG, "F_SETSIG" }, |
| 78 | #endif |
| 79 | #ifdef F_GETSIG |
| 80 | { F_GETSIG, "F_GETSIG" }, |
| 81 | #endif |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 82 | #ifdef F_CHKFL |
| 83 | { F_CHKFL, "F_CHKFL" }, |
| 84 | #endif |
| 85 | #ifdef F_DUP2FD |
| 86 | { F_DUP2FD, "F_DUP2FD" }, |
| 87 | #endif |
| 88 | #ifdef F_ALLOCSP |
| 89 | { F_ALLOCSP, "F_ALLOCSP" }, |
| 90 | #endif |
| 91 | #ifdef F_ISSTREAM |
| 92 | { F_ISSTREAM, "F_ISSTREAM" }, |
| 93 | #endif |
| 94 | #ifdef F_PRIV |
| 95 | { F_PRIV, "F_PRIV" }, |
| 96 | #endif |
| 97 | #ifdef F_NPRIV |
| 98 | { F_NPRIV, "F_NPRIV" }, |
| 99 | #endif |
| 100 | #ifdef F_QUOTACL |
| 101 | { F_QUOTACL, "F_QUOTACL" }, |
| 102 | #endif |
| 103 | #ifdef F_BLOCKS |
| 104 | { F_BLOCKS, "F_BLOCKS" }, |
| 105 | #endif |
| 106 | #ifdef F_BLKSIZE |
| 107 | { F_BLKSIZE, "F_BLKSIZE" }, |
| 108 | #endif |
| 109 | #ifdef F_GETOWN |
| 110 | { F_GETOWN, "F_GETOWN" }, |
| 111 | #endif |
| 112 | #ifdef F_SETOWN |
| 113 | { F_SETOWN, "F_SETOWN" }, |
| 114 | #endif |
| 115 | #ifdef F_REVOKE |
| 116 | { F_REVOKE, "F_REVOKE" }, |
| 117 | #endif |
| 118 | #ifdef F_SETLK |
| 119 | { F_SETLK, "F_SETLK" }, |
| 120 | #endif |
| 121 | #ifdef F_SETLKW |
| 122 | { F_SETLKW, "F_SETLKW" }, |
| 123 | #endif |
| 124 | #ifdef F_FREESP |
| 125 | { F_FREESP, "F_FREESP" }, |
| 126 | #endif |
| 127 | #ifdef F_GETLK |
| 128 | { F_GETLK, "F_GETLK" }, |
| 129 | #endif |
| 130 | #ifdef F_SETLK64 |
| 131 | { F_SETLK64, "F_SETLK64" }, |
| 132 | #endif |
| 133 | #ifdef F_SETLKW64 |
| 134 | { F_SETLKW64, "F_SETLKW64" }, |
| 135 | #endif |
| 136 | #ifdef F_FREESP64 |
| 137 | { F_FREESP64, "F_FREESP64" }, |
| 138 | #endif |
| 139 | #ifdef F_GETLK64 |
| 140 | { F_GETLK64, "F_GETLK64" }, |
| 141 | #endif |
| 142 | #ifdef F_SHARE |
| 143 | { F_SHARE, "F_SHARE" }, |
| 144 | #endif |
| 145 | #ifdef F_UNSHARE |
| 146 | { F_UNSHARE, "F_UNSHARE" }, |
| 147 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 148 | { 0, NULL }, |
| 149 | }; |
| 150 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 151 | static const struct xlat fdflags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 152 | #ifdef FD_CLOEXEC |
| 153 | { FD_CLOEXEC, "FD_CLOEXEC" }, |
| 154 | #endif |
| 155 | { 0, NULL }, |
| 156 | }; |
| 157 | |
| 158 | #ifdef LOCK_SH |
| 159 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 160 | static const struct xlat flockcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 161 | { LOCK_SH, "LOCK_SH" }, |
| 162 | { LOCK_EX, "LOCK_EX" }, |
| 163 | { LOCK_NB, "LOCK_NB" }, |
| 164 | { LOCK_UN, "LOCK_UN" }, |
| 165 | { 0, NULL }, |
| 166 | }; |
| 167 | |
| 168 | #endif /* LOCK_SH */ |
| 169 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 170 | static const struct xlat lockfcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 171 | { F_RDLCK, "F_RDLCK" }, |
| 172 | { F_WRLCK, "F_WRLCK" }, |
| 173 | { F_UNLCK, "F_UNLCK" }, |
| 174 | #ifdef F_EXLCK |
| 175 | { F_EXLCK, "F_EXLCK" }, |
| 176 | #endif |
| 177 | #ifdef F_SHLCK |
| 178 | { F_SHLCK, "F_SHLCK" }, |
| 179 | #endif |
| 180 | { 0, NULL }, |
| 181 | }; |
| 182 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 183 | static const struct xlat whence[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 184 | { SEEK_SET, "SEEK_SET" }, |
| 185 | { SEEK_CUR, "SEEK_CUR" }, |
| 186 | { SEEK_END, "SEEK_END" }, |
| 187 | { 0, NULL }, |
| 188 | }; |
| 189 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 190 | #ifndef HAVE_LONG_LONG_OFF_T |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 191 | /* fcntl/lockf */ |
| 192 | static void |
| 193 | printflock(tcp, addr, getlk) |
| 194 | struct tcb *tcp; |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 195 | long addr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 196 | int getlk; |
| 197 | { |
| 198 | struct flock fl; |
| 199 | |
| 200 | if (umove(tcp, addr, &fl) < 0) { |
| 201 | tprintf("{...}"); |
| 202 | return; |
| 203 | } |
| 204 | tprintf("{type="); |
| 205 | printxval(lockfcmds, fl.l_type, "F_???"); |
| 206 | tprintf(", whence="); |
| 207 | printxval(whence, fl.l_whence, "SEEK_???"); |
| 208 | tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len); |
| 209 | if (getlk) |
| 210 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 211 | else |
| 212 | tprintf("}"); |
| 213 | } |
John Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 214 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 215 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 216 | #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 217 | /* fcntl/lockf */ |
| 218 | static void |
| 219 | printflock64(tcp, addr, getlk) |
| 220 | struct tcb *tcp; |
Roland McGrath | 81634e4 | 2003-01-14 07:53:31 +0000 | [diff] [blame] | 221 | long addr; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 222 | int getlk; |
| 223 | { |
| 224 | struct flock64 fl; |
| 225 | |
| 226 | if (umove(tcp, addr, &fl) < 0) { |
| 227 | tprintf("{...}"); |
| 228 | return; |
| 229 | } |
| 230 | tprintf("{type="); |
| 231 | printxval(lockfcmds, fl.l_type, "F_???"); |
| 232 | tprintf(", whence="); |
| 233 | printxval(whence, fl.l_whence, "SEEK_???"); |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 234 | tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 235 | if (getlk) |
| 236 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 237 | else |
| 238 | tprintf("}"); |
| 239 | } |
| 240 | #endif |
| 241 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 242 | static char * |
| 243 | sprintflags(xlat, flags) |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 244 | const struct xlat *xlat; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 245 | int flags; |
| 246 | { |
| 247 | static char outstr[1024]; |
| 248 | char *sep; |
| 249 | |
| 250 | strcpy(outstr, "flags "); |
| 251 | sep = ""; |
| 252 | for (; xlat->str; xlat++) { |
| 253 | if ((flags & xlat->val) == xlat->val) { |
| 254 | sprintf(outstr + strlen(outstr), |
| 255 | "%s%s", sep, xlat->str); |
| 256 | sep = "|"; |
| 257 | flags &= ~xlat->val; |
| 258 | } |
| 259 | } |
| 260 | if (flags) |
| 261 | sprintf(outstr + strlen(outstr), |
| 262 | "%s%#x", sep, flags); |
| 263 | return outstr; |
| 264 | } |
| 265 | |
| 266 | int |
| 267 | sys_fcntl(tcp) |
| 268 | struct tcb *tcp; |
| 269 | { |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 270 | extern const struct xlat openmodes[]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 271 | |
| 272 | if (entering(tcp)) { |
| 273 | tprintf("%ld, ", tcp->u_arg[0]); |
| 274 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 275 | switch (tcp->u_arg[1]) { |
| 276 | case F_SETFD: |
| 277 | tprintf(", "); |
| 278 | if (printflags(fdflags, tcp->u_arg[2]) == 0) |
| 279 | tprintf("0"); |
| 280 | break; |
| 281 | case F_SETOWN: case F_DUPFD: |
| 282 | tprintf(", %ld", tcp->u_arg[2]); |
| 283 | break; |
| 284 | case F_SETFL: |
| 285 | tprintf(", "); |
| 286 | if (printflags(openmodes, tcp->u_arg[2] + 1) == 0) |
| 287 | tprintf("0"); |
| 288 | break; |
| 289 | case F_SETLK: case F_SETLKW: |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 290 | #ifdef F_FREESP |
| 291 | case F_FREESP: |
| 292 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 293 | tprintf(", "); |
| 294 | printflock(tcp, tcp->u_arg[2], 0); |
| 295 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 296 | #if _LFS64_LARGEFILE |
| 297 | #ifdef F_FREESP64 |
| 298 | case F_FREESP64: |
| 299 | #endif |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 300 | /* Linux glibc defines SETLK64 as SETLK, |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 301 | even though the kernel has different values - as does Solaris. */ |
| 302 | #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK |
| 303 | case F_SETLK64: |
| 304 | #endif |
| 305 | #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW |
| 306 | case F_SETLKW64: |
| 307 | #endif |
| 308 | tprintf(", "); |
| 309 | printflock64(tcp, tcp->u_arg[2], 0); |
| 310 | break; |
| 311 | #endif |
| 312 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 313 | } |
| 314 | else { |
| 315 | switch (tcp->u_arg[1]) { |
| 316 | case F_DUPFD: |
| 317 | case F_SETFD: case F_SETFL: |
| 318 | case F_SETLK: case F_SETLKW: |
| 319 | case F_SETOWN: case F_GETOWN: |
| 320 | break; |
| 321 | case F_GETFD: |
| 322 | if (tcp->u_rval == 0) |
| 323 | return 0; |
| 324 | tcp->auxstr = sprintflags(fdflags, tcp->u_rval); |
| 325 | return RVAL_HEX|RVAL_STR; |
| 326 | case F_GETFL: |
| 327 | tcp->auxstr = sprintflags(openmodes, tcp->u_rval + 1); |
| 328 | return RVAL_HEX|RVAL_STR; |
| 329 | case F_GETLK: |
| 330 | tprintf(", "); |
| 331 | printflock(tcp, tcp->u_arg[2], 1); |
| 332 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 333 | #if _LFS64_LARGEFILE |
| 334 | #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK |
| 335 | case F_GETLK64: |
| 336 | #endif |
| 337 | tprintf(", "); |
| 338 | printflock64(tcp, tcp->u_arg[2], 1); |
| 339 | break; |
| 340 | #endif |
| 341 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 342 | tprintf(", %#lx", tcp->u_arg[2]); |
| 343 | break; |
| 344 | } |
| 345 | } |
| 346 | return 0; |
| 347 | } |
| 348 | |
| 349 | #ifdef LOCK_SH |
| 350 | |
| 351 | int |
| 352 | sys_flock(tcp) |
| 353 | struct tcb *tcp; |
| 354 | { |
| 355 | if (entering(tcp)) { |
| 356 | tprintf("%ld, ", tcp->u_arg[0]); |
| 357 | if (!printflags(flockcmds, tcp->u_arg[1])) |
| 358 | tprintf("LOCK_???"); |
| 359 | } |
| 360 | return 0; |
| 361 | } |
| 362 | #endif /* LOCK_SH */ |
| 363 | |
| 364 | int |
| 365 | sys_close(tcp) |
| 366 | struct tcb *tcp; |
| 367 | { |
| 368 | if (entering(tcp)) { |
| 369 | tprintf("%ld", tcp->u_arg[0]); |
| 370 | } |
| 371 | return 0; |
| 372 | } |
| 373 | |
| 374 | int |
| 375 | sys_dup(tcp) |
| 376 | struct tcb *tcp; |
| 377 | { |
| 378 | if (entering(tcp)) { |
| 379 | tprintf("%ld", tcp->u_arg[0]); |
| 380 | } |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | int |
| 385 | sys_dup2(tcp) |
| 386 | struct tcb *tcp; |
| 387 | { |
| 388 | if (entering(tcp)) { |
| 389 | tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]); |
| 390 | } |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | int |
| 395 | sys_getdtablesize(tcp) |
| 396 | struct tcb *tcp; |
| 397 | { |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static int |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 402 | decode_select(tcp, args, bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 403 | struct tcb *tcp; |
| 404 | long *args; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 405 | int bitness; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 406 | { |
| 407 | int i, j, nfds; |
| 408 | fd_set fds; |
| 409 | struct timeval tv; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 410 | #ifdef ALPHA |
| 411 | struct timeval32 { |
| 412 | unsigned tv_sec; |
| 413 | unsigned tv_usec; |
| 414 | } *tv32; |
| 415 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 416 | static char outstr[1024]; |
| 417 | char *sep; |
| 418 | long arg; |
| 419 | |
| 420 | if (entering(tcp)) { |
| 421 | nfds = args[0]; |
| 422 | tprintf("%d", nfds); |
| 423 | for (i = 0; i < 3; i++) { |
| 424 | arg = args[i+1]; |
| 425 | if (arg == 0) { |
| 426 | tprintf(", NULL"); |
| 427 | continue; |
| 428 | } |
| 429 | if (!verbose(tcp)) { |
| 430 | tprintf(", %#lx", arg); |
| 431 | continue; |
| 432 | } |
| 433 | if (umove(tcp, arg, &fds) < 0) { |
| 434 | tprintf(", [?]"); |
| 435 | continue; |
| 436 | } |
| 437 | tprintf(", ["); |
| 438 | for (j = 0, sep = ""; j < nfds; j++) { |
| 439 | if (FD_ISSET(j, &fds)) { |
| 440 | tprintf("%s%u", sep, j); |
| 441 | sep = " "; |
| 442 | } |
| 443 | } |
| 444 | tprintf("]"); |
| 445 | } |
| 446 | if (!args[4]) |
| 447 | tprintf(", NULL"); |
| 448 | else if (!verbose(tcp)) |
| 449 | tprintf(", %#lx", args[4]); |
| 450 | else if (umove(tcp, args[4], &tv) < 0) |
| 451 | tprintf(", {...}"); |
| 452 | else { |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 453 | #ifdef ALPHA |
| 454 | if (bitness) { |
| 455 | tv32=(struct timeval32*)&tv; |
Wichert Akkerman | 221f54f | 1999-11-18 17:26:45 +0000 | [diff] [blame] | 456 | tprintf(", {%u, %u}", tv32->tv_sec, tv32->tv_usec); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 457 | } else |
| 458 | #endif |
| 459 | tprintf(", {%lu, %lu}", |
| 460 | (long) tv.tv_sec, (long) tv.tv_usec); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 461 | } |
| 462 | } |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 463 | else |
| 464 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 465 | unsigned int cumlen = 0; |
| 466 | char *sep = ""; |
| 467 | |
| 468 | if (syserror(tcp)) |
| 469 | return 0; |
| 470 | |
| 471 | if ((nfds = tcp->u_rval) == 0) { |
| 472 | tcp->auxstr = "Timeout"; |
| 473 | return RVAL_STR; |
| 474 | } |
| 475 | outstr[0] = '\0'; |
| 476 | for (i = 0; i < 3; i++) { |
| 477 | int first = 1; |
| 478 | char str[20]; |
| 479 | |
| 480 | tcp->auxstr = outstr; |
| 481 | arg = args[i+1]; |
| 482 | if (!arg || umove(tcp, arg, &fds) < 0) |
| 483 | continue; |
| 484 | for (j = 0; j < args[0]; j++) { |
| 485 | if (FD_ISSET(j, &fds)) { |
| 486 | if (first) { |
| 487 | sprintf(str, "%s%s [%u", sep, |
| 488 | i == 0 ? "in" : |
| 489 | i == 1 ? "out" : |
| 490 | "except", j); |
| 491 | first = 0; |
| 492 | sep = ", "; |
| 493 | } |
| 494 | else |
| 495 | sprintf(str, " %u", j); |
| 496 | cumlen += strlen(str); |
| 497 | if (cumlen < sizeof(outstr)) |
| 498 | strcat(outstr, str); |
| 499 | nfds--; |
| 500 | } |
| 501 | } |
| 502 | if (cumlen) |
| 503 | strcat(outstr, "]"); |
| 504 | if (nfds == 0) |
| 505 | break; |
| 506 | } |
| 507 | #ifdef LINUX |
| 508 | /* This contains no useful information on SunOS. */ |
| 509 | if (args[4]) { |
| 510 | char str[20]; |
| 511 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 512 | if (umove(tcp, args[4], &tv) >= 0) { |
| 513 | #ifdef ALPHA |
| 514 | if (bitness) { |
| 515 | tv32=(struct timeval32*)&tv; |
| 516 | sprintf(str, "%sleft {%u, %u}", sep, |
| 517 | tv32->tv_sec, tv32->tv_usec); |
| 518 | } else |
| 519 | #endif |
| 520 | sprintf(str, "%sleft {%lu, %lu}", sep, |
| 521 | (long) tv.tv_sec, (long) tv.tv_usec); |
| 522 | |
| 523 | if ((cumlen += strlen(str)) < sizeof(outstr)) |
| 524 | strcat(outstr, str); |
| 525 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 526 | } |
| 527 | #endif /* LINUX */ |
| 528 | return RVAL_STR; |
| 529 | } |
| 530 | return 0; |
| 531 | } |
| 532 | |
| 533 | #ifdef LINUX |
| 534 | |
| 535 | int |
| 536 | sys_oldselect(tcp) |
| 537 | struct tcb *tcp; |
| 538 | { |
| 539 | long args[5]; |
| 540 | |
| 541 | if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) { |
| 542 | tprintf("[...]"); |
| 543 | return 0; |
| 544 | } |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 545 | return decode_select(tcp, args, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 546 | } |
| 547 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 548 | #ifdef ALPHA |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 549 | int |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 550 | sys_osf_select(tcp) |
| 551 | struct tcb *tcp; |
| 552 | { |
| 553 | long *args = tcp->u_arg; |
| 554 | return decode_select(tcp, args, 1); |
| 555 | } |
| 556 | #endif |
| 557 | |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 558 | static struct xlat epollctls[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 559 | #ifdef EPOLL_CTL_ADD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 560 | { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 561 | #endif |
| 562 | #ifdef EPOLL_CTL_MOD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 563 | { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 564 | #endif |
| 565 | #ifdef EPOLL_CTL_DEL |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 566 | { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 567 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 568 | { 0, NULL } |
| 569 | }; |
| 570 | |
| 571 | static struct xlat epollevents[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 572 | #ifdef EPOLLIN |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 573 | { EPOLLIN, "EPOLLIN" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 574 | #endif |
| 575 | #ifdef EPOLLPRI |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 576 | { EPOLLPRI, "EPOLLPRI" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 577 | #endif |
| 578 | #ifdef EPOLLOUT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 579 | { EPOLLOUT, "EPOLLOUT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 580 | #endif |
| 581 | #ifdef EPOLLRDNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 582 | { EPOLLRDNORM, "EPOLLRDNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 583 | #endif |
| 584 | #ifdef EPOLLRDBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 585 | { EPOLLRDBAND, "EPOLLRDBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 586 | #endif |
| 587 | #ifdef EPOLLWRNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 588 | { EPOLLWRNORM, "EPOLLWRNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 589 | #endif |
| 590 | #ifdef EPOLLWRBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 591 | { EPOLLWRBAND, "EPOLLWRBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 592 | #endif |
| 593 | #ifdef EPOLLMSG |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 594 | { EPOLLMSG, "EPOLLMSG" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 595 | #endif |
| 596 | #ifdef EPOLLERR |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 597 | { EPOLLERR, "EPOLLERR" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 598 | #endif |
| 599 | #ifdef EPOLLHUP |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 600 | { EPOLLHUP, "EPOLLHUP" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 601 | #endif |
| 602 | #ifdef EPOLLONESHOT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 603 | { EPOLLONESHOT, "EPOLLONESHOT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 604 | #endif |
| 605 | #ifdef EPOLLET |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 606 | { EPOLLET, "EPOLLET" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 607 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 608 | { 0, NULL } |
| 609 | }; |
| 610 | |
| 611 | int |
| 612 | sys_epoll_create(tcp) |
| 613 | struct tcb *tcp; |
| 614 | { |
| 615 | if (entering(tcp)) |
| 616 | tprintf("%ld", tcp->u_arg[0]); |
| 617 | return 0; |
| 618 | } |
| 619 | |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 620 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 621 | static void |
| 622 | print_epoll_event(ev) |
| 623 | struct epoll_event *ev; |
| 624 | { |
| 625 | tprintf("{"); |
| 626 | if (printflags(epollevents, ev->events) == 0) |
| 627 | tprintf("0"); |
| 628 | /* We cannot know what format the program uses, so print u32 and u64 |
| 629 | which will cover every value. */ |
| 630 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 631 | ev->data.u32, ev->data.u64); |
| 632 | } |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 633 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 634 | |
| 635 | int |
| 636 | sys_epoll_ctl(tcp) |
| 637 | struct tcb *tcp; |
| 638 | { |
| 639 | if (entering(tcp)) { |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 640 | tprintf("%ld, ", tcp->u_arg[0]); |
| 641 | printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???"); |
| 642 | tprintf(", %ld, ", tcp->u_arg[2]); |
| 643 | if (tcp->u_arg[3] == 0) |
| 644 | tprintf("NULL"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 645 | else { |
| 646 | #ifdef HAVE_SYS_EPOLL_H |
| 647 | struct epoll_event ev; |
Roland McGrath | 6e52d23 | 2004-10-20 02:17:41 +0000 | [diff] [blame^] | 648 | if (umove(tcp, tcp->u_arg[3], &ev) == 0) |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 649 | print_epoll_event(&ev); |
| 650 | else |
| 651 | #endif |
| 652 | tprintf("{...}"); |
| 653 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 654 | } |
| 655 | return 0; |
| 656 | } |
| 657 | |
| 658 | int |
| 659 | sys_epoll_wait(tcp) |
| 660 | struct tcb *tcp; |
| 661 | { |
| 662 | if (entering(tcp)) |
| 663 | tprintf("%ld, ", tcp->u_arg[0]); |
| 664 | else { |
| 665 | if (syserror(tcp)) |
| 666 | tprintf("%lx", tcp->u_arg[1]); |
| 667 | else if (tcp->u_rval == 0) |
| 668 | tprintf("{}"); |
| 669 | else { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 670 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 671 | struct epoll_event evs[tcp->u_rval]; |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 672 | if (umove(tcp, tcp->u_arg[1], evs) == 0) { |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 673 | unsigned long i; |
| 674 | tprintf("{"); |
| 675 | for (i = 0; i < tcp->u_rval; ++i) { |
| 676 | if (i > 0) |
| 677 | tprintf(", "); |
| 678 | print_epoll_event(&evs[i]); |
| 679 | } |
| 680 | tprintf("}"); |
| 681 | } |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 682 | else |
| 683 | #endif |
| 684 | tprintf("{...}"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 685 | } |
| 686 | tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]); |
| 687 | } |
| 688 | return 0; |
| 689 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 690 | #endif /* LINUX */ |
| 691 | |
| 692 | int |
| 693 | sys_select(tcp) |
| 694 | struct tcb *tcp; |
| 695 | { |
| 696 | long *args = tcp->u_arg; |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 697 | return decode_select(tcp, args, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 698 | } |