Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +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> |
| 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
| 6 | * All rights reserved. |
| 7 | * |
| 8 | * Redistribution and use in source and binary forms, with or without |
| 9 | * modification, are permitted provided that the following conditions |
| 10 | * are met: |
| 11 | * 1. Redistributions of source code must retain the above copyright |
| 12 | * notice, this list of conditions and the following disclaimer. |
| 13 | * 2. Redistributions in binary form must reproduce the above copyright |
| 14 | * notice, this list of conditions and the following disclaimer in the |
| 15 | * documentation and/or other materials provided with the distribution. |
| 16 | * 3. The name of the author may not be used to endorse or promote products |
| 17 | * derived from this software without specific prior written permission. |
| 18 | * |
| 19 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 20 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 21 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 22 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 23 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 24 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 25 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 26 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 27 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 28 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include "defs.h" |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 32 | #include <linux/aio_abi.h> |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 33 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 34 | SYS_FUNC(io_setup) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 35 | { |
| 36 | if (entering(tcp)) |
Elvira Khabirova | afac9f0 | 2015-08-18 18:02:20 +0300 | [diff] [blame] | 37 | tprintf("%u, ", (unsigned int) tcp->u_arg[0]); |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 38 | else |
Dmitry V. Levin | 2479ef0 | 2015-08-18 14:58:27 +0000 | [diff] [blame] | 39 | printnum_ulong(tcp, tcp->u_arg[1]); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 40 | return 0; |
| 41 | } |
| 42 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 43 | SYS_FUNC(io_destroy) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 44 | { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 45 | tprintf("%lu", tcp->u_arg[0]); |
| 46 | |
| 47 | return RVAL_DECODED; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 48 | } |
| 49 | |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 50 | enum iocb_sub { |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 51 | SUB_NONE, SUB_COMMON, SUB_VECTOR |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 52 | }; |
| 53 | |
| 54 | static enum iocb_sub |
| 55 | tprint_lio_opcode(unsigned cmd) |
| 56 | { |
| 57 | static const struct { |
| 58 | const char *name; |
| 59 | enum iocb_sub sub; |
| 60 | } cmds[] = { |
| 61 | { "pread", SUB_COMMON }, |
| 62 | { "pwrite", SUB_COMMON }, |
| 63 | { "fsync", SUB_NONE }, |
| 64 | { "fdsync", SUB_NONE }, |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 65 | { "preadx", SUB_NONE }, |
| 66 | { "poll", SUB_NONE }, |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 67 | { "noop", SUB_NONE }, |
| 68 | { "preadv", SUB_VECTOR }, |
| 69 | { "pwritev", SUB_VECTOR }, |
| 70 | }; |
| 71 | |
| 72 | if (cmd < ARRAY_SIZE(cmds)) { |
| 73 | tprints(cmds[cmd].name); |
| 74 | return cmds[cmd].sub; |
| 75 | } |
| 76 | tprintf("%u /* SUB_??? */", cmd); |
| 77 | return SUB_NONE; |
| 78 | } |
| 79 | |
| 80 | static void |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 81 | print_common_flags(const struct iocb *cb) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 82 | { |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 83 | /* IOCB_FLAG_RESFD is available since v2.6.22-rc1~47 */ |
| 84 | #ifdef IOCB_FLAG_RESFD |
| 85 | if (cb->aio_flags & IOCB_FLAG_RESFD) |
| 86 | tprintf(", resfd=%d", cb->aio_resfd); |
| 87 | if (cb->aio_flags & ~IOCB_FLAG_RESFD) |
| 88 | tprintf(", flags=%x", cb->aio_flags); |
Dmitry V. Levin | b7dd5e6 | 2014-09-08 15:20:10 +0000 | [diff] [blame] | 89 | #endif |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 92 | static bool |
| 93 | iocb_is_valid(const struct iocb *cb) |
| 94 | { |
| 95 | return cb->aio_buf == (unsigned long) cb->aio_buf && |
| 96 | cb->aio_nbytes == (size_t) cb->aio_nbytes && |
| 97 | (ssize_t) cb->aio_nbytes >= 0; |
| 98 | } |
| 99 | |
| 100 | static enum iocb_sub |
| 101 | print_iocb_header(const struct iocb *cb) |
| 102 | { |
| 103 | enum iocb_sub sub; |
| 104 | |
| 105 | if (cb->aio_data) |
| 106 | tprintf("data=%#" PRIx64 ", ", |
| 107 | (uint64_t) cb->aio_data); |
| 108 | |
| 109 | if (cb->aio_key) |
| 110 | tprintf("key=%u, ", cb->aio_key); |
| 111 | |
| 112 | sub = tprint_lio_opcode(cb->aio_lio_opcode); |
| 113 | if (cb->aio_reqprio) |
| 114 | tprintf(", reqprio=%hd", cb->aio_reqprio); |
| 115 | |
| 116 | tprintf(", fildes=%d", cb->aio_fildes); |
| 117 | |
| 118 | return sub; |
| 119 | } |
| 120 | |
| 121 | static void |
| 122 | print_iocb(struct tcb *tcp, const struct iocb *cb) |
| 123 | { |
| 124 | enum iocb_sub sub = print_iocb_header(cb); |
| 125 | |
| 126 | switch (sub) { |
| 127 | case SUB_COMMON: |
| 128 | if (cb->aio_lio_opcode == 1 && iocb_is_valid(cb)) { |
| 129 | tprints(", str="); |
| 130 | printstr(tcp, (unsigned long) cb->aio_buf, |
| 131 | (unsigned long) cb->aio_nbytes); |
| 132 | } else { |
| 133 | tprintf(", buf=%#" PRIx64, (uint64_t) cb->aio_buf); |
| 134 | } |
| 135 | tprintf(", nbytes=%" PRIu64 ", offset=%" PRId64, |
| 136 | (uint64_t) cb->aio_nbytes, (int64_t) cb->aio_offset); |
| 137 | print_common_flags(cb); |
| 138 | break; |
| 139 | case SUB_VECTOR: |
| 140 | if (iocb_is_valid(cb)) { |
| 141 | tprints(", iovec="); |
| 142 | tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf, |
| 143 | cb->aio_lio_opcode == 8); |
| 144 | } else { |
| 145 | tprintf(", buf=%#" PRIx64 ", nbytes=%" PRIu64, |
| 146 | (uint64_t) cb->aio_buf, |
| 147 | (uint64_t) cb->aio_nbytes); |
| 148 | } |
| 149 | tprintf(", offset=%" PRId64, (int64_t) cb->aio_offset); |
| 150 | print_common_flags(cb); |
| 151 | break; |
| 152 | case SUB_NONE: |
| 153 | break; |
| 154 | } |
| 155 | } |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 156 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 157 | SYS_FUNC(io_submit) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 158 | { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 159 | long nr = tcp->u_arg[1]; |
| 160 | /* if nr <= 0, we end up printing just "[]" */ |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 161 | tprintf("%lu, %ld, [", tcp->u_arg[0], nr); |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 162 | { |
| 163 | long i; |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame] | 164 | long iocbs = tcp->u_arg[2]; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 165 | |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame] | 166 | for (i = 0; i < nr; ++i, iocbs += current_wordsize) { |
Dmitry V. Levin | 09a1a5a | 2015-09-14 23:02:29 +0000 | [diff] [blame] | 167 | unsigned long iocbp; |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 168 | struct iocb cb; |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame] | 169 | |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 170 | if (i) |
| 171 | tprints(", "); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 172 | |
Dmitry V. Levin | 09a1a5a | 2015-09-14 23:02:29 +0000 | [diff] [blame] | 173 | if (umove_ulong_or_printaddr(tcp, iocbs, &iocbp)) { |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame] | 174 | /* |
| 175 | * No point in trying to read the whole array |
| 176 | * because nr can be ridiculously large. |
| 177 | */ |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 178 | break; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 179 | } |
Dmitry V. Levin | 13c2173 | 2015-08-26 12:49:07 +0000 | [diff] [blame] | 180 | |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 181 | tprints("{"); |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 182 | if (!umove_or_printaddr(tcp, iocbp, &cb)) |
| 183 | print_iocb(tcp, &cb); |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 184 | tprints("}"); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 185 | } |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 186 | } |
| 187 | tprints("]"); |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 188 | return RVAL_DECODED; |
| 189 | } |
| 190 | |
| 191 | static int |
| 192 | print_io_event(struct tcb *tcp, const long addr) |
| 193 | { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 194 | struct io_event event; |
| 195 | |
| 196 | if (umove_or_printaddr(tcp, addr, &event)) |
| 197 | return -1; |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 198 | tprintf("{data=%#" PRIx64 ", obj=%#" PRIx64 |
| 199 | ", res=%" PRId64 ", res2=%" PRId64 "}", |
| 200 | (uint64_t) event.data, (uint64_t) event.obj, |
| 201 | (int64_t) event.res, (int64_t) event.res2); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 202 | return 0; |
| 203 | } |
| 204 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 205 | SYS_FUNC(io_cancel) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 206 | { |
| 207 | if (entering(tcp)) { |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 208 | tprintf("%lu, ", tcp->u_arg[0]); |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 209 | struct iocb cb; |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 210 | |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 211 | if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) { |
| 212 | tprints("{"); |
| 213 | print_iocb_header(&cb); |
| 214 | tprints("}"); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 215 | } |
Dmitry V. Levin | f56046e | 2015-08-26 17:48:40 +0000 | [diff] [blame] | 216 | tprints(", "); |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 217 | } else { |
| 218 | print_io_event(tcp, tcp->u_arg[2]); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 219 | } |
| 220 | return 0; |
| 221 | } |
| 222 | |
Dmitry V. Levin | a0bd374 | 2015-04-07 01:36:50 +0000 | [diff] [blame] | 223 | SYS_FUNC(io_getevents) |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 224 | { |
| 225 | if (entering(tcp)) { |
Dmitry V. Levin | 5687283 | 2015-08-26 16:15:46 +0000 | [diff] [blame] | 226 | tprintf("%lu, %ld, %ld, ", |
| 227 | tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 228 | } else { |
| 229 | if (tcp->u_rval == 0) { |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 230 | tprints("[]"); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 231 | } else { |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 232 | struct io_event *events = (void *)tcp->u_arg[3]; |
| 233 | long i, nr = tcp->u_rval; |
| 234 | |
| 235 | for (i = 0; i < nr; i++, events++) { |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 236 | if (i == 0) |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 237 | tprints("["); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 238 | else |
| 239 | tprints(", "); |
| 240 | |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 241 | if (print_io_event(tcp, (long)events)) |
| 242 | break; |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 243 | } |
Dmitry V. Levin | 07eaf50 | 2015-07-20 18:40:46 +0000 | [diff] [blame] | 244 | tprints("], "); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Dmitry V. Levin | 3858b93 | 2015-09-18 01:54:59 +0000 | [diff] [blame^] | 247 | /* |
| 248 | * Since the timeout parameter is read by the kernel |
| 249 | * on entering syscall, it has to be decoded the same way |
| 250 | * whether the syscall has failed or not. |
| 251 | */ |
| 252 | temporarily_clear_syserror(tcp); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 253 | print_timespec(tcp, tcp->u_arg[4]); |
Dmitry V. Levin | 3858b93 | 2015-09-18 01:54:59 +0000 | [diff] [blame^] | 254 | restore_cleared_syserror(tcp); |
Dmitry V. Levin | 2b64034 | 2013-11-11 15:06:18 +0000 | [diff] [blame] | 255 | } |
| 256 | return 0; |
| 257 | } |