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