-
Notifications
You must be signed in to change notification settings - Fork 117
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
Conversation
rts/System/Platform/Linux/Futex.cpp
Outdated
syscall(SYS_futex, &mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL, 0); | ||
#else | ||
futex(&mtx, FUTEX_WAIT, 2, NULL, NULL); |
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.
not _PRIVATE on the FIUTEX constant?
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.
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!
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.
changed it to _PRIVATE
futex flags
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.
Looks good. There's currently a merge freeze though.
rts/System/Platform/Linux/Futex.cpp
Outdated
#ifndef __OpenBSD__ | ||
syscall(SYS_futex, &mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL, 0); | ||
#else | ||
futex(&mtx, FUTEX_WAIT_PRIVATE, 2, NULL, NULL); | ||
#endif |
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.
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
#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); |
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.
that makes sense indeed. Will be easier to read/maintain. I'll rebase to do it this way
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.