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.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
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.
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.
39 printfd(tcp, tcp->u_arg[0]);
43 printaddr(tcp->u_arg[1]);
45 printstrn(tcp, tcp->u_arg[1], tcp->u_rval);
46 tprintf(", %" PRI_klu, tcp->u_arg[2]);
53 printfd(tcp, tcp->u_arg[0]);
55 printstrn(tcp, tcp->u_arg[1], tcp->u_arg[2]);
56 tprintf(", %" PRI_klu, tcp->u_arg[2]);
61 struct print_iovec_config {
62 enum iov_decode decode_iov;
63 kernel_ulong_t data_size;
67 print_iovec(struct tcb *tcp, void *elem_buf, size_t elem_size, void *data)
69 const kernel_ulong_t *iov;
70 kernel_ulong_t iov_buf[2], len;
71 struct print_iovec_config *c = data;
73 if (elem_size < sizeof(iov_buf)) {
74 iov_buf[0] = ((unsigned int *) elem_buf)[0];
75 iov_buf[1] = ((unsigned int *) elem_buf)[1];
81 tprints("{iov_base=");
85 switch (c->decode_iov) {
87 if (len > c->data_size)
89 if (c->data_size != (kernel_ulong_t) -1)
91 printstrn(tcp, iov[0], len);
93 case IOV_DECODE_NETLINK:
94 if (len > c->data_size)
96 if (c->data_size != (kernel_ulong_t) -1)
98 /* assume that the descriptor is 1st syscall argument */
99 decode_netlink(tcp, tcp->u_arg[0], iov[0], len);
106 tprintf(", iov_len=%" PRI_klu "}", iov[1]);
112 * data_size limits the cumulative size of printed data.
113 * Example: recvmsg returing a short read.
116 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)
120 kernel_ulong_t iov[2];
121 struct print_iovec_config config =
122 { .decode_iov = decode_iov, .data_size = data_size };
124 print_array(tcp, addr, len, iov, current_wordsize * 2,
125 umoven_or_printaddr_ignore_syserror, print_iovec, &config);
131 printfd(tcp, tcp->u_arg[0]);
134 tprint_iov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1],
135 syserror(tcp) ? IOV_DECODE_ADDR :
136 IOV_DECODE_STR, tcp->u_rval);
137 tprintf(", %" PRI_klu, tcp->u_arg[2]);
144 printfd(tcp, tcp->u_arg[0]);
146 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
147 tprintf(", %" PRI_klu, tcp->u_arg[2]);
155 printfd(tcp, tcp->u_arg[0]);
159 printaddr(tcp->u_arg[1]);
161 printstrn(tcp, tcp->u_arg[1], tcp->u_rval);
162 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
163 printllval(tcp, "%lld", 3);
170 printfd(tcp, tcp->u_arg[0]);
172 printstrn(tcp, tcp->u_arg[1], tcp->u_arg[2]);
173 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
174 printllval(tcp, "%lld", 3);
180 print_lld_from_low_high_val(struct tcb *tcp, int arg)
182 #if SIZEOF_KERNEL_LONG_T > 4
183 # ifndef current_klongsize
184 if (current_klongsize < SIZEOF_KERNEL_LONG_T) {
185 tprintf("%" PRI_kld, (tcp->u_arg[arg + 1] << 32)
188 # endif /* !current_klongsize */
190 tprintf("%" PRI_kld, tcp->u_arg[arg]);
192 #else /* SIZEOF_KERNEL_LONG_T == 4 */
194 ((long long) tcp->u_arg[arg + 1] << 32)
195 | ((long long) tcp->u_arg[arg]));
199 #include "xlat/rwf_flags.h"
202 do_preadv(struct tcb *tcp, const int flags_arg)
205 printfd(tcp, tcp->u_arg[0]);
209 truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
211 tprint_iov_upto(tcp, len, tcp->u_arg[1],
212 syserror(tcp) ? IOV_DECODE_ADDR :
213 IOV_DECODE_STR, tcp->u_rval);
214 tprintf(", %" PRI_klu ", ", len);
215 print_lld_from_low_high_val(tcp, 3);
216 if (flags_arg >= 0) {
218 printflags(rwf_flags, tcp->u_arg[flags_arg], "RWF_???");
226 return do_preadv(tcp, -1);
230 do_pwritev(struct tcb *tcp, const int flags_arg)
233 truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
235 printfd(tcp, tcp->u_arg[0]);
237 tprint_iov(tcp, len, tcp->u_arg[1], IOV_DECODE_STR);
238 tprintf(", %" PRI_klu ", ", len);
239 print_lld_from_low_high_val(tcp, 3);
240 if (flags_arg >= 0) {
242 printflags(rwf_flags, tcp->u_arg[flags_arg], "RWF_???");
250 return do_pwritev(tcp, -1);
254 * x32 is the only architecture where preadv2 takes 5 arguments
255 * instead of 6, see preadv64v2 in kernel sources.
256 * Likewise, x32 is the only architecture where pwritev2 takes 5 arguments
257 * instead of 6, see pwritev64v2 in kernel sources.
261 # define PREADV2_PWRITEV2_FLAGS_ARG_NO (current_personality == 2 ? 4 : 5)
263 # define PREADV2_PWRITEV2_FLAGS_ARG_NO (current_personality == 0 ? 4 : 5)
265 # define PREADV2_PWRITEV2_FLAGS_ARG_NO 5
270 return do_preadv(tcp, PREADV2_PWRITEV2_FLAGS_ARG_NO);
275 return do_pwritev(tcp, PREADV2_PWRITEV2_FLAGS_ARG_NO);
278 #include "xlat/splice_flags.h"
283 printfd(tcp, tcp->u_arg[0]);
286 printfd(tcp, tcp->u_arg[1]);
289 tprintf("%" PRI_klu ", ", tcp->u_arg[2]);
290 /* unsigned int flags */
291 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
299 printfd(tcp, tcp->u_arg[0]);
302 printnum_int64(tcp, tcp->u_arg[1], "%" PRId64);
305 printfd(tcp, tcp->u_arg[2]);
307 /* loff_t *off_out */
308 printnum_int64(tcp, tcp->u_arg[3], "%" PRId64);
311 tprintf("%" PRI_klu ", ", tcp->u_arg[4]);
312 /* unsigned int flags */
313 printflags(splice_flags, tcp->u_arg[5], "SPLICE_F_???");
321 printfd(tcp, tcp->u_arg[0]);
323 /* const struct iovec *iov, unsigned long nr_segs */
324 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
325 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
326 /* unsigned int flags */
327 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");