From 4792258fd0b2dc7ac89d98b270e10264c5491e82 Mon Sep 17 00:00:00 2001 From: Yifan Lu Date: Tue, 4 Oct 2016 19:51:51 -0700 Subject: Added option to removed pthread dependency Added option to remove dynamic linker stuff Fixed a reference in strerror.c that depends on __APPLE__ being defined --- lib/hook-functions.c | 6 ++++++ lib/strerror.c | 2 ++ lib/substitute.h | 6 ++++-- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/hook-functions.c b/lib/hook-functions.c index fed9e3e..8363567 100644 --- a/lib/hook-functions.c +++ b/lib/hook-functions.c @@ -5,7 +5,9 @@ #include "transform-dis.h" #include "execmem.h" #include stringify(TARGET_DIR/jump-patch.h) +#ifndef NO_PTHREADS #include +#endif struct hook_internal { int offset_by_pcdiff[MAX_EXTENDED_PATCH_SIZE + 1]; @@ -135,9 +137,13 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks, size_t nhooks, struct substitute_function_hook_record **recordp, int options) { +#ifndef NO_PTHREADS bool thread_safe = !(options & SUBSTITUTE_NO_THREAD_SAFETY); if (thread_safe && !pthread_main_np()) return SUBSTITUTE_ERR_NOT_ON_MAIN_THREAD; +#else + bool thread_safe = false; +#endif if (recordp) *recordp = NULL; diff --git a/lib/strerror.c b/lib/strerror.c index 3720f57..db11944 100644 --- a/lib/strerror.c +++ b/lib/strerror.c @@ -24,8 +24,10 @@ const char *substitute_strerror(int err) { _SUBSTITUTE_CURRENT_MAX_ERR_PLUS_ONE + 1, "not all errors named in strerror.c"); /* substitute-internal.h */ +#ifdef __APPLE__ CASE(SUBSTITUTE_ERR_TASK_FOR_PID); CASE(SUBSTITUTE_ERR_MISC); +#endif /* __APPLE__ */ default: return "(unknown libsubstitute error)"; } diff --git a/lib/substitute.h b/lib/substitute.h index 72c3919..d3af586 100644 --- a/lib/substitute.h +++ b/lib/substitute.h @@ -101,9 +101,11 @@ struct substitute_function_hook { }; /* 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. @@ -153,7 +155,7 @@ int substitute_hook_functions(const struct substitute_function_hook *hooks, struct substitute_function_hook_record **recordp, int options); -#if 1 /* declare dynamic linker-related stuff? */ +#ifndef NO_DYNAMIC_LINKER_STUFF /* declare dynamic linker-related stuff? */ #ifdef __APPLE__ #include @@ -271,7 +273,7 @@ int substitute_interpose_imports(const struct substitute_image *handle, int options); -#endif /* 1 */ +#endif /* NO_DYNAMIC_LINKER_STUFF */ #if defined(__APPLE__) #include -- cgit v1.2.3