aboutsummaryrefslogtreecommitdiff
path: root/src/hook.c
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-16 20:58:38 +0100
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-04-16 21:31:20 +0100
commit7dcdcd0f62c7c103148b17aed8376a457aad6d8a (patch)
treebcd4b63f5c3e6a24550292e1d9dae80b28cada54 /src/hook.c
parent4fddfa831d2a33ab3eee7ceb5f181c82d5aa78d2 (diff)
downloadsst-7dcdcd0f62c7c103148b17aed8376a457aad6d8a.tar.gz
sst-7dcdcd0f62c7c103148b17aed8376a457aad6d8a.zip
Remove iflush() from inline hooking code
I had this hunch that Intel's strong memory model wouldn't actually require anything like this, and some cursory research suggests this is correct even across threads, or at least definitely within the same thread which is what we care about. I kind of don't know why FlushInstructionCache() even exists in that case. Maybe it's for other architectures or maybe it's just for the benefit of debuggers. Microsoft's documentation helpfully asserts that it is necessary to call it even though it isn't, and doesn't elaborate further. Of course.
Diffstat (limited to 'src/hook.c')
-rw-r--r--src/hook.c21
1 files changed, 0 insertions, 21 deletions
diff --git a/src/hook.c b/src/hook.c
index a1504da..5f964ad 100644
--- a/src/hook.c
+++ b/src/hook.c
@@ -24,13 +24,6 @@
#include "os.h"
#include "x86.h"
-#ifdef _WIN32
-// try to avoid pulling in all of Windows.h for this... (redundant dllimport
-// avoids warnings in hook.test.c where Windows.h is included via test.h)
-__declspec(dllimport) int __stdcall FlushInstructionCache(
- void *, const void *, usize);
-#endif
-
// Warning: half-arsed hacky implementation (because that's all we really need)
// Almost certainly breaks in some weird cases. Oh well! Most of the time,
// vtable hooking is more reliable, this is only for, uh, emergencies.
@@ -44,18 +37,6 @@ bool hook_init() {
return os_mprot(trampolines, 4096, PAGE_EXECUTE_READWRITE);
}
-static inline void iflush(void *p, int len) {
-#if defined(_WIN32)
- // -1 is the current process, and it's a constant in the WDK, so it's
- // assumed we can safely avoid the useless GetCurrentProcess call
- FlushInstructionCache((void *)-1, p, len);
-#elif defined(__GNUC__)
- __builtin___clear_cache((char *)p, (char *)p + len);
-#else
-#error no way to flush instruction cache
-#endif
-}
-
struct hook_inline_prep_ret hook_inline_prep(void *func, void **trampoline) {
uchar *p = func;
// dumb hack: if we hit some thunk that immediately jumps elsewhere (which
@@ -108,7 +89,6 @@ void hook_inline_commit(void *restrict prologue, void *restrict target) {
u32 diff = (uchar *)target - (p + 5); // goto the hook target
p[0] = X86_JMPIW;
memcpy(p + 1, &diff, 4);
- iflush(p, 5);
}
void unhook_inline(void *orig) {
@@ -117,7 +97,6 @@ void unhook_inline(void *orig) {
int off = mem_loads32(p + len + 1);
uchar *q = p + off + 5;
memcpy(q, p, 5); // XXX: not atomic atm! (does any of it even need to be?)
- iflush(q, 5);
}
// vi: sw=4 ts=4 noet tw=80 cc=80