diff options
author | Yifan Lu | 2016-10-26 19:12:21 -0700 |
---|---|---|
committer | Yifan Lu | 2016-10-26 19:12:21 -0700 |
commit | e895cdc598997a83a7999b558fba745ebc2a815d (patch) | |
tree | b9e6c0b4b05c9ddc60482acdeb6b3be7da62421c | |
parent | Vita: Added logging and changed cache flush name (diff) | |
download | substitute-e895cdc598997a83a7999b558fba745ebc2a815d.tar.gz |
Added passing of the opt data to records
-rw-r--r-- | lib/hook-functions.c | 3 | ||||
-rw-r--r-- | lib/substitute.h | 5 |
2 files changed, 6 insertions, 2 deletions
diff --git a/lib/hook-functions.c b/lib/hook-functions.c index 310b839..674d424 100644 --- a/lib/hook-functions.c +++ b/lib/hook-functions.c @@ -295,6 +295,7 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks, fws[i].opt = hooks[i].opt; if (records) { records->function = hi->code; + records->opt = hooks[i].opt; records->buffer_size = hi->jump_patch_size; memcpy(records->saved_buffer, hi->code, hi->jump_patch_size); records = (struct substitute_function_hook_record *)((char *)&records->saved_buffer + records->buffer_size); @@ -337,7 +338,7 @@ int substitute_free_hooks(struct substitute_function_hook_record *records, fws[i].dst = cur->function; fws[i].src = cur->saved_buffer; fws[i].len = cur->buffer_size; - fws[i].opt = NULL; + fws[i].opt = cur->opt; cur = (struct substitute_function_hook_record *)((char *)&cur->saved_buffer + cur->buffer_size); } /* TODO: Fix the case when thread is inside a patch/trampoline. */ diff --git a/lib/substitute.h b/lib/substitute.h index becf4b0..8cc2a4d 100644 --- a/lib/substitute.h +++ b/lib/substitute.h @@ -98,13 +98,16 @@ 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 */ + /* 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 |