From 4fb41e761e108c25a6f2d7a96047cad5ead1ac97 Mon Sep 17 00:00:00 2001 From: wrstuden Date: Wed, 15 Oct 2008 06:52:38 +0000 Subject: [PATCH] Merge wrstuden-revivesa into HEAD. Catch some files that I forgot to revive on HEAD in previous commit. --- sys/arch/m68k/include/saframe.h | 53 ++++++ sys/compat/netbsd32/netbsd32_sa.c | 215 +++++++++++++++++++++++++ sys/compat/netbsd32/netbsd32_sa.h | 53 ++++++ sys/rump/librump/rumpkern/opt/opt_sa.h | 1 + sys/sys/sa.h | 74 +++++++++ sys/sys/satypes.h | 43 +++++ sys/sys/savar.h | 205 +++++++++++++++++++++++ 7 files changed, 644 insertions(+) create mode 100644 sys/arch/m68k/include/saframe.h create mode 100644 sys/compat/netbsd32/netbsd32_sa.c create mode 100644 sys/compat/netbsd32/netbsd32_sa.h create mode 100644 sys/rump/librump/rumpkern/opt/opt_sa.h create mode 100644 sys/sys/sa.h create mode 100644 sys/sys/satypes.h create mode 100644 sys/sys/savar.h diff --git a/sys/arch/m68k/include/saframe.h b/sys/arch/m68k/include/saframe.h new file mode 100644 index 000000000000..bc4b007c1bb8 --- /dev/null +++ b/sys/arch/m68k/include/saframe.h @@ -0,0 +1,53 @@ +/* $NetBSD: saframe.h,v 1.7 2008/10/15 06:52:38 wrstuden Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _M68K_SAFRAME_H +#define _M68K_SAFRAME_H + +#include + +/* + * Scheduler activations upcall frame + */ +struct saframe { + int sa_ra; + int sa_type; + struct sa_t** sa_sas; + int sa_events; + int sa_interrupted; + void* sa_arg; +}; + +#endif diff --git a/sys/compat/netbsd32/netbsd32_sa.c b/sys/compat/netbsd32/netbsd32_sa.c new file mode 100644 index 000000000000..ea24e2133fe6 --- /dev/null +++ b/sys/compat/netbsd32/netbsd32_sa.c @@ -0,0 +1,215 @@ +/* $NetBSD: netbsd32_sa.c,v 1.7 2008/10/15 06:52:38 wrstuden Exp $ */ + +/* + * Copyright (c) 2005 The NetBSD Foundation. + * All rights reserved. + * + * This code is derived from software contributed to the NetBSD Foundation + * by Quentin Garnier. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__KERNEL_RCSID(0, "$NetBSD: netbsd32_sa.c,v 1.7 2008/10/15 06:52:38 wrstuden Exp $"); + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +/* SA emulation helpers */ +int +netbsd32_sacopyout(int type, const void *src, void *dst) +{ + switch (type) { + case SAOUT_UCONTEXT: + { + const ucontext_t *u = src; + ucontext32_t u32; + + memset(&u32, 0, sizeof(u32)); + u32.uc_flags = u->uc_flags; + u32.uc_stack.ss_sp = (uintptr_t)u->uc_stack.ss_sp; + u32.uc_stack.ss_size = u->uc_stack.ss_size; + u32.uc_stack.ss_flags = u->uc_stack.ss_flags; + + return copyout(&u32, dst, sizeof(u32)); + } break; + case SAOUT_SA_T: + { + const struct sa_t *sa = src; + struct netbsd32_sa_t sa32; + + sa32.sa_id = sa->sa_id; + sa32.sa_cpu = sa->sa_cpu; + NETBSD32PTR32(sa32.sa_context, sa->sa_context); + + return copyout(&sa32, dst, sizeof(sa32)); + } break; + case SAOUT_SAP_T: + { + void * const *p = src; + netbsd32_pointer_t p32; + + NETBSD32PTR32(p32, *p); + return copyout(&p32, dst, sizeof(p32)); + } break; + } + return EINVAL; +} + +int +netbsd32_upcallconv(struct lwp *l, int type, size_t *pargsize, void **parg, + void (**pfunc)(void *)) +{ + switch (type & SA_UPCALL_TYPE_MASK) { + case SA_UPCALL_SIGNAL: + case SA_UPCALL_SIGEV: + { + siginfo32_t si32; + siginfo_t *si = *parg; + + netbsd32_si_to_si32(&si32, si); + + /* + * This is so wrong, but assuming + * sizeof(siginfo32_t) < sizeof(siginfo_t) is not + * very dangerous. + */ + memcpy(*parg, &si32, sizeof(si32)); + *pargsize = sizeof(si32); + } + } + + return 0; +} + +void * +netbsd32_sa_ucsp(void *arg) +{ + ucontext32_t *uc32 = arg; + + return NETBSD32IPTR64(_UC_MACHINE32_SP(uc32)); +} + +/* Sycalls conversion */ + +int +netbsd32_sa_register(struct lwp *l, + const struct netbsd32_sa_register_args *uap, register_t *retval) +{ + /* { + syscallarg(netbsd32_sa_upcall_t) new; + syscallarg(netbsd32_sa_upcallp_t) old; + syscallarg(int) flags; + syscallarg(netbsd32_ssize_t) stackinfo_offset; + } */ + sa_upcall_t prev; + int error; + + error = dosa_register(l, NETBSD32PTR64(SCARG(uap, new)), &prev, + SCARG(uap, flags), SCARG(uap, stackinfo_offset)); + if (error) + return error; + + if (NETBSD32PTR64(SCARG(uap, old))) { + + netbsd32_sa_upcall_t old; + NETBSD32PTR32(old, prev); + return copyout(&old, NETBSD32PTR64(SCARG(uap, old)), + sizeof(old)); + } + + return 0; +} + +static int +netbsd32_sa_copyin_stack(stack_t *stacks, int index, stack_t *dest) +{ + stack32_t s32, *stacks32; + int error; + + stacks32 = (stack32_t *)stacks; + error = copyin(stacks32 + index, &s32, sizeof(s32)); + if (error) + return error; + + dest->ss_sp = NETBSD32IPTR64(s32.ss_sp); + dest->ss_size = s32.ss_size; + dest->ss_flags = s32.ss_flags; + + return 0; +} + +int +netbsd32_sa_stacks(struct lwp *l, const struct netbsd32_sa_stacks_args *uap, + register_t *retval) +{ + /* { + syscallarg(int) num; + syscallarg(netbsd32_stackp_t) stacks; + } */ + + return sa_stacks1(l, retval, SCARG(uap, num), + NETBSD32PTR64(SCARG(uap, stacks)), netbsd32_sa_copyin_stack); +} + +int +netbsd32_sa_setconcurrency(struct lwp *l, + const struct netbsd32_sa_setconcurrency_args *uap, register_t *retval) +{ + /* { + syscallarg(int) concurrency; + } */ + struct sys_sa_setconcurrency_args ua; + + NETBSD32TO64_UAP(concurrency); + return sys_sa_setconcurrency(l, &ua, retval); +} + +int +netbsd32_sa_preempt(struct lwp *l, const struct netbsd32_sa_preempt_args *uap, + register_t *retval) +{ + /* { + syscallarg(int) sa_id; + } */ + struct sys_sa_preempt_args ua; + + NETBSD32TO64_UAP(sa_id); + return sys_sa_preempt(l, &ua, retval); +} diff --git a/sys/compat/netbsd32/netbsd32_sa.h b/sys/compat/netbsd32/netbsd32_sa.h new file mode 100644 index 000000000000..11719b3af33c --- /dev/null +++ b/sys/compat/netbsd32/netbsd32_sa.h @@ -0,0 +1,53 @@ +/* $NetBSD: netbsd32_sa.h,v 1.5 2008/10/15 06:52:38 wrstuden Exp $ */ + +/* + * Copyright (c) 2006 The NetBSD Foundation. + * All rights reserved. + * + * This code is derived from software contributed to the NetBSD Foundation + * by Quentin Garnier. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _COMPAT_NETBSD32_SA_H_ +#define _COMPAT_NETBSD32_SA_H_ + +struct netbsd32_sa_t { + netbsd32_ucontextp sa_context; + int sa_id; + int sa_cpu; +}; + +typedef netbsd32_pointer_t netbsd32_sa_tp; + +int netbsd32_sacopyout(int, const void *, void *); +int netbsd32_upcallconv(struct lwp *, int, size_t *, void **, + void (**)(void *)); +void *netbsd32_sa_ucsp(void *); + +void getucontext32_sa(struct lwp *, ucontext32_t *); + +#endif /* !_COMPAT_NETBSD32_SA_H_ */ diff --git a/sys/rump/librump/rumpkern/opt/opt_sa.h b/sys/rump/librump/rumpkern/opt/opt_sa.h new file mode 100644 index 000000000000..3ed242ef7304 --- /dev/null +++ b/sys/rump/librump/rumpkern/opt/opt_sa.h @@ -0,0 +1 @@ +/* $NetBSD: opt_sa.h,v 1.2 2008/10/15 06:52:38 wrstuden Exp $ */ diff --git a/sys/sys/sa.h b/sys/sys/sa.h new file mode 100644 index 000000000000..7fc5f9f648b5 --- /dev/null +++ b/sys/sys/sa.h @@ -0,0 +1,74 @@ +/* $NetBSD: sa.h,v 1.12 2008/10/15 06:52:38 wrstuden Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nathan J. Williams. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SA_H_ +#define _SYS_SA_H_ + +#include +#include + +struct sa_t { + ucontext_t *sa_context; + int sa_id; + int sa_cpu; +}; + +/* kernel known per upcall stack data */ +struct sa_stackinfo_t { + unsigned int sasi_stackgen; /* stack generation counter */ +}; + +#define SA_UPCALL_NEWPROC 0 +#define SA_UPCALL_PREEMPTED 1 +#define SA_UPCALL_BLOCKED 2 +#define SA_UPCALL_UNBLOCKED 3 +#define SA_UPCALL_SIGNAL 4 +#define SA_UPCALL_SIGEV 5 +#define SA_UPCALL_USER 6 +#define SA_UPCALL_NUPCALLS 7 + +#define SA_UPCALL_STRINGS "newproc", "preempted", "blocked", "unblocked", \ + "signal", "sigev", "user" + +#define SA_FLAG_PREEMPT 0x0001 /* Generate upcalls on a vanilla preempt() */ + +#define SA_FLAG_STACKINFO 0x010000 /* Use stackinfo for upcall stack return */ + +int sa_system_disabled; + +#endif /* !_SYS_SA_H_ */ diff --git a/sys/sys/satypes.h b/sys/sys/satypes.h new file mode 100644 index 000000000000..e22191babd4c --- /dev/null +++ b/sys/sys/satypes.h @@ -0,0 +1,43 @@ +/* $NetBSD: satypes.h,v 1.2 2008/10/15 06:52:38 wrstuden Exp $ */ + +/*- + * Copyright (c) 2008 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nathan J. Williams. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _SYS_SATYPES_H_ +#define _SYS_SATYPES_H_ + +/* + * Type definitions for types used in SA code. + */ + +struct sa_t; + +typedef void (*sa_upcall_t)(int, struct sa_t *[], int, int, void *); + +#endif /* !_SYS_SATYPES_H_ */ diff --git a/sys/sys/savar.h b/sys/sys/savar.h new file mode 100644 index 000000000000..3eb655ab08d8 --- /dev/null +++ b/sys/sys/savar.h @@ -0,0 +1,205 @@ +/* $NetBSD: savar.h,v 1.25 2008/10/15 06:52:38 wrstuden Exp $ */ + +/*- + * Copyright (c) 2001 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Nathan J. Williams. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Internal data usd by the scheduler activation implementation + */ + +#ifndef _SYS_SAVAR_H_ +#define _SYS_SAVAR_H_ + +#include +#include +#include +#include + +union sau_state { + struct { + ucontext_t ss_ctx; + struct sa_t ss_sa; + } ss_captured; + struct { + struct lwp *ss_lwp; + } ss_deferred; +}; + +struct sa_emul { + size_t sae_ucsize; /* Size of ucontext_t */ + size_t sae_sasize; /* Size of sa_t */ + size_t sae_sapsize; /* Size of (sa_t *) */ + int (*sae_sacopyout)(int, const void *, void *); + int (*sae_upcallconv)(struct lwp *, int, size_t *, void **, + void (**)(void *)); + void (*sae_upcall)(struct lwp *, int, int, int, void *, + void *, void *, sa_upcall_t); + void (*sae_getucontext)(struct lwp *, void *); + void *(*sae_ucsp)(void *); /* Stack ptr from an ucontext_t */ +}; + +struct sadata_upcall { + SIMPLEQ_ENTRY(sadata_upcall) sau_next; + int sau_flags; + int sau_type; + size_t sau_argsize; + void *sau_arg; + void (*sau_argfreefunc)(void *); + stack_t sau_stack; + union sau_state sau_event; + union sau_state sau_interrupted; +}; + +#define SAU_FLAG_DEFERRED_EVENT 0x1 +#define SAU_FLAG_DEFERRED_INTERRUPTED 0x2 + +#define SA_UPCALL_TYPE_MASK 0x00FF + +#define SA_UPCALL_DEFER_EVENT 0x1000 +#define SA_UPCALL_DEFER_INTERRUPTED 0x2000 +#define SA_UPCALL_DEFER (SA_UPCALL_DEFER_EVENT | \ + SA_UPCALL_DEFER_INTERRUPTED) +#define SA_UPCALL_LOCKED_EVENT 0x4000 +#define SA_UPCALL_LOCKED_INTERRUPTED 0x8000 + +struct sastack { + stack_t sast_stack; + RB_ENTRY(sastack) sast_node; + unsigned int sast_gen; +}; + +/* + * Locking: + * + * m: sadata::sa_mutex + * p: proc::p_lock + * v: sadata_vp::savp_mutex + * (: unlocked, stable + * !: unlocked, may only be reliably accessed by the blessed LWP itself + */ +struct sadata_vp { + kmutex_t savp_mutex; /* (: mutex */ + int savp_id; /* (: "virtual processor" identifier */ + SLIST_ENTRY(sadata_vp) savp_next; /* m: link to next sadata_vp */ + struct lwp *savp_lwp; /* !: lwp on "virtual processor" */ + struct lwp *savp_blocker; /* !: recently blocked lwp */ + sleepq_t savp_woken; /* m: list of unblocked lwps */ + sleepq_t savp_lwpcache; /* m: list of cached lwps */ + vaddr_t savp_faultaddr; /* !: page fault address */ + vaddr_t savp_ofaultaddr; /* !: old page fault address */ + struct sadata_upcall *savp_sleeper_upcall; + /* !: cached upcall data */ + SIMPLEQ_HEAD(, sadata_upcall) savp_upcalls; /* ?: pending upcalls */ + int savp_woken_count; /* m: count of woken lwps */ + int savp_lwpcache_count; /* m: count of cached lwps */ + int savp_pflags; /* !: blessed-private flags */ +}; + +#define SAVP_FLAG_NOUPCALLS 0x0001 /* Already did upcalls, don't redo */ +#define SAVP_FLAG_DELIVERING 0x0002 /* Delivering an upcall, no block */ + +/* + * Locking: + * + * m: sadata::sa_mutex + * p: proc::p_lock + * (: unlocked, stable + */ +struct sadata { + kmutex_t sa_mutex; /* (: lock on these fields */ + int sa_flag; /* m: SA_* flags */ + sa_upcall_t sa_upcall; /* m: upcall entry point */ + int sa_concurrency; /* m: current concurrency */ + int sa_maxconcurrency; /* m: requested concurrency */ + int sa_stackchg; /* m: stacks change indicator */ + RB_HEAD(sasttree, sastack) sa_stackstree; /* s, m: tree of upcall stacks */ + struct sastack *sa_stacknext; /* m: next free stack */ + ssize_t sa_stackinfo_offset; /* m: offset from ss_sp to stackinfo data */ + int sa_nstacks; /* m: number of upcall stacks */ + sigset_t sa_sigmask; /* p: process-wide masked sigs*/ + SLIST_HEAD(, sadata_vp) sa_vps; /* m: virtual processors */ + kcondvar_t sa_cv; /* m: condvar for sa_yield */ +}; + +#define SA_FLAG_ALL SA_FLAG_PREEMPT + +#define SA_MAXNUMSTACKS 16 /* Maximum number of upcall stacks per VP. */ + +struct sadata_upcall *sadata_upcall_alloc(int); +void sadata_upcall_free(struct sadata_upcall *); +void sadata_upcall_drain(void); + +void sa_awaken(struct lwp *); +void sa_release(struct proc *); +void sa_switch(struct lwp *); +void sa_preempt(struct lwp *); +void sa_yield(struct lwp *); +int sa_upcall(struct lwp *, int, struct lwp *, struct lwp *, size_t, void *, + void (*)(void *)); + +void sa_putcachelwp(struct proc *, struct lwp *); +struct lwp *sa_getcachelwp(struct proc *, struct sadata_vp *); + +/* + * API permitting other parts of the kernel to indicate that they + * are entering code paths in which blocking events should NOT generate + * upcalls to an SA process. These routines should ONLY be used by code + * involved in scheduling or process/thread initialization (such as + * stack copying). These calls must be balanced. They may be nested, but + * MUST be released in a LIFO order. These calls assume that the lwp is + * locked. + */ +typedef int sa_critpath_t; +void sa_critpath_enter(struct lwp *, sa_critpath_t *); +void sa_critpath_exit(struct lwp *, sa_critpath_t *); + + +void sa_unblock_userret(struct lwp *); +void sa_upcall_userret(struct lwp *); +void cpu_upcall(struct lwp *, int, int, int, void *, void *, void *, sa_upcall_t); + +typedef int (*sa_copyin_stack_t)(stack_t *, int, stack_t *); +int sa_stacks1(struct lwp *, register_t *, int, stack_t *, + sa_copyin_stack_t); +int dosa_register(struct lwp *, sa_upcall_t, sa_upcall_t *, int, ssize_t); + +void *sa_ucsp(void *); + +#define SAOUT_UCONTEXT 0 +#define SAOUT_SA_T 1 +#define SAOUT_SAP_T 2 + +#endif /* !_SYS_SAVAR_H_ */