NetBSD various support improvements

This commit is contained in:
David Carlier
2019-09-29 12:30:10 +01:00
parent fb31a3bf2e
commit 2109d37298
4 changed files with 35 additions and 5 deletions

View File

@ -49,6 +49,10 @@ ifneq "$(findstring FreeBSD, $(shell uname))" ""
CFLAGS += -pthread CFLAGS += -pthread
endif endif
ifneq "$(findstring NetBSD, $(shell uname))" ""
CFLAGS += -pthread
endif
ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" "" ifeq "$(findstring clang, $(shell $(CC) --version 2>/dev/null))" ""
TEST_CC = afl-gcc TEST_CC = afl-gcc
else else

View File

@ -48,6 +48,12 @@ if [ "$PLATFORM" = "OpenBSD" ] ; then
echo echo
echo 'System security features cannot be disabled on OpenBSD.' echo 'System security features cannot be disabled on OpenBSD.'
fi fi
if [ "$PLATFORM" = "FreeBSD" ] ; then
echo
echo It is recommended to enable unprivileged users to set cpu affinity
to be able to use afl-gotcpu meaningfully.
/sbin/sysctl -w security.models.extensions.user_set_cpu_affinity=1
fi
if [ "$PLATFORM" = "Darwin" ] ; then if [ "$PLATFORM" = "Darwin" ] ; then
if [ $(launchctl list 2>/dev/null | grep -q '\.ReportCrash$') ] ; then if [ $(launchctl list 2>/dev/null | grep -q '\.ReportCrash$') ] ; then
echo We unload the default crash reporter here echo We unload the default crash reporter here

View File

@ -786,7 +786,7 @@ double get_runnable_processes(void) {
static double res; static double res;
#if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) #if defined(__APPLE__) || defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
/* I don't see any portable sysctl or so that would quickly give us the /* I don't see any portable sysctl or so that would quickly give us the
number of runnable processes; the 1-minute load average can be a number of runnable processes; the 1-minute load average can be a
@ -827,7 +827,7 @@ double get_runnable_processes(void) {
} }
#endif /* ^(__APPLE__ || __FreeBSD__ || __OpenBSD__) */ #endif /* ^(__APPLE__ || __FreeBSD__ || __OpenBSD__ || __NetBSD__) */
return res; return res;

View File

@ -52,15 +52,18 @@
#include "types.h" #include "types.h"
#include "debug.h" #include "debug.h"
#if defined(__linux__) || defined(__FreeBSD__) #if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__)
#define HAVE_AFFINITY 1 #define HAVE_AFFINITY 1
# if defined(__FreeBSD__) # if defined(__FreeBSD__)
# include <pthread.h> # include <pthread.h>
# include <pthread_np.h> # include <pthread_np.h>
# include <sys/cpuset.h> # include <sys/cpuset.h>
# define cpu_set_t cpuset_t # define cpu_set_t cpuset_t
# elif defined(__NetBSD__)
# include <pthread.h>
# include <sched.h>
# endif # endif
#endif /* __linux__ || __FreeBSD__ */ #endif /* __linux__ || __FreeBSD__ || __NetBSD__ */
/* Get unix time in microseconds. */ /* Get unix time in microseconds. */
@ -160,17 +163,34 @@ int main(int argc, char** argv) {
if (!fr) { if (!fr) {
cpu_set_t c;
u32 util_perc; u32 util_perc;
#if defined(__linux__) || defined(__FreeBSD__)
cpu_set_t c;
CPU_ZERO(&c); CPU_ZERO(&c);
CPU_SET(i, &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 defined(__FreeBSD__)
if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c)) if (pthread_setaffinity_np(pthread_self(), sizeof(c), &c))
PFATAL("pthread_setaffinity_np failed"); PFATAL("pthread_setaffinity_np failed");
#endif #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 defined(__linux__)
if (sched_setaffinity(0, sizeof(c), &c)) if (sched_setaffinity(0, sizeof(c), &c))
PFATAL("sched_setaffinity failed"); PFATAL("sched_setaffinity failed");