aboutsummaryrefslogtreecommitdiff
path: root/lib/substitute.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/substitute.h')
-rw-r--r--lib/substitute.h35
1 files changed, 31 insertions, 4 deletions
diff --git a/lib/substitute.h b/lib/substitute.h
index 72c3919..8cc2a4d 100644
--- a/lib/substitute.h
+++ b/lib/substitute.h
@@ -98,12 +98,29 @@ struct substitute_function_hook {
/* Currently unused; pass 0. (Protip: When using C {} struct initializer
* syntax, you can just omit this.) */
int options;
+ /* Any platform specific auxiliary data. The data pointed to must remain
+ * valid until after the hook is freed! */
+ void *opt;
+};
+
+struct substitute_function_hook_record {
+ /* Function that was originally hooked. */
+ void *function;
+ /* Any platform specific auxiliary data copied from the hook */
+ void *opt;
+ /** Should at least be MAX_JUMP_PATCH_SIZE for your platform */
+ size_t buffer_size;
+ /** Store the original code. Must be large enough to hold MAX_JUMP_PATCH_SIZE
+ * for whatever platform your are targeting! */
+ char saved_buffer[];
};
/* substitute_hook_functions options */
+#ifndef NO_PTHREADS
enum {
SUBSTITUTE_NO_THREAD_SAFETY = 1,
};
+#endif
/* Patch the machine code of the specified functions to redirect them to the
* specified replacements.
@@ -143,17 +160,27 @@ enum {
* @hooks see struct substitute_function_hook
* @nhooks number of hooks
* @recordp if non-NULL, on success receives a pointer that can be used to
- * cleanly undo the hooks; currently unimplemented, so pass NULL
+ * cleanly undo the hooks
* @options options - see above
* @return SUBSTITUTE_OK, or any of most of the SUBSTITUTE_ERR_*
*/
-struct substitute_function_hook_record;
int substitute_hook_functions(const struct substitute_function_hook *hooks,
size_t nhooks,
struct substitute_function_hook_record **recordp,
int options);
-#if 1 /* declare dynamic linker-related stuff? */
+/**
+ * @brief Frees hooks and restores original code.
+ *
+ * @param records from `substitute_hook_functions`
+ * @param[in] nhooks Number of hooks to free
+ *
+ * @return SUBSTITUTE_OK, or any of most of the SUBSTITUTE_ERR_*
+ */
+int substitute_free_hooks(struct substitute_function_hook_record *records,
+ size_t nhooks);
+
+#ifndef NO_DYNAMIC_LINKER_STUFF /* declare dynamic linker-related stuff? */
#ifdef __APPLE__
#include <mach-o/nlist.h>
@@ -271,7 +298,7 @@ int substitute_interpose_imports(const struct substitute_image *handle,
int options);
-#endif /* 1 */
+#endif /* NO_DYNAMIC_LINKER_STUFF */
#if defined(__APPLE__)
#include <objc/runtime.h>