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 | |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 133 | #if defined(SVR4) || defined(FREEBSD) |
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 | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 150 | #ifndef FREEBSD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 151 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 152 | (((unsigned long long) tcp->u_arg[4]) << 32 |
| 153 | | tcp->u_arg[3])); |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 154 | #else |
| 155 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 156 | (((off_t) tcp->u_arg[3]) << 32) + tcp->u_arg[4]); |
| 157 | #endif |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 158 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 159 | } |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | int |
| 164 | sys_pwrite(tcp) |
| 165 | struct tcb *tcp; |
| 166 | { |
| 167 | if (entering(tcp)) { |
| 168 | tprintf("%ld, ", tcp->u_arg[0]); |
| 169 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 170 | #if UNIXWARE |
| 171 | /* off_t is signed int */ |
| 172 | tprintf(", %lu, %ld", tcp->u_arg[2], tcp->u_arg[3]); |
| 173 | #else |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 174 | #ifndef FREEBSD |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 175 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 176 | (((unsigned long long) tcp->u_arg[4]) << 32 |
| 177 | | tcp->u_arg[3])); |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 178 | #else |
| 179 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 180 | (((off_t) tcp->u_arg[3]) << 32) + tcp->u_arg[4]); |
| 181 | #endif |
Wichert Akkerman | 9ce1a63 | 1999-08-29 23:15:07 +0000 | [diff] [blame] | 182 | #endif |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 183 | } |
| 184 | return 0; |
| 185 | } |
Wichert Akkerman | bf79f2e | 2000-09-01 21:03:06 +0000 | [diff] [blame] | 186 | #endif /* SVR4 || FREEBSD */ |
| 187 | |
| 188 | #ifdef FREEBSD |
| 189 | #include <sys/types.h> |
| 190 | #include <sys/socket.h> |
| 191 | |
| 192 | int |
| 193 | sys_sendfile(tcp) |
| 194 | struct tcb *tcp; |
| 195 | { |
| 196 | if (entering(tcp)) { |
| 197 | tprintf("%ld, %ld, %llu, %lu", tcp->u_arg[0], tcp->u_arg[1], |
| 198 | (((unsigned long long) tcp->u_arg[3]) << 32 | |
| 199 | tcp->u_arg[2]), tcp->u_arg[4]); |
| 200 | } else { |
| 201 | off_t offset; |
| 202 | |
| 203 | if (!tcp->u_arg[5]) |
| 204 | tprintf(", NULL"); |
| 205 | else { |
| 206 | struct sf_hdtr hdtr; |
| 207 | |
| 208 | if (umove(tcp, tcp->u_arg[5], &hdtr) < 0) |
| 209 | tprintf(", %#lx", tcp->u_arg[5]); |
| 210 | else { |
| 211 | tprintf(", { "); |
| 212 | tprint_iov(tcp, hdtr.hdr_cnt, hdtr.headers); |
| 213 | tprintf(", %u, ", hdtr.hdr_cnt); |
| 214 | tprint_iov(tcp, hdtr.trl_cnt, hdtr.trailers); |
| 215 | tprintf(", %u }", hdtr.hdr_cnt); |
| 216 | } |
| 217 | } |
| 218 | if (!tcp->u_arg[6]) |
| 219 | tprintf(", NULL"); |
| 220 | else if (umove(tcp, tcp->u_arg[6], &offset) < 0) |
| 221 | tprintf(", %#lx", tcp->u_arg[6]); |
| 222 | else |
| 223 | tprintf(", [%llu]", offset); |
| 224 | tprintf(", %lu", tcp->u_arg[7]); |
| 225 | } |
| 226 | return 0; |
| 227 | } |
| 228 | #endif /* FREEBSD */ |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 229 | |
| 230 | #ifdef LINUX |
| 231 | int |
| 232 | sys_pread(tcp) |
| 233 | struct tcb *tcp; |
| 234 | { |
| 235 | if (entering(tcp)) { |
| 236 | tprintf("%ld, ", tcp->u_arg[0]); |
| 237 | } else { |
| 238 | if (syserror(tcp)) |
| 239 | tprintf("%#lx", tcp->u_arg[1]); |
| 240 | else |
| 241 | printstr(tcp, tcp->u_arg[1], tcp->u_rval); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 242 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 243 | *(unsigned long long *)&tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 244 | } |
| 245 | return 0; |
| 246 | } |
| 247 | |
| 248 | int |
| 249 | sys_pwrite(tcp) |
| 250 | struct tcb *tcp; |
| 251 | { |
| 252 | if (entering(tcp)) { |
| 253 | tprintf("%ld, ", tcp->u_arg[0]); |
| 254 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
Wichert Akkerman | 2e2553a | 1999-05-09 00:29:58 +0000 | [diff] [blame] | 255 | tprintf(", %lu, %llu", tcp->u_arg[2], |
| 256 | *(unsigned long long *)&tcp->u_arg[3]); |
| 257 | } |
| 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | int |
| 262 | sys_sendfile(tcp) |
| 263 | struct tcb *tcp; |
| 264 | { |
| 265 | if (entering(tcp)) { |
| 266 | off_t offset; |
| 267 | |
| 268 | tprintf("%ld, %ld, ", tcp->u_arg[0], tcp->u_arg[1]); |
| 269 | if (!tcp->u_arg[2]) |
| 270 | tprintf("NULL"); |
| 271 | else if (umove(tcp, tcp->u_arg[2], &offset) < 0) |
| 272 | tprintf("%#lx", tcp->u_arg[2]); |
| 273 | else |
| 274 | tprintf("[%lu]", offset); |
| 275 | tprintf(", %lu", tcp->u_arg[3]); |
Wichert Akkerman | 76baf7c | 1999-02-19 00:21:36 +0000 | [diff] [blame] | 276 | } |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | #endif /* LINUX */ |
| 281 | |
| 282 | int |
| 283 | sys_ioctl(tcp) |
| 284 | struct tcb *tcp; |
| 285 | { |
| 286 | char *symbol; |
| 287 | |
| 288 | if (entering(tcp)) { |
| 289 | tprintf("%ld, ", tcp->u_arg[0]); |
| 290 | symbol = ioctl_lookup(tcp->u_arg[1]); |
| 291 | if (symbol) |
| 292 | tprintf("%s", symbol); |
| 293 | else |
| 294 | tprintf("%#lx", tcp->u_arg[1]); |
| 295 | ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 296 | } |
| 297 | else { |
| 298 | if (ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]) == 0) |
| 299 | tprintf(", %#lx", tcp->u_arg[2]); |
| 300 | } |
| 301 | return 0; |
| 302 | } |