detour_manage_thread
This commit is contained in:
parent
dbdfa84fab
commit
d63c15d582
1 changed files with 43 additions and 0 deletions
|
|
@ -405,3 +405,46 @@ mach_error_t detour_transaction_commit_ex(detour_func_t** out_failed_target)
|
|||
}
|
||||
return s_pending_error;
|
||||
}
|
||||
|
||||
mach_error_t detour_manage_thread(thread_t thread)
|
||||
{
|
||||
mach_error_t error;
|
||||
|
||||
// If any of the pending operations failed, then we don't need to do this.
|
||||
if (s_pending_error != err_none) {
|
||||
return s_pending_error;
|
||||
}
|
||||
|
||||
// must be the transaction thread
|
||||
if (s_transaction_thread != mach_thread_self()) {
|
||||
return detour_err_wrong_thread;
|
||||
}
|
||||
|
||||
// Silently (and safely) drop any attempt to suspend our own thread.
|
||||
if (thread == mach_thread_self()) {
|
||||
return err_none;
|
||||
}
|
||||
|
||||
detour_pending_thread* new_pending_thread = malloc(sizeof(detour_pending_thread));
|
||||
if (!new_pending_thread) {
|
||||
error = KERN_RESOURCE_SHORTAGE;
|
||||
fail:
|
||||
free(new_pending_thread);
|
||||
s_pending_error = error;
|
||||
s_pending_error_pointer = nullptr;
|
||||
DETOUR_BREAK();
|
||||
return error;
|
||||
}
|
||||
|
||||
error = thread_suspend(thread);
|
||||
if (error != err_none) {
|
||||
DETOUR_BREAK();
|
||||
goto fail;
|
||||
}
|
||||
|
||||
new_pending_thread->thread = thread;
|
||||
new_pending_thread->next = s_pending_threads_head;
|
||||
s_pending_threads_head = new_pending_thread;
|
||||
|
||||
return err_none;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue