blob: 7dff4e63b1a2a8239b519ded522b57025e3618f2 [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +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>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00005 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00006 * 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 * $Id$
31 */
32
33#include "defs.h"
34
35#include <fcntl.h>
John Hughes1d08dcf2001-07-10 13:48:44 +000036#if HAVE_SYS_UIO_H
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000037#include <sys/uio.h>
John Hughes1d08dcf2001-07-10 13:48:44 +000038#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000039
40int
Dmitry V. Levin31382132011-03-04 05:08:02 +030041sys_read(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000042{
43 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +030044 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020045 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000046 } else {
47 if (syserror(tcp))
48 tprintf("%#lx", tcp->u_arg[1]);
49 else
50 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
51 tprintf(", %lu", tcp->u_arg[2]);
52 }
53 return 0;
54}
55
56int
Dmitry V. Levin31382132011-03-04 05:08:02 +030057sys_write(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058{
59 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +030060 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020061 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
63 tprintf(", %lu", tcp->u_arg[2]);
64 }
65 return 0;
66}
67
John Hughes1d08dcf2001-07-10 13:48:44 +000068#if HAVE_SYS_UIO_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000069void
Dmitry V. Levin88849682011-06-13 22:58:44 +000070tprint_iov(struct tcb *tcp, unsigned long len, unsigned long addr, int decode_iov)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000071{
Denys Vlasenko84703742012-02-25 02:38:52 +010072#if SUPPORTED_PERSONALITIES > 1
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000073 union {
74 struct { u_int32_t base; u_int32_t len; } iov32;
75 struct { u_int64_t base; u_int64_t len; } iov64;
76 } iov;
77#define sizeof_iov \
78 (personality_wordsize[current_personality] == 4 \
79 ? sizeof(iov.iov32) : sizeof(iov.iov64))
80#define iov_iov_base \
81 (personality_wordsize[current_personality] == 4 \
82 ? (u_int64_t) iov.iov32.base : iov.iov64.base)
83#define iov_iov_len \
84 (personality_wordsize[current_personality] == 4 \
85 ? (u_int64_t) iov.iov32.len : iov.iov64.len)
86#else
Roland McGrathaa524c82005-06-01 19:22:06 +000087 struct iovec iov;
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000088#define sizeof_iov sizeof(iov)
89#define iov_iov_base iov.iov_base
90#define iov_iov_len iov.iov_len
91#endif
Roland McGrathaa524c82005-06-01 19:22:06 +000092 unsigned long size, cur, end, abbrev_end;
93 int failed = 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000094
95 if (!len) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020096 tprints("[]");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000097 return;
98 }
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000099 size = len * sizeof_iov;
Roland McGrathaa524c82005-06-01 19:22:06 +0000100 end = addr + size;
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000101 if (!verbose(tcp) || size / sizeof_iov != len || end < addr) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000102 tprintf("%#lx", addr);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000103 return;
104 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000105 if (abbrev(tcp)) {
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000106 abbrev_end = addr + max_strlen * sizeof_iov;
Roland McGrathaa524c82005-06-01 19:22:06 +0000107 if (abbrev_end < addr)
108 abbrev_end = end;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000109 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000110 abbrev_end = end;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000111 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200112 tprints("[");
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000113 for (cur = addr; cur < end; cur += sizeof_iov) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000114 if (cur > addr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200115 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000116 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200117 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000118 break;
119 }
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000120 if (umoven(tcp, cur, sizeof_iov, (char *) &iov) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200121 tprints("?");
Roland McGrathaa524c82005-06-01 19:22:06 +0000122 failed = 1;
123 break;
124 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200125 tprints("{");
Dmitry V. Levin88849682011-06-13 22:58:44 +0000126 if (decode_iov)
127 printstr(tcp, (long) iov_iov_base, iov_iov_len);
128 else
129 tprintf("%#lx", (long) iov_iov_base);
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000130 tprintf(", %lu}", (unsigned long)iov_iov_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000131 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200132 tprints("]");
Roland McGrathaa524c82005-06-01 19:22:06 +0000133 if (failed)
134 tprintf(" %#lx", addr);
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000135#undef sizeof_iov
136#undef iov_iov_base
137#undef iov_iov_len
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000138}
139
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300141sys_readv(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000143 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300144 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200145 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000146 } else {
147 if (syserror(tcp)) {
148 tprintf("%#lx, %lu",
149 tcp->u_arg[1], tcp->u_arg[2]);
150 return 0;
151 }
Dmitry V. Levin88849682011-06-13 22:58:44 +0000152 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153 tprintf(", %lu", tcp->u_arg[2]);
154 }
155 return 0;
156}
157
158int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300159sys_writev(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000160{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000161 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300162 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200163 tprints(", ");
Dmitry V. Levin88849682011-06-13 22:58:44 +0000164 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000165 tprintf(", %lu", tcp->u_arg[2]);
166 }
167 return 0;
168}
John Hughes1d08dcf2001-07-10 13:48:44 +0000169#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000170
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000172
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000173
174/* The SH4 ABI does allow long longs in odd-numbered registers, but
175 does not allow them to be split between registers and memory - and
176 there are only four argument registers for normal functions. As a
177 result pread takes an extra padding argument before the offset. This
178 was changed late in the 2.4 series (around 2.4.20). */
179#if defined(SH)
180#define PREAD_OFFSET_ARG 4
181#else
182#define PREAD_OFFSET_ARG 3
183#endif
184
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000185int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300186sys_pread(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187{
188 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300189 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200190 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 } else {
192 if (syserror(tcp))
193 tprintf("%#lx", tcp->u_arg[1]);
194 else
195 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100196 tprintf(", %lu, ", tcp->u_arg[2]);
197 printllval(tcp, "%llu", PREAD_OFFSET_ARG);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000198 }
199 return 0;
200}
201
202int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300203sys_pwrite(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000204{
205 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300206 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200207 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000208 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100209 tprintf(", %lu, ", tcp->u_arg[2]);
210 printllval(tcp, "%llu", PREAD_OFFSET_ARG);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000211 }
212 return 0;
213}
214
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400215#if HAVE_SYS_UIO_H
216int
217sys_preadv(struct tcb *tcp)
218{
219 if (entering(tcp)) {
220 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200221 tprints(", ");
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400222 } else {
223 if (syserror(tcp)) {
224 tprintf("%#lx, %lu", tcp->u_arg[1], tcp->u_arg[2]);
225 return 0;
226 }
Dmitry V. Levin88849682011-06-13 22:58:44 +0000227 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400228 tprintf(", %lu, ", tcp->u_arg[2]);
229 printllval(tcp, "%llu", PREAD_OFFSET_ARG);
230 }
231 return 0;
232}
233
234int
235sys_pwritev(struct tcb *tcp)
236{
237 if (entering(tcp)) {
238 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200239 tprints(", ");
Dmitry V. Levin88849682011-06-13 22:58:44 +0000240 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400241 tprintf(", %lu, ", tcp->u_arg[2]);
242 printllval(tcp, "%llu", PREAD_OFFSET_ARG);
243 }
244 return 0;
245}
246#endif /* HAVE_SYS_UIO_H */
247
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000248int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300249sys_sendfile(struct tcb *tcp)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000250{
251 if (entering(tcp)) {
252 off_t offset;
253
Dmitry V. Levin31382132011-03-04 05:08:02 +0300254 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200255 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300256 printfd(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200257 tprints(", ");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000258 if (!tcp->u_arg[2])
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200259 tprints("NULL");
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000260 else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
261 tprintf("%#lx", tcp->u_arg[2]);
262 else
H.J. Lu6ca26102012-02-03 10:12:10 -0800263#ifdef HAVE_LONG_LONG_OFF_T
264 tprintf("[%llu]", offset);
265#else
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000266 tprintf("[%lu]", offset);
H.J. Lu6ca26102012-02-03 10:12:10 -0800267#endif
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000268 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000269 }
270 return 0;
271}
272
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000273static void
274print_loff_t(struct tcb *tcp, long addr)
275{
276 loff_t offset;
277
278 if (!addr)
279 tprints("NULL");
280 else if (umove(tcp, addr, &offset) < 0)
281 tprintf("%#lx", addr);
282 else
283 tprintf("[%llu]", (unsigned long long int) offset);
284}
285
Roland McGrath186c5ac2002-12-15 23:58:23 +0000286int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300287sys_sendfile64(struct tcb *tcp)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000288{
289 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300290 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200291 tprints(", ");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300292 printfd(tcp, tcp->u_arg[1]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200293 tprints(", ");
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000294 print_loff_t(tcp, tcp->u_arg[2]);
Roland McGrath186c5ac2002-12-15 23:58:23 +0000295 tprintf(", %lu", tcp->u_arg[3]);
296 }
297 return 0;
298}
299
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000300static const struct xlat splice_flags[] = {
301#ifdef SPLICE_F_MOVE
302 { SPLICE_F_MOVE, "SPLICE_F_MOVE" },
303#endif
304#ifdef SPLICE_F_NONBLOCK
305 { SPLICE_F_NONBLOCK, "SPLICE_F_NONBLOCK" },
306#endif
307#ifdef SPLICE_F_MORE
308 { SPLICE_F_MORE, "SPLICE_F_MORE" },
309#endif
310#ifdef SPLICE_F_GIFT
311 { SPLICE_F_GIFT, "SPLICE_F_GIFT" },
312#endif
313 { 0, NULL },
314};
315
316int
317sys_tee(struct tcb *tcp)
318{
319 if (entering(tcp)) {
320 /* int fd_in */
321 printfd(tcp, tcp->u_arg[0]);
322 tprints(", ");
323 /* int fd_out */
324 printfd(tcp, tcp->u_arg[1]);
325 tprints(", ");
326 /* size_t len */
327 tprintf("%lu, ", tcp->u_arg[2]);
328 /* unsigned int flags */
329 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
330 }
331 return 0;
332}
333
334int
335sys_splice(struct tcb *tcp)
336{
337 if (entering(tcp)) {
338 /* int fd_in */
339 printfd(tcp, tcp->u_arg[0]);
340 tprints(", ");
341 /* loff_t *off_in */
342 print_loff_t(tcp, tcp->u_arg[1]);
343 tprints(", ");
344 /* int fd_out */
345 printfd(tcp, tcp->u_arg[2]);
346 tprints(", ");
347 /* loff_t *off_out */
348 print_loff_t(tcp, tcp->u_arg[3]);
349 tprints(", ");
350 /* size_t len */
351 tprintf("%lu, ", tcp->u_arg[4]);
352 /* unsigned int flags */
353 printflags(splice_flags, tcp->u_arg[5], "SPLICE_F_???");
354 }
355 return 0;
356}
357
358int
359sys_vmsplice(struct tcb *tcp)
360{
361 if (entering(tcp)) {
362 /* int fd */
363 printfd(tcp, tcp->u_arg[0]);
364 tprints(", ");
365 /* const struct iovec *iov, unsigned long nr_segs */
366 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
367 tprints(", ");
368 /* unsigned int flags */
369 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
370 }
371 return 0;
372}
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000373
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000374int
Dmitry V. Levin31382132011-03-04 05:08:02 +0300375sys_ioctl(struct tcb *tcp)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000376{
Roland McGrathee36ce12004-09-04 03:53:10 +0000377 const struct ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000378
379 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300380 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200381 tprints(", ");
Roland McGrath2843a4e2003-11-14 02:54:03 +0000382 iop = ioctl_lookup(tcp->u_arg[1]);
383 if (iop) {
Denys Vlasenko5940e652011-09-01 09:55:05 +0200384 tprints(iop->symbol);
Roland McGrath2843a4e2003-11-14 02:54:03 +0000385 while ((iop = ioctl_next_match(iop)))
386 tprintf(" or %s", iop->symbol);
387 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000388 tprintf("%#lx", tcp->u_arg[1]);
389 ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
390 }
391 else {
Denys Vlasenko5d645812011-08-20 12:48:18 +0200392 int ret = ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
393 if (!ret)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000394 tprintf(", %#lx", tcp->u_arg[2]);
John Hughes38ae88d2002-05-23 11:48:58 +0000395 else
396 return ret - 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397 }
398 return 0;
399}