Skip to content

Standalone: implement getentropy() via wasi_snapshot_preview1.random_get() #22782

Closed

Description

@martijneken

Please include the following in your bug report:

Version of emscripten/emsdk: 3.1.67 (and likely latest)

Failing command line in full:

Compiling absl::random code in standalone mode results in a wasm module that crashes. Sample code:

absl::BitGen bitgen;
int digit = absl::Uniform(bitgen, 0, 2);

The reason is that Abseil under Emscripten uses the getentropy() syscall as a seed: https://github.com/abseil/abseil-cpp/blob/07fff76ed619672bb7bf00939231ba45aef2b043/absl/random/internal/seed_material.cc#L60-L64

And standalone Emscripten defaults to a crashing implementation:

// There is no good source of entropy without an import. Make this weak so that
// it can be replaced with a pRNG or a proper import.
weak int getentropy(void* buffer, size_t length) {
abort();
}

Would it be reasonable to use wasi_snapshot_preview1.random_get() to implement getentropy()?

Activity

  1. sbc100 commented on Oct 24, 2024

    @sbc100
    Collaborator

    Yes, I think that would make sense.

    There is a simple implementation in wasi-libc already: https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/sources/getentropy.c

    Would you like the send a PR? I imagine the hardest part would be figuring out where/how to test it.

  2. added 6 commits that reference this issue on Oct 31, 2024
    2f79c58
    5dccc4a
    90359cc
    622acdb
    a9992c0
    688d5df
  3. added a commit that references this issue on Nov 1, 2024
    8f08ccc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions