sys/vm/vm_vmspace.c
int
sys_vmspace_create(struct vmspace_create_args *uap)
{
	struct vmspace_entry *ve;
	struct vkernel_proc *vkp;
	struct proc *p = curproc;
	int error;

	if (vkernel_enable == 0)
		return (EOPNOTSUPP);

	/*
	 * Create a virtual kernel side-structure for the process if one
	 * does not exist.
	 *
	 * Implement a simple resolution for SMP races.
	 */
	if ((vkp = p->p_vkernel) == NULL) {
		vkp = kmalloc(sizeof(*vkp), M_VKERNEL, M_WAITOK|M_ZERO);
		lwkt_gettoken(&proc_token);
		if (p->p_vkernel == NULL) {
			vkp->refs = 1;
			lwkt_token_init(&vkp->token, "vkernel");
			RB_INIT(&vkp->root);
			p->p_vkernel = vkp;
		} else {
			kfree(vkp, M_VKERNEL);
			vkp = p->p_vkernel;
		}
		lwkt_reltoken(&proc_token);
	}

	get_mplock();

	/*
	 * Create a new VMSPACE, disallow conflicting ids
	 */
	ve = kmalloc(sizeof(struct vmspace_entry), M_VKERNEL, M_WAITOK|M_ZERO);
	ve->vmspace = vmspace_alloc(VM_MIN_USER_ADDRESS, VM_MAX_USER_ADDRESS);
	ve->id = uap->id;
	pmap_pinit2(vmspace_pmap(ve->vmspace));

	lwkt_gettoken(&vkp->token);
	if (RB_INSERT(vmspace_rb_tree, &vkp->root, ve)) {
		vmspace_free(ve->vmspace);
		ve->vmspace = NULL; /* safety */
		kfree(ve, M_VKERNEL);
		error = EEXIST;
	} else {
		error = 0;
	}
	lwkt_reltoken(&vkp->token);
	rel_mplock();
	return (error);
}
/*
 * vmspace_create (void *id, int type, void *data)
 *
 * Create a VMSPACE under the control of the caller with the specified id.
 * An id of NULL cannot be used.  The type and data fields must currently
 * be 0.
 *
 * The vmspace starts out completely empty.  Memory may be mapped into the
 * VMSPACE with vmspace_mmap() and MAP_VPAGETABLE section(s) controlled
 * with vmspace_mcontrol().
 *
 * No requirements.
 */
vmspace_create (void *id, int type, void *data)
Create a VMSPACE under the control of the caller with the specified id.
An id of NULL cannot be used.  The type and data fields must currently
be 0.

The vmspace starts out completely empty.  Memory may be mapped into the
VMSPACE with vmspace_mmap() and MAP_VPAGETABLE section(s) controlled
with vmspace_mcontrol().

No requirements.
vmspace_create ( void * id int type void * data ) Create a VMSPACE under the control of the caller with the specified id . An id of NULL cannot be used . The type and data fields must currently be 0 . The vmspace starts out completely empty . Memory may be mapped into the VMSPACE with vmspace_mmap () and MAP_VPAGETABLE section ( s ) controlled with vmspace_mcontrol () . No requirements .
int
sys_vmspace_create(struct vmspace_create_args *uap)
{
	struct vmspace_entry *ve;
	struct vkernel_proc *vkp;
	struct proc *p = curproc;
	int error;
	if (vkernel_enable == 0)
		return (EOPNOTSUPP);
	if ((vkp = p->p_vkernel) == NULL) {
		vkp = kmalloc(sizeof(*vkp), M_VKERNEL, M_WAITOK|M_ZERO);
		lwkt_gettoken(&proc_token);
		if (p->p_vkernel == NULL) {
			vkp->refs = 1;
			lwkt_token_init(&vkp->token, "vkernel");
			RB_INIT(&vkp->root);
			p->p_vkernel = vkp;
		} else {
			kfree(vkp, M_VKERNEL);
			vkp = p->p_vkernel;
		}
		lwkt_reltoken(&proc_token);
	}
	get_mplock();
	ve = kmalloc(sizeof(struct vmspace_entry), M_VKERNEL, M_WAITOK|M_ZERO);
	ve->vmspace = vmspace_alloc(VM_MIN_USER_ADDRESS, VM_MAX_USER_ADDRESS);
	ve->id = uap->id;
	pmap_pinit2(vmspace_pmap(ve->vmspace));
	lwkt_gettoken(&vkp->token);
	if (RB_INSERT(vmspace_rb_tree, &vkp->root, ve)) {
		vmspace_free(ve->vmspace);
		ve->vmspace = NULL; 
		kfree(ve, M_VKERNEL);
		error = EEXIST;
	} else {
		error = 0;
	}
	lwkt_reltoken(&vkp->token);
	rel_mplock();
	return (error);
}
int sys_vmspace_create ( struct vmspace_create_args * uap ) { struct vmspace_entry * ve ; struct vkernel_proc * vkp ; struct proc * p = curproc ; int error ; if ( vkernel_enable == 0 ) return ( EOPNOTSUPP ) ; if ( ( vkp = p -> p_vkernel ) == NULL ) { vkp = kmalloc ( sizeof ( * vkp ) , M_VKERNEL , M_WAITOK | M_ZERO ) ; lwkt_gettoken ( & proc_token ) ; if ( p -> p_vkernel == NULL ) { vkp -> refs = 1 ; lwkt_token_init ( & vkp -> token , " " ) ; RB_INIT ( & vkp -> root ) ; p -> p_vkernel = vkp ; } else { kfree ( vkp , M_VKERNEL ) ; vkp = p -> p_vkernel ; } lwkt_reltoken ( & proc_token ) ; } get_mplock ( ) ; ve = kmalloc ( sizeof ( struct vmspace_entry ) , M_VKERNEL , M_WAITOK | M_ZERO ) ; ve -> vmspace = vmspace_alloc ( VM_MIN_USER_ADDRESS , VM_MAX_USER_ADDRESS ) ; ve -> id = uap -> id ; pmap_pinit2 ( vmspace_pmap ( ve -> vmspace ) ) ; lwkt_gettoken ( & vkp -> token ) ; if ( RB_INSERT ( vmspace_rb_tree , & vkp -> root , ve ) ) { vmspace_free ( ve -> vmspace ) ; ve -> vmspace = NULL ; kfree ( ve , M_VKERNEL ) ; error = EEXIST ; } else { error = 0 ; } lwkt_reltoken ( & vkp -> token ) ; rel_mplock ( ) ; return ( error ) ; }
vmspace_create (void *id, int type, void *data)
 Create a VMSPACE under the control of the caller with the specified id.
vmspace_create ( void * id int type void * data ) Create a VMSPACE under the control of the caller with the specified id .
/*
	 * Create a virtual kernel side-structure for the process if one
	 * does not exist.
	 *
	 * Implement a simple resolution for SMP races.
	 */ /*
	 * Create a new VMSPACE, disallow conflicting ids
	 */ /* safety */