blob: 543772ada1642ab02dd0b4582718acdba3ced0c7 [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>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "defs.h"
33
34#include <fcntl.h>
35#include <sys/uio.h>
36
37int
38sys_read(tcp)
39struct tcb *tcp;
40{
41 if (entering(tcp)) {
42 tprintf("%ld, ", tcp->u_arg[0]);
43 } else {
44 if (syserror(tcp))
45 tprintf("%#lx", tcp->u_arg[1]);
46 else
47 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
48 tprintf(", %lu", tcp->u_arg[2]);
49 }
50 return 0;
51}
52
53int
54sys_write(tcp)
55struct tcb *tcp;
56{
57 if (entering(tcp)) {
58 tprintf("%ld, ", tcp->u_arg[0]);
59 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
60 tprintf(", %lu", tcp->u_arg[2]);
61 }
62 return 0;
63}
64
65int
66sys_readv(tcp)
67struct tcb *tcp;
68{
69 struct iovec *iov;
70 int i, len;
71
72 if (entering(tcp)) {
73 tprintf("%ld, ", tcp->u_arg[0]);
74 } else {
75 if (syserror(tcp)) {
76 tprintf("%#lx, %lu",
77 tcp->u_arg[1], tcp->u_arg[2]);
78 return 0;
79 }
80 len = tcp->u_arg[2];
81 if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) {
82 fprintf(stderr, "No memory");
83 return 0;
84 }
85 if (umoven(tcp, tcp->u_arg[1],
86 len * sizeof *iov, (char *) iov) < 0) {
87 tprintf("%#lx", tcp->u_arg[1]);
88 } else {
89 tprintf("[");
90 for (i = 0; i < len; i++) {
91 if (i)
92 tprintf(", ");
93 tprintf("{");
94 printstr(tcp, (long) iov[i].iov_base,
95 iov[i].iov_len);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000096 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000097 }
98 tprintf("]");
99 }
100 free((char *) iov);
101 tprintf(", %lu", tcp->u_arg[2]);
102 }
103 return 0;
104}
105
106int
107sys_writev(tcp)
108struct tcb *tcp;
109{
110 struct iovec *iov;
111 int i, len;
112
113 if (entering(tcp)) {
114 tprintf("%ld, ", tcp->u_arg[0]);
115 len = tcp->u_arg[2];
116 iov = (struct iovec *) malloc(len * sizeof *iov);
117 if (iov == NULL) {
118 fprintf(stderr, "No memory");
119 return 0;
120 }
121 if (umoven(tcp, tcp->u_arg[1],
122 len * sizeof *iov, (char *) iov) < 0) {
123 tprintf("%#lx", tcp->u_arg[1]);
124 } else {
125 tprintf("[");
126 for (i = 0; i < len; i++) {
127 if (i)
128 tprintf(", ");
129 tprintf("{");
130 printstr(tcp, (long) iov[i].iov_base,
131 iov[i].iov_len);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000132 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000133 }
134 tprintf("]");
135 }
136 free((char *) iov);
137 tprintf(", %lu", tcp->u_arg[2]);
138 }
139 return 0;
140}
141
142#ifdef SVR4
143
144int
145sys_pread(tcp)
146struct tcb *tcp;
147{
148 if (entering(tcp)) {
149 tprintf("%ld, ", tcp->u_arg[0]);
150 } else {
151 if (syserror(tcp))
152 tprintf("%#lx", tcp->u_arg[1]);
153 else
154 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
155 tprintf(", %lu, %llu", tcp->u_arg[2],
156 (((unsigned long long) tcp->u_arg[4]) << 32
157 | tcp->u_arg[3]));
158 }
159 return 0;
160}
161
162int
163sys_pwrite(tcp)
164struct tcb *tcp;
165{
166 if (entering(tcp)) {
167 tprintf("%ld, ", tcp->u_arg[0]);
168 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
169 tprintf(", %lu, %llu", tcp->u_arg[2],
170 (((unsigned long long) tcp->u_arg[4]) << 32
171 | tcp->u_arg[3]));
172 }
173 return 0;
174}
175#endif /* SVR4 */
176
177#ifdef LINUX
178int
179sys_pread(tcp)
180struct tcb *tcp;
181{
182 if (entering(tcp)) {
183 tprintf("%ld, ", tcp->u_arg[0]);
184 } else {
185 if (syserror(tcp))
186 tprintf("%#lx", tcp->u_arg[1]);
187 else
188 printstr(tcp, tcp->u_arg[1], tcp->u_rval);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000189 tprintf(", %lu, %llu", tcp->u_arg[2],
190 *(unsigned long long *)&tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 }
192 return 0;
193}
194
195int
196sys_pwrite(tcp)
197struct tcb *tcp;
198{
199 if (entering(tcp)) {
200 tprintf("%ld, ", tcp->u_arg[0]);
201 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +0000202 tprintf(", %lu, %llu", tcp->u_arg[2],
203 *(unsigned long long *)&tcp->u_arg[3]);
204 }
205 return 0;
206}
207
208int
209sys_sendfile(tcp)
210struct tcb *tcp;
211{
212 if (entering(tcp)) {
213 off_t offset;
214
215 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
216 if (!tcp->u_arg[2])
217 tprintf("NULL");
218 else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
219 tprintf("%#lx", tcp->u_arg[2]);
220 else
221 tprintf("[%lu]", offset);
222 tprintf(", %lu", tcp->u_arg[3]);
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000223 }
224 return 0;
225}
226
227#endif /* LINUX */
228
229int
230sys_ioctl(tcp)
231struct tcb *tcp;
232{
233 char *symbol;
234
235 if (entering(tcp)) {
236 tprintf("%ld, ", tcp->u_arg[0]);
237 symbol = ioctl_lookup(tcp->u_arg[1]);
238 if (symbol)
239 tprintf("%s", symbol);
240 else
241 tprintf("%#lx", tcp->u_arg[1]);
242 ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
243 }
244 else {
245 if (ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]) == 0)
246 tprintf(", %#lx", tcp->u_arg[2]);
247 }
248 return 0;
249}