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
check libc before using SYS_getrandom
on Linux
#285
Comments
Good catch, this library aims to have an identical implementation to the standard library (see rust-lang/rust#62079), so we shouldn't deviate unless it's necessary. I think adding this sort of detection would be fine. Our logic would then become:
|
Personally, on Linux I prefer using syscalls directly, to the point of thinking that ideally we should not rely on Regardless of the approach used by
Assuming we will add the |
How does the Rust stdlib ensure that the
Reasonably policy. But, let's make sure that the standard library is doing the right thing. |
The I am not sure how we test that both code paths (weak symbol found, weak symbol not found and fallback to syscall) are correct in CI/CD. |
@ahgamut after looking at this again, I think the correct approach is to not compile for a Linux target unless you are actually targeting Linux. Given Cosmopolitan's goals of being a compile-once/run-everywhere libc, it shouldn't be using the Given that the Linux fallback logic is already fairly complex, I don't think it makes sense to make it more complex. An alternative would be to only use the syscall wrapper on Linux targets which lack |
Hi,
I was porting HVM to run on Cosmopolitan Libc, and I noticed a small difference between how
getrandom
is handled by this crate when compared to the Rust standard library.The Rust standard library has a
syscall
macro which creates a weak symbol forgetrandom
, so if the underlying libc providesgetrandom
, that function is called instead of making a syscall. The standard library usesgetrandom
for HashMap keys here.The
getrandom
crate makes the Linux syscall directly without first checking forgetrandom
in the libc.The pattern used in the Rust standard library is flexible to which libc is used, be it glibc, musl, or Cosmopolitan.
Could you change https://github.com/rust-random/getrandom/blob/master/src/linux_android.rs to check if
getrandom
is provided by the libc first, before using the syscall?The text was updated successfully, but these errors were encountered: