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

Support vgetrandom on Linux 6.11+ #21590

Open
The-King-of-Toasters opened this issue Oct 4, 2024 · 1 comment
Open

Support vgetrandom on Linux 6.11+ #21590

The-King-of-Toasters opened this issue Oct 4, 2024 · 1 comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-linux standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@The-King-of-Toasters
Copy link
Contributor

The-King-of-Toasters commented Oct 4, 2024

Linux 6.11 added getrandom to the vdso. The supported architectures are:

  • x86_64
  • aarch64
  • loongarch64
  • s390x
  • powerpc64(le)

The API is:

ssize_t vgetrandom(void *buffer, size_t len, unsigned int flags,
                   void *opaque_state, size_t opaque_len);
// If buffer = len = flags = 0 && opaque_len = ~0, opaque_state is set to the struct:
struct vgetrandom_opaque_params {
    __u32 size_of_opaque_state;
    __u32 mmap_prot;
    __u32 mmap_flags;
    __u32 reserved[13];
};

Note that it isn't as simple as calling vgetrandom, callers need to pre-allocate memory to pass to the syscall.

Go recently implemented support in golang/go/issues/69577 (see https://go-review.googlesource.com/c/go/+/614835 for the patchset). Note that this impl allocates a pool of states per the number of CPUs, and uses a lock to fetch an unused state.

@The-King-of-Toasters
Copy link
Contributor Author

Tagging @jedisct1 since this effects the std.crypto namespace.

@Vexu Vexu added standard library This issue involves writing Zig code for the standard library. os-linux labels Oct 6, 2024
@Vexu Vexu added this to the 0.15.0 milestone Oct 6, 2024
@alexrp alexrp added the enhancement Solving this issue will likely involve adding new logic or components to the codebase. label Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Solving this issue will likely involve adding new logic or components to the codebase. os-linux standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

No branches or pull requests

3 participants