Skip to content

Commit

Permalink
Ensure reservation_ is initialized correctly
Browse files Browse the repository at this point in the history
Fix an issue introduced in commit 12d693d
where reservation_ field may not be initalized with the result of a successful
anon_mmap() call.  In the deconstructor, the memory is released based on
reservation_ value.

Signed-off-by: Joran Siu <[email protected]>
  • Loading branch information
joransiu committed Oct 2, 2018
1 parent 12d693d commit 9ba7834
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions src/base/platform/platform-zos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment)
: address_(NULL), size_(0), reservation_(NULL) {
DCHECK((alignment % OS::AllocateAlignment()) == 0);
//Memory pages with 1MB alignment will be allocated using __moservices
bool rmode64 = SysInfo::ExecutablePagesAbove2GB();
bool rmode64 = SysInfo::ExecutablePagesAbove2GB();
if (rmode64 && size % kMegaByte == 0) {
void * reservation = anon_mmap(OS::GetRandomMmapAddr(),
size);
Expand All @@ -348,19 +348,21 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment)
//to allocate memory with requested size and alignment, since there will
//be some fragmentation by going down this path
if (reservation == MAP_FAILED) {
request_size = RoundUp(size + alignment,
static_cast<intptr_t>(kMegaByte));
reservation = anon_mmap(OS::GetRandomMmapAddr(),
request_size);
if (reservation == MAP_FAILED) return;
reservation_ = reservation;

uint8_t * base = static_cast<uint8_t *>(reservation_);
uint8_t * aligned_base = RoundUp(base, alignment);
DCHECK_LE(base, aligned_base);
address_ = aligned_base;
size = request_size;
return;
request_size = RoundUp(size + alignment,
static_cast<intptr_t>(kMegaByte));
reservation = anon_mmap(OS::GetRandomMmapAddr(),
request_size);

if (reservation == MAP_FAILED)
return;

uint8_t * base = static_cast<uint8_t *>(reservation);
uint8_t * aligned_base = RoundUp(base, alignment);
DCHECK_LE(base, aligned_base);
address_ = aligned_base;
size = request_size;
reservation_ = reservation;
return;
}

uint8_t* base = static_cast<uint8_t*>(reservation);
Expand All @@ -386,6 +388,7 @@ VirtualMemory::VirtualMemory(size_t size, size_t alignment)

address_ = static_cast<void*>(aligned_base);
size_ = aligned_size;
reservation_ = reservation;
#if defined(LEAK_SANITIZER)
__lsan_register_root_region(address_, size_);
#endif
Expand Down

0 comments on commit 9ba7834

Please sign in to comment.