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