2 * Copyright (c) 2010 Andreas Schwab <schwab@linux-m68k.org>
3 * Copyright (c) 2012-2013 Denys Vlasenko <vda.linux@googlemail.com>
4 * Copyright (c) 2014 Masatake YAMATO <yamato@redhat.com>
5 * Copyright (c) 2010-2016 Dmitry V. Levin <ldv@altlinux.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
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.
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.
37 fetch_struct_mmsghdr_or_printaddr(struct tcb *const tcp,
38 const kernel_ulong_t addr,
39 const unsigned int len, void *const mh)
41 if ((entering(tcp) || !syserror(tcp))
42 && fetch_struct_mmsghdr(tcp, addr, mh)) {
50 struct print_struct_mmsghdr_config {
51 const int *p_user_msg_namelen;
52 unsigned int msg_len_vlen;
58 print_struct_mmsghdr(struct tcb *tcp, void *elem_buf,
59 size_t elem_size, void *data)
61 const struct mmsghdr *const mmsg = elem_buf;
62 struct print_struct_mmsghdr_config *const c = data;
71 print_struct_msghdr(tcp, &mmsg->msg_hdr, c->p_user_msg_namelen,
72 c->use_msg_len ? mmsg->msg_len : (kernel_ulong_t) -1);
73 if (c->msg_len_vlen) {
74 tprintf(", msg_len=%u", mmsg->msg_len);
79 if (c->p_user_msg_namelen)
80 ++c->p_user_msg_namelen;
86 free_mmsgvec_data(void *ptr)
102 save_mmsgvec_namelen(struct tcb *const tcp, kernel_ulong_t addr,
103 unsigned int len, const char *const timeout)
108 const size_t data_size = offsetof(struct mmsgvec_data, namelen)
110 struct mmsgvec_data *const data = xmalloc(data_size);
111 data->timeout = xstrdup(timeout);
113 unsigned int i, fetched;
115 for (i = 0; i < len; ++i, addr += fetched) {
118 fetched = fetch_struct_mmsghdr(tcp, addr, &mh);
121 data->namelen[i] = mh.msg_hdr.msg_namelen;
125 set_tcb_priv_data(tcp, data, free_mmsgvec_data);
129 decode_mmsgvec(struct tcb *const tcp, const kernel_ulong_t addr,
130 const unsigned int vlen, const unsigned int msg_len_vlen,
131 const bool use_msg_len)
134 struct print_struct_mmsghdr_config c = {
135 .msg_len_vlen = msg_len_vlen,
137 .use_msg_len = use_msg_len
139 const struct mmsgvec_data *const data = get_tcb_priv_data(tcp);
142 if (data->count < c.count)
143 c.count = data->count;
144 c.p_user_msg_namelen = data->namelen;
147 print_array(tcp, addr, vlen, &mmsg, sizeof_struct_mmsghdr(),
148 fetch_struct_mmsghdr_or_printaddr,
149 print_struct_mmsghdr, &c);
153 dumpiov_in_mmsghdr(struct tcb *const tcp, kernel_ulong_t addr)
155 unsigned int len = tcp->u_rval;
156 unsigned int i, fetched;
159 for (i = 0; i < len; ++i, addr += fetched) {
160 fetched = fetch_struct_mmsghdr(tcp, addr, &mmsg);
163 tprintf(" = %" PRI_klu " buffers in vector %u\n",
164 (kernel_ulong_t) mmsg.msg_hdr.msg_iovlen, i);
165 dumpiov_upto(tcp, mmsg.msg_hdr.msg_iovlen,
166 ptr_to_kulong(mmsg.msg_hdr.msg_iov),
175 printfd(tcp, tcp->u_arg[0]);
179 printaddr(tcp->u_arg[1]);
181 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
183 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
187 const unsigned int msg_len_vlen =
188 syserror(tcp) ? 0 : tcp->u_rval;
190 temporarily_clear_syserror(tcp);
191 decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_arg[2],
192 msg_len_vlen, false);
193 restore_cleared_syserror(tcp);
195 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
197 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
205 printfd(tcp, tcp->u_arg[0]);
208 save_mmsgvec_namelen(tcp, tcp->u_arg[1], tcp->u_arg[2],
209 sprint_timespec(tcp, tcp->u_arg[4]));
212 printaddr(tcp->u_arg[1]);
214 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
216 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
218 print_timespec(tcp, tcp->u_arg[4]);
224 decode_mmsgvec(tcp, tcp->u_arg[1], tcp->u_rval,
227 tprintf(", %u, ", (unsigned int) tcp->u_arg[2]);
229 printflags(msg_flags, tcp->u_arg[3], "MSG_???");
231 /* timeout on entrance */
232 tprints(*(const char **) get_tcb_priv_data(tcp));
236 if (tcp->u_rval == 0) {
237 tcp->auxstr = "Timeout";
240 if (!verbose(tcp) || !tcp->u_arg[4])
242 /* timeout on exit */
243 static char str[sizeof("left") + TIMESPEC_TEXT_BUFSIZE];
244 xsprintf(str, "left %s", sprint_timespec(tcp, tcp->u_arg[4]));