X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/39236c6e673c41db228275375ab7fdb0f837b292..04b8595b18b1b41ac7a206e4b3d51a635f8413d7:/osfmk/kern/thread_act.c diff --git a/osfmk/kern/thread_act.c b/osfmk/kern/thread_act.c index 0f2a4dc3a..86041cd80 100644 --- a/osfmk/kern/thread_act.c +++ b/osfmk/kern/thread_act.c @@ -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: *