blob: 3bb779885a867919e2ce417c137ca6fc98ced446 [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;
81int len;
John Hughes1d08dcf2001-07-10 13:48:44 +000082long addr;
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000083{
84 struct iovec *iov;
85 int i;
86
87
88 if (!len) {
89 tprintf("[]");
90 return;
91 }
92
93 if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) {
94 fprintf(stderr, "No memory");
95 return;
96 }
John Hughes1d08dcf2001-07-10 13:48:44 +000097 if (umoven(tcp, addr,
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +000098 len * sizeof *iov, (char *) iov) < 0) {
99 tprintf("%#lx", tcp->u_arg[1]);
100 } else {
101 tprintf("[");
102 for (i = 0; i < len; i++) {
103 if (i)
104 tprintf(", ");
105 tprintf("{");
106 printstr(tcp, (long) iov[i].iov_base,
107 iov[i].iov_len);
108 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
109 }
110 tprintf("]");
111 }
112 free((char *) iov);
113}
114
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000115int
116sys_readv(tcp)
117struct tcb *tcp;
118{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000119 if (entering(tcp)) {
120 tprintf("%ld, ", tcp->u_arg[0]);
121 } else {
122 if (syserror(tcp)) {
123 tprintf("%#lx, %lu",
124 tcp->u_arg[1], tcp->u_arg[2]);
125 return 0;
126 }
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000127 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000128 tprintf(", %lu", tcp->u_arg[2]);
129 }
130 return 0;
131}
132
133int
134sys_writev(tcp)
135struct tcb *tcp;
136{
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000137 if (entering(tcp)) {
138 tprintf("%ld, ", tcp->u_arg[0]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000139 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000140 tprintf(", %lu", tcp->u_arg[2]);
141 }
142 return 0;
143}
John Hughes1d08dcf2001-07-10 13:48:44 +0000144#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000145
John Hughes5a826b82001-03-07 13:21:24 +0000146#if defined(SVR4)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000147
148int
149sys_pread(tcp)
150struct tcb *tcp;
151{
152 if (entering(tcp)) {
153 tprintf("%ld, ", tcp->u_arg[0]);
154 } else {
155 if (syserror(tcp))
156 tprintf("%#lx", tcp->u_arg[1]);
157 else
158 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000159#if UNIXWARE
160 /* off_t is signed int */
161 tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
162#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000163 tprintf(", %lu, %llu", tcp->u_arg[2],
164 (((unsigned long long) tcp->u_arg[4]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000165 | (unsigned) tcp->u_arg[3]));
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000166#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167 }
168 return 0;
169}
170
171int
172sys_pwrite(tcp)
173struct tcb *tcp;
174{
175 if (entering(tcp)) {
176 tprintf("%ld, ", tcp->u_arg[0]);
177 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000178#if UNIXWARE
179 /* off_t is signed int */
180 tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
181#else
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000182 tprintf(", %lu, %llu", tcp->u_arg[2],
183 (((unsigned long long) tcp->u_arg[4]) << 32
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000184 | (unsigned) tcp->u_arg[3]));
Wichert Akkerman9ce1a631999-08-29 23:15:07 +0000185#endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000186 }
187 return 0;
188}
John Hughes5a826b82001-03-07 13:21:24 +0000189#endif /* SVR4 */
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000190
191#ifdef FREEBSD
192#include <sys/types.h>
193#include <sys/socket.h>
194
195int
196sys_sendfile(tcp)
197struct tcb *tcp;
198{
199 if (entering(tcp)) {
200 tprintf("%ld, %ld, %llu, %lu", tcp->u_arg[0], tcp->u_arg[1],
201 (((unsigned long long) tcp->u_arg[3]) << 32 |
Wichert Akkerman7ab47b62002-03-31 19:00:02 +0000202 (unsigned) tcp->u_arg[2]), tcp->u_arg[4]);
Wichert Akkermanbf79f2e2000-09-01 21:03:06 +0000203 } else {
204 off_t offset;
205
206 if (!tcp->u_arg[5])
207 tprintf(", NULL");
208 else {
209 struct sf_hdtr hdtr;
210
211 if (umove(tcp, tcp->u_arg[5], &hdtr) < 0)
212 tprintf(", %#lx", tcp->u_arg[5]);
213 else {
214 tprintf(", { ");
215 tprint_iov(tcp, hdtr.hdr_cnt, hdtr.headers);
216 tprintf(", %u, ", hdtr.hdr_cnt);
217 tprint_iov(tcp, hdtr.trl_cnt, hdtr.trailers);
218 tprintf(", %u }", hdtr.hdr_cnt);
219 }
220 }
221 if (!tcp->u_arg[6])
222 tprintf(", NULL");
223 else if (umove(tcp, tcp->u_arg[6], &offset) < 0)
224 tprintf(", %#lx", tcp->u_arg[6]);
225 else
226 tprintf(", [%llu]", offset);
227 tprintf(", %lu", tcp->u_arg[7]);
228 }
229 return 0;
230}
231#endif /* FREEBSD */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000232
233#ifdef LINUX
234int
235sys_pread(tcp)
236struct tcb *tcp;
237{
238 if (entering(tcp)) {
239 tprintf("%ld, ", tcp->u_arg[0]);
240 } else {
241 if (syserror(tcp))
242 tprintf("%#lx", tcp->u_arg[1]);
243 else
244 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000245 tprintf(", %lu, %llu", tcp->u_arg[2],
246 *(unsigned long long *)&tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000247 }
248 return 0;
249}
250
251int
252sys_pwrite(tcp)
253struct tcb *tcp;
254{
255 if (entering(tcp)) {
256 tprintf("%ld, ", tcp->u_arg[0]);
257 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000258 tprintf(", %lu, %llu", tcp->u_arg[2],
259 *(unsigned long long *)&tcp->u_arg[3]);
260 }
261 return 0;
262}
263
264int
265sys_sendfile(tcp)
266struct tcb *tcp;
267{
268 if (entering(tcp)) {
269 off_t offset;
270
271 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
272 if (!tcp->u_arg[2])
273 tprintf("NULL");
274 else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
275 tprintf("%#lx", tcp->u_arg[2]);
276 else
277 tprintf("[%lu]", offset);
278 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000279 }
280 return 0;
281}
282
283#endif /* LINUX */
284
John Hughes70623be2001-03-08 13:59:00 +0000285#if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
John Hughesbdf48f52001-03-06 15:08:09 +0000286int
287sys_pread64(tcp)
288struct tcb *tcp;
289{
290 if (entering(tcp)) {
291 tprintf("%ld, ", tcp->u_arg[0]);
292 } else {
John Hughes5a826b82001-03-07 13:21:24 +0000293 ALIGN64 (tcp, 3);
John Hughesbdf48f52001-03-06 15:08:09 +0000294 if (syserror(tcp))
295 tprintf("%#lx", tcp->u_arg[1]);
296 else
297 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
John Hughes5a826b82001-03-07 13:21:24 +0000298 tprintf(", %lu, %#llx", tcp->u_arg[2],
John Hughes0c79e012001-03-08 14:40:06 +0000299 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
John Hughesbdf48f52001-03-06 15:08:09 +0000300 }
301 return 0;
302}
303
304int
305sys_pwrite64(tcp)
306struct tcb *tcp;
307{
308 if (entering(tcp)) {
John Hughes5a826b82001-03-07 13:21:24 +0000309 ALIGN64 (tcp, 3);
John Hughesbdf48f52001-03-06 15:08:09 +0000310 tprintf("%ld, ", tcp->u_arg[0]);
311 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
John Hughes5a826b82001-03-07 13:21:24 +0000312 tprintf(", %lu, %#llx", tcp->u_arg[2],
John Hughes0c79e012001-03-08 14:40:06 +0000313 LONG_LONG(tcp->u_arg[3], tcp->u_arg[4]));
John Hughesbdf48f52001-03-06 15:08:09 +0000314 }
315 return 0;
316}
317#endif
318
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000319int
320sys_ioctl(tcp)
321struct tcb *tcp;
322{
323 char *symbol;
324
325 if (entering(tcp)) {
326 tprintf("%ld, ", tcp->u_arg[0]);
327 symbol = ioctl_lookup(tcp->u_arg[1]);
328 if (symbol)
329 tprintf("%s", symbol);
330 else
331 tprintf("%#lx", tcp->u_arg[1]);
332 ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
333 }
334 else {
John Hughes38ae88d2002-05-23 11:48:58 +0000335 int ret;
336 if (!(ret = ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2])))
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000337 tprintf(", %#lx", tcp->u_arg[2]);
John Hughes38ae88d2002-05-23 11:48:58 +0000338 else
339 return ret - 1;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000340 }
341 return 0;
342}