]> granicus.if.org Git - strace/blob - io.c
Add pollhack
[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  * 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
37 int
38 sys_read(tcp)
39 struct 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
53 int
54 sys_write(tcp)
55 struct 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
65 int
66 sys_readv(tcp)
67 struct 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);
96                                 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
97                         }
98                         tprintf("]");
99                 }
100                 free((char *) iov);
101                 tprintf(", %lu", tcp->u_arg[2]);
102         }
103         return 0;
104 }
105
106 int
107 sys_writev(tcp)
108 struct 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);
132                                 tprintf(", %lu}", (unsigned long)iov[i].iov_len);
133                         }
134                         tprintf("]");
135                 }
136                 free((char *) iov);
137                 tprintf(", %lu", tcp->u_arg[2]);
138         }
139         return 0;
140 }
141
142 #ifdef 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 LINUX
188 int
189 sys_pread(tcp)
190 struct tcb *tcp;
191 {
192         if (entering(tcp)) {
193                 tprintf("%ld, ", tcp->u_arg[0]);
194         } else {
195                 if (syserror(tcp))
196                         tprintf("%#lx", tcp->u_arg[1]);
197                 else
198                         printstr(tcp, tcp->u_arg[1], tcp->u_rval);
199                 tprintf(", %lu, %llu", tcp->u_arg[2],
200                         *(unsigned long long *)&tcp->u_arg[3]);
201         }
202         return 0;
203 }
204
205 int
206 sys_pwrite(tcp)
207 struct tcb *tcp;
208 {
209         if (entering(tcp)) {
210                 tprintf("%ld, ", tcp->u_arg[0]);
211                 printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]);
212                 tprintf(", %lu, %llu", tcp->u_arg[2],
213                         *(unsigned long long *)&tcp->u_arg[3]);
214         }
215         return 0;
216 }
217
218 int
219 sys_sendfile(tcp)
220 struct tcb *tcp;
221 {
222         if (entering(tcp)) {
223                 off_t offset;
224
225                 tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]);
226                 if (!tcp->u_arg[2])
227                         tprintf("NULL");
228                 else if (umove(tcp, tcp->u_arg[2], &offset) < 0)
229                         tprintf("%#lx", tcp->u_arg[2]);
230                 else
231                         tprintf("[%lu]", offset);
232                 tprintf(", %lu", tcp->u_arg[3]);
233         }
234         return 0;
235 }
236
237 #endif /* LINUX */
238
239 int
240 sys_ioctl(tcp)
241 struct tcb *tcp;
242 {
243         char *symbol;
244
245         if (entering(tcp)) {
246                 tprintf("%ld, ", tcp->u_arg[0]);
247                 symbol = ioctl_lookup(tcp->u_arg[1]);
248                 if (symbol)
249                         tprintf("%s", symbol);
250                 else
251                         tprintf("%#lx", tcp->u_arg[1]);
252                 ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]);
253         }
254         else {
255                 if (ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]) == 0)
256                         tprintf(", %#lx", tcp->u_arg[2]);
257         }
258         return 0;
259 }