Skip to content

Commit

Permalink
[wasm64] Fix emmalloc+verbose under wasm64 (emscripten-core#20654)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbc100 authored Nov 13, 2023
1 parent a92c42c commit 04a0cad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
36 changes: 18 additions & 18 deletions system/lib/emmalloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -374,17 +374,17 @@ static void dump_memory_regions()
Region *r = (Region*)root;
assert(debug_region_is_consistent(r));
uint8_t *lastRegionEnd = root->endPtr;
MAIN_THREAD_ASYNC_EM_ASM(out('Region block '+ptrToString($0)+' - '+ptrToString($1)+ ' ('+($2>>>0)+' bytes):'),
MAIN_THREAD_ASYNC_EM_ASM(out('Region block '+ptrToString($0)+' - '+ptrToString($1)+ ' ('+toString(Number($2))+' bytes):'),
r, lastRegionEnd, lastRegionEnd-(uint8_t*)r);
while((uint8_t*)r < lastRegionEnd)
{
MAIN_THREAD_ASYNC_EM_ASM(out('Region '+ptrToString($0)+', size: '+($1>>>0)+' ('+($2?"used":"--FREE--")+')'),
MAIN_THREAD_ASYNC_EM_ASM(out('Region '+ptrToString($0)+', size: '+toString(Number($1))+' ('+($2?"used":"--FREE--")+')'),
r, r->size, region_ceiling_size(r) == r->size);

assert(debug_region_is_consistent(r));
size_t sizeFromCeiling = size_of_region_from_ceiling(r);
if (sizeFromCeiling != r->size)
MAIN_THREAD_ASYNC_EM_ASM(out('Corrupt region! Size marker at the end of the region does not match: '+($0>>>0)), sizeFromCeiling);
MAIN_THREAD_ASYNC_EM_ASM(out('Corrupt region! Size marker at the end of the region does not match: '+toString(Number($0))), sizeFromCeiling);
if (r->size == 0)
break;
r = next_region(r);
Expand All @@ -399,7 +399,7 @@ static void dump_memory_regions()
Region *fr = freeRegionBuckets[i].next;
while(fr != &freeRegionBuckets[i])
{
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + ($2>>>0) + ' (size at ceiling: '+($3>>>0)+'), prev: ' + ptrToString($4) + ', next: ' + ptrToString($5)),
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + toString(Number($2)) + ' (size at ceiling: '+toString(Number($3))+'), prev: ' + ptrToString($4) + ', next: ' + ptrToString($5)),
i, fr, fr->size, size_of_region_from_ceiling(fr), fr->prev, fr->next);
assert(debug_region_is_consistent(fr));
assert(region_is_free(fr));
Expand All @@ -410,7 +410,7 @@ static void dump_memory_regions()
fr = fr->next;
}
}
MAIN_THREAD_ASYNC_EM_ASM(out('Free bucket index map: ' + ($0>>>0).toString(2) + ' ' + ($1>>>0).toString(2)), (uint32_t)(freeRegionBucketsUsed >> 32), (uint32_t)freeRegionBucketsUsed);
MAIN_THREAD_ASYNC_EM_ASM(out('Free bucket index map: ' + toString(Number($0)).toString(2) + ' ' + toString(Number($1)).toString(2)), (uint32_t)(freeRegionBucketsUsed >> 32), (uint32_t)freeRegionBucketsUsed);
MAIN_THREAD_ASYNC_EM_ASM(out(""));
}

Expand All @@ -430,7 +430,7 @@ static int validate_memory_regions()
Region *r = (Region*)root;
if (!debug_region_is_consistent(r))
{
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+($1>>>0)+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+toString(Number($1))+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
r, r->size, region_ceiling_size(r) == r->size);
return 1;
}
Expand All @@ -439,7 +439,7 @@ static int validate_memory_regions()
{
if (!debug_region_is_consistent(r))
{
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+($1>>>0)+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
MAIN_THREAD_ASYNC_EM_ASM(err('Used region '+ptrToString($0)+', size: '+toString(Number($1))+' ('+($2?"used":"--FREE--")+') is corrupt (size markers in the beginning and at the end of the region do not match!)'),
r, r->size, region_ceiling_size(r) == r->size);
return 1;
}
Expand All @@ -457,7 +457,7 @@ static int validate_memory_regions()
{
if (!debug_region_is_consistent(fr) || !region_is_free(fr) || fr->prev != prev || fr->next == fr || fr->prev == fr)
{
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + ($2>>>0) + ' (size at ceiling: '+($3>>>0)+'), prev: ' + ptrToString($4) + ', next: ' + ptrToString($5) + ' is corrupt!'),
MAIN_THREAD_ASYNC_EM_ASM(out('In bucket '+$0+', free region '+ptrToString($1)+', size: ' + toString(Number($2)) + ' (size at ceiling: '+toString(Number($3))+'), prev: ' + ptrToString($4) + ', next: 0x' + ptrToString($5) + ' is corrupt!'),
i, fr, fr->size, size_of_region_from_ceiling(fr), fr->prev, fr->next);
return 1;
}
Expand All @@ -479,7 +479,7 @@ int emmalloc_validate_memory_regions()
static bool claim_more_memory(size_t numBytes)
{
#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('claim_more_memory(numBytes='+($0>>>0)+ ')'), numBytes);
MAIN_THREAD_ASYNC_EM_ASM(out('claim_more_memory(numBytes='+Number($0)+ ')'), numBytes);
#endif

#ifdef EMMALLOC_MEMVALIDATE
Expand All @@ -496,7 +496,7 @@ static bool claim_more_memory(size_t numBytes)
return false;
}
#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('claim_more_memory: claimed ' + ptrToString($0) + ' - ' + ptrToString($1) + ' (' + ($2) + ' bytes) via sbrk()'), startPtr, startPtr + numBytes, numBytes);
MAIN_THREAD_ASYNC_EM_ASM(out('claim_more_memory: claimed ' + ptrToString($0) + ' - ' + ptrToString($1) + ' (' + Number($2) + ' bytes) via sbrk()'), startPtr, startPtr + numBytes, numBytes);
#endif
assert(HAS_ALIGNMENT(startPtr, alignof(size_t)));
uint8_t *endPtr = startPtr + numBytes;
Expand Down Expand Up @@ -646,7 +646,7 @@ static void *attempt_allocate(Region *freeRegion, size_t alignment, size_t size)
#endif

#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_allocate - succeeded allocating memory, region ptr=' + ptrToString($0) + ', align=' + $1 + ', payload size=' + ($2) + ' bytes)'), freeRegion, alignment, size);
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_allocate - succeeded allocating memory, region ptr=' + ptrToString($0) + ', align=' + $1 + ', payload size=' + toString(Number($2)) + ' bytes)'), freeRegion, alignment, size);
#endif

return (uint8_t*)freeRegion + sizeof(size_t);
Expand Down Expand Up @@ -682,7 +682,7 @@ static void *allocate_memory(size_t alignment, size_t size)
ASSERT_MALLOC_IS_ACQUIRED();

#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('allocate_memory(align=' + $0 + ', size=' + ($1>>>0) + ' bytes)'), alignment, size);
MAIN_THREAD_ASYNC_EM_ASM(out('allocate_memory(align=' + $0 + ', size=' + toString(Number($1)) + ' bytes)'), alignment, size);
#endif

#ifdef EMMALLOC_MEMVALIDATE
Expand All @@ -700,7 +700,7 @@ static void *allocate_memory(size_t alignment, size_t size)
if (size > MAX_ALLOC_SIZE)
{
#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + ($0 >>> 0) + 'bytes! (negative integer wraparound?)'), size);
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
#endif
return 0;
}
Expand Down Expand Up @@ -947,7 +947,7 @@ static int attempt_region_resize(Region *region, size_t size)
assert(HAS_ALIGNMENT(size, sizeof(size_t)));

#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_region_resize(region=' + ptrToString($0) + ', size=' + ($1>>>0) + ' bytes)'), region, size);
MAIN_THREAD_ASYNC_EM_ASM(out('attempt_region_resize(region=' + ptrToString($0) + ', size=' + toString(Number($1)) + ' bytes)'), region, size);
#endif

// First attempt to resize this region, if the next region that follows this one
Expand Down Expand Up @@ -1015,7 +1015,7 @@ static int acquire_and_attempt_region_resize(Region *region, size_t size)
void *emmalloc_aligned_realloc(void *ptr, size_t alignment, size_t size)
{
#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('aligned_realloc(ptr=' + ptrToString($0) + ', alignment=' + $1 + ', size=' + ($2>>>0)), ptr, alignment, size);
MAIN_THREAD_ASYNC_EM_ASM(out('aligned_realloc(ptr=' + ptrToString($0) + ', alignment=' + $1 + ', size=' + toString(Number($2))), ptr, alignment, size);
#endif

if (!ptr)
Expand All @@ -1030,7 +1030,7 @@ void *emmalloc_aligned_realloc(void *ptr, size_t alignment, size_t size)
if (size > MAX_ALLOC_SIZE)
{
#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + ($0 >>> 0) + 'bytes! (negative integer wraparound?)'), size);
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
#endif
return 0;
}
Expand Down Expand Up @@ -1084,7 +1084,7 @@ void *emmalloc_realloc_try(void *ptr, size_t size)
if (size > MAX_ALLOC_SIZE)
{
#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + ($0 >>> 0) + 'bytes! (negative integer wraparound?)'), size);
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
#endif
return 0;
}
Expand Down Expand Up @@ -1119,7 +1119,7 @@ void *emmalloc_aligned_realloc_uninitialized(void *ptr, size_t alignment, size_t
if (size > MAX_ALLOC_SIZE)
{
#ifdef EMMALLOC_VERBOSE
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + ($0 >>> 0) + 'bytes! (negative integer wraparound?)'), size);
MAIN_THREAD_ASYNC_EM_ASM(out('Allocation failed: attempted allocation size is too large: ' + toString(Number($0)) + 'bytes! (negative integer wraparound?)'), size);
#endif
return 0;
}
Expand Down
2 changes: 0 additions & 2 deletions test/test_browser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5591,8 +5591,6 @@ def test_zzz_zzz_emmalloc_4gb(self):
'memvalidate_verbose': (['-sMALLOC=emmalloc-memvalidate-verbose'],),
})
def test_emmalloc_3gb(self, args):
if self.is_wasm64() and 'verbose' in args[0]:
self.skipTest('https://github.com/emscripten-core/emscripten/pull/20654')
self.btest_exit('alloc_3gb.c',
args=['-sMAXIMUM_MEMORY=4GB', '-sALLOW_MEMORY_GROWTH=1'] + args)

Expand Down

0 comments on commit 04a0cad

Please sign in to comment.