Skip to content

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

Closed
@martijneken

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()?

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