From 90600faa134fcaab4d132f02ebd58a6afea46039 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 31 Jul 2019 09:03:32 +0000 Subject: [PATCH] FreeBSD: implements cpu availability command line. --- afl-gotcpu.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/afl-gotcpu.c b/afl-gotcpu.c index 35ff92223..9a6604530 100644 --- a/afl-gotcpu.c +++ b/afl-gotcpu.c @@ -49,8 +49,14 @@ #include "types.h" #include "debug.h" -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) # define HAVE_AFFINITY 1 +# if defined(__FreeBSD__) +# include +# include +# include +# define cpu_set_t cpuset_t +# endif #endif /* __linux__ */ @@ -149,8 +155,13 @@ 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"); +#else if (sched_setaffinity(0, sizeof(c), &c)) PFATAL("sched_setaffinity failed"); +#endif util_perc = measure_preemption(CTEST_CORE_TRG_MS);