blob: 5565d0c7289e6f419cb9dfd29b39dcd809f1fda6 [file] [log] [blame]
Dmitry V. Levin2b640342013-11-11 15:06:18 +00001/*
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 Hughes39bac052017-05-25 16:56:11 -07006 * Copyright (c) 1999-2017 The strace developers.
Dmitry V. Levin2b640342013-11-11 15:06:18 +00007 * 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. Levinf56046e2015-08-26 17:48:40 +000033#include <linux/aio_abi.h>
Dmitry V. Levin2b640342013-11-11 15:06:18 +000034
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000035SYS_FUNC(io_setup)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000036{
37 if (entering(tcp))
Elvira Khabirovaafac9f02015-08-18 18:02:20 +030038 tprintf("%u, ", (unsigned int) tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000039 else
Dmitry V. Levined292f62016-09-07 11:22:51 +000040 printnum_ptr(tcp, tcp->u_arg[1]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +000041 return 0;
42}
43
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000044SYS_FUNC(io_destroy)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000045{
Dmitry V. Levined292f62016-09-07 11:22:51 +000046 printaddr(tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000047
48 return RVAL_DECODED;
Dmitry V. Levin2b640342013-11-11 15:06:18 +000049}
50
Dmitry V. Levin2b640342013-11-11 15:06:18 +000051enum iocb_sub {
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000052 SUB_NONE, SUB_COMMON, SUB_VECTOR
Dmitry V. Levin2b640342013-11-11 15:06:18 +000053};
54
55static enum iocb_sub
56tprint_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. Levinf56046e2015-08-26 17:48:40 +000066 { "preadx", SUB_NONE },
67 { "poll", SUB_NONE },
Dmitry V. Levin2b640342013-11-11 15:06:18 +000068 { "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 Hughes39bac052017-05-25 16:56:11 -070077 tprintf("%u", cmd);
78 tprints_comment("SUB_???");
Dmitry V. Levin2b640342013-11-11 15:06:18 +000079 return SUB_NONE;
80}
81
82static void
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +030083print_common_flags(struct tcb *tcp, const struct iocb *cb)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000084{
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000085/* IOCB_FLAG_RESFD is available since v2.6.22-rc1~47 */
86#ifdef IOCB_FLAG_RESFD
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +030087 if (cb->aio_flags & IOCB_FLAG_RESFD) {
88 tprints(", resfd=");
89 printfd(tcp, cb->aio_resfd);
90 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000091 if (cb->aio_flags & ~IOCB_FLAG_RESFD)
Elliott Hughesd35df492017-02-15 15:19:05 -080092 tprintf(", flags=%#x", cb->aio_flags);
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +000093#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +000094}
95
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000096static bool
97iocb_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
104static enum iocb_sub
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300105print_iocb_header(struct tcb *tcp, const struct iocb *cb)
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000106{
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 Syromyatnikov2b962b22016-09-05 04:32:16 +0300120 tprints(", fildes=");
121 printfd(tcp, cb->aio_fildes);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000122
123 return sub;
124}
125
126static void
127print_iocb(struct tcb *tcp, const struct iocb *cb)
128{
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300129 enum iocb_sub sub = print_iocb_header(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000130
131 switch (sub) {
132 case SUB_COMMON:
133 if (cb->aio_lio_opcode == 1 && iocb_is_valid(cb)) {
134 tprints(", str=");
Elliott Hughesd35df492017-02-15 15:19:05 -0800135 printstrn(tcp, cb->aio_buf, cb->aio_nbytes);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000136 } 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 Syromyatnikov2b962b22016-09-05 04:32:16 +0300141 print_common_flags(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000142 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 Siron2a54d8b2016-06-22 13:27:03 +0000147 cb->aio_lio_opcode == 8
148 ? IOV_DECODE_STR
149 : IOV_DECODE_ADDR);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000150 } 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 Syromyatnikov2b962b22016-09-05 04:32:16 +0300156 print_common_flags(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000157 break;
158 case SUB_NONE:
159 break;
160 }
161}
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000162
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000163static bool
164print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
165{
Elliott Hughesd35df492017-02-15 15:19:05 -0800166 kernel_ulong_t addr;
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000167 struct iocb cb;
168
Elliott Hughesd35df492017-02-15 15:19:05 -0800169 if (elem_size < sizeof(kernel_ulong_t)) {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000170 addr = * (unsigned int *) elem_buf;
171 } else {
Elliott Hughesd35df492017-02-15 15:19:05 -0800172 addr = * (kernel_ulong_t *) elem_buf;
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000173 }
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. Levina0bd3742015-04-07 01:36:50 +0000183SYS_FUNC(io_submit)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000184{
Elliott Hughesd35df492017-02-15 15:19:05 -0800185 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. Levin2b640342013-11-11 15:06:18 +0000189
Dmitry V. Levined292f62016-09-07 11:22:51 +0000190 printaddr(tcp->u_arg[0]);
Elliott Hughesd35df492017-02-15 15:19:05 -0800191 tprintf(", %" PRI_kld ", ", nr);
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000192
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000193 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. Levin2b640342013-11-11 15:06:18 +0000198
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000199 return RVAL_DECODED;
200}
201
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000202static bool
203print_io_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000204{
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000205 struct io_event *event = elem_buf;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000206
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000207 tprintf("{data=%#" PRIx64 ", obj=%#" PRIx64
208 ", res=%" PRId64 ", res2=%" PRId64 "}",
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000209 (uint64_t) event->data, (uint64_t) event->obj,
210 (int64_t) event->res, (int64_t) event->res2);
211
212 return true;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000213}
214
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000215SYS_FUNC(io_cancel)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000216{
217 if (entering(tcp)) {
Dmitry V. Levined292f62016-09-07 11:22:51 +0000218 printaddr(tcp->u_arg[0]);
219 tprints(", ");
220
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000221 struct iocb cb;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000222
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000223 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) {
224 tprints("{");
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300225 print_iocb_header(tcp, &cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000226 tprints("}");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000227 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000228 tprints(", ");
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000229 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000230 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. Levin2b640342013-11-11 15:06:18 +0000234 }
235 return 0;
236}
237
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000238SYS_FUNC(io_getevents)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000239{
240 if (entering(tcp)) {
Dmitry V. Levined292f62016-09-07 11:22:51 +0000241 printaddr(tcp->u_arg[0]);
Elliott Hughesd35df492017-02-15 15:19:05 -0800242 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. Levin2b640342013-11-11 15:06:18 +0000245 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000246 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. Levin3858b932015-09-18 01:54:59 +0000250 /*
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. Levin2b640342013-11-11 15:06:18 +0000256 print_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levin3858b932015-09-18 01:54:59 +0000257 restore_cleared_syserror(tcp);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000258 }
259 return 0;
260}