aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Carlier <devnexen@gmail.com>2020-06-10 16:16:47 +0100
committerDavid Carlier <devnexen@gmail.com>2020-06-10 16:16:47 +0100
commitb3feda052d36aacd657b394169b90f05afdbbbde (patch)
treed6ac2e893bf7fea279b58a65bb19dbf57c1edd6e
parent5cb6dc77955bb19316859c37684cb838418392cc (diff)
downloadafl++-b3feda052d36aacd657b394169b90f05afdbbbde.tar.gz
start of illumos cpu binding implementation.
The current user needs the proc_owner permission, not something doable via the settings script.
-rw-r--r--GNUmakefile5
-rw-r--r--include/afl-fuzz.h7
-rw-r--r--src/afl-fuzz-init.c88
-rw-r--r--src/afl-gotcpu.c17
4 files changed, 106 insertions, 11 deletions
diff --git a/GNUmakefile b/GNUmakefile
index 7556b617..0714a9d2 100644
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -58,6 +58,11 @@ ifneq "$(shell uname)" "Darwin"
CFLAGS_OPT += -D_FORTIFY_SOURCE=2
endif
+ifeq "$(shell uname)" "SunOS"
+ CFLAGS_OPT += -Wno-format-truncation
+ LDFLAGS=-lkstat
+endif
+
ifdef STATIC
$(info Compiling static version of binaries)
# Disable python for static compilation to simplify things
diff --git a/include/afl-fuzz.h b/include/afl-fuzz.h
index 3b5cc0e2..f17bebd7 100644
--- a/include/afl-fuzz.h
+++ b/include/afl-fuzz.h
@@ -83,7 +83,7 @@
can hope... */
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
- defined(__DragonFly__)
+ defined(__DragonFly__) || defined(__sun)
#define HAVE_AFFINITY 1
#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <sys/param.h>
@@ -96,6 +96,11 @@
#define cpu_set_t cpuset_t
#elif defined(__NetBSD__)
#include <pthread.h>
+ #elif defined(__sun)
+ #include <sys/types.h>
+ #include <kstat.h>
+ #include <sys/sysinfo.h>
+ #include <sys/pset.h>
#endif
#endif /* __linux__ */
diff --git a/src/afl-fuzz-init.c b/src/afl-fuzz-init.c
index 4184fa6b..16980681 100644
--- a/src/afl-fuzz-init.c
+++ b/src/afl-fuzz-init.c
@@ -37,6 +37,8 @@ void bind_to_free_cpu(afl_state_t *afl) {
cpu_set_t c;
#elif defined(__NetBSD__)
cpuset_t * c;
+ #elif defined(__sun)
+ psetid_t c;
#endif
u8 cpu_used[4096] = {0};
@@ -181,6 +183,58 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
ck_free(procs);
+ #elif defined(__sun)
+ kstat_named_t *n;
+ kstat_ctl_t *m;
+ kstat_t *k;
+ cpu_stat_t cs;
+ u32 ncpus;
+
+ m = kstat_open();
+
+ if (!m) FATAL("kstat_open failed");
+
+ k = kstat_lookup(m, "unix", 0, "system_misc");
+
+ if (!k) {
+
+ kstat_close(m);
+ return;
+
+ }
+
+ if (kstat_read(m, k, NULL)) {
+
+ kstat_close(m);
+ return;
+
+ }
+
+ n = kstat_data_lookup(k, "ncpus");
+ ncpus = n->value.i32;
+
+ if (ncpus > sizeof(cpu_used))
+ ncpus = sizeof(cpu_used);
+
+ for (i = 0; i < ncpus; i ++) {
+
+ k = kstat_lookup(m, "cpu_stat", i, NULL);
+ if (kstat_read(m, k, &cs)) {
+
+ kstat_close(m);
+ return;
+
+ }
+
+ if (cs.cpu_sysinfo.cpu[CPU_IDLE] > 0)
+ continue;
+
+ if (cs.cpu_sysinfo.cpu[CPU_USER] > 0 || cs.cpu_sysinfo.cpu[CPU_KERNEL] > 0)
+ cpu_used[i] = 1;
+
+ }
+
+ kstat_close(m);
#else
#warning \
"For this platform we do not have free CPU binding code yet. If possible, please supply a PR to https://github.com/AFLplusplus/AFLplusplus"
@@ -189,7 +243,7 @@ void bind_to_free_cpu(afl_state_t *afl) {
size_t cpu_start = 0;
try:
- #ifndef __ANDROID__
+ #if !defined(__ANDROID__)
for (i = cpu_start; i < afl->cpu_core_count; i++) {
if (!cpu_used[i]) { break; }
@@ -228,6 +282,9 @@ void bind_to_free_cpu(afl_state_t *afl) {
c = cpuset_create();
if (c == NULL) PFATAL("cpuset_create failed");
cpuset_set(i, c);
+ #elif defined(__sun)
+ pset_create(&c);
+ if (pset_assign(c, i, NULL)) PFATAL("pset_assign failed");
#endif
#if defined(__linux__)
@@ -259,18 +316,31 @@ void bind_to_free_cpu(afl_state_t *afl) {
}
#elif defined(__NetBSD__)
-if (pthread_setaffinity_np(pthread_self(), cpuset_size(c), c)) {
+ if (pthread_setaffinity_np(pthread_self(), cpuset_size(c), c)) {
- if (cpu_start == afl->cpu_core_count)
- PFATAL("pthread_setaffinity failed for cpu %d, exit", i);
- WARNF("pthread_setaffinity failed to CPU %d, trying next CPU", i);
- cpu_start++;
- goto try
+ if (cpu_start == afl->cpu_core_count)
+ PFATAL("pthread_setaffinity failed for cpu %d, exit", i);
+ WARNF("pthread_setaffinity failed to CPU %d, trying next CPU", i);
+ cpu_start++;
+ goto try
;
-}
+ }
+
+ cpuset_destroy(c);
+ #elif defined(__sun)
+ if (pset_bind(c, P_PID, getpid(), NULL)) {
+
+ if (cpu_start == afl->cpu_core_count)
+ PFATAL("pset_bind failed for cpu %d, exit", i);
+ WARNF("pthread_setaffinity failed to CPU %d, trying next CPU", i);
+ cpu_start++;
+ goto try
+ ;
+
+ }
-cpuset_destroy(c);
+ pset_destroy(c);
#else
// this will need something for other platforms
// TODO: Solaris/Illumos has processor_bind ... might worth a try
diff --git a/src/afl-gotcpu.c b/src/afl-gotcpu.c
index 43b3196b..bdf63e8f 100644
--- a/src/afl-gotcpu.c
+++ b/src/afl-gotcpu.c
@@ -54,7 +54,7 @@
#include "common.h"
#if defined(__linux__) || defined(__FreeBSD__) || defined(__NetBSD__) || \
- defined(__APPLE__) || defined(__DragonFly__)
+ defined(__APPLE__) || defined(__DragonFly__) || defined(__sun)
#define HAVE_AFFINITY 1
#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <pthread.h>
@@ -70,6 +70,8 @@
#include <pthread.h>
#include <mach/thread_act.h>
#include <mach/thread_policy.h>
+ #elif defined(__sun)
+ #include <sys/pset.h>
#endif
#endif /* __linux__ || __FreeBSD__ || __NetBSD__ || __APPLE__ */
@@ -181,6 +183,12 @@ int main(int argc, char **argv) {
if (thread_policy_set(native_thread, THREAD_AFFINITY_POLICY,
(thread_policy_t)&c, 1) != KERN_SUCCESS)
PFATAL("thread_policy_set failed");
+ #elif defined(__sun)
+ psetid_t c;
+
+ if (pset_create(&c)) PFATAL("pset_create failed");
+
+ if (pset_assign(c, i, NULL)) PFATAL("pset_assign failed");
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
@@ -195,6 +203,13 @@ int main(int argc, char **argv) {
cpuset_destroy(c);
#endif
+ #if defined(__sun)
+ if (pset_bind(c, P_PID, getpid(), NULL))
+ PFATAL("pset_bind failed");
+
+ pset_destroy(c);
+ #endif
+
#if defined(__linux__)
if (sched_setaffinity(0, sizeof(c), &c)) {