authorgravatar for 124872+jedisct1@users.noreply.github.comFrank Denis <124872+jedisct1@users.noreply.github.com> 2023-01-12 14:48:14+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2023-01-12 13:48:14+00:00
logcbbf8c8a2d77d84ce88ea1cef9a3e7d54081e33d
treedc5243974d7ffa4b2ea42ae5f3607a1f4965298e
parent4b329176460d91056b75f0798778b1c58e0f104b
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

wasi-libc: use __heap_end if available (#14273)

The symbol was introduced in LLD 15.0.7, as a way to know how much memory can be allocated: https://github.com/llvm/llvm-project/commit/1095870e8ceddc5371f446f4e7c3473f89a461cd https://github.com/WebAssembly/wasi-libc/pull/377

1 files changed, 5 insertions(+), 1 deletions(-)

lib/libc/wasi/emmalloc/emmalloc.c+5-1
......@@ -56,6 +56,7 @@
5656
5757// Defind by the linker to have the address of the start of the heap.
5858extern unsigned char __heap_base;
59extern unsigned char __heap_end __attribute__((__weak__));
5960
6061// Behavior of right shifting a signed integer is compiler implementation defined.
6162static_assert((((int32_t)0x80000000U) >> 31) == -1, "This malloc implementation requires that right-shifting a signed integer produces a sign-extending (arithmetic) shift!");
......@@ -545,7 +546,10 @@ static bool claim_more_memory(size_t numBytes)
545546 // If this is the first time we're called, see if we can use
546547 // the initial heap memory set up by wasm-ld.
547548 if (!listOfAllRegions) {
548 unsigned char *heap_end = sbrk(0);
549 unsigned char *heap_end = &__heap_end;
550 if (heap_end == NULL)
551 heap_end = sbrk(0);
552
549553 if (numBytes <= (size_t)(heap_end - &__heap_base)) {
550554 startPtr = &__heap_base;
551555 endPtr = heap_end;