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