aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYifan Lu2016-10-04 19:51:51 -0700
committerYifan Lu2016-10-04 19:51:51 -0700
commit4792258fd0b2dc7ac89d98b270e10264c5491e82 (patch)
tree54a44b939fb8f815f920bde71aa0b9223a2a842e
parentmake ln command more robust (diff)
downloadsubstitute-4792258fd0b2dc7ac89d98b270e10264c5491e82.tar.gz
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
-rw-r--r--lib/hook-functions.c6
-rw-r--r--lib/strerror.c2
-rw-r--r--lib/substitute.h6
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 <pthread.h>
+#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 <mach-o/nlist.h>
@@ -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 <objc/runtime.h>