PERFORCE change 75128 for review
David Xu
davidxu at FreeBSD.org
Wed Apr 13 20:09:02 PDT 2005
http://perforce.freebsd.org/chv.cgi?CH=75128
Change 75128 by davidxu at davidxu_celeron on 2005/04/14 03:08:49
Implement cpu_set_user_tls.
Affected files ...
.. //depot/projects/davidxu_thread/src/sys/i386/i386/vm_machdep.c#7 edit
Differences ...
==== //depot/projects/davidxu_thread/src/sys/i386/i386/vm_machdep.c#7 (text+ko) ====
@@ -469,6 +469,48 @@
(int)arg);
}
+void
+cpu_set_user_tls(struct thread *td, void *tls_base, size_t tls_size,
+ int tls_seg)
+{
+ struct segment_descriptor sd;
+ uint32_t base;
+
+ /*
+ * Construct a descriptor and store it in the pcb for
+ * the next context switch. Also store it in the gdt
+ * so that the load of tf_fs into %fs will activate it
+ * at return to userland.
+ */
+ base = (uint32_t)tls_base;
+ sd.sd_lobase = base & 0xffffff;
+ sd.sd_hibase = (base >> 24) & 0xff;
+ sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
+ sd.sd_hilimit = 0xf;
+ sd.sd_type = SDT_MEMRWA;
+ sd.sd_dpl = SEL_UPL;
+ sd.sd_p = 1;
+ sd.sd_xx = 0;
+ sd.sd_def32 = 1;
+ sd.sd_gran = 1;
+ mtx_lock_spin(&sched_lock);
+ if (tls_seg == 0) {
+ /* set %gs */
+ td->td_pcb->pcb_gsd = sd;
+ if (td == curthread) {
+ PCPU_GET(fsgs_gdt)[1] = sd;
+ load_gs(GSEL(GUGS_SEL, SEL_UPL));
+ }
+ } else {
+ /* set %fs */
+ td->td_pcb->pcb_fsd = sd;
+ if (td == curthread)
+ PCPU_GET(fsgs_gdt)[0] = sd;
+ td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL);
+ }
+ mtx_unlock_spin(&sched_lock);
+}
+
/*
* Convert kernel VA to physical address
*/
More information about the p4-projects
mailing list