blob: 600f88efc8446a6d2b682702c414450897a41ef9 [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"
Elliott Hughes77c3ff82017-09-08 17:11:00 -070033#include "print_fields.h"
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000034#include <linux/aio_abi.h>
Dmitry V. Levin2b640342013-11-11 15:06:18 +000035
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000036SYS_FUNC(io_setup)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000037{
38 if (entering(tcp))
Elvira Khabirovaafac9f02015-08-18 18:02:20 +030039 tprintf("%u, ", (unsigned int) tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000040 else
Dmitry V. Levined292f62016-09-07 11:22:51 +000041 printnum_ptr(tcp, tcp->u_arg[1]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +000042 return 0;
43}
44
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000045SYS_FUNC(io_destroy)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000046{
Dmitry V. Levined292f62016-09-07 11:22:51 +000047 printaddr(tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000048
49 return RVAL_DECODED;
Dmitry V. Levin2b640342013-11-11 15:06:18 +000050}
51
Dmitry V. Levin2b640342013-11-11 15:06:18 +000052enum iocb_sub {
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000053 SUB_NONE, SUB_COMMON, SUB_VECTOR
Dmitry V. Levin2b640342013-11-11 15:06:18 +000054};
55
56static enum iocb_sub
Elliott Hughes77c3ff82017-09-08 17:11:00 -070057tprint_lio_opcode(unsigned int cmd)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000058{
59 static const struct {
60 const char *name;
61 enum iocb_sub sub;
62 } cmds[] = {
Elliott Hughes77c3ff82017-09-08 17:11:00 -070063 { "IOCB_CMD_PREAD", SUB_COMMON },
64 { "IOCB_CMD_PWRITE", SUB_COMMON },
65 { "IOCB_CMD_FSYNC", SUB_NONE },
66 { "IOCB_CMD_FDSYNC", SUB_NONE },
67 { "IOCB_CMD_PREADX", SUB_NONE },
68 { "IOCB_CMD_POLL", SUB_NONE },
69 { "IOCB_CMD_NOOP", SUB_NONE },
70 { "IOCB_CMD_PREADV", SUB_VECTOR },
71 { "IOCB_CMD_PWRITEV", SUB_VECTOR },
Dmitry V. Levin2b640342013-11-11 15:06:18 +000072 };
73
74 if (cmd < ARRAY_SIZE(cmds)) {
75 tprints(cmds[cmd].name);
76 return cmds[cmd].sub;
77 }
Elliott Hughes39bac052017-05-25 16:56:11 -070078 tprintf("%u", cmd);
Elliott Hughes77c3ff82017-09-08 17:11:00 -070079 tprints_comment("IOCB_CMD_???");
Dmitry V. Levin2b640342013-11-11 15:06:18 +000080 return SUB_NONE;
81}
82
83static void
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +030084print_common_flags(struct tcb *tcp, const struct iocb *cb)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000085{
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000086/* IOCB_FLAG_RESFD is available since v2.6.22-rc1~47 */
87#ifdef IOCB_FLAG_RESFD
Elliott Hughes77c3ff82017-09-08 17:11:00 -070088 if (cb->aio_flags & IOCB_FLAG_RESFD)
89 PRINT_FIELD_FD(", ", *cb, aio_resfd, tcp);
90
Dmitry V. Levinf56046e2015-08-26 17:48:40 +000091 if (cb->aio_flags & ~IOCB_FLAG_RESFD)
Elliott Hughes77c3ff82017-09-08 17:11:00 -070092 PRINT_FIELD_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
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700109 if (cb->aio_data){
110 PRINT_FIELD_X("", *cb, aio_data);
111 tprints(", ");
112 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000113
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700114 if (cb->aio_key) {
115 PRINT_FIELD_U("", *cb, aio_key);
116 tprints(", ");
117 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000118
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700119 tprints("aio_lio_opcode=");
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000120 sub = tprint_lio_opcode(cb->aio_lio_opcode);
121 if (cb->aio_reqprio)
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700122 PRINT_FIELD_D(", ", *cb, aio_reqprio);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000123
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700124 PRINT_FIELD_FD(", ", *cb, aio_fildes, tcp);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000125
126 return sub;
127}
128
129static void
130print_iocb(struct tcb *tcp, const struct iocb *cb)
131{
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300132 enum iocb_sub sub = print_iocb_header(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000133
134 switch (sub) {
135 case SUB_COMMON:
136 if (cb->aio_lio_opcode == 1 && iocb_is_valid(cb)) {
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700137 PRINT_FIELD_STRN(", ", *cb, aio_buf,
138 cb->aio_nbytes, tcp);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000139 } else {
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700140 PRINT_FIELD_X(", ", *cb, aio_buf);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000141 }
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700142 PRINT_FIELD_U(", ", *cb, aio_nbytes);
143 PRINT_FIELD_D(", ", *cb, aio_offset);
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300144 print_common_flags(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000145 break;
146 case SUB_VECTOR:
147 if (iocb_is_valid(cb)) {
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700148 tprints(", aio_buf=");
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000149 tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf,
Fabien Siron2a54d8b2016-06-22 13:27:03 +0000150 cb->aio_lio_opcode == 8
151 ? IOV_DECODE_STR
152 : IOV_DECODE_ADDR);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000153 } else {
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700154 PRINT_FIELD_X(", ", *cb, aio_buf);
155 PRINT_FIELD_U(", ", *cb, aio_nbytes);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000156 }
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700157 PRINT_FIELD_D(", ", *cb, aio_offset);
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300158 print_common_flags(tcp, cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000159 break;
160 case SUB_NONE:
161 break;
162 }
163}
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000164
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000165static bool
166print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
167{
Elliott Hughesd35df492017-02-15 15:19:05 -0800168 kernel_ulong_t addr;
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000169 struct iocb cb;
170
Elliott Hughesd35df492017-02-15 15:19:05 -0800171 if (elem_size < sizeof(kernel_ulong_t)) {
Elliott Hughesdc75b012017-07-05 13:54:44 -0700172 addr = *(unsigned int *) elem_buf;
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000173 } else {
Elliott Hughesdc75b012017-07-05 13:54:44 -0700174 addr = *(kernel_ulong_t *) elem_buf;
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000175 }
176
177 tprints("{");
178 if (!umove_or_printaddr(tcp, addr, &cb))
179 print_iocb(tcp, &cb);
180 tprints("}");
181
182 return true;
183}
184
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000185SYS_FUNC(io_submit)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000186{
Elliott Hughesd35df492017-02-15 15:19:05 -0800187 const kernel_long_t nr =
188 truncate_klong_to_current_wordsize(tcp->u_arg[1]);
189 const kernel_ulong_t addr = tcp->u_arg[2];
190 kernel_ulong_t iocbp;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000191
Dmitry V. Levined292f62016-09-07 11:22:51 +0000192 printaddr(tcp->u_arg[0]);
Elliott Hughesd35df492017-02-15 15:19:05 -0800193 tprintf(", %" PRI_kld ", ", nr);
Dmitry V. Levin13c21732015-08-26 12:49:07 +0000194
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000195 if (nr < 0)
196 printaddr(addr);
197 else
198 print_array(tcp, addr, nr, &iocbp, current_wordsize,
199 umoven_or_printaddr, print_iocbp, 0);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000200
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000201 return RVAL_DECODED;
202}
203
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000204static bool
205print_io_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000206{
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000207 struct io_event *event = elem_buf;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000208
Elliott Hughes77c3ff82017-09-08 17:11:00 -0700209 PRINT_FIELD_X("{", *event, data);
210 PRINT_FIELD_X(", ", *event, obj);
211 PRINT_FIELD_D(", ", *event, res);
212 PRINT_FIELD_D(", ", *event, res2);
213 tprints("}");
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000214
215 return true;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000216}
217
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000218SYS_FUNC(io_cancel)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000219{
220 if (entering(tcp)) {
Dmitry V. Levined292f62016-09-07 11:22:51 +0000221 printaddr(tcp->u_arg[0]);
222 tprints(", ");
223
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000224 struct iocb cb;
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000225
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000226 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) {
227 tprints("{");
Eugene Syromyatnikov2b962b22016-09-05 04:32:16 +0300228 print_iocb_header(tcp, &cb);
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000229 tprints("}");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000230 }
Dmitry V. Levinf56046e2015-08-26 17:48:40 +0000231 tprints(", ");
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000232 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000233 struct io_event event;
234
235 if (!umove_or_printaddr(tcp, tcp->u_arg[2], &event))
236 print_io_event(tcp, &event, sizeof(event), 0);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000237 }
238 return 0;
239}
240
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000241SYS_FUNC(io_getevents)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000242{
243 if (entering(tcp)) {
Dmitry V. Levined292f62016-09-07 11:22:51 +0000244 printaddr(tcp->u_arg[0]);
Elliott Hughesd35df492017-02-15 15:19:05 -0800245 tprintf(", %" PRI_kld ", %" PRI_kld ", ",
246 truncate_klong_to_current_wordsize(tcp->u_arg[1]),
247 truncate_klong_to_current_wordsize(tcp->u_arg[2]));
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000248 } else {
Dmitry V. Levin2868e2b2016-05-07 22:40:06 +0000249 struct io_event buf;
250 print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf),
251 umoven_or_printaddr, print_io_event, 0);
252 tprints(", ");
Dmitry V. Levin3858b932015-09-18 01:54:59 +0000253 /*
254 * Since the timeout parameter is read by the kernel
255 * on entering syscall, it has to be decoded the same way
256 * whether the syscall has failed or not.
257 */
258 temporarily_clear_syserror(tcp);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000259 print_timespec(tcp, tcp->u_arg[4]);
Dmitry V. Levin3858b932015-09-18 01:54:59 +0000260 restore_cleared_syserror(tcp);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000261 }
262 return 0;
263}