Branch data Line data Source code
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 : : * Copyright (c) 1999-2017 The strace developers.
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"
33 : : #include "print_fields.h"
34 : : #include <linux/aio_abi.h>
35 : :
36 : 12 : SYS_FUNC(io_setup)
37 : : {
38 [ + + ]: 12 : if (entering(tcp))
39 : 6 : tprintf("%u, ", (unsigned int) tcp->u_arg[0]);
40 : : else
41 : 6 : printnum_ptr(tcp, tcp->u_arg[1]);
42 : 12 : return 0;
43 : : }
44 : :
45 : 4 : SYS_FUNC(io_destroy)
46 : : {
47 : 4 : printaddr(tcp->u_arg[0]);
48 : :
49 : 4 : return RVAL_DECODED;
50 : : }
51 : :
52 : : enum iocb_sub {
53 : : SUB_NONE, SUB_COMMON, SUB_VECTOR
54 : : };
55 : :
56 : : static enum iocb_sub
57 : 20 : tprint_lio_opcode(unsigned int cmd)
58 : : {
59 : : static const struct {
60 : : const char *name;
61 : : enum iocb_sub sub;
62 : : } cmds[] = {
63 : : { "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 },
72 : : };
73 : :
74 [ + + ]: 20 : if (cmd < ARRAY_SIZE(cmds)) {
75 : 18 : tprints(cmds[cmd].name);
76 : 18 : return cmds[cmd].sub;
77 : : }
78 : 2 : tprintf("%u", cmd);
79 : 2 : tprints_comment("IOCB_CMD_???");
80 : 2 : return SUB_NONE;
81 : : }
82 : :
83 : : static void
84 : 32 : print_common_flags(struct tcb *tcp, const struct iocb *cb)
85 : : {
86 : : /* IOCB_FLAG_RESFD is available since v2.6.22-rc1~47 */
87 : : #ifdef IOCB_FLAG_RESFD
88 [ + + ]: 16 : if (cb->aio_flags & IOCB_FLAG_RESFD)
89 : 2 : PRINT_FIELD_FD(", ", *cb, aio_resfd, tcp);
90 : :
91 [ + + ]: 16 : if (cb->aio_flags & ~IOCB_FLAG_RESFD)
92 : 2 : PRINT_FIELD_X(", ", *cb, aio_flags);
93 : : #endif
94 : 16 : }
95 : :
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 : 12 : (ssize_t) cb->aio_nbytes >= 0;
102 : : }
103 : :
104 : : static enum iocb_sub
105 : 20 : print_iocb_header(struct tcb *tcp, const struct iocb *cb)
106 : : {
107 : : enum iocb_sub sub;
108 : :
109 [ + + ]: 20 : if (cb->aio_data){
110 : 12 : PRINT_FIELD_X("", *cb, aio_data);
111 : 12 : tprints(", ");
112 : : }
113 : :
114 [ + + ]: 20 : if (cb->aio_key) {
115 : 10 : PRINT_FIELD_U("", *cb, aio_key);
116 : 10 : tprints(", ");
117 : : }
118 : :
119 : 20 : tprints("aio_lio_opcode=");
120 : 20 : sub = tprint_lio_opcode(cb->aio_lio_opcode);
121 [ + + ]: 20 : if (cb->aio_reqprio)
122 : 18 : PRINT_FIELD_D(", ", *cb, aio_reqprio);
123 : :
124 : 20 : PRINT_FIELD_FD(", ", *cb, aio_fildes, tcp);
125 : :
126 : 20 : return sub;
127 : : }
128 : :
129 : : static void
130 : 18 : print_iocb(struct tcb *tcp, const struct iocb *cb)
131 : : {
132 : 18 : enum iocb_sub sub = print_iocb_header(tcp, cb);
133 : :
134 [ + + + ]: 18 : switch (sub) {
135 : : case SUB_COMMON:
136 [ + + ][ + + ]: 10 : if (cb->aio_lio_opcode == 1 && iocb_is_valid(cb)) {
137 : 4 : PRINT_FIELD_STRN(", ", *cb, aio_buf,
138 : : cb->aio_nbytes, tcp);
139 : : } else {
140 : 6 : PRINT_FIELD_X(", ", *cb, aio_buf);
141 : : }
142 : 10 : PRINT_FIELD_U(", ", *cb, aio_nbytes);
143 : 10 : PRINT_FIELD_D(", ", *cb, aio_offset);
144 : 10 : print_common_flags(tcp, cb);
145 : 10 : break;
146 : : case SUB_VECTOR:
147 [ + + ]: 6 : if (iocb_is_valid(cb)) {
148 : 4 : tprints(", aio_buf=");
149 : 4 : tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf,
150 : 4 : cb->aio_lio_opcode == 8
151 : : ? IOV_DECODE_STR
152 : : : IOV_DECODE_ADDR);
153 : : } else {
154 : 2 : PRINT_FIELD_X(", ", *cb, aio_buf);
155 : 2 : PRINT_FIELD_U(", ", *cb, aio_nbytes);
156 : : }
157 : 6 : PRINT_FIELD_D(", ", *cb, aio_offset);
158 : 6 : print_common_flags(tcp, cb);
159 : 6 : break;
160 : : case SUB_NONE:
161 : : break;
162 : : }
163 : 18 : }
164 : :
165 : : static bool
166 : 22 : print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
167 : : {
168 : : kernel_ulong_t addr;
169 : : struct iocb cb;
170 : :
171 [ + + ]: 22 : if (elem_size < sizeof(kernel_ulong_t)) {
172 : 11 : addr = *(unsigned int *) elem_buf;
173 : : } else {
174 : 11 : addr = *(kernel_ulong_t *) elem_buf;
175 : : }
176 : :
177 : 22 : tprints("{");
178 [ + + ]: 22 : if (!umove_or_printaddr(tcp, addr, &cb))
179 : 18 : print_iocb(tcp, &cb);
180 : 22 : tprints("}");
181 : :
182 : 22 : return true;
183 : : }
184 : :
185 : 16 : SYS_FUNC(io_submit)
186 : : {
187 : 16 : const kernel_long_t nr =
188 : 16 : truncate_klong_to_current_wordsize(tcp->u_arg[1]);
189 : 16 : const kernel_ulong_t addr = tcp->u_arg[2];
190 : : kernel_ulong_t iocbp;
191 : :
192 : 16 : printaddr(tcp->u_arg[0]);
193 : 16 : tprintf(", %" PRI_kld ", ", nr);
194 : :
195 [ + + ]: 16 : if (nr < 0)
196 : 8 : printaddr(addr);
197 : : else
198 : 8 : print_array(tcp, addr, nr, &iocbp, current_wordsize,
199 : : umoven_or_printaddr, print_iocbp, 0);
200 : :
201 : 16 : return RVAL_DECODED;
202 : : }
203 : :
204 : : static bool
205 : 4 : print_io_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
206 : : {
207 : 4 : struct io_event *event = elem_buf;
208 : :
209 : 4 : PRINT_FIELD_X("{", *event, data);
210 : 4 : PRINT_FIELD_X(", ", *event, obj);
211 : 4 : PRINT_FIELD_D(", ", *event, res);
212 : 4 : PRINT_FIELD_D(", ", *event, res2);
213 : 4 : tprints("}");
214 : :
215 : 4 : return true;
216 : : }
217 : :
218 : 12 : SYS_FUNC(io_cancel)
219 : : {
220 [ + + ]: 12 : if (entering(tcp)) {
221 : 6 : printaddr(tcp->u_arg[0]);
222 : 6 : tprints(", ");
223 : :
224 : : struct iocb cb;
225 : :
226 [ + + ]: 6 : if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) {
227 : 2 : tprints("{");
228 : 2 : print_iocb_header(tcp, &cb);
229 : 2 : tprints("}");
230 : : }
231 : 6 : tprints(", ");
232 : : } else {
233 : : struct io_event event;
234 : :
235 [ - + ]: 6 : if (!umove_or_printaddr(tcp, tcp->u_arg[2], &event))
236 : 6 : print_io_event(tcp, &event, sizeof(event), 0);
237 : : }
238 : 12 : return 0;
239 : : }
240 : :
241 : 20 : SYS_FUNC(io_getevents)
242 : : {
243 [ + + ]: 20 : if (entering(tcp)) {
244 : 10 : printaddr(tcp->u_arg[0]);
245 : 10 : tprintf(", %" PRI_kld ", %" PRI_kld ", ",
246 : 10 : truncate_klong_to_current_wordsize(tcp->u_arg[1]),
247 : 10 : truncate_klong_to_current_wordsize(tcp->u_arg[2]));
248 : : } else {
249 : : struct io_event buf;
250 : 10 : print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf),
251 : : umoven_or_printaddr, print_io_event, 0);
252 : 10 : tprints(", ");
253 : : /*
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 : 10 : temporarily_clear_syserror(tcp);
259 : 10 : print_timespec(tcp, tcp->u_arg[4]);
260 : 10 : restore_cleared_syserror(tcp);
261 : : }
262 : 20 : return 0;
263 : : }
|