From e3fd5ad05a7d933d401de431ce2d27a99d3b9995 Mon Sep 17 00:00:00 2001 From: Michael Smith Date: Mon, 27 Jun 2022 00:36:48 +0100 Subject: Add update detection, clean up minor stuff --- src/hook.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/hook.c') diff --git a/src/hook.c b/src/hook.c index bca226d..8465fbe 100644 --- a/src/hook.c +++ b/src/hook.c @@ -29,14 +29,20 @@ #if defined(_WIN32) && !defined(_WIN64) +#if defined(__GNUC__) || defined(__clang__) __attribute__((aligned(4096))) +#elif defined(_MSC_VER) +__declspec(align(4096)) +#else +#error no way to align stuff! +#endif static uchar trampolines[4096]; static uchar *nexttrampoline = trampolines; -__attribute__((constructor)) -static void setrwx(void) { - // PE doesn't support rwx sections, not sure about ELF. Eh, just hack it in - // a constructor instead. If this fails and we segfault later, too bad! - os_mprot(trampolines, sizeof(trampolines), PAGE_EXECUTE_READWRITE); + +bool hook_init(void) { + // PE doesn't support rwx sections, not sure about ELF. Meh, just set it + // here instead. + return os_mprot(trampolines, sizeof(trampolines), PAGE_EXECUTE_READWRITE); } void *hook_inline(void *func_, void *target) { -- cgit v1.2.3