detour_manage_thread

This commit is contained in:
Lysann Tranvouez 2025-09-29 01:28:30 +02:00
parent dbdfa84fab
commit d63c15d582

View file

@ -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;
}