lots of docs + small tweaks for consistency

This commit is contained in:
Lysann Tranvouez 2025-10-03 22:09:26 +02:00
parent 01b1defbc3
commit 728e795c2c
2 changed files with 143 additions and 38 deletions

View file

@ -582,16 +582,20 @@ mach_error_t detour_manage_all_threads()
const mach_port_t port = mach_task_self();
thread_act_array_t threads = nullptr;
mach_msg_type_number_t numThreads = 0;
const kern_return_t result = task_threads(port, &threads, &numThreads);
mach_error_t result = task_threads(port, &threads, &numThreads);
if (result != err_none) {
return result;
}
for (mach_msg_type_number_t i = 0; i < numThreads; i++) {
DETOUR_CHECK( detour_manage_thread(threads[i]) );
const mach_error_t error = detour_manage_thread(threads[i]);
if (error != err_none) {
DETOUR_BREAK();
result = error;
}
}
DETOUR_CHECK( vm_deallocate(port, (vm_address_t)threads, numThreads * sizeof(*threads)) );
return err_none;
return result;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -614,6 +618,17 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
if (out_real_detour) {
*out_real_detour = nullptr;
}
if (s_transaction_thread != mach_thread_self()) {
return detour_err_wrong_thread;
}
// If any of the pending operations failed, then we don't need to do this.
if (s_pending_error != err_none) {
DETOUR_TRACE(("pending transaction error=%d\n", s_pending_error));
return s_pending_error;
}
if (!detour) {
DETOUR_TRACE(("empty detour\n"));
return KERN_INVALID_ARGUMENT;
@ -631,20 +646,6 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
return s_pending_error;
}
{
const thread_t active_thread = s_transaction_thread;
if (active_thread != mach_thread_self()) {
DETOUR_TRACE(("transaction conflict with thread id=%u\n", active_thread));
return detour_err_wrong_thread;
}
}
// If any of the pending operations failed, then we don't need to do this.
if (s_pending_error != err_none) {
DETOUR_TRACE(("pending transaction error=%d\n", s_pending_error));
return s_pending_error;
}
mach_error_t error = err_none;
detour_trampoline* trampoline = nullptr;
detour_operation* op = nullptr;
@ -959,7 +960,7 @@ mach_error_t detour_detach(detour_func_t* inout_pointer, detour_func_t detour)
op->next = s_pending_operations_head;
s_pending_operations_head = op;
return ERR_SUCCESS;
return err_none;
}
mach_error_t detour_attach_and_commit(detour_func_t* inout_pointer, detour_func_t detour)