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-2018 The strace developers.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
33 #include "print_fields.h"
34 #include <linux/aio_abi.h>
36 #include "xlat/aio_cmds.h"
41 tprintf("%u, ", (unsigned int) tcp->u_arg[0]);
43 printnum_ptr(tcp, tcp->u_arg[1]);
49 printaddr(tcp->u_arg[0]);
55 SUB_NONE, SUB_COMMON, SUB_VECTOR
59 tprint_lio_opcode(unsigned int cmd)
61 static const enum iocb_sub subs[] = {
62 [IOCB_CMD_PREAD] = SUB_COMMON,
63 [IOCB_CMD_PWRITE] = SUB_COMMON,
64 [IOCB_CMD_FSYNC] = SUB_NONE,
65 [IOCB_CMD_FDSYNC] = SUB_NONE,
66 [IOCB_CMD_PREADX] = SUB_NONE,
67 [IOCB_CMD_POLL] = SUB_NONE,
68 [IOCB_CMD_NOOP] = SUB_NONE,
69 [IOCB_CMD_PREADV] = SUB_VECTOR,
70 [IOCB_CMD_PWRITEV] = SUB_VECTOR,
73 printxval_indexn_ex(ARRSZ_PAIR(aio_cmds), cmd, "IOCB_CMD_???",
76 return cmd < ARRAY_SIZE(subs) ? subs[cmd] : SUB_NONE;
80 print_common_flags(struct tcb *tcp, const struct iocb *cb)
82 /* IOCB_FLAG_RESFD is available since v2.6.22-rc1~47 */
83 #ifdef IOCB_FLAG_RESFD
84 if (cb->aio_flags & IOCB_FLAG_RESFD)
85 PRINT_FIELD_FD(", ", *cb, aio_resfd, tcp);
87 if (cb->aio_flags & ~IOCB_FLAG_RESFD)
88 PRINT_FIELD_X(", ", *cb, aio_flags);
93 iocb_is_valid(const struct iocb *cb)
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;
101 print_iocb_header(struct tcb *tcp, const struct iocb *cb)
106 PRINT_FIELD_X("", *cb, aio_data);
111 PRINT_FIELD_U("", *cb, aio_key);
115 tprints("aio_lio_opcode=");
116 sub = tprint_lio_opcode(cb->aio_lio_opcode);
118 PRINT_FIELD_D(", ", *cb, aio_reqprio);
120 PRINT_FIELD_FD(", ", *cb, aio_fildes, tcp);
126 print_iocb(struct tcb *tcp, const struct iocb *cb)
130 enum iocb_sub sub = print_iocb_header(tcp, cb);
134 if (cb->aio_lio_opcode == 1 && iocb_is_valid(cb)) {
135 PRINT_FIELD_STRN(", ", *cb, aio_buf,
136 cb->aio_nbytes, tcp);
138 PRINT_FIELD_X(", ", *cb, aio_buf);
140 PRINT_FIELD_U(", ", *cb, aio_nbytes);
141 PRINT_FIELD_D(", ", *cb, aio_offset);
142 print_common_flags(tcp, cb);
145 if (iocb_is_valid(cb)) {
146 tprints(", aio_buf=");
147 tprint_iov(tcp, cb->aio_nbytes, cb->aio_buf,
148 cb->aio_lio_opcode == 8
152 PRINT_FIELD_X(", ", *cb, aio_buf);
153 PRINT_FIELD_U(", ", *cb, aio_nbytes);
155 PRINT_FIELD_D(", ", *cb, aio_offset);
156 print_common_flags(tcp, cb);
166 print_iocbp(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
171 if (elem_size < sizeof(kernel_ulong_t)) {
172 addr = *(unsigned int *) elem_buf;
174 addr = *(kernel_ulong_t *) elem_buf;
177 if (!umove_or_printaddr(tcp, addr, &cb))
178 print_iocb(tcp, &cb);
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;
190 printaddr(tcp->u_arg[0]);
191 tprintf(", %" PRI_kld ", ", nr);
196 print_array(tcp, addr, nr, &iocbp, current_wordsize,
197 tfetch_mem, print_iocbp, 0);
203 print_io_event(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
205 struct io_event *event = elem_buf;
207 PRINT_FIELD_X("{", *event, data);
208 PRINT_FIELD_X(", ", *event, obj);
209 PRINT_FIELD_D(", ", *event, res);
210 PRINT_FIELD_D(", ", *event, res2);
219 printaddr(tcp->u_arg[0]);
224 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &cb)) {
226 print_iocb_header(tcp, &cb);
231 struct io_event event;
233 if (!umove_or_printaddr(tcp, tcp->u_arg[2], &event))
234 print_io_event(tcp, &event, sizeof(event), 0);
240 print_io_getevents(struct tcb *tcp, bool has_usig)
243 printaddr(tcp->u_arg[0]);
244 tprintf(", %" PRI_kld ", %" PRI_kld ", ",
245 truncate_klong_to_current_wordsize(tcp->u_arg[1]),
246 truncate_klong_to_current_wordsize(tcp->u_arg[2]));
249 print_array(tcp, tcp->u_arg[3], tcp->u_rval, &buf, sizeof(buf),
250 tfetch_mem, print_io_event, 0);
253 * Since the timeout and usig parameters are read by the kernel
254 * on entering syscall, it has to be decoded the same way
255 * whether the syscall has failed or not.
257 temporarily_clear_syserror(tcp);
258 print_timespec(tcp, tcp->u_arg[4]);
261 print_aio_sigset(tcp, tcp->u_arg[5]);
263 restore_cleared_syserror(tcp);
268 SYS_FUNC(io_getevents)
270 return print_io_getevents(tcp, false);
273 SYS_FUNC(io_pgetevents)
275 return print_io_getevents(tcp, true);