File tree 1 file changed +27
-0
lines changed 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -271,3 +271,30 @@ 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
+ int32_t __imported_wasi_snapshot_preview1_random_get (int32_t arg0, int32_t arg1)
279
+ __attribute__((__import_module__(" wasi_snapshot_preview1" ), __import_name__(" random_get" )));
280
+
281
+ typedef uint16_t __wasi_errno_t ;
282
+ typedef size_t __wasi_size_t ;
283
+
284
+ __wasi_errno_t __wasi_random_get (uint8_t *buf, __wasi_size_t buf_len) {
285
+ int32_t ret = __imported_wasi_snapshot_preview1_random_get ((int32_t )buf, (int32_t )buf_len);
286
+ return (uint16_t )ret;
287
+ }
288
+
289
+ extern " C" int getentropy (void *buffer, size_t len) {
290
+ if (len > 256 ) {
291
+ errno = EIO;
292
+ return -1 ;
293
+ }
294
+ int r = __wasi_random_get ((uint8_t *)buffer, len);
295
+ if (r != 0 ) {
296
+ errno = r;
297
+ return -1 ;
298
+ }
299
+ return 0 ;
300
+ }
You can’t perform that action at this time.
0 commit comments