blob: b701f81b7eb796ea9419aa551d4f6db04520a5e5 [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.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000029 */
30
31#include "defs.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000032#include <fcntl.h>
Dmitry V. Levinb2fa2be2014-11-21 20:46:16 +000033#include <sys/uio.h>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000034
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000035SYS_FUNC(read)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000036{
37 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +030038 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020039 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000040 } else {
41 if (syserror(tcp))
Dmitry V. Levin43b5a1f2015-07-20 11:06:54 +000042 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000043 else
44 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
45 tprintf(", %lu", tcp->u_arg[2]);
46 }
47 return 0;
48}
49
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000050SYS_FUNC(write)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000051{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +000052 printfd(tcp, tcp->u_arg[0]);
53 tprints(", ");
54 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
55 tprintf(", %lu", tcp->u_arg[2]);
56
57 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000058}
59
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +020060/*
61 * data_size limits the cumulative size of printed data.
62 * Example: recvmsg returing a short read.
63 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000064void
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +020065tprint_iov_upto(struct tcb *tcp, unsigned long len, unsigned long addr, int decode_iov, unsigned long data_size)
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000066{
Denys Vlasenko84703742012-02-25 02:38:52 +010067#if SUPPORTED_PERSONALITIES > 1
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000068 union {
69 struct { u_int32_t base; u_int32_t len; } iov32;
70 struct { u_int64_t base; u_int64_t len; } iov64;
71 } iov;
72#define sizeof_iov \
Denys Vlasenko9fd4f962012-03-19 09:36:42 +010073 (current_wordsize == 4 ? sizeof(iov.iov32) : sizeof(iov.iov64))
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000074#define iov_iov_base \
Denys Vlasenko9fd4f962012-03-19 09:36:42 +010075 (current_wordsize == 4 ? (uint64_t) iov.iov32.base : iov.iov64.base)
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000076#define iov_iov_len \
Denys Vlasenko9fd4f962012-03-19 09:36:42 +010077 (current_wordsize == 4 ? (uint64_t) iov.iov32.len : iov.iov64.len)
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000078#else
Roland McGrathaa524c82005-06-01 19:22:06 +000079 struct iovec iov;
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000080#define sizeof_iov sizeof(iov)
81#define iov_iov_base iov.iov_base
82#define iov_iov_len iov.iov_len
83#endif
Roland McGrathaa524c82005-06-01 19:22:06 +000084 unsigned long size, cur, end, abbrev_end;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000085
86 if (!len) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020087 tprints("[]");
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000088 return;
89 }
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000090 size = len * sizeof_iov;
Roland McGrathaa524c82005-06-01 19:22:06 +000091 end = addr + size;
Dmitry V. Levin43b5a1f2015-07-20 11:06:54 +000092 if (!verbose(tcp) || (exiting(tcp) && syserror(tcp)) ||
93 !addr || size / sizeof_iov != len || end < addr) {
94 printaddr(addr);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000095 return;
96 }
Roland McGrathaa524c82005-06-01 19:22:06 +000097 if (abbrev(tcp)) {
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000098 abbrev_end = addr + max_strlen * sizeof_iov;
Roland McGrathaa524c82005-06-01 19:22:06 +000099 if (abbrev_end < addr)
100 abbrev_end = end;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000101 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000102 abbrev_end = end;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000103 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200104 tprints("[");
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000105 for (cur = addr; cur < end; cur += sizeof_iov) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000106 if (cur > addr)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200107 tprints(", ");
Roland McGrathaa524c82005-06-01 19:22:06 +0000108 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200109 tprints("...");
Roland McGrathaa524c82005-06-01 19:22:06 +0000110 break;
111 }
Dmitry V. Levin43b5a1f2015-07-20 11:06:54 +0000112 if (umoven_or_printaddr(tcp, cur, sizeof_iov, &iov))
Roland McGrathaa524c82005-06-01 19:22:06 +0000113 break;
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200114 tprints("{");
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200115 if (decode_iov) {
116 unsigned long len = iov_iov_len;
117 if (len > data_size)
118 len = data_size;
119 data_size -= len;
120 printstr(tcp, (long) iov_iov_base, len);
121 } else
Dmitry V. Levin43b5a1f2015-07-20 11:06:54 +0000122 printaddr((long) iov_iov_base);
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000123 tprintf(", %lu}", (unsigned long)iov_iov_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000124 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200125 tprints("]");
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000126#undef sizeof_iov
127#undef iov_iov_base
128#undef iov_iov_len
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000129}
130
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200131void
132tprint_iov(struct tcb *tcp, unsigned long len, unsigned long addr, int decode_iov)
133{
Dmitry V. Levin043b5f82012-05-01 20:30:02 +0000134 tprint_iov_upto(tcp, len, addr, decode_iov, (unsigned long) -1L);
Denys Vlasenkoe0bc2222012-04-28 14:26:18 +0200135}
136
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000137SYS_FUNC(readv)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000138{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000139 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300140 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200141 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000142 } else {
Dmitry V. Levin88849682011-06-13 22:58:44 +0000143 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000144 tprintf(", %lu", tcp->u_arg[2]);
145 }
146 return 0;
147}
148
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000149SYS_FUNC(writev)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000150{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000151 printfd(tcp, tcp->u_arg[0]);
152 tprints(", ");
153 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
154 tprintf(", %lu", tcp->u_arg[2]);
155
156 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000157}
158
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000159/* The SH4 ABI does allow long longs in odd-numbered registers, but
160 does not allow them to be split between registers and memory - and
161 there are only four argument registers for normal functions. As a
162 result pread takes an extra padding argument before the offset. This
163 was changed late in the 2.4 series (around 2.4.20). */
164#if defined(SH)
165#define PREAD_OFFSET_ARG 4
166#else
167#define PREAD_OFFSET_ARG 3
168#endif
169
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000170SYS_FUNC(pread)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171{
172 if (entering(tcp)) {
Dmitry V. Levin31382132011-03-04 05:08:02 +0300173 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200174 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000175 } else {
176 if (syserror(tcp))
Dmitry V. Levin43b5a1f2015-07-20 11:06:54 +0000177 printaddr(tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000178 else
179 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Andreas Schwabb5600fc2009-11-04 17:08:34 +0100180 tprintf(", %lu, ", tcp->u_arg[2]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000181 printllval(tcp, "%llu", PREAD_OFFSET_ARG);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 }
183 return 0;
184}
185
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000186SYS_FUNC(pwrite)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000187{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000188 printfd(tcp, tcp->u_arg[0]);
189 tprints(", ");
190 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
191 tprintf(", %lu, ", tcp->u_arg[2]);
192 printllval(tcp, "%llu", PREAD_OFFSET_ARG);
193
194 return RVAL_DECODED;
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000195}
196
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000197static void
198print_llu_from_low_high_val(struct tcb *tcp, int arg)
199{
200#if SIZEOF_LONG == SIZEOF_LONG_LONG
Dmitry V. Levin5de5a7a2015-01-23 20:04:37 +0000201# if SUPPORTED_PERSONALITIES > 1
202 if (current_wordsize == sizeof(long))
203# endif
204 tprintf("%lu", (unsigned long) tcp->u_arg[arg]);
205# if SUPPORTED_PERSONALITIES > 1
206 else
207 tprintf("%lu",
208 ((unsigned long) tcp->u_arg[arg + 1] << current_wordsize * 8)
209 | (unsigned long) tcp->u_arg[arg]);
210# endif
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000211#else
212# ifdef X32
213 if (current_personality == 0)
214 tprintf("%llu", (unsigned long long) tcp->ext_arg[arg]);
215 else
216# endif
217 tprintf("%llu",
Dmitry V. Levin20b84a62014-08-07 11:42:46 +0000218 ((unsigned long long) (unsigned long) tcp->u_arg[arg + 1] << sizeof(long) * 8)
219 | (unsigned long long) (unsigned long) tcp->u_arg[arg]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000220#endif
221}
222
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000223SYS_FUNC(preadv)
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400224{
225 if (entering(tcp)) {
226 printfd(tcp, tcp->u_arg[0]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200227 tprints(", ");
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400228 } else {
Dmitry V. Levin88849682011-06-13 22:58:44 +0000229 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400230 tprintf(", %lu, ", tcp->u_arg[2]);
Dmitry V. Levin3c49b022014-08-07 00:07:28 +0000231 print_llu_from_low_high_val(tcp, 3);
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400232 }
233 return 0;
234}
235
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000236SYS_FUNC(pwritev)
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400237{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000238 printfd(tcp, tcp->u_arg[0]);
239 tprints(", ");
240 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
241 tprintf(", %lu, ", tcp->u_arg[2]);
242 print_llu_from_low_high_val(tcp, 3);
243
244 return RVAL_DECODED;
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400245}
Damir Shayhutdinov3087dd62011-05-12 16:57:40 +0400246
Dmitry V. Levin2c42f322013-03-20 09:48:44 +0000247static void
248print_off_t(struct tcb *tcp, long addr)
249{
Dmitry V. Levin43b5a1f2015-07-20 11:06:54 +0000250 if (current_wordsize == sizeof(int))
251 printnum_int(tcp, addr, "%u");
Dmitry V. Levin2c42f322013-03-20 09:48:44 +0000252 else
Dmitry V. Levin43b5a1f2015-07-20 11:06:54 +0000253 printnum_long(tcp, addr, "%lu");
Dmitry V. Levin2c42f322013-03-20 09:48:44 +0000254}
255
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000256SYS_FUNC(sendfile)
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000257{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000258 printfd(tcp, tcp->u_arg[0]);
259 tprints(", ");
260 printfd(tcp, tcp->u_arg[1]);
261 tprints(", ");
262 print_off_t(tcp, tcp->u_arg[2]);
263 tprintf(", %lu", tcp->u_arg[3]);
264
265 return RVAL_DECODED;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000266}
267
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000268SYS_FUNC(sendfile64)
Roland McGrath186c5ac2002-12-15 23:58:23 +0000269{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000270 printfd(tcp, tcp->u_arg[0]);
271 tprints(", ");
272 printfd(tcp, tcp->u_arg[1]);
273 tprints(", ");
274 printnum_int64(tcp, tcp->u_arg[2], "%" PRIu64);
275 tprintf(", %lu", tcp->u_arg[3]);
276
277 return RVAL_DECODED;
Roland McGrath186c5ac2002-12-15 23:58:23 +0000278}
279
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000280#include "xlat/splice_flags.h"
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000281
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000282SYS_FUNC(tee)
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000283{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000284 /* int fd_in */
285 printfd(tcp, tcp->u_arg[0]);
286 tprints(", ");
287 /* int fd_out */
288 printfd(tcp, tcp->u_arg[1]);
289 tprints(", ");
290 /* size_t len */
291 tprintf("%lu, ", tcp->u_arg[2]);
292 /* unsigned int flags */
293 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
294
295 return RVAL_DECODED;
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000296}
297
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000298SYS_FUNC(splice)
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000299{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000300 /* int fd_in */
301 printfd(tcp, tcp->u_arg[0]);
302 tprints(", ");
303 /* loff_t *off_in */
304 printnum_int64(tcp, tcp->u_arg[1], "%" PRIu64);
305 tprints(", ");
306 /* int fd_out */
307 printfd(tcp, tcp->u_arg[2]);
308 tprints(", ");
309 /* loff_t *off_out */
310 printnum_int64(tcp, tcp->u_arg[3], "%" PRIu64);
311 tprints(", ");
312 /* size_t len */
313 tprintf("%lu, ", tcp->u_arg[4]);
314 /* unsigned int flags */
315 printflags(splice_flags, tcp->u_arg[5], "SPLICE_F_???");
316
317 return RVAL_DECODED;
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000318}
319
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000320SYS_FUNC(vmsplice)
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000321{
Dmitry V. Levin1f255fd2015-07-20 11:19:30 +0000322 /* int fd */
323 printfd(tcp, tcp->u_arg[0]);
324 tprints(", ");
325 /* const struct iovec *iov, unsigned long nr_segs */
326 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], 1);
327 tprintf(", %lu, ", tcp->u_arg[2]);
328 /* unsigned int flags */
329 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
330
331 return RVAL_DECODED;
Dmitry V. Levind99e48c2011-10-11 17:07:05 +0000332}