prefix platform specific functions clearly

This commit is contained in:
Lysann Tranvouez 2025-10-01 22:55:31 +02:00
parent db603acded
commit 848e8cc183
3 changed files with 65 additions and 63 deletions

View file

@ -187,7 +187,7 @@ static detour_trampoline* internal_detour_alloc_trampoline(uint8_t* target)
detour_trampoline* lo;
detour_trampoline* hi;
internal_detour_find_jmp_bounds(target, &lo, &hi);
detour_platform_find_jmp_bounds(target, &lo, &hi);
// ReSharper disable once CppDFAUnusedValue
detour_trampoline* trampoline = nullptr;
@ -421,8 +421,8 @@ mach_error_t detour_transaction_commit_ex(detour_func_t** out_failed_target)
operation->target[4], operation->target[5], operation->target[6], operation->target[7],
operation->target[8], operation->target[9], operation->target[10], operation->target[11]));
internal_detour_operation_commit_detour(operation);
*operation->pointer = internal_detour_operation_get_trampoline_ptr(operation)
detour_platform_operation_commit_detour(operation);
*operation->pointer = detour_platform_operation_get_trampoline_ptr(operation)
DETOUR_TRACE(("detours: target=%p: "
"%02x %02x %02x %02x "
@ -449,7 +449,7 @@ mach_error_t detour_transaction_commit_ex(detour_func_t** out_failed_target)
case detour_operation_kind_detach: {
memcpy(operation->target, operation->trampoline->restore_code,
operation->trampoline->restore_code_size);
*operation->pointer = internal_detour_operation_get_target_ptr(operation);
*operation->pointer = detour_platform_operation_get_target_ptr(operation);
break;
}
}
@ -457,7 +457,7 @@ mach_error_t detour_transaction_commit_ex(detour_func_t** out_failed_target)
// Update any suspended threads.
for (detour_pending_thread* thread = s_pending_threads_head; thread != nullptr; thread = thread->next) {
internal_detour_update_thread_on_commit(thread, s_pending_operations_head);
detour_platform_update_thread_on_commit(thread, s_pending_operations_head);
}
// Restore all the page permissions
@ -606,8 +606,8 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
detour_trampoline* trampoline = nullptr;
detour_operation* op = nullptr;
uint8_t* target = internal_detour_skip_jmp(*inout_pointer);
detour = internal_detour_skip_jmp(detour);
uint8_t* target = detour_platform_skip_jmp(*inout_pointer);
detour = detour_platform_skip_jmp(detour);
// Don't follow a jump if its destination is the target function.
// This happens when the detour does nothing other than call the target.
@ -678,7 +678,7 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
uint32_t offset_target = 0;
uint32_t align_idx = 0;
while (offset_target < DETOUR_SIZE_OF_JMP) {
while (offset_target < DETOUR_PLATFORM_SIZE_OF_JMP) {
const uint8_t* curr_op = src;
uint32_t extra_len = 0;
@ -695,14 +695,14 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
break;
}
if (internal_detour_does_code_end_function(curr_op)) {
if (detour_platform_does_code_end_function(curr_op)) {
break;
}
}
// Consume, but don't duplicate padding if it is needed and available.
while (offset_target < DETOUR_SIZE_OF_JMP) {
const uint32_t len_filler = internal_detour_is_code_filler(src);
while (offset_target < DETOUR_PLATFORM_SIZE_OF_JMP) {
const uint32_t len_filler = detour_platform_is_code_filler(src);
if (len_filler == 0) {
break;
}
@ -725,7 +725,7 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
}
#endif
if (offset_target < DETOUR_SIZE_OF_JMP || align_idx > ARRAYSIZE(trampoline->align)) {
if (offset_target < DETOUR_PLATFORM_SIZE_OF_JMP || align_idx > ARRAYSIZE(trampoline->align)) {
// Too few instructions.
error = detour_err_too_small;
if (s_ignore_too_small) {
@ -744,7 +744,7 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
trampoline->restore_code_size = (uint8_t)offset_target;
memcpy(trampoline->restore_code, target, offset_target);
if (offset_target > sizeof(trampoline->code) - DETOUR_SIZE_OF_JMP) {
if (offset_target > sizeof(trampoline->code) - DETOUR_PLATFORM_SIZE_OF_JMP) {
// Too many instructions.
error = detour_err_too_large;
DETOUR_BREAK();
@ -757,8 +757,8 @@ mach_error_t detour_attach_ex(detour_func_t* inout_pointer, detour_func_t detour
trampoline_code = trampoline->code + trampoline->code_size;
trampoline_code =
internal_detour_gen_jmp_immediate(trampoline_code, &trampoline_code_limit, trampoline->ptr_remain);
trampoline_code = internal_detour_gen_brk(trampoline_code, trampoline_code_limit);
detour_platform_gen_jmp_immediate(trampoline_code, &trampoline_code_limit, trampoline->ptr_remain);
trampoline_code = detour_platform_gen_brk(trampoline_code, trampoline_code_limit);
UNUSED_VARIABLE(trampoline_code);
const mach_port_t port = mach_task_self();
@ -856,8 +856,8 @@ mach_error_t detour_detach(detour_func_t* inout_pointer, detour_func_t detour)
return error;
}
detour_trampoline* trampoline = (detour_trampoline*)internal_detour_skip_jmp(*inout_pointer);
detour = internal_detour_skip_jmp(detour);
detour_trampoline* trampoline = (detour_trampoline*)detour_platform_skip_jmp(*inout_pointer);
detour = detour_platform_skip_jmp(detour);
// Verify that Trampoline is in place.
const int32_t restore_code_size = trampoline->restore_code_size;