From 7c26a1964d2d2e54f87d9c42735f6c99b546abd4 Mon Sep 17 00:00:00 2001 From: comex Date: Wed, 18 Feb 2015 02:22:36 -0500 Subject: Fix hook-function: - Thread stoppage is now complemented by sigaction to catch injected threads (sigaction is not used exclusively because the rest of the program could be trying to use sigaction itself in the meantime - this is a real thing, ask Dolphin) - mprotect is no longer used due to max_protection possibly getting in the way; instead, a copy is created and mapped onto the original. --- lib/execmem.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'lib/execmem.h') diff --git a/lib/execmem.h b/lib/execmem.h index b4860e9..895769d 100644 --- a/lib/execmem.h +++ b/lib/execmem.h @@ -1,9 +1,22 @@ #pragma once -#include -/* Write to a foreign page which is already RX / with unknown permissions. */ -int execmem_write(void *dest, const void *src, size_t len); - +#include /* For allocating trampolines - this is just a mmap wrapper. */ int execmem_alloc_unsealed(uintptr_t hint, void **page_p, size_t *size_p); int execmem_seal(void *page); void execmem_free(void *page); + +/* Write to foreign pages which are already RX or have unknown permissions. + * If callback is not NULL, run it on all other threads 'atomically', in the + * sense that it will be called on any thread which executed any of the old + * instructions in the write region. + * Oh, and it might mutate writes (to sort it). */ +struct execmem_foreign_write { + void *dst; + const void *src; + size_t len; +}; +typedef uintptr_t (*execmem_pc_patch_callback)(void *ctx, uintptr_t pc); +int execmem_foreign_write_with_pc_patch(struct execmem_foreign_write *writes, + size_t nwrites, + execmem_pc_patch_callback callback, + void *callback_ctx); -- cgit v1.2.3