Skip to content
Open
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
6 changes: 5 additions & 1 deletion emmalloc/emmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 __attribute__((__weak__));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since #394, this should no longer be weak.

In fact, building with MALLOC_IMPL=emmalloc is currently broken due to missing this symbol.


// 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!");
Expand Down Expand Up @@ -545,7 +546,10 @@ 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);
unsigned char *heap_end = &__heap_end;
if (heap_end == NULL)
heap_end = (unsigned char*) ((size_t) &__heap_base + (PAGE_SIZE-1) & -PAGE_SIZE);
Copy link
Contributor

Choose a reason for hiding this comment

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

Once non-weak, the NULL fallback is not needed, but the dlmalloc code is trapping on end < base.


if (numBytes <= (size_t)(heap_end - &__heap_base)) {
startPtr = &__heap_base;
endPtr = heap_end;
Expand Down