Skip to content
This repository was archived by the owner on Mar 22, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Android.bp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ cc_library_static {
vendor_available: true,
host_supported: true,
recovery_available: true,
sdk_version: "9",

defaults: [
"afl-defaults",
Expand Down
23 changes: 19 additions & 4 deletions afl-fuzz.c
Original file line number Diff line number Diff line change
Expand Up @@ -488,9 +488,19 @@ static void bind_to_free_cpu(void) {

closedir(d);

for (i = 0; i < cpu_core_count; i++) if (!cpu_used[i]) break;

size_t cpu_start = 0;

try:
#ifndef __ANDROID__
for (i = cpu_start; i < cpu_core_count; i++) if (!cpu_used[i]) break;

if (i == cpu_core_count) {
#else
for (i = cpu_core_count - cpu_start - 1; i > -1; i--) if (!cpu_used[i]) break;

if (i == -1) {
#endif

SAYF("\n" cLRD "[-] " cRST
"Uh-oh, looks like all %u CPU cores on your system are allocated to\n"
Expand All @@ -503,15 +513,20 @@ static void bind_to_free_cpu(void) {

}

OKF("Found a free CPU core, binding to #%u.", i);
OKF("Found a free CPU core, try binding to #%u.", i);

cpu_aff = i;

CPU_ZERO(&c);
CPU_SET(i, &c);

if (sched_setaffinity(0, sizeof(c), &c))
PFATAL("sched_setaffinity failed");
if (sched_setaffinity(0, sizeof(c), &c)) {
if (cpu_start == cpu_core_count)
PFATAL("sched_setaffinity failed to cpu %d, exit", i);
WARNF("sched_setaffinity failed to cpu %d, try next cpu", i);
cpu_start++;
goto try;
}

}

Expand Down