5 #include "src/base/bounded-page-allocator.h" 11 Address start,
size_t size,
12 size_t allocate_page_size)
13 : allocate_page_size_(allocate_page_size),
14 commit_page_size_(page_allocator->CommitPageSize()),
15 page_allocator_(page_allocator),
16 region_allocator_(start, size, allocate_page_size_) {
17 CHECK_NOT_NULL(page_allocator);
19 CHECK(IsAligned(allocate_page_size_, commit_page_size_));
22 BoundedPageAllocator::Address BoundedPageAllocator::begin()
const {
23 return region_allocator_.begin();
26 size_t BoundedPageAllocator::size()
const {
return region_allocator_.size(); }
31 MutexGuard guard(&mutex_);
32 CHECK(IsAligned(alignment, region_allocator_.page_size()));
36 CHECK_LE(alignment, allocate_page_size_);
39 Address address = region_allocator_.AllocateRegion(size);
40 if (address == RegionAllocator::kAllocationFailure) {
43 CHECK(page_allocator_->SetPermissions(reinterpret_cast<void*>(address), size,
45 return reinterpret_cast<void*
>(address);
48 bool BoundedPageAllocator::AllocatePagesAt(Address address,
size_t size,
50 CHECK(IsAligned(address, allocate_page_size_));
51 CHECK(IsAligned(size, allocate_page_size_));
52 CHECK(region_allocator_.contains(address, size));
54 if (!region_allocator_.AllocateRegionAt(address, size)) {
57 CHECK(page_allocator_->SetPermissions(reinterpret_cast<void*>(address), size,
63 MutexGuard guard(&mutex_);
66 size_t freed_size = region_allocator_.FreeRegion(address);
67 if (freed_size != size)
return false;
68 CHECK(page_allocator_->SetPermissions(raw_address, size,
69 PageAllocator::kNoAccess));
76 CHECK(IsAligned(address, allocate_page_size_));
78 DCHECK_LT(new_size, size);
79 DCHECK(IsAligned(size - new_size, commit_page_size_));
82 size_t allocated_size = RoundUp(size, allocate_page_size_);
83 size_t new_allocated_size = RoundUp(new_size, allocate_page_size_);
89 MutexGuard guard(&mutex_);
90 CHECK_EQ(allocated_size, region_allocator_.CheckRegion(address));
94 if (new_allocated_size < allocated_size) {
95 MutexGuard guard(&mutex_);
96 region_allocator_.TrimRegion(address, new_allocated_size);
100 Address free_address = address + new_size;
101 size_t free_size = size - new_size;
102 return page_allocator_->SetPermissions(reinterpret_cast<void*>(free_address),
103 free_size, PageAllocator::kNoAccess);
108 DCHECK(IsAligned(reinterpret_cast<Address>(address), commit_page_size_));
109 DCHECK(IsAligned(size, commit_page_size_));
110 DCHECK(region_allocator_.contains(reinterpret_cast<Address>(address), size));
111 return page_allocator_->SetPermissions(address, size, access);
115 return page_allocator_->DiscardSystemPages(address, size);
bool SetPermissions(void *address, size_t size, Permission access) override
bool ReleasePages(void *address, size_t size, size_t new_size) override
void * AllocatePages(void *hint, size_t size, size_t alignment, Permission access) override
bool DiscardSystemPages(void *address, size_t size) override
virtual size_t AllocatePageSize()=0
bool FreePages(void *address, size_t size) override