blob: add3fb60a80f08025d806ff4023f4db55187e80f [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
John Hughes70623be2001-03-08 13:59:00 +000040#ifdef HAVE_LONG_LONG_OFF_T
41/*
42 * Hacks for systems that have a long long off_t
43 */
44
45#define sys_pread64 sys_pread
46#define sys_pwrite64 sys_pwrite
47#endif
48
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049int
50sys_read(tcp)
51struct tcb *tcp;
52{
53 if (entering(tcp)) {
54 tprintf("%ld, ", tcp->u_arg[0]);
55 } else {
56 if (syserror(tcp))
57 tprintf("%#lx", tcp->u_arg[1]);
58 else
59 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
60 tprintf(", %lu", tcp->u_arg[2]);
61 }
62 return 0;
63}
64
65int
66sys_write(tcp)
67struct tcb *tcp;
68{
69 if (entering(tcp)) {
70 tprintf("%ld, ", tcp->u_arg[0]);
71 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
72 tprintf(", %lu", tcp->u_arg[2]);
73 }
74 return 0;
75}
76
John Hughes1d08dcf2001-07-10 13:48:44 +000077#if HAVE_SYS_UIO_H
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000078void
79tprint_iov(tcp, len, addr)
80struct tcb * tcp;
Roland McGrathaa524c82005-06-01 19:22:06 +000081unsigned long len;
82unsigned long addr;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000083{
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +000084#if defined(LINUX) && SUPPORTED_PERSONALITIES > 1
85 union {
86 struct { u_int32_t base; u_int32_t len; } iov32;
87 struct { u_int64_t base; u_int64_t len; } iov64;
88 } iov;
89#define sizeof_iov \
90 (personality_wordsize[current_personality] == 4 \
91 ? sizeof(iov.iov32) : sizeof(iov.iov64))
92#define iov_iov_base \
93 (personality_wordsize[current_personality] == 4 \
94 ? (u_int64_t) iov.iov32.base : iov.iov64.base)
95#define iov_iov_len \
96 (personality_wordsize[current_personality] == 4 \
97 ? (u_int64_t) iov.iov32.len : iov.iov64.len)
98#else
Roland McGrathaa524c82005-06-01 19:22:06 +000099 struct iovec iov;
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000100#define sizeof_iov sizeof(iov)
101#define iov_iov_base iov.iov_base
102#define iov_iov_len iov.iov_len
103#endif
Roland McGrathaa524c82005-06-01 19:22:06 +0000104 unsigned long size, cur, end, abbrev_end;
105 int failed = 0;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000106
107 if (!len) {
108 tprintf("[]");
109 return;
110 }
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000111 size = len * sizeof_iov;
Roland McGrathaa524c82005-06-01 19:22:06 +0000112 end = addr + size;
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000113 if (!verbose(tcp) || size / sizeof_iov != len || end < addr) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000114 tprintf("%#lx", addr);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000115 return;
116 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000117 if (abbrev(tcp)) {
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000118 abbrev_end = addr + max_strlen * sizeof_iov;
Roland McGrathaa524c82005-06-01 19:22:06 +0000119 if (abbrev_end < addr)
120 abbrev_end = end;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000121 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000122 abbrev_end = end;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000123 }
Roland McGrathaa524c82005-06-01 19:22:06 +0000124 tprintf("[");
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000125 for (cur = addr; cur < end; cur += sizeof_iov) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000126 if (cur > addr)
127 tprintf(", ");
128 if (cur >= abbrev_end) {
129 tprintf("...");
130 break;
131 }
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000132 if (umoven(tcp, cur, sizeof_iov, (char *) &iov) < 0) {
Roland McGrathaa524c82005-06-01 19:22:06 +0000133 tprintf("?");
134 failed = 1;
135 break;
136 }
137 tprintf("{");
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000138 printstr(tcp, (long) iov_iov_base, iov_iov_len);
139 tprintf(", %lu}", (unsigned long)iov_iov_len);
Roland McGrathaa524c82005-06-01 19:22:06 +0000140 }
141 tprintf("]");
142 if (failed)
143 tprintf(" %#lx", addr);
Dmitry V. Levin4ebb4e32006-12-13 17:08:08 +0000144#undef sizeof_iov
145#undef iov_iov_base
146#undef iov_iov_len
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000147}
148
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000149int
150sys_readv(tcp)
151struct tcb *tcp;
152{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000153 if (entering(tcp)) {
154 tprintf("%ld, ", tcp->u_arg[0]);
155 } else {
156 if (syserror(tcp)) {
157 tprintf("%#lx, %lu",
158 tcp->u_arg[1], tcp->u_arg[2]);
159 return 0;
160 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000161 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000162 tprintf(", %lu", tcp->u_arg[2]);
163 }
164 return 0;
165}
166
167int
168sys_writev(tcp)
169struct tcb *tcp;
170{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000171 if (entering(tcp)) {
172 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000173 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000174 tprintf(", %lu", tcp->u_arg[2]);
175 }
176 return 0;
177}
John Hughes1d08dcf2001-07-10 13:48:44 +0000178#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000179
John Hughes5a826b82001-03-07 13:21:24 +0000180#if defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000181
182int
183sys_pread(tcp)
184struct tcb *tcp;
185{
186 if (entering(tcp)) {
187 tprintf("%ld, ", tcp->u_arg[0]);
188 } else {
189 if (syserror(tcp))
190 tprintf("%#lx", tcp->u_arg[1]);
191 else
192 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000193#if UNIXWARE
194 /* off_t is signed int */
195 tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
196#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000197 tprintf(", %lu, %llu", tcp->u_arg[2],
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000198 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000199#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200 }
201 return 0;
202}
203
204int
205sys_pwrite(tcp)
206struct tcb *tcp;
207{
208 if (entering(tcp)) {
209 tprintf("%ld, ", tcp->u_arg[0]);
210 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000211#if UNIXWARE
212 /* off_t is signed int */
213 tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
214#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000215 tprintf(", %lu, %llu", tcp->u_arg[2],
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000216 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000217#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000218 }
219 return 0;
220}
John Hughes5a826b82001-03-07 13:21:24 +0000221#endif /* SVR4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000222
223#ifdef FREEBSD
224#include <sys/types.h>
225#include <sys/socket.h>
226
227int
228sys_sendfile(tcp)
229struct tcb *tcp;
230{
231 if (entering(tcp)) {
232 tprintf("%ld, %ld, %llu, %lu", tcp->u_arg[0], tcp->u_arg[1],
Roland McGrath2fe2a3e2004-10-07 19:09:16 +0000233 LONG_LONG(tcp->u_arg[2], tcp->u_arg[3]),
234 tcp->u_arg[4]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000235 } else {
236 off_t offset;
237
238 if (!tcp->u_arg[5])
239 tprintf(", NULL");
240 else {
241 struct sf_hdtr hdtr;
242
243 if (umove(tcp, tcp->u_arg[5], &hdtr) < 0)
244 tprintf(", %#lx", tcp->u_arg[5]);
245 else {
246 tprintf(", { ");
247 tprint_iov(tcp, hdtr.hdr_cnt, hdtr.headers);
248 tprintf(", %u, ", hdtr.hdr_cnt);
249 tprint_iov(tcp, hdtr.trl_cnt, hdtr.trailers);
250 tprintf(", %u }", hdtr.hdr_cnt);
251 }
252 }
253 if (!tcp->u_arg[6])
254 tprintf(", NULL");
255 else if (umove(tcp, tcp->u_arg[6], &offset) < 0)
256 tprintf(", %#lx", tcp->u_arg[6]);
257 else
258 tprintf(", [%llu]", offset);
259 tprintf(", %lu", tcp->u_arg[7]);
260 }
261 return 0;
262}
263#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000264
265#ifdef LINUX
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000266
267/* The SH4 ABI does allow long longs in odd-numbered registers, but
268 does not allow them to be split between registers and memory - and
269 there are only four argument registers for normal functions. As a
270 result pread takes an extra padding argument before the offset. This
271 was changed late in the 2.4 series (around 2.4.20). */
272#if defined(SH)
273#define PREAD_OFFSET_ARG 4
274#else
275#define PREAD_OFFSET_ARG 3
276#endif
277
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000278int
279sys_pread(tcp)
280struct tcb *tcp;
281{
282 if (entering(tcp)) {
283 tprintf("%ld, ", tcp->u_arg[0]);
284 } else {
285 if (syserror(tcp))
286 tprintf("%#lx", tcp->u_arg[1]);
287 else
288 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000289 ALIGN64 (tcp, PREAD_OFFSET_ARG); /* PowerPC alignment restriction */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000290 tprintf(", %lu, %llu", tcp->u_arg[2],
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000291 *(unsigned long long *)&tcp->u_arg[PREAD_OFFSET_ARG]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000292 }
293 return 0;
294}
295
296int
297sys_pwrite(tcp)
298struct tcb *tcp;
299{
300 if (entering(tcp)) {
301 tprintf("%ld, ", tcp->u_arg[0]);
302 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000303 ALIGN64 (tcp, PREAD_OFFSET_ARG); /* PowerPC alignment restriction */
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000304 tprintf(", %lu, %llu", tcp->u_arg[2],
Roland McGrathc0f8bbd2003-08-21 09:58:00 +0000305 *(unsigned long long *)&tcp->u_arg[PREAD_OFFSET_ARG]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000306 }
307 return 0;
308}
309
310int
311sys_sendfile(tcp)
312struct tcb *tcp;
313{
314 if (entering(tcp)) {
315 off_t offset;
316
317 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
318 if (!tcp->u_arg[2])
319 tprintf("NULL");
320 else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
321 tprintf("%#lx", tcp->u_arg[2]);
322 else
323 tprintf("[%lu]", offset);
324 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000325 }
326 return 0;
327}
328
Roland McGrath186c5ac2002-12-15 23:58:23 +0000329int
330sys_sendfile64(tcp)
331struct tcb *tcp;
332{
333 if (entering(tcp)) {
334 loff_t offset;
335
336 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
337 if (!tcp->u_arg[2])
338 tprintf("NULL");
339 else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
340 tprintf("%#lx", tcp->u_arg[2]);
341 else
342 tprintf("[%llu]", (unsigned long long int) offset);
343 tprintf(", %lu", tcp->u_arg[3]);
344 }
345 return 0;
346}
347
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000348#endif /* LINUX */
349
John Hughes70623be2001-03-08 13:59:00 +0000350#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000351int
352sys_pread64(tcp)
353struct tcb *tcp;
354{
355 if (entering(tcp)) {
356 tprintf("%ld, ", tcp->u_arg[0]);
357 } else {
John Hughes5a826b82001-03-07 13:21:24 +0000358 ALIGN64 (tcp, 3);
John Hughesbdf48f52001-03-06 15:08:09 +0000359 if (syserror(tcp))
360 tprintf("%#lx", tcp->u_arg[1]);
361 else
362 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Roland McGrath542c2c62008-05-20 01:11:56 +0000363#ifdef MIPS_LINUXN32
364 tprintf(", %lu, %#llx", tcp->u_arg[2], tcp->ext_arg[3]);
365#else
John Hughes5a826b82001-03-07 13:21:24 +0000366 tprintf(", %lu, %#llx", tcp->u_arg[2],
John Hughes0c79e012001-03-08 14:40:06 +0000367 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrath542c2c62008-05-20 01:11:56 +0000368#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000369 }
370 return 0;
371}
372
373int
374sys_pwrite64(tcp)
375struct tcb *tcp;
376{
377 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000378 ALIGN64 (tcp, 3);
John Hughesbdf48f52001-03-06 15:08:09 +0000379 tprintf("%ld, ", tcp->u_arg[0]);
380 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Roland McGrath542c2c62008-05-20 01:11:56 +0000381#ifdef MIPS_LINUXN32
382 tprintf(", %lu, %#llx", tcp->u_arg[2], tcp->ext_arg[3]);
383#else
John Hughes5a826b82001-03-07 13:21:24 +0000384 tprintf(", %lu, %#llx", tcp->u_arg[2],
John Hughes0c79e012001-03-08 14:40:06 +0000385 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
Roland McGrath542c2c62008-05-20 01:11:56 +0000386#endif
John Hughesbdf48f52001-03-06 15:08:09 +0000387 }
388 return 0;
389}
390#endif
Roland McGrath186c5ac2002-12-15 23:58:23 +0000391
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000392int
393sys_ioctl(tcp)
394struct tcb *tcp;
395{
Roland McGrathee36ce12004-09-04 03:53:10 +0000396 const struct ioctlent *iop;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000397
398 if (entering(tcp)) {
399 tprintf("%ld, ", tcp->u_arg[0]);
Roland McGrath2843a4e2003-11-14 02:54:03 +0000400 iop = ioctl_lookup(tcp->u_arg[1]);
401 if (iop) {
402 tprintf("%s", iop->symbol);
403 while ((iop = ioctl_next_match(iop)))
404 tprintf(" or %s", iop->symbol);
405 } else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000406 tprintf("%#lx", tcp->u_arg[1]);
407 ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
408 }
409 else {
John Hughes38ae88d2002-05-23 11:48:58 +0000410 int ret;
411 if (!(ret = ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2])))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000412 tprintf(", %#lx", tcp->u_arg[2]);
John Hughes38ae88d2002-05-23 11:48:58 +0000413 else
414 return ret - 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000415 }
416 return 0;
417}