about summary refs log tree commit diff
path: root/instrumentation/afl-compiler-rt.o.c
diff options
context:
space:
mode:
authorvanhauser-thc <vh@thc.org>2022-02-08 20:36:06 +0100
committervanhauser-thc <vh@thc.org>2022-02-08 20:36:06 +0100
commit056ebbff15bb6ebef6664776dee05217cebdc7fe (patch)
tree5b413281a88e52722571474a6cc3cf6491f7c294 /instrumentation/afl-compiler-rt.o.c
parentcf853fb2494912a1c4b531ffcf302843266639b7 (diff)
downloadafl++-056ebbff15bb6ebef6664776dee05217cebdc7fe.tar.gz
add AFL_EARLY_FORKSERVER support
Diffstat (limited to 'instrumentation/afl-compiler-rt.o.c')
-rw-r--r--instrumentation/afl-compiler-rt.o.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/instrumentation/afl-compiler-rt.o.c b/instrumentation/afl-compiler-rt.o.c
index 9a12831e..db7ac7b0 100644
--- a/instrumentation/afl-compiler-rt.o.c
+++ b/instrumentation/afl-compiler-rt.o.c
@@ -68,6 +68,7 @@
 #endif
 
 #define CTOR_PRIO 3
+#define EARLY_FS_PRIO 5
 
 #include <sys/mman.h>
 #include <fcntl.h>
@@ -145,6 +146,7 @@ u32 __afl_already_initialized_shm;
 u32 __afl_already_initialized_forkserver;
 u32 __afl_already_initialized_first;
 u32 __afl_already_initialized_second;
+u32 __afl_already_initialized_init;
 
 /* Dummy pipe for area_is_valid() */
 
@@ -1253,6 +1255,8 @@ void __afl_manual_init(void) {
 
 __attribute__((constructor())) void __afl_auto_init(void) {
 
+  if (__afl_already_initialized_init) { return; }
+
 #ifdef __ANDROID__
   // Disable handlers in linker/debuggerd, check include/debuggerd/handler.h
   signal(SIGABRT, SIG_DFL);
@@ -1265,6 +1269,8 @@ __attribute__((constructor())) void __afl_auto_init(void) {
   signal(SIGTRAP, SIG_DFL);
 #endif
 
+  __afl_already_initialized_init = 1;
+
   if (getenv("AFL_DISABLE_LLVM_INSTRUMENTATION")) return;
 
   if (getenv(DEFER_ENV_VAR)) return;
@@ -1273,6 +1279,14 @@ __attribute__((constructor())) void __afl_auto_init(void) {
 
 }
 
+/* Optionally run an early forkserver */
+
+__attribute__((constructor(EARLY_FS_PRIO))) void __early_forkserver(void) {
+
+  if (getenv("AFL_EARLY_FORKSERVER")) { __afl_auto_init(); }
+
+}
+
 /* Initialization of the shmem - earliest possible because of LTO fixed mem. */
 
 __attribute__((constructor(CTOR_PRIO))) void __afl_auto_early(void) {