[memory] Make sure size is properly aligned in FreePages.
- Adds a DCHECK to FreePages that size is a multiple of allocation granularity. - Makes VirtualMemory::Free conform to this. This is to conform more closely to Chromium's page allocator API. Bug:chromium:756050 Change-Id: I673e1c225b8bd1009775de1597b575120bd06f8e Reviewed-on: https://chromium-review.googlesource.com/898008 Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Commit-Queue: Bill Budge <bbudge@chromium.org> Cr-Commit-Position: refs/heads/master@{#51064}
This commit is contained in:
parent
c462ddc80b
commit
a231fed8bf
@ -160,6 +160,7 @@ void* AllocatePages(void* address, size_t size, size_t alignment,
|
||||
}
|
||||
|
||||
bool FreePages(void* address, const size_t size) {
|
||||
DCHECK_EQ(0UL, size & (GetPageAllocator()->AllocatePageSize() - 1));
|
||||
bool result = GetPageAllocator()->FreePages(address, size);
|
||||
#if defined(LEAK_SANITIZER)
|
||||
if (result) {
|
||||
@ -260,7 +261,9 @@ void VirtualMemory::Free() {
|
||||
size_t size = size_;
|
||||
CHECK(InVM(address, size));
|
||||
Reset();
|
||||
CHECK(FreePages(address, size));
|
||||
// FreePages expects size to be aligned to allocation granularity. Trimming
|
||||
// may leave size at only commit granularity. Align it here.
|
||||
CHECK(FreePages(address, RoundUp(size, AllocatePageSize())));
|
||||
}
|
||||
|
||||
void VirtualMemory::TakeControl(VirtualMemory* from) {
|
||||
|
@ -836,8 +836,7 @@ void* OS::Allocate(void* address, size_t size, size_t alignment,
|
||||
// static
|
||||
bool OS::Free(void* address, const size_t size) {
|
||||
DCHECK_EQ(0, reinterpret_cast<uintptr_t>(address) % AllocatePageSize());
|
||||
// TODO(bbudge) Add DCHECK_EQ(0, size % AllocatePageSize()) when callers
|
||||
// pass the correct size on Windows.
|
||||
DCHECK_EQ(0, size % AllocatePageSize());
|
||||
USE(size);
|
||||
return VirtualFree(address, 0, MEM_RELEASE) != 0;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user