Branch data Line data Source code
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 : : * Copyright (c) 1999-2017 The strace developers.
7 : : * All rights reserved.
8 : : *
9 : : * Redistribution and use in source and binary forms, with or without
10 : : * modification, are permitted provided that the following conditions
11 : : * are met:
12 : : * 1. Redistributions of source code must retain the above copyright
13 : : * notice, this list of conditions and the following disclaimer.
14 : : * 2. Redistributions in binary form must reproduce the above copyright
15 : : * notice, this list of conditions and the following disclaimer in the
16 : : * documentation and/or other materials provided with the distribution.
17 : : * 3. The name of the author may not be used to endorse or promote products
18 : : * derived from this software without specific prior written permission.
19 : : *
20 : : * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 : : * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 : : * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 : : * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 : : * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 : : * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 : : * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 : : * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 : : * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 : : * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 : : */
31 : :
32 : : #include "defs.h"
33 : : #include <fcntl.h>
34 : : #include <sys/uio.h>
35 : :
36 : 176 : SYS_FUNC(read)
37 : : {
38 [ + + ]: 176 : if (entering(tcp)) {
39 : 88 : printfd(tcp, tcp->u_arg[0]);
40 : 88 : tprints(", ");
41 : : } else {
42 [ + + ]: 88 : if (syserror(tcp))
43 : 2 : printaddr(tcp->u_arg[1]);
44 : : else
45 : 86 : printstrn(tcp, tcp->u_arg[1], tcp->u_rval);
46 : 88 : tprintf(", %" PRI_klu, tcp->u_arg[2]);
47 : : }
48 : 176 : return 0;
49 : : }
50 : :
51 : 74 : SYS_FUNC(write)
52 : : {
53 : 74 : printfd(tcp, tcp->u_arg[0]);
54 : 74 : tprints(", ");
55 : 74 : printstrn(tcp, tcp->u_arg[1], tcp->u_arg[2]);
56 : 74 : tprintf(", %" PRI_klu, tcp->u_arg[2]);
57 : :
58 : 74 : return RVAL_DECODED;
59 : : }
60 : :
61 : : struct print_iovec_config {
62 : : enum iov_decode decode_iov;
63 : : kernel_ulong_t data_size;
64 : : };
65 : :
66 : : static bool
67 : 238230 : print_iovec(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
68 : : {
69 : : const kernel_ulong_t *iov;
70 : : kernel_ulong_t iov_buf[2], len;
71 : 238230 : struct print_iovec_config *c = data;
72 : :
73 [ + + ]: 238230 : if (elem_size < sizeof(iov_buf)) {
74 : 119088 : iov_buf[0] = ((unsigned int *) elem_buf)[0];
75 : 119088 : iov_buf[1] = ((unsigned int *) elem_buf)[1];
76 : 119088 : iov = iov_buf;
77 : : } else {
78 : : iov = elem_buf;
79 : : }
80 : :
81 : 238230 : tprints("{iov_base=");
82 : :
83 : 238230 : len = iov[1];
84 : :
85 [ + - + ]: 238230 : switch (c->decode_iov) {
86 : : case IOV_DECODE_STR:
87 [ + + ]: 238132 : if (len > c->data_size)
88 : 85 : len = c->data_size;
89 [ + + ]: 238132 : if (c->data_size != (kernel_ulong_t) -1)
90 : 765 : c->data_size -= len;
91 : 238132 : printstrn(tcp, iov[0], len);
92 : : break;
93 : : case IOV_DECODE_NETLINK:
94 [ # # ]: 0 : if (len > c->data_size)
95 : 0 : len = c->data_size;
96 [ # # ]: 0 : if (c->data_size != (kernel_ulong_t) -1)
97 : 0 : c->data_size -= len;
98 : : /* assume that the descriptor is 1st syscall argument */
99 : 0 : decode_netlink(tcp, tcp->u_arg[0], iov[0], len);
100 : 0 : break;
101 : : default:
102 : 98 : printaddr(iov[0]);
103 : 98 : break;
104 : : }
105 : :
106 : 238230 : tprintf(", iov_len=%" PRI_klu "}", iov[1]);
107 : :
108 : 238230 : return true;
109 : : }
110 : :
111 : : /*
112 : : * data_size limits the cumulative size of printed data.
113 : : * Example: recvmsg returing a short read.
114 : : */
115 : : void
116 : 303090 : tprint_iov_upto(struct tcb *const tcp, const kernel_ulong_t len,
117 : : const kernel_ulong_t addr, const enum iov_decode decode_iov,
118 : : const kernel_ulong_t data_size)
119 : : {
120 : : kernel_ulong_t iov[2];
121 : 303090 : struct print_iovec_config config = {
122 : : .decode_iov = decode_iov, .data_size = data_size
123 : : };
124 : :
125 : 303090 : print_array(tcp, addr, len, iov, current_wordsize * 2,
126 : : umoven_or_printaddr_ignore_syserror, print_iovec, &config);
127 : 303090 : }
128 : :
129 : 146 : SYS_FUNC(readv)
130 : : {
131 [ + + ]: 146 : if (entering(tcp)) {
132 : 73 : printfd(tcp, tcp->u_arg[0]);
133 : 73 : tprints(", ");
134 : : } else {
135 : 73 : tprint_iov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1],
136 : 73 : syserror(tcp) ? IOV_DECODE_ADDR :
137 : 73 : IOV_DECODE_STR, tcp->u_rval);
138 : 73 : tprintf(", %" PRI_klu, tcp->u_arg[2]);
139 : : }
140 : 146 : return 0;
141 : : }
142 : :
143 : 232897 : SYS_FUNC(writev)
144 : : {
145 : 232897 : printfd(tcp, tcp->u_arg[0]);
146 : 232897 : tprints(", ");
147 : 232897 : tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
148 : 232897 : tprintf(", %" PRI_klu, tcp->u_arg[2]);
149 : :
150 : 232897 : return RVAL_DECODED;
151 : : }
152 : :
153 : 156 : SYS_FUNC(pread)
154 : : {
155 [ + + ]: 156 : if (entering(tcp)) {
156 : 78 : printfd(tcp, tcp->u_arg[0]);
157 : 78 : tprints(", ");
158 : : } else {
159 [ + + ]: 78 : if (syserror(tcp))
160 : 4 : printaddr(tcp->u_arg[1]);
161 : : else
162 : 74 : printstrn(tcp, tcp->u_arg[1], tcp->u_rval);
163 : 78 : tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
164 : 78 : printllval(tcp, "%lld", 3);
165 : : }
166 : 156 : return 0;
167 : : }
168 : :
169 : 76 : SYS_FUNC(pwrite)
170 : : {
171 : 76 : printfd(tcp, tcp->u_arg[0]);
172 : 76 : tprints(", ");
173 : 76 : printstrn(tcp, tcp->u_arg[1], tcp->u_arg[2]);
174 : 76 : tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
175 : 76 : printllval(tcp, "%lld", 3);
176 : :
177 : 76 : return RVAL_DECODED;
178 : : }
179 : :
180 : : static void
181 : 86 : print_lld_from_low_high_val(struct tcb *tcp, int arg)
182 : : {
183 : : #if SIZEOF_KERNEL_LONG_T > 4
184 : : # ifndef current_klongsize
185 [ + + ]: 86 : if (current_klongsize < SIZEOF_KERNEL_LONG_T) {
186 : 43 : tprintf("%" PRI_kld, (tcp->u_arg[arg + 1] << 32)
187 : 43 : | tcp->u_arg[arg]);
188 : : } else
189 : : # endif /* !current_klongsize */
190 : : {
191 : 43 : tprintf("%" PRI_kld, tcp->u_arg[arg]);
192 : : }
193 : : #else /* SIZEOF_KERNEL_LONG_T == 4 */
194 : : tprintf("%lld",
195 : : ((long long) tcp->u_arg[arg + 1] << 32)
196 : : | ((long long) tcp->u_arg[arg]));
197 : : #endif
198 : 86 : }
199 : :
200 : : #include "xlat/rwf_flags.h"
201 : :
202 : : static int
203 : 52 : do_preadv(struct tcb *tcp, const int flags_arg)
204 : : {
205 [ + + ]: 52 : if (entering(tcp)) {
206 : 26 : printfd(tcp, tcp->u_arg[0]);
207 : 26 : tprints(", ");
208 : : } else {
209 : 26 : kernel_ulong_t len =
210 : 26 : truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
211 : :
212 : 26 : tprint_iov_upto(tcp, len, tcp->u_arg[1],
213 : 26 : syserror(tcp) ? IOV_DECODE_ADDR :
214 : 26 : IOV_DECODE_STR, tcp->u_rval);
215 : 26 : tprintf(", %" PRI_klu ", ", len);
216 : 26 : print_lld_from_low_high_val(tcp, 3);
217 [ + + ]: 26 : if (flags_arg >= 0) {
218 : 6 : tprints(", ");
219 : 6 : printflags(rwf_flags, tcp->u_arg[flags_arg], "RWF_???");
220 : : }
221 : : }
222 : 52 : return 0;
223 : : }
224 : :
225 : 40 : SYS_FUNC(preadv)
226 : : {
227 : 40 : return do_preadv(tcp, -1);
228 : : }
229 : :
230 : : static int
231 : 60 : do_pwritev(struct tcb *tcp, const int flags_arg)
232 : : {
233 : 60 : kernel_ulong_t len =
234 : 60 : truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
235 : :
236 : 60 : printfd(tcp, tcp->u_arg[0]);
237 : 60 : tprints(", ");
238 : 60 : tprint_iov(tcp, len, tcp->u_arg[1], IOV_DECODE_STR);
239 : 60 : tprintf(", %" PRI_klu ", ", len);
240 : 60 : print_lld_from_low_high_val(tcp, 3);
241 [ + + ]: 60 : if (flags_arg >= 0) {
242 : 8 : tprints(", ");
243 : 8 : printflags(rwf_flags, tcp->u_arg[flags_arg], "RWF_???");
244 : : }
245 : :
246 : 60 : return RVAL_DECODED;
247 : : }
248 : :
249 : 52 : SYS_FUNC(pwritev)
250 : : {
251 : 52 : return do_pwritev(tcp, -1);
252 : : }
253 : :
254 : : /*
255 : : * x32 is the only architecture where preadv2 takes 5 arguments
256 : : * instead of 6, see preadv64v2 in kernel sources.
257 : : * Likewise, x32 is the only architecture where pwritev2 takes 5 arguments
258 : : * instead of 6, see pwritev64v2 in kernel sources.
259 : : */
260 : :
261 : : #if defined X86_64
262 : : # define PREADV2_PWRITEV2_FLAGS_ARG_NO (current_personality == 2 ? 4 : 5)
263 : : #elif defined X32
264 : : # define PREADV2_PWRITEV2_FLAGS_ARG_NO (current_personality == 0 ? 4 : 5)
265 : : #else
266 : : # define PREADV2_PWRITEV2_FLAGS_ARG_NO 5
267 : : #endif
268 : :
269 : 12 : SYS_FUNC(preadv2)
270 : : {
271 [ + - ]: 12 : return do_preadv(tcp, PREADV2_PWRITEV2_FLAGS_ARG_NO);
272 : : }
273 : :
274 : 8 : SYS_FUNC(pwritev2)
275 : : {
276 [ + - ]: 8 : return do_pwritev(tcp, PREADV2_PWRITEV2_FLAGS_ARG_NO);
277 : : }
278 : :
279 : : #include "xlat/splice_flags.h"
280 : :
281 : 2 : SYS_FUNC(tee)
282 : : {
283 : : /* int fd_in */
284 : 2 : printfd(tcp, tcp->u_arg[0]);
285 : 2 : tprints(", ");
286 : : /* int fd_out */
287 : 2 : printfd(tcp, tcp->u_arg[1]);
288 : 2 : tprints(", ");
289 : : /* size_t len */
290 : 2 : tprintf("%" PRI_klu ", ", tcp->u_arg[2]);
291 : : /* unsigned int flags */
292 : 2 : printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
293 : :
294 : 2 : return RVAL_DECODED;
295 : : }
296 : :
297 : 2 : SYS_FUNC(splice)
298 : : {
299 : : /* int fd_in */
300 : 2 : printfd(tcp, tcp->u_arg[0]);
301 : 2 : tprints(", ");
302 : : /* loff_t *off_in */
303 : 2 : printnum_int64(tcp, tcp->u_arg[1], "%" PRId64);
304 : 2 : tprints(", ");
305 : : /* int fd_out */
306 : 2 : printfd(tcp, tcp->u_arg[2]);
307 : 2 : tprints(", ");
308 : : /* loff_t *off_out */
309 : 2 : printnum_int64(tcp, tcp->u_arg[3], "%" PRId64);
310 : 2 : tprints(", ");
311 : : /* size_t len */
312 : 2 : tprintf("%" PRI_klu ", ", tcp->u_arg[4]);
313 : : /* unsigned int flags */
314 : 2 : printflags(splice_flags, tcp->u_arg[5], "SPLICE_F_???");
315 : :
316 : 2 : return RVAL_DECODED;
317 : : }
318 : :
319 : 2 : SYS_FUNC(vmsplice)
320 : : {
321 : : /* int fd */
322 : 2 : printfd(tcp, tcp->u_arg[0]);
323 : 2 : tprints(", ");
324 : : /* const struct iovec *iov, unsigned long nr_segs */
325 : 2 : tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
326 : 2 : tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
327 : : /* unsigned int flags */
328 : 2 : printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
329 : :
330 : 2 : return RVAL_DECODED;
331 : : }
|