aboutsummaryrefslogtreecommitdiff
path: root/lib/hook-functions.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/hook-functions.c')
-rw-r--r--lib/hook-functions.c32
1 files changed, 32 insertions, 0 deletions
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;
+}