No empty .Rs/.Re
[netbsd-mini2440.git] / sys / compat / netbsd32 / netbsd32_sa.c
blob7f6074d89167c03acedeac201188d22dc9b47685
1 /* $NetBSD: netbsd32_sa.c,v 1.10 2009/01/21 10:01:42 tron Exp $ */
3 /*
4 * Copyright (c) 2005 The NetBSD Foundation.
5 * All rights reserved.
7 * This code is derived from software contributed to the NetBSD Foundation
8 * by Quentin Garnier.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The NetBSD Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: netbsd32_sa.c,v 1.10 2009/01/21 10:01:42 tron Exp $");
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/dirent.h>
43 #include <sys/mount.h>
44 #include <sys/proc.h>
45 #include <sys/sa.h>
46 #include <sys/savar.h>
47 #include <sys/syscallargs.h>
49 #include <compat/netbsd32/netbsd32.h>
50 #include <compat/netbsd32/netbsd32_syscallargs.h>
51 #include <compat/netbsd32/netbsd32_conv.h>
52 #include <compat/netbsd32/netbsd32_sa.h>
54 const struct sa_emul saemul_netbsd32 = {
55 sizeof(ucontext32_t),
56 sizeof(struct netbsd32_sa_t),
57 sizeof(netbsd32_sa_tp),
58 netbsd32_sacopyout,
59 netbsd32_upcallconv,
60 netbsd32_cpu_upcall,
61 (void (*)(struct lwp *, void *))getucontext32_sa,
62 #ifdef KERN_SA
63 netbsd32_sa_ucsp
64 #else
65 NULL
66 #endif
67 };
69 /* SA emulation helpers */
70 int
71 netbsd32_sacopyout(int type, const void *src, void *dst)
73 switch (type) {
74 case SAOUT_UCONTEXT:
76 const ucontext_t *u = src;
77 ucontext32_t u32;
79 memset(&u32, 0, sizeof(u32));
80 u32.uc_flags = u->uc_flags;
81 u32.uc_stack.ss_sp = (uintptr_t)u->uc_stack.ss_sp;
82 u32.uc_stack.ss_size = u->uc_stack.ss_size;
83 u32.uc_stack.ss_flags = u->uc_stack.ss_flags;
85 return copyout(&u32, dst, sizeof(u32));
86 } break;
87 case SAOUT_SA_T:
89 const struct sa_t *sa = src;
90 struct netbsd32_sa_t sa32;
92 sa32.sa_id = sa->sa_id;
93 sa32.sa_cpu = sa->sa_cpu;
94 NETBSD32PTR32(sa32.sa_context, sa->sa_context);
96 return copyout(&sa32, dst, sizeof(sa32));
97 } break;
98 case SAOUT_SAP_T:
100 void * const *p = src;
101 netbsd32_pointer_t p32;
103 NETBSD32PTR32(p32, *p);
104 return copyout(&p32, dst, sizeof(p32));
105 } break;
107 return EINVAL;
111 netbsd32_upcallconv(struct lwp *l, int type, size_t *pargsize, void **parg,
112 void (**pfunc)(void *))
114 switch (type & SA_UPCALL_TYPE_MASK) {
115 case SA_UPCALL_SIGNAL:
116 case SA_UPCALL_SIGEV:
118 siginfo32_t si32;
119 siginfo_t *si = *parg;
121 netbsd32_si_to_si32(&si32, si);
124 * This is so wrong, but assuming
125 * sizeof(siginfo32_t) < sizeof(siginfo_t) is not
126 * very dangerous.
128 memcpy(*parg, &si32, sizeof(si32));
129 *pargsize = sizeof(si32);
133 return 0;
136 void *
137 netbsd32_sa_ucsp(void *arg)
139 ucontext32_t *uc32 = arg;
141 return NETBSD32IPTR64(_UC_MACHINE32_SP(uc32));
144 /* Sycalls conversion */
147 netbsd32_sa_register(struct lwp *l,
148 const struct netbsd32_sa_register_args *uap, register_t *retval)
150 #ifdef COMPAT_40
151 /* {
152 syscallarg(netbsd32_sa_upcall_t) new;
153 syscallarg(netbsd32_sa_upcallp_t) old;
154 syscallarg(int) flags;
155 syscallarg(netbsd32_ssize_t) stackinfo_offset;
156 } */
157 sa_upcall_t prev;
158 int error;
160 error = dosa_register(l, NETBSD32PTR64(SCARG(uap, new)), &prev,
161 SCARG(uap, flags), SCARG(uap, stackinfo_offset));
162 if (error)
163 return error;
165 if (NETBSD32PTR64(SCARG(uap, old))) {
167 netbsd32_sa_upcall_t old;
168 NETBSD32PTR32(old, prev);
169 return copyout(&old, NETBSD32PTR64(SCARG(uap, old)),
170 sizeof(old));
173 return 0;
174 #else
175 return ENOSYS;
176 #endif
179 #ifdef COMPAT_40
180 static int
181 netbsd32_sa_copyin_stack(stack_t *stacks, int index, stack_t *dest)
183 stack32_t s32, *stacks32;
184 int error;
186 stacks32 = (stack32_t *)stacks;
187 error = copyin(stacks32 + index, &s32, sizeof(s32));
188 if (error)
189 return error;
191 dest->ss_sp = NETBSD32IPTR64(s32.ss_sp);
192 dest->ss_size = s32.ss_size;
193 dest->ss_flags = s32.ss_flags;
195 return 0;
197 #endif
200 netbsd32_sa_stacks(struct lwp *l, const struct netbsd32_sa_stacks_args *uap,
201 register_t *retval)
203 #ifdef COMPAT_40
204 /* {
205 syscallarg(int) num;
206 syscallarg(netbsd32_stackp_t) stacks;
207 } */
209 return sa_stacks1(l, retval, SCARG(uap, num),
210 NETBSD32PTR64(SCARG(uap, stacks)), netbsd32_sa_copyin_stack);
211 #else
212 return ENOSYS;
213 #endif
217 netbsd32_sa_setconcurrency(struct lwp *l,
218 const struct netbsd32_sa_setconcurrency_args *uap, register_t *retval)
220 /* {
221 syscallarg(int) concurrency;
222 } */
223 struct sys_sa_setconcurrency_args ua;
225 NETBSD32TO64_UAP(concurrency);
226 return sys_sa_setconcurrency(l, &ua, retval);
230 netbsd32_sa_preempt(struct lwp *l, const struct netbsd32_sa_preempt_args *uap,
231 register_t *retval)
233 /* {
234 syscallarg(int) sa_id;
235 } */
236 struct sys_sa_preempt_args ua;
238 NETBSD32TO64_UAP(sa_id);
239 return sys_sa_preempt(l, &ua, retval);