blob: fd10553f77916e9c9ce86048c7299e7929c9fa31 [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>
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
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.
18 *
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.
29 */
30
31#include "defs.h"
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +000032#ifdef HAVE_LIBAIO_H
33# include <libaio.h>
Dmitry V. Levin2b640342013-11-11 15:06:18 +000034#endif
35
Dmitry V. Levin2b640342013-11-11 15:06:18 +000036/* Not defined in libaio.h */
37#ifndef IOCB_RESFD
38# define IOCB_RESFD (1 << 0)
39#endif
40
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000041SYS_FUNC(io_setup)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000042{
43 if (entering(tcp))
44 tprintf("%ld, ", tcp->u_arg[0]);
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000045 else
46#ifdef X32
47 printnum_int64(tcp, tcp->u_arg[1], "%" PRIu64);
48#else
49 printnum_long(tcp, tcp->u_arg[1], "%lu");
50#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +000051 return 0;
52}
53
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000054SYS_FUNC(io_destroy)
Dmitry V. Levin2b640342013-11-11 15:06:18 +000055{
Dmitry V. Levin07eaf502015-07-20 18:40:46 +000056 tprintf("%lu", tcp->u_arg[0]);
57
58 return RVAL_DECODED;
Dmitry V. Levin2b640342013-11-11 15:06:18 +000059}
60
61#ifdef HAVE_LIBAIO_H
62
63enum iocb_sub {
64 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
65};
66
67static enum iocb_sub
68tprint_lio_opcode(unsigned cmd)
69{
70 static const struct {
71 const char *name;
72 enum iocb_sub sub;
73 } cmds[] = {
74 { "pread", SUB_COMMON },
75 { "pwrite", SUB_COMMON },
76 { "fsync", SUB_NONE },
77 { "fdsync", SUB_NONE },
78 { "op4", SUB_NONE },
79 { "poll", SUB_POLL },
80 { "noop", SUB_NONE },
81 { "preadv", SUB_VECTOR },
82 { "pwritev", SUB_VECTOR },
83 };
84
85 if (cmd < ARRAY_SIZE(cmds)) {
86 tprints(cmds[cmd].name);
87 return cmds[cmd].sub;
88 }
89 tprintf("%u /* SUB_??? */", cmd);
90 return SUB_NONE;
91}
92
93static void
94print_common_flags(struct iocb *iocb)
95{
Dmitry V. Levind93c4e82015-06-17 20:09:13 +000096#ifdef HAVE_STRUCT_IOCB_U_C_FLAGS
Dmitry V. Levin2b640342013-11-11 15:06:18 +000097 if (iocb->u.c.flags & IOCB_RESFD)
98 tprintf(", resfd=%d", iocb->u.c.resfd);
99 if (iocb->u.c.flags & ~IOCB_RESFD)
100 tprintf(", flags=%x", iocb->u.c.flags);
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000101#else
102# warning "libaio.h is too old => limited io_submit decoding"
103#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000104}
105
106#endif /* HAVE_LIBAIO_H */
107
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000108SYS_FUNC(io_submit)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000109{
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000110#ifdef HAVE_LIBAIO_H
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000111 long nr = tcp->u_arg[1];
112 /* if nr <= 0, we end up printing just "[]" */
113 tprintf("%lu, %ld, [", tcp->u_arg[0], tcp->u_arg[1]);
114 {
115 long i;
116 struct iocb **iocbs = (void *)tcp->u_arg[2];
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000117//FIXME: decoding of 32-bit call by 64-bit strace
118
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000119 for (i = 0; i < nr; i++, iocbs++) {
120 enum iocb_sub sub;
121 struct iocb *iocbp;
122 struct iocb iocb;
123 if (i)
124 tprints(", ");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000125
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000126 if (umove_or_printaddr(tcp, (unsigned long)iocbs, &iocbp)) {
127 /* No point in trying to read iocbs+1 etc */
128 /* (nr can be ridiculously large): */
129 break;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000130 }
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000131 tprints("{");
132 if (umove_or_printaddr(tcp, (unsigned long)iocbp, &iocb)) {
133 tprints("}");
134 continue;
135 }
136 if (iocb.data) {
137 tprints("data=");
138 printaddr((long) iocb.data);
139 tprints(", ");
140 }
141 if (iocb.key)
142 tprintf("key=%u, ", iocb.key);
143 sub = tprint_lio_opcode(iocb.aio_lio_opcode);
144 if (iocb.aio_reqprio)
145 tprintf(", reqprio=%d", iocb.aio_reqprio);
146 tprintf(", filedes=%d", iocb.aio_fildes);
147 switch (sub) {
148 case SUB_COMMON:
149#if HAVE_DECL_IO_CMD_PWRITE
150 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
151 tprints(", str=");
152 printstr(tcp, (unsigned long)iocb.u.c.buf,
153 iocb.u.c.nbytes);
154 } else
155#endif
156 {
157 tprints(", buf=");
158 printaddr((long) iocb.u.c.buf);
159 }
160 tprintf(", nbytes=%lu, offset=%lld",
161 iocb.u.c.nbytes,
162 iocb.u.c.offset);
163 print_common_flags(&iocb);
164 break;
165 case SUB_VECTOR:
166 tprintf(", %lld", iocb.u.v.offset);
167 print_common_flags(&iocb);
168 tprints(", ");
169 tprint_iov(tcp, iocb.u.v.nr,
170 (unsigned long)iocb.u.v.vec,
171#if HAVE_DECL_IO_CMD_PWRITEV
172 iocb.aio_lio_opcode == IO_CMD_PWRITEV
173#else
174 0
175#endif
176 );
177 break;
178 case SUB_POLL:
179 tprintf(", %x", iocb.u.poll.events);
180 break;
181 case SUB_NONE:
182 break;
183 }
184 tprints("}");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000185 }
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000186 }
187 tprints("]");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000188#else
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000189# warning "libaio.h is not available => no io_submit decoding"
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000190 tprintf("%lu, %ld, %#lx", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
191#endif
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000192 return RVAL_DECODED;
193}
194
195static int
196print_io_event(struct tcb *tcp, const long addr)
197{
198#ifdef HAVE_LIBAIO_H
199 struct io_event event;
200
201 if (umove_or_printaddr(tcp, addr, &event))
202 return -1;
203 tprints("{data=");
204 printaddr((long) event.data);
205 tprints(", obj=");
206 printaddr((long) event.obj);
207 tprintf(", res=%ld, res2=%ld}", event.res, event.res2);
208#else
209 printaddr(tcp->u_arg[2]);
210#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000211 return 0;
212}
213
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000214SYS_FUNC(io_cancel)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000215{
216 if (entering(tcp)) {
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000217 tprintf("%lu, ", tcp->u_arg[0]);
218#ifdef HAVE_LIBAIO_H
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000219 struct iocb iocb;
220
221 if (!umove_or_printaddr(tcp, tcp->u_arg[1], &iocb)) {
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000222 tprintf("{%p, %u, %u, %u, %d}, ",
223 iocb.data, iocb.key,
224 (unsigned)iocb.aio_lio_opcode,
225 (unsigned)iocb.aio_reqprio, iocb.aio_fildes);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000226 }
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000227#else
228 printaddr(tcp->u_arg[1]);
229#endif
230 } else {
231 print_io_event(tcp, tcp->u_arg[2]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000232 }
233 return 0;
234}
235
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000236SYS_FUNC(io_getevents)
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000237{
238 if (entering(tcp)) {
239 tprintf("%ld, %ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1],
240 tcp->u_arg[2]);
241 } else {
242 if (tcp->u_rval == 0) {
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000243 tprints("[]");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000244 } else {
245#ifdef HAVE_LIBAIO_H
246 struct io_event *events = (void *)tcp->u_arg[3];
247 long i, nr = tcp->u_rval;
248
249 for (i = 0; i < nr; i++, events++) {
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000250 if (i == 0)
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000251 tprints("[");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000252 else
253 tprints(", ");
254
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000255 if (print_io_event(tcp, (long)events))
256 break;
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000257 }
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000258 tprints("], ");
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000259#else
Dmitry V. Levin07eaf502015-07-20 18:40:46 +0000260 printaddr(tcp->u_arg[3]);
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000261#endif
262 }
263
264 print_timespec(tcp, tcp->u_arg[4]);
265 }
266 return 0;
267}