From 2795a1a5b34bffc350f9366fcf05a6165067eafa Mon Sep 17 00:00:00 2001 From: comex Date: Wed, 21 Jan 2015 18:24:08 -0500 Subject: stopping other threads. --- lib/hook-functions.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lib/hook-functions.c (limited to 'lib/hook-functions.c') diff --git a/lib/hook-functions.c b/lib/hook-functions.c new file mode 100644 index 0000000..975520e --- /dev/null +++ b/lib/hook-functions.c @@ -0,0 +1,32 @@ +#include "substitute.h" +#include "substitute-internal.h" + +static uintptr_t patch_callback(UNUSED void *ctx, uintptr_t pc) { + printf("patch_callback: pc=%llx\n", (long long) pc); + return pc; +} + +EXPORT +int substitute_hook_functions(const struct substitute_function_hook *hooks, + size_t nhooks, + int options) { + (void) hooks; (void) nhooks; + int ret = SUBSTITUTE_OK; + void *stop_token; + if (!(options & SUBSTITUTE_DONT_STOP_THREADS)) { + if ((ret = stop_other_threads(&stop_token))) + return ret; + } + if (!(options & SUBSTITUTE_DONT_STOP_THREADS)) { + if ((ret = apply_pc_patch_callback(stop_token, patch_callback, NULL))) + goto fail; + } + +fail: + if (!(options & SUBSTITUTE_DONT_STOP_THREADS)) { + int r2 = resume_other_threads(stop_token); + if (!ret) + ret = r2; + } + return ret; +} -- cgit v1.2.3