Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.

Commit f182880

Browse files
committed
FreeBSD: implements cpu availability command line.
1 parent fb1f871 commit f182880

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

afl-gotcpu.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,14 @@
4949
#include "types.h"
5050
#include "debug.h"
5151

52-
#ifdef __linux__
52+
#if defined(__linux__) || defined(__FreeBSD__)
5353
# define HAVE_AFFINITY 1
54+
# if defined(__FreeBSD__)
55+
# include <pthread.h>
56+
# include <pthread_np.h>
57+
# include <sys/cpuset.h>
58+
# define cpu_set_t cpuset_t
59+
# endif
5460
#endif /* __linux__ */
5561

5662

@@ -149,8 +155,13 @@ int main(int argc, char** argv) {
149155
CPU_ZERO(&c);
150156
CPU_SET(i, &c);
151157

158+
#if defined(__linux__)
152159
if (sched_setaffinity(0, sizeof(c), &c))
153160
PFATAL("sched_setaffinity failed");
161+
#elif defined(__FreeBSD__)
162+
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
163+
PFATAL("pthread_setaffinity_np failed");
164+
#endif
154165

155166
util_perc = measure_preemption(CTEST_CORE_TRG_MS);
156167

0 commit comments

Comments
 (0)