diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/strerror.c | 7 | ||||
-rw-r--r-- | lib/substitute-internal.h | 1 | ||||
-rw-r--r-- | lib/substitute.h | 26 |
3 files changed, 20 insertions, 14 deletions
diff --git a/lib/strerror.c b/lib/strerror.c index 3cdecae..3720f57 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -3,12 +3,14 @@ EXPORT const char *substitute_strerror(int err) { - #define CASE(code) case code: return #code + #define CASE(code) case code: (void) __COUNTER__; return #code switch (err) { /* substitute.h */ + enum { _start = __COUNTER__ }; CASE(SUBSTITUTE_OK); CASE(SUBSTITUTE_ERR_FUNC_TOO_SHORT); CASE(SUBSTITUTE_ERR_FUNC_BAD_INSN_AT_START); + CASE(SUBSTITUTE_ERR_FUNC_CALLS_AT_START); CASE(SUBSTITUTE_ERR_FUNC_JUMPS_TO_START); CASE(SUBSTITUTE_ERR_OOM); CASE(SUBSTITUTE_ERR_VM); @@ -18,6 +20,9 @@ const char *substitute_strerror(int err) { CASE(SUBSTITUTE_ERR_UNKNOWN_RELOCATION_TYPE); CASE(SUBSTITUTE_ERR_NO_SUCH_SELECTOR); CASE(SUBSTITUTE_ERR_ADJUSTING_THREADS); + _Static_assert(__COUNTER__ - _start == + _SUBSTITUTE_CURRENT_MAX_ERR_PLUS_ONE + 1, + "not all errors named in strerror.c"); /* substitute-internal.h */ CASE(SUBSTITUTE_ERR_TASK_FOR_PID); CASE(SUBSTITUTE_ERR_MISC); diff --git a/lib/substitute-internal.h b/lib/substitute-internal.h index 8f900a4..80c8b22 100644 --- a/lib/substitute-internal.h +++ b/lib/substitute-internal.h @@ -75,7 +75,6 @@ enum { * can happen are really complicated and dumb, but generally one solution * is to be root */ SUBSTITUTE_ERR_TASK_FOR_PID = 1000, - SUBSTITUTE_ERR_TIMEOUT = 1000, SUBSTITUTE_ERR_MISC, }; diff --git a/lib/substitute.h b/lib/substitute.h index d8b9fd0..749b83f 100644 --- a/lib/substitute.h +++ b/lib/substitute.h @@ -21,13 +21,13 @@ enum { /* substitute_hook_functions: can't patch a function because it's too short- * i.e. there's an unconditional return instruction inside the patch region * (and not at its end) */ - SUBSTITUTE_ERR_FUNC_TOO_SHORT, + SUBSTITUTE_ERR_FUNC_TOO_SHORT = 1, /* substitute_hook_functions: can't patch a function because one of the * instructions within the patch region is one of a few special problematic * cases - if you get this on real code, the library should probably be * updated to handle that case properly */ - SUBSTITUTE_ERR_FUNC_BAD_INSN_AT_START, + SUBSTITUTE_ERR_FUNC_BAD_INSN_AT_START = 2, /* substitute_hook_functions: can't patch a function because one of the * instructions within the patch region (other than the last instruction) @@ -35,28 +35,28 @@ enum { * to point to clobbered code) could be on some thread's stack, where we * can't easily find and patch it. This check is skipped if * SUBSTITUTE_NO_THREAD_SAFETY is set. */ - SUBSTITUTE_ERR_FUNC_CALLS_AT_START, + SUBSTITUTE_ERR_FUNC_CALLS_AT_START = 3, /* substitute_hook_functions: can't patch a function because the (somewhat * cursory) jump analysis found a jump later in the function to within the * patch region at the beginning */ - SUBSTITUTE_ERR_FUNC_JUMPS_TO_START, + SUBSTITUTE_ERR_FUNC_JUMPS_TO_START = 4, /* out of memory */ - SUBSTITUTE_ERR_OOM, + SUBSTITUTE_ERR_OOM = 5, /* substitute_hook_functions: mmap, mprotect, vm_copy, or * vm_remap failure * substitute_hook_objc_message: vm_remap failure * Most likely to come up with substitute_hook_functions if the kernel is * preventing pages from being marked executable. */ - SUBSTITUTE_ERR_VM, + SUBSTITUTE_ERR_VM = 6, /* substitute_hook_functions: not on the main thread (so stopping all other * threads would be unsafe, as concurrent attempts to do the same from * other threads would result in deadlock), and you did not pass * SUBSTITUTE_NO_THREAD_SAFETY */ - SUBSTITUTE_ERR_NOT_ON_MAIN_THREAD, + SUBSTITUTE_ERR_NOT_ON_MAIN_THREAD = 7, /* substitute_hook_functions: when trying to patch the PC of other threads * (in case they were inside the patched prolog when they were suspended), @@ -64,22 +64,24 @@ enum { * instruction boundary * The hooks were otherwise completed, but the thread in question will * probably crash now that its code has changed under it. */ - SUBSTITUTE_ERR_UNEXPECTED_PC_ON_OTHER_THREAD, + SUBSTITUTE_ERR_UNEXPECTED_PC_ON_OTHER_THREAD = 8, /* substitute_hook_functions: destination was out of range, and mmap * wouldn't give us a trampoline in range */ - SUBSTITUTE_ERR_OUT_OF_RANGE, + SUBSTITUTE_ERR_OUT_OF_RANGE = 9, /* substitute_interpose_imports: couldn't redo relocation for an import * because the type was unknown */ - SUBSTITUTE_ERR_UNKNOWN_RELOCATION_TYPE, + SUBSTITUTE_ERR_UNKNOWN_RELOCATION_TYPE = 10, /* substitute_hook_objc_message: no such selector existed in the class's * inheritance tree */ - SUBSTITUTE_ERR_NO_SUCH_SELECTOR, + SUBSTITUTE_ERR_NO_SUCH_SELECTOR = 11, /* substitute_hook_functions: OS error suspending other threads */ - SUBSTITUTE_ERR_ADJUSTING_THREADS, + SUBSTITUTE_ERR_ADJUSTING_THREADS = 12, + + _SUBSTITUTE_CURRENT_MAX_ERR_PLUS_ONE, }; struct substitute_function_hook { |