]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/kern/thread_act.c
xnu-2782.20.48.tar.gz
[apple/xnu.git] / osfmk / kern / thread_act.c
index 0f2a4dc3ae18e203e82518ba27206a088cc4f71e..86041cd8053b281d1ada8bef7e9bf2642faf9eef 100644 (file)
@@ -484,7 +484,7 @@ thread_set_state_internal(
 
                        thread_mtx_unlock(thread);
 
-                       if (thread_stop(thread, FALSE)) {
+                       if (thread_stop(thread, TRUE)) {
                                thread_mtx_lock(thread);
                                result = machine_thread_set_state(
                                                                                thread, flavor, state, state_count);
@@ -660,6 +660,51 @@ thread_getstatus(
        return (thread_get_state(thread, flavor, tstate, count));
 }
 
+/*
+ *     Change thread's machine-dependent userspace TSD base.
+ *  Called with nothing locked.  Returns same way.
+ */
+kern_return_t
+thread_set_tsd_base(
+       thread_t                        thread,
+       mach_vm_offset_t        tsd_base)
+{
+       kern_return_t           result = KERN_SUCCESS;
+
+       if (thread == THREAD_NULL)
+               return (KERN_INVALID_ARGUMENT);
+
+       thread_mtx_lock(thread);
+
+       if (thread->active) {
+               if (thread != current_thread()) {
+                       thread_hold(thread);
+
+                       thread_mtx_unlock(thread);
+
+                       if (thread_stop(thread, TRUE)) {
+                               thread_mtx_lock(thread);
+                               result = machine_thread_set_tsd_base(thread, tsd_base);
+                               thread_unstop(thread);
+                       }
+                       else {
+                               thread_mtx_lock(thread);
+                               result = KERN_ABORTED;
+                       }
+
+                       thread_release(thread);
+               }
+               else
+                       result = machine_thread_set_tsd_base(thread, tsd_base);
+       }
+       else
+               result = KERN_TERMINATED;
+
+       thread_mtx_unlock(thread);
+
+       return (result);
+}
+
 /*
  * install_special_handler:
  *