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

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

Closed
martijneken opened this issue Oct 24, 2024 · 1 comment · Fixed by #22820
Closed

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

martijneken opened this issue Oct 24, 2024 · 1 comment · Fixed by #22820

Comments

@martijneken
Copy link

martijneken commented Oct 24, 2024

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

@sbc100
Copy link
Collaborator

sbc100 commented Oct 24, 2024

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.

martijneken added a commit to martijneken/proxy-wasm-cpp-sdk that referenced this issue Oct 26, 2024
martijneken added a commit to martijneken/proxy-wasm-cpp-sdk that referenced this issue Oct 26, 2024
mpwarres pushed a commit to proxy-wasm/proxy-wasm-cpp-sdk that referenced this issue Oct 28, 2024
* fix: Implement getentropy while Emscripten gets patched

Issue: emscripten-core/emscripten#22782

Signed-off-by: Martijn Stevenson <[email protected]>
sbc100 added a commit to sbc100/emscripten that referenced this issue Oct 31, 2024
This allows it to work in standalone mode.

Fixes: emscripten-core#22782
sbc100 added a commit to sbc100/emscripten that referenced this issue Oct 31, 2024
This allows it to work in standalone mode.

Fixes: emscripten-core#22782
sbc100 added a commit to sbc100/emscripten that referenced this issue Oct 31, 2024
This allows it to work in standalone mode.

Fixes: emscripten-core#22782
sbc100 added a commit to sbc100/emscripten that referenced this issue Oct 31, 2024
This allows it to work in standalone mode.

Fixes: emscripten-core#22782
sbc100 added a commit to sbc100/emscripten that referenced this issue Oct 31, 2024
This allows it to work in standalone mode.

Fixes: emscripten-core#22782
sbc100 added a commit to sbc100/emscripten that referenced this issue Nov 1, 2024
This allows it to work in standalone mode.

Fixes: emscripten-core#22782
@sbc100 sbc100 closed this as completed in 8f08ccc Nov 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants