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