FreeBSD/sys/compat/ndis/kern_windrv.c
/*
 * Context switch from UNIX to Windows. Save the existing value
 * of %fs for this processor, then change it to point to our
 * fake TID. Note that it is also possible to pin ourselves
 * to our current CPU, though I'm not sure this is really
 * necessary. It depends on whether or not an interrupt might
 * preempt us while Windows code is running and we wind up
 * scheduled onto another CPU as a result. So far, it doesn't
 * seem like this is what happens.
 */
Context switch from UNIX to Windows. Save the existing value
of %fs for this processor, then change it to point to our
fake TID. Note that it is also possible to pin ourselves
to our current CPU, though I'm not sure this is really
necessary. It depends on whether or not an interrupt might
preempt us while Windows code is running and we wind up
scheduled onto another CPU as a result. So far, it doesn't
seem like this is what happens.
Context switch from UNIX to Windows . Save the existing value of %fs for this processor then change it to point to our fake TID . Note that it is also possible to pin ourselves to our current CPU though I ' m not sure this is really necessary . It depends on whether or not an interrupt might preempt us while Windows code is running and we wind up scheduled onto another CPU as a result . So far it doesn ' t seem like this is what happens .
void
ctxsw_utow(void)
{
	struct tid		*t;
	t = &my_tids[curthread->td_oncpu];
	if (t->tid_self != t)
		x86_newldt(NULL);
	x86_critical_enter();
	t->tid_oldfs = x86_getfs();
	t->tid_cpu = curthread->td_oncpu;
	sched_pin();
	x86_setfs(SEL_TO_FS(t->tid_selector));
	x86_critical_exit();
}
void ctxsw_utow ( void ) { struct tid * t ; t = & my_tids [ curthread -> td_oncpu ] ; if ( t -> tid_self != t ) x86_newldt ( NULL ) ; x86_critical_enter ( ) ; t -> tid_oldfs = x86_getfs ( ) ; t -> tid_cpu = curthread -> td_oncpu ; sched_pin ( ) ; x86_setfs ( SEL_TO_FS ( t -> tid_selector ) ) ; x86_critical_exit ( ) ; }
Context switch from UNIX to Windows.
Context switch from UNIX to Windows .
/*
	 * Ugly hack. During system bootstrap (cold == 1), only CPU 0
	 * is running. So if we were loaded at bootstrap, only CPU 0
	 * will have our special GDT entry. This is a problem for SMP
	 * systems, so to deal with this, we check here to make sure
	 * the TID for this processor has been initialized, and if it
	 * hasn't, we need to do it right now or else things will
	 * explode.
	 */ /* Now entering Windows land, population: you. */