sys/vm/vm_vmspace.c
void
vkernel_trap(struct lwp *lp, struct trapframe *frame)
{
	struct proc *p = lp->lwp_proc;
	struct vmspace_entry *ve;
	struct vkernel_lwp *vklp;
	int error;

	/*
	 * Which vmspace entry was running?
	 */
	vklp = lp->lwp_vkernel;
	KKASSERT(vklp);
	ve = vklp->ve;
	KKASSERT(ve != NULL);

	/*
	 * Switch the LWP vmspace back to the virtual kernel's VM space.
	 */
	vklp->ve = NULL;
	pmap_setlwpvm(lp, p->p_vmspace);
	KKASSERT(ve->refs > 0);
	atomic_subtract_int(&ve->refs, 1);
	/* ve is invalid once we kill our ref */

	/*
	 * Copy the emulated process frame to the virtual kernel process.
	 * The emulated process cannot change TLS descriptors so don't
	 * bother saving them, we already have a copy.
	 *
	 * Restore the virtual kernel's saved context so the virtual kernel
	 * process can resume.
	 */
	error = copyout(frame, vklp->user_trapframe, sizeof(*frame));
	bcopy(&vklp->save_trapframe, frame, sizeof(*frame));
	bcopy(&vklp->save_vextframe.vx_tls, &curthread->td_tls,
	      sizeof(vklp->save_vextframe.vx_tls));
	set_user_TLS();
	cpu_vkernel_trap(frame, error);
}
/*
 * A VM space under virtual kernel control trapped out or made a system call
 * or otherwise needs to return control to the virtual kernel context.
 *
 * No requirements.
 */
A VM space under virtual kernel control trapped out or made a system call
or otherwise needs to return control to the virtual kernel context.

No requirements.
A VM space under virtual kernel control trapped out or made a system call or otherwise needs to return control to the virtual kernel context . No requirements .
void
vkernel_trap(struct lwp *lp, struct trapframe *frame)
{
	struct proc *p = lp->lwp_proc;
	struct vmspace_entry *ve;
	struct vkernel_lwp *vklp;
	int error;
	vklp = lp->lwp_vkernel;
	KKASSERT(vklp);
	ve = vklp->ve;
	KKASSERT(ve != NULL);
	vklp->ve = NULL;
	pmap_setlwpvm(lp, p->p_vmspace);
	KKASSERT(ve->refs > 0);
	atomic_subtract_int(&ve->refs, 1);
	error = copyout(frame, vklp->user_trapframe, sizeof(*frame));
	bcopy(&vklp->save_trapframe, frame, sizeof(*frame));
	bcopy(&vklp->save_vextframe.vx_tls, &curthread->td_tls,
	      sizeof(vklp->save_vextframe.vx_tls));
	set_user_TLS();
	cpu_vkernel_trap(frame, error);
}
void vkernel_trap ( struct lwp * lp , struct trapframe * frame ) { struct proc * p = lp -> lwp_proc ; struct vmspace_entry * ve ; struct vkernel_lwp * vklp ; int error ; vklp = lp -> lwp_vkernel ; KKASSERT ( vklp ) ; ve = vklp -> ve ; KKASSERT ( ve != NULL ) ; vklp -> ve = NULL ; pmap_setlwpvm ( lp , p -> p_vmspace ) ; KKASSERT ( ve -> refs > 0 ) ; atomic_subtract_int ( & ve -> refs , 1 ) ; error = copyout ( frame , vklp -> user_trapframe , sizeof ( * frame ) ) ; bcopy ( & vklp -> save_trapframe , frame , sizeof ( * frame ) ) ; bcopy ( & vklp -> save_vextframe . vx_tls , & curthread -> td_tls , sizeof ( vklp -> save_vextframe . vx_tls ) ) ; set_user_TLS ( ) ; cpu_vkernel_trap ( frame , error ) ; }
A VM space under virtual kernel control trapped out or made a system call
 or otherwise needs to return control to the virtual kernel context.
A VM space under virtual kernel control trapped out or made a system call or otherwise needs to return control to the virtual kernel context .
/*
	 * Which vmspace entry was running?
	 */ /*
	 * Switch the LWP vmspace back to the virtual kernel's VM space.
	 */ /* ve is invalid once we kill our ref */ /*
	 * Copy the emulated process frame to the virtual kernel process.
	 * The emulated process cannot change TLS descriptors so don't
	 * bother saving them, we already have a copy.
	 *
	 * Restore the virtual kernel's saved context so the virtual kernel
	 * process can resume.
	 */