diff options
author | Michael Smith <mikesmiffy128@gmail.com> | 2024-08-03 23:40:31 +0100 |
---|---|---|
committer | Michael Smith <mikesmiffy128@gmail.com> | 2024-08-23 20:37:37 +0100 |
commit | 83da606072ce272eb053d4e1497d77e647cfecae (patch) | |
tree | 71d0110881ff8685184c5f4ab720cc8d49c24678 /src/hook.c | |
parent | acbd30e0427b16f885f96aed59881ec04eff25bc (diff) |
Revise syntax macros and add a ton of branch hints
My new programming style is branch hints. All non-confusing branches
must be hinted when I can be bothered. It's faster, sometimes, maybe.
Also, start trying to use more signed sizes in at least some of the
places where it makes sense. Unsigned sizes are surprisingly
error-prone!
Diffstat (limited to 'src/hook.c')
-rw-r--r-- | src/hook.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -19,6 +19,7 @@ #include "con_.h" #include "intdefs.h" +#include "langext.h" #include "mem.h" #include "os.h" #include "x86.h" @@ -67,7 +68,7 @@ void *hook_inline(void *func_, void *target) { // dumb hack: if we hit some thunk that immediately jumps elsewhere (which // seems common for win32 API functions), hook the underlying thing instead. while (*func == X86_JMPIW) func += mem_loads32(func + 1) + 5; - if (!os_mprot(func, 5, PAGE_EXECUTE_READWRITE)) return 0; + if_cold (!os_mprot(func, 5, PAGE_EXECUTE_READWRITE)) return 0; int len = 0; for (;;) { // FIXME: these cases may result in somewhat dodgy error messaging. They @@ -91,7 +92,7 @@ void *hook_inline(void *func_, void *target) { } } // for simplicity, just bump alloc the trampoline. no need to free anyway - if (nexttrampoline - trampolines > sizeof(trampolines) - len - 6) { + if_cold (nexttrampoline - trampolines > sizeof(trampolines) - len - 6) { con_warn("hook_inline: out of trampoline space\n"); return 0; } |