aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorhexcoder <hexcoder-@users.noreply.github.com>2019-10-19 17:37:40 +0200
committerGitHub <noreply@github.com>2019-10-19 17:37:40 +0200
commit452ec28761db9648e2f4b66b1e9374ca3f62e22d (patch)
tree67930a6055b279c690eaed94f6434c1a8a9c96b0 /src
parent8a786377196fbaafeecbca17fad66ea1e76c7de2 (diff)
parent1fdb75068d6b815baf9736e63e3545b66de688c5 (diff)
downloadAFLplusplus-452ec28761db9648e2f4b66b1e9374ca3f62e22d.tar.gz
Merge pull request #82 from devnexen/darwin_gotcpu_portage
afl-gotcpu: porting to Darwin using mach API. Thanks! Looks good!
Diffstat (limited to 'src')
-rw-r--r--src/afl-gotcpu.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/afl-gotcpu.c b/src/afl-gotcpu.c
index bdb727de..dc938b65 100644
--- a/src/afl-gotcpu.c
+++ b/src/afl-gotcpu.c
@@ -52,7 +52,7 @@
#include "types.h"
#include "debug.h"
-#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
+#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__APPLE__)
#define HAVE_AFFINITY 1
#if defined(__FreeBSD__)
#include <pthread.h>
@@ -62,8 +62,12 @@
#elif defined(__NetBSD__)
#include <pthread.h>
#include <sched.h>
+#elif defined(__APPLE__)
+#include <pthread.h>
+#include <mach/thread_act.h>
+#include <mach/thread_policy.h>
#endif
-#endif /* __linux__ || __FreeBSD__ || __NetBSD__ */
+#endif /* __linux__ || __FreeBSD__ || __NetBSD__ || __APPLE__ */
/* Get unix time in microseconds. */
@@ -176,6 +180,12 @@ int main(int argc, char** argv) {
if (c == NULL) PFATAL("cpuset_create failed");
cpuset_set(i, c);
+#elif defined(__APPLE__)
+ thread_affinity_policy_data_t c = { i };
+ thread_port_t native_thread = pthread_mach_thread_np(pthread_self());
+ if (thread_policy_set(native_thread, THREAD_AFFINITY_POLICY,
+ (thread_policy_t)&c, 1) != KERN_SUCCESS)
+ PFATAL("thread_policy_set failed");
#endif
#if defined(__FreeBSD__)