Make sbrk(0) deterministic (#115)

* fix the behavior of sbrk(0)

* review changes
This commit is contained in:
vms 2019-10-22 01:44:23 +03:00 committed by Dan Gohman
parent b59b83cbc2
commit d253aa3de2

View File

@ -3,8 +3,14 @@
#include <errno.h>
#include <__macro_PAGESIZE.h>
/* Bare-bones implementation of sbrk: just call memory.grow. */
/* Bare-bones implementation of sbrk. */
void *sbrk(intptr_t increment) {
/* sbrk(0) returns the current memory size. */
if (increment == 0) {
/* The wasm spec doesn't guarantee that memory.grow of 0 always succeeds. */
return (void *)(__builtin_wasm_memory_size(0) * PAGESIZE);
}
/* We only support page-size increments. */
if (increment % PAGESIZE != 0) {
abort();