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> |
| 34 | |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 35 | #include "xlat/fcntlcmds.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 36 | #include "xlat/fdflags.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 37 | #include "xlat/flockcmds.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 38 | #include "xlat/lockfcmds.h" |
Dmitry V. Levin | 0ed617b | 2014-04-25 23:30:54 +0000 | [diff] [blame] | 39 | #include "xlat/notifyflags.h" |
Ben Noordhuis | 88eafd8 | 2013-02-04 00:04:57 +0100 | [diff] [blame] | 40 | |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 41 | /* |
| 42 | * Assume that F_SETLK64, F_SETLKW64, and F_GETLK64 are either defined |
| 43 | * or not defined altogether. |
| 44 | */ |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 45 | #if defined(F_SETLK64) && F_SETLK64 + 0 != F_SETLK |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 46 | # define USE_PRINTFLOCK64 1 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 47 | #else |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 48 | # define USE_PRINTFLOCK64 0 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 49 | #endif |
| 50 | |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 51 | #if USE_PRINTFLOCK64 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 52 | |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 53 | # ifndef HAVE_STRUCT_FLOCK64 |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 54 | struct flock64 { |
| 55 | short int l_type, l_whence; |
| 56 | int64_t l_start, l_len; |
| 57 | int l_pid; |
| 58 | }; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 59 | # endif |
Dmitry V. Levin | 594eb8f | 2013-11-12 21:49:03 +0000 | [diff] [blame] | 60 | |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 61 | static void |
| 62 | printflock64(struct tcb *tcp, long addr, int getlk) |
| 63 | { |
| 64 | struct flock64 fl; |
| 65 | |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 66 | if (umove_or_printaddr(tcp, addr, &fl)) |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 67 | return; |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 68 | tprints("{type="); |
| 69 | printxval(lockfcmds, fl.l_type, "F_???"); |
| 70 | tprints(", whence="); |
| 71 | printxval(whence_codes, fl.l_whence, "SEEK_???"); |
| 72 | tprintf(", start=%lld, len=%lld", (long long) fl.l_start, (long long) fl.l_len); |
| 73 | if (getlk) |
| 74 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 75 | else |
| 76 | tprints("}"); |
| 77 | } |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 78 | #endif /* USE_PRINTFLOCK64 */ |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 79 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 80 | static void |
Denys Vlasenko | 30b5e5a | 2009-01-06 15:12:52 +0000 | [diff] [blame] | 81 | printflock(struct tcb *tcp, long addr, int getlk) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 82 | { |
| 83 | struct flock fl; |
| 84 | |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 85 | #if SUPPORTED_PERSONALITIES > 1 |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 86 | if ( |
| 87 | # if SIZEOF_OFF_T > SIZEOF_LONG |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 88 | current_personality != DEFAULT_PERSONALITY && |
| 89 | # endif |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 90 | current_wordsize != sizeof(fl.l_start)) { |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 91 | if (current_wordsize == 4) { |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 92 | /* 32-bit x86 app on x86_64 and similar cases */ |
| 93 | struct { |
| 94 | short int l_type; |
| 95 | short int l_whence; |
| 96 | int32_t l_start; /* off_t */ |
| 97 | int32_t l_len; /* off_t */ |
| 98 | int32_t l_pid; /* pid_t */ |
| 99 | } fl32; |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 100 | if (umove_or_printaddr(tcp, addr, &fl32)) |
| 101 | return; |
| 102 | fl.l_type = fl32.l_type; |
| 103 | fl.l_whence = fl32.l_whence; |
| 104 | fl.l_start = fl32.l_start; |
| 105 | fl.l_len = fl32.l_len; |
| 106 | fl.l_pid = fl32.l_pid; |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 107 | } else { |
| 108 | /* let people know we have a problem here */ |
Denys Vlasenko | 751acb3 | 2013-02-08 15:34:46 +0100 | [diff] [blame] | 109 | tprintf("<decode error: unsupported wordsize %d>", |
Denys Vlasenko | 9fd4f96 | 2012-03-19 09:36:42 +0100 | [diff] [blame] | 110 | current_wordsize); |
Denys Vlasenko | 7a862d7 | 2009-04-15 13:22:59 +0000 | [diff] [blame] | 111 | return; |
| 112 | } |
| 113 | } else |
| 114 | #endif |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 115 | if (umove_or_printaddr(tcp, addr, &fl)) |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 116 | return; |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 117 | tprints("{type="); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 118 | printxval(lockfcmds, fl.l_type, "F_???"); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 119 | tprints(", whence="); |
Denys Vlasenko | 86738a2 | 2013-02-17 14:31:55 +0100 | [diff] [blame] | 120 | printxval(whence_codes, fl.l_whence, "SEEK_???"); |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 121 | #if SIZEOF_OFF_T > SIZEOF_LONG |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 122 | tprintf(", start=%lld, len=%lld", fl.l_start, fl.l_len); |
| 123 | #else |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 124 | tprintf(", start=%ld, len=%ld", fl.l_start, fl.l_len); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 125 | #endif |
Dmitry V. Levin | 0eeda2c | 2013-05-01 16:37:08 +0000 | [diff] [blame] | 126 | if (getlk) |
| 127 | tprintf(", pid=%lu}", (unsigned long) fl.l_pid); |
| 128 | else |
| 129 | tprints("}"); |
| 130 | } |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 131 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 132 | SYS_FUNC(fcntl) |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 133 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 134 | if (entering(tcp)) { |
Dmitry V. Levin | 3138213 | 2011-03-04 05:08:02 +0300 | [diff] [blame] | 135 | printfd(tcp, tcp->u_arg[0]); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 136 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 137 | printxval(fcntlcmds, tcp->u_arg[1], "F_???"); |
| 138 | switch (tcp->u_arg[1]) { |
| 139 | case F_SETFD: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 140 | tprints(", "); |
Roland McGrath | b2dee13 | 2005-06-01 19:02:36 +0000 | [diff] [blame] | 141 | printflags(fdflags, tcp->u_arg[2], "FD_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 142 | break; |
| 143 | case F_SETOWN: case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 144 | #ifdef F_DUPFD_CLOEXEC |
| 145 | case F_DUPFD_CLOEXEC: |
| 146 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 147 | tprintf(", %ld", tcp->u_arg[2]); |
| 148 | break; |
| 149 | case F_SETFL: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 150 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 151 | tprint_open_modes(tcp->u_arg[2]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 152 | break; |
| 153 | case F_SETLK: case F_SETLKW: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 154 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 155 | printflock(tcp, tcp->u_arg[2], 0); |
| 156 | break; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 157 | #if USE_PRINTFLOCK64 |
| 158 | case F_SETLK64: case F_SETLKW64: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 159 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 160 | printflock64(tcp, tcp->u_arg[2], 0); |
| 161 | break; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 162 | #endif /* USE_PRINTFLOCK64 */ |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 163 | #ifdef F_NOTIFY |
| 164 | case F_NOTIFY: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 165 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 166 | printflags(notifyflags, tcp->u_arg[2], "DN_???"); |
| 167 | break; |
| 168 | #endif |
| 169 | #ifdef F_SETLEASE |
| 170 | case F_SETLEASE: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 171 | tprints(", "); |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 172 | printxval(lockfcmds, tcp->u_arg[2], "F_???"); |
| 173 | break; |
| 174 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 175 | } |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 176 | } else { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 177 | switch (tcp->u_arg[1]) { |
| 178 | case F_DUPFD: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 179 | #ifdef F_DUPFD_CLOEXEC |
| 180 | case F_DUPFD_CLOEXEC: |
| 181 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 182 | case F_SETFD: case F_SETFL: |
| 183 | case F_SETLK: case F_SETLKW: |
| 184 | case F_SETOWN: case F_GETOWN: |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 185 | #ifdef F_NOTIFY |
| 186 | case F_NOTIFY: |
| 187 | #endif |
| 188 | #ifdef F_SETLEASE |
| 189 | case F_SETLEASE: |
| 190 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 191 | break; |
| 192 | case F_GETFD: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 193 | if (syserror(tcp) || tcp->u_rval == 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 194 | return 0; |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 195 | tcp->auxstr = sprintflags("flags ", fdflags, tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 196 | return RVAL_HEX|RVAL_STR; |
| 197 | case F_GETFL: |
Dmitry V. Levin | 21a7534 | 2008-09-03 01:22:18 +0000 | [diff] [blame] | 198 | if (syserror(tcp)) |
| 199 | return 0; |
Dmitry V. Levin | 9b5b67e | 2007-01-11 23:19:55 +0000 | [diff] [blame] | 200 | tcp->auxstr = sprint_open_modes(tcp->u_rval); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 201 | return RVAL_HEX|RVAL_STR; |
| 202 | case F_GETLK: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 203 | tprints(", "); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 204 | printflock(tcp, tcp->u_arg[2], 1); |
| 205 | break; |
Dmitry V. Levin | 54cabef | 2014-03-03 23:09:47 +0000 | [diff] [blame] | 206 | #if USE_PRINTFLOCK64 |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 207 | case F_GETLK64: |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 208 | tprints(", "); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 209 | printflock64(tcp, tcp->u_arg[2], 1); |
| 210 | break; |
| 211 | #endif |
Denys Vlasenko | eedaac7 | 2009-03-10 20:41:58 +0000 | [diff] [blame] | 212 | #ifdef F_GETLEASE |
| 213 | case F_GETLEASE: |
| 214 | if (syserror(tcp)) |
| 215 | return 0; |
| 216 | tcp->auxstr = xlookup(lockfcmds, tcp->u_rval); |
| 217 | return RVAL_HEX|RVAL_STR; |
| 218 | #endif |
Denys Vlasenko | 5ae2b7c | 2009-02-27 20:32:52 +0000 | [diff] [blame] | 219 | default: |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 220 | tprintf(", %#lx", tcp->u_arg[2]); |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | return 0; |
| 225 | } |
| 226 | |
| 227 | #ifdef LOCK_SH |
| 228 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 229 | SYS_FUNC(flock) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 230 | { |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 231 | printfd(tcp, tcp->u_arg[0]); |
| 232 | tprints(", "); |
| 233 | printflags(flockcmds, tcp->u_arg[1], "LOCK_???"); |
| 234 | |
| 235 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 236 | } |
| 237 | #endif /* LOCK_SH */ |
| 238 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 239 | SYS_FUNC(close) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 240 | { |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 241 | printfd(tcp, tcp->u_arg[0]); |
| 242 | |
| 243 | return RVAL_DECODED; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 246 | SYS_FUNC(dup) |
Zubin Mithra | 64aa1b1 | 2014-06-04 08:30:41 +0530 | [diff] [blame] | 247 | { |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 248 | printfd(tcp, tcp->u_arg[0]); |
| 249 | |
| 250 | return RVAL_DECODED | RVAL_FD; |
Zubin Mithra | 64aa1b1 | 2014-06-04 08:30:41 +0530 | [diff] [blame] | 251 | } |
| 252 | |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 253 | static int |
| 254 | do_dup2(struct tcb *tcp, int flags_arg) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 255 | { |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 256 | printfd(tcp, tcp->u_arg[0]); |
| 257 | tprints(", "); |
| 258 | printfd(tcp, tcp->u_arg[1]); |
| 259 | if (flags_arg >= 0) { |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 260 | tprints(", "); |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 261 | printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 262 | } |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 263 | |
| 264 | return RVAL_DECODED | RVAL_FD; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 265 | } |
| 266 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 267 | SYS_FUNC(dup2) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 268 | { |
| 269 | return do_dup2(tcp, -1); |
| 270 | } |
| 271 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 272 | SYS_FUNC(dup3) |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 273 | { |
| 274 | return do_dup2(tcp, 2); |
| 275 | } |
Dmitry V. Levin | 4371b10 | 2008-11-10 22:53:02 +0000 | [diff] [blame] | 276 | |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 277 | #if defined(ALPHA) |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 278 | SYS_FUNC(getdtablesize) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 279 | { |
| 280 | return 0; |
| 281 | } |
Denys Vlasenko | 8470374 | 2012-02-25 02:38:52 +0100 | [diff] [blame] | 282 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 283 | |
Dmitry V. Levin | c2982b5 | 2013-11-05 23:00:22 +0000 | [diff] [blame] | 284 | static int |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 285 | decode_select(struct tcb *tcp, long *args, enum bitness_t bitness) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 286 | { |
Denys Vlasenko | ad5155a | 2011-09-01 18:18:04 +0200 | [diff] [blame] | 287 | int i, j; |
Denys Vlasenko | 1f65c3c | 2013-11-05 16:20:16 +0100 | [diff] [blame] | 288 | int nfds, fdsize; |
Dmitry V. Levin | 6522f13 | 2014-09-09 22:42:12 +0000 | [diff] [blame] | 289 | fd_set *fds = NULL; |
Dmitry V. Levin | 30145dd | 2010-09-06 22:08:24 +0000 | [diff] [blame] | 290 | const char *sep; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 291 | long arg; |
| 292 | |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 293 | /* Kernel truncates arg[0] to int, we do the same. */ |
| 294 | nfds = (int) args[0]; |
| 295 | |
| 296 | /* Kernel rejects negative nfds, so we don't parse it either. */ |
Dmitry V. Levin | 6522f13 | 2014-09-09 22:42:12 +0000 | [diff] [blame] | 297 | if (nfds < 0) |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 298 | nfds = 0; |
Dmitry V. Levin | 6522f13 | 2014-09-09 22:42:12 +0000 | [diff] [blame] | 299 | |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 300 | /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */ |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 301 | if (nfds > 1024*1024) |
| 302 | nfds = 1024*1024; |
| 303 | |
| 304 | /* |
| 305 | * 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] | 306 | * Instead of args[0], use nfds for fd count, fdsize for array lengths. |
| 307 | */ |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 308 | fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize; |
Denys Vlasenko | 79a79ea | 2011-09-01 16:35:44 +0200 | [diff] [blame] | 309 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 310 | if (entering(tcp)) { |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 311 | tprintf("%d", (int) args[0]); |
| 312 | |
Dmitry V. Levin | 3e9d71f | 2015-05-25 20:41:02 +0000 | [diff] [blame] | 313 | if (verbose(tcp) && fdsize > 0) |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 314 | fds = malloc(fdsize); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 315 | for (i = 0; i < 3; i++) { |
| 316 | arg = args[i+1]; |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 317 | tprints(", "); |
Dmitry V. Levin | 2fc5d80 | 2015-01-28 01:26:04 +0000 | [diff] [blame] | 318 | if (!fds) { |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 319 | printaddr(arg); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 320 | continue; |
| 321 | } |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 322 | if (umoven_or_printaddr(tcp, arg, fdsize, fds)) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 323 | continue; |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 324 | tprints("["); |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 325 | for (j = 0, sep = "";; j++) { |
| 326 | j = next_set_bit(fds, j, nfds); |
| 327 | if (j < 0) |
| 328 | break; |
| 329 | tprints(sep); |
| 330 | printfd(tcp, j); |
| 331 | sep = " "; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 332 | } |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 333 | tprints("]"); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 334 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 335 | free(fds); |
Denys Vlasenko | 60fe8c1 | 2011-09-01 10:00:28 +0200 | [diff] [blame] | 336 | tprints(", "); |
Roland McGrath | 6afc565 | 2007-07-24 01:57:11 +0000 | [diff] [blame] | 337 | printtv_bitness(tcp, args[4], bitness, 0); |
Dmitry V. Levin | df0c18c | 2015-07-20 16:59:50 +0000 | [diff] [blame] | 338 | } else { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 339 | static char outstr[1024]; |
| 340 | char *outptr; |
| 341 | #define end_outstr (outstr + sizeof(outstr)) |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 342 | int ready_fds; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 343 | |
| 344 | if (syserror(tcp)) |
| 345 | return 0; |
| 346 | |
Dr. David Alan Gilbert | 025f108 | 2013-11-05 11:54:51 +0100 | [diff] [blame] | 347 | ready_fds = tcp->u_rval; |
| 348 | if (ready_fds == 0) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 349 | tcp->auxstr = "Timeout"; |
| 350 | return RVAL_STR; |
| 351 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 352 | |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 353 | fds = malloc(fdsize); |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 354 | |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 355 | outptr = outstr; |
| 356 | sep = ""; |
Dmitry V. Levin | f3696b3 | 2013-11-05 22:46:43 +0000 | [diff] [blame] | 357 | for (i = 0; i < 3 && ready_fds > 0; i++) { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 358 | int first = 1; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 359 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 360 | arg = args[i+1]; |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 361 | if (!arg || !fds || umoven(tcp, arg, fdsize, fds) < 0) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 362 | continue; |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 363 | for (j = 0;; j++) { |
| 364 | j = next_set_bit(fds, j, nfds); |
| 365 | if (j < 0) |
| 366 | break; |
| 367 | /* +2 chars needed at the end: ']',NUL */ |
| 368 | if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) { |
| 369 | if (first) { |
| 370 | outptr += sprintf(outptr, "%s%s [%u", |
| 371 | sep, |
| 372 | i == 0 ? "in" : i == 1 ? "out" : "except", |
| 373 | j |
| 374 | ); |
| 375 | first = 0; |
| 376 | sep = ", "; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 377 | } |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 378 | else { |
| 379 | outptr += sprintf(outptr, " %u", j); |
| 380 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 381 | } |
Denys Vlasenko | b338f2d | 2013-11-09 20:40:31 +0100 | [diff] [blame] | 382 | if (--ready_fds == 0) |
| 383 | break; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 384 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 385 | if (outptr != outstr) |
| 386 | *outptr++ = ']'; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 387 | } |
Roland McGrath | e85aaa4 | 2005-02-06 01:55:12 +0000 | [diff] [blame] | 388 | free(fds); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 389 | /* This contains no useful information on SunOS. */ |
| 390 | if (args[4]) { |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 391 | if (outptr < end_outstr - (10 + TIMEVAL_TEXT_BUFSIZE)) { |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 392 | outptr += sprintf(outptr, "%sleft ", sep); |
Denys Vlasenko | a1d541e | 2012-01-20 11:04:04 +0100 | [diff] [blame] | 393 | outptr = sprinttv(outptr, tcp, args[4], bitness, /*special:*/ 0); |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 394 | } |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 395 | } |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 396 | *outptr = '\0'; |
Denys Vlasenko | 1161725 | 2011-09-01 11:27:37 +0200 | [diff] [blame] | 397 | tcp->auxstr = outstr; |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 398 | return RVAL_STR; |
Denys Vlasenko | 2fb4db3 | 2011-08-31 12:26:03 +0200 | [diff] [blame] | 399 | #undef end_outstr |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 400 | } |
| 401 | return 0; |
| 402 | } |
| 403 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 404 | SYS_FUNC(oldselect) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 405 | { |
Elvira Khabirova | c44df3e | 2015-07-29 21:38:54 +0300 | [diff] [blame] | 406 | long long_args[5]; |
| 407 | #undef oldselect_args |
| 408 | #if SIZEOF_LONG == 4 |
| 409 | # define oldselect_args long_args |
| 410 | #else |
| 411 | unsigned int oldselect_args[5]; |
| 412 | unsigned int i; |
| 413 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 414 | |
Elvira Khabirova | c44df3e | 2015-07-29 21:38:54 +0300 | [diff] [blame] | 415 | if (umove(tcp, tcp->u_arg[0], &oldselect_args) < 0) { |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 416 | printaddr(tcp->u_arg[0]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 417 | return 0; |
| 418 | } |
Elvira Khabirova | c44df3e | 2015-07-29 21:38:54 +0300 | [diff] [blame] | 419 | #ifndef oldselect_args |
| 420 | for (i = 0; i < 5; i++) { |
| 421 | long_args[i] = oldselect_args[i]; |
| 422 | } |
| 423 | #endif |
| 424 | return decode_select(tcp, long_args, BITNESS_CURRENT); |
| 425 | #undef oldselect_args |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 426 | } |
| 427 | |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 428 | #ifdef ALPHA |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 429 | SYS_FUNC(osf_select) |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 430 | { |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 431 | return decode_select(tcp, tcp->u_arg, BITNESS_32); |
Wichert Akkerman | f5eeabb | 1999-11-18 17:09:47 +0000 | [diff] [blame] | 432 | } |
| 433 | #endif |
| 434 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 435 | SYS_FUNC(select) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 436 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 437 | return decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 438 | } |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 439 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 440 | SYS_FUNC(pselect6) |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 441 | { |
Dmitry V. Levin | a7945a3 | 2006-12-13 17:10:11 +0000 | [diff] [blame] | 442 | int rc = decode_select(tcp, tcp->u_arg, BITNESS_CURRENT); |
Roland McGrath | fe10aa7 | 2007-11-01 21:52:20 +0000 | [diff] [blame] | 443 | if (entering(tcp)) { |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame^] | 444 | unsigned long data[2]; |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 445 | |
| 446 | tprints(", "); |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame^] | 447 | if (!umove_ulong_array_or_printaddr(tcp, tcp->u_arg[5], data, |
| 448 | ARRAY_SIZE(data))) { |
Dmitry V. Levin | e6019fd | 2015-07-20 16:44:51 +0000 | [diff] [blame] | 449 | tprints("{"); |
Dmitry V. Levin | b172a94 | 2015-09-15 02:17:32 +0000 | [diff] [blame^] | 450 | /* NB: kernel requires data[1] == NSIG / 8 */ |
| 451 | print_sigset_addr_len(tcp, data[0], data[1]); |
| 452 | tprintf(", %lu}", data[1]); |
Dmitry V. Levin | 95ebf5a | 2006-10-13 20:25:12 +0000 | [diff] [blame] | 453 | } |
| 454 | } |
| 455 | return rc; |
| 456 | } |