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>
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.
35 printfd(tcp, tcp->u_arg[0]);
42 printfd(tcp, tcp->u_arg[0]);
44 return RVAL_DECODED | RVAL_FD;
48 do_dup2(struct tcb *tcp, int flags_arg)
50 printfd(tcp, tcp->u_arg[0]);
52 printfd(tcp, tcp->u_arg[1]);
55 printflags(open_mode_flags, tcp->u_arg[flags_arg], "O_???");
58 return RVAL_DECODED | RVAL_FD;
63 return do_dup2(tcp, -1);
68 return do_dup2(tcp, 2);
72 SYS_FUNC(getdtablesize)
79 decode_select(struct tcb *tcp, long *args,
80 void (*print_tv_ts) (struct tcb *, const long),
81 const char * (*sprint_tv_ts) (struct tcb *, const long))
89 /* Kernel truncates arg[0] to int, we do the same. */
92 /* Kernel rejects negative nfds, so we don't parse it either. */
96 /* Beware of select(2^31-1, NULL, NULL, NULL) and similar... */
101 * We had bugs a-la "while (j < args[0])" and "umoven(args[0])" below.
102 * Instead of args[0], use nfds for fd count, fdsize for array lengths.
104 fdsize = (((nfds + 7) / 8) + current_wordsize-1) & -current_wordsize;
107 tprintf("%d", (int) args[0]);
109 if (verbose(tcp) && fdsize > 0)
110 fds = malloc(fdsize);
111 for (i = 0; i < 3; i++) {
118 if (umoven_or_printaddr(tcp, arg, fdsize, fds))
121 for (j = 0, sep = "";; j++) {
122 j = next_set_bit(fds, j, nfds);
133 print_tv_ts(tcp, args[4]);
135 static char outstr[1024];
137 #define end_outstr (outstr + sizeof(outstr))
143 ready_fds = tcp->u_rval;
144 if (ready_fds == 0) {
145 tcp->auxstr = "Timeout";
149 fds = malloc(fdsize);
153 for (i = 0; i < 3 && ready_fds > 0; i++) {
157 if (!arg || !fds || umoven(tcp, arg, fdsize, fds) < 0)
160 j = next_set_bit(fds, j, nfds);
163 /* +2 chars needed at the end: ']',NUL */
164 if (outptr < end_outstr - (sizeof(", except [") + sizeof(int)*3 + 2)) {
166 outptr += sprintf(outptr, "%s%s [%u",
168 i == 0 ? "in" : i == 1 ? "out" : "except",
175 outptr += sprintf(outptr, " %u", j);
178 if (--ready_fds == 0)
181 if (outptr != outstr)
185 /* This contains no useful information on SunOS. */
187 const char *str = sprint_tv_ts(tcp, args[4]);
188 if (outptr + sizeof("left ") + strlen(sep) + strlen(str) < end_outstr) {
189 outptr += sprintf(outptr, "%sleft %s", sep, str);
193 tcp->auxstr = outstr;
203 #undef oldselect_args
205 # define oldselect_args long_args
207 unsigned int oldselect_args[5];
211 if (umove(tcp, tcp->u_arg[0], &oldselect_args) < 0) {
212 printaddr(tcp->u_arg[0]);
215 #ifndef oldselect_args
216 for (i = 0; i < 5; i++) {
217 long_args[i] = oldselect_args[i];
220 return decode_select(tcp, long_args, print_timeval, sprint_timeval);
221 #undef oldselect_args
227 return decode_select(tcp, tcp->u_arg, print_timeval32, sprint_timeval32);
233 return decode_select(tcp, tcp->u_arg, print_timeval, sprint_timeval);
236 #include "kernel_types.h"
239 umove_kulong_array_or_printaddr(struct tcb *tcp, const long addr,
240 kernel_ulong_t *ptr, size_t n)
242 #if defined X86_64 || defined X32
243 if (current_personality == 1) {
245 if (current_wordsize < sizeof(*ptr)) {
248 int r = umove_or_printaddr(tcp, addr, &ptr32);
252 for (i = 0; i < n; ++i)
253 ptr[i] = (kernel_ulong_t) ptr32[i];
257 return umoven_or_printaddr(tcp, addr, n * sizeof(*ptr), ptr);
262 int rc = decode_select(tcp, tcp->u_arg, print_timespec, sprint_timespec);
264 kernel_ulong_t data[2];
267 if (!umove_kulong_array_or_printaddr(tcp, tcp->u_arg[5],
268 data, ARRAY_SIZE(data))) {
270 /* NB: kernel requires data[1] == NSIG / 8 */
271 print_sigset_addr_len(tcp, (unsigned long) data[0],
272 (unsigned long) data[1]);
273 tprintf(", %Lu}", (unsigned long long) data[1]);