Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions system/lib/standalone/standalone.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,22 @@ weak int __syscall_lstat64(intptr_t path, intptr_t buf) {
return -ENOSYS;
}

// 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.
// copied from wasi-libc's getentropy.c:
// https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/sources/getentropy.c
weak int getentropy(void* buffer, size_t length) {
abort();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you copy the code from https://github.com/WebAssembly/wasi-libc/blob/main/libc-bottom-half/sources/getentropy.c? (With a link/attribution I think).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. should I leave it weak?

if (length > 256) {
errno = EIO;
return -1;
}

int r = __wasi_random_get(buffer, length);

if (r != 0) {
errno = r;
return -1;
}

return 0;
}

// Emscripten additions
Expand Down
Loading