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 | #include <inttypes.h> |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 38 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 39 | #include <sys/epoll.h> |
| 40 | #endif |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 41 | #ifdef HAVE_LIBAIO_H |
| 42 | #include <libaio.h> |
| 43 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 44 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 45 | #if HAVE_LONG_LONG_OFF_T |
| 46 | /* |
| 47 | * Hacks for systems that have a long long off_t |
| 48 | */ |
John Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 49 | #define flock64 flock /* Horrid hack */ |
| 50 | #define printflock printflock64 /* Horrider hack */ |
| 51 | #endif |
| 52 | |
| 53 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 54 | static const struct xlat fcntlcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 55 | { F_DUPFD, "F_DUPFD" }, |
| 56 | { F_GETFD, "F_GETFD" }, |
| 57 | { F_SETFD, "F_SETFD" }, |
| 58 | { F_GETFL, "F_GETFL" }, |
| 59 | { F_SETFL, "F_SETFL" }, |
| 60 | { F_GETLK, "F_GETLK" }, |
| 61 | { F_SETLK, "F_SETLK" }, |
| 62 | { F_SETLKW, "F_SETLKW" }, |
| 63 | { F_GETOWN, "F_GETOWN" }, |
| 64 | { F_SETOWN, "F_SETOWN" }, |
| 65 | #ifdef F_RSETLK |
| 66 | { F_RSETLK, "F_RSETLK" }, |
| 67 | #endif |
| 68 | #ifdef F_RSETLKW |
| 69 | { F_RSETLKW, "F_RSETLKW" }, |
| 70 | #endif |
| 71 | #ifdef F_RGETLK |
| 72 | { F_RGETLK, "F_RGETLK" }, |
| 73 | #endif |
| 74 | #ifdef F_CNVT |
| 75 | { F_CNVT, "F_CNVT" }, |
| 76 | #endif |
Wichert Akkerman | 5ae21ea | 2000-05-01 01:53:59 +0000 | [diff] [blame] | 77 | #ifdef F_SETSIG |
| 78 | { F_SETSIG, "F_SETSIG" }, |
| 79 | #endif |
| 80 | #ifdef F_GETSIG |
| 81 | { F_GETSIG, "F_GETSIG" }, |
| 82 | #endif |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 83 | #ifdef F_CHKFL |
| 84 | { F_CHKFL, "F_CHKFL" }, |
| 85 | #endif |
| 86 | #ifdef F_DUP2FD |
| 87 | { F_DUP2FD, "F_DUP2FD" }, |
| 88 | #endif |
| 89 | #ifdef F_ALLOCSP |
| 90 | { F_ALLOCSP, "F_ALLOCSP" }, |
| 91 | #endif |
| 92 | #ifdef F_ISSTREAM |
| 93 | { F_ISSTREAM, "F_ISSTREAM" }, |
| 94 | #endif |
| 95 | #ifdef F_PRIV |
| 96 | { F_PRIV, "F_PRIV" }, |
| 97 | #endif |
| 98 | #ifdef F_NPRIV |
| 99 | { F_NPRIV, "F_NPRIV" }, |
| 100 | #endif |
| 101 | #ifdef F_QUOTACL |
| 102 | { F_QUOTACL, "F_QUOTACL" }, |
| 103 | #endif |
| 104 | #ifdef F_BLOCKS |
| 105 | { F_BLOCKS, "F_BLOCKS" }, |
| 106 | #endif |
| 107 | #ifdef F_BLKSIZE |
| 108 | { F_BLKSIZE, "F_BLKSIZE" }, |
| 109 | #endif |
| 110 | #ifdef F_GETOWN |
| 111 | { F_GETOWN, "F_GETOWN" }, |
| 112 | #endif |
| 113 | #ifdef F_SETOWN |
| 114 | { F_SETOWN, "F_SETOWN" }, |
| 115 | #endif |
| 116 | #ifdef F_REVOKE |
| 117 | { F_REVOKE, "F_REVOKE" }, |
| 118 | #endif |
| 119 | #ifdef F_SETLK |
| 120 | { F_SETLK, "F_SETLK" }, |
| 121 | #endif |
| 122 | #ifdef F_SETLKW |
| 123 | { F_SETLKW, "F_SETLKW" }, |
| 124 | #endif |
| 125 | #ifdef F_FREESP |
| 126 | { F_FREESP, "F_FREESP" }, |
| 127 | #endif |
| 128 | #ifdef F_GETLK |
| 129 | { F_GETLK, "F_GETLK" }, |
| 130 | #endif |
| 131 | #ifdef F_SETLK64 |
| 132 | { F_SETLK64, "F_SETLK64" }, |
| 133 | #endif |
| 134 | #ifdef F_SETLKW64 |
| 135 | { F_SETLKW64, "F_SETLKW64" }, |
| 136 | #endif |
| 137 | #ifdef F_FREESP64 |
| 138 | { F_FREESP64, "F_FREESP64" }, |
| 139 | #endif |
| 140 | #ifdef F_GETLK64 |
| 141 | { F_GETLK64, "F_GETLK64" }, |
| 142 | #endif |
| 143 | #ifdef F_SHARE |
| 144 | { F_SHARE, "F_SHARE" }, |
| 145 | #endif |
| 146 | #ifdef F_UNSHARE |
| 147 | { F_UNSHARE, "F_UNSHARE" }, |
| 148 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 149 | #ifdef F_SETLEASE |
| 150 | { F_SETLEASE, "F_SETLEASE" }, |
| 151 | #endif |
| 152 | #ifdef F_GETLEASE |
| 153 | { F_GETLEASE, "F_GETLEASE" }, |
| 154 | #endif |
| 155 | #ifdef F_NOTIFY |
| 156 | { F_NOTIFY, "F_NOTIFY" }, |
| 157 | #endif |
| 158 | #ifdef F_DUPFD_CLOEXEC |
| 159 | { F_DUPFD_CLOEXEC,"F_DUPFD_CLOEXEC"}, |
| 160 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 161 | { 0, NULL }, |
| 162 | }; |
| 163 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 164 | static const struct xlat fdflags[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 165 | #ifdef FD_CLOEXEC |
| 166 | { FD_CLOEXEC, "FD_CLOEXEC" }, |
| 167 | #endif |
| 168 | { 0, NULL }, |
| 169 | }; |
| 170 | |
| 171 | #ifdef LOCK_SH |
| 172 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 173 | static const struct xlat flockcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 174 | { LOCK_SH, "LOCK_SH" }, |
| 175 | { LOCK_EX, "LOCK_EX" }, |
| 176 | { LOCK_NB, "LOCK_NB" }, |
| 177 | { LOCK_UN, "LOCK_UN" }, |
| 178 | { 0, NULL }, |
| 179 | }; |
| 180 | |
| 181 | #endif /* LOCK_SH */ |
| 182 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 183 | static const struct xlat lockfcmds[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 184 | { F_RDLCK, "F_RDLCK" }, |
| 185 | { F_WRLCK, "F_WRLCK" }, |
| 186 | { F_UNLCK, "F_UNLCK" }, |
| 187 | #ifdef F_EXLCK |
| 188 | { F_EXLCK, "F_EXLCK" }, |
| 189 | #endif |
| 190 | #ifdef F_SHLCK |
| 191 | { F_SHLCK, "F_SHLCK" }, |
| 192 | #endif |
| 193 | { 0, NULL }, |
| 194 | }; |
| 195 | |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 196 | #ifdef F_NOTIFY |
| 197 | static const struct xlat notifyflags[] = { |
| 198 | #ifdef DN_ACCESS |
| 199 | { DN_ACCESS, "DN_ACCESS" }, |
| 200 | #endif |
| 201 | #ifdef DN_MODIFY |
| 202 | { DN_MODIFY, "DN_MODIFY" }, |
| 203 | #endif |
| 204 | #ifdef DN_CREATE |
| 205 | { DN_CREATE, "DN_CREATE" }, |
| 206 | #endif |
| 207 | #ifdef DN_DELETE |
| 208 | { DN_DELETE, "DN_DELETE" }, |
| 209 | #endif |
| 210 | #ifdef DN_RENAME |
| 211 | { DN_RENAME, "DN_RENAME" }, |
| 212 | #endif |
| 213 | #ifdef DN_ATTRIB |
| 214 | { DN_ATTRIB, "DN_ATTRIB" }, |
| 215 | #endif |
| 216 | #ifdef DN_MULTISHOT |
| 217 | { DN_MULTISHOT, "DN_MULTISHOT" }, |
| 218 | #endif |
| 219 | { 0, NULL }, |
| 220 | }; |
| 221 | #endif |
| 222 | |
Roland McGrath | d9f816f | 2004-09-04 03:39:20 +0000 | [diff] [blame] | 223 | static const struct xlat whence[] = { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 224 | { SEEK_SET, "SEEK_SET" }, |
| 225 | { SEEK_CUR, "SEEK_CUR" }, |
| 226 | { SEEK_END, "SEEK_END" }, |
| 227 | { 0, NULL }, |
| 228 | }; |
| 229 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 230 | #ifndef HAVE_LONG_LONG_OFF_T |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 231 | /* fcntl/lockf */ |
| 232 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 233 | printflock(struct tcb *tcp, long addr, int getlk) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 234 | { |
| 235 | struct flock fl; |
| 236 | |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 237 | #if SUPPORTED_PERSONALITIES > 1 |
| 238 | if (personality_wordsize[current_personality] != sizeof(fl.l_start)) { |
| 239 | if (personality_wordsize[current_personality] == 4) { |
| 240 | /* 32-bit x86 app on x86_64 and similar cases */ |
| 241 | struct { |
| 242 | short int l_type; |
| 243 | short int l_whence; |
| 244 | int32_t l_start; /* off_t */ |
| 245 | int32_t l_len; /* off_t */ |
| 246 | int32_t l_pid; /* pid_t */ |
| 247 | } fl32; |
| 248 | if (umove(tcp, addr, &fl32) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 249 | tprints("{...}"); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 250 | return; |
| 251 | } |
| 252 | fl.l_type = fl32.l_type; |
| 253 | fl.l_whence = fl32.l_whence; |
| 254 | fl.l_start = fl32.l_start; |
| 255 | fl.l_len = fl32.l_len; |
| 256 | fl.l_pid = fl32.l_pid; |
| 257 | } else { |
| 258 | /* let people know we have a problem here */ |
| 259 | tprintf("{ <decode error: unsupported wordsize %d> }", |
| 260 | personality_wordsize[current_personality]); |
| 261 | return; |
| 262 | } |
| 263 | } else |
| 264 | #endif |
| 265 | { |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 266 | if (umove(tcp, addr, &fl) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 267 | tprints("{...}"); |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 268 | return; |
| 269 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 270 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 271 | tprints("{type="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 272 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 273 | tprints(", whence="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 274 | printxval(whence, fl.l_whence, "SEEK_???"); |
| 275 | tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len); |
| 276 | if (getlk) |
| 277 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 278 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 279 | tprints("}"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 280 | } |
John Hughes | b8c9f77 | 2001-03-07 16:53:07 +0000 | [diff] [blame] | 281 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 282 | |
John Hughes | 70623be | 2001-03-08 13:59:00 +0000 | [diff] [blame] | 283 | #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 284 | /* fcntl/lockf */ |
| 285 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 286 | printflock64(struct tcb *tcp, long addr, int getlk) |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 287 | { |
| 288 | struct flock64 fl; |
| 289 | |
| 290 | if (umove(tcp, addr, &fl) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 291 | tprints("{...}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 292 | return; |
| 293 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 294 | tprints("{type="); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 295 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 296 | tprints(", whence="); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 297 | printxval(whence, fl.l_whence, "SEEK_???"); |
Wichert Akkerman | 7b3346b | 2001-10-09 23:47:38 +0000 | [diff] [blame] | 298 | 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] | 299 | if (getlk) |
| 300 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 301 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 302 | tprints("}"); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 303 | } |
| 304 | #endif |
| 305 | |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 306 | int |
| 307 | sys_fcntl(struct tcb *tcp) |
| 308 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 309 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 310 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 311 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 312 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 313 | switch (tcp->u_arg[1]) { |
| 314 | case F_SETFD: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 315 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 316 | printflags(fdflags, tcp->u_arg[2], "FD_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 317 | break; |
| 318 | case F_SETOWN: case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 319 | #ifdef F_DUPFD_CLOEXEC |
| 320 | case F_DUPFD_CLOEXEC: |
| 321 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 322 | tprintf(", %ld", tcp->u_arg[2]); |
| 323 | break; |
| 324 | case F_SETFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 325 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 326 | tprint_open_modes(tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 327 | break; |
| 328 | case F_SETLK: case F_SETLKW: |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 329 | #ifdef F_FREESP |
| 330 | case F_FREESP: |
| 331 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 332 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 333 | printflock(tcp, tcp->u_arg[2], 0); |
| 334 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 335 | #if _LFS64_LARGEFILE |
| 336 | #ifdef F_FREESP64 |
| 337 | case F_FREESP64: |
| 338 | #endif |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 339 | /* Linux glibc defines SETLK64 as SETLK, |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 340 | even though the kernel has different values - as does Solaris. */ |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 341 | #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 342 | case F_SETLK64: |
| 343 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 344 | #if defined(F_SETLKW64) && F_SETLKW64 + 0 != F_SETLKW |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 345 | case F_SETLKW64: |
| 346 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 347 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 348 | printflock64(tcp, tcp->u_arg[2], 0); |
| 349 | break; |
| 350 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 351 | #ifdef F_NOTIFY |
| 352 | case F_NOTIFY: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 353 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 354 | printflags(notifyflags, tcp->u_arg[2], "DN_???"); |
| 355 | break; |
| 356 | #endif |
| 357 | #ifdef F_SETLEASE |
| 358 | case F_SETLEASE: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 359 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 360 | printxval(lockfcmds, tcp->u_arg[2], "F_???"); |
| 361 | break; |
| 362 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 363 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 364 | } |
| 365 | else { |
| 366 | switch (tcp->u_arg[1]) { |
| 367 | case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 368 | #ifdef F_DUPFD_CLOEXEC |
| 369 | case F_DUPFD_CLOEXEC: |
| 370 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 371 | case F_SETFD: case F_SETFL: |
| 372 | case F_SETLK: case F_SETLKW: |
| 373 | case F_SETOWN: case F_GETOWN: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 374 | #ifdef F_NOTIFY |
| 375 | case F_NOTIFY: |
| 376 | #endif |
| 377 | #ifdef F_SETLEASE |
| 378 | case F_SETLEASE: |
| 379 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 380 | break; |
| 381 | case F_GETFD: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 382 | if (syserror(tcp) || tcp->u_rval == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 383 | return 0; |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 384 | tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 385 | return RVAL_HEX|RVAL_STR; |
| 386 | case F_GETFL: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 387 | if (syserror(tcp)) |
| 388 | return 0; |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 389 | tcp->auxstr = sprint_open_modes(tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 390 | return RVAL_HEX|RVAL_STR; |
| 391 | case F_GETLK: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 392 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 393 | printflock(tcp, tcp->u_arg[2], 1); |
| 394 | break; |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 395 | #if _LFS64_LARGEFILE |
Denys Vlasenko | b63256e | 2011-06-07 12:13:24 +0200 | [diff] [blame] | 396 | #if defined(F_GETLK64) && F_GETLK64+0 != F_GETLK |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 397 | case F_GETLK64: |
| 398 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 399 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 400 | printflock64(tcp, tcp->u_arg[2], 1); |
| 401 | break; |
| 402 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 403 | #ifdef F_GETLEASE |
| 404 | case F_GETLEASE: |
| 405 | if (syserror(tcp)) |
| 406 | return 0; |
| 407 | tcp->auxstr = xlookup(lockfcmds, tcp->u_rval); |
| 408 | return RVAL_HEX|RVAL_STR; |
| 409 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 410 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 411 | tprintf(", %#lx", tcp->u_arg[2]); |
| 412 | break; |
| 413 | } |
| 414 | } |
| 415 | return 0; |
| 416 | } |
| 417 | |
| 418 | #ifdef LOCK_SH |
| 419 | |
| 420 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 421 | sys_flock(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 422 | { |
| 423 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 424 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 425 | tprints(", "); |
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)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 436 | printfd(tcp, tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 437 | } |
| 438 | return 0; |
| 439 | } |
| 440 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 441 | static int |
| 442 | do_dup2(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 443 | { |
| 444 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 445 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 446 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 447 | printfd(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 448 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 449 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 450 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 451 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 452 | } |
| 453 | return 0; |
| 454 | } |
| 455 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 456 | int |
| 457 | sys_dup2(struct tcb *tcp) |
| 458 | { |
| 459 | return do_dup2(tcp, -1); |
| 460 | } |
| 461 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 462 | int |
| 463 | sys_dup3(struct tcb *tcp) |
| 464 | { |
| 465 | return do_dup2(tcp, 2); |
| 466 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 467 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame^] | 468 | #if defined(ALPHA) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 469 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 470 | sys_getdtablesize(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 471 | { |
| 472 | return 0; |
| 473 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame^] | 474 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 475 | |
| 476 | static int |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 477 | decode_select(struct tcb *tcp, long *args, enum bitness_t bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 478 | { |
Denys Vlasenko | ad5155a | 2011-09-01 18:18:04 +0200 | [diff] [blame] | 479 | int i, j; |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 480 | unsigned nfds, fdsize; |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 481 | fd_set *fds; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 482 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 483 | long arg; |
| 484 | |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 485 | fdsize = args[0]; |
| 486 | /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */ |
| 487 | if (args[0] > 1024*1024) |
| 488 | fdsize = 1024*1024; |
| 489 | if (args[0] < 0) |
| 490 | fdsize = 0; |
| 491 | fdsize = (((fdsize + 7) / 8) + sizeof(long)-1) & -sizeof(long); |
| 492 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 493 | if (entering(tcp)) { |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 494 | fds = malloc(fdsize); |
| 495 | if (!fds) |
| 496 | die_out_of_memory(); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 497 | nfds = args[0]; |
| 498 | tprintf("%d", nfds); |
| 499 | for (i = 0; i < 3; i++) { |
| 500 | arg = args[i+1]; |
| 501 | if (arg == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 502 | tprints(", NULL"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 503 | continue; |
| 504 | } |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 505 | if (!verbose(tcp)) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 506 | tprintf(", %#lx", arg); |
| 507 | continue; |
| 508 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 509 | if (umoven(tcp, arg, fdsize, (char *) fds) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 510 | tprints(", [?]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 511 | continue; |
| 512 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 513 | tprints(", ["); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 514 | for (j = 0, sep = ""; j < nfds; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 515 | if (FD_ISSET(j, fds)) { |
Denys Vlasenko | 5940e65 | 2011-09-01 09:55:05 +0200 | [diff] [blame] | 516 | tprints(sep); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 517 | printfd(tcp, j); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 518 | sep = " "; |
| 519 | } |
| 520 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 521 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 522 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 523 | free(fds); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 524 | tprints(", "); |
Roland McGrath | 6afc565 | 2007-07-24 01:57:11 +0000 | [diff] [blame] | 525 | printtv_bitness(tcp, args[4], bitness, 0); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 526 | } |
Denys Vlasenko | 7b609d5 | 2011-06-22 14:32:43 +0200 | [diff] [blame] | 527 | else { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 528 | static char outstr[1024]; |
| 529 | char *outptr; |
| 530 | #define end_outstr (outstr + sizeof(outstr)) |
| 531 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 532 | |
| 533 | if (syserror(tcp)) |
| 534 | return 0; |
| 535 | |
Denys Vlasenko | 5d64581 | 2011-08-20 12:48:18 +0200 | [diff] [blame] | 536 | nfds = tcp->u_rval; |
| 537 | if (nfds == 0) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 538 | tcp->auxstr = "Timeout"; |
| 539 | return RVAL_STR; |
| 540 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 541 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 542 | fds = malloc(fdsize); |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 543 | if (!fds) |
| 544 | die_out_of_memory(); |
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 | outptr = outstr; |
| 547 | sep = ""; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 548 | for (i = 0; i < 3; i++) { |
| 549 | int first = 1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 550 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 551 | arg = args[i+1]; |
Denys Vlasenko | 1d46ba5 | 2011-08-31 14:00:02 +0200 | [diff] [blame] | 552 | if (!arg || umoven(tcp, arg, fdsize, (char *) fds) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 553 | continue; |
| 554 | for (j = 0; j < args[0]; j++) { |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 555 | if (FD_ISSET(j, fds)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 556 | /* +2 chars needed at the end: ']',NUL */ |
| 557 | if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) { |
| 558 | if (first) { |
| 559 | outptr += sprintf(outptr, "%s%s [%u", |
| 560 | sep, |
| 561 | i == 0 ? "in" : i == 1 ? "out" : "except", |
| 562 | j |
| 563 | ); |
| 564 | first = 0; |
| 565 | sep = ", "; |
| 566 | } |
| 567 | else { |
| 568 | outptr += sprintf(outptr, " %u", j); |
| 569 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 570 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 571 | nfds--; |
| 572 | } |
| 573 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 574 | if (outptr != outstr) |
| 575 | *outptr++ = ']'; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 | /* This contains no useful information on SunOS. */ |
| 581 | if (args[4]) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 582 | if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 583 | outptr += sprintf(outptr, "%sleft ", sep); |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 584 | outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0); |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 585 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 586 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 587 | *outptr = '\0'; |
Denys Vlasenko | 1161725 | 2011-09-01 11:27:37 +0200 | [diff] [blame] | 588 | tcp->auxstr = outstr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 589 | return RVAL_STR; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 590 | #undef end_outstr |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 591 | } |
| 592 | return 0; |
| 593 | } |
| 594 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 595 | |
| 596 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 597 | sys_oldselect(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 598 | { |
| 599 | long args[5]; |
| 600 | |
| 601 | if (umoven(tcp, tcp->u_arg[0], sizeof args, (char *) args) < 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 602 | tprints("[...]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 603 | return 0; |
| 604 | } |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 605 | return decode_select(tcp, args, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 606 | } |
| 607 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 608 | #ifdef ALPHA |
Roland McGrath | e948faf | 2002-12-15 23:58:18 +0000 | [diff] [blame] | 609 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 610 | sys_osf_select(struct tcb *tcp) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 611 | { |
| 612 | long *args = tcp->u_arg; |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 613 | return decode_select(tcp, args, BITNESS_32); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 614 | } |
| 615 | #endif |
| 616 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 617 | static const struct xlat epollctls[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 618 | #ifdef EPOLL_CTL_ADD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 619 | { EPOLL_CTL_ADD, "EPOLL_CTL_ADD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 620 | #endif |
| 621 | #ifdef EPOLL_CTL_MOD |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 622 | { EPOLL_CTL_MOD, "EPOLL_CTL_MOD" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 623 | #endif |
| 624 | #ifdef EPOLL_CTL_DEL |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 625 | { EPOLL_CTL_DEL, "EPOLL_CTL_DEL" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 626 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 627 | { 0, NULL } |
| 628 | }; |
| 629 | |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 630 | static const struct xlat epollevents[] = { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 631 | #ifdef EPOLLIN |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 632 | { EPOLLIN, "EPOLLIN" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 633 | #endif |
| 634 | #ifdef EPOLLPRI |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 635 | { EPOLLPRI, "EPOLLPRI" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 636 | #endif |
| 637 | #ifdef EPOLLOUT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 638 | { EPOLLOUT, "EPOLLOUT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 639 | #endif |
| 640 | #ifdef EPOLLRDNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 641 | { EPOLLRDNORM, "EPOLLRDNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 642 | #endif |
| 643 | #ifdef EPOLLRDBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 644 | { EPOLLRDBAND, "EPOLLRDBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 645 | #endif |
| 646 | #ifdef EPOLLWRNORM |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 647 | { EPOLLWRNORM, "EPOLLWRNORM" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 648 | #endif |
| 649 | #ifdef EPOLLWRBAND |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 650 | { EPOLLWRBAND, "EPOLLWRBAND" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 651 | #endif |
| 652 | #ifdef EPOLLMSG |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 653 | { EPOLLMSG, "EPOLLMSG" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 654 | #endif |
| 655 | #ifdef EPOLLERR |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 656 | { EPOLLERR, "EPOLLERR" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 657 | #endif |
| 658 | #ifdef EPOLLHUP |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 659 | { EPOLLHUP, "EPOLLHUP" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 660 | #endif |
Dmitry V. Levin | 5967c1a | 2011-10-11 15:55:40 +0000 | [diff] [blame] | 661 | #ifdef EPOLLRDHUP |
| 662 | { EPOLLRDHUP, "EPOLLRDHUP" }, |
| 663 | #endif |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 664 | #ifdef EPOLLONESHOT |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 665 | { EPOLLONESHOT, "EPOLLONESHOT" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 666 | #endif |
| 667 | #ifdef EPOLLET |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 668 | { EPOLLET, "EPOLLET" }, |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 669 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 670 | { 0, NULL } |
| 671 | }; |
| 672 | |
| 673 | int |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 674 | sys_epoll_create(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 675 | { |
| 676 | if (entering(tcp)) |
| 677 | tprintf("%ld", tcp->u_arg[0]); |
| 678 | return 0; |
| 679 | } |
| 680 | |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 681 | static const struct xlat epollflags[] = { |
| 682 | #ifdef EPOLL_CLOEXEC |
| 683 | { EPOLL_CLOEXEC, "EPOLL_CLOEXEC" }, |
| 684 | #endif |
| 685 | #ifdef EPOLL_NONBLOCK |
| 686 | { EPOLL_NONBLOCK, "EPOLL_NONBLOCK" }, |
| 687 | #endif |
| 688 | { 0, NULL } |
| 689 | }; |
| 690 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 691 | int |
| 692 | sys_epoll_create1(struct tcb *tcp) |
| 693 | { |
| 694 | if (entering(tcp)) |
Mike Frysinger | aed334c | 2011-10-13 22:33:45 -0400 | [diff] [blame] | 695 | printflags(epollflags, tcp->u_arg[0], "EPOLL_???"); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 696 | return 0; |
| 697 | } |
| 698 | |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 699 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 700 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 701 | print_epoll_event(struct epoll_event *ev) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 702 | { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 703 | tprints("{"); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 704 | printflags(epollevents, ev->events, "EPOLL???"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 705 | /* We cannot know what format the program uses, so print u32 and u64 |
| 706 | which will cover every value. */ |
| 707 | tprintf(", {u32=%" PRIu32 ", u64=%" PRIu64 "}}", |
| 708 | ev->data.u32, ev->data.u64); |
| 709 | } |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 710 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 711 | |
| 712 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 713 | sys_epoll_ctl(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 714 | { |
| 715 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 716 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 717 | tprints(", "); |
Denys Vlasenko | adedb51 | 2008-12-30 18:47:55 +0000 | [diff] [blame] | 718 | printxval(epollctls, tcp->u_arg[1], "EPOLL_CTL_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 719 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 720 | printfd(tcp, tcp->u_arg[2]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 721 | tprints(", "); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 722 | if (tcp->u_arg[3] == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 723 | tprints("NULL"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 724 | else { |
| 725 | #ifdef HAVE_SYS_EPOLL_H |
| 726 | struct epoll_event ev; |
Roland McGrath | 6e52d23 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 727 | if (umove(tcp, tcp->u_arg[3], &ev) == 0) |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 728 | print_epoll_event(&ev); |
| 729 | else |
| 730 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 731 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 732 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 733 | } |
| 734 | return 0; |
| 735 | } |
| 736 | |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 737 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 738 | epoll_wait_common(struct tcb *tcp) |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 739 | { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 740 | if (entering(tcp)) { |
| 741 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 742 | tprints(", "); |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 743 | } else { |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 744 | if (syserror(tcp)) |
| 745 | tprintf("%lx", tcp->u_arg[1]); |
| 746 | else if (tcp->u_rval == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 747 | tprints("{}"); |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 748 | else { |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 749 | #ifdef HAVE_SYS_EPOLL_H |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 750 | struct epoll_event ev, *start, *cur, *end; |
| 751 | int failed = 0; |
| 752 | |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 753 | tprints("{"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 754 | start = (struct epoll_event *) tcp->u_arg[1]; |
| 755 | end = start + tcp->u_rval; |
| 756 | for (cur = start; cur < end; ++cur) { |
| 757 | if (cur > start) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 758 | tprints(", "); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 759 | if (umove(tcp, (long) cur, &ev) == 0) |
| 760 | print_epoll_event(&ev); |
| 761 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 762 | tprints("?"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 763 | failed = 1; |
| 764 | break; |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 765 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 766 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 767 | tprints("}"); |
Roland McGrath | aa524c8 | 2005-06-01 19:22:06 +0000 | [diff] [blame] | 768 | if (failed) |
| 769 | tprintf(" %#lx", (long) start); |
| 770 | #else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 771 | tprints("{...}"); |
Roland McGrath | 63d6e54 | 2004-10-20 02:17:41 +0000 | [diff] [blame] | 772 | #endif |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 773 | } |
Dmitry V. Levin | c327d71 | 2011-10-11 16:05:57 +0000 | [diff] [blame] | 774 | 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] | 775 | } |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 779 | sys_epoll_wait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 780 | { |
| 781 | epoll_wait_common(tcp); |
| 782 | return 0; |
| 783 | } |
| 784 | |
| 785 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 786 | sys_epoll_pwait(struct tcb *tcp) |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 787 | { |
| 788 | epoll_wait_common(tcp); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 789 | if (exiting(tcp)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 790 | tprints(", "); |
Roland McGrath | f240005 | 2007-08-02 01:13:26 +0000 | [diff] [blame] | 791 | print_sigset(tcp, tcp->u_arg[4], 0); |
Dmitry V. Levin | 9676499 | 2010-04-06 23:54:18 +0000 | [diff] [blame] | 792 | } |
Roland McGrath | 93817bf | 2004-10-06 22:23:31 +0000 | [diff] [blame] | 793 | return 0; |
| 794 | } |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 795 | |
| 796 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 797 | sys_io_setup(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 798 | { |
| 799 | if (entering(tcp)) |
| 800 | tprintf("%ld, ", tcp->u_arg[0]); |
| 801 | else { |
| 802 | if (syserror(tcp)) |
| 803 | tprintf("0x%0lx", tcp->u_arg[1]); |
| 804 | else { |
| 805 | unsigned long user_id; |
| 806 | if (umove(tcp, tcp->u_arg[1], &user_id) == 0) |
| 807 | tprintf("{%lu}", user_id); |
| 808 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 809 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 810 | } |
| 811 | } |
| 812 | return 0; |
| 813 | } |
| 814 | |
| 815 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 816 | sys_io_destroy(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 817 | { |
| 818 | if (entering(tcp)) |
| 819 | tprintf("%lu", tcp->u_arg[0]); |
| 820 | return 0; |
| 821 | } |
| 822 | |
Dmitry V. Levin | 081e72f | 2011-06-21 15:11:57 +0000 | [diff] [blame] | 823 | #ifdef HAVE_LIBAIO_H |
| 824 | |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 825 | enum iocb_sub { |
| 826 | SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR |
| 827 | }; |
| 828 | |
| 829 | static const char * |
| 830 | iocb_cmd_lookup(unsigned cmd, enum iocb_sub *sub) |
| 831 | { |
Denys Vlasenko | 7999262 | 2011-08-19 19:44:17 +0200 | [diff] [blame] | 832 | static char buf[sizeof("%u /* SUB_??? */") + sizeof(int)*3]; |
| 833 | static const struct { |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 834 | const char *name; |
| 835 | enum iocb_sub sub; |
| 836 | } cmds[] = { |
| 837 | { "pread", SUB_COMMON }, |
| 838 | { "pwrite", SUB_COMMON }, |
| 839 | { "fsync", SUB_NONE }, |
| 840 | { "fdsync", SUB_NONE }, |
| 841 | { "op4", SUB_NONE }, |
| 842 | { "poll", SUB_POLL }, |
| 843 | { "noop", SUB_NONE }, |
| 844 | { "preadv", SUB_VECTOR }, |
| 845 | { "pwritev", SUB_VECTOR }, |
| 846 | }; |
| 847 | |
| 848 | if (cmd < ARRAY_SIZE(cmds)) { |
| 849 | *sub = cmds[cmd].sub; |
| 850 | return cmds[cmd].name; |
| 851 | } |
| 852 | *sub = SUB_NONE; |
Denys Vlasenko | 7999262 | 2011-08-19 19:44:17 +0200 | [diff] [blame] | 853 | sprintf(buf, "%u /* SUB_??? */", cmd); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 854 | return buf; |
| 855 | } |
| 856 | |
| 857 | /* Not defined in libaio.h */ |
| 858 | #ifndef IOCB_RESFD |
| 859 | # define IOCB_RESFD (1 << 0) |
| 860 | #endif |
| 861 | |
| 862 | static void |
| 863 | print_common_flags(struct iocb *iocb) |
| 864 | { |
| 865 | if (iocb->u.c.flags & IOCB_RESFD) |
| 866 | tprintf("resfd=%d, ", iocb->u.c.resfd); |
| 867 | if (iocb->u.c.flags & ~IOCB_RESFD) |
| 868 | tprintf("flags=%x, ", iocb->u.c.flags); |
| 869 | } |
Dmitry V. Levin | 081e72f | 2011-06-21 15:11:57 +0000 | [diff] [blame] | 870 | |
| 871 | #endif /* HAVE_LIBAIO_H */ |
| 872 | |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 873 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 874 | sys_io_submit(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 875 | { |
| 876 | long nr; |
| 877 | if (entering(tcp)) { |
| 878 | tprintf("%lu, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 879 | nr = tcp->u_arg[1]; |
| 880 | /* and if nr is negative? */ |
| 881 | if (nr == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 882 | tprints("{}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 883 | else { |
| 884 | #ifdef HAVE_LIBAIO_H |
| 885 | long i; |
| 886 | struct iocb *iocbp, **iocbs = (void *)tcp->u_arg[2]; |
| 887 | |
| 888 | for (i = 0; i < nr; i++, iocbs++) { |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 889 | enum iocb_sub sub; |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 890 | struct iocb iocb; |
| 891 | if (i == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 892 | tprints("{"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 893 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 894 | tprints(", "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 895 | |
| 896 | if (umove(tcp, (unsigned long)iocbs, &iocbp) || |
| 897 | umove(tcp, (unsigned long)iocbp, &iocb)) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 898 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 899 | continue; |
| 900 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 901 | tprints("{"); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 902 | if (iocb.data) |
| 903 | tprintf("data:%p, ", iocb.data); |
| 904 | if (iocb.key) |
| 905 | tprintf("key:%u, ", iocb.key); |
| 906 | tprintf("%s, ", iocb_cmd_lookup(iocb.aio_lio_opcode, &sub)); |
| 907 | if (iocb.aio_reqprio) |
| 908 | tprintf("reqprio:%d, ", iocb.aio_reqprio); |
| 909 | tprintf("filedes:%d", iocb.aio_fildes); |
| 910 | switch (sub) { |
| 911 | case SUB_COMMON: |
| 912 | if (iocb.aio_lio_opcode == IO_CMD_PWRITE) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 913 | tprints(", str:"); |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 914 | printstr(tcp, (unsigned long)iocb.u.c.buf, |
| 915 | iocb.u.c.nbytes); |
| 916 | } else { |
| 917 | tprintf(", buf:%p", iocb.u.c.buf); |
| 918 | } |
| 919 | tprintf(", nbytes:%lu, offset:%llx", |
| 920 | iocb.u.c.nbytes, |
| 921 | iocb.u.c.offset); |
| 922 | print_common_flags(&iocb); |
| 923 | break; |
| 924 | case SUB_VECTOR: |
| 925 | tprintf(", %llx, ", iocb.u.v.offset); |
| 926 | print_common_flags(&iocb); |
| 927 | tprint_iov(tcp, iocb.u.v.nr, |
| 928 | (unsigned long)iocb.u.v.vec, |
| 929 | iocb.aio_lio_opcode == IO_CMD_PWRITEV); |
| 930 | break; |
| 931 | case SUB_POLL: |
| 932 | tprintf(", %x", iocb.u.poll.events); |
| 933 | break; |
| 934 | case SUB_NONE: |
| 935 | break; |
| 936 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 937 | tprints("}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 938 | } |
| 939 | if (i) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 940 | tprints("}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 941 | #else |
Andi Kleen | dfcd741 | 2011-06-13 22:05:44 +0000 | [diff] [blame] | 942 | #warning "libaio-devel is not available => no io_submit decoding" |
| 943 | tprintf("%#lx", tcp->u_arg[2]); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 944 | #endif |
| 945 | } |
| 946 | } |
| 947 | return 0; |
| 948 | } |
| 949 | |
| 950 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 951 | sys_io_cancel(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 952 | { |
| 953 | if (entering(tcp)) { |
| 954 | #ifdef HAVE_LIBAIO_H |
| 955 | struct iocb iocb; |
| 956 | #endif |
| 957 | tprintf("%lu, ", tcp->u_arg[0]); |
| 958 | #ifdef HAVE_LIBAIO_H |
| 959 | if (umove(tcp, tcp->u_arg[1], &iocb) == 0) { |
| 960 | tprintf("{%p, %u, %hu, %hu, %d}, ", |
| 961 | iocb.data, iocb.key, |
| 962 | iocb.aio_lio_opcode, |
| 963 | iocb.aio_reqprio, iocb.aio_fildes); |
| 964 | } else |
| 965 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 966 | tprints("{...}, "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 967 | } else { |
| 968 | if (tcp->u_rval < 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 969 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 970 | else { |
| 971 | #ifdef HAVE_LIBAIO_H |
| 972 | struct io_event event; |
| 973 | if (umove(tcp, tcp->u_arg[2], &event) == 0) |
| 974 | tprintf("{%p, %p, %ld, %ld}", |
| 975 | event.data, event.obj, |
| 976 | event.res, event.res2); |
Dmitry V. Levin | 414fe7d | 2009-07-08 11:21:17 +0000 | [diff] [blame] | 977 | else |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 978 | #endif |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 979 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 980 | } |
| 981 | } |
| 982 | return 0; |
| 983 | } |
| 984 | |
| 985 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 986 | sys_io_getevents(struct tcb *tcp) |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 987 | { |
| 988 | if (entering(tcp)) { |
| 989 | tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1], |
| 990 | tcp->u_arg[2]); |
| 991 | } else { |
| 992 | if (tcp->u_rval == 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 993 | tprints("{}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 994 | } else { |
| 995 | #ifdef HAVE_LIBAIO_H |
| 996 | struct io_event *events = (void *)tcp->u_arg[3]; |
| 997 | long i, nr = tcp->u_rval; |
| 998 | |
| 999 | for (i = 0; i < nr; i++, events++) { |
| 1000 | struct io_event event; |
| 1001 | |
| 1002 | if (i == 0) |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1003 | tprints("{"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1004 | else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1005 | tprints(", "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1006 | |
| 1007 | if (umove(tcp, (unsigned long)events, &event) != 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1008 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1009 | continue; |
| 1010 | } |
| 1011 | tprintf("{%p, %p, %ld, %ld}", event.data, |
| 1012 | event.obj, event.res, event.res2); |
| 1013 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1014 | tprints("}, "); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1015 | #else |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1016 | tprints("{...}"); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1017 | #endif |
| 1018 | } |
| 1019 | |
Roland McGrath | 6bc09da | 2007-11-01 21:50:54 +0000 | [diff] [blame] | 1020 | print_timespec(tcp, tcp->u_arg[4]); |
Roland McGrath | 37b9f84 | 2005-05-09 08:02:00 +0000 | [diff] [blame] | 1021 | } |
| 1022 | return 0; |
| 1023 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1024 | |
| 1025 | int |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 1026 | sys_select(struct tcb *tcp) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1027 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 1028 | return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 1029 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1030 | |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1031 | int |
| 1032 | sys_pselect6(struct tcb *tcp) |
| 1033 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 1034 | int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 1035 | if (entering(tcp)) { |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1036 | struct { |
| 1037 | void *ss; |
| 1038 | unsigned long len; |
| 1039 | } data; |
| 1040 | if (umove(tcp, tcp->u_arg[5], &data) < 0) |
| 1041 | tprintf(", %#lx", tcp->u_arg[5]); |
| 1042 | else { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1043 | tprints(", {"); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 1044 | if (data.len < sizeof(long)) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 1045 | tprintf("%#lx", (long)data.ss); |
| 1046 | else |
| 1047 | print_sigset(tcp, (long)data.ss, 0); |
| 1048 | tprintf(", %lu}", data.len); |
| 1049 | } |
| 1050 | } |
| 1051 | return rc; |
| 1052 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1053 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1054 | static int |
| 1055 | do_eventfd(struct tcb *tcp, int flags_arg) |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1056 | { |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1057 | if (entering(tcp)) { |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1058 | tprintf("%lu", tcp->u_arg[0]); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1059 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 1060 | tprints(", "); |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1061 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
| 1062 | } |
| 1063 | } |
Roland McGrath | e7c3967 | 2007-08-02 01:32:17 +0000 | [diff] [blame] | 1064 | return 0; |
| 1065 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 1066 | |
| 1067 | int |
| 1068 | sys_eventfd(struct tcb *tcp) |
| 1069 | { |
| 1070 | return do_eventfd(tcp, -1); |
| 1071 | } |
| 1072 | |
| 1073 | int |
| 1074 | sys_eventfd2(struct tcb *tcp) |
| 1075 | { |
| 1076 | return do_eventfd(tcp, 1); |
| 1077 | } |