| ... | @@ -56,6 +56,7 @@ | ... | @@ -56,6 +56,7 @@ |
| 56 | | 56 | |
| 57 | // Defind by the linker to have the address of the start of the heap. | 57 | // Defind by the linker to have the address of the start of the heap. |
| 58 | extern unsigned char __heap_base; | 58 | extern unsigned char __heap_base; |
| | 59 | extern unsigned char __heap_end __attribute__((__weak__)); |
| 59 | | 60 | |
| 60 | // Behavior of right shifting a signed integer is compiler implementation defined. | 61 | // Behavior of right shifting a signed integer is compiler implementation defined. |
| 61 | static_assert((((int32_t)0x80000000U) >> 31) == -1, "This malloc implementation requires that right-shifting a signed integer produces a sign-extending (arithmetic) shift!"); | 62 | static_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) | ... | @@ -545,7 +546,10 @@ static bool claim_more_memory(size_t numBytes) |
| 545 | // If this is the first time we're called, see if we can use | 546 | // If this is the first time we're called, see if we can use |
| 546 | // the initial heap memory set up by wasm-ld. | 547 | // the initial heap memory set up by wasm-ld. |
| 547 | if (!listOfAllRegions) { | 548 | 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 | |
| 549 | if (numBytes <= (size_t)(heap_end - &__heap_base)) { | 553 | if (numBytes <= (size_t)(heap_end - &__heap_base)) { |
| 550 | startPtr = &__heap_base; | 554 | startPtr = &__heap_base; |
| 551 | endPtr = heap_end; | 555 | endPtr = heap_end; |