diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:08:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-26 16:08:03 +0000 |
commit | d53be633495379df577148d121a9cf52246b0c5e (patch) | |
tree | bbc827718e0859af4dc7332e03e2e8ddc56cc09c /emmalloc | |
parent | Adding debian version 0.0~git20230821.ec4566b-2. (diff) | |
download | wasi-libc-d53be633495379df577148d121a9cf52246b0c5e.tar.xz wasi-libc-d53be633495379df577148d121a9cf52246b0c5e.zip |
Merging upstream version 0.0~git20240411.9e8c542.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | emmalloc/emmalloc.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/emmalloc/emmalloc.c b/emmalloc/emmalloc.c index c98e42e..e97ef44 100644 --- a/emmalloc/emmalloc.c +++ b/emmalloc/emmalloc.c @@ -56,6 +56,7 @@ // Defind by the linker to have the address of the start of the heap. extern unsigned char __heap_base; +extern unsigned char __heap_end; // Behavior of right shifting a signed integer is compiler implementation defined. static_assert((((int32_t)0x80000000U) >> 31) == -1, "This malloc implementation requires that right-shifting a signed integer produces a sign-extending (arithmetic) shift!"); @@ -545,9 +546,13 @@ static bool claim_more_memory(size_t numBytes) // If this is the first time we're called, see if we can use // the initial heap memory set up by wasm-ld. if (!listOfAllRegions) { - unsigned char *heap_end = sbrk(0); - if (numBytes <= (size_t)(heap_end - &__heap_base)) { - startPtr = &__heap_base; + unsigned char *heap_base = &__heap_base; + unsigned char *heap_end = &__heap_end; + if (heap_end < heap_base) { + __builtin_trap(); + } + if (numBytes <= (size_t)(heap_end - heap_base)) { + startPtr = heap_base; endPtr = heap_end; break; } |