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