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) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 251 | tprints("{...}"); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 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) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 269 | tprints("{...}"); |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 270 | return; |
| 271 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 272 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 273 | tprints("{type="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 274 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 275 | tprints(", whence="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 281 | tprints("}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 293 | tprints("{...}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 294 | return; |
| 295 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 296 | tprints("{type="); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 297 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 298 | tprints(", whence="); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 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 |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 304 | tprints("}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 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)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 312 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 313 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 314 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 315 | switch (tcp->u_arg[1]) { |
| 316 | case F_SETFD: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 317 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 318 | printflags(fdflags, tcp->u_arg[2], "FD_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 319 | break; |
| 320 | case F_SETOWN: case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 321 | #ifdef F_DUPFD_CLOEXEC |
| 322 | case F_DUPFD_CLOEXEC: |
| 323 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 324 | tprintf(", %ld", tcp->u_arg[2]); |
| 325 | break; |
| 326 | case F_SETFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 327 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 328 | tprint_open_modes(tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 329 | break; |
| 330 | case F_SETLK: case F_SETLKW: |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 331 | #ifdef F_FREESP |
| 332 | case F_FREESP: |
| 333 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 334 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 335 | printflock(tcp, tcp->u_arg[2], 0); |
| 336 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 337 | #if _LFS64_LARGEFILE |
| 338 | #ifdef F_FREESP64 |
| 339 | case F_FREESP64: |
| 340 | #endif |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 341 | /* Linux glibc defines SETLK64 as SETLK, |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 342 | even though the kernel has different values - as does Solaris. */ |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 343 | #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 344 | case F_SETLK64: |
| 345 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 346 | #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 347 | case F_SETLKW64: |
| 348 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 349 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 350 | printflock64(tcp, tcp->u_arg[2], 0); |
| 351 | break; |
| 352 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 353 | #ifdef F_NOTIFY |
| 354 | case F_NOTIFY: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 355 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 356 | printflags(notifyflags, tcp->u_arg[2], "DN_???"); |
| 357 | break; |
| 358 | #endif |
| 359 | #ifdef F_SETLEASE |
| 360 | case F_SETLEASE: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 361 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 362 | printxval(lockfcmds, tcp->u_arg[2], "F_???"); |
| 363 | break; |
| 364 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 365 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 366 | } |
| 367 | else { |
| 368 | switch (tcp->u_arg[1]) { |
| 369 | case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 370 | #ifdef F_DUPFD_CLOEXEC |
| 371 | case F_DUPFD_CLOEXEC: |
| 372 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 373 | case F_SETFD: case F_SETFL: |
| 374 | case F_SETLK: case F_SETLKW: |
| 375 | case F_SETOWN: case F_GETOWN: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 376 | #ifdef F_NOTIFY |
| 377 | case F_NOTIFY: |
| 378 | #endif |
| 379 | #ifdef F_SETLEASE |
| 380 | case F_SETLEASE: |
| 381 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 382 | break; |
| 383 | case F_GETFD: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 384 | if (syserror(tcp) || tcp->u_rval == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 385 | return 0; |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 386 | tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 387 | return RVAL_HEX|RVAL_STR; |
| 388 | case F_GETFL: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 389 | if (syserror(tcp)) |
| 390 | return 0; |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 391 | tcp->auxstr = sprint_open_modes(tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 392 | return RVAL_HEX|RVAL_STR; |
| 393 | case F_GETLK: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 394 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 395 | printflock(tcp, tcp->u_arg[2], 1); |
| 396 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 397 | #if _LFS64_LARGEFILE |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 398 | #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 399 | case F_GETLK64: |
| 400 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 401 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 402 | printflock64(tcp, tcp->u_arg[2], 1); |
| 403 | break; |
| 404 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 405 | #ifdef F_GETLEASE |
| 406 | case F_GETLEASE: |
| 407 | if (syserror(tcp)) |
| 408 | return 0; |
| 409 | tcp->auxstr = xlookup(lockfcmds, tcp->u_rval); |
| 410 | return RVAL_HEX|RVAL_STR; |
| 411 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 412 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 413 | tprintf(", %#lx", tcp->u_arg[2]); |
| 414 | break; |
| 415 | } |
| 416 | } |
| 417 | return 0; |
| 418 | } |
| 419 | |
| 420 | #ifdef LOCK_SH |
| 421 | |
| 422 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 423 | sys_flock(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 424 | { |
| 425 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 426 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 427 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 428 | printflags(flockcmds, tcp->u_arg[1], "LOCK_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 429 | } |
| 430 | return 0; |
| 431 | } |
| 432 | #endif /* LOCK_SH */ |
| 433 | |
| 434 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 435 | sys_close(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 436 | { |
| 437 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 438 | printfd(tcp, tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 439 | } |
| 440 | return 0; |
| 441 | } |
| 442 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 443 | static int |
| 444 | do_dup2(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 445 | { |
| 446 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 447 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 448 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 449 | printfd(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 450 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 451 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 452 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 453 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 454 | } |
| 455 | return 0; |
| 456 | } |
| 457 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 458 | int |
| 459 | sys_dup2(struct tcb *tcp) |
| 460 | { |
| 461 | return do_dup2(tcp, -1); |
| 462 | } |
| 463 | |
| 464 | #ifdef LINUX |
| 465 | int |
| 466 | sys_dup3(struct tcb *tcp) |
| 467 | { |
| 468 | return do_dup2(tcp, 2); |
| 469 | } |
| 470 | #endif |
| 471 | |
Dmitry V. Levin | b9fe011 | 2006-12-13 16:59:44 +0000 | [diff] [blame] | 472 | #if defined(ALPHA) || defined(FREEBSD) || defined(SUNOS4) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 473 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 474 | sys_getdtablesize(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 475 | { |
| 476 | return 0; |
| 477 | } |
Dmitry V. Levin | b9fe011 | 2006-12-13 16:59:44 +0000 | [diff] [blame] | 478 | #endif /* ALPHA || FREEBSD || SUNOS4 */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 479 | |
| 480 | static int |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 481 | decode_select(struct tcb *tcp, long *args, enum bitness_t bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 482 | { |
Denys Vlasenko | ad5155a | 2011-09-01 18:18:04 +0200 | [diff] [blame] | 483 | int i, j; |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 484 | unsigned nfds, fdsize; |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 485 | fd_set *fds; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 486 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 487 | long arg; |
| 488 | |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 489 | fdsize = args[0]; |
| 490 | /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */ |
| 491 | if (args[0] > 1024*1024) |
| 492 | fdsize = 1024*1024; |
| 493 | if (args[0] < 0) |
| 494 | fdsize = 0; |
| 495 | fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long); |
| 496 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 497 | if (entering(tcp)) { |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 498 | fds = malloc(fdsize); |
| 499 | if (!fds) |
| 500 | die_out_of_memory(); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 501 | nfds = args[0]; |
| 502 | tprintf("%d", nfds); |
| 503 | for (i = 0; i < 3; i++) { |
| 504 | arg = args[i+1]; |
| 505 | if (arg == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 506 | tprints(", NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 507 | continue; |
| 508 | } |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 509 | if (!verbose(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 510 | tprintf(", %#lx", arg); |
| 511 | continue; |
| 512 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 513 | if (umoven(tcp, arg, fdsize, (char *) fds) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 514 | tprints(", [?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 515 | continue; |
| 516 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 517 | tprints(", ["); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 518 | for (j = 0, sep = ""; j < nfds; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 519 | if (FD_ISSET(j, fds)) { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 520 | tprints(sep); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 521 | printfd(tcp, j); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 522 | sep = " "; |
| 523 | } |
| 524 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 525 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 526 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 527 | free(fds); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 528 | tprints(", "); |
Roland McGrath | 6afc565 | 2007-07-24 01:57:11 +0000 | [diff] [blame] | 529 | printtv_bitness(tcp, args[4], bitness, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 530 | } |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 531 | else { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 532 | static char outstr[1024]; |
| 533 | char *outptr; |
| 534 | #define end_outstr (outstr + sizeof(outstr)) |
| 535 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 536 | |
| 537 | if (syserror(tcp)) |
| 538 | return 0; |
| 539 | |
Denys Vlasenko | 5d64581 | 2011-08-20 12:48:18 +0200 | [diff] [blame] | 540 | nfds = tcp->u_rval; |
| 541 | if (nfds == 0) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 542 | tcp->auxstr = "Timeout"; |
| 543 | return RVAL_STR; |
| 544 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 545 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 546 | fds = malloc(fdsize); |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 547 | if (!fds) |
| 548 | die_out_of_memory(); |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 549 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 550 | outptr = outstr; |
| 551 | sep = ""; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 552 | for (i = 0; i < 3; i++) { |
| 553 | int first = 1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 554 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 555 | arg = args[i+1]; |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 556 | if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 557 | continue; |
| 558 | for (j = 0; j < args[0]; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 559 | if (FD_ISSET(j, fds)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 560 | /* +2 chars needed at the end: ']',NUL */ |
| 561 | if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) { |
| 562 | if (first) { |
| 563 | outptr += sprintf(outptr, "%s%s [%u", |
| 564 | sep, |
| 565 | i == 0 ? "in" : i == 1 ? "out" : "except", |
| 566 | j |
| 567 | ); |
| 568 | first = 0; |
| 569 | sep = ", "; |
| 570 | } |
| 571 | else { |
| 572 | outptr += sprintf(outptr, " %u", j); |
| 573 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 574 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 575 | nfds--; |
| 576 | } |
| 577 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 578 | if (outptr != outstr) |
| 579 | *outptr++ = ']'; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 580 | if (nfds == 0) |
| 581 | break; |
| 582 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 583 | free(fds); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 584 | #ifdef LINUX |
| 585 | /* This contains no useful information on SunOS. */ |
| 586 | if (args[4]) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame^] | 587 | if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 588 | outptr += sprintf(outptr, "%sleft ", sep); |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame^] | 589 | outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0); |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 590 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 591 | } |
| 592 | #endif /* LINUX */ |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 593 | *outptr = '\0'; |
Denys Vlasenko | 1161725 | 2011-09-01 11:27:37 +0200 | [diff] [blame] | 594 | tcp->auxstr = outstr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 595 | return RVAL_STR; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 596 | #undef end_outstr |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 597 | } |
| 598 | return 0; |
| 599 | } |
| 600 | |
| 601 | #ifdef LINUX |
| 602 | |
| 603 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 604 | sys_oldselect(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 605 | { |
| 606 | long args[5]; |
| 607 | |
| 608 | if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 609 | tprints("[...]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 610 | return 0; |
| 611 | } |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 612 | return decode_select(tcp, args, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 613 | } |
| 614 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 615 | #ifdef ALPHA |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 616 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 617 | sys_osf_select(struct tcb *tcp) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 618 | { |
| 619 | long *args = tcp->u_arg; |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 620 | return decode_select(tcp, args, BITNESS_32); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 621 | } |
| 622 | #endif |
| 623 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 624 | static const struct xlat epollctls[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 625 | #ifdef EPOLL_CTL_ADD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 626 | { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 627 | #endif |
| 628 | #ifdef EPOLL_CTL_MOD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 629 | { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 630 | #endif |
| 631 | #ifdef EPOLL_CTL_DEL |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 632 | { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 633 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 634 | { 0, NULL } |
| 635 | }; |
| 636 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 637 | static const struct xlat epollevents[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 638 | #ifdef EPOLLIN |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 639 | { EPOLLIN, "EPOLLIN" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 640 | #endif |
| 641 | #ifdef EPOLLPRI |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 642 | { EPOLLPRI, "EPOLLPRI" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 643 | #endif |
| 644 | #ifdef EPOLLOUT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 645 | { EPOLLOUT, "EPOLLOUT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 646 | #endif |
| 647 | #ifdef EPOLLRDNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 648 | { EPOLLRDNORM, "EPOLLRDNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 649 | #endif |
| 650 | #ifdef EPOLLRDBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 651 | { EPOLLRDBAND, "EPOLLRDBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 652 | #endif |
| 653 | #ifdef EPOLLWRNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 654 | { EPOLLWRNORM, "EPOLLWRNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 655 | #endif |
| 656 | #ifdef EPOLLWRBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 657 | { EPOLLWRBAND, "EPOLLWRBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 658 | #endif |
| 659 | #ifdef EPOLLMSG |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 660 | { EPOLLMSG, "EPOLLMSG" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 661 | #endif |
| 662 | #ifdef EPOLLERR |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 663 | { EPOLLERR, "EPOLLERR" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 664 | #endif |
| 665 | #ifdef EPOLLHUP |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 666 | { EPOLLHUP, "EPOLLHUP" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 667 | #endif |
Dmitry V. Levin | 5967c1a | 2011-10-11 15:55:40 +0000 | [diff] [blame] | 668 | #ifdef EPOLLRDHUP |
| 669 | { EPOLLRDHUP, "EPOLLRDHUP" }, |
| 670 | #endif |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 671 | #ifdef EPOLLONESHOT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 672 | { EPOLLONESHOT, "EPOLLONESHOT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 673 | #endif |
| 674 | #ifdef EPOLLET |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 675 | { EPOLLET, "EPOLLET" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 676 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 677 | { 0, NULL } |
| 678 | }; |
| 679 | |
| 680 | int |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 681 | sys_epoll_create(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 682 | { |
| 683 | if (entering(tcp)) |
| 684 | tprintf("%ld", tcp->u_arg[0]); |
| 685 | return 0; |
| 686 | } |
| 687 | |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 688 | static const struct xlat epollflags[] = { |
| 689 | #ifdef EPOLL_CLOEXEC |
| 690 | { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" }, |
| 691 | #endif |
| 692 | #ifdef EPOLL_NONBLOCK |
| 693 | { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" }, |
| 694 | #endif |
| 695 | { 0, NULL } |
| 696 | }; |
| 697 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 698 | int |
| 699 | sys_epoll_create1(struct tcb *tcp) |
| 700 | { |
| 701 | if (entering(tcp)) |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 702 | printflags(epollflags, tcp->u_arg[0], "EPOLL_???"); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 703 | return 0; |
| 704 | } |
| 705 | |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 706 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 707 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 708 | print_epoll_event(struct epoll_event *ev) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 709 | { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 710 | tprints("{"); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 711 | printflags(epollevents, ev->events, "EPOLL???"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 712 | /* We cannot know what format the program uses, so print u32 and u64 |
| 713 | which will cover every value. */ |
| 714 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 715 | ev->data.u32, ev->data.u64); |
| 716 | } |
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 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 720 | sys_epoll_ctl(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 721 | { |
| 722 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 723 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 724 | tprints(", "); |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 725 | printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 726 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 727 | printfd(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 728 | tprints(", "); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 729 | if (tcp->u_arg[3] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 730 | tprints("NULL"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 731 | else { |
| 732 | #ifdef HAVE_SYS_EPOLL_H |
| 733 | struct epoll_event ev; |
Roland McGrath | 6e52d23 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 734 | if (umove(tcp, tcp->u_arg[3], &ev) == 0) |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 735 | print_epoll_event(&ev); |
| 736 | else |
| 737 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 738 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 739 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 740 | } |
| 741 | return 0; |
| 742 | } |
| 743 | |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 744 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 745 | epoll_wait_common(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 746 | { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 747 | if (entering(tcp)) { |
| 748 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 749 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 750 | } else { |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 751 | if (syserror(tcp)) |
| 752 | tprintf("%lx", tcp->u_arg[1]); |
| 753 | else if (tcp->u_rval == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 754 | tprints("{}"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 755 | else { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 756 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 757 | struct epoll_event ev, *start, *cur, *end; |
| 758 | int failed = 0; |
| 759 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 760 | tprints("{"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 761 | start = (struct epoll_event *) tcp->u_arg[1]; |
| 762 | end = start + tcp->u_rval; |
| 763 | for (cur = start; cur < end; ++cur) { |
| 764 | if (cur > start) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 765 | tprints(", "); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 766 | if (umove(tcp, (long) cur, &ev) == 0) |
| 767 | print_epoll_event(&ev); |
| 768 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 769 | tprints("?"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 770 | failed = 1; |
| 771 | break; |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 772 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 773 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 774 | tprints("}"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 775 | if (failed) |
| 776 | tprintf(" %#lx", (long) start); |
| 777 | #else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 778 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 779 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 780 | } |
Dmitry V. Levin | c327d71 | 2011-10-11 16:05:57 +0000 | [diff] [blame] | 781 | tprintf(", %d, %d", (int) tcp->u_arg[2], (int) tcp->u_arg[3]); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 782 | } |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 786 | sys_epoll_wait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 787 | { |
| 788 | epoll_wait_common(tcp); |
| 789 | return 0; |
| 790 | } |
| 791 | |
| 792 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 793 | sys_epoll_pwait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 794 | { |
| 795 | epoll_wait_common(tcp); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 796 | if (exiting(tcp)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 797 | tprints(", "); |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 798 | print_sigset(tcp, tcp->u_arg[4], 0); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 799 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 800 | return 0; |
| 801 | } |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 802 | |
| 803 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 804 | sys_io_setup(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 805 | { |
| 806 | if (entering(tcp)) |
| 807 | tprintf("%ld, ", tcp->u_arg[0]); |
| 808 | else { |
| 809 | if (syserror(tcp)) |
| 810 | tprintf("0x%0lx", tcp->u_arg[1]); |
| 811 | else { |
| 812 | unsigned long user_id; |
| 813 | if (umove(tcp, tcp->u_arg[1], &user_id) == 0) |
| 814 | tprintf("{%lu}", user_id); |
| 815 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 816 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 817 | } |
| 818 | } |
| 819 | return 0; |
| 820 | } |
| 821 | |
| 822 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 823 | sys_io_destroy(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 824 | { |
| 825 | if (entering(tcp)) |
| 826 | tprintf("%lu", tcp->u_arg[0]); |
| 827 | return 0; |
| 828 | } |
| 829 | |
Dmitry V. Levin | 081e72f | 2011-06-21 15:11:57 +0000 | [diff] [blame] | 830 | #ifdef HAVE_LIBAIO_H |
| 831 | |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 832 | enum iocb_sub { |
| 833 | SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR |
| 834 | }; |
| 835 | |
| 836 | static const char * |
| 837 | iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub) |
| 838 | { |
Denys Vlasenko | 7999262 | 2011-08-19 19:44:17 +0200 | [diff] [blame] | 839 | static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3]; |
| 840 | static const struct { |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 841 | const char *name; |
| 842 | enum iocb_sub sub; |
| 843 | } cmds[] = { |
| 844 | { "pread", SUB_COMMON }, |
| 845 | { "pwrite", SUB_COMMON }, |
| 846 | { "fsync", SUB_NONE }, |
| 847 | { "fdsync", SUB_NONE }, |
| 848 | { "op4", SUB_NONE }, |
| 849 | { "poll", SUB_POLL }, |
| 850 | { "noop", SUB_NONE }, |
| 851 | { "preadv", SUB_VECTOR }, |
| 852 | { "pwritev", SUB_VECTOR }, |
| 853 | }; |
| 854 | |
| 855 | if (cmd < ARRAY_SIZE(cmds)) { |
| 856 | *sub = cmds[cmd].sub; |
| 857 | return cmds[cmd].name; |
| 858 | } |
| 859 | *sub = SUB_NONE; |
Denys Vlasenko | 7999262 | 2011-08-19 19:44:17 +0200 | [diff] [blame] | 860 | sprintf(buf, "%u /* SUB_??? */", cmd); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 861 | return buf; |
| 862 | } |
| 863 | |
| 864 | /* Not defined in libaio.h */ |
| 865 | #ifndef IOCB_RESFD |
| 866 | # define IOCB_RESFD (1 << 0) |
| 867 | #endif |
| 868 | |
| 869 | static void |
| 870 | print_common_flags(struct iocb *iocb) |
| 871 | { |
| 872 | if (iocb->u.c.flags & IOCB_RESFD) |
| 873 | tprintf("resfd=%d, ", iocb->u.c.resfd); |
| 874 | if (iocb->u.c.flags & ~IOCB_RESFD) |
| 875 | tprintf("flags=%x, ", iocb->u.c.flags); |
| 876 | } |
Dmitry V. Levin | 081e72f | 2011-06-21 15:11:57 +0000 | [diff] [blame] | 877 | |
| 878 | #endif /* HAVE_LIBAIO_H */ |
| 879 | |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 880 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 881 | sys_io_submit(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 882 | { |
| 883 | long nr; |
| 884 | if (entering(tcp)) { |
| 885 | tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 886 | nr = tcp->u_arg[1]; |
| 887 | /* and if nr is negative? */ |
| 888 | if (nr == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 889 | tprints("{}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 890 | else { |
| 891 | #ifdef HAVE_LIBAIO_H |
| 892 | long i; |
| 893 | struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2]; |
| 894 | |
| 895 | for (i = 0; i < nr; i++, iocbs++) { |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 896 | enum iocb_sub sub; |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 897 | struct iocb iocb; |
| 898 | if (i == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 899 | tprints("{"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 900 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 901 | tprints(", "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 902 | |
| 903 | if (umove(tcp, (unsigned long)iocbs, &iocbp) || |
| 904 | umove(tcp, (unsigned long)iocbp, &iocb)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 905 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 906 | continue; |
| 907 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 908 | tprints("{"); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 909 | if (iocb.data) |
| 910 | tprintf("data:%p, ", iocb.data); |
| 911 | if (iocb.key) |
| 912 | tprintf("key:%u, ", iocb.key); |
| 913 | tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub)); |
| 914 | if (iocb.aio_reqprio) |
| 915 | tprintf("reqprio:%d, ", iocb.aio_reqprio); |
| 916 | tprintf("filedes:%d", iocb.aio_fildes); |
| 917 | switch (sub) { |
| 918 | case SUB_COMMON: |
| 919 | if (iocb.aio_lio_opcode == IO_CMD_PWRITE) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 920 | tprints(", str:"); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 921 | printstr(tcp, (unsigned long)iocb.u.c.buf, |
| 922 | iocb.u.c.nbytes); |
| 923 | } else { |
| 924 | tprintf(", buf:%p", iocb.u.c.buf); |
| 925 | } |
| 926 | tprintf(", nbytes:%lu, offset:%llx", |
| 927 | iocb.u.c.nbytes, |
| 928 | iocb.u.c.offset); |
| 929 | print_common_flags(&iocb); |
| 930 | break; |
| 931 | case SUB_VECTOR: |
| 932 | tprintf(", %llx, ", iocb.u.v.offset); |
| 933 | print_common_flags(&iocb); |
| 934 | tprint_iov(tcp, iocb.u.v.nr, |
| 935 | (unsigned long)iocb.u.v.vec, |
| 936 | iocb.aio_lio_opcode == IO_CMD_PWRITEV); |
| 937 | break; |
| 938 | case SUB_POLL: |
| 939 | tprintf(", %x", iocb.u.poll.events); |
| 940 | break; |
| 941 | case SUB_NONE: |
| 942 | break; |
| 943 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 944 | tprints("}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 945 | } |
| 946 | if (i) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 947 | tprints("}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 948 | #else |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 949 | #warning "libaio-devel is not available => no io_submit decoding" |
| 950 | tprintf("%#lx", tcp->u_arg[2]); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 951 | #endif |
| 952 | } |
| 953 | } |
| 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 958 | sys_io_cancel(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 959 | { |
| 960 | if (entering(tcp)) { |
| 961 | #ifdef HAVE_LIBAIO_H |
| 962 | struct iocb iocb; |
| 963 | #endif |
| 964 | tprintf("%lu, ", tcp->u_arg[0]); |
| 965 | #ifdef HAVE_LIBAIO_H |
| 966 | if (umove(tcp, tcp->u_arg[1], &iocb) == 0) { |
| 967 | tprintf("{%p, %u, %hu, %hu, %d}, ", |
| 968 | iocb.data, iocb.key, |
| 969 | iocb.aio_lio_opcode, |
| 970 | iocb.aio_reqprio, iocb.aio_fildes); |
| 971 | } else |
| 972 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 973 | tprints("{...}, "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 974 | } else { |
| 975 | if (tcp->u_rval < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 976 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 977 | else { |
| 978 | #ifdef HAVE_LIBAIO_H |
| 979 | struct io_event event; |
| 980 | if (umove(tcp, tcp->u_arg[2], &event) == 0) |
| 981 | tprintf("{%p, %p, %ld, %ld}", |
| 982 | event.data, event.obj, |
| 983 | event.res, event.res2); |
Dmitry V. Levin | 414fe7d | 2009-07-08 11:21:17 +0000 | [diff] [blame] | 984 | else |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 985 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 986 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | return 0; |
| 990 | } |
| 991 | |
| 992 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 993 | sys_io_getevents(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 994 | { |
| 995 | if (entering(tcp)) { |
| 996 | tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1], |
| 997 | tcp->u_arg[2]); |
| 998 | } else { |
| 999 | if (tcp->u_rval == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1000 | tprints("{}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1001 | } else { |
| 1002 | #ifdef HAVE_LIBAIO_H |
| 1003 | struct io_event *events = (void *)tcp->u_arg[3]; |
| 1004 | long i, nr = tcp->u_rval; |
| 1005 | |
| 1006 | for (i = 0; i < nr; i++, events++) { |
| 1007 | struct io_event event; |
| 1008 | |
| 1009 | if (i == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1010 | tprints("{"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1011 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1012 | tprints(", "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1013 | |
| 1014 | if (umove(tcp, (unsigned long)events, &event) != 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1015 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1016 | continue; |
| 1017 | } |
| 1018 | tprintf("{%p, %p, %ld, %ld}", event.data, |
| 1019 | event.obj, event.res, event.res2); |
| 1020 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1021 | tprints("}, "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1022 | #else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1023 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1024 | #endif |
| 1025 | } |
| 1026 | |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 1027 | print_timespec(tcp, tcp->u_arg[4]); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1028 | } |
| 1029 | return 0; |
| 1030 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1031 | #endif /* LINUX */ |
| 1032 | |
| 1033 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 1034 | sys_select(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1035 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 1036 | return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1037 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1038 | |
| 1039 | #ifdef LINUX |
| 1040 | int |
| 1041 | sys_pselect6(struct tcb *tcp) |
| 1042 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 1043 | int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 1044 | if (entering(tcp)) { |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1045 | struct { |
| 1046 | void *ss; |
| 1047 | unsigned long len; |
| 1048 | } data; |
| 1049 | if (umove(tcp, tcp->u_arg[5], &data) < 0) |
| 1050 | tprintf(", %#lx", tcp->u_arg[5]); |
| 1051 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1052 | tprints(", {"); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 1053 | if (data.len < sizeof(long)) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1054 | tprintf("%#lx", (long)data.ss); |
| 1055 | else |
| 1056 | print_sigset(tcp, (long)data.ss, 0); |
| 1057 | tprintf(", %lu}", data.len); |
| 1058 | } |
| 1059 | } |
| 1060 | return rc; |
| 1061 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1062 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1063 | static int |
| 1064 | do_eventfd(struct tcb *tcp, int flags_arg) |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1065 | { |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1066 | if (entering(tcp)) { |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1067 | tprintf("%lu", tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1068 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1069 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1070 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 1071 | } |
| 1072 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1073 | return 0; |
| 1074 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1075 | |
| 1076 | int |
| 1077 | sys_eventfd(struct tcb *tcp) |
| 1078 | { |
| 1079 | return do_eventfd(tcp, -1); |
| 1080 | } |
| 1081 | |
| 1082 | int |
| 1083 | sys_eventfd2(struct tcb *tcp) |
| 1084 | { |
| 1085 | return do_eventfd(tcp, 1); |
| 1086 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1087 | #endif |