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

FreeBSD, implementing binding to free cpu. #7

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

devnexen
Copy link

going through processes and finding the first potential free cpu.

going through processes and finding the first potential free cpu.
Copy link
Contributor

@Dor1s Dor1s left a 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
Copy link
Contributor

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};
Copy link
Contributor

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;
Copy link
Contributor

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

Copy link
Author

@devnexen devnexen Jul 29, 2019

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;
Copy link
Contributor

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 ++) {
Copy link
Contributor

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:
Copy link
Contributor

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

Copy link
Author

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
Copy link
Contributor

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?

Copy link
Author

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants