-
Notifications
You must be signed in to change notification settings - Fork 635
FreeBSD, implementing binding to free cpu. #7
base: master
Are you sure you want to change the base?
Conversation
going through processes and finding the first potential free cpu.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the patch. Can you please add a test that would verify the expected behavior?
afl-fuzz.c
Outdated
@@ -485,6 +490,26 @@ static void bind_to_free_cpu(void) { | |||
} | |||
|
|||
closedir(d); | |||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be #elif __FreeBSD__
?
afl-fuzz.c
Outdated
size_t nprocs; | ||
size_t proccount; | ||
cpuset_t c; | ||
int s_name[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"3" is not necessary here, better to remove
afl-fuzz.c
Outdated
size_t proccount; | ||
cpuset_t c; | ||
int s_name[3] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL}; | ||
if (sysctl(s_name, 3, NULL, &nprocs, NULL, 0) < 0) return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not use magic numbers, please add a macro for calculating array length via sizeof(array) / sizeof(array[0])
and use it instead of literal 3
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure but in fact I "mimicked" a similar sysctl call above (ie to get number of cpus) I usually try to fit the general style but not pb I can change.
afl-fuzz.c
Outdated
if (sysctl(s_name, 3, NULL, &nprocs, NULL, 0) < 0) return; | ||
proccount = nprocs / sizeof(*procs); | ||
procs = ck_alloc(nprocs); | ||
if (sysctl(s_name, 3, NULL, &nprocs, NULL, 0) < 0) goto procs_free; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
afl-fuzz.c
Outdated
procs = ck_alloc(nprocs); | ||
if (sysctl(s_name, 3, NULL, &nprocs, NULL, 0) < 0) goto procs_free; | ||
|
||
for (i = 0; i < proccount; i ++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove space between i
and ++
afl-fuzz.c
Outdated
cpu_used[procs[i].ki_oncpu] = 1; | ||
} | ||
|
||
procs_free: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write this without a `goto please? Just branch on the line 502
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sure
afl-fuzz.c
Outdated
if (sched_setaffinity(0, sizeof(c), &c)) | ||
PFATAL("sched_setaffinity failed"); | ||
#else |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would #elif __FreeBSD__
make sense here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well ... I think only NetBSD has this call too in case someone wants to port it too ... but I ll change it
going through processes and finding the first potential free cpu.