Skip to content

Commit d253aa3

Browse files
mikevoronovsunfishcode
authored andcommitted
Make sbrk(0) deterministic (#115)
* fix the behavior of sbrk(0) * review changes
1 parent b59b83c commit d253aa3

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

  • libc-bottom-half/sources

libc-bottom-half/sources/sbrk.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,14 @@
33
#include <errno.h>
44
#include <__macro_PAGESIZE.h>
55

6-
/* Bare-bones implementation of sbrk: just call memory.grow. */
6+
/* Bare-bones implementation of sbrk. */
77
void *sbrk(intptr_t increment) {
8+
/* sbrk(0) returns the current memory size. */
9+
if (increment == 0) {
10+
/* The wasm spec doesn't guarantee that memory.grow of 0 always succeeds. */
11+
return (void *)(__builtin_wasm_memory_size(0) * PAGESIZE);
12+
}
13+
814
/* We only support page-size increments. */
915
if (increment % PAGESIZE != 0) {
1016
abort();

0 commit comments

Comments
 (0)