File tree 1 file changed +22
-0
lines changed
1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -271,3 +271,25 @@ extern "C" PROXY_WASM_KEEPALIVE void
271
271
proxy_on_foreign_function (uint32_t context_id, uint32_t foreign_function_id, uint32_t data_size) {
272
272
getContextBase (context_id)->onForeignFunction (foreign_function_id, data_size);
273
273
}
274
+
275
+ // Patch an Emscripten gap: https://github.com/emscripten-core/emscripten/issues/22782
276
+ // Implement getentropy for RNG support (e.g. for absl::random).
277
+
278
+ typedef uint16_t __wasi_errno_t ;
279
+ typedef size_t __wasi_size_t ;
280
+
281
+ __wasi_errno_t __wasi_random_get (uint8_t *buf, __wasi_size_t buf_len)
282
+ __attribute__((__import_module__(" wasi_snapshot_preview1" ), __import_name__(" random_get" )));
283
+
284
+ extern " C" int getentropy (void *buffer, size_t len) {
285
+ if (len > 256 ) {
286
+ errno = EIO;
287
+ return -1 ;
288
+ }
289
+ int r = __wasi_random_get ((uint8_t *)buffer, len);
290
+ if (r != 0 ) {
291
+ errno = r;
292
+ return -1 ;
293
+ }
294
+ return 0 ;
295
+ }
You can’t perform that action at this time.
0 commit comments