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 |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 43 | #ifdef HAVE_LIBAIO_H |
| 44 | #include <libaio.h> |
| 45 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 46 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 47 | #if HAVE_LONG_LONG_OFF_T |
| 48 | /* |
| 49 | * Hacks for systems that have a long long off_t |
| 50 | */ |
John Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 51 | #define flock64 flock /* Horrid hack */ |
| 52 | #define printflock printflock64 /* Horrider hack */ |
| 53 | #endif |
| 54 | |
| 55 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 56 | static const struct xlat fcntlcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 57 | { 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 Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 79 | #ifdef F_SETSIG |
| 80 | { F_SETSIG, "F_SETSIG" }, |
| 81 | #endif |
| 82 | #ifdef F_GETSIG |
| 83 | { F_GETSIG, "F_GETSIG" }, |
| 84 | #endif |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 85 | #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 Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 151 | { 0, NULL }, |
| 152 | }; |
| 153 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 154 | static const struct xlat fdflags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 155 | #ifdef FD_CLOEXEC |
| 156 | { FD_CLOEXEC, "FD_CLOEXEC" }, |
| 157 | #endif |
| 158 | { 0, NULL }, |
| 159 | }; |
| 160 | |
| 161 | #ifdef LOCK_SH |
| 162 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 163 | static const struct xlat flockcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 164 | { 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 McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 173 | static const struct xlat lockfcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 174 | { 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 McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 186 | static const struct xlat whence[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 187 | { SEEK_SET, "SEEK_SET" }, |
| 188 | { SEEK_CUR, "SEEK_CUR" }, |
| 189 | { SEEK_END, "SEEK_END" }, |
| 190 | { 0, NULL }, |
| 191 | }; |
| 192 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 193 | #ifndef HAVE_LONG_LONG_OFF_T |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 194 | /* fcntl/lockf */ |
| 195 | static void |
| 196 | printflock(tcp, addr, getlk) |
| 197 | struct tcb *tcp; |
Wichert Akkerman | 8b1b40c | 2000-02-03 21:58:30 +0000 | [diff] [blame] | 198 | long addr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 199 | int 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 Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 217 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 218 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 219 | #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 220 | /* fcntl/lockf */ |
| 221 | static void |
| 222 | printflock64(tcp, addr, getlk) |
| 223 | struct tcb *tcp; |
Roland McGrath | 81634e4 | 2003-01-14 07:53:31 +0000 | [diff] [blame] | 224 | long addr; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 225 | int 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 Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 237 | 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] | 238 | if (getlk) |
| 239 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 240 | else |
| 241 | tprintf("}"); |
| 242 | } |
| 243 | #endif |
| 244 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 245 | extern const struct xlat open_mode_flags[]; |
| 246 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 247 | /* |
| 248 | * low bits of the open(2) flags define access mode, |
| 249 | * other bits are real flags. |
| 250 | */ |
| 251 | static const char * |
| 252 | sprint_open_modes(mode_t flags) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 253 | { |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 254 | extern const struct xlat open_access_modes[]; |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 255 | static char outstr[1024]; |
| 256 | const char *str = xlookup(open_access_modes, flags & 3); |
| 257 | const char *sep = ""; |
| 258 | const struct xlat *x; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 259 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 260 | strcpy(outstr, "flags "); |
| 261 | if (str) |
| 262 | { |
| 263 | strcat(outstr, str); |
| 264 | flags &= ~3; |
| 265 | if (!flags) |
| 266 | return outstr; |
| 267 | strcat(outstr, "|"); |
| 268 | } |
| 269 | |
| 270 | for (x = open_mode_flags; x->str; x++) |
| 271 | { |
| 272 | if ((flags & x->val) == x->val) |
| 273 | { |
| 274 | sprintf(outstr + strlen(outstr), |
| 275 | "%s%s", sep, x->str); |
| 276 | sep = "|"; |
| 277 | flags &= ~x->val; |
| 278 | } |
| 279 | } |
| 280 | if (flags) |
| 281 | sprintf(outstr + strlen(outstr), "%s%#x", sep, flags); |
| 282 | return outstr; |
| 283 | } |
| 284 | |
| 285 | int |
| 286 | sys_fcntl(struct tcb *tcp) |
| 287 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 288 | if (entering(tcp)) { |
| 289 | tprintf("%ld, ", tcp->u_arg[0]); |
| 290 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 291 | switch (tcp->u_arg[1]) { |
| 292 | case F_SETFD: |
| 293 | tprintf(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 294 | printflags(fdflags, tcp->u_arg[2], "FD_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 295 | break; |
| 296 | case F_SETOWN: case F_DUPFD: |
| 297 | tprintf(", %ld", tcp->u_arg[2]); |
| 298 | break; |
| 299 | case F_SETFL: |
| 300 | tprintf(", "); |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 301 | tprint_open_modes(tcp, tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 302 | break; |
| 303 | case F_SETLK: case F_SETLKW: |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 304 | #ifdef F_FREESP |
| 305 | case F_FREESP: |
| 306 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 307 | tprintf(", "); |
| 308 | printflock(tcp, tcp->u_arg[2], 0); |
| 309 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 310 | #if _LFS64_LARGEFILE |
| 311 | #ifdef F_FREESP64 |
| 312 | case F_FREESP64: |
| 313 | #endif |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 314 | /* Linux glibc defines SETLK64 as SETLK, |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 315 | even though the kernel has different values - as does Solaris. */ |
| 316 | #if defined(F_SETLK64) && F_SETLK64+0!=F_SETLK |
| 317 | case F_SETLK64: |
| 318 | #endif |
| 319 | #if defined(F_SETLKW64) && F_SETLKW64+0!=F_SETLKW |
| 320 | case F_SETLKW64: |
| 321 | #endif |
| 322 | tprintf(", "); |
| 323 | printflock64(tcp, tcp->u_arg[2], 0); |
| 324 | break; |
| 325 | #endif |
| 326 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 327 | } |
| 328 | else { |
| 329 | switch (tcp->u_arg[1]) { |
| 330 | case F_DUPFD: |
| 331 | case F_SETFD: case F_SETFL: |
| 332 | case F_SETLK: case F_SETLKW: |
| 333 | case F_SETOWN: case F_GETOWN: |
| 334 | break; |
| 335 | case F_GETFD: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 336 | if (syserror(tcp) || tcp->u_rval == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 337 | return 0; |
Roland McGrath | a6c0d8c | 2007-11-01 21:46:22 +0000 | [diff] [blame] | 338 | tcp->auxstr = |
| 339 | sprintflags("flags ", fdflags, tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 340 | return RVAL_HEX|RVAL_STR; |
| 341 | case F_GETFL: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 342 | if (syserror(tcp)) |
| 343 | return 0; |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 344 | tcp->auxstr = sprint_open_modes(tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 345 | return RVAL_HEX|RVAL_STR; |
| 346 | case F_GETLK: |
| 347 | tprintf(", "); |
| 348 | printflock(tcp, tcp->u_arg[2], 1); |
| 349 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 350 | #if _LFS64_LARGEFILE |
| 351 | #if defined(F_GETLK64) && F_GETLK64+0!=F_GETLK |
| 352 | case F_GETLK64: |
| 353 | #endif |
| 354 | tprintf(", "); |
| 355 | printflock64(tcp, tcp->u_arg[2], 1); |
| 356 | break; |
| 357 | #endif |
| 358 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 359 | tprintf(", %#lx", tcp->u_arg[2]); |
| 360 | break; |
| 361 | } |
| 362 | } |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | #ifdef LOCK_SH |
| 367 | |
| 368 | int |
| 369 | sys_flock(tcp) |
| 370 | struct tcb *tcp; |
| 371 | { |
| 372 | if (entering(tcp)) { |
| 373 | tprintf("%ld, ", tcp->u_arg[0]); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 374 | printflags(flockcmds, tcp->u_arg[1], "LOCK_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 375 | } |
| 376 | return 0; |
| 377 | } |
| 378 | #endif /* LOCK_SH */ |
| 379 | |
| 380 | int |
| 381 | sys_close(tcp) |
| 382 | struct tcb *tcp; |
| 383 | { |
| 384 | if (entering(tcp)) { |
| 385 | tprintf("%ld", tcp->u_arg[0]); |
| 386 | } |
| 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | int |
| 391 | sys_dup(tcp) |
| 392 | struct tcb *tcp; |
| 393 | { |
| 394 | if (entering(tcp)) { |
| 395 | tprintf("%ld", tcp->u_arg[0]); |
| 396 | } |
| 397 | return 0; |
| 398 | } |
| 399 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 400 | static int |
| 401 | do_dup2(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 402 | { |
| 403 | if (entering(tcp)) { |
| 404 | tprintf("%ld, %ld", tcp->u_arg[0], tcp->u_arg[1]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 405 | if (flags_arg >= 0) { |
| 406 | tprintf(", "); |
| 407 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 408 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 409 | } |
| 410 | return 0; |
| 411 | } |
| 412 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 413 | int |
| 414 | sys_dup2(struct tcb *tcp) |
| 415 | { |
| 416 | return do_dup2(tcp, -1); |
| 417 | } |
| 418 | |
| 419 | #ifdef LINUX |
| 420 | int |
| 421 | sys_dup3(struct tcb *tcp) |
| 422 | { |
| 423 | return do_dup2(tcp, 2); |
| 424 | } |
| 425 | #endif |
| 426 | |
Dmitry V. Levin | b9fe011 | 2006-12-13 16:59:44 +0000 | [diff] [blame] | 427 | #if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 428 | int |
| 429 | sys_getdtablesize(tcp) |
| 430 | struct tcb *tcp; |
| 431 | { |
| 432 | return 0; |
| 433 | } |
Dmitry V. Levin | b9fe011 | 2006-12-13 16:59:44 +0000 | [diff] [blame] | 434 | #endif /* ALPHA || FREEBSD || SUNOS4 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 435 | |
| 436 | static int |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 437 | decode_select(struct tcb *tcp, long *args, enum bitness_t bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 438 | { |
| 439 | int i, j, nfds; |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 440 | unsigned int fdsize = ((((args[0] + 7) / 8) + sizeof(long) - 1) |
| 441 | & -sizeof(long)); |
| 442 | fd_set *fds; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 443 | static char outstr[1024]; |
| 444 | char *sep; |
| 445 | long arg; |
| 446 | |
| 447 | if (entering(tcp)) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 448 | fds = (fd_set *) malloc(fdsize); |
Roland McGrath | 46100d0 | 2005-06-01 18:55:42 +0000 | [diff] [blame] | 449 | if (fds == NULL) |
| 450 | fprintf(stderr, "out of memory\n"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 451 | nfds = args[0]; |
| 452 | tprintf("%d", nfds); |
| 453 | for (i = 0; i < 3; i++) { |
| 454 | arg = args[i+1]; |
| 455 | if (arg == 0) { |
| 456 | tprintf(", NULL"); |
| 457 | continue; |
| 458 | } |
Roland McGrath | 46100d0 | 2005-06-01 18:55:42 +0000 | [diff] [blame] | 459 | if (fds == NULL || !verbose(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 460 | tprintf(", %#lx", arg); |
| 461 | continue; |
| 462 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 463 | if (umoven(tcp, arg, fdsize, (char *) fds) < 0) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 464 | tprintf(", [?]"); |
| 465 | continue; |
| 466 | } |
| 467 | tprintf(", ["); |
| 468 | for (j = 0, sep = ""; j < nfds; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 469 | if (FD_ISSET(j, fds)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 470 | tprintf("%s%u", sep, j); |
| 471 | sep = " "; |
| 472 | } |
| 473 | } |
| 474 | tprintf("]"); |
| 475 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 476 | free(fds); |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 477 | tprintf(", "); |
Roland McGrath | 6afc565 | 2007-07-24 01:57:11 +0000 | [diff] [blame] | 478 | printtv_bitness(tcp, args[4], bitness, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 479 | } |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 480 | else |
| 481 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 482 | unsigned int cumlen = 0; |
| 483 | char *sep = ""; |
| 484 | |
| 485 | if (syserror(tcp)) |
| 486 | return 0; |
| 487 | |
| 488 | if ((nfds = tcp->u_rval) == 0) { |
| 489 | tcp->auxstr = "Timeout"; |
| 490 | return RVAL_STR; |
| 491 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 492 | |
| 493 | fds = (fd_set *) malloc(fdsize); |
Roland McGrath | 46100d0 | 2005-06-01 18:55:42 +0000 | [diff] [blame] | 494 | if (fds == NULL) |
| 495 | fprintf(stderr, "out of memory\n"); |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 496 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 497 | outstr[0] = '\0'; |
| 498 | for (i = 0; i < 3; i++) { |
| 499 | int first = 1; |
| 500 | char str[20]; |
| 501 | |
| 502 | tcp->auxstr = outstr; |
| 503 | arg = args[i+1]; |
Roland McGrath | 46100d0 | 2005-06-01 18:55:42 +0000 | [diff] [blame] | 504 | if (fds == NULL || !arg || |
| 505 | umoven(tcp, arg, fdsize, (char *) fds) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 506 | continue; |
| 507 | for (j = 0; j < args[0]; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 508 | if (FD_ISSET(j, fds)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 509 | if (first) { |
| 510 | sprintf(str, "%s%s [%u", sep, |
| 511 | i == 0 ? "in" : |
| 512 | i == 1 ? "out" : |
| 513 | "except", j); |
| 514 | first = 0; |
| 515 | sep = ", "; |
| 516 | } |
| 517 | else |
| 518 | sprintf(str, " %u", j); |
| 519 | cumlen += strlen(str); |
| 520 | if (cumlen < sizeof(outstr)) |
| 521 | strcat(outstr, str); |
| 522 | nfds--; |
| 523 | } |
| 524 | } |
| 525 | if (cumlen) |
| 526 | strcat(outstr, "]"); |
| 527 | if (nfds == 0) |
| 528 | break; |
| 529 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 530 | free(fds); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 531 | #ifdef LINUX |
| 532 | /* This contains no useful information on SunOS. */ |
| 533 | if (args[4]) { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 534 | char str[128]; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 535 | |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 536 | sprintf(str, "%sleft ", sep); |
| 537 | sprinttv(tcp, args[4], bitness, str + strlen(str)); |
| 538 | if ((cumlen += strlen(str)) < sizeof(outstr)) |
| 539 | strcat(outstr, str); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 540 | } |
| 541 | #endif /* LINUX */ |
| 542 | return RVAL_STR; |
| 543 | } |
| 544 | return 0; |
| 545 | } |
| 546 | |
| 547 | #ifdef LINUX |
| 548 | |
| 549 | int |
| 550 | sys_oldselect(tcp) |
| 551 | struct tcb *tcp; |
| 552 | { |
| 553 | long args[5]; |
| 554 | |
| 555 | if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) { |
| 556 | tprintf("[...]"); |
| 557 | return 0; |
| 558 | } |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 559 | return decode_select(tcp, args, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 560 | } |
| 561 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 562 | #ifdef ALPHA |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 563 | int |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 564 | sys_osf_select(tcp) |
| 565 | struct tcb *tcp; |
| 566 | { |
| 567 | long *args = tcp->u_arg; |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 568 | return decode_select(tcp, args, BITNESS_32); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 569 | } |
| 570 | #endif |
| 571 | |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 572 | static struct xlat epollctls[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 573 | #ifdef EPOLL_CTL_ADD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 574 | { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 575 | #endif |
| 576 | #ifdef EPOLL_CTL_MOD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 577 | { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 578 | #endif |
| 579 | #ifdef EPOLL_CTL_DEL |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 580 | { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 581 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 582 | { 0, NULL } |
| 583 | }; |
| 584 | |
| 585 | static struct xlat epollevents[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 586 | #ifdef EPOLLIN |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 587 | { EPOLLIN, "EPOLLIN" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 588 | #endif |
| 589 | #ifdef EPOLLPRI |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 590 | { EPOLLPRI, "EPOLLPRI" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 591 | #endif |
| 592 | #ifdef EPOLLOUT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 593 | { EPOLLOUT, "EPOLLOUT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 594 | #endif |
| 595 | #ifdef EPOLLRDNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 596 | { EPOLLRDNORM, "EPOLLRDNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 597 | #endif |
| 598 | #ifdef EPOLLRDBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 599 | { EPOLLRDBAND, "EPOLLRDBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 600 | #endif |
| 601 | #ifdef EPOLLWRNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 602 | { EPOLLWRNORM, "EPOLLWRNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 603 | #endif |
| 604 | #ifdef EPOLLWRBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 605 | { EPOLLWRBAND, "EPOLLWRBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 606 | #endif |
| 607 | #ifdef EPOLLMSG |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 608 | { EPOLLMSG, "EPOLLMSG" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 609 | #endif |
| 610 | #ifdef EPOLLERR |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 611 | { EPOLLERR, "EPOLLERR" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 612 | #endif |
| 613 | #ifdef EPOLLHUP |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 614 | { EPOLLHUP, "EPOLLHUP" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 615 | #endif |
| 616 | #ifdef EPOLLONESHOT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 617 | { EPOLLONESHOT, "EPOLLONESHOT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 618 | #endif |
| 619 | #ifdef EPOLLET |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 620 | { EPOLLET, "EPOLLET" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 621 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 622 | { 0, NULL } |
| 623 | }; |
| 624 | |
| 625 | int |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 626 | sys_epoll_create(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 627 | { |
| 628 | if (entering(tcp)) |
| 629 | tprintf("%ld", tcp->u_arg[0]); |
| 630 | return 0; |
| 631 | } |
| 632 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 633 | int |
| 634 | sys_epoll_create1(struct tcb *tcp) |
| 635 | { |
| 636 | if (entering(tcp)) |
| 637 | printflags(open_mode_flags, tcp->u_arg[0], "O_???"); |
| 638 | return 0; |
| 639 | } |
| 640 | |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 641 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 642 | static void |
| 643 | print_epoll_event(ev) |
| 644 | struct epoll_event *ev; |
| 645 | { |
| 646 | tprintf("{"); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 647 | printflags(epollevents, ev->events, "EPOLL???"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 648 | /* We cannot know what format the program uses, so print u32 and u64 |
| 649 | which will cover every value. */ |
| 650 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 651 | ev->data.u32, ev->data.u64); |
| 652 | } |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 653 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 654 | |
| 655 | int |
| 656 | sys_epoll_ctl(tcp) |
| 657 | struct tcb *tcp; |
| 658 | { |
| 659 | if (entering(tcp)) { |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 660 | tprintf("%ld, ", tcp->u_arg[0]); |
| 661 | printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???"); |
| 662 | tprintf(", %ld, ", tcp->u_arg[2]); |
| 663 | if (tcp->u_arg[3] == 0) |
| 664 | tprintf("NULL"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 665 | else { |
| 666 | #ifdef HAVE_SYS_EPOLL_H |
| 667 | struct epoll_event ev; |
Roland McGrath | 6e52d23 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 668 | if (umove(tcp, tcp->u_arg[3], &ev) == 0) |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 669 | print_epoll_event(&ev); |
| 670 | else |
| 671 | #endif |
| 672 | tprintf("{...}"); |
| 673 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 674 | } |
| 675 | return 0; |
| 676 | } |
| 677 | |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 678 | static void |
| 679 | epoll_wait_common(tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 680 | struct tcb *tcp; |
| 681 | { |
| 682 | if (entering(tcp)) |
| 683 | tprintf("%ld, ", tcp->u_arg[0]); |
| 684 | else { |
| 685 | if (syserror(tcp)) |
| 686 | tprintf("%lx", tcp->u_arg[1]); |
| 687 | else if (tcp->u_rval == 0) |
| 688 | tprintf("{}"); |
| 689 | else { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 690 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 691 | struct epoll_event ev, *start, *cur, *end; |
| 692 | int failed = 0; |
| 693 | |
| 694 | tprintf("{"); |
| 695 | start = (struct epoll_event *) tcp->u_arg[1]; |
| 696 | end = start + tcp->u_rval; |
| 697 | for (cur = start; cur < end; ++cur) { |
| 698 | if (cur > start) |
| 699 | tprintf(", "); |
| 700 | if (umove(tcp, (long) cur, &ev) == 0) |
| 701 | print_epoll_event(&ev); |
| 702 | else { |
| 703 | tprintf("?"); |
| 704 | failed = 1; |
| 705 | break; |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 706 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 707 | } |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 708 | tprintf("}"); |
| 709 | if (failed) |
| 710 | tprintf(" %#lx", (long) start); |
| 711 | #else |
| 712 | tprintf("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 713 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 714 | } |
| 715 | tprintf(", %ld, %ld", tcp->u_arg[2], tcp->u_arg[3]); |
| 716 | } |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | int |
| 720 | sys_epoll_wait(tcp) |
| 721 | struct tcb *tcp; |
| 722 | { |
| 723 | epoll_wait_common(tcp); |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | int |
| 728 | sys_epoll_pwait(tcp) |
| 729 | struct tcb *tcp; |
| 730 | { |
| 731 | epoll_wait_common(tcp); |
| 732 | if (exiting(tcp)) |
| 733 | print_sigset(tcp, tcp->u_arg[4], 0); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 734 | return 0; |
| 735 | } |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 736 | |
| 737 | int |
| 738 | sys_io_setup(tcp) |
| 739 | struct tcb *tcp; |
| 740 | { |
| 741 | if (entering(tcp)) |
| 742 | tprintf("%ld, ", tcp->u_arg[0]); |
| 743 | else { |
| 744 | if (syserror(tcp)) |
| 745 | tprintf("0x%0lx", tcp->u_arg[1]); |
| 746 | else { |
| 747 | unsigned long user_id; |
| 748 | if (umove(tcp, tcp->u_arg[1], &user_id) == 0) |
| 749 | tprintf("{%lu}", user_id); |
| 750 | else |
| 751 | tprintf("{...}"); |
| 752 | } |
| 753 | } |
| 754 | return 0; |
| 755 | } |
| 756 | |
| 757 | int |
| 758 | sys_io_destroy(tcp) |
| 759 | struct tcb *tcp; |
| 760 | { |
| 761 | if (entering(tcp)) |
| 762 | tprintf("%lu", tcp->u_arg[0]); |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | int |
| 767 | sys_io_submit(tcp) |
| 768 | struct tcb *tcp; |
| 769 | { |
| 770 | long nr; |
| 771 | if (entering(tcp)) { |
| 772 | tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 773 | nr = tcp->u_arg[1]; |
| 774 | /* and if nr is negative? */ |
| 775 | if (nr == 0) |
| 776 | tprintf("{}"); |
| 777 | else { |
| 778 | #ifdef HAVE_LIBAIO_H |
| 779 | long i; |
| 780 | struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2]; |
| 781 | |
| 782 | for (i = 0; i < nr; i++, iocbs++) { |
| 783 | struct iocb iocb; |
| 784 | if (i == 0) |
| 785 | tprintf("{"); |
| 786 | else |
| 787 | tprintf(", "); |
| 788 | |
| 789 | if (umove(tcp, (unsigned long)iocbs, &iocbp) || |
| 790 | umove(tcp, (unsigned long)iocbp, &iocb)) { |
| 791 | tprintf("{...}"); |
| 792 | continue; |
| 793 | } |
| 794 | tprintf("{%p, %u, %hu, %hu, %d}", |
| 795 | iocb.data, iocb.key, |
| 796 | iocb.aio_lio_opcode, |
| 797 | iocb.aio_reqprio, iocb.aio_fildes); |
| 798 | } |
| 799 | if (i) |
| 800 | tprintf("}"); |
| 801 | #else |
| 802 | tprintf("{...}"); |
| 803 | #endif |
| 804 | } |
| 805 | } |
| 806 | return 0; |
| 807 | } |
| 808 | |
| 809 | int |
| 810 | sys_io_cancel(tcp) |
| 811 | struct tcb *tcp; |
| 812 | { |
| 813 | if (entering(tcp)) { |
| 814 | #ifdef HAVE_LIBAIO_H |
| 815 | struct iocb iocb; |
| 816 | #endif |
| 817 | tprintf("%lu, ", tcp->u_arg[0]); |
| 818 | #ifdef HAVE_LIBAIO_H |
| 819 | if (umove(tcp, tcp->u_arg[1], &iocb) == 0) { |
| 820 | tprintf("{%p, %u, %hu, %hu, %d}, ", |
| 821 | iocb.data, iocb.key, |
| 822 | iocb.aio_lio_opcode, |
| 823 | iocb.aio_reqprio, iocb.aio_fildes); |
| 824 | } else |
| 825 | #endif |
| 826 | tprintf("{...}, "); |
| 827 | } else { |
| 828 | if (tcp->u_rval < 0) |
| 829 | tprintf("{...}"); |
| 830 | else { |
| 831 | #ifdef HAVE_LIBAIO_H |
| 832 | struct io_event event; |
| 833 | if (umove(tcp, tcp->u_arg[2], &event) == 0) |
| 834 | tprintf("{%p, %p, %ld, %ld}", |
| 835 | event.data, event.obj, |
| 836 | event.res, event.res2); |
| 837 | else |
| 838 | #endif |
| 839 | tprintf("{...}"); |
| 840 | } |
| 841 | } |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | int |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 846 | sys_io_getevents(struct tcb * tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 847 | { |
| 848 | if (entering(tcp)) { |
| 849 | tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1], |
| 850 | tcp->u_arg[2]); |
| 851 | } else { |
| 852 | if (tcp->u_rval == 0) { |
| 853 | tprintf("{}"); |
| 854 | } else { |
| 855 | #ifdef HAVE_LIBAIO_H |
| 856 | struct io_event *events = (void *)tcp->u_arg[3]; |
| 857 | long i, nr = tcp->u_rval; |
| 858 | |
| 859 | for (i = 0; i < nr; i++, events++) { |
| 860 | struct io_event event; |
| 861 | |
| 862 | if (i == 0) |
| 863 | tprintf("{"); |
| 864 | else |
| 865 | tprintf(", "); |
| 866 | |
| 867 | if (umove(tcp, (unsigned long)events, &event) != 0) { |
| 868 | tprintf("{...}"); |
| 869 | continue; |
| 870 | } |
| 871 | tprintf("{%p, %p, %ld, %ld}", event.data, |
| 872 | event.obj, event.res, event.res2); |
| 873 | } |
| 874 | tprintf("}, "); |
| 875 | #else |
| 876 | tprintf("{...}"); |
| 877 | #endif |
| 878 | } |
| 879 | |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 880 | print_timespec(tcp, tcp->u_arg[4]); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 881 | } |
| 882 | return 0; |
| 883 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 884 | #endif /* LINUX */ |
| 885 | |
| 886 | int |
| 887 | sys_select(tcp) |
| 888 | struct tcb *tcp; |
| 889 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 890 | return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 891 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 892 | |
| 893 | #ifdef LINUX |
| 894 | int |
| 895 | sys_pselect6(struct tcb *tcp) |
| 896 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 897 | int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 898 | if (entering(tcp)) { |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 899 | struct { |
| 900 | void *ss; |
| 901 | unsigned long len; |
| 902 | } data; |
| 903 | if (umove(tcp, tcp->u_arg[5], &data) < 0) |
| 904 | tprintf(", %#lx", tcp->u_arg[5]); |
| 905 | else { |
| 906 | tprintf(", {"); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 907 | if (data.len < sizeof(long)) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 908 | tprintf("%#lx", (long)data.ss); |
| 909 | else |
| 910 | print_sigset(tcp, (long)data.ss, 0); |
| 911 | tprintf(", %lu}", data.len); |
| 912 | } |
| 913 | } |
| 914 | return rc; |
| 915 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 916 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 917 | static int |
| 918 | do_eventfd(struct tcb *tcp, int flags_arg) |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 919 | { |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 920 | if (entering(tcp)) { |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 921 | tprintf("%lu", tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 922 | if (flags_arg >= 0) { |
| 923 | tprintf(", "); |
| 924 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 925 | } |
| 926 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 927 | return 0; |
| 928 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame^] | 929 | |
| 930 | int |
| 931 | sys_eventfd(struct tcb *tcp) |
| 932 | { |
| 933 | return do_eventfd(tcp, -1); |
| 934 | } |
| 935 | |
| 936 | int |
| 937 | sys_eventfd2(struct tcb *tcp) |
| 938 | { |
| 939 | return do_eventfd(tcp, 1); |
| 940 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 941 | #endif |