blob: 4d8549ba59924a40b1b3f978429bda67ab1dfb7d [file] [log] [blame]
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00001/*
2 * Copyright (c) 1993, 1994, 1995, 1996 Rick Sladkey <jrs@world.std.com>
Wichert Akkerman4dc8a2a1999-12-23 14:20:14 +00003 * Copyright (c) 1996-1999 Wichert Akkerman <wichert@cistron.nl>
Wichert Akkerman76baf7c1999-02-19 00:21:36 +00004 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000027 */
28
29#include "defs.h"
Dmitry V. Levind64a7e42013-11-06 01:17:05 +000030#if defined HAVE_POLL_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010031# include <poll.h>
Dmitry V. Levind64a7e42013-11-06 01:17:05 +000032#elif defined HAVE_SYS_POLL_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010033# include <sys/poll.h>
Pavel Machek245a6ac2000-02-01 16:12:33 +000034#endif
Wichert Akkerman42080d82001-04-10 10:32:26 +000035#ifdef HAVE_SYS_CONF_H
Denys Vlasenkoa6d91de2012-03-16 12:02:22 +010036# include <sys/conf.h>
Wichert Akkerman42080d82001-04-10 10:32:26 +000037#endif
Wichert Akkerman42080d82001-04-10 10:32:26 +000038
Denys Vlasenkocc902912013-03-05 16:50:12 +010039/* Who has STREAMS syscalls?
40 * Linux hasn't. Solaris has (had?).
41 * Just in case I miss something, retain in for Sparc...
42 */
43#if defined(SPARC) || defined(SPARC64)
44
45# ifdef HAVE_STROPTS_H
46# include <stropts.h>
47# else
48# define RS_HIPRI 1
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000049struct strbuf {
Denys Vlasenkoadedb512008-12-30 18:47:55 +000050 int maxlen; /* no. of bytes in buffer */
51 int len; /* no. of bytes returned */
Dmitry V. Levin30145dd2010-09-06 22:08:24 +000052 const char *buf; /* pointer to data */
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000053};
Denys Vlasenkocc902912013-03-05 16:50:12 +010054# define MORECTL 1
55# define MOREDATA 2
56# endif
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000057
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +000058#include "xlat/msgflags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000059
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000060static void
Denys Vlasenko12014262011-05-30 14:00:14 +020061printstrbuf(struct tcb *tcp, struct strbuf *sbp, int getting)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000062{
63 if (sbp->maxlen == -1 && getting)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020064 tprints("{maxlen=-1}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000065 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020066 tprints("{");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000067 if (getting)
68 tprintf("maxlen=%d, ", sbp->maxlen);
69 tprintf("len=%d, buf=", sbp->len);
Wichert Akkerman2e2553a1999-05-09 00:29:58 +000070 printstr(tcp, (unsigned long) sbp->buf, sbp->len);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020071 tprints("}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000072 }
73}
74
75static void
Denys Vlasenkoe7db4652013-03-05 16:17:46 +010076printstrbufarg(struct tcb *tcp, long arg, int getting)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000077{
78 struct strbuf buf;
79
80 if (arg == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020081 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000082 else if (umove(tcp, arg, &buf) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020083 tprints("{...}");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000084 else
85 printstrbuf(tcp, &buf, getting);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +020086 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000087}
88
Dmitry V. Levina0bd3742015-04-07 01:36:50 +000089SYS_FUNC(putmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +000090{
91 int i;
92
93 if (entering(tcp)) {
94 /* fd */
95 tprintf("%ld, ", tcp->u_arg[0]);
96 /* control and data */
97 for (i = 1; i < 3; i++)
98 printstrbufarg(tcp, tcp->u_arg[i], 0);
99 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000100 printflags(msgflags, tcp->u_arg[3], "RS_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000101 }
102 return 0;
103}
104
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000105SYS_FUNC(getmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000106{
107 int i, flags;
108
109 if (entering(tcp)) {
110 /* fd */
111 tprintf("%lu, ", tcp->u_arg[0]);
112 } else {
113 if (syserror(tcp)) {
114 tprintf("%#lx, %#lx, %#lx",
115 tcp->u_arg[1], tcp->u_arg[2], tcp->u_arg[3]);
116 return 0;
117 }
118 /* control and data */
119 for (i = 1; i < 3; i++)
120 printstrbufarg(tcp, tcp->u_arg[i], 1);
121 /* pointer to flags */
122 if (tcp->u_arg[3] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200123 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000124 else if (umove(tcp, tcp->u_arg[3], &flags) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200125 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000126 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200127 tprints("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000128 printflags(msgflags, flags, "RS_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200129 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000130 }
131 /* decode return value */
132 switch (tcp->u_rval) {
133 case MORECTL:
134 tcp->auxstr = "MORECTL";
135 break;
136 case MORECTL|MOREDATA:
137 tcp->auxstr = "MORECTL|MOREDATA";
138 break;
139 case MOREDATA:
140 tcp->auxstr = "MORECTL";
141 break;
142 default:
143 tcp->auxstr = NULL;
144 break;
145 }
146 }
147 return RVAL_HEX | RVAL_STR;
148}
149
Denys Vlasenkocc902912013-03-05 16:50:12 +0100150# if defined SYS_putpmsg || defined SYS_getpmsg
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000151#include "xlat/pmsgflags.h"
Denys Vlasenkocc902912013-03-05 16:50:12 +0100152# ifdef SYS_putpmsg
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000153SYS_FUNC(putpmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000154{
155 int i;
156
157 if (entering(tcp)) {
158 /* fd */
159 tprintf("%ld, ", tcp->u_arg[0]);
160 /* control and data */
161 for (i = 1; i < 3; i++)
162 printstrbufarg(tcp, tcp->u_arg[i], 0);
163 /* band */
164 tprintf("%ld, ", tcp->u_arg[3]);
165 /* flags */
Roland McGrathb2dee132005-06-01 19:02:36 +0000166 printflags(pmsgflags, tcp->u_arg[4], "MSG_???");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000167 }
168 return 0;
169}
Denys Vlasenkocc902912013-03-05 16:50:12 +0100170# endif
171# ifdef SYS_getpmsg
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000172SYS_FUNC(getpmsg)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000173{
174 int i, flags;
175
176 if (entering(tcp)) {
177 /* fd */
178 tprintf("%lu, ", tcp->u_arg[0]);
179 } else {
180 if (syserror(tcp)) {
181 tprintf("%#lx, %#lx, %#lx, %#lx", tcp->u_arg[1],
182 tcp->u_arg[2], tcp->u_arg[3], tcp->u_arg[4]);
183 return 0;
184 }
185 /* control and data */
186 for (i = 1; i < 3; i++)
187 printstrbufarg(tcp, tcp->u_arg[i], 1);
188 /* pointer to band */
Dmitry V. Levinf55cca72015-02-17 22:00:45 +0000189 printnum_int(tcp, tcp->u_arg[3], "%d");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200190 tprints(", ");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000191 /* pointer to flags */
192 if (tcp->u_arg[4] == 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200193 tprints("NULL");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000194 else if (umove(tcp, tcp->u_arg[4], &flags) < 0)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200195 tprints("[?]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000196 else {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200197 tprints("[");
Roland McGrathb2dee132005-06-01 19:02:36 +0000198 printflags(pmsgflags, flags, "MSG_???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200199 tprints("]");
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000200 }
201 /* decode return value */
202 switch (tcp->u_rval) {
203 case MORECTL:
204 tcp->auxstr = "MORECTL";
205 break;
206 case MORECTL|MOREDATA:
207 tcp->auxstr = "MORECTL|MOREDATA";
208 break;
209 case MOREDATA:
210 tcp->auxstr = "MORECTL";
211 break;
212 default:
213 tcp->auxstr = NULL;
214 break;
215 }
216 }
217 return RVAL_HEX | RVAL_STR;
218}
Denys Vlasenkocc902912013-03-05 16:50:12 +0100219# endif
220# endif /* getpmsg/putpmsg */
221
222#endif /* STREAMS syscalls support */
223
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000224
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000225#ifdef HAVE_SYS_POLL_H
226
Dmitry V. Levin0ed617b2014-04-25 23:30:54 +0000227#include "xlat/pollflags.h"
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000228
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000229static int
Roland McGrathf17106e2007-11-01 21:49:49 +0000230decode_poll(struct tcb *tcp, long pts)
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000231{
Roland McGrathaa524c82005-06-01 19:22:06 +0000232 struct pollfd fds;
233 unsigned nfds;
234 unsigned long size, start, cur, end, abbrev_end;
235 int failed = 0;
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000236
Roland McGrathf17106e2007-11-01 21:49:49 +0000237 if (entering(tcp)) {
238 nfds = tcp->u_arg[1];
239 size = sizeof(fds) * nfds;
240 start = tcp->u_arg[0];
241 end = start + size;
242 if (nfds == 0 || size / sizeof(fds) != nfds || end < start) {
243 tprintf("%#lx, %d, ",
244 tcp->u_arg[0], nfds);
245 return 0;
246 }
247 if (abbrev(tcp)) {
248 abbrev_end = start + max_strlen * sizeof(fds);
249 if (abbrev_end < start)
250 abbrev_end = end;
251 } else {
Roland McGrathaa524c82005-06-01 19:22:06 +0000252 abbrev_end = end;
Roland McGrathf17106e2007-11-01 21:49:49 +0000253 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200254 tprints("[");
Roland McGrathf17106e2007-11-01 21:49:49 +0000255 for (cur = start; cur < end; cur += sizeof(fds)) {
256 if (cur > start)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200257 tprints(", ");
Roland McGrathf17106e2007-11-01 21:49:49 +0000258 if (cur >= abbrev_end) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200259 tprints("...");
Roland McGrathf17106e2007-11-01 21:49:49 +0000260 break;
261 }
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100262 if (umoven(tcp, cur, sizeof fds, &fds) < 0) {
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200263 tprints("?");
Roland McGrathf17106e2007-11-01 21:49:49 +0000264 failed = 1;
265 break;
266 }
267 if (fds.fd < 0) {
268 tprintf("{fd=%d}", fds.fd);
269 continue;
270 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200271 tprints("{fd=");
Dmitry V. Levin31382132011-03-04 05:08:02 +0300272 printfd(tcp, fds.fd);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200273 tprints(", events=");
Roland McGrathf17106e2007-11-01 21:49:49 +0000274 printflags(pollflags, fds.events, "POLL???");
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200275 tprints("}");
Roland McGrathf17106e2007-11-01 21:49:49 +0000276 }
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200277 tprints("]");
Roland McGrathf17106e2007-11-01 21:49:49 +0000278 if (failed)
279 tprintf(" %#lx", start);
280 tprintf(", %d, ", nfds);
281 return 0;
Roland McGrathaa524c82005-06-01 19:22:06 +0000282 } else {
Roland McGrathf17106e2007-11-01 21:49:49 +0000283 static char outstr[1024];
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200284 char *outptr;
285#define end_outstr (outstr + sizeof(outstr))
Denys Vlasenkoadedb512008-12-30 18:47:55 +0000286 const char *flagstr;
Roland McGrathf17106e2007-11-01 21:49:49 +0000287
288 if (syserror(tcp))
289 return 0;
290 if (tcp->u_rval == 0) {
291 tcp->auxstr = "Timeout";
292 return RVAL_STR;
293 }
294
295 nfds = tcp->u_arg[1];
296 size = sizeof(fds) * nfds;
297 start = tcp->u_arg[0];
298 end = start + size;
299 if (nfds == 0 || size / sizeof(fds) != nfds || end < start)
300 return 0;
301 if (abbrev(tcp)) {
302 abbrev_end = start + max_strlen * sizeof(fds);
303 if (abbrev_end < start)
304 abbrev_end = end;
305 } else {
306 abbrev_end = end;
307 }
308
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200309 outptr = outstr;
Roland McGrathf17106e2007-11-01 21:49:49 +0000310
311 for (cur = start; cur < end; cur += sizeof(fds)) {
Denys Vlasenko7e69ed92015-03-21 19:50:53 +0100312 if (umoven(tcp, cur, sizeof fds, &fds) < 0) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200313 if (outptr < end_outstr - 2)
314 *outptr++ = '?';
Roland McGrathf17106e2007-11-01 21:49:49 +0000315 failed = 1;
316 break;
317 }
318 if (!fds.revents)
319 continue;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200320 if (outptr == outstr) {
321 *outptr++ = '[';
Roland McGrathf17106e2007-11-01 21:49:49 +0000322 } else {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200323 if (outptr < end_outstr - 3)
324 outptr = stpcpy(outptr, ", ");
Roland McGrathf17106e2007-11-01 21:49:49 +0000325 }
326 if (cur >= abbrev_end) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200327 if (outptr < end_outstr - 4)
328 outptr = stpcpy(outptr, "...");
Roland McGrathf17106e2007-11-01 21:49:49 +0000329 break;
330 }
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200331 if (outptr < end_outstr - (sizeof("{fd=%d, revents=") + sizeof(int)*3) + 1)
332 outptr += sprintf(outptr, "{fd=%d, revents=", fds.fd);
Denys Vlasenkob63256e2011-06-07 12:13:24 +0200333 flagstr = sprintflags("", pollflags, fds.revents);
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200334 if (outptr < end_outstr - (strlen(flagstr) + 2)) {
335 outptr = stpcpy(outptr, flagstr);
336 *outptr++ = '}';
Roland McGrathf17106e2007-11-01 21:49:49 +0000337 }
338 }
339 if (failed)
340 return 0;
341
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200342 if (outptr != outstr /* && outptr < end_outstr - 1 (always true)*/)
343 *outptr++ = ']';
Roland McGrathf17106e2007-11-01 21:49:49 +0000344
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200345 *outptr = '\0';
Roland McGrathf17106e2007-11-01 21:49:49 +0000346 if (pts) {
Denys Vlasenkoa1d541e2012-01-20 11:04:04 +0100347 if (outptr < end_outstr - (10 + TIMESPEC_TEXT_BUFSIZE)) {
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200348 outptr = stpcpy(outptr, outptr == outstr ? "left " : ", left ");
349 sprint_timespec(outptr, tcp, pts);
350 }
Roland McGrathf17106e2007-11-01 21:49:49 +0000351 }
352
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200353 if (outptr == outstr)
Roland McGrathf17106e2007-11-01 21:49:49 +0000354 return 0;
355
356 tcp->auxstr = outstr;
357 return RVAL_STR;
Denys Vlasenko2fb4db32011-08-31 12:26:03 +0200358#undef end_outstr
Roland McGrathaa524c82005-06-01 19:22:06 +0000359 }
Wichert Akkerman76baf7c1999-02-19 00:21:36 +0000360}
361
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000362SYS_FUNC(poll)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000363{
Roland McGrathf17106e2007-11-01 21:49:49 +0000364 int rc = decode_poll(tcp, 0);
365 if (entering(tcp)) {
Denys Vlasenkocc902912013-03-05 16:50:12 +0100366# ifdef INFTIM
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000367 if (tcp->u_arg[2] == INFTIM)
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200368 tprints("INFTIM");
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000369 else
Denys Vlasenkocc902912013-03-05 16:50:12 +0100370# endif
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000371 tprintf("%ld", tcp->u_arg[2]);
372 }
373 return rc;
374}
375
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000376SYS_FUNC(ppoll)
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000377{
Roland McGrathf17106e2007-11-01 21:49:49 +0000378 int rc = decode_poll(tcp, tcp->u_arg[2]);
379 if (entering(tcp)) {
Roland McGrath6bc09da2007-11-01 21:50:54 +0000380 print_timespec(tcp, tcp->u_arg[2]);
Denys Vlasenko60fe8c12011-09-01 10:00:28 +0200381 tprints(", ");
Denys Vlasenko5e133aa2013-07-18 17:02:21 +0200382 /* NB: kernel requires arg[4] == NSIG / 8 */
383 print_sigset_addr_len(tcp, tcp->u_arg[3], tcp->u_arg[4]);
Dmitry V. Levin95ebf5a2006-10-13 20:25:12 +0000384 tprintf(", %lu", tcp->u_arg[4]);
385 }
386 return rc;
387}
Roland McGrathaa524c82005-06-01 19:22:06 +0000388
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000389#else /* !HAVE_SYS_POLL_H */
Dmitry V. Levina0bd3742015-04-07 01:36:50 +0000390SYS_FUNC(poll)
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000391{
Denys Vlasenko5ae2b7c2009-02-27 20:32:52 +0000392 return 0;
Wichert Akkermanfaf72222000-02-19 23:59:03 +0000393}
394#endif