diff options
Diffstat (limited to 'src/afl-gotcpu.c')
-rw-r--r-- | src/afl-gotcpu.c | 39 |
1 files changed, 36 insertions, 3 deletions
diff --git a/src/afl-gotcpu.c b/src/afl-gotcpu.c index de41177c..ece5a850 100644 --- a/src/afl-gotcpu.c +++ b/src/afl-gotcpu.c @@ -52,9 +52,18 @@ #include "types.h" #include "debug.h" -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) #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 +# elif defined(__NetBSD__) +# include <pthread.h> +# include <sched.h> +# endif +#endif /* __linux__ || __FreeBSD__ || __NetBSD__ */ /* Get unix time in microseconds. */ @@ -154,14 +163,38 @@ int main(int argc, char** argv) { if (!fr) { - cpu_set_t c; u32 util_perc; +#if defined(__linux__) || defined(__FreeBSD__) + cpu_set_t c; CPU_ZERO(&c); CPU_SET(i, &c); +#elif defined(__NetBSD__) + cpuset_t *c; + + c = cpuset_create(); + if (c == NULL) + PFATAL("cpuset_create failed"); + cpuset_set(i, c); +#endif + +#if defined(__FreeBSD__) + if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c)) + PFATAL("pthread_setaffinity_np failed"); +#endif + +#if defined(__NetBSD__) + if (pthread_setaffinity_np(pthread_self(), cpuset_size(c), c)) + PFATAL("pthread_setaffinity_np failed"); + + cpuset_destroy(c); +#endif + +#if defined(__linux__) if (sched_setaffinity(0, sizeof(c), &c)) PFATAL("sched_setaffinity failed"); +#endif util_perc = measure_preemption(CTEST_CORE_TRG_MS); |