1 /* $NetBSD: netbsd32_sa.c,v 1.10 2009/01/21 10:01:42 tron Exp $ */
4 * Copyright (c) 2005 The NetBSD Foundation.
7 * This code is derived from software contributed to the NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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>
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
= {
56 sizeof(struct netbsd32_sa_t
),
57 sizeof(netbsd32_sa_tp
),
61 (void (*)(struct lwp
*, void *))getucontext32_sa
,
69 /* SA emulation helpers */
71 netbsd32_sacopyout(int type
, const void *src
, void *dst
)
76 const ucontext_t
*u
= src
;
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
));
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
));
100 void * const *p
= src
;
101 netbsd32_pointer_t p32
;
103 NETBSD32PTR32(p32
, *p
);
104 return copyout(&p32
, dst
, sizeof(p32
));
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
:
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
128 memcpy(*parg
, &si32
, sizeof(si32
));
129 *pargsize
= sizeof(si32
);
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
)
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;
160 error
= dosa_register(l
, NETBSD32PTR64(SCARG(uap
, new)), &prev
,
161 SCARG(uap
, flags
), SCARG(uap
, stackinfo_offset
));
165 if (NETBSD32PTR64(SCARG(uap
, old
))) {
167 netbsd32_sa_upcall_t old
;
168 NETBSD32PTR32(old
, prev
);
169 return copyout(&old
, NETBSD32PTR64(SCARG(uap
, old
)),
181 netbsd32_sa_copyin_stack(stack_t
*stacks
, int index
, stack_t
*dest
)
183 stack32_t s32
, *stacks32
;
186 stacks32
= (stack32_t
*)stacks
;
187 error
= copyin(stacks32
+ index
, &s32
, sizeof(s32
));
191 dest
->ss_sp
= NETBSD32IPTR64(s32
.ss_sp
);
192 dest
->ss_size
= s32
.ss_size
;
193 dest
->ss_flags
= s32
.ss_flags
;
200 netbsd32_sa_stacks(struct lwp
*l
, const struct netbsd32_sa_stacks_args
*uap
,
206 syscallarg(netbsd32_stackp_t) stacks;
209 return sa_stacks1(l
, retval
, SCARG(uap
, num
),
210 NETBSD32PTR64(SCARG(uap
, stacks
)), netbsd32_sa_copyin_stack
);
217 netbsd32_sa_setconcurrency(struct lwp
*l
,
218 const struct netbsd32_sa_setconcurrency_args
*uap
, register_t
*retval
)
221 syscallarg(int) concurrency;
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
,
234 syscallarg(int) sa_id;
236 struct sys_sa_preempt_args ua
;
238 NETBSD32TO64_UAP(sa_id
);
239 return sys_sa_preempt(l
, &ua
, retval
);