Sat Aug 19 03:40:48 2017 UTC ()
Pull up following revision(s) (requested by mrg in ticket #1479):
	sys/compat/svr4/svr4_lwp.c: 1.20
	sys/compat/svr4/svr4_signal.c: 1.67
	sys/compat/svr4/svr4_stream.c: 1.89-1.91 via patch
	sys/compat/svr4_32/svr4_32_signal.c: 1.29
Fix some of the multitudinous holes in svr4 streams.
We should never have enabled this by default; it is a minefield.
From Ilja Van Sprundel.
--
Zero stack data before copyout.
From Ilja Van Sprundel.
--
Fix indexing of svr4 signals.
From Ilja Van Sprundel.
--
Feebly attempt to get this reference counting less bad.
This svr4 streams code is bad and it should feel bad.
From Ilja Van Sprundel.
--
Check bounds in svr4_sys_putmsg.  Check more svr4_strmcmd bounds.
svr4 streams code is still a disaster.
From Ilja Van Sprundel.


(snj)
diff -r1.19 -r1.19.32.1 src/sys/compat/svr4/svr4_lwp.c
diff -r1.65 -r1.65.24.1 src/sys/compat/svr4/svr4_signal.c
diff -r1.79 -r1.79.22.1 src/sys/compat/svr4/svr4_stream.c
diff -r1.26 -r1.26.56.1 src/sys/compat/svr4_32/svr4_32_signal.c

cvs diff -r1.19 -r1.19.32.1 src/sys/compat/svr4/Attic/svr4_lwp.c (switch to unified diff)

--- src/sys/compat/svr4/Attic/svr4_lwp.c 2009/11/23 00:46:07 1.19
+++ src/sys/compat/svr4/Attic/svr4_lwp.c 2017/08/19 03:40:48 1.19.32.1
@@ -1,178 +1,180 @@ @@ -1,178 +1,180 @@
1/* $NetBSD: svr4_lwp.c,v 1.19 2009/11/23 00:46:07 rmind Exp $ */ 1/* $NetBSD: svr4_lwp.c,v 1.19.32.1 2017/08/19 03:40:48 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc. 4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: svr4_lwp.c,v 1.19 2009/11/23 00:46:07 rmind Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: svr4_lwp.c,v 1.19.32.1 2017/08/19 03:40:48 snj Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/kernel.h> 36#include <sys/kernel.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/queue.h> 38#include <sys/queue.h>
39#include <sys/mbuf.h> 39#include <sys/mbuf.h>
40#include <sys/file.h> 40#include <sys/file.h>
41#include <sys/mount.h> 41#include <sys/mount.h>
42#include <sys/time.h> 42#include <sys/time.h>
43#include <sys/resourcevar.h> 43#include <sys/resourcevar.h>
44#include <sys/proc.h> 44#include <sys/proc.h>
45#include <sys/socket.h> 45#include <sys/socket.h>
46#include <sys/socketvar.h> 46#include <sys/socketvar.h>
47#include <sys/syscallargs.h> 47#include <sys/syscallargs.h>
48#include <sys/un.h> 48#include <sys/un.h>
49#include <sys/stat.h> 49#include <sys/stat.h>
50 50
51#include <compat/svr4/svr4_types.h> 51#include <compat/svr4/svr4_types.h>
52#include <compat/svr4/svr4_util.h> 52#include <compat/svr4/svr4_util.h>
53#include <compat/svr4/svr4_socket.h> 53#include <compat/svr4/svr4_socket.h>
54#include <compat/svr4/svr4_signal.h> 54#include <compat/svr4/svr4_signal.h>
55#include <compat/svr4/svr4_sockmod.h> 55#include <compat/svr4/svr4_sockmod.h>
56#include <compat/svr4/svr4_lwp.h> 56#include <compat/svr4/svr4_lwp.h>
57#include <compat/svr4/svr4_ucontext.h> 57#include <compat/svr4/svr4_ucontext.h>
58#include <compat/svr4/svr4_syscallargs.h> 58#include <compat/svr4/svr4_syscallargs.h>
59 59
60 60
61int 61int
62svr4_sys__lwp_self(struct lwp *l, const void *uap, register_t *retval) 62svr4_sys__lwp_self(struct lwp *l, const void *uap, register_t *retval)
63{ 63{
64 return sys__lwp_self(l, uap, retval); 64 return sys__lwp_self(l, uap, retval);
65} 65}
66 66
67int 67int
68svr4_sys__lwp_create(struct lwp *l, const struct svr4_sys__lwp_create_args *uap, register_t *retval) 68svr4_sys__lwp_create(struct lwp *l, const struct svr4_sys__lwp_create_args *uap, register_t *retval)
69{ 69{
70 struct sys__lwp_create_args lc; 70 struct sys__lwp_create_args lc;
71 int flags; 71 int flags;
72 72
73 flags = 0; 73 flags = 0;
74 74
75 if (SCARG(uap, flags) & SVR4_LWP_DETACHED) 75 if (SCARG(uap, flags) & SVR4_LWP_DETACHED)
76 flags &= LWP_DETACHED; 76 flags &= LWP_DETACHED;
77 77
78 if (SCARG(uap, flags) & SVR4_LWP_SUSPENDED) 78 if (SCARG(uap, flags) & SVR4_LWP_SUSPENDED)
79 flags &= LWP_SUSPENDED; 79 flags &= LWP_SUSPENDED;
80 80
81 if (SCARG(uap, flags) & SVR4___LWP_ASLWP) { 81 if (SCARG(uap, flags) & SVR4___LWP_ASLWP) {
82 /* XXX Punt! */ 82 /* XXX Punt! */
83 } 83 }
84 84
85 85
86 /* XXX At the moment, svr4_ucontext_t and ucontext_t are the same */ 86 /* XXX At the moment, svr4_ucontext_t and ucontext_t are the same */
87 SCARG(&lc, ucp) = (ucontext_t *)SCARG(uap, uc); 87 SCARG(&lc, ucp) = (ucontext_t *)SCARG(uap, uc);
88 SCARG(&lc, flags) = flags; 88 SCARG(&lc, flags) = flags;
89 SCARG(&lc, new_lwp) = (lwpid_t *)SCARG(uap, lwpid); 89 SCARG(&lc, new_lwp) = (lwpid_t *)SCARG(uap, lwpid);
90 90
91 91
92 return sys__lwp_create(l, &lc, retval); 92 return sys__lwp_create(l, &lc, retval);
93} 93}
94 94
95int 95int
96svr4_sys__lwp_kill(struct lwp *l, const struct svr4_sys__lwp_kill_args *uap, register_t *retval) 96svr4_sys__lwp_kill(struct lwp *l, const struct svr4_sys__lwp_kill_args *uap, register_t *retval)
97{ 97{
98 struct sys__lwp_kill_args ap; 98 struct sys__lwp_kill_args ap;
99 SCARG(&ap, target) = SCARG(uap, lwpid); 99 SCARG(&ap, target) = SCARG(uap, lwpid);
100 SCARG(&ap, signo) = SCARG(uap, signum); 100 SCARG(&ap, signo) = SCARG(uap, signum);
101 101
102 return sys__lwp_kill(l, &ap, retval); 102 return sys__lwp_kill(l, &ap, retval);
103} 103}
104 104
105int 105int
106svr4_sys__lwp_info(struct lwp *l, const struct svr4_sys__lwp_info_args *uap, register_t *retval) 106svr4_sys__lwp_info(struct lwp *l, const struct svr4_sys__lwp_info_args *uap, register_t *retval)
107{ 107{
108 struct svr4_lwpinfo lwpinfo; 108 struct svr4_lwpinfo lwpinfo;
109 int error; 109 int error;
110 110
 111 memset(&lwpinfo, 0, sizeof(lwpinfo));
 112
111 /* XXX NJWLWP */ 113 /* XXX NJWLWP */
112 TIMEVAL_TO_TIMESPEC(&l->l_proc->p_stats->p_ru.ru_stime, &lwpinfo.lwp_stime); 114 TIMEVAL_TO_TIMESPEC(&l->l_proc->p_stats->p_ru.ru_stime, &lwpinfo.lwp_stime);
113 TIMEVAL_TO_TIMESPEC(&l->l_proc->p_stats->p_ru.ru_utime, &lwpinfo.lwp_utime); 115 TIMEVAL_TO_TIMESPEC(&l->l_proc->p_stats->p_ru.ru_utime, &lwpinfo.lwp_utime);
114 116
115 if ((error = copyout(&lwpinfo, SCARG(uap, lwpinfo), sizeof(lwpinfo))) == 117 if ((error = copyout(&lwpinfo, SCARG(uap, lwpinfo), sizeof(lwpinfo))) ==
116 -1) 118 -1)
117 return error; 119 return error;
118 return 0; 120 return 0;
119} 121}
120 122
121int 123int
122svr4_sys__lwp_exit(struct lwp *l, const void *v, register_t *retval) 124svr4_sys__lwp_exit(struct lwp *l, const void *v, register_t *retval)
123{ 125{
124 126
125 return sys__lwp_exit(l, NULL, retval); 127 return sys__lwp_exit(l, NULL, retval);
126} 128}
127 129
128int 130int
129svr4_sys__lwp_wait(struct lwp *l, const struct svr4_sys__lwp_wait_args *uap, register_t *retval) 131svr4_sys__lwp_wait(struct lwp *l, const struct svr4_sys__lwp_wait_args *uap, register_t *retval)
130{ 132{
131 struct sys__lwp_wait_args ap; 133 struct sys__lwp_wait_args ap;
132 134
133 SCARG(&ap, wait_for) = SCARG(uap, wait_for); 135 SCARG(&ap, wait_for) = SCARG(uap, wait_for);
134 SCARG(&ap, departed) = (lwpid_t *)SCARG(uap, departed_lwp); 136 SCARG(&ap, departed) = (lwpid_t *)SCARG(uap, departed_lwp);
135 137
136 return sys__lwp_wait(l, &ap, retval); 138 return sys__lwp_wait(l, &ap, retval);
137} 139}
138 140
139int 141int
140svr4_sys__lwp_suspend(struct lwp *l, const struct svr4_sys__lwp_suspend_args *uap, register_t *retval) 142svr4_sys__lwp_suspend(struct lwp *l, const struct svr4_sys__lwp_suspend_args *uap, register_t *retval)
141{ 143{
142 struct sys__lwp_suspend_args ap; 144 struct sys__lwp_suspend_args ap;
143 145
144 SCARG(&ap, target) = SCARG(uap, lwpid); 146 SCARG(&ap, target) = SCARG(uap, lwpid);
145 147
146 return sys__lwp_suspend(l, &ap, retval); 148 return sys__lwp_suspend(l, &ap, retval);
147} 149}
148 150
149 151
150int 152int
151svr4_sys__lwp_continue(struct lwp *l, const struct svr4_sys__lwp_continue_args *uap, register_t *retval) 153svr4_sys__lwp_continue(struct lwp *l, const struct svr4_sys__lwp_continue_args *uap, register_t *retval)
152{ 154{
153 struct sys__lwp_continue_args ap; 155 struct sys__lwp_continue_args ap;
154 156
155 SCARG(&ap, target) = SCARG(uap, lwpid); 157 SCARG(&ap, target) = SCARG(uap, lwpid);
156 158
157 return sys__lwp_continue(l, &ap, retval); 159 return sys__lwp_continue(l, &ap, retval);
158} 160}
159 161
160int 162int
161svr4_sys__lwp_getprivate(struct lwp *l, const void *v, register_t *retval) 163svr4_sys__lwp_getprivate(struct lwp *l, const void *v, register_t *retval)
162{ 164{
163 /* XXX NJWLWP: Replace with call to native version if we ever 165 /* XXX NJWLWP: Replace with call to native version if we ever
164 * implement that. */ 166 * implement that. */
165 167
166 *retval = (register_t)l->l_private; 168 *retval = (register_t)l->l_private;
167 return 0; 169 return 0;
168} 170}
169 171
170int 172int
171svr4_sys__lwp_setprivate(struct lwp *l, const struct svr4_sys__lwp_setprivate_args *uap, register_t *retval) 173svr4_sys__lwp_setprivate(struct lwp *l, const struct svr4_sys__lwp_setprivate_args *uap, register_t *retval)
172{ 174{
173 175
174 /* XXX NJWLWP: Replace with call to native version if we ever 176 /* XXX NJWLWP: Replace with call to native version if we ever
175 * implement that. */ 177 * implement that. */
176 178
177 return copyin(SCARG(uap, buffer), &l->l_private, sizeof(void *)); 179 return copyin(SCARG(uap, buffer), &l->l_private, sizeof(void *));
178} 180}

cvs diff -r1.65 -r1.65.24.1 src/sys/compat/svr4/Attic/svr4_signal.c (switch to unified diff)

--- src/sys/compat/svr4/Attic/svr4_signal.c 2011/02/03 21:45:31 1.65
+++ src/sys/compat/svr4/Attic/svr4_signal.c 2017/08/19 03:40:48 1.65.24.1
@@ -1,487 +1,516 @@ @@ -1,487 +1,516 @@
1/* $NetBSD: svr4_signal.c,v 1.65 2011/02/03 21:45:31 joerg Exp $ */ 1/* $NetBSD: svr4_signal.c,v 1.65.24.1 2017/08/19 03:40:48 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994, 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas and by Charles M. Hannum. 8 * by Christos Zoulas and by Charles M. Hannum.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: svr4_signal.c,v 1.65 2011/02/03 21:45:31 joerg Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: svr4_signal.c,v 1.65.24.1 2017/08/19 03:40:48 snj Exp $");
34 34
35#include <sys/param.h> 35#include <sys/param.h>
36#include <sys/systm.h> 36#include <sys/systm.h>
37#include <sys/namei.h> 37#include <sys/namei.h>
38#include <sys/proc.h> 38#include <sys/proc.h>
39#include <sys/filedesc.h> 39#include <sys/filedesc.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/mount.h> 41#include <sys/mount.h>
42#include <sys/kernel.h> 42#include <sys/kernel.h>
43#include <sys/signal.h> 43#include <sys/signal.h>
44#include <sys/signalvar.h> 44#include <sys/signalvar.h>
45#include <sys/malloc.h> 45#include <sys/malloc.h>
46#include <sys/wait.h> 46#include <sys/wait.h>
47 47
48#include <sys/syscallargs.h> 48#include <sys/syscallargs.h>
49 49
50#include <uvm/uvm_extern.h> 50#include <uvm/uvm_extern.h>
51 51
52#include <compat/svr4/svr4_types.h> 52#include <compat/svr4/svr4_types.h>
53#include <compat/svr4/svr4_signal.h> 53#include <compat/svr4/svr4_signal.h>
54#include <compat/svr4/svr4_lwp.h> 54#include <compat/svr4/svr4_lwp.h>
55#include <compat/svr4/svr4_ucontext.h> 55#include <compat/svr4/svr4_ucontext.h>
56#include <compat/svr4/svr4_syscallargs.h> 56#include <compat/svr4/svr4_syscallargs.h>
57#include <compat/svr4/svr4_util.h> 57#include <compat/svr4/svr4_util.h>
58 58
59#include <compat/common/compat_sigaltstack.h> 59#include <compat/common/compat_sigaltstack.h>
60 60
61#define svr4_sigmask(n) (1 << (((n) - 1) & 31)) 61#define svr4_sigmask(n) (1 << (((n) - 1) & 31))
62#define svr4_sigword(n) (((n) - 1) >> 5) 62#define svr4_sigword(n) (((n) - 1) >> 5)
63#define svr4_sigemptyset(s) memset((s), 0, sizeof(*(s))) 63#define svr4_sigemptyset(s) memset((s), 0, sizeof(*(s)))
64#define svr4_sigismember(s, n) ((s)->bits[svr4_sigword(n)] & svr4_sigmask(n)) 64#define svr4_sigismember(s, n) ((s)->bits[svr4_sigword(n)] & svr4_sigmask(n))
65#define svr4_sigaddset(s, n) ((s)->bits[svr4_sigword(n)] |= svr4_sigmask(n)) 65#define svr4_sigaddset(s, n) ((s)->bits[svr4_sigword(n)] |= svr4_sigmask(n))
66 66
67static inline void svr4_sigfillset(svr4_sigset_t *); 67static inline void svr4_sigfillset(svr4_sigset_t *);
68void svr4_to_native_sigaction(const struct svr4_sigaction *, 68void svr4_to_native_sigaction(const struct svr4_sigaction *,
69 struct sigaction *); 69 struct sigaction *);
70void native_to_svr4_sigaction(const struct sigaction *, 70void native_to_svr4_sigaction(const struct sigaction *,
71 struct svr4_sigaction *); 71 struct svr4_sigaction *);
72 72
73extern const int native_to_svr4_signo[]; 73extern const int native_to_svr4_signo[];
74extern const int svr4_to_native_signo[]; 74extern const int svr4_to_native_signo[];
75 75
 76static int
 77svr4_decode_signum(int signum, int *native_signo, int *sigcall)
 78{
 79
 80 if (SVR4_SIGNO(signum) >= SVR4_NSIG)
 81 return EINVAL;
 82
 83 if (native_signo)
 84 *native_signo = svr4_to_native_signo[SVR4_SIGNO(signum)];
 85 if (sigcall)
 86 *sigcall = SVR4_SIGCALL(signum);
 87
 88 return 0;
 89}
 90
76static inline void 91static inline void
77svr4_sigfillset(svr4_sigset_t *s) 92svr4_sigfillset(svr4_sigset_t *s)
78{ 93{
79 int i; 94 int i;
80 95
81 svr4_sigemptyset(s); 96 svr4_sigemptyset(s);
82 for (i = 1; i < SVR4_NSIG; i++) 97 for (i = 1; i < SVR4_NSIG; i++)
83 if (svr4_to_native_signo[i] != 0) 98 if (svr4_to_native_signo[i] != 0)
84 svr4_sigaddset(s, i); 99 svr4_sigaddset(s, i);
85} 100}
86 101
87void 102void
88svr4_to_native_sigset(const svr4_sigset_t *sss, sigset_t *bss) 103svr4_to_native_sigset(const svr4_sigset_t *sss, sigset_t *bss)
89{ 104{
90 int i, newsig; 105 int i, newsig;
91 106
92 sigemptyset(bss); 107 sigemptyset(bss);
93 for (i = 1; i < SVR4_NSIG; i++) { 108 for (i = 1; i < SVR4_NSIG; i++) {
94 if (svr4_sigismember(sss, i)) { 109 if (svr4_sigismember(sss, i)) {
95 newsig = svr4_to_native_signo[i]; 110 newsig = svr4_to_native_signo[i];
96 if (newsig) 111 if (newsig)
97 sigaddset(bss, newsig); 112 sigaddset(bss, newsig);
98 } 113 }
99 } 114 }
100} 115}
101 116
102 117
103void 118void
104native_to_svr4_sigset(const sigset_t *bss, svr4_sigset_t *sss) 119native_to_svr4_sigset(const sigset_t *bss, svr4_sigset_t *sss)
105{ 120{
106 int i, newsig; 121 int i, newsig;
107 122
108 svr4_sigemptyset(sss); 123 svr4_sigemptyset(sss);
109 for (i = 1; i < NSIG; i++) { 124 for (i = 1; i < NSIG; i++) {
110 if (sigismember(bss, i)) { 125 if (sigismember(bss, i)) {
111 newsig = native_to_svr4_signo[i]; 126 newsig = native_to_svr4_signo[i];
112 if (newsig) 127 if (newsig)
113 svr4_sigaddset(sss, newsig); 128 svr4_sigaddset(sss, newsig);
114 } 129 }
115 } 130 }
116} 131}
117 132
118/* 133/*
119 * XXX: Only a subset of the flags is currently implemented. 134 * XXX: Only a subset of the flags is currently implemented.
120 */ 135 */
121void 136void
122svr4_to_native_sigaction(const struct svr4_sigaction *ssa, struct sigaction *bsa) 137svr4_to_native_sigaction(const struct svr4_sigaction *ssa, struct sigaction *bsa)
123{ 138{
124 139
125 bsa->sa_handler = (sig_t) ssa->svr4_sa_handler; 140 bsa->sa_handler = (sig_t) ssa->svr4_sa_handler;
126 svr4_to_native_sigset(&ssa->svr4_sa_mask, &bsa->sa_mask); 141 svr4_to_native_sigset(&ssa->svr4_sa_mask, &bsa->sa_mask);
127 bsa->sa_flags = 0; 142 bsa->sa_flags = 0;
128 if ((ssa->svr4_sa_flags & SVR4_SA_ONSTACK) != 0) 143 if ((ssa->svr4_sa_flags & SVR4_SA_ONSTACK) != 0)
129 bsa->sa_flags |= SA_ONSTACK; 144 bsa->sa_flags |= SA_ONSTACK;
130 if ((ssa->svr4_sa_flags & SVR4_SA_RESETHAND) != 0) 145 if ((ssa->svr4_sa_flags & SVR4_SA_RESETHAND) != 0)
131 bsa->sa_flags |= SA_RESETHAND; 146 bsa->sa_flags |= SA_RESETHAND;
132 if ((ssa->svr4_sa_flags & SVR4_SA_RESTART) != 0) 147 if ((ssa->svr4_sa_flags & SVR4_SA_RESTART) != 0)
133 bsa->sa_flags |= SA_RESTART; 148 bsa->sa_flags |= SA_RESTART;
134 if ((ssa->svr4_sa_flags & SVR4_SA_SIGINFO) != 0) 149 if ((ssa->svr4_sa_flags & SVR4_SA_SIGINFO) != 0)
135 bsa->sa_flags |= SA_SIGINFO; 150 bsa->sa_flags |= SA_SIGINFO;
136 if ((ssa->svr4_sa_flags & SVR4_SA_NODEFER) != 0) 151 if ((ssa->svr4_sa_flags & SVR4_SA_NODEFER) != 0)
137 bsa->sa_flags |= SA_NODEFER; 152 bsa->sa_flags |= SA_NODEFER;
138 if ((ssa->svr4_sa_flags & SVR4_SA_NOCLDWAIT) != 0) 153 if ((ssa->svr4_sa_flags & SVR4_SA_NOCLDWAIT) != 0)
139 bsa->sa_flags |= SA_NOCLDWAIT; 154 bsa->sa_flags |= SA_NOCLDWAIT;
140 if ((ssa->svr4_sa_flags & SVR4_SA_NOCLDSTOP) != 0) 155 if ((ssa->svr4_sa_flags & SVR4_SA_NOCLDSTOP) != 0)
141 bsa->sa_flags |= SA_NOCLDSTOP; 156 bsa->sa_flags |= SA_NOCLDSTOP;
142 if ((ssa->svr4_sa_flags & ~SVR4_SA_ALLBITS) != 0) { 157 if ((ssa->svr4_sa_flags & ~SVR4_SA_ALLBITS) != 0) {
143 DPRINTF(("svr4_to_native_sigaction: extra bits %x ignored\n", 158 DPRINTF(("svr4_to_native_sigaction: extra bits %x ignored\n",
144 ssa->svr4_sa_flags & ~SVR4_SA_ALLBITS)); 159 ssa->svr4_sa_flags & ~SVR4_SA_ALLBITS));
145 } 160 }
146} 161}
147 162
148void 163void
149native_to_svr4_sigaction(const struct sigaction *bsa, struct svr4_sigaction *ssa) 164native_to_svr4_sigaction(const struct sigaction *bsa, struct svr4_sigaction *ssa)
150{ 165{
151 166
152 ssa->svr4_sa_handler = (svr4_sig_t) bsa->sa_handler; 167 ssa->svr4_sa_handler = (svr4_sig_t) bsa->sa_handler;
153 native_to_svr4_sigset(&bsa->sa_mask, &ssa->svr4_sa_mask); 168 native_to_svr4_sigset(&bsa->sa_mask, &ssa->svr4_sa_mask);
154 ssa->svr4_sa_flags = 0; 169 ssa->svr4_sa_flags = 0;
155 if ((bsa->sa_flags & SA_ONSTACK) != 0) 170 if ((bsa->sa_flags & SA_ONSTACK) != 0)
156 ssa->svr4_sa_flags |= SVR4_SA_ONSTACK; 171 ssa->svr4_sa_flags |= SVR4_SA_ONSTACK;
157 if ((bsa->sa_flags & SA_RESETHAND) != 0) 172 if ((bsa->sa_flags & SA_RESETHAND) != 0)
158 ssa->svr4_sa_flags |= SVR4_SA_RESETHAND; 173 ssa->svr4_sa_flags |= SVR4_SA_RESETHAND;
159 if ((bsa->sa_flags & SA_RESTART) != 0) 174 if ((bsa->sa_flags & SA_RESTART) != 0)
160 ssa->svr4_sa_flags |= SVR4_SA_RESTART; 175 ssa->svr4_sa_flags |= SVR4_SA_RESTART;
161 if ((bsa->sa_flags & SA_NODEFER) != 0) 176 if ((bsa->sa_flags & SA_NODEFER) != 0)
162 ssa->svr4_sa_flags |= SVR4_SA_NODEFER; 177 ssa->svr4_sa_flags |= SVR4_SA_NODEFER;
163 if ((bsa->sa_flags & SA_NOCLDSTOP) != 0) 178 if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
164 ssa->svr4_sa_flags |= SVR4_SA_NOCLDSTOP; 179 ssa->svr4_sa_flags |= SVR4_SA_NOCLDSTOP;
165} 180}
166 181
167int 182int
168svr4_sys_sigaction(struct lwp *l, const struct svr4_sys_sigaction_args *uap, register_t *retval) 183svr4_sys_sigaction(struct lwp *l, const struct svr4_sys_sigaction_args *uap, register_t *retval)
169{ 184{
170 /* { 185 /* {
171 syscallarg(int) signum; 186 syscallarg(int) signum;
172 syscallarg(const struct svr4_sigaction *) nsa; 187 syscallarg(const struct svr4_sigaction *) nsa;
173 syscallarg(struct svr4_sigaction *) osa; 188 syscallarg(struct svr4_sigaction *) osa;
174 } */ 189 } */
175 struct svr4_sigaction nssa, ossa; 190 struct svr4_sigaction nssa, ossa;
176 struct sigaction nbsa, obsa; 191 struct sigaction nbsa, obsa;
 192 int native_signo;
177 int error; 193 int error;
178 194
179 if (SCARG(uap, nsa)) { 195 if (SCARG(uap, nsa)) {
180 error = copyin(SCARG(uap, nsa), &nssa, sizeof(nssa)); 196 error = copyin(SCARG(uap, nsa), &nssa, sizeof(nssa));
181 if (error) 197 if (error)
182 return (error); 198 return (error);
183 svr4_to_native_sigaction(&nssa, &nbsa); 199 svr4_to_native_sigaction(&nssa, &nbsa);
184 } 200 }
185 error = sigaction1(l, svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))], 201
 202 error = svr4_decode_signum(SCARG(uap, signum), &native_signo, NULL);
 203 if (error)
 204 return error;
 205
 206 error = sigaction1(l, native_signo,
186 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0, 207 SCARG(uap, nsa) ? &nbsa : 0, SCARG(uap, osa) ? &obsa : 0,
187 NULL, 0); 208 NULL, 0);
188 if (error) 209 if (error)
189 return (error); 210 return (error);
190 if (SCARG(uap, osa)) { 211 if (SCARG(uap, osa)) {
191 native_to_svr4_sigaction(&obsa, &ossa); 212 native_to_svr4_sigaction(&obsa, &ossa);
192 error = copyout(&ossa, SCARG(uap, osa), sizeof(ossa)); 213 error = copyout(&ossa, SCARG(uap, osa), sizeof(ossa));
193 if (error) 214 if (error)
194 return (error); 215 return (error);
195 } 216 }
196 return (0); 217 return (0);
197} 218}
198 219
199int 220int
200svr4_sys_sigaltstack(struct lwp *l, const struct svr4_sys_sigaltstack_args *uap, register_t *retval) 221svr4_sys_sigaltstack(struct lwp *l, const struct svr4_sys_sigaltstack_args *uap, register_t *retval)
201{ 222{
202 /* { 223 /* {
203 syscallarg(const struct svr4_sigaltstack *) nss; 224 syscallarg(const struct svr4_sigaltstack *) nss;
204 syscallarg(struct svr4_sigaltstack *) oss; 225 syscallarg(struct svr4_sigaltstack *) oss;
205 } */ 226 } */
206 compat_sigaltstack(uap, svr4_sigaltstack, 227 compat_sigaltstack(uap, svr4_sigaltstack,
207 SVR4_SS_ONSTACK, SVR4_SS_DISABLE); 228 SVR4_SS_ONSTACK, SVR4_SS_DISABLE);
208} 229}
209 230
210/* 231/*
211 * Stolen from the ibcs2 one 232 * Stolen from the ibcs2 one
212 */ 233 */
213int 234int
214svr4_sys_signal(struct lwp *l, const struct svr4_sys_signal_args *uap, register_t *retval) 235svr4_sys_signal(struct lwp *l, const struct svr4_sys_signal_args *uap, register_t *retval)
215{ 236{
216 /* { 237 /* {
217 syscallarg(int) signum; 238 syscallarg(int) signum;
218 syscallarg(svr4_sig_t) handler; 239 syscallarg(svr4_sig_t) handler;
219 } */ 240 } */
220 int signum = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))]; 241 int native_signo, sigcall;
221 struct proc *p = l->l_proc; 242 struct proc *p = l->l_proc;
222 struct sigaction nbsa, obsa; 243 struct sigaction nbsa, obsa;
223 sigset_t ss; 244 sigset_t ss;
224 int error; 245 int error;
225 246
226 if (signum <= 0 || signum >= SVR4_NSIG) 247 error = svr4_decode_signum(SCARG(uap, signum), &native_signo,
227 return (EINVAL); 248 &sigcall);
 249 if (error)
 250 return error;
228 251
229 switch (SVR4_SIGCALL(SCARG(uap, signum))) { 252 switch (sigcall) {
230 case SVR4_SIGDEFER_MASK: 253 case SVR4_SIGDEFER_MASK:
231 if (SCARG(uap, handler) == SVR4_SIG_HOLD) 254 if (SCARG(uap, handler) == SVR4_SIG_HOLD)
232 goto sighold; 255 goto sighold;
233 /* FALLTHROUGH */ 256 /* FALLTHROUGH */
234 257
235 case SVR4_SIGNAL_MASK: 258 case SVR4_SIGNAL_MASK:
236 nbsa.sa_handler = (sig_t)SCARG(uap, handler); 259 nbsa.sa_handler = (sig_t)SCARG(uap, handler);
237 sigemptyset(&nbsa.sa_mask); 260 sigemptyset(&nbsa.sa_mask);
238 nbsa.sa_flags = 0; 261 nbsa.sa_flags = 0;
239 error = sigaction1(l, signum, &nbsa, &obsa, NULL, 0); 262 error = sigaction1(l, native_signo, &nbsa, &obsa, NULL, 0);
240 if (error) 263 if (error)
241 return (error); 264 return (error);
242 *retval = (u_int)(u_long)obsa.sa_handler; 265 *retval = (u_int)(u_long)obsa.sa_handler;
243 return (0); 266 return (0);
244 267
245 case SVR4_SIGHOLD_MASK: 268 case SVR4_SIGHOLD_MASK:
246 sighold: 269 sighold:
247 sigemptyset(&ss); 270 sigemptyset(&ss);
248 sigaddset(&ss, signum); 271 sigaddset(&ss, native_signo);
249 mutex_enter(p->p_lock); 272 mutex_enter(p->p_lock);
250 error = sigprocmask1(l, SIG_BLOCK, &ss, 0); 273 error = sigprocmask1(l, SIG_BLOCK, &ss, 0);
251 mutex_exit(p->p_lock); 274 mutex_exit(p->p_lock);
252 return error; 275 return error;
253 276
254 case SVR4_SIGRELSE_MASK: 277 case SVR4_SIGRELSE_MASK:
255 sigemptyset(&ss); 278 sigemptyset(&ss);
256 sigaddset(&ss, signum); 279 sigaddset(&ss, native_signo);
257 mutex_enter(p->p_lock); 280 mutex_enter(p->p_lock);
258 error = sigprocmask1(l, SIG_UNBLOCK, &ss, 0); 281 error = sigprocmask1(l, SIG_UNBLOCK, &ss, 0);
259 mutex_exit(p->p_lock); 282 mutex_exit(p->p_lock);
260 return error; 283 return error;
261 284
262 case SVR4_SIGIGNORE_MASK: 285 case SVR4_SIGIGNORE_MASK:
263 nbsa.sa_handler = SIG_IGN; 286 nbsa.sa_handler = SIG_IGN;
264 sigemptyset(&nbsa.sa_mask); 287 sigemptyset(&nbsa.sa_mask);
265 nbsa.sa_flags = 0; 288 nbsa.sa_flags = 0;
266 return (sigaction1(l, signum, &nbsa, 0, NULL, 0)); 289 return (sigaction1(l, native_signo, &nbsa, 0, NULL, 0));
267 290
268 case SVR4_SIGPAUSE_MASK: 291 case SVR4_SIGPAUSE_MASK:
269 ss = l->l_sigmask; /* XXXAD locking */ 292 ss = l->l_sigmask; /* XXXAD locking */
270 sigdelset(&ss, signum); 293 sigdelset(&ss, native_signo);
271 return (sigsuspend1(l, &ss)); 294 return (sigsuspend1(l, &ss));
272 295
273 default: 296 default:
274 return (ENOSYS); 297 return (ENOSYS);
275 } 298 }
276} 299}
277 300
278int 301int
279svr4_sys_sigprocmask(struct lwp *l, const struct svr4_sys_sigprocmask_args *uap, register_t *retval) 302svr4_sys_sigprocmask(struct lwp *l, const struct svr4_sys_sigprocmask_args *uap, register_t *retval)
280{ 303{
281 /* { 304 /* {
282 syscallarg(int) how; 305 syscallarg(int) how;
283 syscallarg(const svr4_sigset_t *) set; 306 syscallarg(const svr4_sigset_t *) set;
284 syscallarg(svr4_sigset_t *) oset; 307 syscallarg(svr4_sigset_t *) oset;
285 } */ 308 } */
286 struct proc *p = l->l_proc; 309 struct proc *p = l->l_proc;
287 svr4_sigset_t nsss, osss; 310 svr4_sigset_t nsss, osss;
288 sigset_t nbss, obss; 311 sigset_t nbss, obss;
289 int how; 312 int how;
290 int error; 313 int error;
291 314
292 /* 315 /*
293 * Initialize how to 0 to avoid a compiler warning. Note that 316 * Initialize how to 0 to avoid a compiler warning. Note that
294 * this is safe because of the check in the default: case. 317 * this is safe because of the check in the default: case.
295 */ 318 */
296 how = 0; 319 how = 0;
297 320
298 switch (SCARG(uap, how)) { 321 switch (SCARG(uap, how)) {
299 case SVR4_SIG_BLOCK: 322 case SVR4_SIG_BLOCK:
300 how = SIG_BLOCK; 323 how = SIG_BLOCK;
301 break; 324 break;
302 case SVR4_SIG_UNBLOCK: 325 case SVR4_SIG_UNBLOCK:
303 how = SIG_UNBLOCK; 326 how = SIG_UNBLOCK;
304 break; 327 break;
305 case SVR4_SIG_SETMASK: 328 case SVR4_SIG_SETMASK:
306 how = SIG_SETMASK; 329 how = SIG_SETMASK;
307 break; 330 break;
308 default: 331 default:
309 if (SCARG(uap, set)) 332 if (SCARG(uap, set))
310 return EINVAL; 333 return EINVAL;
311 break; 334 break;
312 } 335 }
313 336
314 if (SCARG(uap, set)) { 337 if (SCARG(uap, set)) {
315 error = copyin(SCARG(uap, set), &nsss, sizeof(nsss)); 338 error = copyin(SCARG(uap, set), &nsss, sizeof(nsss));
316 if (error) 339 if (error)
317 return error; 340 return error;
318 svr4_to_native_sigset(&nsss, &nbss); 341 svr4_to_native_sigset(&nsss, &nbss);
319 } 342 }
320 mutex_enter(p->p_lock); 343 mutex_enter(p->p_lock);
321 error = sigprocmask1(l, how, 344 error = sigprocmask1(l, how,
322 SCARG(uap, set) ? &nbss : NULL, SCARG(uap, oset) ? &obss : NULL); 345 SCARG(uap, set) ? &nbss : NULL, SCARG(uap, oset) ? &obss : NULL);
323 mutex_exit(p->p_lock); 346 mutex_exit(p->p_lock);
324 if (error) 347 if (error)
325 return error; 348 return error;
326 if (SCARG(uap, oset)) { 349 if (SCARG(uap, oset)) {
327 native_to_svr4_sigset(&obss, &osss); 350 native_to_svr4_sigset(&obss, &osss);
328 error = copyout(&osss, SCARG(uap, oset), sizeof(osss)); 351 error = copyout(&osss, SCARG(uap, oset), sizeof(osss));
329 if (error) 352 if (error)
330 return error; 353 return error;
331 } 354 }
332 return 0; 355 return 0;
333} 356}
334 357
335int 358int
336svr4_sys_sigpending(struct lwp *l, const struct svr4_sys_sigpending_args *uap, register_t *retval) 359svr4_sys_sigpending(struct lwp *l, const struct svr4_sys_sigpending_args *uap, register_t *retval)
337{ 360{
338 /* { 361 /* {
339 syscallarg(int) what; 362 syscallarg(int) what;
340 syscallarg(svr4_sigset_t *) set; 363 syscallarg(svr4_sigset_t *) set;
341 } */ 364 } */
342 sigset_t bss; 365 sigset_t bss;
343 svr4_sigset_t sss; 366 svr4_sigset_t sss;
344 367
345 switch (SCARG(uap, what)) { 368 switch (SCARG(uap, what)) {
346 case 1: /* sigpending */ 369 case 1: /* sigpending */
347 sigpending1(l, &bss); 370 sigpending1(l, &bss);
348 native_to_svr4_sigset(&bss, &sss); 371 native_to_svr4_sigset(&bss, &sss);
349 break; 372 break;
350 373
351 case 2: /* sigfillset */ 374 case 2: /* sigfillset */
352 svr4_sigfillset(&sss); 375 svr4_sigfillset(&sss);
353 break; 376 break;
354 377
355 default: 378 default:
356 return (EINVAL); 379 return (EINVAL);
357 } 380 }
358 return (copyout(&sss, SCARG(uap, set), sizeof(sss))); 381 return (copyout(&sss, SCARG(uap, set), sizeof(sss)));
359} 382}
360 383
361int 384int
362svr4_sys_sigsuspend(struct lwp *l, const struct svr4_sys_sigsuspend_args *uap, register_t *retval) 385svr4_sys_sigsuspend(struct lwp *l, const struct svr4_sys_sigsuspend_args *uap, register_t *retval)
363{ 386{
364 /* { 387 /* {
365 syscallarg(const svr4_sigset_t *) set; 388 syscallarg(const svr4_sigset_t *) set;
366 } */ 389 } */
367 svr4_sigset_t sss; 390 svr4_sigset_t sss;
368 sigset_t bss; 391 sigset_t bss;
369 int error; 392 int error;
370 393
371 if (SCARG(uap, set)) { 394 if (SCARG(uap, set)) {
372 error = copyin(SCARG(uap, set), &sss, sizeof(sss)); 395 error = copyin(SCARG(uap, set), &sss, sizeof(sss));
373 if (error) 396 if (error)
374 return (error); 397 return (error);
375 svr4_to_native_sigset(&sss, &bss); 398 svr4_to_native_sigset(&sss, &bss);
376 } 399 }
377 400
378 return (sigsuspend1(l, SCARG(uap, set) ? &bss : 0)); 401 return (sigsuspend1(l, SCARG(uap, set) ? &bss : 0));
379} 402}
380 403
381int 404int
382svr4_sys_pause(struct lwp *l, const void *v, register_t *retval) 405svr4_sys_pause(struct lwp *l, const void *v, register_t *retval)
383{ 406{
384 407
385 return (sigsuspend1(l, 0)); 408 return (sigsuspend1(l, 0));
386} 409}
387 410
388int 411int
389svr4_sys_kill(struct lwp *l, const struct svr4_sys_kill_args *uap, register_t *retval) 412svr4_sys_kill(struct lwp *l, const struct svr4_sys_kill_args *uap, register_t *retval)
390{ 413{
391 /* { 414 /* {
392 syscallarg(int) pid; 415 syscallarg(int) pid;
393 syscallarg(int) signum; 416 syscallarg(int) signum;
394 } */ 417 } */
395 struct sys_kill_args ka; 418 struct sys_kill_args ka;
 419 int native_signo;
 420 int error;
 421
 422 error = svr4_decode_signum(SCARG(uap, signum), &native_signo, NULL);
 423 if (error)
 424 return error;
396 425
397 SCARG(&ka, pid) = SCARG(uap, pid); 426 SCARG(&ka, pid) = SCARG(uap, pid);
398 SCARG(&ka, signum) = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))]; 427 SCARG(&ka, signum) = native_signo;
399 return sys_kill(l, &ka, retval); 428 return sys_kill(l, &ka, retval);
400} 429}
401 430
402void 431void
403svr4_getcontext(struct lwp *l, struct svr4_ucontext *uc) 432svr4_getcontext(struct lwp *l, struct svr4_ucontext *uc)
404{ 433{
405 sigset_t mask; 434 sigset_t mask;
406 struct proc *p = l->l_proc; 435 struct proc *p = l->l_proc;
407 436
408 svr4_getmcontext(l, &uc->uc_mcontext, &uc->uc_flags); 437 svr4_getmcontext(l, &uc->uc_mcontext, &uc->uc_flags);
409 uc->uc_link = l->l_ctxlink; 438 uc->uc_link = l->l_ctxlink;
410 439
411 /* 440 /*
412 * The (unsupplied) definition of the `current execution stack' 441 * The (unsupplied) definition of the `current execution stack'
413 * in the System V Interface Definition appears to allow returning 442 * in the System V Interface Definition appears to allow returning
414 * the main context stack. 443 * the main context stack.
415 */ 444 */
416 if ((l->l_sigstk.ss_flags & SS_ONSTACK) == 0) { 445 if ((l->l_sigstk.ss_flags & SS_ONSTACK) == 0) {
417 uc->uc_stack.ss_sp = (void *)USRSTACK; 446 uc->uc_stack.ss_sp = (void *)USRSTACK;
418 uc->uc_stack.ss_size = ctob(p->p_vmspace->vm_ssize); 447 uc->uc_stack.ss_size = ctob(p->p_vmspace->vm_ssize);
419 uc->uc_stack.ss_flags = 0; /* XXX, def. is Very Fishy */ 448 uc->uc_stack.ss_flags = 0; /* XXX, def. is Very Fishy */
420 } else { 449 } else {
421 /* Simply copy alternate signal execution stack. */ 450 /* Simply copy alternate signal execution stack. */
422 uc->uc_stack.ss_sp = l->l_sigstk.ss_sp; 451 uc->uc_stack.ss_sp = l->l_sigstk.ss_sp;
423 uc->uc_stack.ss_size = l->l_sigstk.ss_size; 452 uc->uc_stack.ss_size = l->l_sigstk.ss_size;
424 uc->uc_stack.ss_flags = l->l_sigstk.ss_flags; 453 uc->uc_stack.ss_flags = l->l_sigstk.ss_flags;
425 } 454 }
426 (void)sigprocmask1(l, 0, NULL, &mask); 455 (void)sigprocmask1(l, 0, NULL, &mask);
427 456
428 native_to_svr4_sigset(&mask, &uc->uc_sigmask); 457 native_to_svr4_sigset(&mask, &uc->uc_sigmask);
429 uc->uc_flags |= _UC_SIGMASK | _UC_STACK; 458 uc->uc_flags |= _UC_SIGMASK | _UC_STACK;
430} 459}
431 460
432 461
433int 462int
434svr4_setcontext(struct lwp *l, struct svr4_ucontext *uc) 463svr4_setcontext(struct lwp *l, struct svr4_ucontext *uc)
435{ 464{
436 struct proc *p = l->l_proc; 465 struct proc *p = l->l_proc;
437 sigset_t mask; 466 sigset_t mask;
438 467
439 if (uc->uc_flags & _UC_SIGMASK) { 468 if (uc->uc_flags & _UC_SIGMASK) {
440 svr4_to_native_sigset(&uc->uc_sigmask, &mask); 469 svr4_to_native_sigset(&uc->uc_sigmask, &mask);
441 mutex_enter(p->p_lock); 470 mutex_enter(p->p_lock);
442 sigprocmask1(l, SIG_SETMASK, &mask, NULL); 471 sigprocmask1(l, SIG_SETMASK, &mask, NULL);
443 mutex_exit(p->p_lock); 472 mutex_exit(p->p_lock);
444 } 473 }
445 474
446 /* Ignore the stack; see comment in svr4_getcontext. */ 475 /* Ignore the stack; see comment in svr4_getcontext. */
447 476
448 l->l_ctxlink = uc->uc_link; 477 l->l_ctxlink = uc->uc_link;
449 svr4_setmcontext(l, &uc->uc_mcontext, uc->uc_flags); 478 svr4_setmcontext(l, &uc->uc_mcontext, uc->uc_flags);
450 479
451 return EJUSTRETURN; 480 return EJUSTRETURN;
452} 481}
453 482
454int 483int
455svr4_sys_context(struct lwp *l, const struct svr4_sys_context_args *uap, register_t *retval) 484svr4_sys_context(struct lwp *l, const struct svr4_sys_context_args *uap, register_t *retval)
456{ 485{
457 /* { 486 /* {
458 syscallarg(int) func; 487 syscallarg(int) func;
459 syscallarg(struct svr4_ucontext *) uc; 488 syscallarg(struct svr4_ucontext *) uc;
460 } */ 489 } */
461 int error; 490 int error;
462 svr4_ucontext_t uc; 491 svr4_ucontext_t uc;
463 *retval = 0; 492 *retval = 0;
464 493
465 memset(&uc, 0, sizeof(uc)); 494 memset(&uc, 0, sizeof(uc));
466 495
467 switch (SCARG(uap, func)) { 496 switch (SCARG(uap, func)) {
468 case SVR4_GETCONTEXT: 497 case SVR4_GETCONTEXT:
469 DPRINTF(("getcontext(%p)\n", SCARG(uap, uc))); 498 DPRINTF(("getcontext(%p)\n", SCARG(uap, uc)));
470 svr4_getcontext(l, &uc); 499 svr4_getcontext(l, &uc);
471 return (copyout(&uc, SCARG(uap, uc), sizeof (*SCARG(uap, uc)))); 500 return (copyout(&uc, SCARG(uap, uc), sizeof (*SCARG(uap, uc))));
472 501
473 502
474 case SVR4_SETCONTEXT: 503 case SVR4_SETCONTEXT:
475 DPRINTF(("setcontext(%p)\n", SCARG(uap, uc))); 504 DPRINTF(("setcontext(%p)\n", SCARG(uap, uc)));
476 error = copyin(SCARG(uap, uc), &uc, sizeof (uc)); 505 error = copyin(SCARG(uap, uc), &uc, sizeof (uc));
477 if (error) 506 if (error)
478 return (error); 507 return (error);
479 svr4_setcontext(l, &uc); 508 svr4_setcontext(l, &uc);
480 return EJUSTRETURN; 509 return EJUSTRETURN;
481 510
482 default: 511 default:
483 DPRINTF(("context(%d, %p)\n", SCARG(uap, func), 512 DPRINTF(("context(%d, %p)\n", SCARG(uap, func),
484 SCARG(uap, uc))); 513 SCARG(uap, uc)));
485 return ENOSYS; 514 return ENOSYS;
486 } 515 }
487} 516}

cvs diff -r1.79 -r1.79.22.1 src/sys/compat/svr4/Attic/svr4_stream.c (switch to unified diff)

--- src/sys/compat/svr4/Attic/svr4_stream.c 2011/06/26 16:42:41 1.79
+++ src/sys/compat/svr4/Attic/svr4_stream.c 2017/08/19 03:40:48 1.79.22.1
@@ -1,1851 +1,1892 @@ @@ -1,1851 +1,1892 @@
1/* $NetBSD: svr4_stream.c,v 1.79 2011/06/26 16:42:41 christos Exp $ */ 1/* $NetBSD: svr4_stream.c,v 1.79.22.1 2017/08/19 03:40:48 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994, 2008 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994, 2008 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas. 8 * by Christos Zoulas.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32/* 32/*
33 * Pretend that we have streams... 33 * Pretend that we have streams...
34 * Yes, this is gross. 34 * Yes, this is gross.
35 * 35 *
36 * ToDo: The state machine for getmsg needs re-thinking 36 * ToDo: The state machine for getmsg needs re-thinking
37 * 37 *
38 * The svr4_32 version is built from this file as well. 38 * The svr4_32 version is built from this file as well.
39 */ 39 */
40 40
41#include <sys/cdefs.h> 41#include <sys/cdefs.h>
42__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.79 2011/06/26 16:42:41 christos Exp $"); 42__KERNEL_RCSID(0, "$NetBSD: svr4_stream.c,v 1.79.22.1 2017/08/19 03:40:48 snj Exp $");
43 43
44#include <sys/param.h> 44#include <sys/param.h>
45#include <sys/kernel.h> 45#include <sys/kernel.h>
46#include <sys/systm.h> 46#include <sys/systm.h>
47#include <sys/buf.h> 47#include <sys/buf.h>
48#include <sys/malloc.h> 48#include <sys/malloc.h>
49#include <sys/ioctl.h> 49#include <sys/ioctl.h>
50#include <sys/tty.h> 50#include <sys/tty.h>
51#include <sys/file.h> 51#include <sys/file.h>
52#include <sys/filedesc.h> 52#include <sys/filedesc.h>
53#include <sys/namei.h> 53#include <sys/namei.h>
54#include <sys/select.h> 54#include <sys/select.h>
55#include <sys/socket.h> 55#include <sys/socket.h>
56#include <sys/socketvar.h> 56#include <sys/socketvar.h>
57#include <sys/protosw.h> 57#include <sys/protosw.h>
58#include <sys/un.h> 58#include <sys/un.h>
59#include <net/if.h> 59#include <net/if.h>
60#include <netinet/in.h> 60#include <netinet/in.h>
61#include <sys/mbuf.h> 61#include <sys/mbuf.h>
62#include <sys/mount.h> 62#include <sys/mount.h>
63#include <sys/proc.h> 63#include <sys/proc.h>
64#include <sys/vfs_syscalls.h> 64#include <sys/vfs_syscalls.h>
65#include <sys/vnode.h> 65#include <sys/vnode.h>
66#include <sys/device.h> 66#include <sys/device.h>
67#include <sys/stat.h> 67#include <sys/stat.h>
68 68
69#include <sys/syscallargs.h> 69#include <sys/syscallargs.h>
70 70
71#ifndef SVR4_32 71#ifndef SVR4_32
72#define compat(name) <compat/svr4/svr4_##name> 72#define compat(name) <compat/svr4/svr4_##name>
73#else 73#else
74#define compat(name) <compat/svr4_32/svr4_32_##name> 74#define compat(name) <compat/svr4_32/svr4_32_##name>
75#endif 75#endif
76 76
77#include compat(types.h) 77#include compat(types.h)
78#include compat(util.h) 78#include compat(util.h)
79#include compat(signal.h) 79#include compat(signal.h)
80#include compat(lwp.h) 80#include compat(lwp.h)
81#include compat(ucontext.h) 81#include compat(ucontext.h)
82#include compat(syscallargs.h) 82#include compat(syscallargs.h)
83#include compat(stropts.h) 83#include compat(stropts.h)
84#include compat(timod.h) 84#include compat(timod.h)
85#include <compat/svr4/svr4_sockmod.h> 85#include <compat/svr4/svr4_sockmod.h>
86#include compat(ioctl.h) 86#include compat(ioctl.h)
87#include compat(socket.h) 87#include compat(socket.h)
88 88
89#undef compat 89#undef compat
90 90
91#ifndef SVR4_32 91#ifndef SVR4_32
92 92
93#define SCARG_PTR(uap, arg) SCARG(uap, arg) 93#define SCARG_PTR(uap, arg) SCARG(uap, arg)
94#define NETBSD32PTR(ptr) (ptr) 94#define NETBSD32PTR(ptr) (ptr)
95 95
96#else 96#else
97 97
98#define SCARG_PTR(uap, arg) SCARG_P32(uap, arg) 98#define SCARG_PTR(uap, arg) SCARG_P32(uap, arg)
99#define NETBSD32PTR(ptr) NETBSD32PTR64(ptr) 99#define NETBSD32PTR(ptr) NETBSD32PTR64(ptr)
100 100
101/* Rename stuff that is different for the svr4_32 build */ 101/* Rename stuff that is different for the svr4_32 build */
102#define svr4_infocmd svr4_32_infocmd 102#define svr4_infocmd svr4_32_infocmd
103#define svr4_ino_t svr4_32_ino_t 103#define svr4_ino_t svr4_32_ino_t
104#define svr4_netaddr_in svr4_32_netaddr_in 104#define svr4_netaddr_in svr4_32_netaddr_in
105#define svr4_netaddr_un svr4_32_netaddr_un 105#define svr4_netaddr_un svr4_32_netaddr_un
106#define svr4_strbuf svr4_32_strbuf 106#define svr4_strbuf svr4_32_strbuf
107#define svr4_stream_get svr4_32_stream_get 107#define svr4_stream_get svr4_32_stream_get
108#define svr4_stream_ioctl svr4_32_stream_ioctl 108#define svr4_stream_ioctl svr4_32_stream_ioctl
109#define svr4_stream_ti_ioctl svr4_32_stream_ti_ioctl 109#define svr4_stream_ti_ioctl svr4_32_stream_ti_ioctl
110#define svr4_strfdinsert svr4_32_strfdinsert 110#define svr4_strfdinsert svr4_32_strfdinsert
111#define svr4_strioctl svr4_32_strioctl 111#define svr4_strioctl svr4_32_strioctl
112#define svr4_strmcmd svr4_32_strmcmd 112#define svr4_strmcmd svr4_32_strmcmd
113#define svr4_sys_getmsg svr4_32_sys_getmsg 113#define svr4_sys_getmsg svr4_32_sys_getmsg
114#define svr4_sys_getmsg_args svr4_32_sys_getmsg_args 114#define svr4_sys_getmsg_args svr4_32_sys_getmsg_args
115#define svr4_sys_putmsg svr4_32_sys_putmsg 115#define svr4_sys_putmsg svr4_32_sys_putmsg
116#define svr4_sys_putmsg_args svr4_32_sys_putmsg_args 116#define svr4_sys_putmsg_args svr4_32_sys_putmsg_args
117 117
118#endif /* SVR4_32 */ 118#endif /* SVR4_32 */
119 119
120/* Utils */ 120/* Utils */
121static int clean_pipe(struct lwp *, const char *); 121static int clean_pipe(struct lwp *, const char *);
122static void getparm(file_t *, struct svr4_si_sockparms *); 122static void getparm(file_t *, struct svr4_si_sockparms *);
123 123
124/* Address Conversions */ 124/* Address Conversions */
125static void sockaddr_to_netaddr_in(struct svr4_strmcmd *, 125static void sockaddr_to_netaddr_in(struct svr4_strmcmd *,
126 const struct sockaddr_in *); 126 const struct sockaddr_in *);
127static void sockaddr_to_netaddr_un(struct svr4_strmcmd *, 127static void sockaddr_to_netaddr_un(struct svr4_strmcmd *,
128 const struct sockaddr_un *); 128 const struct sockaddr_un *);
129static void netaddr_to_sockaddr_in(struct sockaddr_in *, 129static void netaddr_to_sockaddr_in(struct sockaddr_in *,
130 const struct svr4_strmcmd *); 130 const struct svr4_strmcmd *);
131static void netaddr_to_sockaddr_un(struct sockaddr_un *, 131static void netaddr_to_sockaddr_un(struct sockaddr_un *,
132 const struct svr4_strmcmd *); 132 const struct svr4_strmcmd *);
133 133
134/* stream ioctls */ 134/* stream ioctls */
135static int i_nread(file_t *, struct lwp *, register_t *, int, 135static int i_nread(file_t *, struct lwp *, register_t *, int,
136 u_long, void *); 136 u_long, void *);
137static int i_fdinsert(file_t *, struct lwp *, register_t *, int, 137static int i_fdinsert(file_t *, struct lwp *, register_t *, int,
138 u_long, void *); 138 u_long, void *);
139static int i_str(file_t *, struct lwp *, register_t *, int, 139static int i_str(file_t *, struct lwp *, register_t *, int,
140 u_long, void *); 140 u_long, void *);
141static int i_setsig(file_t *, struct lwp *, register_t *, int, 141static int i_setsig(file_t *, struct lwp *, register_t *, int,
142 u_long, void *); 142 u_long, void *);
143static int i_getsig(file_t *, struct lwp *, register_t *, int, 143static int i_getsig(file_t *, struct lwp *, register_t *, int,
144 u_long, void *); 144 u_long, void *);
145static int _i_bind_rsvd(file_t *, struct lwp *, register_t *, int, 145static int _i_bind_rsvd(file_t *, struct lwp *, register_t *, int,
146 u_long, void *); 146 u_long, void *);
147static int _i_rele_rsvd(file_t *, struct lwp *, register_t *, int, 147static int _i_rele_rsvd(file_t *, struct lwp *, register_t *, int,
148 u_long, void *); 148 u_long, void *);
149 149
150/* i_str sockmod calls */ 150/* i_str sockmod calls */
151static int sockmod(file_t *, int, struct svr4_strioctl *, 151static int sockmod(file_t *, int, struct svr4_strioctl *,
152 struct lwp *); 152 struct lwp *);
153static int si_listen(file_t *, int, struct svr4_strioctl *, 153static int si_listen(file_t *, int, struct svr4_strioctl *,
154 struct lwp *); 154 struct lwp *);
155static int si_ogetudata(file_t *, int, struct svr4_strioctl *, 155static int si_ogetudata(file_t *, int, struct svr4_strioctl *,
156 struct lwp *); 156 struct lwp *);
157static int si_sockparams(file_t *, int, struct svr4_strioctl *, 157static int si_sockparams(file_t *, int, struct svr4_strioctl *,
158 struct lwp *); 158 struct lwp *);
159static int si_shutdown(file_t *, int, struct svr4_strioctl *, 159static int si_shutdown(file_t *, int, struct svr4_strioctl *,
160 struct lwp *); 160 struct lwp *);
161static int si_getudata(file_t *, int, struct svr4_strioctl *, 161static int si_getudata(file_t *, int, struct svr4_strioctl *,
162 struct lwp *); 162 struct lwp *);
163 163
164/* i_str timod calls */ 164/* i_str timod calls */
165static int timod(file_t *, int, struct svr4_strioctl *, 165static int timod(file_t *, int, struct svr4_strioctl *,
166 struct lwp *); 166 struct lwp *);
167static int ti_getinfo(file_t *, int, struct svr4_strioctl *, 167static int ti_getinfo(file_t *, int, struct svr4_strioctl *,
168 struct lwp *); 168 struct lwp *);
169static int ti_bind(file_t *, int, struct svr4_strioctl *, 169static int ti_bind(file_t *, int, struct svr4_strioctl *,
170 struct lwp *); 170 struct lwp *);
171 171
172#ifdef DEBUG_SVR4 172#ifdef DEBUG_SVR4
173static void bufprint(u_char *, size_t); 173static void bufprint(u_char *, size_t);
174static int show_ioc(const char *, struct svr4_strioctl *); 174static int show_ioc(const char *, struct svr4_strioctl *);
175static int show_strbuf(struct svr4_strbuf *); 175static int show_strbuf(struct svr4_strbuf *);
176static void show_msg(const char *, int, struct svr4_strbuf *, 176static void show_msg(const char *, int, struct svr4_strbuf *,
177 struct svr4_strbuf *, int); 177 struct svr4_strbuf *, int);
178 178
179static void 179static void
180bufprint(u_char *buf, size_t len) 180bufprint(u_char *buf, size_t len)
181{ 181{
182 size_t i; 182 size_t i;
183 183
184 uprintf("\n\t"); 184 uprintf("\n\t");
185 for (i = 0; i < len; i++) { 185 for (i = 0; i < len; i++) {
186 uprintf("%x ", buf[i]); 186 uprintf("%x ", buf[i]);
187 if (i && (i % 16) == 0) 187 if (i && (i % 16) == 0)
188 uprintf("\n\t"); 188 uprintf("\n\t");
189 } 189 }
190} 190}
191 191
192static int 192static int
193show_ioc(const char *str, struct svr4_strioctl *ioc) 193show_ioc(const char *str, struct svr4_strioctl *ioc)
194{ 194{
195 u_char *ptr; 195 u_char *ptr;
196 int error, len; 196 int error, len;
197 197
198 len = ioc->len; 198 len = ioc->len;
199 if (len > 1024) 199 if (len > 1024)
200 len = 1024; 200 len = 1024;
201 201
202 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK); 202 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
203 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ", 203 uprintf("%s cmd = %ld, timeout = %d, len = %d, buf = %p { ",
204 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf); 204 str, ioc->cmd, ioc->timeout, ioc->len, ioc->buf);
205 205
206 if ((error = copyin(ioc->buf, ptr, len)) != 0) { 206 if ((error = copyin(ioc->buf, ptr, len)) != 0) {
207 free((char *) ptr, M_TEMP); 207 free((char *) ptr, M_TEMP);
208 return error; 208 return error;
209 } 209 }
210 210
211 bufprint(ptr, len); 211 bufprint(ptr, len);
212 212
213 uprintf("}\n"); 213 uprintf("}\n");
214 214
215 free((char *) ptr, M_TEMP); 215 free((char *) ptr, M_TEMP);
216 return 0; 216 return 0;
217} 217}
218 218
219 219
220static int 220static int
221show_strbuf(struct svr4_strbuf *str) 221show_strbuf(struct svr4_strbuf *str)
222{ 222{
223 int error; 223 int error;
224 u_char *ptr = NULL; 224 u_char *ptr = NULL;
225 int maxlen = str->maxlen; 225 int maxlen = str->maxlen;
226 int len = str->len; 226 int len = str->len;
227 227
228 if (maxlen > 8192) 228 if (maxlen > 8192)
229 maxlen = 8192; 229 maxlen = 8192;
230 230
231 if (maxlen < 0) 231 if (maxlen < 0)
232 maxlen = 0; 232 maxlen = 0;
233 233
234 if (len >= maxlen) 234 if (len >= maxlen)
235 len = maxlen; 235 len = maxlen;
236 236
237 if (len > 0) { 237 if (len > 0) {
238 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK); 238 ptr = (u_char *) malloc(len, M_TEMP, M_WAITOK);
239 239
240 if ((error = copyin(str->buf, ptr, len)) != 0) { 240 if ((error = copyin(str->buf, ptr, len)) != 0) {
241 free((char *) ptr, M_TEMP); 241 free((char *) ptr, M_TEMP);
242 return error; 242 return error;
243 } 243 }
244 } 244 }
245 245
246 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf); 246 uprintf(", { %d, %d, %p=[ ", str->maxlen, str->len, str->buf);
247 247
248 if (ptr) 248 if (ptr)
249 bufprint(ptr, len); 249 bufprint(ptr, len);
250 250
251 uprintf("]}"); 251 uprintf("]}");
252 252
253 if (ptr) 253 if (ptr)
254 free((char *) ptr, M_TEMP); 254 free((char *) ptr, M_TEMP);
255 255
256 return 0; 256 return 0;
257} 257}
258 258
259 259
260static void 260static void
261show_msg(const char *str, int fd, struct svr4_strbuf *ctl, struct svr4_strbuf *dat, int flags) 261show_msg(const char *str, int fd, struct svr4_strbuf *ctl, struct svr4_strbuf *dat, int flags)
262{ 262{
263 struct svr4_strbuf buf; 263 struct svr4_strbuf buf;
264 int error; 264 int error;
265 265
266 uprintf("%s(%d", str, fd); 266 uprintf("%s(%d", str, fd);
267 if (ctl != NULL) { 267 if (ctl != NULL) {
268 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0) 268 if ((error = copyin(ctl, &buf, sizeof(buf))) != 0)
269 return; 269 return;
270 show_strbuf(&buf); 270 show_strbuf(&buf);
271 } 271 }
272 else 272 else
273 uprintf(", NULL"); 273 uprintf(", NULL");
274 274
275 if (dat != NULL) { 275 if (dat != NULL) {
276 if ((error = copyin(dat, &buf, sizeof(buf))) != 0) 276 if ((error = copyin(dat, &buf, sizeof(buf))) != 0)
277 return; 277 return;
278 show_strbuf(&buf); 278 show_strbuf(&buf);
279 } 279 }
280 else 280 else
281 uprintf(", NULL"); 281 uprintf(", NULL");
282 282
283 uprintf(", %x);\n", flags); 283 uprintf(", %x);\n", flags);
284} 284}
285 285
286#endif /* DEBUG_SVR4 */ 286#endif /* DEBUG_SVR4 */
287 287
288 288
289/* 289/*
290 * We are faced with an interesting situation. On svr4 unix sockets 290 * We are faced with an interesting situation. On svr4 unix sockets
291 * are really pipes. But we really have sockets, and we might as 291 * are really pipes. But we really have sockets, and we might as
292 * well use them. At the point where svr4 calls TI_BIND, it has 292 * well use them. At the point where svr4 calls TI_BIND, it has
293 * already created a named pipe for the socket using mknod(2). 293 * already created a named pipe for the socket using mknod(2).
294 * We need to create a socket with the same name when we bind, 294 * We need to create a socket with the same name when we bind,
295 * so we need to remove the pipe before, otherwise we'll get address 295 * so we need to remove the pipe before, otherwise we'll get address
296 * already in use. So we *carefully* remove the pipe, to avoid 296 * already in use. So we *carefully* remove the pipe, to avoid
297 * using this as a random file removal tool. 297 * using this as a random file removal tool.
298 */ 298 */
299static int 299static int
300clean_pipe(struct lwp *l, const char *path) 300clean_pipe(struct lwp *l, const char *path)
301{ 301{
302 struct pathbuf *pb; 302 struct pathbuf *pb;
303 struct nameidata nd; 303 struct nameidata nd;
304 struct vattr va; 304 struct vattr va;
305 int error; 305 int error;
306 306
307 pb = pathbuf_create(path); 307 pb = pathbuf_create(path);
308 if (pb == NULL) { 308 if (pb == NULL) {
309 return ENOMEM; 309 return ENOMEM;
310 } 310 }
311 311
312 NDINIT(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF | TRYEMULROOT, pb); 312 NDINIT(&nd, DELETE, NOFOLLOW | LOCKPARENT | LOCKLEAF | TRYEMULROOT, pb);
313 error = namei(&nd); 313 error = namei(&nd);
314 if (error != 0) { 314 if (error != 0) {
315 pathbuf_destroy(pb); 315 pathbuf_destroy(pb);
316 return error; 316 return error;
317 } 317 }
318 318
319 /* 319 /*
320 * Make sure we are dealing with a mode 0 named pipe. 320 * Make sure we are dealing with a mode 0 named pipe.
321 */ 321 */
322 if (nd.ni_vp->v_type != VFIFO) 322 if (nd.ni_vp->v_type != VFIFO)
323 goto bad; 323 goto bad;
324 error = VOP_GETATTR(nd.ni_vp, &va, l->l_cred); 324 error = VOP_GETATTR(nd.ni_vp, &va, l->l_cred);
325 if (error != 0) 325 if (error != 0)
326 goto bad; 326 goto bad;
327 if ((va.va_mode & ALLPERMS) != 0) 327 if ((va.va_mode & ALLPERMS) != 0)
328 goto bad; 328 goto bad;
329 329
330 error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd); 330 error = VOP_REMOVE(nd.ni_dvp, nd.ni_vp, &nd.ni_cnd);
331 pathbuf_destroy(pb); 331 pathbuf_destroy(pb);
332 return error; 332 return error;
333 333
334 bad: 334 bad:
335 if (nd.ni_dvp == nd.ni_vp) 335 if (nd.ni_dvp == nd.ni_vp)
336 vrele(nd.ni_dvp); 336 vrele(nd.ni_dvp);
337 else 337 else
338 vput(nd.ni_dvp); 338 vput(nd.ni_dvp);
339 vput(nd.ni_vp); 339 vput(nd.ni_vp);
340 pathbuf_destroy(pb); 340 pathbuf_destroy(pb);
341 return error; 341 return error;
342} 342}
343 343
344 344
345static void 345static void
346sockaddr_to_netaddr_in(struct svr4_strmcmd *sc, const struct sockaddr_in *sain) 346sockaddr_to_netaddr_in(struct svr4_strmcmd *sc, const struct sockaddr_in *sain)
347{ 347{
348 struct svr4_netaddr_in *na; 348 struct svr4_netaddr_in *na;
349 na = SVR4_ADDROF(sc); 349 na = SVR4_ADDROF(sc);
350 350
351 na->family = sain->sin_family; 351 na->family = sain->sin_family;
352 na->port = sain->sin_port; 352 na->port = sain->sin_port;
353 na->addr = sain->sin_addr.s_addr; 353 na->addr = sain->sin_addr.s_addr;
354 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port, 354 DPRINTF(("sockaddr_in -> netaddr %d %d %lx\n", na->family, na->port,
355 na->addr)); 355 na->addr));
356} 356}
357 357
358 358
359static void 359static void
360sockaddr_to_netaddr_un(struct svr4_strmcmd *sc, const struct sockaddr_un *saun) 360sockaddr_to_netaddr_un(struct svr4_strmcmd *sc, const struct sockaddr_un *saun)
361{ 361{
362 struct svr4_netaddr_un *na; 362 struct svr4_netaddr_un *na;
363 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 - 363 char *dst, *edst = ((char *) sc) + sc->offs + sizeof(na->family) + 1 -
364 sizeof(*sc); 364 sizeof(*sc);
365 const char *src; 365 const char *src;
366 366
367 na = SVR4_ADDROF(sc); 367 na = SVR4_ADDROF(sc);
368 na->family = saun->sun_family; 368 na->family = saun->sun_family;
369 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; ) 369 for (src = saun->sun_path, dst = na->path; (*dst++ = *src++) != '\0'; )
370 if (dst == edst) 370 if (dst == edst)
371 break; 371 break;
372 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path)); 372 DPRINTF(("sockaddr_un -> netaddr %d %s\n", na->family, na->path));
373} 373}
374 374
375 375
376static void 376static void
377netaddr_to_sockaddr_in(struct sockaddr_in *sain, const struct svr4_strmcmd *sc) 377netaddr_to_sockaddr_in(struct sockaddr_in *sain, const struct svr4_strmcmd *sc)
378{ 378{
379 const struct svr4_netaddr_in *na; 379 const struct svr4_netaddr_in *na;
380 380
381 381
382 na = SVR4_C_ADDROF(sc); 382 na = SVR4_C_ADDROF(sc);
383 memset(sain, 0, sizeof(*sain)); 383 memset(sain, 0, sizeof(*sain));
384 sain->sin_len = sizeof(*sain); 384 sain->sin_len = sizeof(*sain);
385 sain->sin_family = na->family; 385 sain->sin_family = na->family;
386 sain->sin_port = na->port; 386 sain->sin_port = na->port;
387 sain->sin_addr.s_addr = na->addr; 387 sain->sin_addr.s_addr = na->addr;
388 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family, 388 DPRINTF(("netaddr -> sockaddr_in %d %d %x\n", sain->sin_family,
389 sain->sin_port, sain->sin_addr.s_addr)); 389 sain->sin_port, sain->sin_addr.s_addr));
390} 390}
391 391
392 392
393static void 393static void
394netaddr_to_sockaddr_un(struct sockaddr_un *saun, const struct svr4_strmcmd *sc) 394netaddr_to_sockaddr_un(struct sockaddr_un *saun, const struct svr4_strmcmd *sc)
395{ 395{
396 const struct svr4_netaddr_un *na; 396 const struct svr4_netaddr_un *na;
397 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1]; 397 char *dst, *edst = &saun->sun_path[sizeof(saun->sun_path) - 1];
398 const char *src; 398 const char *src;
399 399
400 na = SVR4_C_ADDROF(sc); 400 na = SVR4_C_ADDROF(sc);
401 memset(saun, 0, sizeof(*saun)); 401 memset(saun, 0, sizeof(*saun));
402 saun->sun_family = na->family; 402 saun->sun_family = na->family;
403 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; ) 403 for (src = na->path, dst = saun->sun_path; (*dst++ = *src++) != '\0'; )
404 if (dst == edst) 404 if (dst == edst)
405 break; 405 break;
406 saun->sun_len = dst - saun->sun_path; 406 saun->sun_len = dst - saun->sun_path;
407 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family, 407 DPRINTF(("netaddr -> sockaddr_un %d %s\n", saun->sun_family,
408 saun->sun_path)); 408 saun->sun_path));
409} 409}
410 410
411 411
412static void 412static void
413getparm(file_t *fp, struct svr4_si_sockparms *pa) 413getparm(file_t *fp, struct svr4_si_sockparms *pa)
414{ 414{
415 struct svr4_strm *st = svr4_stream_get(fp); 415 struct svr4_strm *st = svr4_stream_get(fp);
416 struct socket *so = (struct socket *) fp->f_data; 416 struct socket *so = (struct socket *) fp->f_data;
417 417
418 if (st == NULL) 418 if (st == NULL)
419 return; 419 return;
420 420
421 pa->family = st->s_family; 421 pa->family = st->s_family;
422 422
423 switch (so->so_type) { 423 switch (so->so_type) {
424 case SOCK_DGRAM: 424 case SOCK_DGRAM:
425 pa->type = SVR4_T_CLTS; 425 pa->type = SVR4_T_CLTS;
426 pa->protocol = IPPROTO_UDP; 426 pa->protocol = IPPROTO_UDP;
427 DPRINTF(("getparm(dgram)\n")); 427 DPRINTF(("getparm(dgram)\n"));
428 return; 428 return;
429 429
430 case SOCK_STREAM: 430 case SOCK_STREAM:
431 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */ 431 pa->type = SVR4_T_COTS; /* What about T_COTS_ORD? XXX */
432 pa->protocol = IPPROTO_IP; 432 pa->protocol = IPPROTO_IP;
433 DPRINTF(("getparm(stream)\n")); 433 DPRINTF(("getparm(stream)\n"));
434 return; 434 return;
435 435
436 case SOCK_RAW: 436 case SOCK_RAW:
437 pa->type = SVR4_T_CLTS; 437 pa->type = SVR4_T_CLTS;
438 pa->protocol = IPPROTO_RAW; 438 pa->protocol = IPPROTO_RAW;
439 DPRINTF(("getparm(raw)\n")); 439 DPRINTF(("getparm(raw)\n"));
440 return; 440 return;
441 441
442 default: 442 default:
443 pa->type = 0; 443 pa->type = 0;
444 pa->protocol = 0; 444 pa->protocol = 0;
445 DPRINTF(("getparm(type %d?)\n", so->so_type)); 445 DPRINTF(("getparm(type %d?)\n", so->so_type));
446 return; 446 return;
447 } 447 }
448} 448}
449 449
450 450
451static int 451static int
452si_ogetudata(file_t *fp, int fd, struct svr4_strioctl *ioc, 452si_ogetudata(file_t *fp, int fd, struct svr4_strioctl *ioc,
453 struct lwp *l) 453 struct lwp *l)
454{ 454{
455 int error; 455 int error;
456 struct svr4_si_oudata ud; 456 struct svr4_si_oudata ud;
457 struct svr4_si_sockparms pa; 457 struct svr4_si_sockparms pa;
458 (void)memset(&pa, 0, sizeof(pa)); /* XXX: GCC */ 458 (void)memset(&pa, 0, sizeof(pa)); /* XXX: GCC */
459 459
460 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) { 460 if (ioc->len != sizeof(ud) && ioc->len != sizeof(ud) - sizeof(int)) {
461 DPRINTF(("SI_OGETUDATA: Wrong size %ld != %d\n", 461 DPRINTF(("SI_OGETUDATA: Wrong size %ld != %d\n",
462 (unsigned long)sizeof(ud), ioc->len)); 462 (unsigned long)sizeof(ud), ioc->len));
463 return EINVAL; 463 return EINVAL;
464 } 464 }
465 465
466 if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0) 466 if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0)
467 return error; 467 return error;
468 468
469 getparm(fp, &pa); 469 getparm(fp, &pa);
470 470
471 switch (pa.family) { 471 switch (pa.family) {
472 case AF_INET: 472 case AF_INET:
473 ud.tidusize = 16384; 473 ud.tidusize = 16384;
474 ud.addrsize = sizeof(struct sockaddr_in); 474 ud.addrsize = sizeof(struct sockaddr_in);
475 if (pa.type == SVR4_SOCK_STREAM) 475 if (pa.type == SVR4_SOCK_STREAM)
476 ud.etsdusize = 1; 476 ud.etsdusize = 1;
477 else 477 else
478 ud.etsdusize = 0; 478 ud.etsdusize = 0;
479 break; 479 break;
480 480
481 case AF_LOCAL: 481 case AF_LOCAL:
482 ud.tidusize = 65536; 482 ud.tidusize = 65536;
483 ud.addrsize = 128; 483 ud.addrsize = 128;
484 ud.etsdusize = 128; 484 ud.etsdusize = 128;
485 break; 485 break;
486 486
487 default: 487 default:
488 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n", 488 DPRINTF(("SI_OGETUDATA: Unsupported address family %d\n",
489 pa.family)); 489 pa.family));
490 return ENOSYS; 490 return ENOSYS;
491 } 491 }
492 492
493 /* I have no idea what these should be! */ 493 /* I have no idea what these should be! */
494 ud.optsize = 128; 494 ud.optsize = 128;
495 ud.tsdusize = 128; 495 ud.tsdusize = 128;
496 496
497 ud.servtype = pa.type; 497 ud.servtype = pa.type;
498 498
499 /* XXX: Fixme */ 499 /* XXX: Fixme */
500 ud.so_state = 0; 500 ud.so_state = 0;
501 ud.so_options = 0; 501 ud.so_options = 0;
502 return copyout(&ud, NETBSD32PTR(ioc->buf), ioc->len); 502 return copyout(&ud, NETBSD32PTR(ioc->buf), ioc->len);
503} 503}
504 504
505 505
506static int 506static int
507si_sockparams(file_t *fp, int fd, struct svr4_strioctl *ioc, 507si_sockparams(file_t *fp, int fd, struct svr4_strioctl *ioc,
508 struct lwp *l) 508 struct lwp *l)
509{ 509{
510 struct svr4_si_sockparms pa; 510 struct svr4_si_sockparms pa;
511 511
512 getparm(fp, &pa); 512 getparm(fp, &pa);
513 return copyout(&pa, NETBSD32PTR(ioc->buf), sizeof(pa)); 513 return copyout(&pa, NETBSD32PTR(ioc->buf), sizeof(pa));
514} 514}
515 515
516 516
517static int 517static int
518si_listen(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) 518si_listen(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l)
519{ 519{
520 int error; 520 int error;
521 struct svr4_strm *st = svr4_stream_get(fp); 521 struct svr4_strm *st = svr4_stream_get(fp);
522 register_t retval; 522 register_t retval;
523 struct svr4_strmcmd lst; 523 struct svr4_strmcmd lst;
524 struct sys_listen_args la; 524 struct sys_listen_args la;
525 525
526 if (st == NULL) 526 if (st == NULL)
527 return EINVAL; 527 return EINVAL;
528 528
529 if (ioc->len > sizeof(lst)) 529 if (ioc->len < offsetof(struct svr4_strmcmd, pad) ||
 530 ioc->len > sizeof(lst))
530 return EINVAL; 531 return EINVAL;
531 532
532 if ((error = copyin(NETBSD32PTR(ioc->buf), &lst, ioc->len)) != 0) 533 if ((error = copyin(NETBSD32PTR(ioc->buf), &lst, ioc->len)) != 0)
533 return error; 534 return error;
 535 if (lst.offs < 0 ||
 536 lst.len < 0 ||
 537 lst.len > ioc->len ||
 538 ioc->len - lst.len < lst.offs)
 539 return EINVAL;
534 540
535 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) { 541 if (lst.cmd != SVR4_TI_OLD_BIND_REQUEST) {
536 DPRINTF(("si_listen: bad request %ld\n", lst.cmd)); 542 DPRINTF(("si_listen: bad request %ld\n", lst.cmd));
537 return EINVAL; 543 return EINVAL;
538 } 544 }
539 545
540 /* 546 /*
541 * We are making assumptions again... 547 * We are making assumptions again...
542 */ 548 */
543 SCARG(&la, s) = fd; 549 SCARG(&la, s) = fd;
544 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5)); 550 DPRINTF(("SI_LISTEN: fileno %d backlog = %d\n", fd, 5));
545 SCARG(&la, backlog) = 5; 551 SCARG(&la, backlog) = 5;
546 552
547 if ((error = sys_listen(l, &la, &retval)) != 0) { 553 if ((error = sys_listen(l, &la, &retval)) != 0) {
548 DPRINTF(("SI_LISTEN: listen failed %d\n", error)); 554 DPRINTF(("SI_LISTEN: listen failed %d\n", error));
549 return error; 555 return error;
550 } 556 }
551 557
552 st->s_cmd = SVR4_TI__ACCEPT_WAIT; 558 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
553 lst.cmd = SVR4_TI_BIND_REPLY; 559 lst.cmd = SVR4_TI_BIND_REPLY;
554 560
555 switch (st->s_family) { 561 switch (st->s_family) {
556 case AF_INET: 562 case AF_INET:
557 /* XXX: Fill the length here */ 563 /* XXX: Fill the length here */
558 break; 564 break;
559 565
560 case AF_LOCAL: 566 case AF_LOCAL:
561 lst.len = 140; 567 lst.len = 140;
562 lst.pad[28] = 0x00000000; /* magic again */ 568 lst.pad[28] = 0x00000000; /* magic again */
563 lst.pad[29] = 0x00000800; /* magic again */ 569 lst.pad[29] = 0x00000800; /* magic again */
564 lst.pad[30] = 0x80001400; /* magic again */ 570 lst.pad[30] = 0x80001400; /* magic again */
565 break; 571 break;
566 572
567 default: 573 default:
568 DPRINTF(("SI_LISTEN: Unsupported address family %d\n", 574 DPRINTF(("SI_LISTEN: Unsupported address family %d\n",
569 st->s_family)); 575 st->s_family));
570 return ENOSYS; 576 return ENOSYS;
571 } 577 }
572 578
573 579
574 if ((error = copyout(&lst, NETBSD32PTR(ioc->buf), ioc->len)) != 0) 580 if ((error = copyout(&lst, NETBSD32PTR(ioc->buf), ioc->len)) != 0)
575 return error; 581 return error;
576 582
577 return 0; 583 return 0;
578} 584}
579 585
580 586
581static int 587static int
582si_getudata(file_t *fp, int fd, struct svr4_strioctl *ioc, 588si_getudata(file_t *fp, int fd, struct svr4_strioctl *ioc,
583 struct lwp *l) 589 struct lwp *l)
584{ 590{
585 int error; 591 int error;
586 struct svr4_si_udata ud; 592 struct svr4_si_udata ud;
587 593
588 if (sizeof(ud) != ioc->len) { 594 if (sizeof(ud) != ioc->len) {
589 DPRINTF(("SI_GETUDATA: Wrong size %ld != %d\n", 595 DPRINTF(("SI_GETUDATA: Wrong size %ld != %d\n",
590 (unsigned long)sizeof(ud), ioc->len)); 596 (unsigned long)sizeof(ud), ioc->len));
591 return EINVAL; 597 return EINVAL;
592 } 598 }
593 599
594 if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0) 600 if ((error = copyin(NETBSD32PTR(ioc->buf), &ud, sizeof(ud))) != 0)
595 return error; 601 return error;
596 602
597 getparm(fp, &ud.sockparms); 603 getparm(fp, &ud.sockparms);
598 604
599 switch (ud.sockparms.family) { 605 switch (ud.sockparms.family) {
600 case AF_INET: 606 case AF_INET:
601 ud.tidusize = 16384; 607 ud.tidusize = 16384;
602 ud.tsdusize = 16384; 608 ud.tsdusize = 16384;
603 ud.addrsize = sizeof(struct sockaddr_in); 609 ud.addrsize = sizeof(struct sockaddr_in);
604 if (ud.sockparms.type == SVR4_SOCK_STREAM) 610 if (ud.sockparms.type == SVR4_SOCK_STREAM)
605 ud.etsdusize = 1; 611 ud.etsdusize = 1;
606 else 612 else
607 ud.etsdusize = 0; 613 ud.etsdusize = 0;
608 ud.optsize = 0; 614 ud.optsize = 0;
609 break; 615 break;
610 616
611 case AF_LOCAL: 617 case AF_LOCAL:
612 ud.tidusize = 65536; 618 ud.tidusize = 65536;
613 ud.tsdusize = 128; 619 ud.tsdusize = 128;
614 ud.addrsize = 128; 620 ud.addrsize = 128;
615 ud.etsdusize = 128; 621 ud.etsdusize = 128;
616 ud.optsize = 128; 622 ud.optsize = 128;
617 break; 623 break;
618 624
619 default: 625 default:
620 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n", 626 DPRINTF(("SI_GETUDATA: Unsupported address family %d\n",
621 ud.sockparms.family)); 627 ud.sockparms.family));
622 return ENOSYS; 628 return ENOSYS;
623 } 629 }
624 630
625 631
626 ud.servtype = ud.sockparms.type; 632 ud.servtype = ud.sockparms.type;
627 633
628 /* XXX: Fixme */ 634 /* XXX: Fixme */
629 ud.so_state = 0; 635 ud.so_state = 0;
630 ud.so_options = 0; 636 ud.so_options = 0;
631 return copyout(&ud, NETBSD32PTR(ioc->buf), sizeof(ud)); 637 return copyout(&ud, NETBSD32PTR(ioc->buf), sizeof(ud));
632} 638}
633 639
634 640
635static int 641static int
636si_shutdown(file_t *fp, int fd, struct svr4_strioctl *ioc, 642si_shutdown(file_t *fp, int fd, struct svr4_strioctl *ioc,
637 struct lwp *l) 643 struct lwp *l)
638{ 644{
639 int error; 645 int error;
640 struct sys_shutdown_args ap; 646 struct sys_shutdown_args ap;
641 register_t retval; 647 register_t retval;
642 648
643 if (ioc->len != sizeof(SCARG(&ap, how))) { 649 if (ioc->len != sizeof(SCARG(&ap, how))) {
644 DPRINTF(("SI_SHUTDOWN: Wrong size %ld != %d\n", 650 DPRINTF(("SI_SHUTDOWN: Wrong size %ld != %d\n",
645 (unsigned long)sizeof(SCARG(&ap, how)), ioc->len)); 651 (unsigned long)sizeof(SCARG(&ap, how)), ioc->len));
646 return EINVAL; 652 return EINVAL;
647 } 653 }
648 654
649 if ((error = copyin(NETBSD32PTR(ioc->buf), &SCARG(&ap, how), ioc->len)) != 0) 655 if ((error = copyin(NETBSD32PTR(ioc->buf), &SCARG(&ap, how), ioc->len)) != 0)
650 return error; 656 return error;
651 657
652 SCARG(&ap, s) = fd; 658 SCARG(&ap, s) = fd;
653 659
654 return sys_shutdown(l, &ap, &retval); 660 return sys_shutdown(l, &ap, &retval);
655} 661}
656 662
657 663
658static int 664static int
659sockmod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) 665sockmod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l)
660{ 666{
661 switch (ioc->cmd) { 667 switch (ioc->cmd) {
662 case SVR4_SI_OGETUDATA: 668 case SVR4_SI_OGETUDATA:
663 DPRINTF(("SI_OGETUDATA\n")); 669 DPRINTF(("SI_OGETUDATA\n"));
664 return si_ogetudata(fp, fd, ioc, l); 670 return si_ogetudata(fp, fd, ioc, l);
665 671
666 case SVR4_SI_SHUTDOWN: 672 case SVR4_SI_SHUTDOWN:
667 DPRINTF(("SI_SHUTDOWN\n")); 673 DPRINTF(("SI_SHUTDOWN\n"));
668 return si_shutdown(fp, fd, ioc, l); 674 return si_shutdown(fp, fd, ioc, l);
669 675
670 case SVR4_SI_LISTEN: 676 case SVR4_SI_LISTEN:
671 DPRINTF(("SI_LISTEN\n")); 677 DPRINTF(("SI_LISTEN\n"));
672 return si_listen(fp, fd, ioc, l); 678 return si_listen(fp, fd, ioc, l);
673 679
674 case SVR4_SI_SETMYNAME: 680 case SVR4_SI_SETMYNAME:
675 DPRINTF(("SI_SETMYNAME\n")); 681 DPRINTF(("SI_SETMYNAME\n"));
676 return 0; 682 return 0;
677 683
678 case SVR4_SI_SETPEERNAME: 684 case SVR4_SI_SETPEERNAME:
679 DPRINTF(("SI_SETPEERNAME\n")); 685 DPRINTF(("SI_SETPEERNAME\n"));
680 return 0; 686 return 0;
681 687
682 case SVR4_SI_GETINTRANSIT: 688 case SVR4_SI_GETINTRANSIT:
683 DPRINTF(("SI_GETINTRANSIT\n")); 689 DPRINTF(("SI_GETINTRANSIT\n"));
684 return 0; 690 return 0;
685 691
686 case SVR4_SI_TCL_LINK: 692 case SVR4_SI_TCL_LINK:
687 DPRINTF(("SI_TCL_LINK\n")); 693 DPRINTF(("SI_TCL_LINK\n"));
688 return 0; 694 return 0;
689 695
690 case SVR4_SI_TCL_UNLINK: 696 case SVR4_SI_TCL_UNLINK:
691 DPRINTF(("SI_TCL_UNLINK\n")); 697 DPRINTF(("SI_TCL_UNLINK\n"));
692 return 0; 698 return 0;
693 699
694 case SVR4_SI_SOCKPARAMS: 700 case SVR4_SI_SOCKPARAMS:
695 DPRINTF(("SI_SOCKPARAMS\n")); 701 DPRINTF(("SI_SOCKPARAMS\n"));
696 return si_sockparams(fp, fd, ioc, l); 702 return si_sockparams(fp, fd, ioc, l);
697 703
698 case SVR4_SI_GETUDATA: 704 case SVR4_SI_GETUDATA:
699 DPRINTF(("SI_GETUDATA\n")); 705 DPRINTF(("SI_GETUDATA\n"));
700 return si_getudata(fp, fd, ioc, l); 706 return si_getudata(fp, fd, ioc, l);
701 707
702 default: 708 default:
703 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd)); 709 DPRINTF(("Unknown sockmod ioctl %lx\n", ioc->cmd));
704 return 0; 710 return 0;
705 711
706 } 712 }
707} 713}
708 714
709 715
710static int 716static int
711ti_getinfo(file_t *fp, int fd, struct svr4_strioctl *ioc, 717ti_getinfo(file_t *fp, int fd, struct svr4_strioctl *ioc,
712 struct lwp *l) 718 struct lwp *l)
713{ 719{
714 int error; 720 int error;
715 struct svr4_infocmd info; 721 struct svr4_infocmd info;
716 722
717 memset(&info, 0, sizeof(info)); 723 memset(&info, 0, sizeof(info));
718 724
719 if (ioc->len > sizeof(info)) 725 /* tsdu is next after cmd, the only field we read */
 726 if (ioc->len < offsetof(struct svr4_infocmd, tsdu) ||
 727 ioc->len > sizeof(info))
720 return EINVAL; 728 return EINVAL;
721 729
722 if ((error = copyin(NETBSD32PTR(ioc->buf), &info, ioc->len)) != 0) 730 if ((error = copyin(NETBSD32PTR(ioc->buf), &info, ioc->len)) != 0)
723 return error; 731 return error;
724 732
725 if (info.cmd != SVR4_TI_INFO_REQUEST) 733 if (info.cmd != SVR4_TI_INFO_REQUEST)
726 return EINVAL; 734 return EINVAL;
727 735
728 info.cmd = SVR4_TI_INFO_REPLY; 736 info.cmd = SVR4_TI_INFO_REPLY;
729 info.tsdu = 0; 737 info.tsdu = 0;
730 info.etsdu = 1; 738 info.etsdu = 1;
731 info.cdata = -2; 739 info.cdata = -2;
732 info.ddata = -2; 740 info.ddata = -2;
733 info.addr = 16; 741 info.addr = 16;
734 info.opt = -1; 742 info.opt = -1;
735 info.tidu = 16384; 743 info.tidu = 16384;
736 info.serv = 2; 744 info.serv = 2;
737 info.current = 0; 745 info.current = 0;
738 info.provider = 2; 746 info.provider = 2;
739 747
740 ioc->len = sizeof(info); 748 ioc->len = sizeof(info);
741 if ((error = copyout(&info, NETBSD32PTR(ioc->buf), ioc->len)) != 0) 749 if ((error = copyout(&info, NETBSD32PTR(ioc->buf), ioc->len)) != 0)
742 return error; 750 return error;
743 751
744 return 0; 752 return 0;
745} 753}
746 754
747 755
748static int 756static int
749ti_bind(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) 757ti_bind(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l)
750{ 758{
751 int error; 759 int error;
752 struct svr4_strm *st = svr4_stream_get(fp); 760 struct svr4_strm *st = svr4_stream_get(fp);
753 struct sockaddr_in sain; 761 struct sockaddr_in sain;
754 struct sockaddr_un saun; 762 struct sockaddr_un saun;
755 void *skp, *sup = NULL; 763 void *skp, *sup = NULL;
756 int sasize; 764 int sasize;
757 struct svr4_strmcmd bnd; 765 struct svr4_strmcmd bnd;
758 struct mbuf *name; 766 struct mbuf *name;
759 767
760 if (st == NULL) { 768 if (st == NULL) {
761 DPRINTF(("ti_bind: bad file descriptor\n")); 769 DPRINTF(("ti_bind: bad file descriptor\n"));
762 return EINVAL; 770 return EINVAL;
763 } 771 }
764 772
765 if (ioc->len > sizeof(bnd)) 773 if (ioc->len < offsetof(struct svr4_strmcmd, pad) ||
 774 ioc->len > sizeof(bnd))
766 return EINVAL; 775 return EINVAL;
767 776
768 if ((error = copyin(NETBSD32PTR(ioc->buf), &bnd, ioc->len)) != 0) 777 if ((error = copyin(NETBSD32PTR(ioc->buf), &bnd, ioc->len)) != 0)
769 return error; 778 return error;
770 779
771 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) { 780 if (bnd.cmd != SVR4_TI_OLD_BIND_REQUEST) {
772 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd)); 781 DPRINTF(("ti_bind: bad request %ld\n", bnd.cmd));
773 return EINVAL; 782 return EINVAL;
774 } 783 }
 784 if (bnd.offs < 0 ||
 785 bnd.len < 0 ||
 786 bnd.len > ioc->len ||
 787 ioc->len - bnd.len < bnd.offs)
 788 return EINVAL;
775 789
776 switch (st->s_family) { 790 switch (st->s_family) {
777 case AF_INET: 791 case AF_INET:
778 skp = &sain; 792 skp = &sain;
779 sasize = sizeof(sain); 793 sasize = sizeof(sain);
780 794
781 if (bnd.offs == 0) 795 if (bnd.offs == 0)
782 goto reply; 796 goto reply;
783 797
 798 if (ioc->len < sizeof(struct svr4_netaddr_in) ||
 799 bnd.offs > ioc->len - sizeof(struct svr4_netaddr_in))
 800 return EINVAL;
784 netaddr_to_sockaddr_in(&sain, &bnd); 801 netaddr_to_sockaddr_in(&sain, &bnd);
785 802
786 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n", 803 DPRINTF(("TI_BIND: fam %d, port %d, addr %x\n",
787 sain.sin_family, sain.sin_port, 804 sain.sin_family, sain.sin_port,
788 sain.sin_addr.s_addr)); 805 sain.sin_addr.s_addr));
789 break; 806 break;
790 807
791 case AF_LOCAL: 808 case AF_LOCAL:
792 skp = &saun; 809 skp = &saun;
793 sasize = sizeof(saun); 810 sasize = sizeof(saun);
794 if (bnd.offs == 0) 811 if (bnd.offs == 0)
795 goto reply; 812 goto reply;
796 813
 814 if (ioc->len < sizeof(struct svr4_netaddr_un) ||
 815 bnd.offs > ioc->len - sizeof(struct svr4_netaddr_un))
 816 return EINVAL;
797 netaddr_to_sockaddr_un(&saun, &bnd); 817 netaddr_to_sockaddr_un(&saun, &bnd);
798 818
799 if (saun.sun_path[0] == '\0') 819 if (saun.sun_path[0] == '\0')
800 goto reply; 820 goto reply;
801 821
802 DPRINTF(("TI_BIND: fam %d, path %s\n", 822 DPRINTF(("TI_BIND: fam %d, path %s\n",
803 saun.sun_family, saun.sun_path)); 823 saun.sun_family, saun.sun_path));
804 824
805 if ((error = clean_pipe(l, saun.sun_path)) != 0) 825 if ((error = clean_pipe(l, saun.sun_path)) != 0)
806 return error; 826 return error;
807 827
808 bnd.pad[28] = 0x00001000; /* magic again */ 828 bnd.pad[28] = 0x00001000; /* magic again */
809 break; 829 break;
810 830
811 default: 831 default:
812 DPRINTF(("TI_BIND: Unsupported address family %d\n", 832 DPRINTF(("TI_BIND: Unsupported address family %d\n",
813 st->s_family)); 833 st->s_family));
814 return ENOSYS; 834 return ENOSYS;
815 } 835 }
816 836
817 name = m_get(M_WAIT, MT_SONAME); 837 name = m_get(M_WAIT, MT_SONAME);
818 if (sasize > MLEN) 838 if (sasize > MLEN)
819 MEXTMALLOC(name, sasize, M_WAITOK); 839 MEXTMALLOC(name, sasize, M_WAITOK);
820 840
821 memcpy(mtod(name, void *), skp, sasize); 841 memcpy(mtod(name, void *), skp, sasize);
822 842
823 DPRINTF(("TI_BIND: fileno %d\n", fd)); 843 DPRINTF(("TI_BIND: fileno %d\n", fd));
824 844
825 error = do_sys_bind(l, fd, name); 845 error = do_sys_bind(l, fd, name);
826 if (error != 0) { 846 if (error != 0) {
827 DPRINTF(("TI_BIND: bind failed %d\n", error)); 847 DPRINTF(("TI_BIND: bind failed %d\n", error));
828 return error; 848 return error;
829 } 849 }
830 850
831reply: 851reply:
832 if (sup == NULL) { 852 if (sup == NULL) {
833 memset(&bnd, 0, sizeof(bnd)); 853 memset(&bnd, 0, sizeof(bnd));
834 bnd.len = sasize + 4; 854 bnd.len = sasize + 4;
835 bnd.offs = 0x10; /* XXX */ 855 bnd.offs = 0x10; /* XXX */
836 } 856 }
837 857
838 bnd.cmd = SVR4_TI_BIND_REPLY; 858 bnd.cmd = SVR4_TI_BIND_REPLY;
839 859
840 if ((error = copyout(&bnd, NETBSD32PTR(ioc->buf), ioc->len)) != 0) 860 if ((error = copyout(&bnd, NETBSD32PTR(ioc->buf), ioc->len)) != 0)
841 return error; 861 return error;
842 862
843 return 0; 863 return 0;
844} 864}
845 865
846 866
847static int 867static int
848timod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l) 868timod(file_t *fp, int fd, struct svr4_strioctl *ioc, struct lwp *l)
849{ 869{
850 switch (ioc->cmd) { 870 switch (ioc->cmd) {
851 case SVR4_TI_GETINFO: 871 case SVR4_TI_GETINFO:
852 DPRINTF(("TI_GETINFO\n")); 872 DPRINTF(("TI_GETINFO\n"));
853 return ti_getinfo(fp, fd, ioc, l); 873 return ti_getinfo(fp, fd, ioc, l);
854 874
855 case SVR4_TI_OPTMGMT: 875 case SVR4_TI_OPTMGMT:
856 DPRINTF(("TI_OPTMGMT\n")); 876 DPRINTF(("TI_OPTMGMT\n"));
857 return 0; 877 return 0;
858 878
859 case SVR4_TI_BIND: 879 case SVR4_TI_BIND:
860 DPRINTF(("TI_BIND\n")); 880 DPRINTF(("TI_BIND\n"));
861 return ti_bind(fp, fd, ioc, l); 881 return ti_bind(fp, fd, ioc, l);
862 882
863 case SVR4_TI_UNBIND: 883 case SVR4_TI_UNBIND:
864 DPRINTF(("TI_UNBIND\n")); 884 DPRINTF(("TI_UNBIND\n"));
865 return 0; 885 return 0;
866 886
867 default: 887 default:
868 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd)); 888 DPRINTF(("Unknown timod ioctl %lx\n", ioc->cmd));
869 return 0; 889 return 0;
870 } 890 }
871} 891}
872 892
873 893
874int 894int
875svr4_stream_ti_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat) 895svr4_stream_ti_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat)
876{ 896{
877 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat; 897 struct svr4_strbuf skb, *sub = (struct svr4_strbuf *) dat;
878 struct svr4_strm *st = svr4_stream_get(fp); 898 struct svr4_strm *st = svr4_stream_get(fp);
879 int error; 899 int error;
880 struct svr4_strmcmd sc; 900 struct svr4_strmcmd sc;
881 struct mbuf *name; 901 struct mbuf *name;
882 902
883 if (st == NULL) 903 if (st == NULL)
884 return EINVAL; 904 return EINVAL;
885 905
886 sc.offs = 0x10; 906 sc.offs = 0x10;
887 907
888 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) { 908 if ((error = copyin(sub, &skb, sizeof(skb))) != 0) {
889 DPRINTF(("ti_ioctl: error copying in strbuf\n")); 909 DPRINTF(("ti_ioctl: error copying in strbuf\n"));
890 return error; 910 return error;
891 } 911 }
892 912
893 switch (cmd) { 913 switch (cmd) {
894 case SVR4_TI_GETMYNAME: 914 case SVR4_TI_GETMYNAME:
895 DPRINTF(("TI_GETMYNAME\n")); 915 DPRINTF(("TI_GETMYNAME\n"));
896 cmd = PRU_SOCKADDR; 916 cmd = PRU_SOCKADDR;
897 break; 917 break;
898 918
899 case SVR4_TI_GETPEERNAME: 919 case SVR4_TI_GETPEERNAME:
900 DPRINTF(("TI_GETPEERNAME\n")); 920 DPRINTF(("TI_GETPEERNAME\n"));
901 cmd = PRU_PEERADDR; 921 cmd = PRU_PEERADDR;
902 break; 922 break;
903 923
904 case SVR4_TI_SETMYNAME: 924 case SVR4_TI_SETMYNAME:
905 DPRINTF(("TI_SETMYNAME\n")); 925 DPRINTF(("TI_SETMYNAME\n"));
906 return 0; 926 return 0;
907 927
908 case SVR4_TI_SETPEERNAME: 928 case SVR4_TI_SETPEERNAME:
909 DPRINTF(("TI_SETPEERNAME\n")); 929 DPRINTF(("TI_SETPEERNAME\n"));
910 return 0; 930 return 0;
911 default: 931 default:
912 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd)); 932 DPRINTF(("ti_ioctl: Unknown ioctl %lx\n", cmd));
913 return ENOSYS; 933 return ENOSYS;
914 } 934 }
915 935
916 error = do_sys_getsockname(l, fd, cmd, &name); 936 error = do_sys_getsockname(l, fd, cmd, &name);
917 if (error != 0) 937 if (error != 0)
918 return error; 938 return error;
919 939
920 switch (st->s_family) { 940 switch (st->s_family) {
921 case AF_INET: 941 case AF_INET:
922 sockaddr_to_netaddr_in(&sc, mtod(name, void *)); 942 sockaddr_to_netaddr_in(&sc, mtod(name, void *));
923 skb.len = sizeof (struct sockaddr_in); 943 skb.len = sizeof (struct sockaddr_in);
924 break; 944 break;
925 945
926 case AF_LOCAL: 946 case AF_LOCAL:
927 sockaddr_to_netaddr_un(&sc, mtod(name, void *)); 947 sockaddr_to_netaddr_un(&sc, mtod(name, void *));
928 /* XXX: the length gets adjusted but the copyout doesn't */ 948 /* XXX: the length gets adjusted but the copyout doesn't */
929 skb.len = sizeof (struct sockaddr_un) + 4; 949 skb.len = sizeof (struct sockaddr_un) + 4;
930 break; 950 break;
931 951
932 default: 952 default:
933 DPRINTF(("ti_ioctl: Unsupported address family %d\n", 953 DPRINTF(("ti_ioctl: Unsupported address family %d\n",
934 st->s_family)); 954 st->s_family));
935 m_free(name); 955 m_free(name);
936 return ENOSYS; 956 return ENOSYS;
937 } 957 }
938 958
939 error = copyout(SVR4_ADDROF(&sc), NETBSD32PTR(skb.buf), name->m_len); 959 error = copyout(SVR4_ADDROF(&sc), NETBSD32PTR(skb.buf), name->m_len);
940 m_free(name); 960 m_free(name);
941 if (error != 0) { 961 if (error != 0) {
942 DPRINTF(("ti_ioctl: error copying out socket data\n")); 962 DPRINTF(("ti_ioctl: error copying out socket data\n"));
943 return error; 963 return error;
944 } 964 }
945 965
946 966
947 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) { 967 if ((error = copyout(&skb, sub, sizeof(skb))) != 0) {
948 DPRINTF(("ti_ioctl: error copying out strbuf\n")); 968 DPRINTF(("ti_ioctl: error copying out strbuf\n"));
949 return error; 969 return error;
950 } 970 }
951 971
952 return error; 972 return error;
953} 973}
954 974
955 975
956 976
957 977
958static int 978static int
959i_nread(file_t *fp, struct lwp *l, register_t *retval, int fd, 979i_nread(file_t *fp, struct lwp *l, register_t *retval, int fd,
960 u_long cmd, void *dat) 980 u_long cmd, void *dat)
961{ 981{
962 int error; 982 int error;
963 int nread = 0; 983 int nread = 0;
964 984
965 /* 985 /*
966 * We are supposed to return the message length in nread, and the 986 * We are supposed to return the message length in nread, and the
967 * number of messages in retval. We don't have the notion of number 987 * number of messages in retval. We don't have the notion of number
968 * of stream messages, so we just find out if we have any bytes waiting 988 * of stream messages, so we just find out if we have any bytes waiting
969 * for us, and if we do, then we assume that we have at least one 989 * for us, and if we do, then we assume that we have at least one
970 * message waiting for us. 990 * message waiting for us.
971 */ 991 */
972 if ((error = (*fp->f_ops->fo_ioctl)(fp, FIONREAD, &nread)) != 0) 992 if ((error = (*fp->f_ops->fo_ioctl)(fp, FIONREAD, &nread)) != 0)
973 return error; 993 return error;
974 994
975 if (nread != 0) 995 if (nread != 0)
976 *retval = 1; 996 *retval = 1;
977 else 997 else
978 *retval = 0; 998 *retval = 0;
979 999
980 return copyout(&nread, dat, sizeof(nread)); 1000 return copyout(&nread, dat, sizeof(nread));
981} 1001}
982 1002
983static int 1003static int
984i_fdinsert(file_t *fp, struct lwp *l, register_t *retval, int fd, 1004i_fdinsert(file_t *fp, struct lwp *l, register_t *retval, int fd,
985 u_long cmd, void *dat) 1005 u_long cmd, void *dat)
986{ 1006{
987 /* 1007 /*
988 * Major hack again here. We assume that we are using this to 1008 * Major hack again here. We assume that we are using this to
989 * implement accept(2). If that is the case, we have already 1009 * implement accept(2). If that is the case, we have already
990 * called accept, and we have stored the file descriptor in 1010 * called accept, and we have stored the file descriptor in
991 * afd. We find the file descriptor that the code wants to use 1011 * afd. We find the file descriptor that the code wants to use
992 * in fd insert, and then we dup2() our accepted file descriptor 1012 * in fd insert, and then we dup2() our accepted file descriptor
993 * to it. 1013 * to it.
994 */ 1014 */
995 int error; 1015 int error;
996 struct svr4_strm *st = svr4_stream_get(fp); 1016 struct svr4_strm *st = svr4_stream_get(fp);
997 struct svr4_strfdinsert fdi; 1017 struct svr4_strfdinsert fdi;
998 struct sys_dup2_args d2p; 1018 struct sys_dup2_args d2p;
999 struct sys_close_args clp; 1019 struct sys_close_args clp;
1000 1020
1001 if (st == NULL) { 1021 if (st == NULL) {
1002 DPRINTF(("fdinsert: bad file type\n")); 1022 DPRINTF(("fdinsert: bad file type\n"));
1003 return EINVAL; 1023 return EINVAL;
1004 } 1024 }
1005 1025
1006 if (st->s_afd == -1) { 1026 if (st->s_afd == -1) {
1007 DPRINTF(("fdinsert: accept fd not found\n")); 1027 DPRINTF(("fdinsert: accept fd not found\n"));
1008 return ENOENT; 1028 return ENOENT;
1009 } 1029 }
1010 1030
1011 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) { 1031 if ((error = copyin(dat, &fdi, sizeof(fdi))) != 0) {
1012 DPRINTF(("fdinsert: copyin failed %d\n", error)); 1032 DPRINTF(("fdinsert: copyin failed %d\n", error));
1013 return error; 1033 return error;
1014 } 1034 }
1015 1035
1016 SCARG(&d2p, from) = st->s_afd; 1036 SCARG(&d2p, from) = st->s_afd;
1017 SCARG(&d2p, to) = fdi.fd; 1037 SCARG(&d2p, to) = fdi.fd;
1018 1038
1019 if ((error = sys_dup2(l, &d2p, retval)) != 0) { 1039 if ((error = sys_dup2(l, &d2p, retval)) != 0) {
1020 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n", 1040 DPRINTF(("fdinsert: dup2(%d, %d) failed %d\n",
1021 st->s_afd, fdi.fd, error)); 1041 st->s_afd, fdi.fd, error));
1022 return error; 1042 return error;
1023 } 1043 }
1024 1044
1025 SCARG(&clp, fd) = st->s_afd; 1045 SCARG(&clp, fd) = st->s_afd;
1026 1046
1027 if ((error = sys_close(l, &clp, retval)) != 0) { 1047 if ((error = sys_close(l, &clp, retval)) != 0) {
1028 DPRINTF(("fdinsert: close(%d) failed %d\n", 1048 DPRINTF(("fdinsert: close(%d) failed %d\n",
1029 st->s_afd, error)); 1049 st->s_afd, error));
1030 return error; 1050 return error;
1031 } 1051 }
1032 1052
1033 st->s_afd = -1; 1053 st->s_afd = -1;
1034 1054
1035 *retval = 0; 1055 *retval = 0;
1036 return 0; 1056 return 0;
1037} 1057}
1038 1058
1039 1059
1040static int 1060static int
1041_i_bind_rsvd(file_t *fp, struct lwp *l, register_t *retval, 1061_i_bind_rsvd(file_t *fp, struct lwp *l, register_t *retval,
1042 int fd, u_long cmd, void *dat) 1062 int fd, u_long cmd, void *dat)
1043{ 1063{
1044 struct sys_mkfifo_args ap; 1064 struct sys_mkfifo_args ap;
1045 1065
1046 /* 1066 /*
1047 * This is a supposed to be a kernel and library only ioctl. 1067 * This is a supposed to be a kernel and library only ioctl.
1048 * It gets called before ti_bind, when we have a unix 1068 * It gets called before ti_bind, when we have a unix
1049 * socket, to physically create the socket transport and 1069 * socket, to physically create the socket transport and
1050 * ``reserve'' it. I don't know how this get reserved inside 1070 * ``reserve'' it. I don't know how this get reserved inside
1051 * the kernel, but we are going to create it nevertheless. 1071 * the kernel, but we are going to create it nevertheless.
1052 */ 1072 */
1053 SCARG(&ap, path) = dat; 1073 SCARG(&ap, path) = dat;
1054 SCARG(&ap, mode) = S_IFIFO; 1074 SCARG(&ap, mode) = S_IFIFO;
1055 1075
1056 return sys_mkfifo(l, &ap, retval); 1076 return sys_mkfifo(l, &ap, retval);
1057} 1077}
1058 1078
1059static int 1079static int
1060_i_rele_rsvd(file_t *fp, struct lwp *l, register_t *retval, 1080_i_rele_rsvd(file_t *fp, struct lwp *l, register_t *retval,
1061 int fd, u_long cmd, void *dat) 1081 int fd, u_long cmd, void *dat)
1062{ 1082{
1063 struct sys_unlink_args ap; 1083 struct sys_unlink_args ap;
1064 1084
1065 /* 1085 /*
1066 * This is a supposed to be a kernel and library only ioctl. 1086 * This is a supposed to be a kernel and library only ioctl.
1067 * I guess it is supposed to release the socket. 1087 * I guess it is supposed to release the socket.
1068 */ 1088 */
1069 SCARG(&ap, path) = dat; 1089 SCARG(&ap, path) = dat;
1070 1090
1071 return sys_unlink(l, &ap, retval); 1091 return sys_unlink(l, &ap, retval);
1072} 1092}
1073 1093
1074static int 1094static int
1075i_str(file_t *fp, struct lwp *l, register_t *retval, int fd, 1095i_str(file_t *fp, struct lwp *l, register_t *retval, int fd,
1076 u_long cmd, void *dat) 1096 u_long cmd, void *dat)
1077{ 1097{
1078 int error; 1098 int error;
1079 struct svr4_strioctl ioc; 1099 struct svr4_strioctl ioc;
1080 1100
1081 /* 1101 /*
1082 * Noop on non sockets 1102 * Noop on non sockets
1083 */ 1103 */
1084 if (fp->f_type != DTYPE_SOCKET) 1104 if (fp->f_type != DTYPE_SOCKET)
1085 return 0; 1105 return 0;
1086 1106
1087 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0) 1107 if ((error = copyin(dat, &ioc, sizeof(ioc))) != 0)
1088 return error; 1108 return error;
1089 1109
1090#ifdef DEBUG_SVR4 1110#ifdef DEBUG_SVR4
1091 if ((error = show_ioc(">", &ioc)) != 0) 1111 if ((error = show_ioc(">", &ioc)) != 0)
1092 return error; 1112 return error;
1093#endif /* DEBUG_SVR4 */ 1113#endif /* DEBUG_SVR4 */
1094 1114
1095 switch (ioc.cmd & 0xff00) { 1115 switch (ioc.cmd & 0xff00) {
1096 case SVR4_SIMOD: 1116 case SVR4_SIMOD:
1097 if ((error = sockmod(fp, fd, &ioc, l)) != 0) 1117 if ((error = sockmod(fp, fd, &ioc, l)) != 0)
1098 return error; 1118 return error;
1099 break; 1119 break;
1100 1120
1101 case SVR4_TIMOD: 1121 case SVR4_TIMOD:
1102 if ((error = timod(fp, fd, &ioc, l)) != 0) 1122 if ((error = timod(fp, fd, &ioc, l)) != 0)
1103 return error; 1123 return error;
1104 break; 1124 break;
1105 1125
1106 default: 1126 default:
1107 DPRINTF(("Unimplemented module %c %ld\n", 1127 DPRINTF(("Unimplemented module %c %ld\n",
1108 (char) (cmd >> 8), cmd & 0xff)); 1128 (char) (cmd >> 8), cmd & 0xff));
1109 return 0; 1129 return 0;
1110 } 1130 }
1111 1131
1112#ifdef DEBUG_SVR4 1132#ifdef DEBUG_SVR4
1113 if ((error = show_ioc("<", &ioc)) != 0) 1133 if ((error = show_ioc("<", &ioc)) != 0)
1114 return error; 1134 return error;
1115#endif /* DEBUG_SVR4 */ 1135#endif /* DEBUG_SVR4 */
1116 return copyout(&ioc, dat, sizeof(ioc)); 1136 return copyout(&ioc, dat, sizeof(ioc));
1117} 1137}
1118 1138
1119static int 1139static int
1120i_setsig(file_t *fp, struct lwp *l, register_t *retval, int fd, 1140i_setsig(file_t *fp, struct lwp *l, register_t *retval, int fd,
1121 u_long cmd, void *dat) 1141 u_long cmd, void *dat)
1122{ 1142{
1123 /* 1143 /*
1124 * This is the best we can do for now; we cannot generate 1144 * This is the best we can do for now; we cannot generate
1125 * signals only for specific events so the signal mask gets 1145 * signals only for specific events so the signal mask gets
1126 * ignored; we save it just to pass it to a possible I_GETSIG... 1146 * ignored; we save it just to pass it to a possible I_GETSIG...
1127 * 1147 *
1128 * We alse have to fix the O_ASYNC fcntl bit, so the 1148 * We alse have to fix the O_ASYNC fcntl bit, so the
1129 * process will get SIGPOLLs. 1149 * process will get SIGPOLLs.
1130 */ 1150 */
1131 struct sys_fcntl_args fa; 1151 struct sys_fcntl_args fa;
1132 int error; 1152 int error;
1133 register_t oflags, flags; 1153 register_t oflags, flags;
1134 struct svr4_strm *st = svr4_stream_get(fp); 1154 struct svr4_strm *st = svr4_stream_get(fp);
1135 1155
1136 if (st == NULL) { 1156 if (st == NULL) {
1137 DPRINTF(("i_setsig: bad file descriptor\n")); 1157 DPRINTF(("i_setsig: bad file descriptor\n"));
1138 return EINVAL; 1158 return EINVAL;
1139 } 1159 }
1140 /* get old status flags */ 1160 /* get old status flags */
1141 SCARG(&fa, fd) = fd; 1161 SCARG(&fa, fd) = fd;
1142 SCARG(&fa, cmd) = F_GETFL; 1162 SCARG(&fa, cmd) = F_GETFL;
1143 1163
1144 if ((error = sys_fcntl(l, &fa, &oflags)) != 0) 1164 if ((error = sys_fcntl(l, &fa, &oflags)) != 0)
1145 return error; 1165 return error;
1146 1166
1147 /* update the flags */ 1167 /* update the flags */
1148 if (dat != NULL) { 1168 if (dat != NULL) {
1149 int mask; 1169 int mask;
1150 1170
1151 flags = oflags | O_ASYNC; 1171 flags = oflags | O_ASYNC;
1152 mask = (int)(u_long)dat; 1172 mask = (int)(u_long)dat;
1153 if (mask & ~SVR4_S_ALLMASK) { 1173 if (mask & ~SVR4_S_ALLMASK) {
1154 DPRINTF(("i_setsig: bad eventmask data %x\n", mask)); 1174 DPRINTF(("i_setsig: bad eventmask data %x\n", mask));
1155 return EINVAL; 1175 return EINVAL;
1156 } 1176 }
1157 st->s_eventmask = mask; 1177 st->s_eventmask = mask;
1158 } 1178 }
1159 else { 1179 else {
1160 flags = oflags & ~O_ASYNC; 1180 flags = oflags & ~O_ASYNC;
1161 st->s_eventmask = 0; 1181 st->s_eventmask = 0;
1162 } 1182 }
1163 1183
1164 /* set the new flags, if changed */ 1184 /* set the new flags, if changed */
1165 if (flags != oflags) { 1185 if (flags != oflags) {
1166 SCARG(&fa, cmd) = F_SETFL; 1186 SCARG(&fa, cmd) = F_SETFL;
1167 SCARG(&fa, arg) = (void *) flags; 1187 SCARG(&fa, arg) = (void *) flags;
1168 if ((error = sys_fcntl(l, &fa, &flags)) != 0) 1188 if ((error = sys_fcntl(l, &fa, &flags)) != 0)
1169 return error; 1189 return error;
1170 } 1190 }
1171 1191
1172 /* set up SIGIO receiver if needed */ 1192 /* set up SIGIO receiver if needed */
1173 if (dat != NULL) { 1193 if (dat != NULL) {
1174 SCARG(&fa, cmd) = F_SETOWN; 1194 SCARG(&fa, cmd) = F_SETOWN;
1175 SCARG(&fa, arg) = (void *)(u_long)l->l_proc->p_pid; 1195 SCARG(&fa, arg) = (void *)(u_long)l->l_proc->p_pid;
1176 return sys_fcntl(l, &fa, &flags); 1196 return sys_fcntl(l, &fa, &flags);
1177 } 1197 }
1178 return 0; 1198 return 0;
1179} 1199}
1180 1200
1181static int 1201static int
1182i_getsig(file_t *fp, struct lwp *l, register_t *retval, 1202i_getsig(file_t *fp, struct lwp *l, register_t *retval,
1183 int fd, u_long cmd, void *dat) 1203 int fd, u_long cmd, void *dat)
1184{ 1204{
1185 int error; 1205 int error;
1186 1206
1187 if (dat != NULL) { 1207 if (dat != NULL) {
1188 struct svr4_strm *st = svr4_stream_get(fp); 1208 struct svr4_strm *st = svr4_stream_get(fp);
1189 1209
1190 if (st == NULL) { 1210 if (st == NULL) {
1191 DPRINTF(("i_getsig: bad file descriptor\n")); 1211 DPRINTF(("i_getsig: bad file descriptor\n"));
1192 return EINVAL; 1212 return EINVAL;
1193 } 1213 }
1194 if ((error = copyout(&st->s_eventmask, dat, 1214 if ((error = copyout(&st->s_eventmask, dat,
1195 sizeof(st->s_eventmask))) != 0) { 1215 sizeof(st->s_eventmask))) != 0) {
1196 DPRINTF(("i_getsig: bad eventmask pointer\n")); 1216 DPRINTF(("i_getsig: bad eventmask pointer\n"));
1197 return error; 1217 return error;
1198 } 1218 }
1199 } 1219 }
1200 return 0; 1220 return 0;
1201} 1221}
1202 1222
1203int 1223int
1204svr4_stream_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat) 1224svr4_stream_ioctl(file_t *fp, struct lwp *l, register_t *retval, int fd, u_long cmd, void *dat)
1205{ 1225{
1206 *retval = 0; 1226 *retval = 0;
1207 1227
1208 /* 1228 /*
1209 * All the following stuff assumes "sockmod" is pushed... 1229 * All the following stuff assumes "sockmod" is pushed...
1210 */ 1230 */
1211 switch (cmd) { 1231 switch (cmd) {
1212 case SVR4_I_NREAD: 1232 case SVR4_I_NREAD:
1213 DPRINTF(("I_NREAD\n")); 1233 DPRINTF(("I_NREAD\n"));
1214 return i_nread(fp, l, retval, fd, cmd, dat); 1234 return i_nread(fp, l, retval, fd, cmd, dat);
1215 1235
1216 case SVR4_I_PUSH: 1236 case SVR4_I_PUSH:
1217 DPRINTF(("I_PUSH\n")); 1237 DPRINTF(("I_PUSH\n"));
1218 return 0; 1238 return 0;
1219 1239
1220 case SVR4_I_POP: 1240 case SVR4_I_POP:
1221 DPRINTF(("I_POP\n")); 1241 DPRINTF(("I_POP\n"));
1222 return 0; 1242 return 0;
1223 1243
1224 case SVR4_I_LOOK: 1244 case SVR4_I_LOOK:
1225 DPRINTF(("I_LOOK\n")); 1245 DPRINTF(("I_LOOK\n"));
1226 return 0; 1246 return 0;
1227 1247
1228 case SVR4_I_FLUSH: 1248 case SVR4_I_FLUSH:
1229 DPRINTF(("I_FLUSH\n")); 1249 DPRINTF(("I_FLUSH\n"));
1230 return 0; 1250 return 0;
1231 1251
1232 case SVR4_I_SRDOPT: 1252 case SVR4_I_SRDOPT:
1233 DPRINTF(("I_SRDOPT\n")); 1253 DPRINTF(("I_SRDOPT\n"));
1234 return 0; 1254 return 0;
1235 1255
1236 case SVR4_I_GRDOPT: 1256 case SVR4_I_GRDOPT:
1237 DPRINTF(("I_GRDOPT\n")); 1257 DPRINTF(("I_GRDOPT\n"));
1238 return 0; 1258 return 0;
1239 1259
1240 case SVR4_I_STR: 1260 case SVR4_I_STR:
1241 DPRINTF(("I_STR\n")); 1261 DPRINTF(("I_STR\n"));
1242 return i_str(fp, l, retval, fd, cmd, dat); 1262 return i_str(fp, l, retval, fd, cmd, dat);
1243 1263
1244 case SVR4_I_SETSIG: 1264 case SVR4_I_SETSIG:
1245 DPRINTF(("I_SETSIG\n")); 1265 DPRINTF(("I_SETSIG\n"));
1246 return i_setsig(fp, l, retval, fd, cmd, dat); 1266 return i_setsig(fp, l, retval, fd, cmd, dat);
1247 1267
1248 case SVR4_I_GETSIG: 1268 case SVR4_I_GETSIG:
1249 DPRINTF(("I_GETSIG\n")); 1269 DPRINTF(("I_GETSIG\n"));
1250 return i_getsig(fp, l, retval, fd, cmd, dat); 1270 return i_getsig(fp, l, retval, fd, cmd, dat);
1251 1271
1252 case SVR4_I_FIND: 1272 case SVR4_I_FIND:
1253 DPRINTF(("I_FIND\n")); 1273 DPRINTF(("I_FIND\n"));
1254 /* 1274 /*
1255 * Here we are not pushing modules really, we just 1275 * Here we are not pushing modules really, we just
1256 * pretend all are present 1276 * pretend all are present
1257 */ 1277 */
1258 *retval = 1; 1278 *retval = 1;
1259 return 0; 1279 return 0;
1260 1280
1261 case SVR4_I_LINK: 1281 case SVR4_I_LINK:
1262 DPRINTF(("I_LINK\n")); 1282 DPRINTF(("I_LINK\n"));
1263 return 0; 1283 return 0;
1264 1284
1265 case SVR4_I_UNLINK: 1285 case SVR4_I_UNLINK:
1266 DPRINTF(("I_UNLINK\n")); 1286 DPRINTF(("I_UNLINK\n"));
1267 return 0; 1287 return 0;
1268 1288
1269 case SVR4_I_ERECVFD: 1289 case SVR4_I_ERECVFD:
1270 DPRINTF(("I_ERECVFD\n")); 1290 DPRINTF(("I_ERECVFD\n"));
1271 return 0; 1291 return 0;
1272 1292
1273 case SVR4_I_PEEK: 1293 case SVR4_I_PEEK:
1274 DPRINTF(("I_PEEK\n")); 1294 DPRINTF(("I_PEEK\n"));
1275 return 0; 1295 return 0;
1276 1296
1277 case SVR4_I_FDINSERT: 1297 case SVR4_I_FDINSERT:
1278 DPRINTF(("I_FDINSERT\n")); 1298 DPRINTF(("I_FDINSERT\n"));
1279 return i_fdinsert(fp, l, retval, fd, cmd, dat); 1299 return i_fdinsert(fp, l, retval, fd, cmd, dat);
1280 1300
1281 case SVR4_I_SENDFD: 1301 case SVR4_I_SENDFD:
1282 DPRINTF(("I_SENDFD\n")); 1302 DPRINTF(("I_SENDFD\n"));
1283 return 0; 1303 return 0;
1284 1304
1285 case SVR4_I_RECVFD: 1305 case SVR4_I_RECVFD:
1286 DPRINTF(("I_RECVFD\n")); 1306 DPRINTF(("I_RECVFD\n"));
1287 return 0; 1307 return 0;
1288 1308
1289 case SVR4_I_SWROPT: 1309 case SVR4_I_SWROPT:
1290 DPRINTF(("I_SWROPT\n")); 1310 DPRINTF(("I_SWROPT\n"));
1291 return 0; 1311 return 0;
1292 1312
1293 case SVR4_I_GWROPT: 1313 case SVR4_I_GWROPT:
1294 DPRINTF(("I_GWROPT\n")); 1314 DPRINTF(("I_GWROPT\n"));
1295 return 0; 1315 return 0;
1296 1316
1297 case SVR4_I_LIST: 1317 case SVR4_I_LIST:
1298 DPRINTF(("I_LIST\n")); 1318 DPRINTF(("I_LIST\n"));
1299 return 0; 1319 return 0;
1300 1320
1301 case SVR4_I_PLINK: 1321 case SVR4_I_PLINK:
1302 DPRINTF(("I_PLINK\n")); 1322 DPRINTF(("I_PLINK\n"));
1303 return 0; 1323 return 0;
1304 1324
1305 case SVR4_I_PUNLINK: 1325 case SVR4_I_PUNLINK:
1306 DPRINTF(("I_PUNLINK\n")); 1326 DPRINTF(("I_PUNLINK\n"));
1307 return 0; 1327 return 0;
1308 1328
1309 case SVR4_I_SETEV: 1329 case SVR4_I_SETEV:
1310 DPRINTF(("I_SETEV\n")); 1330 DPRINTF(("I_SETEV\n"));
1311 return 0; 1331 return 0;
1312 1332
1313 case SVR4_I_GETEV: 1333 case SVR4_I_GETEV:
1314 DPRINTF(("I_GETEV\n")); 1334 DPRINTF(("I_GETEV\n"));
1315 return 0; 1335 return 0;
1316 1336
1317 case SVR4_I_STREV: 1337 case SVR4_I_STREV:
1318 DPRINTF(("I_STREV\n")); 1338 DPRINTF(("I_STREV\n"));
1319 return 0; 1339 return 0;
1320 1340
1321 case SVR4_I_UNSTREV: 1341 case SVR4_I_UNSTREV:
1322 DPRINTF(("I_UNSTREV\n")); 1342 DPRINTF(("I_UNSTREV\n"));
1323 return 0; 1343 return 0;
1324 1344
1325 case SVR4_I_FLUSHBAND: 1345 case SVR4_I_FLUSHBAND:
1326 DPRINTF(("I_FLUSHBAND\n")); 1346 DPRINTF(("I_FLUSHBAND\n"));
1327 return 0; 1347 return 0;
1328 1348
1329 case SVR4_I_CKBAND: 1349 case SVR4_I_CKBAND:
1330 DPRINTF(("I_CKBAND\n")); 1350 DPRINTF(("I_CKBAND\n"));
1331 return 0; 1351 return 0;
1332 1352
1333 case SVR4_I_GETBAND: 1353 case SVR4_I_GETBAND:
1334 DPRINTF(("I_GETBANK\n")); 1354 DPRINTF(("I_GETBANK\n"));
1335 return 0; 1355 return 0;
1336 1356
1337 case SVR4_I_ATMARK: 1357 case SVR4_I_ATMARK:
1338 DPRINTF(("I_ATMARK\n")); 1358 DPRINTF(("I_ATMARK\n"));
1339 return 0; 1359 return 0;
1340 1360
1341 case SVR4_I_SETCLTIME: 1361 case SVR4_I_SETCLTIME:
1342 DPRINTF(("I_SETCLTIME\n")); 1362 DPRINTF(("I_SETCLTIME\n"));
1343 return 0; 1363 return 0;
1344 1364
1345 case SVR4_I_GETCLTIME: 1365 case SVR4_I_GETCLTIME:
1346 DPRINTF(("I_GETCLTIME\n")); 1366 DPRINTF(("I_GETCLTIME\n"));
1347 return 0; 1367 return 0;
1348 1368
1349 case SVR4_I_CANPUT: 1369 case SVR4_I_CANPUT:
1350 DPRINTF(("I_CANPUT\n")); 1370 DPRINTF(("I_CANPUT\n"));
1351 return 0; 1371 return 0;
1352 1372
1353 case SVR4__I_BIND_RSVD: 1373 case SVR4__I_BIND_RSVD:
1354 DPRINTF(("_I_BIND_RSVD\n")); 1374 DPRINTF(("_I_BIND_RSVD\n"));
1355 return _i_bind_rsvd(fp, l, retval, fd, cmd, dat); 1375 return _i_bind_rsvd(fp, l, retval, fd, cmd, dat);
1356 1376
1357 case SVR4__I_RELE_RSVD: 1377 case SVR4__I_RELE_RSVD:
1358 DPRINTF(("_I_RELE_RSVD\n")); 1378 DPRINTF(("_I_RELE_RSVD\n"));
1359 return _i_rele_rsvd(fp, l, retval, fd, cmd, dat); 1379 return _i_rele_rsvd(fp, l, retval, fd, cmd, dat);
1360 1380
1361 default: 1381 default:
1362 DPRINTF(("unimpl cmd = %lx\n", cmd)); 1382 DPRINTF(("unimpl cmd = %lx\n", cmd));
1363 break; 1383 break;
1364 } 1384 }
1365 1385
1366 return 0; 1386 return 0;
1367} 1387}
1368 1388
1369 1389
1370 1390
1371 1391
1372int 1392int
1373svr4_sys_putmsg(struct lwp *l, const struct svr4_sys_putmsg_args *uap, register_t *retval) 1393svr4_sys_putmsg(struct lwp *l, const struct svr4_sys_putmsg_args *uap, register_t *retval)
1374{ 1394{
1375 struct proc *p = l->l_proc; 1395 struct proc *p = l->l_proc;
1376 file_t *fp; 1396 file_t *fp;
1377 struct svr4_strbuf dat, ctl; 1397 struct svr4_strbuf dat, ctl;
1378 struct svr4_strmcmd sc; 1398 struct svr4_strmcmd sc;
1379 struct sockaddr_in sain; 1399 struct sockaddr_in sain;
1380 struct sockaddr_un saun; 1400 struct sockaddr_un saun;
1381 void *skp; 1401 void *skp;
1382 int sasize; 1402 int sasize;
1383 struct svr4_strm *st; 1403 struct svr4_strm *st;
1384 int error; 1404 int error;
1385 struct mbuf *nam; 1405 struct mbuf *nam;
1386 struct msghdr msg; 1406 struct msghdr msg;
1387 struct iovec aiov; 1407 struct iovec aiov;
1388 1408
1389 1409
1390#ifdef DEBUG_SVR4 1410#ifdef DEBUG_SVR4
1391 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl), 1411 show_msg(">putmsg", SCARG(uap, fd), SCARG(uap, ctl),
1392 SCARG(uap, dat), SCARG(uap, flags)); 1412 SCARG(uap, dat), SCARG(uap, flags));
1393#endif /* DEBUG_SVR4 */ 1413#endif /* DEBUG_SVR4 */
1394 1414
1395 if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) 1415 if ((fp = fd_getfile(SCARG(uap, fd))) == NULL)
1396 return EBADF; 1416 return EBADF;
1397 1417
1398 KERNEL_LOCK(1, NULL); /* svr4_find_socket */ 1418 KERNEL_LOCK(1, NULL); /* svr4_find_socket */
1399 1419
1400 if (SCARG_PTR(uap, ctl) != NULL) { 1420 if (SCARG_PTR(uap, ctl) != NULL) {
1401 if ((error = copyin(SCARG_PTR(uap, ctl), 1421 if ((error = copyin(SCARG_PTR(uap, ctl),
1402 &ctl, sizeof(ctl))) != 0) 1422 &ctl, sizeof(ctl))) != 0)
1403 goto out; 1423 goto out;
1404 } else 1424 } else
1405 ctl.len = -1; 1425 ctl.len = -1;
1406 1426
1407 if (SCARG_PTR(uap, dat) != NULL) { 1427 if (SCARG_PTR(uap, dat) != NULL) {
1408 if ((error = copyin(SCARG_PTR(uap, dat), 1428 if ((error = copyin(SCARG_PTR(uap, dat),
1409 &dat, sizeof(dat))) != 0) 1429 &dat, sizeof(dat))) != 0)
1410 goto out; 1430 goto out;
1411 } else 1431 } else
1412 dat.len = -1; 1432 dat.len = -1;
1413 1433
1414 /* 1434 /*
1415 * Only for sockets for now. 1435 * Only for sockets for now.
1416 */ 1436 */
1417 if ((st = svr4_stream_get(fp)) == NULL) { 1437 if ((st = svr4_stream_get(fp)) == NULL) {
1418 DPRINTF(("putmsg: bad file type\n")); 1438 DPRINTF(("putmsg: bad file type\n"));
1419 error = EINVAL; 1439 error = EINVAL;
1420 goto out; 1440 goto out;
1421 } 1441 }
1422 1442
1423 if (ctl.len > sizeof(sc)) { 1443 if (ctl.len < offsetof(struct svr4_strmcmd, pad) ||
 1444 ctl.len > sizeof(sc)) {
1424 DPRINTF(("putmsg: Bad control size %ld != %d\n", 1445 DPRINTF(("putmsg: Bad control size %ld != %d\n",
1425 (unsigned long)sizeof(struct svr4_strmcmd), ctl.len)); 1446 (unsigned long)sizeof(struct svr4_strmcmd), ctl.len));
1426 error = EINVAL; 1447 error = EINVAL;
1427 goto out; 1448 goto out;
1428 } 1449 }
1429 1450
1430 if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0) 1451 if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0)
1431 goto out; 1452 goto out;
 1453 if (sc.offs < 0 ||
 1454 sc.len < 0 ||
 1455 sc.len > ctl.len ||
 1456 sc.offs > ctl.len - sc.len) {
 1457 error = EINVAL;
 1458 goto out;
 1459 }
1432 1460
1433 switch (st->s_family) { 1461 switch (st->s_family) {
1434 case AF_INET: 1462 case AF_INET:
1435 if (sc.len != sizeof(sain)) { 1463 if (sc.len != sizeof(sain)) {
1436#ifdef notyet 1464#ifdef notyet
1437 if (sc.cmd == SVR4_TI_DATA_REQUEST) { 1465 if (sc.cmd == SVR4_TI_DATA_REQUEST) {
1438 struct sys_write_args wa; 1466 struct sys_write_args wa;
1439 1467
1440 /* Solaris seems to use sc.cmd = 3 to 1468 /* Solaris seems to use sc.cmd = 3 to
1441 * send "expedited" data. telnet uses 1469 * send "expedited" data. telnet uses
1442 * this for options processing, sending EOF, 1470 * this for options processing, sending EOF,
1443 * etc. I'm sure other things use it too. 1471 * etc. I'm sure other things use it too.
1444 * I don't have any documentation 1472 * I don't have any documentation
1445 * on it, so I'm making a guess that this 1473 * on it, so I'm making a guess that this
1446 * is how it works. newton@atdot.dotat.org XXX 1474 * is how it works. newton@atdot.dotat.org XXX
1447 * 1475 *
1448 * Hmm, expedited data seems to be sc.cmd = 4. 1476 * Hmm, expedited data seems to be sc.cmd = 4.
1449 * I think 3 is normal data. (christos) 1477 * I think 3 is normal data. (christos)
1450 */ 1478 */
1451 DPRINTF(("sending expedited data (?)\n")); 1479 DPRINTF(("sending expedited data (?)\n"));
1452 SCARG(&wa, fd) = SCARG(uap, fd); 1480 SCARG(&wa, fd) = SCARG(uap, fd);
1453 SCARG(&wa, buf) = dat.buf; 1481 SCARG(&wa, buf) = dat.buf;
1454 SCARG(&wa, nbyte) = dat.len; 1482 SCARG(&wa, nbyte) = dat.len;
1455 error = sys_write(l, &wa, retval); 1483 error = sys_write(l, &wa, retval);
1456 goto out; 1484 goto out;
1457 } 1485 }
1458#endif 1486#endif
1459 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len)); 1487 DPRINTF(("putmsg: Invalid inet length %ld\n", sc.len));
1460 error = EINVAL; 1488 error = EINVAL;
1461 goto out; 1489 goto out;
1462 } 1490 }
1463 netaddr_to_sockaddr_in(&sain, &sc); 1491 netaddr_to_sockaddr_in(&sain, &sc);
1464 skp = &sain; 1492 skp = &sain;
1465 sasize = sizeof(sain); 1493 sasize = sizeof(sain);
1466 error = sain.sin_family != st->s_family; 1494 error = sain.sin_family != st->s_family;
1467 break; 1495 break;
1468 1496
1469 case AF_LOCAL: 1497 case AF_LOCAL:
1470 if (ctl.len == 8) { 1498 if (ctl.len == 8) {
1471 /* We are doing an accept; succeed */ 1499 /* We are doing an accept; succeed */
1472 DPRINTF(("putmsg: Do nothing\n")); 1500 DPRINTF(("putmsg: Do nothing\n"));
1473 *retval = 0; 1501 *retval = 0;
1474 error = 0; 1502 error = 0;
1475 goto out; 1503 goto out;
1476 } 1504 } else if (sc.len < sizeof(dev_t[2])) {
1477 else { 1505 *retval = 0;
 1506 error = EINVAL;
 1507 goto out;
 1508 } else {
1478 /* Maybe we've been given a device/inode pair */ 1509 /* Maybe we've been given a device/inode pair */
1479 dev_t *dev = SVR4_ADDROF(&sc); 1510 dev_t *dev = SVR4_ADDROF(&sc);
1480 svr4_ino_t *ino = (svr4_ino_t *) &dev[1]; 1511 svr4_ino_t *ino = (svr4_ino_t *) &dev[1];
1481 skp = svr4_find_socket(p, fp, *dev, *ino); 1512 skp = svr4_find_socket(p, fp, *dev, *ino);
1482 if (skp == NULL) { 1513 if (skp == NULL) {
1483 skp = &saun; 1514 skp = &saun;
1484 /* I guess we have it by name */ 1515 /* I guess we have it by name */
1485 netaddr_to_sockaddr_un(skp, &sc); 1516 netaddr_to_sockaddr_un(skp, &sc);
1486 } 1517 }
1487 sasize = sizeof(saun); 1518 sasize = sizeof(saun);
1488 } 1519 }
1489 break; 1520 break;
1490 1521
1491 default: 1522 default:
1492 DPRINTF(("putmsg: Unsupported address family %d\n", 1523 DPRINTF(("putmsg: Unsupported address family %d\n",
1493 st->s_family)); 1524 st->s_family));
1494 error = ENOSYS; 1525 error = ENOSYS;
1495 goto out; 1526 goto out;
1496 } 1527 }
1497 1528
1498 nam = m_get(M_WAIT, MT_SONAME); 1529 nam = m_get(M_WAIT, MT_SONAME);
1499 nam->m_len = sasize; 1530 nam->m_len = sasize;
1500 memcpy(mtod(nam, void *), skp, sasize); 1531 memcpy(mtod(nam, void *), skp, sasize);
1501 1532
1502 switch (st->s_cmd = sc.cmd) { 1533 switch (st->s_cmd = sc.cmd) {
1503 case SVR4_TI_CONNECT_REQUEST: /* connect */ 1534 case SVR4_TI_CONNECT_REQUEST: /* connect */
1504 KERNEL_UNLOCK_ONE(NULL); 1535 KERNEL_UNLOCK_ONE(NULL);
 1536 fd_putfile(SCARG(uap, fd));
1505 return do_sys_connect(l, SCARG(uap, fd), nam); 1537 return do_sys_connect(l, SCARG(uap, fd), nam);
1506 1538
1507 case SVR4_TI_SENDTO_REQUEST: /* sendto */ 1539 case SVR4_TI_SENDTO_REQUEST: /* sendto */
1508 KERNEL_UNLOCK_ONE(NULL); 1540 KERNEL_UNLOCK_ONE(NULL);
 1541 fd_putfile(SCARG(uap, fd));
1509 msg.msg_name = nam; 1542 msg.msg_name = nam;
1510 msg.msg_namelen = sasize; 1543 msg.msg_namelen = sasize;
1511 msg.msg_iov = &aiov; 1544 msg.msg_iov = &aiov;
1512 msg.msg_iovlen = 1; 1545 msg.msg_iovlen = 1;
1513 msg.msg_control = NULL; 1546 msg.msg_control = NULL;
1514 msg.msg_flags = MSG_NAMEMBUF; 1547 msg.msg_flags = MSG_NAMEMBUF;
1515 aiov.iov_base = NETBSD32PTR(dat.buf); 1548 aiov.iov_base = NETBSD32PTR(dat.buf);
1516 aiov.iov_len = dat.len; 1549 aiov.iov_len = dat.len;
1517 error = do_sys_sendmsg(l, SCARG(uap, fd), &msg, 1550 error = do_sys_sendmsg(l, SCARG(uap, fd), &msg,
1518 SCARG(uap, flags), retval); 1551 SCARG(uap, flags), retval);
1519 1552
1520 *retval = 0; 1553 *retval = 0;
1521 return error; 1554 return error;
1522  1555
1523 default: 1556 default:
1524 m_free(nam); 1557 m_free(nam);
1525 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd)); 1558 DPRINTF(("putmsg: Unimplemented command %lx\n", sc.cmd));
1526 error = ENOSYS; 1559 error = ENOSYS;
1527 goto out; 1560 goto out;
1528 } 1561 }
1529 1562
1530 out: 1563 out:
1531 KERNEL_UNLOCK_ONE(NULL); 1564 KERNEL_UNLOCK_ONE(NULL);
1532 fd_putfile(SCARG(uap, fd)); 1565 fd_putfile(SCARG(uap, fd));
1533 return error; 1566 return error;
1534} 1567}
1535 1568
1536 1569
1537int 1570int
1538svr4_sys_getmsg(struct lwp *l, const struct svr4_sys_getmsg_args *uap, register_t *retval) 1571svr4_sys_getmsg(struct lwp *l, const struct svr4_sys_getmsg_args *uap, register_t *retval)
1539{ 1572{
1540 file_t *fp; 1573 file_t *fp;
1541 struct svr4_strbuf dat, ctl; 1574 struct svr4_strbuf dat, ctl;
1542 struct svr4_strmcmd sc; 1575 struct svr4_strmcmd sc;
1543 int error = 0; 1576 int error = 0;
1544 struct msghdr msg; 1577 struct msghdr msg;
1545 struct iovec aiov; 1578 struct iovec aiov;
1546 struct svr4_strm *st; 1579 struct svr4_strm *st;
1547 int fl; 1580 int fl;
1548 struct mbuf *name; 1581 struct mbuf *name;
1549 1582
1550 memset(&sc, 0, sizeof(sc)); 1583 memset(&sc, 0, sizeof(sc));
1551 1584
1552#ifdef DEBUG_SVR4 1585#ifdef DEBUG_SVR4
1553 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl), 1586 show_msg(">getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1554 SCARG(uap, dat), 0); 1587 SCARG(uap, dat), 0);
1555#endif /* DEBUG_SVR4 */ 1588#endif /* DEBUG_SVR4 */
1556 1589
1557 if ((fp = fd_getfile(SCARG(uap, fd))) == NULL) 1590 if ((fp = fd_getfile(SCARG(uap, fd))) == NULL)
1558 return EBADF; 1591 return EBADF;
1559 1592
1560 if (SCARG_PTR(uap, ctl) != NULL) { 1593 if (SCARG_PTR(uap, ctl) != NULL) {
1561 if ((error = copyin(SCARG_PTR(uap, ctl), &ctl, 1594 if ((error = copyin(SCARG_PTR(uap, ctl), &ctl,
1562 sizeof(ctl))) != 0) 1595 sizeof(ctl))) != 0)
1563 goto out; 1596 goto out;
1564 } else { 1597 } else {
1565 ctl.len = -1; 1598 ctl.len = -1;
1566 ctl.maxlen = 0; 1599 ctl.maxlen = 0;
1567 } 1600 }
1568 1601
1569 if (SCARG_PTR(uap, dat) != NULL) { 1602 if (SCARG_PTR(uap, dat) != NULL) {
1570 if ((error = copyin(SCARG_PTR(uap, dat), &dat, 1603 if ((error = copyin(SCARG_PTR(uap, dat), &dat,
1571 sizeof(dat))) != 0) 1604 sizeof(dat))) != 0)
1572 goto out; 1605 goto out;
1573 } else { 1606 } else {
1574 dat.len = -1; 1607 dat.len = -1;
1575 dat.maxlen = 0; 1608 dat.maxlen = 0;
1576 } 1609 }
1577 1610
1578 /* 1611 /*
1579 * Only for sockets for now. 1612 * Only for sockets for now.
1580 */ 1613 */
1581 if ((st = svr4_stream_get(fp)) == NULL) { 1614 if ((st = svr4_stream_get(fp)) == NULL) {
1582 DPRINTF(("getmsg: bad file type\n")); 1615 DPRINTF(("getmsg: bad file type\n"));
1583 error = EINVAL; 1616 error = EINVAL;
1584 goto out; 1617 goto out;
1585 } 1618 }
1586 1619
1587 if (ctl.maxlen == -1 || dat.maxlen == -1) { 1620 if (ctl.maxlen == -1 || dat.maxlen == -1) {
1588 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n")); 1621 DPRINTF(("getmsg: Cannot handle -1 maxlen (yet)\n"));
1589 error = ENOSYS; 1622 error = ENOSYS;
1590 goto out; 1623 goto out;
1591 } 1624 }
1592 1625
1593 switch (st->s_family) { 1626 switch (st->s_family) {
1594 case AF_INET: 1627 case AF_INET:
1595 case AF_LOCAL: 1628 case AF_LOCAL:
1596 break; 1629 break;
1597 1630
1598 default: 1631 default:
1599 DPRINTF(("getmsg: Unsupported address family %d\n", 1632 DPRINTF(("getmsg: Unsupported address family %d\n",
1600 st->s_family)); 1633 st->s_family));
1601 goto out; 1634 goto out;
1602 } 1635 }
1603 1636
1604 switch (st->s_cmd) { 1637 switch (st->s_cmd) {
1605 case SVR4_TI_CONNECT_REQUEST: 1638 case SVR4_TI_CONNECT_REQUEST:
1606 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n")); 1639 DPRINTF(("getmsg: TI_CONNECT_REQUEST\n"));
1607 /* 1640 /*
1608 * We do the connect in one step, so the putmsg should 1641 * We do the connect in one step, so the putmsg should
1609 * have gotten the error. 1642 * have gotten the error.
1610 */ 1643 */
1611 sc.cmd = SVR4_TI_OK_REPLY; 1644 sc.cmd = SVR4_TI_OK_REPLY;
1612 sc.len = 0; 1645 sc.len = 0;
1613 1646
1614 ctl.len = 8; 1647 ctl.len = 8;
1615 dat.len = -1; 1648 dat.len = -1;
1616 fl = 1; 1649 fl = 1;
1617 st->s_cmd = sc.cmd; 1650 st->s_cmd = sc.cmd;
1618 break; 1651 break;
1619 1652
1620 case SVR4_TI_OK_REPLY: 1653 case SVR4_TI_OK_REPLY:
1621 DPRINTF(("getmsg: TI_OK_REPLY\n")); 1654 DPRINTF(("getmsg: TI_OK_REPLY\n"));
1622 /* 1655 /*
1623 * We are immediately after a connect reply, so we send 1656 * We are immediately after a connect reply, so we send
1624 * a connect verification. 1657 * a connect verification.
1625 */ 1658 */
1626 1659
1627 error = do_sys_getsockname(l, SCARG(uap, fd), PRU_SOCKADDR, 1660 error = do_sys_getsockname(l, SCARG(uap, fd), PRU_SOCKADDR,
1628 &name); 1661 &name);
1629 if (error != 0) { 1662 if (error != 0) {
1630 DPRINTF(("getmsg: getpeername failed %d\n", error)); 1663 DPRINTF(("getmsg: getpeername failed %d\n", error));
1631 goto out; 1664 goto out;
1632 } 1665 }
1633 1666
1634 sc.cmd = SVR4_TI_CONNECT_REPLY; 1667 sc.cmd = SVR4_TI_CONNECT_REPLY;
1635 sc.pad[0] = 0x4; 1668 sc.pad[0] = 0x4;
1636 sc.offs = 0x18; 1669 sc.offs = 0x18;
1637 sc.pad[1] = 0x14; 1670 sc.pad[1] = 0x14;
1638 sc.pad[2] = 0x04000402; 1671 sc.pad[2] = 0x04000402;
1639 1672
1640 switch (st->s_family) { 1673 switch (st->s_family) {
1641 case AF_INET: 1674 case AF_INET:
1642 sc.len = sizeof (struct sockaddr_in) + 4; 1675 sc.len = sizeof (struct sockaddr_in) + 4;
1643 sockaddr_to_netaddr_in(&sc, mtod(name, void *)); 1676 sockaddr_to_netaddr_in(&sc, mtod(name, void *));
1644 break; 1677 break;
1645 1678
1646 case AF_LOCAL: 1679 case AF_LOCAL:
1647 sc.len = sizeof (struct sockaddr_un) + 4; 1680 sc.len = sizeof (struct sockaddr_un) + 4;
1648 sockaddr_to_netaddr_un(&sc, mtod(name, void *)); 1681 sockaddr_to_netaddr_un(&sc, mtod(name, void *));
1649 break; 1682 break;
1650 1683
1651 default: 1684 default:
1652 m_free(name); 1685 m_free(name);
1653 error = ENOSYS; 1686 error = ENOSYS;
1654 goto out; 1687 goto out;
1655 } 1688 }
1656 m_free(name); 1689 m_free(name);
1657 1690
1658 ctl.len = 40; 1691 ctl.len = 40;
1659 dat.len = -1; 1692 dat.len = -1;
1660 fl = 0; 1693 fl = 0;
1661 st->s_cmd = sc.cmd; 1694 st->s_cmd = sc.cmd;
1662 break; 1695 break;
1663 1696
1664 case SVR4_TI__ACCEPT_OK: 1697 case SVR4_TI__ACCEPT_OK:
1665 DPRINTF(("getmsg: TI__ACCEPT_OK\n")); 1698 DPRINTF(("getmsg: TI__ACCEPT_OK\n"));
1666 /* 1699 /*
1667 * We do the connect in one step, so the putmsg should 1700 * We do the connect in one step, so the putmsg should
1668 * have gotten the error. 1701 * have gotten the error.
1669 */ 1702 */
1670 sc.cmd = SVR4_TI_OK_REPLY; 1703 sc.cmd = SVR4_TI_OK_REPLY;
1671 sc.len = 1; 1704 sc.len = 1;
1672 1705
1673 ctl.len = 8; 1706 ctl.len = 8;
1674 dat.len = -1; 1707 dat.len = -1;
1675 fl = 1; 1708 fl = 1;
1676 st->s_cmd = SVR4_TI__ACCEPT_WAIT; 1709 st->s_cmd = SVR4_TI__ACCEPT_WAIT;
1677 break; 1710 break;
1678 1711
1679 case SVR4_TI__ACCEPT_WAIT: 1712 case SVR4_TI__ACCEPT_WAIT:
1680 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n")); 1713 DPRINTF(("getmsg: TI__ACCEPT_WAIT\n"));
1681 /* 1714 /*
1682 * We are after a listen, so we try to accept... 1715 * We are after a listen, so we try to accept...
1683 */ 1716 */
1684 1717
1685 error = do_sys_accept(l, SCARG(uap, fd), &name, retval, 1718 error = do_sys_accept(l, SCARG(uap, fd), &name, retval,
1686 NULL, 0, FNONBLOCK); 1719 NULL, 0, FNONBLOCK);
1687 if (error != 0) { 1720 if (error != 0) {
1688 DPRINTF(("getmsg: accept failed %d\n", error)); 1721 DPRINTF(("getmsg: accept failed %d\n", error));
1689 goto out; 1722 goto out;
1690 } 1723 }
1691 1724
1692 st->s_afd = *retval; 1725 st->s_afd = *retval;
1693 1726
1694 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd)); 1727 DPRINTF(("getmsg: Accept fd = %d\n", st->s_afd));
1695 1728
1696 sc.cmd = SVR4_TI_ACCEPT_REPLY; 1729 sc.cmd = SVR4_TI_ACCEPT_REPLY;
1697 sc.offs = 0x18; 1730 sc.offs = 0x18;
1698 sc.pad[0] = 0x0; 1731 sc.pad[0] = 0x0;
1699 1732
1700 switch (st->s_family) { 1733 switch (st->s_family) {
1701 case AF_INET: 1734 case AF_INET:
1702 sc.pad[1] = 0x28; 1735 sc.pad[1] = 0x28;
1703 sockaddr_to_netaddr_in(&sc, mtod(name, void *)); 1736 sockaddr_to_netaddr_in(&sc, mtod(name, void *));
1704 ctl.len = 40; 1737 ctl.len = 40;
1705 sc.len = sizeof (struct sockaddr_in); 1738 sc.len = sizeof (struct sockaddr_in);
1706 break; 1739 break;
1707 1740
1708 case AF_LOCAL: 1741 case AF_LOCAL:
1709 sc.pad[1] = 0x00010000; 1742 sc.pad[1] = 0x00010000;
1710 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */ 1743 sc.pad[2] = 0xf6bcdaa0; /* I don't know what that is */
1711 sc.pad[3] = 0x00010000; 1744 sc.pad[3] = 0x00010000;
1712 ctl.len = 134; 1745 ctl.len = 134;
1713 sc.len = sizeof (struct sockaddr_un) + 4; 1746 sc.len = sizeof (struct sockaddr_un) + 4;
1714 break; 1747 break;
1715 1748
1716 default: 1749 default:
1717 m_free(name); 1750 m_free(name);
1718 error = ENOSYS; 1751 error = ENOSYS;
1719 goto out; 1752 goto out;
1720 } 1753 }
1721 m_free(name); 1754 m_free(name);
1722 1755
1723 dat.len = -1; 1756 dat.len = -1;
1724 fl = 0; 1757 fl = 0;
1725 st->s_cmd = SVR4_TI__ACCEPT_OK; 1758 st->s_cmd = SVR4_TI__ACCEPT_OK;
1726 break; 1759 break;
1727 1760
1728 case SVR4_TI_SENDTO_REQUEST: 1761 case SVR4_TI_SENDTO_REQUEST:
1729 /* 1762 /*
1730 * XXX: dsl - I think this means that because we last did a 1763 * XXX: dsl - I think this means that because we last did a
1731 * 'sendto' we'd better do a recvfrom now. 1764 * 'sendto' we'd better do a recvfrom now.
1732 */ 1765 */
1733 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n")); 1766 DPRINTF(("getmsg: TI_SENDTO_REQUEST\n"));
1734 if (ctl.maxlen > 36 && ctl.len < 36) 1767 if (ctl.maxlen > 36 && ctl.len < 36)
1735 ctl.len = 36; 1768 ctl.len = 36;
1736 if (ctl.len > sizeof(sc)) 1769 if (ctl.len > sizeof(sc))
1737 ctl.len = sizeof(sc); 1770 ctl.len = sizeof(sc);
1738 1771
 1772 if (ctl.len < offsetof(struct svr4_strmcmd, pad)) {
 1773 error = EINVAL;
 1774 goto out;
 1775 }
1739 if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0) 1776 if ((error = copyin(NETBSD32PTR(ctl.buf), &sc, ctl.len)) != 0)
1740 goto out; 1777 goto out;
 1778 if (sc.offs < 0) {
 1779 error = EINVAL;
 1780 goto out;
 1781 }
1741 1782
1742 msg.msg_name = NULL; 1783 msg.msg_name = NULL;
1743 msg.msg_namelen = 0; 1784 msg.msg_namelen = 0;
1744 msg.msg_iov = &aiov; 1785 msg.msg_iov = &aiov;
1745 msg.msg_iovlen = 1; 1786 msg.msg_iovlen = 1;
1746 msg.msg_control = 0; 1787 msg.msg_control = 0;
1747 aiov.iov_base = NETBSD32PTR(dat.buf); 1788 aiov.iov_base = NETBSD32PTR(dat.buf);
1748 aiov.iov_len = dat.maxlen; 1789 aiov.iov_len = dat.maxlen;
1749 msg.msg_flags = 0; 1790 msg.msg_flags = 0;
1750 1791
1751 error = do_sys_recvmsg(l, SCARG(uap, fd), &msg, &name, NULL, 1792 error = do_sys_recvmsg(l, SCARG(uap, fd), &msg, &name, NULL,
1752 retval); 1793 retval);
1753 1794
1754 if (error) { 1795 if (error) {
1755 DPRINTF(("getmsg: do_sys_recvmsg failed %d\n", error)); 1796 DPRINTF(("getmsg: do_sys_recvmsg failed %d\n", error));
1756 goto out; 1797 goto out;
1757 } 1798 }
1758 1799
1759 sc.cmd = SVR4_TI_RECVFROM_IND; 1800 sc.cmd = SVR4_TI_RECVFROM_IND;
1760 1801
1761 switch (st->s_family) { 1802 switch (st->s_family) {
1762 case AF_INET: 1803 case AF_INET:
1763 sc.len = sizeof (struct sockaddr_in); 1804 sc.len = sizeof (struct sockaddr_in);
1764 sockaddr_to_netaddr_in(&sc, mtod(name, void *)); 1805 sockaddr_to_netaddr_in(&sc, mtod(name, void *));
1765 break; 1806 break;
1766 1807
1767 case AF_LOCAL: 1808 case AF_LOCAL:
1768 sc.len = sizeof (struct sockaddr_un) + 4; 1809 sc.len = sizeof (struct sockaddr_un) + 4;
1769 sockaddr_to_netaddr_un(&sc, mtod(name, void *)); 1810 sockaddr_to_netaddr_un(&sc, mtod(name, void *));
1770 break; 1811 break;
1771 1812
1772 default: 1813 default:
1773 m_free(name); 1814 m_free(name);
1774 error = ENOSYS; 1815 error = ENOSYS;
1775 goto out; 1816 goto out;
1776 } 1817 }
1777 m_free(name); 1818 m_free(name);
1778 1819
1779 dat.len = *retval; 1820 dat.len = *retval;
1780 fl = 0; 1821 fl = 0;
1781 st->s_cmd = sc.cmd; 1822 st->s_cmd = sc.cmd;
1782 break; 1823 break;
1783 1824
1784 default: 1825 default:
1785 st->s_cmd = sc.cmd; 1826 st->s_cmd = sc.cmd;
1786#ifdef notyet 1827#ifdef notyet
1787 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) { 1828 if (st->s_cmd == SVR4_TI_CONNECT_REQUEST) {
1788 struct sys_read_args ra; 1829 struct sys_read_args ra;
1789 1830
1790 /* More weirdness: Again, I can't find documentation 1831 /* More weirdness: Again, I can't find documentation
1791 * to back this up, but when a process does a generic 1832 * to back this up, but when a process does a generic
1792 * "getmsg()" call it seems that the command field is 1833 * "getmsg()" call it seems that the command field is
1793 * zero and the length of the data area is zero. I 1834 * zero and the length of the data area is zero. I
1794 * think processes expect getmsg() to fill in dat.len 1835 * think processes expect getmsg() to fill in dat.len
1795 * after reading at most dat.maxlen octets from the 1836 * after reading at most dat.maxlen octets from the
1796 * stream. Since we're using sockets I can let 1837 * stream. Since we're using sockets I can let
1797 * read() look after it and frob return values 1838 * read() look after it and frob return values
1798 * appropriately (or inappropriately :-) 1839 * appropriately (or inappropriately :-)
1799 * -- newton@atdot.dotat.org XXX 1840 * -- newton@atdot.dotat.org XXX
1800 */ 1841 */
1801 SCARG(&ra, fd) = SCARG(uap, fd); 1842 SCARG(&ra, fd) = SCARG(uap, fd);
1802 SCARG(&ra, buf) = dat.buf; 1843 SCARG(&ra, buf) = dat.buf;
1803 SCARG(&ra, nbyte) = dat.maxlen; 1844 SCARG(&ra, nbyte) = dat.maxlen;
1804 if ((error = sys_read(p, &ra, retval)) != 0) 1845 if ((error = sys_read(p, &ra, retval)) != 0)
1805 goto out; 1846 goto out;
1806 dat.len = *retval; 1847 dat.len = *retval;
1807 *retval = 0; 1848 *retval = 0;
1808 st->s_cmd = SVR4_TI_SENDTO_REQUEST; 1849 st->s_cmd = SVR4_TI_SENDTO_REQUEST;
1809 break; 1850 break;
1810 1851
1811 } 1852 }
1812#endif 1853#endif
1813 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd)); 1854 DPRINTF(("getmsg: Unknown state %x\n", st->s_cmd));
1814 error = EINVAL; 1855 error = EINVAL;
1815 goto out; 1856 goto out;
1816 } 1857 }
1817 1858
1818 if (SCARG_PTR(uap, ctl)) { 1859 if (SCARG_PTR(uap, ctl)) {
1819 if (ctl.len != -1) 1860 if (ctl.len != -1)
1820 if ((error = copyout(&sc, NETBSD32PTR(ctl.buf), 1861 if ((error = copyout(&sc, NETBSD32PTR(ctl.buf),
1821 ctl.len)) != 0) 1862 ctl.len)) != 0)
1822 goto out; 1863 goto out;
1823 1864
1824 if ((error = copyout(&ctl, SCARG_PTR(uap, ctl), 1865 if ((error = copyout(&ctl, SCARG_PTR(uap, ctl),
1825 sizeof(ctl))) != 0) 1866 sizeof(ctl))) != 0)
1826 goto out; 1867 goto out;
1827 } 1868 }
1828 1869
1829 if (SCARG_PTR(uap, dat)) { 1870 if (SCARG_PTR(uap, dat)) {
1830 if ((error = copyout(&dat, SCARG_PTR(uap, dat), 1871 if ((error = copyout(&dat, SCARG_PTR(uap, dat),
1831 sizeof(dat))) != 0) 1872 sizeof(dat))) != 0)
1832 goto out; 1873 goto out;
1833 } 1874 }
1834 1875
1835 if (SCARG_PTR(uap, flags)) { /* XXX: Need translation */ 1876 if (SCARG_PTR(uap, flags)) { /* XXX: Need translation */
1836 if ((error = copyout(&fl, SCARG_PTR(uap, flags), 1877 if ((error = copyout(&fl, SCARG_PTR(uap, flags),
1837 sizeof(fl))) != 0) 1878 sizeof(fl))) != 0)
1838 goto out; 1879 goto out;
1839 } 1880 }
1840 1881
1841 *retval = 0; 1882 *retval = 0;
1842 1883
1843#ifdef DEBUG_SVR4 1884#ifdef DEBUG_SVR4
1844 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl), 1885 show_msg("<getmsg", SCARG(uap, fd), SCARG(uap, ctl),
1845 SCARG(uap, dat), fl); 1886 SCARG(uap, dat), fl);
1846#endif /* DEBUG_SVR4 */ 1887#endif /* DEBUG_SVR4 */
1847 1888
1848 out: 1889 out:
1849 fd_putfile(SCARG(uap, fd)); 1890 fd_putfile(SCARG(uap, fd));
1850 return error; 1891 return error;
1851} 1892}

cvs diff -r1.26 -r1.26.56.1 src/sys/compat/svr4_32/Attic/svr4_32_signal.c (switch to unified diff)

--- src/sys/compat/svr4_32/Attic/svr4_32_signal.c 2008/04/28 20:23:46 1.26
+++ src/sys/compat/svr4_32/Attic/svr4_32_signal.c 2017/08/19 03:40:48 1.26.56.1
@@ -1,646 +1,674 @@ @@ -1,646 +1,674 @@
1/* $NetBSD: svr4_32_signal.c,v 1.26 2008/04/28 20:23:46 martin Exp $ */ 1/* $NetBSD: svr4_32_signal.c,v 1.26.56.1 2017/08/19 03:40:48 snj Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1994, 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1994, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas and by Charles M. Hannum. 8 * by Christos Zoulas and by Charles M. Hannum.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright 15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the 16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution. 17 * documentation and/or other materials provided with the distribution.
18 * 18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE. 29 * POSSIBILITY OF SUCH DAMAGE.
30 */ 30 */
31 31
32#include <sys/cdefs.h> 32#include <sys/cdefs.h>
33__KERNEL_RCSID(0, "$NetBSD: svr4_32_signal.c,v 1.26 2008/04/28 20:23:46 martin Exp $"); 33__KERNEL_RCSID(0, "$NetBSD: svr4_32_signal.c,v 1.26.56.1 2017/08/19 03:40:48 snj Exp $");
34 34
35#if defined(_KERNEL_OPT) 35#if defined(_KERNEL_OPT)
36#include "opt_compat_svr4.h" 36#include "opt_compat_svr4.h"
37#endif 37#endif
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/namei.h> 41#include <sys/namei.h>
42#include <sys/proc.h> 42#include <sys/proc.h>
43#include <sys/filedesc.h> 43#include <sys/filedesc.h>
44#include <sys/ioctl.h> 44#include <sys/ioctl.h>
45#include <sys/mount.h> 45#include <sys/mount.h>
46#include <sys/kernel.h> 46#include <sys/kernel.h>
47#include <sys/signal.h> 47#include <sys/signal.h>
48#include <sys/signalvar.h> 48#include <sys/signalvar.h>
49#include <sys/malloc.h> 49#include <sys/malloc.h>
50#include <sys/wait.h> 50#include <sys/wait.h>
51 51
52#include <sys/syscallargs.h> 52#include <sys/syscallargs.h>
53 53
54#include <compat/svr4_32/svr4_32_types.h> 54#include <compat/svr4_32/svr4_32_types.h>
55#include <compat/svr4_32/svr4_32_signal.h> 55#include <compat/svr4_32/svr4_32_signal.h>
56#include <compat/svr4_32/svr4_32_lwp.h> 56#include <compat/svr4_32/svr4_32_lwp.h>
57#include <compat/svr4_32/svr4_32_ucontext.h> 57#include <compat/svr4_32/svr4_32_ucontext.h>
58#include <compat/svr4_32/svr4_32_syscallargs.h> 58#include <compat/svr4_32/svr4_32_syscallargs.h>
59#include <compat/svr4_32/svr4_32_util.h> 59#include <compat/svr4_32/svr4_32_util.h>
60 60
61#include <compat/common/compat_sigaltstack.h> 61#include <compat/common/compat_sigaltstack.h>
62 62
63#define svr4_sigmask(n) (1 << (((n) - 1) & 31)) 63#define svr4_sigmask(n) (1 << (((n) - 1) & 31))
64#define svr4_sigword(n) (((n) - 1) >> 5) 64#define svr4_sigword(n) (((n) - 1) >> 5)
65#define svr4_sigemptyset(s) memset((s), 0, sizeof(*(s))) 65#define svr4_sigemptyset(s) memset((s), 0, sizeof(*(s)))
66#define svr4_sigismember(s, n) ((s)->bits[svr4_sigword(n)] & svr4_sigmask(n)) 66#define svr4_sigismember(s, n) ((s)->bits[svr4_sigword(n)] & svr4_sigmask(n))
67#define svr4_sigaddset(s, n) ((s)->bits[svr4_sigword(n)] |= svr4_sigmask(n)) 67#define svr4_sigaddset(s, n) ((s)->bits[svr4_sigword(n)] |= svr4_sigmask(n))
68 68
69static inline void svr4_32_sigfillset(svr4_32_sigset_t *); 69static inline void svr4_32_sigfillset(svr4_32_sigset_t *);
70void svr4_32_to_native_sigaction(const struct svr4_32_sigaction *, 70void svr4_32_to_native_sigaction(const struct svr4_32_sigaction *,
71 struct sigaction *); 71 struct sigaction *);
72void native_to_svr4_32_sigaction(const struct sigaction *, 72void native_to_svr4_32_sigaction(const struct sigaction *,
73 struct svr4_32_sigaction *); 73 struct svr4_32_sigaction *);
74 74
75#ifndef COMPAT_SVR4 75#ifndef COMPAT_SVR4
76const int native_to_svr4_signo[NSIG] = { 76const int native_to_svr4_signo[NSIG] = {
77 0, /* 0 */ 77 0, /* 0 */
78 SVR4_SIGHUP, /* 1 */ 78 SVR4_SIGHUP, /* 1 */
79 SVR4_SIGINT, /* 2 */ 79 SVR4_SIGINT, /* 2 */
80 SVR4_SIGQUIT, /* 3 */ 80 SVR4_SIGQUIT, /* 3 */
81 SVR4_SIGILL, /* 4 */ 81 SVR4_SIGILL, /* 4 */
82 SVR4_SIGTRAP, /* 5 */ 82 SVR4_SIGTRAP, /* 5 */
83 SVR4_SIGABRT, /* 6 */ 83 SVR4_SIGABRT, /* 6 */
84 SVR4_SIGEMT, /* 7 */ 84 SVR4_SIGEMT, /* 7 */
85 SVR4_SIGFPE, /* 8 */ 85 SVR4_SIGFPE, /* 8 */
86 SVR4_SIGKILL, /* 9 */ 86 SVR4_SIGKILL, /* 9 */
87 SVR4_SIGBUS, /* 10 */ 87 SVR4_SIGBUS, /* 10 */
88 SVR4_SIGSEGV, /* 11 */ 88 SVR4_SIGSEGV, /* 11 */
89 SVR4_SIGSYS, /* 12 */ 89 SVR4_SIGSYS, /* 12 */
90 SVR4_SIGPIPE, /* 13 */ 90 SVR4_SIGPIPE, /* 13 */
91 SVR4_SIGALRM, /* 14 */ 91 SVR4_SIGALRM, /* 14 */
92 SVR4_SIGTERM, /* 15 */ 92 SVR4_SIGTERM, /* 15 */
93 SVR4_SIGURG, /* 16 */ 93 SVR4_SIGURG, /* 16 */
94 SVR4_SIGSTOP, /* 17 */ 94 SVR4_SIGSTOP, /* 17 */
95 SVR4_SIGTSTP, /* 18 */ 95 SVR4_SIGTSTP, /* 18 */
96 SVR4_SIGCONT, /* 19 */ 96 SVR4_SIGCONT, /* 19 */
97 SVR4_SIGCHLD, /* 20 */ 97 SVR4_SIGCHLD, /* 20 */
98 SVR4_SIGTTIN, /* 21 */ 98 SVR4_SIGTTIN, /* 21 */
99 SVR4_SIGTTOU, /* 22 */ 99 SVR4_SIGTTOU, /* 22 */
100 SVR4_SIGIO, /* 23 */ 100 SVR4_SIGIO, /* 23 */
101 SVR4_SIGXCPU, /* 24 */ 101 SVR4_SIGXCPU, /* 24 */
102 SVR4_SIGXFSZ, /* 25 */ 102 SVR4_SIGXFSZ, /* 25 */
103 SVR4_SIGVTALRM, /* 26 */ 103 SVR4_SIGVTALRM, /* 26 */
104 SVR4_SIGPROF, /* 27 */ 104 SVR4_SIGPROF, /* 27 */
105 SVR4_SIGWINCH, /* 28 */ 105 SVR4_SIGWINCH, /* 28 */
106 0, /* 29 SIGINFO */ 106 0, /* 29 SIGINFO */
107 SVR4_SIGUSR1, /* 30 */ 107 SVR4_SIGUSR1, /* 30 */
108 SVR4_SIGUSR2, /* 31 */ 108 SVR4_SIGUSR2, /* 31 */
109 SVR4_SIGPWR, /* 32 */ 109 SVR4_SIGPWR, /* 32 */
110 SVR4_SIGRTMIN + 0, /* 33 */ 110 SVR4_SIGRTMIN + 0, /* 33 */
111 SVR4_SIGRTMIN + 1, /* 34 */ 111 SVR4_SIGRTMIN + 1, /* 34 */
112 SVR4_SIGRTMIN + 2, /* 35 */ 112 SVR4_SIGRTMIN + 2, /* 35 */
113 SVR4_SIGRTMIN + 3, /* 36 */ 113 SVR4_SIGRTMIN + 3, /* 36 */
114 SVR4_SIGRTMIN + 4, /* 37 */ 114 SVR4_SIGRTMIN + 4, /* 37 */
115 SVR4_SIGRTMIN + 5, /* 38 */ 115 SVR4_SIGRTMIN + 5, /* 38 */
116 SVR4_SIGRTMIN + 6, /* 39 */ 116 SVR4_SIGRTMIN + 6, /* 39 */
117 SVR4_SIGRTMIN + 7, /* 40 */ 117 SVR4_SIGRTMIN + 7, /* 40 */
118 SVR4_SIGRTMIN + 8, /* 41 */ 118 SVR4_SIGRTMIN + 8, /* 41 */
119 SVR4_SIGRTMIN + 9, /* 42 */ 119 SVR4_SIGRTMIN + 9, /* 42 */
120 SVR4_SIGRTMIN + 10, /* 43 */ 120 SVR4_SIGRTMIN + 10, /* 43 */
121 SVR4_SIGRTMIN + 11, /* 44 */ 121 SVR4_SIGRTMIN + 11, /* 44 */
122 SVR4_SIGRTMIN + 12, /* 45 */ 122 SVR4_SIGRTMIN + 12, /* 45 */
123 SVR4_SIGRTMIN + 13, /* 46 */ 123 SVR4_SIGRTMIN + 13, /* 46 */
124 SVR4_SIGRTMIN + 14, /* 47 */ 124 SVR4_SIGRTMIN + 14, /* 47 */
125 SVR4_SIGRTMIN + 15, /* 48 */ 125 SVR4_SIGRTMIN + 15, /* 48 */
126 SVR4_SIGRTMIN + 16, /* 49 */ 126 SVR4_SIGRTMIN + 16, /* 49 */
127 SVR4_SIGRTMIN + 17, /* 50 */ 127 SVR4_SIGRTMIN + 17, /* 50 */
128 SVR4_SIGRTMIN + 18, /* 51 */ 128 SVR4_SIGRTMIN + 18, /* 51 */
129 SVR4_SIGRTMIN + 19, /* 52 */ 129 SVR4_SIGRTMIN + 19, /* 52 */
130 SVR4_SIGRTMIN + 20, /* 53 */ 130 SVR4_SIGRTMIN + 20, /* 53 */
131 SVR4_SIGRTMIN + 21, /* 54 */ 131 SVR4_SIGRTMIN + 21, /* 54 */
132 SVR4_SIGRTMIN + 22, /* 55 */ 132 SVR4_SIGRTMIN + 22, /* 55 */
133 SVR4_SIGRTMIN + 23, /* 56 */ 133 SVR4_SIGRTMIN + 23, /* 56 */
134 SVR4_SIGRTMIN + 24, /* 57 */ 134 SVR4_SIGRTMIN + 24, /* 57 */
135 SVR4_SIGRTMIN + 25, /* 58 */ 135 SVR4_SIGRTMIN + 25, /* 58 */
136 SVR4_SIGRTMIN + 26, /* 59 */ 136 SVR4_SIGRTMIN + 26, /* 59 */
137 SVR4_SIGRTMIN + 27, /* 60 */ 137 SVR4_SIGRTMIN + 27, /* 60 */
138 SVR4_SIGRTMIN + 28, /* 61 */ 138 SVR4_SIGRTMIN + 28, /* 61 */
139 SVR4_SIGRTMIN + 29, /* 62 */ 139 SVR4_SIGRTMIN + 29, /* 62 */
140 SVR4_SIGRTMIN + 30, /* 63 */ 140 SVR4_SIGRTMIN + 30, /* 63 */
141}; 141};
142 142
143const int svr4_to_native_signo[SVR4_NSIG] = { 143const int svr4_to_native_signo[SVR4_NSIG] = {
144 0, /* 0 */ 144 0, /* 0 */
145 SIGHUP, /* 1 */ 145 SIGHUP, /* 1 */
146 SIGINT, /* 2 */ 146 SIGINT, /* 2 */
147 SIGQUIT, /* 3 */ 147 SIGQUIT, /* 3 */
148 SIGILL, /* 4 */ 148 SIGILL, /* 4 */
149 SIGTRAP, /* 5 */ 149 SIGTRAP, /* 5 */
150 SIGABRT, /* 6 */ 150 SIGABRT, /* 6 */
151 SIGEMT, /* 7 */ 151 SIGEMT, /* 7 */
152 SIGFPE, /* 8 */ 152 SIGFPE, /* 8 */
153 SIGKILL, /* 9 */ 153 SIGKILL, /* 9 */
154 SIGBUS, /* 10 */ 154 SIGBUS, /* 10 */
155 SIGSEGV, /* 11 */ 155 SIGSEGV, /* 11 */
156 SIGSYS, /* 12 */ 156 SIGSYS, /* 12 */
157 SIGPIPE, /* 13 */ 157 SIGPIPE, /* 13 */
158 SIGALRM, /* 14 */ 158 SIGALRM, /* 14 */
159 SIGTERM, /* 15 */ 159 SIGTERM, /* 15 */
160 SIGUSR1, /* 16 */ 160 SIGUSR1, /* 16 */
161 SIGUSR2, /* 17 */ 161 SIGUSR2, /* 17 */
162 SIGCHLD, /* 18 */ 162 SIGCHLD, /* 18 */
163 SIGPWR, /* 19 */ 163 SIGPWR, /* 19 */
164 SIGWINCH, /* 20 */ 164 SIGWINCH, /* 20 */
165 SIGURG, /* 21 */ 165 SIGURG, /* 21 */
166 SIGIO, /* 22 */ 166 SIGIO, /* 22 */
167 SIGSTOP, /* 23 */ 167 SIGSTOP, /* 23 */
168 SIGTSTP, /* 24 */ 168 SIGTSTP, /* 24 */
169 SIGCONT, /* 25 */ 169 SIGCONT, /* 25 */
170 SIGTTIN, /* 26 */ 170 SIGTTIN, /* 26 */
171 SIGTTOU, /* 27 */ 171 SIGTTOU, /* 27 */
172 SIGVTALRM, /* 28 */ 172 SIGVTALRM, /* 28 */
173 SIGPROF, /* 29 */ 173 SIGPROF, /* 29 */
174 SIGXCPU, /* 30 */ 174 SIGXCPU, /* 30 */
175 SIGXFSZ, /* 31 */ 175 SIGXFSZ, /* 31 */
176 SIGRTMIN + 0, /* 32 */ 176 SIGRTMIN + 0, /* 32 */
177 SIGRTMIN + 1, /* 33 */ 177 SIGRTMIN + 1, /* 33 */
178 SIGRTMIN + 2, /* 34 */ 178 SIGRTMIN + 2, /* 34 */
179 SIGRTMIN + 3, /* 35 */ 179 SIGRTMIN + 3, /* 35 */
180 SIGRTMIN + 4, /* 36 */ 180 SIGRTMIN + 4, /* 36 */
181 SIGRTMIN + 5, /* 37 */ 181 SIGRTMIN + 5, /* 37 */
182 SIGRTMIN + 6, /* 38 */ 182 SIGRTMIN + 6, /* 38 */
183 SIGRTMIN + 7, /* 39 */ 183 SIGRTMIN + 7, /* 39 */
184 SIGRTMIN + 8, /* 40 */ 184 SIGRTMIN + 8, /* 40 */
185 SIGRTMIN + 9, /* 41 */ 185 SIGRTMIN + 9, /* 41 */
186 SIGRTMIN + 10, /* 42 */ 186 SIGRTMIN + 10, /* 42 */
187 SIGRTMIN + 11, /* 43 */ 187 SIGRTMIN + 11, /* 43 */
188 SIGRTMIN + 12, /* 44 */ 188 SIGRTMIN + 12, /* 44 */
189 SIGRTMIN + 13, /* 45 */ 189 SIGRTMIN + 13, /* 45 */
190 SIGRTMIN + 14, /* 46 */ 190 SIGRTMIN + 14, /* 46 */
191 SIGRTMIN + 15, /* 47 */ 191 SIGRTMIN + 15, /* 47 */
192 SIGRTMIN + 16, /* 48 */ 192 SIGRTMIN + 16, /* 48 */
193 SIGRTMIN + 17, /* 49 */ 193 SIGRTMIN + 17, /* 49 */
194 SIGRTMIN + 18, /* 50 */ 194 SIGRTMIN + 18, /* 50 */
195 SIGRTMIN + 19, /* 51 */ 195 SIGRTMIN + 19, /* 51 */
196 SIGRTMIN + 20, /* 52 */ 196 SIGRTMIN + 20, /* 52 */
197 SIGRTMIN + 21, /* 53 */ 197 SIGRTMIN + 21, /* 53 */
198 SIGRTMIN + 22, /* 54 */ 198 SIGRTMIN + 22, /* 54 */
199 SIGRTMIN + 23, /* 55 */ 199 SIGRTMIN + 23, /* 55 */
200 SIGRTMIN + 24, /* 56 */ 200 SIGRTMIN + 24, /* 56 */
201 SIGRTMIN + 25, /* 57 */ 201 SIGRTMIN + 25, /* 57 */
202 SIGRTMIN + 26, /* 58 */ 202 SIGRTMIN + 26, /* 58 */
203 SIGRTMIN + 27, /* 59 */ 203 SIGRTMIN + 27, /* 59 */
204 SIGRTMIN + 28, /* 60 */ 204 SIGRTMIN + 28, /* 60 */
205 SIGRTMIN + 29, /* 61 */ 205 SIGRTMIN + 29, /* 61 */
206 SIGRTMIN + 30, /* 62 */ 206 SIGRTMIN + 30, /* 62 */
207 0, /* 63 */ 207 0, /* 63 */
208}; 208};
209#endif 209#endif
210 210
 211static int
 212svr4_32_decode_signum(int signum, int *native_signo, int *sigcall)
 213{
 214
 215 if (SVR4_SIGNO(signum) >= SVR4_NSIG)
 216 return EINVAL;
 217
 218 if (native_signo)
 219 *native_signo = svr4_to_native_signo[SVR4_SIGNO(signum)];
 220 if (sigcall)
 221 *sigcall = SVR4_SIGCALL(signum);
 222
 223 return 0;
 224}
 225
211static inline void 226static inline void
212svr4_32_sigfillset(svr4_32_sigset_t *s) 227svr4_32_sigfillset(svr4_32_sigset_t *s)
213{ 228{
214 int i; 229 int i;
215 230
216 svr4_sigemptyset(s); 231 svr4_sigemptyset(s);
217 for (i = 1; i < SVR4_NSIG; i++) 232 for (i = 1; i < SVR4_NSIG; i++)
218 if (svr4_to_native_signo[i] != 0) 233 if (svr4_to_native_signo[i] != 0)
219 svr4_sigaddset(s, i); 234 svr4_sigaddset(s, i);
220} 235}
221 236
222void 237void
223svr4_32_to_native_sigset(const svr4_32_sigset_t *sss, sigset_t *bss) 238svr4_32_to_native_sigset(const svr4_32_sigset_t *sss, sigset_t *bss)
224{ 239{
225 int i, newsig; 240 int i, newsig;
226 241
227 sigemptyset(bss); 242 sigemptyset(bss);
228 for (i = 1; i < SVR4_NSIG; i++) { 243 for (i = 1; i < SVR4_NSIG; i++) {
229 if (svr4_sigismember(sss, i)) { 244 if (svr4_sigismember(sss, i)) {
230 newsig = svr4_to_native_signo[i]; 245 newsig = svr4_to_native_signo[i];
231 if (newsig) 246 if (newsig)
232 sigaddset(bss, newsig); 247 sigaddset(bss, newsig);
233 } 248 }
234 } 249 }
235} 250}
236 251
237 252
238void 253void
239native_to_svr4_32_sigset(const sigset_t *bss, svr4_32_sigset_t *sss) 254native_to_svr4_32_sigset(const sigset_t *bss, svr4_32_sigset_t *sss)
240{ 255{
241 int i, newsig; 256 int i, newsig;
242 257
243 svr4_sigemptyset(sss); 258 svr4_sigemptyset(sss);
244 for (i = 1; i < NSIG; i++) { 259 for (i = 1; i < NSIG; i++) {
245 if (sigismember(bss, i)) { 260 if (sigismember(bss, i)) {
246 newsig = native_to_svr4_signo[i]; 261 newsig = native_to_svr4_signo[i];
247 if (newsig) 262 if (newsig)
248 svr4_sigaddset(sss, newsig); 263 svr4_sigaddset(sss, newsig);
249 } 264 }
250 } 265 }
251} 266}
252 267
253/* 268/*
254 * XXX: Only a subset of the flags is currently implemented. 269 * XXX: Only a subset of the flags is currently implemented.
255 */ 270 */
256void 271void
257svr4_32_to_native_sigaction(const struct svr4_32_sigaction *ssa, struct sigaction *bsa) 272svr4_32_to_native_sigaction(const struct svr4_32_sigaction *ssa, struct sigaction *bsa)
258{ 273{
259 274
260 bsa->sa_handler = NETBSD32PTR64(ssa->svr4_32_sa_handler); 275 bsa->sa_handler = NETBSD32PTR64(ssa->svr4_32_sa_handler);
261 svr4_32_to_native_sigset(&ssa->svr4_32_sa_mask, &bsa->sa_mask); 276 svr4_32_to_native_sigset(&ssa->svr4_32_sa_mask, &bsa->sa_mask);
262 bsa->sa_flags = 0; 277 bsa->sa_flags = 0;
263 if ((ssa->svr4_32_sa_flags & SVR4_SA_ONSTACK) != 0) 278 if ((ssa->svr4_32_sa_flags & SVR4_SA_ONSTACK) != 0)
264 bsa->sa_flags |= SA_ONSTACK; 279 bsa->sa_flags |= SA_ONSTACK;
265 if ((ssa->svr4_32_sa_flags & SVR4_SA_RESETHAND) != 0) 280 if ((ssa->svr4_32_sa_flags & SVR4_SA_RESETHAND) != 0)
266 bsa->sa_flags |= SA_RESETHAND; 281 bsa->sa_flags |= SA_RESETHAND;
267 if ((ssa->svr4_32_sa_flags & SVR4_SA_RESTART) != 0) 282 if ((ssa->svr4_32_sa_flags & SVR4_SA_RESTART) != 0)
268 bsa->sa_flags |= SA_RESTART; 283 bsa->sa_flags |= SA_RESTART;
269 if ((ssa->svr4_32_sa_flags & SVR4_SA_SIGINFO) != 0) { 284 if ((ssa->svr4_32_sa_flags & SVR4_SA_SIGINFO) != 0) {
270 DPRINTF(("svr4_to_native_sigaction: SA_SIGINFO ignored\n")); 285 DPRINTF(("svr4_to_native_sigaction: SA_SIGINFO ignored\n"));
271 } 286 }
272 if ((ssa->svr4_32_sa_flags & SVR4_SA_NODEFER) != 0) 287 if ((ssa->svr4_32_sa_flags & SVR4_SA_NODEFER) != 0)
273 bsa->sa_flags |= SA_NODEFER; 288 bsa->sa_flags |= SA_NODEFER;
274 if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDWAIT) != 0) 289 if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDWAIT) != 0)
275 bsa->sa_flags |= SA_NOCLDWAIT; 290 bsa->sa_flags |= SA_NOCLDWAIT;
276 if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDSTOP) != 0) 291 if ((ssa->svr4_32_sa_flags & SVR4_SA_NOCLDSTOP) != 0)
277 bsa->sa_flags |= SA_NOCLDSTOP; 292 bsa->sa_flags |= SA_NOCLDSTOP;
278 if ((ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS) != 0) { 293 if ((ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS) != 0) {
279 DPRINTF(("svr4_32_to_native_sigaction: extra bits %x ignored\n", 294 DPRINTF(("svr4_32_to_native_sigaction: extra bits %x ignored\n",
280 ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS)); 295 ssa->svr4_32_sa_flags & ~SVR4_SA_ALLBITS));
281 } 296 }
282} 297}
283 298
284void 299void
285native_to_svr4_32_sigaction(const struct sigaction *bsa, struct svr4_32_sigaction *ssa) 300native_to_svr4_32_sigaction(const struct sigaction *bsa, struct svr4_32_sigaction *ssa)
286{ 301{
287 302
288 NETBSD32PTR32(ssa->svr4_32_sa_handler, bsa->sa_handler); 303 NETBSD32PTR32(ssa->svr4_32_sa_handler, bsa->sa_handler);
289 native_to_svr4_32_sigset(&bsa->sa_mask, &ssa->svr4_32_sa_mask); 304 native_to_svr4_32_sigset(&bsa->sa_mask, &ssa->svr4_32_sa_mask);
290 ssa->svr4_32_sa_flags = 0; 305 ssa->svr4_32_sa_flags = 0;
291 if ((bsa->sa_flags & SA_ONSTACK) != 0) 306 if ((bsa->sa_flags & SA_ONSTACK) != 0)
292 ssa->svr4_32_sa_flags |= SVR4_SA_ONSTACK; 307 ssa->svr4_32_sa_flags |= SVR4_SA_ONSTACK;
293 if ((bsa->sa_flags & SA_RESETHAND) != 0) 308 if ((bsa->sa_flags & SA_RESETHAND) != 0)
294 ssa->svr4_32_sa_flags |= SVR4_SA_RESETHAND; 309 ssa->svr4_32_sa_flags |= SVR4_SA_RESETHAND;
295 if ((bsa->sa_flags & SA_RESTART) != 0) 310 if ((bsa->sa_flags & SA_RESTART) != 0)
296 ssa->svr4_32_sa_flags |= SVR4_SA_RESTART; 311 ssa->svr4_32_sa_flags |= SVR4_SA_RESTART;
297 if ((bsa->sa_flags & SA_NODEFER) != 0) 312 if ((bsa->sa_flags & SA_NODEFER) != 0)
298 ssa->svr4_32_sa_flags |= SVR4_SA_NODEFER; 313 ssa->svr4_32_sa_flags |= SVR4_SA_NODEFER;
299 if ((bsa->sa_flags & SA_NOCLDSTOP) != 0) 314 if ((bsa->sa_flags & SA_NOCLDSTOP) != 0)
300 ssa->svr4_32_sa_flags |= SVR4_SA_NOCLDSTOP; 315 ssa->svr4_32_sa_flags |= SVR4_SA_NOCLDSTOP;
301} 316}
302 317
303int 318int
304svr4_32_sys_sigaction(struct lwp *l, const struct svr4_32_sys_sigaction_args *uap, register_t *retval) 319svr4_32_sys_sigaction(struct lwp *l, const struct svr4_32_sys_sigaction_args *uap, register_t *retval)
305{ 320{
306 /* { 321 /* {
307 syscallarg(int) signum; 322 syscallarg(int) signum;
308 syscallarg(const struct svr4_32_sigaction *) nsa; 323 syscallarg(const struct svr4_32_sigaction *) nsa;
309 syscallarg(struct svr4_32_sigaction *) osa; 324 syscallarg(struct svr4_32_sigaction *) osa;
310 } */ 325 } */
311 struct svr4_32_sigaction nssa, ossa; 326 struct svr4_32_sigaction nssa, ossa;
312 struct sigaction nbsa, obsa; 327 struct sigaction nbsa, obsa;
 328 int native_signo;
313 int error; 329 int error;
314 330
315 if (SCARG_P32(uap, nsa)) { 331 if (SCARG_P32(uap, nsa)) {
316 error = copyin(SCARG_P32(uap, nsa), 332 error = copyin(SCARG_P32(uap, nsa),
317 &nssa, sizeof(nssa)); 333 &nssa, sizeof(nssa));
318 if (error) 334 if (error)
319 return (error); 335 return (error);
320 svr4_32_to_native_sigaction(&nssa, &nbsa); 336 svr4_32_to_native_sigaction(&nssa, &nbsa);
321 } 337 }
322 error = sigaction1(l, 338
323 svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))], 339 error = svr4_32_decode_signum(SCARG(uap, signum), &native_signo, NULL);
 340 if (error)
 341 return error;
 342
 343 error = sigaction1(l, native_signo,
324 SCARG_P32(uap, nsa) ? &nbsa : 0, SCARG_P32(uap, osa) ? &obsa : 0, 344 SCARG_P32(uap, nsa) ? &nbsa : 0, SCARG_P32(uap, osa) ? &obsa : 0,
325 NULL, 0); 345 NULL, 0);
326 if (error) 346 if (error)
327 return (error); 347 return (error);
328 if (SCARG_P32(uap, osa)) { 348 if (SCARG_P32(uap, osa)) {
329 native_to_svr4_32_sigaction(&obsa, &ossa); 349 native_to_svr4_32_sigaction(&obsa, &ossa);
330 error = copyout(&ossa, SCARG_P32(uap, osa), 350 error = copyout(&ossa, SCARG_P32(uap, osa),
331 sizeof(ossa)); 351 sizeof(ossa));
332 if (error) 352 if (error)
333 return (error); 353 return (error);
334 } 354 }
335 return (0); 355 return (0);
336} 356}
337 357
338int 358int
339svr4_32_sys_sigaltstack(struct lwp *l, const struct svr4_32_sys_sigaltstack_args *uap, register_t *retval) 359svr4_32_sys_sigaltstack(struct lwp *l, const struct svr4_32_sys_sigaltstack_args *uap, register_t *retval)
340{ 360{
341 /* { 361 /* {
342 syscallarg(const struct svr4_32_sigaltstack_tp) nss; 362 syscallarg(const struct svr4_32_sigaltstack_tp) nss;
343 syscallarg(struct svr4_32_sigaltstack_tp) oss; 363 syscallarg(struct svr4_32_sigaltstack_tp) oss;
344 } */ 364 } */
345 compat_sigaltstack(uap, svr4_32_sigaltstack, 365 compat_sigaltstack(uap, svr4_32_sigaltstack,
346 SVR4_SS_ONSTACK, SVR4_SS_DISABLE); 366 SVR4_SS_ONSTACK, SVR4_SS_DISABLE);
347} 367}
348 368
349/* 369/*
350 * Stolen from the ibcs2 one 370 * Stolen from the ibcs2 one
351 */ 371 */
352int 372int
353svr4_32_sys_signal(struct lwp *l, const struct svr4_32_sys_signal_args *uap, register_t *retval) 373svr4_32_sys_signal(struct lwp *l, const struct svr4_32_sys_signal_args *uap, register_t *retval)
354{ 374{
355 /* { 375 /* {
356 syscallarg(int) signum; 376 syscallarg(int) signum;
357 syscallarg(svr4_32_sig_t) handler; 377 syscallarg(svr4_32_sig_t) handler;
358 } */ 378 } */
359 struct proc *p = l->l_proc; 379 struct proc *p = l->l_proc;
360 int signum = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))]; 380 int native_signo, sigcall;
361 struct sigaction nbsa, obsa; 381 struct sigaction nbsa, obsa;
362 sigset_t ss; 382 sigset_t ss;
363 int error; 383 int error;
364 384
365 if (signum <= 0 || signum >= SVR4_NSIG) 385 error = svr4_32_decode_signum(SCARG(uap, signum), &native_signo,
366 return (EINVAL); 386 &sigcall);
 387 if (error)
 388 return error;
367 389
368 switch (SVR4_SIGCALL(SCARG(uap, signum))) { 390 switch (sigcall) {
369 case SVR4_SIGDEFER_MASK: 391 case SVR4_SIGDEFER_MASK:
370 if (SCARG(uap, handler) == SVR4_SIG_HOLD) 392 if (SCARG(uap, handler) == SVR4_SIG_HOLD)
371 goto sighold; 393 goto sighold;
372 /* FALLTHROUGH */ 394 /* FALLTHROUGH */
373 395
374 case SVR4_SIGNAL_MASK: 396 case SVR4_SIGNAL_MASK:
375 nbsa.sa_handler = (sig_t)SCARG(uap, handler); 397 nbsa.sa_handler = (sig_t)SCARG(uap, handler);
376 sigemptyset(&nbsa.sa_mask); 398 sigemptyset(&nbsa.sa_mask);
377 nbsa.sa_flags = 0; 399 nbsa.sa_flags = 0;
378 error = sigaction1(l, signum, &nbsa, &obsa, NULL, 0); 400 error = sigaction1(l, signum, &nbsa, &obsa, NULL, 0);
379 if (error) 401 if (error)
380 return (error); 402 return (error);
381 *retval = (u_int)(u_long)obsa.sa_handler; 403 *retval = (u_int)(u_long)obsa.sa_handler;
382 return (0); 404 return (0);
383 405
384 case SVR4_SIGHOLD_MASK: 406 case SVR4_SIGHOLD_MASK:
385 sighold: 407 sighold:
386 sigemptyset(&ss); 408 sigemptyset(&ss);
387 sigaddset(&ss, signum); 409 sigaddset(&ss, signum);
388 mutex_enter(p->p_lock); 410 mutex_enter(p->p_lock);
389 error = sigprocmask1(l, SIG_BLOCK, &ss, 0); 411 error = sigprocmask1(l, SIG_BLOCK, &ss, 0);
390 mutex_exit(p->p_lock); 412 mutex_exit(p->p_lock);
391 return error; 413 return error;
392 414
393 case SVR4_SIGRELSE_MASK: 415 case SVR4_SIGRELSE_MASK:
394 sigemptyset(&ss); 416 sigemptyset(&ss);
395 sigaddset(&ss, signum); 417 sigaddset(&ss, signum);
396 mutex_enter(p->p_lock); 418 mutex_enter(p->p_lock);
397 error = sigprocmask1(l, SIG_UNBLOCK, &ss, 0); 419 error = sigprocmask1(l, SIG_UNBLOCK, &ss, 0);
398 mutex_exit(p->p_lock); 420 mutex_exit(p->p_lock);
399 return error; 421 return error;
400 422
401 case SVR4_SIGIGNORE_MASK: 423 case SVR4_SIGIGNORE_MASK:
402 nbsa.sa_handler = SIG_IGN; 424 nbsa.sa_handler = SIG_IGN;
403 sigemptyset(&nbsa.sa_mask); 425 sigemptyset(&nbsa.sa_mask);
404 nbsa.sa_flags = 0; 426 nbsa.sa_flags = 0;
405 return (sigaction1(l, signum, &nbsa, 0, NULL, 0)); 427 return (sigaction1(l, signum, &nbsa, 0, NULL, 0));
406 428
407 case SVR4_SIGPAUSE_MASK: 429 case SVR4_SIGPAUSE_MASK:
408 mutex_enter(p->p_lock); 430 mutex_enter(p->p_lock);
409 ss = l->l_sigmask; 431 ss = l->l_sigmask;
410 mutex_exit(p->p_lock); 432 mutex_exit(p->p_lock);
411 sigdelset(&ss, signum); 433 sigdelset(&ss, signum);
412 return (sigsuspend1(l, &ss)); 434 return (sigsuspend1(l, &ss));
413 435
414 default: 436 default:
415 return (ENOSYS); 437 return (ENOSYS);
416 } 438 }
417} 439}
418 440
419int 441int
420svr4_32_sys_sigprocmask(struct lwp *l, const struct svr4_32_sys_sigprocmask_args *uap, register_t *retval) 442svr4_32_sys_sigprocmask(struct lwp *l, const struct svr4_32_sys_sigprocmask_args *uap, register_t *retval)
421{ 443{
422 /* { 444 /* {
423 syscallarg(int) how; 445 syscallarg(int) how;
424 syscallarg(const svr4_32_sigset_t *) set; 446 syscallarg(const svr4_32_sigset_t *) set;
425 syscallarg(svr4_32_sigset_t *) oset; 447 syscallarg(svr4_32_sigset_t *) oset;
426 } */ 448 } */
427 struct proc *p = l->l_proc; 449 struct proc *p = l->l_proc;
428 svr4_32_sigset_t nsss, osss; 450 svr4_32_sigset_t nsss, osss;
429 sigset_t nbss, obss; 451 sigset_t nbss, obss;
430 int how; 452 int how;
431 int error; 453 int error;
432 454
433 /* 455 /*
434 * Initialize how to 0 to avoid a compiler warning. Note that 456 * Initialize how to 0 to avoid a compiler warning. Note that
435 * this is safe because of the check in the default: case. 457 * this is safe because of the check in the default: case.
436 */ 458 */
437 how = 0; 459 how = 0;
438 460
439 switch (SCARG(uap, how)) { 461 switch (SCARG(uap, how)) {
440 case SVR4_SIG_BLOCK: 462 case SVR4_SIG_BLOCK:
441 how = SIG_BLOCK; 463 how = SIG_BLOCK;
442 break; 464 break;
443 case SVR4_SIG_UNBLOCK: 465 case SVR4_SIG_UNBLOCK:
444 how = SIG_UNBLOCK; 466 how = SIG_UNBLOCK;
445 break; 467 break;
446 case SVR4_SIG_SETMASK: 468 case SVR4_SIG_SETMASK:
447 how = SIG_SETMASK; 469 how = SIG_SETMASK;
448 break; 470 break;
449 default: 471 default:
450 if (SCARG_P32(uap, set)) 472 if (SCARG_P32(uap, set))
451 return EINVAL; 473 return EINVAL;
452 break; 474 break;
453 } 475 }
454 476
455 if (SCARG_P32(uap, set)) { 477 if (SCARG_P32(uap, set)) {
456 error = copyin(SCARG_P32(uap, set), 478 error = copyin(SCARG_P32(uap, set),
457 &nsss, sizeof(nsss)); 479 &nsss, sizeof(nsss));
458 if (error) 480 if (error)
459 return error; 481 return error;
460 svr4_32_to_native_sigset(&nsss, &nbss); 482 svr4_32_to_native_sigset(&nsss, &nbss);
461 } 483 }
462 mutex_enter(p->p_lock); 484 mutex_enter(p->p_lock);
463 error = sigprocmask1(l, how, 485 error = sigprocmask1(l, how,
464 SCARG_P32(uap, set) ? &nbss : NULL, SCARG_P32(uap, oset) ? &obss : NULL); 486 SCARG_P32(uap, set) ? &nbss : NULL, SCARG_P32(uap, oset) ? &obss : NULL);
465 mutex_exit(p->p_lock); 487 mutex_exit(p->p_lock);
466 if (error) 488 if (error)
467 return error; 489 return error;
468 if (SCARG_P32(uap, oset)) { 490 if (SCARG_P32(uap, oset)) {
469 native_to_svr4_32_sigset(&obss, &osss); 491 native_to_svr4_32_sigset(&obss, &osss);
470 error = copyout(&osss, SCARG_P32(uap, oset), 492 error = copyout(&osss, SCARG_P32(uap, oset),
471 sizeof(osss)); 493 sizeof(osss));
472 if (error) 494 if (error)
473 return error; 495 return error;
474 } 496 }
475 return 0; 497 return 0;
476} 498}
477 499
478int 500int
479svr4_32_sys_sigpending(struct lwp *l, const struct svr4_32_sys_sigpending_args *uap, register_t *retval) 501svr4_32_sys_sigpending(struct lwp *l, const struct svr4_32_sys_sigpending_args *uap, register_t *retval)
480{ 502{
481 /* { 503 /* {
482 syscallarg(int) what; 504 syscallarg(int) what;
483 syscallarg(svr4_sigset_t *) set; 505 syscallarg(svr4_sigset_t *) set;
484 } */ 506 } */
485 sigset_t bss; 507 sigset_t bss;
486 svr4_32_sigset_t sss; 508 svr4_32_sigset_t sss;
487 509
488 switch (SCARG(uap, what)) { 510 switch (SCARG(uap, what)) {
489 case 1: /* sigpending */ 511 case 1: /* sigpending */
490 sigpending1(l, &bss); 512 sigpending1(l, &bss);
491 native_to_svr4_32_sigset(&bss, &sss); 513 native_to_svr4_32_sigset(&bss, &sss);
492 break; 514 break;
493 515
494 case 2: /* sigfillset */ 516 case 2: /* sigfillset */
495 svr4_32_sigfillset(&sss); 517 svr4_32_sigfillset(&sss);
496 break; 518 break;
497 519
498 default: 520 default:
499 return (EINVAL); 521 return (EINVAL);
500 } 522 }
501 return (copyout(&sss, SCARG_P32(uap, set), sizeof(sss))); 523 return (copyout(&sss, SCARG_P32(uap, set), sizeof(sss)));
502} 524}
503 525
504int 526int
505svr4_32_sys_sigsuspend(struct lwp *l, const struct svr4_32_sys_sigsuspend_args *uap, register_t *retval) 527svr4_32_sys_sigsuspend(struct lwp *l, const struct svr4_32_sys_sigsuspend_args *uap, register_t *retval)
506{ 528{
507 /* { 529 /* {
508 syscallarg(const svr4_32_sigset_t *) set; 530 syscallarg(const svr4_32_sigset_t *) set;
509 } */ 531 } */
510 svr4_32_sigset_t sss; 532 svr4_32_sigset_t sss;
511 sigset_t bss; 533 sigset_t bss;
512 int error; 534 int error;
513 535
514 if (SCARG_P32(uap, set)) { 536 if (SCARG_P32(uap, set)) {
515 error = copyin(SCARG_P32(uap, set), &sss, sizeof(sss)); 537 error = copyin(SCARG_P32(uap, set), &sss, sizeof(sss));
516 if (error) 538 if (error)
517 return (error); 539 return (error);
518 svr4_32_to_native_sigset(&sss, &bss); 540 svr4_32_to_native_sigset(&sss, &bss);
519 } 541 }
520 542
521 return (sigsuspend1(l, SCARG_P32(uap, set) ? &bss : 0)); 543 return (sigsuspend1(l, SCARG_P32(uap, set) ? &bss : 0));
522} 544}
523 545
524int 546int
525svr4_32_sys_pause(struct lwp *l, const void *v, register_t *retval) 547svr4_32_sys_pause(struct lwp *l, const void *v, register_t *retval)
526{ 548{
527 549
528 return (sigsuspend1(l, 0)); 550 return (sigsuspend1(l, 0));
529} 551}
530 552
531int 553int
532svr4_32_sys_kill(struct lwp *l, const struct svr4_32_sys_kill_args *uap, register_t *retval) 554svr4_32_sys_kill(struct lwp *l, const struct svr4_32_sys_kill_args *uap, register_t *retval)
533{ 555{
534 /* { 556 /* {
535 syscallarg(int) pid; 557 syscallarg(int) pid;
536 syscallarg(int) signum; 558 syscallarg(int) signum;
537 } */ 559 } */
538 struct sys_kill_args ka; 560 struct sys_kill_args ka;
 561 int native_signo;
 562 int error;
 563
 564 error = svr4_32_decode_signum(SCARG(uap, signum), &native_signo, NULL);
 565 if (error)
 566 return error;
539 567
540 SCARG(&ka, pid) = SCARG(uap, pid); 568 SCARG(&ka, pid) = SCARG(uap, pid);
541 SCARG(&ka, signum) = svr4_to_native_signo[SVR4_SIGNO(SCARG(uap, signum))]; 569 SCARG(&ka, signum) = native_signo;
542 return sys_kill(l, &ka, retval); 570 return sys_kill(l, &ka, retval);
543} 571}
544 572
545void 573void
546svr4_32_getcontext(struct lwp *l, struct svr4_32_ucontext *uc, const sigset_t *mask) 574svr4_32_getcontext(struct lwp *l, struct svr4_32_ucontext *uc, const sigset_t *mask)
547{ 575{
548 void *sp; 576 void *sp;
549 struct svr4_32_sigaltstack *ss = &uc->uc_stack; 577 struct svr4_32_sigaltstack *ss = &uc->uc_stack;
550 578
551 memset(uc, 0, sizeof(*uc)); 579 memset(uc, 0, sizeof(*uc));
552 580
553 /* get machine context */ 581 /* get machine context */
554 sp = svr4_32_getmcontext(l, &uc->uc_mcontext, &uc->uc_flags); 582 sp = svr4_32_getmcontext(l, &uc->uc_mcontext, &uc->uc_flags);
555 583
556 /* get link */ 584 /* get link */
557 NETBSD32PTR32(uc->uc_link, l->l_ctxlink); 585 NETBSD32PTR32(uc->uc_link, l->l_ctxlink);
558 586
559 /* get stack state. XXX: solaris appears to do this */ 587 /* get stack state. XXX: solaris appears to do this */
560#if 0 588#if 0
561 svr4_32_to_native_sigaltstack(&uc->uc_stack, &p->p_sigacts->ps_sigstk); 589 svr4_32_to_native_sigaltstack(&uc->uc_stack, &p->p_sigacts->ps_sigstk);
562#else 590#else
563 NETBSD32PTR32(ss->ss_sp, (void *)(((u_long) sp) & ~(16384 - 1))); 591 NETBSD32PTR32(ss->ss_sp, (void *)(((u_long) sp) & ~(16384 - 1)));
564 ss->ss_size = 16384; 592 ss->ss_size = 16384;
565 ss->ss_flags = 0; 593 ss->ss_flags = 0;
566#endif 594#endif
567 /* get signal mask */ 595 /* get signal mask */
568 mutex_enter(l->l_proc->p_lock); 596 mutex_enter(l->l_proc->p_lock);
569 native_to_svr4_32_sigset(mask, &uc->uc_sigmask); 597 native_to_svr4_32_sigset(mask, &uc->uc_sigmask);
570 mutex_exit(l->l_proc->p_lock); 598 mutex_exit(l->l_proc->p_lock);
571 599
572 uc->uc_flags |= SVR4_UC_STACK|SVR4_UC_SIGMASK; 600 uc->uc_flags |= SVR4_UC_STACK|SVR4_UC_SIGMASK;
573} 601}
574 602
575 603
576int 604int
577svr4_32_setcontext(struct lwp *l, struct svr4_32_ucontext *uc) 605svr4_32_setcontext(struct lwp *l, struct svr4_32_ucontext *uc)
578{ 606{
579 int error; 607 int error;
580 struct proc *p = l->l_proc; 608 struct proc *p = l->l_proc;
581 609
582 /* set machine context */ 610 /* set machine context */
583 if ((error = svr4_32_setmcontext(l, &uc->uc_mcontext, uc->uc_flags)) != 0) 611 if ((error = svr4_32_setmcontext(l, &uc->uc_mcontext, uc->uc_flags)) != 0)
584 return error; 612 return error;
585 613
586 /* set link */ 614 /* set link */
587 l->l_ctxlink = NETBSD32PTR64(uc->uc_link); 615 l->l_ctxlink = NETBSD32PTR64(uc->uc_link);
588 616
589 mutex_enter(p->p_lock); 617 mutex_enter(p->p_lock);
590 618
591 /* set signal stack */ 619 /* set signal stack */
592 if (uc->uc_flags & SVR4_UC_STACK) { 620 if (uc->uc_flags & SVR4_UC_STACK) {
593 l->l_sigstk.ss_sp = NETBSD32PTR64(uc->uc_stack.ss_sp); 621 l->l_sigstk.ss_sp = NETBSD32PTR64(uc->uc_stack.ss_sp);
594 l->l_sigstk.ss_size = uc->uc_stack.ss_size; 622 l->l_sigstk.ss_size = uc->uc_stack.ss_size;
595 l->l_sigstk.ss_flags = 623 l->l_sigstk.ss_flags =
596 (uc->uc_stack.ss_flags & SVR4_SS_ONSTACK ? SS_ONSTACK : 0) | 624 (uc->uc_stack.ss_flags & SVR4_SS_ONSTACK ? SS_ONSTACK : 0) |
597 (uc->uc_stack.ss_flags & SVR4_SS_DISABLE ? SS_DISABLE : 0); 625 (uc->uc_stack.ss_flags & SVR4_SS_DISABLE ? SS_DISABLE : 0);
598 } 626 }
599 627
600 /* set signal mask */ 628 /* set signal mask */
601 if (uc->uc_flags & SVR4_UC_SIGMASK) { 629 if (uc->uc_flags & SVR4_UC_SIGMASK) {
602 sigset_t mask; 630 sigset_t mask;
603 631
604 svr4_32_to_native_sigset(&uc->uc_sigmask, &mask); 632 svr4_32_to_native_sigset(&uc->uc_sigmask, &mask);
605 (void)sigprocmask1(l, SIG_SETMASK, &mask, 0); 633 (void)sigprocmask1(l, SIG_SETMASK, &mask, 0);
606 } 634 }
607 635
608 mutex_exit(p->p_lock); 636 mutex_exit(p->p_lock);
609 637
610 return EJUSTRETURN; 638 return EJUSTRETURN;
611} 639}
612 640
613int 641int
614svr4_32_sys_context(struct lwp *l, const struct svr4_32_sys_context_args *uap, register_t *retval) 642svr4_32_sys_context(struct lwp *l, const struct svr4_32_sys_context_args *uap, register_t *retval)
615{ 643{
616 /* { 644 /* {
617 syscallarg(int) func; 645 syscallarg(int) func;
618 syscallarg(struct svr4_32_ucontext *) uc; 646 syscallarg(struct svr4_32_ucontext *) uc;
619 } */ 647 } */
620 struct svr4_32_ucontext uc; 648 struct svr4_32_ucontext uc;
621 int error; 649 int error;
622 *retval = 0; 650 *retval = 0;
623 651
624 switch (SCARG(uap, func)) { 652 switch (SCARG(uap, func)) {
625 case SVR4_GETCONTEXT: 653 case SVR4_GETCONTEXT:
626 DPRINTF(("getcontext(%p)\n", SCARG(uap, uc))); 654 DPRINTF(("getcontext(%p)\n", SCARG(uap, uc)));
627 svr4_32_getcontext(l, &uc, &l->l_sigmask); 655 svr4_32_getcontext(l, &uc, &l->l_sigmask);
628 return copyout(&uc, SCARG_P32(uap, uc), sizeof(uc)); 656 return copyout(&uc, SCARG_P32(uap, uc), sizeof(uc));
629 657
630 case SVR4_SETCONTEXT: 658 case SVR4_SETCONTEXT:
631 DPRINTF(("setcontext(%p)\n", SCARG(uap, uc))); 659 DPRINTF(("setcontext(%p)\n", SCARG(uap, uc)));
632 if (!SCARG_P32(uap, uc)) 660 if (!SCARG_P32(uap, uc))
633 exit1(l, W_EXITCODE(0, 0)); 661 exit1(l, W_EXITCODE(0, 0));
634 else if ((error = copyin(SCARG_P32(uap, uc), 662 else if ((error = copyin(SCARG_P32(uap, uc),
635 &uc, sizeof(uc))) != 0) 663 &uc, sizeof(uc))) != 0)
636 return error; 664 return error;
637 else 665 else
638 return svr4_32_setcontext(l, &uc); 666 return svr4_32_setcontext(l, &uc);
639 667
640 default: 668 default:
641 DPRINTF(("context(%d, %p)\n", SCARG(uap, func), 669 DPRINTF(("context(%d, %p)\n", SCARG(uap, func),
642 SCARG(uap, uc))); 670 SCARG(uap, uc)));
643 return ENOSYS; 671 return ENOSYS;
644 } 672 }
645 return 0; 673 return 0;
646} 674}