Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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> |
Wichert Akkerman | 4dc8a2a | 1999-12-23 14:20:14 +0000 | [diff] [blame] | 5 | * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl> |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 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 | int |
| 39 | sys_read(tcp) |
| 40 | struct tcb *tcp; |
| 41 | { |
| 42 | if (entering(tcp)) { |
| 43 | tprintf("%ld, ", tcp->u_arg[0]); |
| 44 | } else { |
| 45 | if (syserror(tcp)) |
| 46 | tprintf("%#lx", tcp->u_arg[1]); |
| 47 | else |
| 48 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
| 49 | tprintf(", %lu", tcp->u_arg[2]); |
| 50 | } |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int |
| 55 | sys_write(tcp) |
| 56 | struct tcb *tcp; |
| 57 | { |
| 58 | if (entering(tcp)) { |
| 59 | tprintf("%ld, ", tcp->u_arg[0]); |
| 60 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 61 | tprintf(", %lu", tcp->u_arg[2]); |
| 62 | } |
| 63 | return 0; |
| 64 | } |
| 65 | |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 66 | void |
| 67 | tprint_iov(tcp, len, addr) |
| 68 | struct tcb * tcp; |
| 69 | int len; |
| 70 | char * addr; |
| 71 | { |
| 72 | struct iovec *iov; |
| 73 | int i; |
| 74 | |
| 75 | |
| 76 | if (!len) { |
| 77 | tprintf("[]"); |
| 78 | return; |
| 79 | } |
| 80 | |
| 81 | if ((iov = (struct iovec *) malloc(len * sizeof *iov)) == NULL) { |
| 82 | fprintf(stderr, "No memory"); |
| 83 | return; |
| 84 | } |
| 85 | if (umoven(tcp, (int) addr, |
| 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 | } |
| 102 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 103 | int |
| 104 | sys_readv(tcp) |
| 105 | struct tcb *tcp; |
| 106 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 107 | if (entering(tcp)) { |
| 108 | tprintf("%ld, ", tcp->u_arg[0]); |
| 109 | } else { |
| 110 | if (syserror(tcp)) { |
| 111 | tprintf("%#lx, %lu", |
| 112 | tcp->u_arg[1], tcp->u_arg[2]); |
| 113 | return 0; |
| 114 | } |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 115 | tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 116 | tprintf(", %lu", tcp->u_arg[2]); |
| 117 | } |
| 118 | return 0; |
| 119 | } |
| 120 | |
| 121 | int |
| 122 | sys_writev(tcp) |
| 123 | struct tcb *tcp; |
| 124 | { |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 125 | if (entering(tcp)) { |
| 126 | tprintf("%ld, ", tcp->u_arg[0]); |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 127 | tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 128 | tprintf(", %lu", tcp->u_arg[2]); |
| 129 | } |
| 130 | return 0; |
| 131 | } |
| 132 | |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame^] | 133 | #if defined(SVR4) |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 134 | |
| 135 | int |
| 136 | sys_pread(tcp) |
| 137 | struct tcb *tcp; |
| 138 | { |
| 139 | if (entering(tcp)) { |
| 140 | tprintf("%ld, ", tcp->u_arg[0]); |
| 141 | } else { |
| 142 | if (syserror(tcp)) |
| 143 | tprintf("%#lx", tcp->u_arg[1]); |
| 144 | else |
| 145 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 146 | #if UNIXWARE |
| 147 | /* off_t is signed int */ |
| 148 | tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]); |
| 149 | #else |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 150 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 151 | (((unsigned long long) tcp->u_arg[4]) << 32 |
| 152 | | tcp->u_arg[3])); |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 153 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 154 | } |
| 155 | return 0; |
| 156 | } |
| 157 | |
| 158 | int |
| 159 | sys_pwrite(tcp) |
| 160 | struct tcb *tcp; |
| 161 | { |
| 162 | if (entering(tcp)) { |
| 163 | tprintf("%ld, ", tcp->u_arg[0]); |
| 164 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 165 | #if UNIXWARE |
| 166 | /* off_t is signed int */ |
| 167 | tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]); |
| 168 | #else |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 169 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 170 | (((unsigned long long) tcp->u_arg[4]) << 32 |
| 171 | | tcp->u_arg[3])); |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 172 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 173 | } |
| 174 | return 0; |
| 175 | } |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame^] | 176 | #endif /* SVR4 */ |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 177 | |
| 178 | #ifdef FREEBSD |
| 179 | #include <sys/types.h> |
| 180 | #include <sys/socket.h> |
| 181 | |
| 182 | int |
| 183 | sys_sendfile(tcp) |
| 184 | struct tcb *tcp; |
| 185 | { |
| 186 | if (entering(tcp)) { |
| 187 | tprintf("%ld, %ld, %llu, %lu", tcp->u_arg[0], tcp->u_arg[1], |
| 188 | (((unsigned long long) tcp->u_arg[3]) << 32 | |
| 189 | tcp->u_arg[2]), tcp->u_arg[4]); |
| 190 | } else { |
| 191 | off_t offset; |
| 192 | |
| 193 | if (!tcp->u_arg[5]) |
| 194 | tprintf(", NULL"); |
| 195 | else { |
| 196 | struct sf_hdtr hdtr; |
| 197 | |
| 198 | if (umove(tcp, tcp->u_arg[5], &hdtr) < 0) |
| 199 | tprintf(", %#lx", tcp->u_arg[5]); |
| 200 | else { |
| 201 | tprintf(", { "); |
| 202 | tprint_iov(tcp, hdtr.hdr_cnt, hdtr.headers); |
| 203 | tprintf(", %u, ", hdtr.hdr_cnt); |
| 204 | tprint_iov(tcp, hdtr.trl_cnt, hdtr.trailers); |
| 205 | tprintf(", %u }", hdtr.hdr_cnt); |
| 206 | } |
| 207 | } |
| 208 | if (!tcp->u_arg[6]) |
| 209 | tprintf(", NULL"); |
| 210 | else if (umove(tcp, tcp->u_arg[6], &offset) < 0) |
| 211 | tprintf(", %#lx", tcp->u_arg[6]); |
| 212 | else |
| 213 | tprintf(", [%llu]", offset); |
| 214 | tprintf(", %lu", tcp->u_arg[7]); |
| 215 | } |
| 216 | return 0; |
| 217 | } |
| 218 | #endif /* FREEBSD */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 219 | |
| 220 | #ifdef LINUX |
| 221 | int |
| 222 | sys_pread(tcp) |
| 223 | struct tcb *tcp; |
| 224 | { |
| 225 | if (entering(tcp)) { |
| 226 | tprintf("%ld, ", tcp->u_arg[0]); |
| 227 | } else { |
| 228 | if (syserror(tcp)) |
| 229 | tprintf("%#lx", tcp->u_arg[1]); |
| 230 | else |
| 231 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 232 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 233 | *(unsigned long long *)&tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 234 | } |
| 235 | return 0; |
| 236 | } |
| 237 | |
| 238 | int |
| 239 | sys_pwrite(tcp) |
| 240 | struct tcb *tcp; |
| 241 | { |
| 242 | if (entering(tcp)) { |
| 243 | tprintf("%ld, ", tcp->u_arg[0]); |
| 244 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 245 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 246 | *(unsigned long long *)&tcp->u_arg[3]); |
| 247 | } |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | int |
| 252 | sys_sendfile(tcp) |
| 253 | struct tcb *tcp; |
| 254 | { |
| 255 | if (entering(tcp)) { |
| 256 | off_t offset; |
| 257 | |
| 258 | tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 259 | if (!tcp->u_arg[2]) |
| 260 | tprintf("NULL"); |
| 261 | else if (umove(tcp, tcp->u_arg[2], &offset) < 0) |
| 262 | tprintf("%#lx", tcp->u_arg[2]); |
| 263 | else |
| 264 | tprintf("[%lu]", offset); |
| 265 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 266 | } |
| 267 | return 0; |
| 268 | } |
| 269 | |
| 270 | #endif /* LINUX */ |
| 271 | |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame^] | 272 | #if _LFS64_LARGEFILE || FREEBSD |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 273 | int |
| 274 | sys_pread64(tcp) |
| 275 | struct tcb *tcp; |
| 276 | { |
| 277 | if (entering(tcp)) { |
| 278 | tprintf("%ld, ", tcp->u_arg[0]); |
| 279 | } else { |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame^] | 280 | ALIGN64 (tcp, 3); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 281 | if (syserror(tcp)) |
| 282 | tprintf("%#lx", tcp->u_arg[1]); |
| 283 | else |
| 284 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame^] | 285 | tprintf(", %lu, %#llx", tcp->u_arg[2], |
| 286 | get64(tcp->u_arg[3], tcp->u_arg[4])); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 287 | } |
| 288 | return 0; |
| 289 | } |
| 290 | |
| 291 | int |
| 292 | sys_pwrite64(tcp) |
| 293 | struct tcb *tcp; |
| 294 | { |
| 295 | if (entering(tcp)) { |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame^] | 296 | ALIGN64 (tcp, 3); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 297 | tprintf("%ld, ", tcp->u_arg[0]); |
| 298 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
John Hughes | 5a826b8 | 2001-03-07 13:21:24 +0000 | [diff] [blame^] | 299 | tprintf(", %lu, %#llx", tcp->u_arg[2], |
| 300 | get64(tcp->u_arg[3], tcp->u_arg[4])); |
John Hughes | bdf48f5 | 2001-03-06 15:08:09 +0000 | [diff] [blame] | 301 | } |
| 302 | return 0; |
| 303 | } |
| 304 | #endif |
| 305 | |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 306 | int |
| 307 | sys_ioctl(tcp) |
| 308 | struct tcb *tcp; |
| 309 | { |
| 310 | char *symbol; |
| 311 | |
| 312 | if (entering(tcp)) { |
| 313 | tprintf("%ld, ", tcp->u_arg[0]); |
| 314 | symbol = ioctl_lookup(tcp->u_arg[1]); |
| 315 | if (symbol) |
| 316 | tprintf("%s", symbol); |
| 317 | else |
| 318 | tprintf("%#lx", tcp->u_arg[1]); |
| 319 | ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 320 | } |
| 321 | else { |
| 322 | if (ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]) == 0) |
| 323 | tprintf(", %#lx", tcp->u_arg[2]); |
| 324 | } |
| 325 | return 0; |
| 326 | } |