summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorGravatar Michael Smith <mikesmiffy128@gmail.com> 2025-12-18 21:35:50 +0000
committerGravatar Michael Smith <mikesmiffy128@gmail.com> 2026-02-16 19:11:24 +0000
commit7a07c08abe46f97f2412f06c77204e9015f97a47 (patch)
tree581b80f55d7d66592fda98fb492d7465cc33f191 /test
parent186aea515dd773bb11464714886ca5203d2be2ab (diff)
downloadsst-7a07c08abe46f97f2412f06c77204e9015f97a47.tar.gz
sst-7a07c08abe46f97f2412f06c77204e9015f97a47.zip
Move to a shared static RWX section
Does away with the need to mark a region as executable on load. Also allows the self-modified stuff and hook trampolines to fit in the same page, so we take up ever-so-slightly less memory. Unfortunately I had issues getting the test binary to build correctly and eventually decided to give up as it wasn't testing much of value anyway. Also note that the build now allows for .c and .S files with the same basename, which required renaming the .o files, so you might want to clean out your .build/ directory before building this one.
Diffstat (limited to 'test')
-rw-r--r--test/hook.test.c71
1 files changed, 0 insertions, 71 deletions
diff --git a/test/hook.test.c b/test/hook.test.c
deleted file mode 100644
index 6a9a7b4..0000000
--- a/test/hook.test.c
+++ /dev/null
@@ -1,71 +0,0 @@
-/* This file is dedicated to the public domain. */
-
-{.desc = "inline function hooking"};
-
-#ifdef _WIN32
-
-#include "../src/chunklets/x86.c"
-#include "../src/hook.c"
-#include "../src/os.c"
-
-#include <stdarg.h>
-#include <stdio.h>
-#include <string.h>
-
-// stub
-void con_warn(const char *msg, ...) {
- va_list l;
- va_start(l, msg);
- vfprintf(stderr, msg, l);
- va_end(l);
-}
-
-typedef int (*testfunc)(int, int);
-
-__attribute__((noinline)) static int func1(int a, int b) { return a + b; }
-static int (*orig_func1)(int, int);
-static int hook1(int a, int b) { return orig_func1(a, b) + 5; }
-
-__attribute__((noinline)) static int func2(int a, int b) { return a - b; }
-static int (*orig_func2)(int, int);
-static int hook2(int a, int b) { return orig_func2(a, b) + 5; }
-
-// basic reimplementation of old API to support existing test cases.
-// XXX: we could probably have tests at the boundaries of the new API too,
-// although the current tests are only testing for regressions in x86 jmp logic.
-static inline void *test_hook_inline(void *func, void *target) {
- void *trampoline;
- struct hook_inline_prep_ret prep = hook_inline_prep(func, &trampoline);
- if (prep.err) return 0;
- if (!hook_inline_mprot(prep.prologue)) return 0;
- hook_inline_commit(prep.prologue, target);
- return trampoline;
-}
-
-TEST("Inline hooks should be able to wrap the original function") {
- if (!hook_init()) return false;
- orig_func1 = (testfunc)test_hook_inline((void *)&func1, (void *)&hook1);
- if (!orig_func1) return false;
- return func1(5, 5) == 15;
-}
-
-TEST("Inline hooks should be removable again") {
- if (!hook_init()) return false;
- orig_func1 = (testfunc)test_hook_inline((void *)&func1, (void *)&hook1);
- if (!orig_func1) return false;
- unhook_inline((void *)orig_func1);
- return func1(5, 5) == 10;
-}
-
-TEST("Multiple functions should be able to be inline-hooked at once") {
- if (!hook_init()) return false;
- orig_func1 = (testfunc)test_hook_inline((void *)&func1, (void *)&hook1);
- if (!orig_func1) return false;
- orig_func2 = (testfunc)test_hook_inline((void *)&func2, (void *)&hook2);
- if (!orig_func2) return false;
- return func2(5, 5) == 5;
-}
-
-#endif
-
-// vi: sw=4 ts=4 noet tw=80 cc=80