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
125 print_array(tcp, addr, len, iov, current_wordsize * 2,
126 umoven_or_printaddr_ignore_syserror, print_iovec, &config);
132 printfd(tcp, tcp->u_arg[0]);
135 tprint_iov_upto(tcp, tcp->u_arg[2], tcp->u_arg[1],
136 syserror(tcp) ? IOV_DECODE_ADDR :
137 IOV_DECODE_STR, tcp->u_rval);
138 tprintf(", %" PRI_klu, tcp->u_arg[2]);
145 printfd(tcp, tcp->u_arg[0]);
147 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
148 tprintf(", %" PRI_klu, tcp->u_arg[2]);
156 printfd(tcp, tcp->u_arg[0]);
160 printaddr(tcp->u_arg[1]);
162 printstrn(tcp, tcp->u_arg[1], tcp->u_rval);
163 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
164 printllval(tcp, "%lld", 3);
171 printfd(tcp, tcp->u_arg[0]);
173 printstrn(tcp, tcp->u_arg[1], tcp->u_arg[2]);
174 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
175 printllval(tcp, "%lld", 3);
181 print_lld_from_low_high_val(struct tcb *tcp, int arg)
183 #if SIZEOF_KERNEL_LONG_T > 4
184 # ifndef current_klongsize
185 if (current_klongsize < SIZEOF_KERNEL_LONG_T) {
186 tprintf("%" PRI_kld, (tcp->u_arg[arg + 1] << 32)
189 # endif /* !current_klongsize */
191 tprintf("%" PRI_kld, tcp->u_arg[arg]);
193 #else /* SIZEOF_KERNEL_LONG_T == 4 */
195 ((long long) tcp->u_arg[arg + 1] << 32)
196 | ((long long) tcp->u_arg[arg]));
200 #include "xlat/rwf_flags.h"
203 do_preadv(struct tcb *tcp, const int flags_arg)
206 printfd(tcp, tcp->u_arg[0]);
210 truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
212 tprint_iov_upto(tcp, len, tcp->u_arg[1],
213 syserror(tcp) ? IOV_DECODE_ADDR :
214 IOV_DECODE_STR, tcp->u_rval);
215 tprintf(", %" PRI_klu ", ", len);
216 print_lld_from_low_high_val(tcp, 3);
217 if (flags_arg >= 0) {
219 printflags(rwf_flags, tcp->u_arg[flags_arg], "RWF_???");
227 return do_preadv(tcp, -1);
231 do_pwritev(struct tcb *tcp, const int flags_arg)
234 truncate_kulong_to_current_wordsize(tcp->u_arg[2]);
236 printfd(tcp, tcp->u_arg[0]);
238 tprint_iov(tcp, len, tcp->u_arg[1], IOV_DECODE_STR);
239 tprintf(", %" PRI_klu ", ", len);
240 print_lld_from_low_high_val(tcp, 3);
241 if (flags_arg >= 0) {
243 printflags(rwf_flags, tcp->u_arg[flags_arg], "RWF_???");
251 return do_pwritev(tcp, -1);
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.
262 # define PREADV2_PWRITEV2_FLAGS_ARG_NO (current_personality == 2 ? 4 : 5)
264 # define PREADV2_PWRITEV2_FLAGS_ARG_NO (current_personality == 0 ? 4 : 5)
266 # define PREADV2_PWRITEV2_FLAGS_ARG_NO 5
271 return do_preadv(tcp, PREADV2_PWRITEV2_FLAGS_ARG_NO);
276 return do_pwritev(tcp, PREADV2_PWRITEV2_FLAGS_ARG_NO);
279 #include "xlat/splice_flags.h"
284 printfd(tcp, tcp->u_arg[0]);
287 printfd(tcp, tcp->u_arg[1]);
290 tprintf("%" PRI_klu ", ", tcp->u_arg[2]);
291 /* unsigned int flags */
292 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");
300 printfd(tcp, tcp->u_arg[0]);
303 printnum_int64(tcp, tcp->u_arg[1], "%" PRId64);
306 printfd(tcp, tcp->u_arg[2]);
308 /* loff_t *off_out */
309 printnum_int64(tcp, tcp->u_arg[3], "%" PRId64);
312 tprintf("%" PRI_klu ", ", tcp->u_arg[4]);
313 /* unsigned int flags */
314 printflags(splice_flags, tcp->u_arg[5], "SPLICE_F_???");
322 printfd(tcp, tcp->u_arg[0]);
324 /* const struct iovec *iov, unsigned long nr_segs */
325 tprint_iov(tcp, tcp->u_arg[2], tcp->u_arg[1], IOV_DECODE_STR);
326 tprintf(", %" PRI_klu ", ", tcp->u_arg[2]);
327 /* unsigned int flags */
328 printflags(splice_flags, tcp->u_arg[3], "SPLICE_F_???");