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