]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/i386/bsd_i386.c
xnu-1504.9.17.tar.gz
[apple/xnu.git] / osfmk / i386 / bsd_i386.c
index 66939fac91d1b01f130173e81862513998d172db..4b933d763f49aa080553c8bb5d4cf7ed558fbb84 100644 (file)
@@ -498,6 +498,7 @@ kern_return_t
 thread_fast_set_cthread_self64(uint64_t self)
 {
        pcb_t pcb = current_thread()->machine.pcb;
+       cpu_data_t              *cdp;
 
        /* check for canonical address, set 0 otherwise  */
        if (!IS_USERADDR64_CANONICAL(self))
@@ -505,11 +506,13 @@ thread_fast_set_cthread_self64(uint64_t self)
 
        pcb->cthread_self = self;
        mp_disable_preemption();
+       cdp = current_cpu_datap();
 #if defined(__x86_64__)
-       if (current_cpu_datap()->cpu_uber.cu_user_gs_base != self)
+       if ((cdp->cpu_uber.cu_user_gs_base != pcb->cthread_self) ||
+           (pcb->cthread_self != rdmsr64(MSR_IA32_KERNEL_GS_BASE)))
                wrmsr64(MSR_IA32_KERNEL_GS_BASE, self);
 #endif
-       current_cpu_datap()->cpu_uber.cu_user_gs_base = self;
+       cdp->cpu_uber.cu_user_gs_base = self;
        mp_enable_preemption();
        return (USER_CTHREAD);
 }