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

Commit 6434b83

Browse files
committed
Loop to next cpu core when set affinity failed
In most Android devices, cpu#0 is small core while cpu#Max is big core
1 parent 077d73f commit 6434b83

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

afl-fuzz.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,9 +488,19 @@ static void bind_to_free_cpu(void) {
488488

489489
closedir(d);
490490

491-
for (i = 0; i < cpu_core_count; i++) if (!cpu_used[i]) break;
491+
492+
size_t cpu_start = 0;
493+
494+
try:
495+
#ifndef __ANDROID__
496+
for (i = cpu_start; i < cpu_core_count; i++) if (!cpu_used[i]) break;
492497

493498
if (i == cpu_core_count) {
499+
#else
500+
for (i = cpu_core_count - cpu_start - 1; i > -1; i--) if (!cpu_used[i]) break;
501+
502+
if (i == -1) {
503+
#endif
494504

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

504514
}
505515

506-
OKF("Found a free CPU core, binding to #%u.", i);
516+
OKF("Found a free CPU core, try binding to #%u.", i);
507517

508518
cpu_aff = i;
509519

510520
CPU_ZERO(&c);
511521
CPU_SET(i, &c);
512522

513-
if (sched_setaffinity(0, sizeof(c), &c))
514-
PFATAL("sched_setaffinity failed");
523+
if (sched_setaffinity(0, sizeof(c), &c)) {
524+
if (cpu_start == cpu_core_count)
525+
PFATAL("sched_setaffinity failed to cpu %d, exit", i);
526+
WARNF("sched_setaffinity failed to cpu %d, try next cpu", i);
527+
cpu_start++;
528+
goto try;
529+
}
515530

516531
}
517532

0 commit comments

Comments
 (0)