diff --git a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp index 1ad2a76ce9c9..83e33ec5a523 100644 --- a/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp +++ b/Source/JavaScriptCore/heap/StructureAlignedMemoryAllocator.cpp @@ -158,7 +158,8 @@ class StructureMemoryManager { #if OS(WINDOWS) || PLATFORM(PLAYSTATION) // libpas isn't calling pas_page_malloc commit, so we've got to commit the region ourselves // https://bugs.webkit.org/show_bug.cgi?id=292771 - OSAllocator::commit(result, MarkedBlock::blockSize, true, false); + if (result) [[likely]] + OSAllocator::commit(result, MarkedBlock::blockSize, true, false); #endif return result; #elif USE(MIMALLOC) diff --git a/Source/bmalloc/libpas/src/libpas/pas_page_malloc.c b/Source/bmalloc/libpas/src/libpas/pas_page_malloc.c index eca281300ad2..b1b77184ad2d 100644 --- a/Source/bmalloc/libpas/src/libpas/pas_page_malloc.c +++ b/Source/bmalloc/libpas/src/libpas/pas_page_malloc.c @@ -387,7 +387,7 @@ static void commit_impl(void* ptr, size_t size, bool do_mprotect, pas_mmap_capab void *currentPtr = ptr; while (totalSeen < size) { MEMORY_BASIC_INFORMATION memInfo; - VirtualQuery(currentPtr, &memInfo, sizeof(memInfo)); + PAS_ASSERT(VirtualQuery(currentPtr, &memInfo, sizeof(memInfo))); PAS_ASSERT(memInfo.State != 0x10000); PAS_ASSERT(memInfo.RegionSize > 0); PAS_ASSERT(virtual_alloc_with_retry(currentPtr, PAS_MIN(memInfo.RegionSize, size - totalSeen), MEM_COMMIT, PAGE_READWRITE)); @@ -456,7 +456,7 @@ static void decommit_impl(void* ptr, size_t size, void* currentPtr = ptr; while (totalSeen < size) { MEMORY_BASIC_INFORMATION memInfo; - VirtualQuery(currentPtr, &memInfo, sizeof(memInfo)); + PAS_ASSERT(VirtualQuery(currentPtr, &memInfo, sizeof(memInfo))); PAS_ASSERT(memInfo.RegionSize > 0); PAS_ASSERT(VirtualFree(currentPtr, PAS_MIN(memInfo.RegionSize, size - totalSeen), MEM_DECOMMIT)); currentPtr = (void*)((uintptr_t)currentPtr + memInfo.RegionSize); @@ -464,17 +464,18 @@ static void decommit_impl(void* ptr, size_t size, } } } else { - /* do_mprotect=false callers (pas_expendable_memory) read payload directly - and rely on seeing zeros after decommit, like MADV_FREE. MEM_DECOMMIT - would make those reads AV, so use DiscardVirtualMemory which frees - physical RAM but keeps pages accessible. This does not release commit - charge, but expendable memory is bounded metadata. */ + /* The only do_mprotect=false caller is pas_expendable_memory, which reads + payload directly and relies on seeing zeros after decommit, like + MADV_FREE. MEM_DECOMMIT would make those reads AV, so use + DiscardVirtualMemory which frees physical RAM but keeps pages + accessible. This does not release commit charge, but expendable memory + is bounded metadata. */ if (DiscardVirtualMemory(ptr, size)) { size_t totalSeen = 0; void* currentPtr = ptr; while (totalSeen < size) { MEMORY_BASIC_INFORMATION memInfo; - VirtualQuery(currentPtr, &memInfo, sizeof(memInfo)); + PAS_ASSERT(VirtualQuery(currentPtr, &memInfo, sizeof(memInfo))); PAS_ASSERT(memInfo.RegionSize > 0); PAS_ASSERT(VirtualAlloc(currentPtr, PAS_MIN(memInfo.RegionSize, size - totalSeen), MEM_RESET, PAGE_READWRITE)); currentPtr = (void*)((uintptr_t)currentPtr + memInfo.RegionSize); diff --git a/Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c b/Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c index f02d69e412e3..cf74bcc126ea 100644 --- a/Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c +++ b/Source/bmalloc/libpas/src/libpas/pas_thread_local_cache.c @@ -122,7 +122,7 @@ static void deallocate(pas_thread_local_cache* thread_local_cache) thread_local_cache->allocator_index_capacity); /* If we're doing symmetric decommit, then we need to commit the memory for the TLC now. */ - pas_page_malloc_commit_without_mprotect(begin, size, pas_may_mmap); + pas_page_malloc_commit(begin, size, pas_may_mmap); pas_large_utility_free_heap_deallocate(begin, size); } @@ -512,7 +512,7 @@ void pas_thread_local_cache_ensure_committed(pas_thread_local_cache* thread_loca /* Don't attempt to do fancy things with spans for commit, since we're no longer really optimizing for symmetric commit anyway. */ - pas_page_malloc_commit_without_mprotect( + pas_page_malloc_commit( (char*)thread_local_cache + (page_index << pas_page_malloc_alignment_shift()), pas_page_malloc_alignment(), pas_may_mmap); @@ -996,7 +996,7 @@ static void decommit_allocator_range(pas_thread_local_cache* cache, if (verbose) pas_log("Decommitting %p...%p\n", (void*)decommit_range.begin, (void*)decommit_range.end); - pas_page_malloc_decommit_without_mprotect( + pas_page_malloc_decommit( (char*)cache + decommit_range.begin, pas_range_size(decommit_range), pas_may_mmap); if (verbose) {