]> granicus.if.org Git - strace/blob - io.c
Use configure to detect 64bit off_t and rlim_t
[strace] / io.c
1 /*
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  * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
6  * 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>
36 #include <sys/uio.h>
37
38 #ifdef HAVE_LONG_LONG_OFF_T
39 /*
40  * Hacks for systems that have a long long off_t
41  */
42
43 #define sys_pread64     sys_pread
44 #define sys_pwrite64    sys_pwrite
45 #endif
46
47 int
48 sys_read(tcp)
49 struct tcb *tcp;
50 {
51         if (entering(tcp)) {
52                 tprintf("%ld, ", tcp->u_arg[0]);
53         } else {
54                 if (syserror(tcp))
55                         tprintf("%#lx", tcp->u_arg[1]);
56                 else
57                         printstr(tcp, tcp->u_arg[1], tcp->u_rval);
58                 tprintf(", %lu", tcp->u_arg[2]);
59         }
60         return 0;
61 }
62
63 int
64 sys_write(tcp)
65 struct tcb *tcp;
66 {
67         if (entering(tcp)) {
68                 tprintf("%ld, ", tcp->u_arg[0]);
69                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
70                 tprintf(", %lu", tcp->u_arg[2]);
71         }
72         return 0;
73 }
74
75 void
76 tprint_iov(tcp, len, addr)
77 struct tcb * tcp;
78 int len;
79 char * addr;
80 {
81         struct iovec *iov;
82         int i;
83
84
85         if (!len) {
86                 tprintf("[]");
87                 return;
88         }
89           
90         if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) {
91                 fprintf(stderr, "No memory");
92                 return;
93         }
94         if (umoven(tcp, (int) addr,
95                    len * sizeof *iov, (char *) iov) < 0) {
96                 tprintf("%#lx", tcp->u_arg[1]);
97         } else {
98                 tprintf("[");
99                 for (i = 0; i < len; i++) {
100                         if (i)
101                                 tprintf(", ");
102                         tprintf("{");
103                         printstr(tcp, (long) iov[i].iov_base,
104                                 iov[i].iov_len);
105                         tprintf(", %lu}", (unsigned long)iov[i].iov_len);
106                 }
107                 tprintf("]");
108         }
109         free((char *) iov);
110 }
111
112 int
113 sys_readv(tcp)
114 struct tcb *tcp;
115 {
116         if (entering(tcp)) {
117                 tprintf("%ld, ", tcp->u_arg[0]);
118         } else {
119                 if (syserror(tcp)) {
120                         tprintf("%#lx, %lu",
121                                         tcp->u_arg[1], tcp->u_arg[2]);
122                         return 0;
123                 }
124                 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
125                 tprintf(", %lu", tcp->u_arg[2]);
126         }
127         return 0;
128 }
129
130 int
131 sys_writev(tcp)
132 struct tcb *tcp;
133 {
134         if (entering(tcp)) {
135                 tprintf("%ld, ", tcp->u_arg[0]);
136                 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]);
137                 tprintf(", %lu", tcp->u_arg[2]);
138         }
139         return 0;
140 }
141
142 #if defined(SVR4)
143
144 int
145 sys_pread(tcp)
146 struct 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 #if UNIXWARE
156                 /* off_t is signed int */
157                 tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
158 #else
159                 tprintf(", %lu, %llu", tcp->u_arg[2],
160                                 (((unsigned long long) tcp->u_arg[4]) << 32
161                                  | tcp->u_arg[3]));
162 #endif
163         }
164         return 0;
165 }
166
167 int
168 sys_pwrite(tcp)
169 struct tcb *tcp;
170 {
171         if (entering(tcp)) {
172                 tprintf("%ld, ", tcp->u_arg[0]);
173                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
174 #if UNIXWARE
175                 /* off_t is signed int */
176                 tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]);
177 #else
178                 tprintf(", %lu, %llu", tcp->u_arg[2],
179                                 (((unsigned long long) tcp->u_arg[4]) << 32
180                                  | tcp->u_arg[3]));
181 #endif
182         }
183         return 0;
184 }
185 #endif /* SVR4 */
186
187 #ifdef FREEBSD
188 #include <sys/types.h>
189 #include <sys/socket.h>
190
191 int
192 sys_sendfile(tcp)
193 struct tcb *tcp;
194 {
195         if (entering(tcp)) {
196                 tprintf("%ld, %ld, %llu, %lu", tcp->u_arg[0], tcp->u_arg[1],
197                         (((unsigned long long) tcp->u_arg[3]) << 32 |
198                          tcp->u_arg[2]), tcp->u_arg[4]);
199         } else {
200                 off_t offset;
201
202                 if (!tcp->u_arg[5])
203                         tprintf(", NULL");
204                 else {
205                         struct sf_hdtr hdtr;
206
207                         if (umove(tcp, tcp->u_arg[5], &hdtr) < 0)
208                                 tprintf(", %#lx", tcp->u_arg[5]);
209                         else {
210                                 tprintf(", { ");
211                                 tprint_iov(tcp, hdtr.hdr_cnt, hdtr.headers);
212                                 tprintf(", %u, ", hdtr.hdr_cnt);
213                                 tprint_iov(tcp, hdtr.trl_cnt, hdtr.trailers);
214                                 tprintf(", %u }", hdtr.hdr_cnt);
215                         }
216                 }
217                 if (!tcp->u_arg[6])
218                         tprintf(", NULL");
219                 else if (umove(tcp, tcp->u_arg[6], &offset) < 0)
220                         tprintf(", %#lx", tcp->u_arg[6]);
221                 else
222                         tprintf(", [%llu]", offset);
223                 tprintf(", %lu", tcp->u_arg[7]);
224         }
225         return 0;
226 }
227 #endif /* FREEBSD */
228
229 #ifdef LINUX
230 int
231 sys_pread(tcp)
232 struct tcb *tcp;
233 {
234         if (entering(tcp)) {
235                 tprintf("%ld, ", tcp->u_arg[0]);
236         } else {
237                 if (syserror(tcp))
238                         tprintf("%#lx", tcp->u_arg[1]);
239                 else
240                         printstr(tcp, tcp->u_arg[1], tcp->u_rval);
241                 tprintf(", %lu, %llu", tcp->u_arg[2],
242                         *(unsigned long long *)&tcp->u_arg[3]);
243         }
244         return 0;
245 }
246
247 int
248 sys_pwrite(tcp)
249 struct tcb *tcp;
250 {
251         if (entering(tcp)) {
252                 tprintf("%ld, ", tcp->u_arg[0]);
253                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
254                 tprintf(", %lu, %llu", tcp->u_arg[2],
255                         *(unsigned long long *)&tcp->u_arg[3]);
256         }
257         return 0;
258 }
259
260 int
261 sys_sendfile(tcp)
262 struct tcb *tcp;
263 {
264         if (entering(tcp)) {
265                 off_t offset;
266
267                 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
268                 if (!tcp->u_arg[2])
269                         tprintf("NULL");
270                 else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
271                         tprintf("%#lx", tcp->u_arg[2]);
272                 else
273                         tprintf("[%lu]", offset);
274                 tprintf(", %lu", tcp->u_arg[3]);
275         }
276         return 0;
277 }
278
279 #endif /* LINUX */
280
281 #if _LFS64_LARGEFILE || HAVE_LONG_LONG_OFF_T
282 int
283 sys_pread64(tcp)
284 struct tcb *tcp;
285 {
286         if (entering(tcp)) {
287                 tprintf("%ld, ", tcp->u_arg[0]);
288         } else {
289                 ALIGN64 (tcp, 3);
290                 if (syserror(tcp))
291                         tprintf("%#lx", tcp->u_arg[1]);
292                 else
293                         printstr(tcp, tcp->u_arg[1], tcp->u_rval);
294                 tprintf(", %lu, %#llx", tcp->u_arg[2],
295                         get64(tcp->u_arg[3], tcp->u_arg[4]));
296         }
297         return 0;
298 }
299
300 int
301 sys_pwrite64(tcp)
302 struct tcb *tcp;
303 {
304         if (entering(tcp)) {
305                 ALIGN64 (tcp, 3);
306                 tprintf("%ld, ", tcp->u_arg[0]);
307                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
308                 tprintf(", %lu, %#llx", tcp->u_arg[2],
309                         get64(tcp->u_arg[3], tcp->u_arg[4]));
310         }
311         return 0;
312 }
313 #endif
314  
315 int
316 sys_ioctl(tcp)
317 struct tcb *tcp;
318 {
319         char *symbol;
320
321         if (entering(tcp)) {
322                 tprintf("%ld, ", tcp->u_arg[0]);
323                 symbol = ioctl_lookup(tcp->u_arg[1]);
324                 if (symbol)
325                         tprintf("%s", symbol);
326                 else
327                         tprintf("%#lx", tcp->u_arg[1]);
328                 ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
329         }
330         else {
331                 if (ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]) == 0)
332                         tprintf(", %#lx", tcp->u_arg[2]);
333         }
334         return 0;
335 }