Home | History | Annotate | Line # | Download | only in rumpkern
rump_private.h revision 1.90
      1 /*	$NetBSD: rump_private.h,v 1.90 2015/04/17 12:43:16 pooka Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2007-2011 Antti Kantee.  All Rights Reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  *
     15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     16  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     17  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     18  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     21  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     25  * SUCH DAMAGE.
     26  */
     27 
     28 #ifndef _SYS_RUMP_PRIVATE_H_
     29 #define _SYS_RUMP_PRIVATE_H_
     30 
     31 #include <sys/param.h>
     32 #include <sys/cpu.h>
     33 #include <sys/device.h>
     34 #include <sys/lwp.h>
     35 #include <sys/proc.h>
     36 #include <sys/systm.h>
     37 #include <sys/types.h>
     38 
     39 #include <uvm/uvm.h>
     40 #include <uvm/uvm_object.h>
     41 #include <uvm/uvm_page.h>
     42 
     43 #include <rump/rump.h>
     44 #include <rump/rumpuser.h>
     45 
     46 #include "rumpkern_if_priv.h"
     47 
     48 extern struct rumpuser_mtx *rump_giantlock;
     49 
     50 extern int rump_threads;
     51 extern struct device rump_rootdev;
     52 
     53 extern struct sysent rump_sysent[];
     54 
     55 enum rump_component_type {
     56 	RUMP_COMPONENT_DEV,
     57 		RUMP_COMPONENT_DEV_AFTERMAINBUS,
     58 	RUMP_COMPONENT_NET,
     59 		RUMP_COMPONENT_NET_ROUTE,
     60 		RUMP_COMPONENT_NET_IF,
     61 		RUMP_COMPONENT_NET_IFCFG,
     62 	RUMP_COMPONENT_VFS,
     63 	RUMP_COMPONENT_KERN,
     64 		RUMP_COMPONENT_KERN_VFS,
     65 	RUMP_COMPONENT_POSTINIT,
     66 	RUMP_COMPONENT_SYSCALL,
     67 
     68 	RUMP__FACTION_DEV,
     69 	RUMP__FACTION_VFS,
     70 	RUMP__FACTION_NET,
     71 
     72 	RUMP_COMPONENT_MAX,
     73 };
     74 struct rump_component {
     75 	enum rump_component_type rc_type;
     76 	void (*rc_init)(void);
     77 	LIST_ENTRY(rump_component) rc_entries;
     78 };
     79 
     80 /*
     81  * If RUMP_USE_CTOR is defined, we use __attribute__((constructor)) to
     82  * determine which components are present when rump_init() is called.
     83  * Otherwise, we use link sets and the __start/__stop symbols generated
     84  * by the toolchain.
     85  */
     86 
     87 #ifdef RUMP_USE_CTOR
     88 #define _RUMP_COMPONENT_REGISTER(type)					\
     89 static void rumpcomp_ctor##type(void) __attribute__((constructor));	\
     90 static void rumpcomp_ctor##type(void)					\
     91 {									\
     92 	rump_component_load(&rumpcomp##type);				\
     93 }
     94 
     95 #else /* RUMP_USE_CTOR */
     96 
     97 #define _RUMP_COMPONENT_REGISTER(type)					\
     98 __link_set_add_rodata(rump_components, rumpcomp##type);
     99 #endif /* RUMP_USE_CTOR */
    100 
    101 #define RUMP_COMPONENT(type)				\
    102 static void rumpcompinit##type(void);			\
    103 static struct rump_component rumpcomp##type = {	\
    104 	.rc_type = type,				\
    105 	.rc_init = rumpcompinit##type,			\
    106 };							\
    107 _RUMP_COMPONENT_REGISTER(type)				\
    108 static void rumpcompinit##type(void)
    109 
    110 #define FLAWLESSCALL(call)						\
    111 do {									\
    112 	int att_error;							\
    113 	if ((att_error = call) != 0)					\
    114 		panic("\"%s\" failed", #call);				\
    115 } while (/*CONSTCOND*/0)
    116 
    117 #define RUMPMEM_UNLIMITED ((unsigned long)-1)
    118 extern unsigned long rump_physmemlimit;
    119 
    120 extern struct vmspace *rump_vmspace_local;
    121 extern struct pmap rump_pmap_local;
    122 #define RUMP_LOCALPROC_P(p) \
    123     (p->p_vmspace == vmspace_kernel() || p->p_vmspace == rump_vmspace_local)
    124 
    125 void		rump_component_load(const struct rump_component *);
    126 void		rump_component_init(enum rump_component_type);
    127 int		rump_component_count(enum rump_component_type);
    128 
    129 typedef void	(*rump_proc_vfs_init_fn)(struct proc *);
    130 typedef void	(*rump_proc_vfs_release_fn)(struct proc *);
    131 extern rump_proc_vfs_init_fn rump_proc_vfs_init;
    132 extern rump_proc_vfs_release_fn rump_proc_vfs_release;
    133 
    134 extern struct cpu_info *rump_cpu;
    135 
    136 extern bool rump_ttycomponent;
    137 
    138 struct lwp *	rump__lwproc_alloclwp(struct proc *);
    139 void		rump__lwproc_lwphold(void);
    140 void		rump__lwproc_lwprele(void);
    141 
    142 void	rump_cpus_bootstrap(int *);
    143 void	rump_biglock_init(void);
    144 void	rump_scheduler_init(int);
    145 void	rump_schedule(void);
    146 void	rump_unschedule(void);
    147 void 	rump_schedule_cpu(struct lwp *);
    148 void 	rump_schedule_cpu_interlock(struct lwp *, void *);
    149 void	rump_unschedule_cpu(struct lwp *);
    150 void	rump_unschedule_cpu_interlock(struct lwp *, void *);
    151 void	rump_unschedule_cpu1(struct lwp *, void *);
    152 int	rump_syscall(int, void *, size_t, register_t *);
    153 
    154 struct rump_onesyscall {
    155 	int ros_num;
    156 	sy_call_t *ros_handler;
    157 };
    158 void	rump_syscall_boot_establish(const struct rump_onesyscall *, size_t);
    159 
    160 void	rump_schedlock_cv_wait(struct rumpuser_cv *);
    161 int	rump_schedlock_cv_timedwait(struct rumpuser_cv *,
    162 				    const struct timespec *);
    163 
    164 void	rump_user_schedule(int, void *);
    165 void	rump_user_unschedule(int, int *, void *);
    166 
    167 void	rump_cpu_attach(struct cpu_info *);
    168 
    169 void	rump_kernel_bigwrap(int *);
    170 void	rump_kernel_bigunwrap(int);
    171 
    172 void	rump_tsleep_init(void);
    173 
    174 void	rump_intr_init(int);
    175 void	rump_softint_run(struct cpu_info *);
    176 
    177 void	*rump_hypermalloc(size_t, int, bool, const char *);
    178 void	rump_hyperfree(void *, size_t);
    179 
    180 void	rump_xc_highpri(struct cpu_info *);
    181 
    182 void	rump_thread_init(void);
    183 void	rump_thread_allow(struct lwp *);
    184 
    185 void	rump_consdev_init(void);
    186 
    187 void	rump_hyperentropy_init(void);
    188 
    189 void	rump_lwproc_init(void);
    190 void	rump_lwproc_curlwp_set(struct lwp *);
    191 void	rump_lwproc_curlwp_clear(struct lwp *);
    192 int	rump_lwproc_rfork_vmspace(struct vmspace *, int);
    193 
    194 /*
    195  * sysproxy is an optional component.  The interfaces with "hyp"
    196  * in the name come into the rump kernel from the client or sysproxy
    197  * stub, the rest go out of the rump kernel.
    198  */
    199 struct rump_sysproxy_ops {
    200 	int (*rspo_copyin)(void *, const void *, void *, size_t);
    201 	int (*rspo_copyinstr)(void *, const void *, void *, size_t *);
    202 	int (*rspo_copyout)(void *, const void *, void *, size_t);
    203 	int (*rspo_copyoutstr)(void *, const void *, void *, size_t *);
    204 	int (*rspo_anonmmap)(void *, size_t, void **);
    205 	int (*rspo_raise)(void *, int);
    206 	void (*rspo_fini)(void *);
    207 
    208 	pid_t (*rspo_hyp_getpid)(void);
    209 	int (*rspo_hyp_syscall)(int, void *, long *);
    210 	int (*rspo_hyp_rfork)(void *, int, const char *);
    211 	void (*rspo_hyp_lwpexit)(void);
    212 	void (*rspo_hyp_execnotify)(const char *);
    213 };
    214 extern struct rump_sysproxy_ops rump_sysproxy_ops;
    215 #define rump_sysproxy_copyin(arg, raddr, laddr, len)			\
    216  	rump_sysproxy_ops.rspo_copyin(arg, raddr, laddr, len)
    217 #define rump_sysproxy_copyinstr(arg, raddr, laddr, lenp)		\
    218  	rump_sysproxy_ops.rspo_copyinstr(arg, raddr, laddr, lenp)
    219 #define rump_sysproxy_copyout(arg, laddr, raddr, len)			\
    220  	rump_sysproxy_ops.rspo_copyout(arg, laddr, raddr, len)
    221 #define rump_sysproxy_copyoutstr(arg, laddr, raddr, lenp)		\
    222  	rump_sysproxy_ops.rspo_copyoutstr(arg, laddr, raddr, lenp)
    223 #define rump_sysproxy_anonmmap(arg, howmuch, addr)			\
    224 	rump_sysproxy_ops.rspo_anonmmap(arg, howmuch, addr)
    225 #define rump_sysproxy_raise(arg, signo)					\
    226 	rump_sysproxy_ops.rspo_raise(arg, signo)
    227 #define rump_sysproxy_fini(arg)						\
    228 	rump_sysproxy_ops.rspo_fini(arg)
    229 #define rump_sysproxy_hyp_getpid()					\
    230 	rump_sysproxy_ops.rspo_hyp_getpid()
    231 #define rump_sysproxy_hyp_syscall(num, arg, retval)			\
    232 	rump_sysproxy_ops.rspo_hyp_syscall(num, arg, retval)
    233 #define rump_sysproxy_hyp_rfork(priv, flag, comm)			\
    234 	rump_sysproxy_ops.rspo_hyp_rfork(priv, flag, comm)
    235 #define rump_sysproxy_hyp_lwpexit()					\
    236 	rump_sysproxy_ops.rspo_hyp_lwpexit()
    237 #define rump_sysproxy_hyp_execnotify(comm)				\
    238 	rump_sysproxy_ops.rspo_hyp_execnotify(comm)
    239 
    240 #endif /* _SYS_RUMP_PRIVATE_H_ */
    241