summaryrefslogtreecommitdiffhomepage
path: root/src/hook.c
diff options
context:
space:
mode:
authorMichael Smith <mikesmiffy128@gmail.com>2023-06-10 16:44:19 +0100
committerMichael Smith <mikesmiffy128@gmail.com>2023-06-10 16:51:02 +0100
commit1c4318331663b152b0b298bd2c9e5c971506a86b (patch)
treea402681cb84b491819ba5018525c16340110fd4d /src/hook.c
parent602a18977d500ad068fd63fbedcafb630c29ee72 (diff)
Prune some comments and tidy up other minor things
Diffstat (limited to 'src/hook.c')
-rw-r--r--src/hook.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/hook.c b/src/hook.c
index ff7ac96..3d6c14d 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -47,9 +47,8 @@ bool hook_init(void) {
void *hook_inline(void *func_, void *target) {
uchar *func = func_;
- // dumb hack: rather than correcting jmp offsets and having to painstakingly
- // track them all, just look for the underlying thing being jmp-ed to and
- // hook _that_.
+ // 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_loadoffset(func + 1) + 5;
if (!os_mprot(func, 5, PAGE_EXECUTE_READWRITE)) return false;
int len = 0;
@@ -76,6 +75,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) goto nosp;
+ // TODO(opt): stop pretending to be thread-safe, it's just slowing us down
uchar *trampoline = (uchar *)InterlockedExchangeAdd(
(volatile long *)&nexttrampoline, len + 6);
// avoid TOCTOU