about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhexcoder- <heiko@hexco.de>2019-09-28 20:50:13 +0200
committerhexcoder- <heiko@hexco.de>2019-09-28 20:50:13 +0200
commit942245b9852e4028f1ec5785c5b8f6df9301b279 (patch)
treedbd96a9f41b5730467abedeff2556f68e0c947b6
parent6e25fde883ce8f3e478ae81b6f0ac2563f1e7bb1 (diff)
downloadafl++-942245b9852e4028f1ec5785c5b8f6df9301b279.tar.gz
included #68 cpu binding for FreeBSD, thanks to devnexen
-rw-r--r--Makefile4
-rw-r--r--src/afl-gotcpu.c17
2 files changed, 19 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index 6cfd16ca..aab53f6d 100644
--- a/Makefile
+++ b/Makefile
@@ -45,6 +45,10 @@ ifneq "$(filter Linux GNU%,$(shell uname))" ""
   LDFLAGS  += -ldl
 endif
 
+ifneq "$(findstring FreeBSD, $(shell uname))" ""
+  CFLAGS += -pthread
+endif
+
 ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" ""
   TEST_CC   = afl-gcc
 else
diff --git a/src/afl-gotcpu.c b/src/afl-gotcpu.c
index de41177c..c3a60c6c 100644
--- a/src/afl-gotcpu.c
+++ b/src/afl-gotcpu.c
@@ -52,9 +52,15 @@
 #include "types.h"
 #include "debug.h"
 
-#ifdef __linux__
+#if defined(__linux__) || defined(__FreeBSD__)
 #define HAVE_AFFINITY 1
-#endif                                                         /* __linux__ */
+# if defined(__FreeBSD__)
+#   include <pthread.h>
+#   include <pthread_np.h>
+#   include <sys/cpuset.h>
+#   define cpu_set_t cpuset_t
+# endif
+#endif                                      /* __linux__ || __FreeBSD__ */
 
 /* Get unix time in microseconds. */
 
@@ -160,8 +166,15 @@ int main(int argc, char** argv) {
       CPU_ZERO(&c);
       CPU_SET(i, &c);
 
+#if defined(__FreeBSD__)
+      if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
+        PFATAL("pthread_setaffinity_np failed");
+#endif
+
+#if defined(__linux__)
       if (sched_setaffinity(0, sizeof(c), &c))
         PFATAL("sched_setaffinity failed");
+#endif
 
       util_perc = measure_preemption(CTEST_CORE_TRG_MS);