blob: 18e53013f208c5373496299e375e7f11dc13fd26 [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
41int
42sys_io_setup(struct tcb *tcp)
43{
44 if (entering(tcp))
45 tprintf("%ld, ", tcp->u_arg[0]);
46 else {
47 if (syserror(tcp))
48 tprintf("0x%0lx", tcp->u_arg[1]);
49 else {
50 unsigned long user_id;
51 if (umove(tcp, tcp->u_arg[1], &user_id) == 0)
52 tprintf("{%lu}", user_id);
53 else
54 tprints("{...}");
55 }
56 }
57 return 0;
58}
59
60int
61sys_io_destroy(struct tcb *tcp)
62{
63 if (entering(tcp))
64 tprintf("%lu", tcp->u_arg[0]);
65 return 0;
66}
67
68#ifdef HAVE_LIBAIO_H
69
70enum iocb_sub {
71 SUB_NONE, SUB_COMMON, SUB_POLL, SUB_VECTOR
72};
73
74static enum iocb_sub
75tprint_lio_opcode(unsigned cmd)
76{
77 static const struct {
78 const char *name;
79 enum iocb_sub sub;
80 } cmds[] = {
81 { "pread", SUB_COMMON },
82 { "pwrite", SUB_COMMON },
83 { "fsync", SUB_NONE },
84 { "fdsync", SUB_NONE },
85 { "op4", SUB_NONE },
86 { "poll", SUB_POLL },
87 { "noop", SUB_NONE },
88 { "preadv", SUB_VECTOR },
89 { "pwritev", SUB_VECTOR },
90 };
91
92 if (cmd < ARRAY_SIZE(cmds)) {
93 tprints(cmds[cmd].name);
94 return cmds[cmd].sub;
95 }
96 tprintf("%u /* SUB_??? */", cmd);
97 return SUB_NONE;
98}
99
100static void
101print_common_flags(struct iocb *iocb)
102{
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000103#if HAVE_STRUCT_IOCB_U_C_FLAGS
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000104 if (iocb->u.c.flags & IOCB_RESFD)
105 tprintf(", resfd=%d", iocb->u.c.resfd);
106 if (iocb->u.c.flags & ~IOCB_RESFD)
107 tprintf(", flags=%x", iocb->u.c.flags);
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000108#else
109# warning "libaio.h is too old => limited io_submit decoding"
110#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000111}
112
113#endif /* HAVE_LIBAIO_H */
114
115int
116sys_io_submit(struct tcb *tcp)
117{
118 if (entering(tcp)) {
119#ifdef HAVE_LIBAIO_H
120 long nr = tcp->u_arg[1];
121 /* if nr <= 0, we end up printing just "{}" */
122 tprintf("%lu, %ld, {", tcp->u_arg[0], tcp->u_arg[1]);
123 {
124 long i;
125 struct iocb **iocbs = (void *)tcp->u_arg[2];
126//FIXME: decoding of 32-bit call by 64-bit strace
127
128 for (i = 0; i < nr; i++, iocbs++) {
129 enum iocb_sub sub;
130 struct iocb *iocbp;
131 struct iocb iocb;
132 if (i)
133 tprints(", ");
134
135 if (umove(tcp, (unsigned long)iocbs, &iocbp)) {
136 tprintf("%#lx", (unsigned long)iocbs);
137 /* No point in trying to read iocbs+1 etc */
138 /* (nr can be ridiculously large): */
139 break;
140 }
141 if (umove(tcp, (unsigned long)iocbp, &iocb)) {
142 tprintf("{%#lx}", (unsigned long)iocbp);
143 continue;
144 }
145 tprints("{");
146 if (iocb.data)
147 tprintf("data:%p, ", iocb.data);
148 if (iocb.key)
149 tprintf("key:%u, ", iocb.key);
150 sub = tprint_lio_opcode(iocb.aio_lio_opcode);
151 if (iocb.aio_reqprio)
152 tprintf(", reqprio:%d", iocb.aio_reqprio);
153 tprintf(", filedes:%d", iocb.aio_fildes);
154 switch (sub) {
155 case SUB_COMMON:
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000156#if HAVE_DECL_IO_CMD_PWRITE
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000157 if (iocb.aio_lio_opcode == IO_CMD_PWRITE) {
158 tprints(", str:");
159 printstr(tcp, (unsigned long)iocb.u.c.buf,
160 iocb.u.c.nbytes);
161 } else
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000162#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000163 tprintf(", buf:%p", iocb.u.c.buf);
164 tprintf(", nbytes:%lu, offset:%lld",
165 iocb.u.c.nbytes,
166 iocb.u.c.offset);
167 print_common_flags(&iocb);
168 break;
169 case SUB_VECTOR:
170 tprintf(", %lld", iocb.u.v.offset);
171 print_common_flags(&iocb);
172 tprints(", ");
173 tprint_iov(tcp, iocb.u.v.nr,
174 (unsigned long)iocb.u.v.vec,
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000175#if HAVE_DECL_IO_CMD_PWRITEV
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000176 iocb.aio_lio_opcode == IO_CMD_PWRITEV
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000177#else
178 0
179#endif
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000180 );
181 break;
182 case SUB_POLL:
183 tprintf(", %x", iocb.u.poll.events);
184 break;
185 case SUB_NONE:
186 break;
187 }
188 tprints("}");
189 }
190 }
191 tprints("}");
192#else
Dmitry V. Levinb7dd5e62014-09-08 15:20:10 +0000193# warning "libaio.h is not available => no io_submit decoding"
Dmitry V. Levin2b640342013-11-11 15:06:18 +0000194 tprintf("%lu, %ld, %#lx", tcp->u_arg[0], tcp->u_arg[1], tcp->u_arg[2]);
195#endif
196 }
197 return 0;
198}
199
200int
201sys_io_cancel(struct tcb *tcp)
202{
203 if (entering(tcp)) {
204#ifdef HAVE_LIBAIO_H
205 struct iocb iocb;
206#endif
207 tprintf("%lu, ", tcp->u_arg[0]);
208#ifdef HAVE_LIBAIO_H
209 if (umove(tcp, tcp->u_arg[1], &iocb) == 0) {
210 tprintf("{%p, %u, %u, %u, %d}, ",
211 iocb.data, iocb.key,
212 (unsigned)iocb.aio_lio_opcode,
213 (unsigned)iocb.aio_reqprio, iocb.aio_fildes);
214 } else
215#endif
216 tprints("{...}, ");
217 } else {
218 if (tcp->u_rval < 0)
219 tprints("{...}");
220 else {
221#ifdef HAVE_LIBAIO_H
222 struct io_event event;
223 if (umove(tcp, tcp->u_arg[2], &event) == 0)
224 tprintf("{%p, %p, %ld, %ld}",
225 event.data, event.obj,
226 event.res, event.res2);
227 else
228#endif
229 tprints("{...}");
230 }
231 }
232 return 0;
233}
234
235int
236sys_io_getevents(struct tcb *tcp)
237{
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) {
243 tprints("{}");
244 } 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++) {
250 struct io_event event;
251
252 if (i == 0)
253 tprints("{");
254 else
255 tprints(", ");
256
257 if (umove(tcp, (unsigned long)events, &event) != 0) {
258 tprints("{...}");
259 continue;
260 }
261 tprintf("{%p, %p, %ld, %ld}", event.data,
262 event.obj, event.res, event.res2);
263 }
264 tprints("}, ");
265#else
266 tprints("{...}");
267#endif
268 }
269
270 print_timespec(tcp, tcp->u_arg[4]);
271 }
272 return 0;
273}