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> |
| 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(", %u}", 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(", %u}", 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 | 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 | |
| 162 | int |
| 163 | sys_pwrite(tcp) |
| 164 | struct 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 |
| 178 | int |
| 179 | sys_pread(tcp) |
| 180 | struct 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); |
| 189 | tprintf(", %lu, %lu", tcp->u_arg[2], tcp->u_arg[3]); |
| 190 | } |
| 191 | return 0; |
| 192 | } |
| 193 | |
| 194 | int |
| 195 | sys_pwrite(tcp) |
| 196 | struct tcb *tcp; |
| 197 | { |
| 198 | if (entering(tcp)) { |
| 199 | tprintf("%ld, ", tcp->u_arg[0]); |
| 200 | printstr(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 201 | tprintf(", %lu, %lu", tcp->u_arg[2], tcp->u_arg[3]); |
| 202 | } |
| 203 | return 0; |
| 204 | } |
| 205 | |
| 206 | #endif /* LINUX */ |
| 207 | |
| 208 | int |
| 209 | sys_ioctl(tcp) |
| 210 | struct tcb *tcp; |
| 211 | { |
| 212 | char *symbol; |
| 213 | |
| 214 | if (entering(tcp)) { |
| 215 | tprintf("%ld, ", tcp->u_arg[0]); |
| 216 | symbol = ioctl_lookup(tcp->u_arg[1]); |
| 217 | if (symbol) |
| 218 | tprintf("%s", symbol); |
| 219 | else |
| 220 | tprintf("%#lx", tcp->u_arg[1]); |
| 221 | ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]); |
| 222 | } |
| 223 | else { |
| 224 | if (ioctl_decode(tcp, tcp->u_arg[1], tcp->u_arg[2]) == 0) |
| 225 | tprintf(", %#lx", tcp->u_arg[2]); |
| 226 | } |
| 227 | return 0; |
| 228 | } |