Skip to content

check libc before using SYS_getrandom on Linux  #285

@ahgamut

Description

@ahgamut

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 for getrandom, so if the underlying libc provides getrandom, that function is called instead of making a syscall. The standard library uses getrandom for HashMap keys here.

The getrandom crate makes the Linux syscall directly without first checking for getrandom 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions