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>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 /* --- Copied from libaio-0.3.109/src/libaio.h ---
34 * Why keep a copy instead of using external libaio.h?
35 * Because we want to properly decode 32-bit aio calls
36 * by 64-bit strace. For that, we need more definitions than
37 * libaio.h provides. (TODO).
38 * Keeping our local 32-bit compat defs in sync with libaio.h
39 * _without seeing libaio structs_ is hard/more bug-prone.
40 * A smaller benefit is that we don't need libaio installed.
42 #define HAVE_LIBAIO_H 1
43 typedef enum io_iocb_cmd {
50 IO_CMD_POLL = 5, /* Never implemented in mainline, see io_prep_poll */
56 #if defined(__i386__) /* little endian, 32 bits */
57 #define PADDED(x, y) x; unsigned y
58 #define PADDEDptr(x, y) x; unsigned y
59 #define PADDEDul(x, y) unsigned long x; unsigned y
60 #elif defined(__ia64__) || defined(__x86_64__) || defined(__alpha__)
61 #define PADDED(x, y) x, y
62 #define PADDEDptr(x, y) x
63 #define PADDEDul(x, y) unsigned long x
64 #elif defined(__powerpc64__) /* big endian, 64 bits */
65 #define PADDED(x, y) unsigned y; x
66 #define PADDEDptr(x,y) x
67 #define PADDEDul(x, y) unsigned long x
68 #elif defined(__PPC__) /* big endian, 32 bits */
69 #define PADDED(x, y) unsigned y; x
70 #define PADDEDptr(x, y) unsigned y; x
71 #define PADDEDul(x, y) unsigned y; unsigned long x
72 #elif defined(__s390x__) /* big endian, 64 bits */
73 #define PADDED(x, y) unsigned y; x
74 #define PADDEDptr(x,y) x
75 #define PADDEDul(x, y) unsigned long x
76 #elif defined(__s390__) /* big endian, 32 bits */
77 #define PADDED(x, y) unsigned y; x
78 #define PADDEDptr(x, y) unsigned y; x
79 #define PADDEDul(x, y) unsigned y; unsigned long x
80 #elif defined(__arm__)
81 # if defined (__ARMEB__) /* big endian, 32 bits */
82 #define PADDED(x, y) unsigned y; x
83 #define PADDEDptr(x, y) unsigned y; x
84 #define PADDEDul(x, y) unsigned y; unsigned long x
85 # else /* little endian, 32 bits */
86 #define PADDED(x, y) x; unsigned y
87 #define PADDEDptr(x, y) x; unsigned y
88 #define PADDEDul(x, y) unsigned long x; unsigned y
91 # warning No AIO definitions for this architecture => no io_submit decoding
97 PADDED(int events, __pad1);
98 }; /* result code is the set of result flags or -'ve errno */
100 struct io_iocb_sockaddr {
101 struct sockaddr *addr;
103 }; /* result code is the length of the sockaddr, or -'ve errno */
105 struct io_iocb_common {
106 PADDEDptr(void *buf, __pad1);
107 PADDEDul(nbytes, __pad2);
112 }; /* result code is the amount read or -'ve errno */
114 struct io_iocb_vector {
115 const struct iovec *vec;
118 }; /* result code is the amount read or -'ve errno */
121 PADDEDptr(void *data, __pad1); /* Return in the io completion event */
122 PADDED(unsigned key, __pad2); /* For use in identifying io requests */
124 short aio_lio_opcode;
129 struct io_iocb_common c;
130 struct io_iocb_vector v;
131 struct io_iocb_poll poll;
132 struct io_iocb_sockaddr saddr;
137 PADDEDptr(void *data, __pad1);
138 PADDEDptr(struct iocb *obj, __pad2);
139 PADDEDul(res, __pad3);
140 PADDEDul(res2, __pad4);
147 #endif /* HAVE_LIBAIO_H */
149 /* --- End of a chunk of libaio.h --- */
150 /* Not defined in libaio.h */
152 # define IOCB_RESFD (1 << 0)
156 sys_io_setup(struct tcb *tcp)
159 tprintf("%ld, ", tcp->u_arg[0]);
162 tprintf("0x%0lx", tcp->u_arg[1]);
164 unsigned long user_id;
165 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
166 tprintf("{%lu}", user_id);
175 sys_io_destroy(struct tcb *tcp)
178 tprintf("%lu", tcp->u_arg[0]);
185 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
189 tprint_lio_opcode(unsigned cmd)
191 static const struct {
195 { "pread", SUB_COMMON },
196 { "pwrite", SUB_COMMON },
197 { "fsync", SUB_NONE },
198 { "fdsync", SUB_NONE },
200 { "poll", SUB_POLL },
201 { "noop", SUB_NONE },
202 { "preadv", SUB_VECTOR },
203 { "pwritev", SUB_VECTOR },
206 if (cmd < ARRAY_SIZE(cmds)) {
207 tprints(cmds[cmd].name);
208 return cmds[cmd].sub;
210 tprintf("%u /* SUB_??? */", cmd);
215 print_common_flags(struct iocb *iocb)
217 if (iocb->u.c.flags & IOCB_RESFD)
218 tprintf(", resfd=%d", iocb->u.c.resfd);
219 if (iocb->u.c.flags & ~IOCB_RESFD)
220 tprintf(", flags=%x", iocb->u.c.flags);
223 #endif /* HAVE_LIBAIO_H */
226 sys_io_submit(struct tcb *tcp)
230 long nr = tcp->u_arg[1];
231 /* if nr <= 0, we end up printing just "{}" */
232 tprintf("%lu, %ld, {", tcp->u_arg[0], tcp->u_arg[1]);
235 struct iocb **iocbs = (void *)tcp->u_arg[2];
236 //FIXME: decoding of 32-bit call by 64-bit strace
238 for (i = 0; i < nr; i++, iocbs++) {
245 if (umove(tcp, (unsigned long)iocbs, &iocbp)) {
246 tprintf("%#lx", (unsigned long)iocbs);
247 /* No point in trying to read iocbs+1 etc */
248 /* (nr can be ridiculously large): */
251 if (umove(tcp, (unsigned long)iocbp, &iocb)) {
252 tprintf("{%#lx}", (unsigned long)iocbp);
257 tprintf("data:%p, ", iocb.data);
259 tprintf("key:%u, ", iocb.key);
260 sub = tprint_lio_opcode(iocb.aio_lio_opcode);
261 if (iocb.aio_reqprio)
262 tprintf(", reqprio:%d", iocb.aio_reqprio);
263 tprintf(", filedes:%d", iocb.aio_fildes);
266 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
268 printstr(tcp, (unsigned long)iocb.u.c.buf,
271 tprintf(", buf:%p", iocb.u.c.buf);
272 tprintf(", nbytes:%lu, offset:%lld",
275 print_common_flags(&iocb);
278 tprintf(", %lld", iocb.u.v.offset);
279 print_common_flags(&iocb);
281 tprint_iov(tcp, iocb.u.v.nr,
282 (unsigned long)iocb.u.v.vec,
283 iocb.aio_lio_opcode == IO_CMD_PWRITEV
287 tprintf(", %x", iocb.u.poll.events);
297 tprintf("%lu, %ld, %#lx", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
304 sys_io_cancel(struct tcb *tcp)
310 tprintf("%lu, ", tcp->u_arg[0]);
312 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
313 tprintf("{%p, %u, %u, %u, %d}, ",
315 (unsigned)iocb.aio_lio_opcode,
316 (unsigned)iocb.aio_reqprio, iocb.aio_fildes);
325 struct io_event event;
326 if (umove(tcp, tcp->u_arg[2], &event) == 0)
327 tprintf("{%p, %p, %ld, %ld}",
328 event.data, event.obj,
329 event.res, event.res2);
339 sys_io_getevents(struct tcb *tcp)
342 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
345 if (tcp->u_rval == 0) {
349 struct io_event *events = (void *)tcp->u_arg[3];
350 long i, nr = tcp->u_rval;
352 for (i = 0; i < nr; i++, events++) {
353 struct io_event event;
360 if (umove(tcp, (unsigned long)events, &event) != 0) {
364 tprintf("{%p, %p, %ld, %ld}", event.data,
365 event.obj, event.res, event.res2);
373 print_timespec(tcp, tcp->u_arg[4]);