Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use futex directly instead of via syscall on OpenBSD #1621

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rfht
Copy link
Contributor

@rfht rfht commented Jul 27, 2024

This is necessary for building on OpenBSD (and currently used in the OpenBSD port of recoil). syscall entry point was removed from OpenBSD in 2023 for security reasons and the recommended way is use of the specific syscall as in this diff.

syscall(SYS_futex, &mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL, 0);
#else
futex(&mtx, FUTEX_WAIT, 2, NULL, NULL);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not _PRIVATE on the FIUTEX constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't use _PRIVATE because it's not documented in our man page, but I see that these constants are also defined in sys/futex.h. I'll do a build with the _PRIVATE parts and if that works, I'll change it!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it to _PRIVATE futex flags

Copy link
Collaborator

@sprunk sprunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. There's currently a merge freeze though.

Comment on lines 36 to 40
#ifndef __OpenBSD__
syscall(SYS_futex, &mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL, 0);
#else
futex(&mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL);
#endif
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this pattern could be extracted to a function? So somewhere above there would be

static inline void do_futex (uint32_t *mtx, uint32_t value)
{
	#ifndef __OpenBSD__
		syscall(SYS_futex, mtx, FUTEX_WAIT_PRIVATE, value, NULL, NULL, 0);
	#else
		futex(mtx, FUTEX_WAIT_PRIVATE, value, NULL, NULL);
	#endif
}

And this would become just

Suggested change
#ifndef __OpenBSD__
syscall(SYS_futex, &mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL, 0);
#else
futex(&mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL);
#endif
do_futex(&mtx, 2);

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that makes sense indeed. Will be easier to read/maintain. I'll rebase to do it this way

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

Successfully merging this pull request may close these issues.

2 participants