5 #include "src/base/page-allocator.h" 7 #include "src/base/platform/platform.h" 12 #define STATIC_ASSERT_ENUM(a, b) \ 13 static_assert(static_cast<int>(a) == static_cast<int>(b), \ 14 "mismatching enum: " #a) 16 STATIC_ASSERT_ENUM(PageAllocator::kNoAccess,
17 base::OS::MemoryPermission::kNoAccess);
18 STATIC_ASSERT_ENUM(PageAllocator::kReadWrite,
19 base::OS::MemoryPermission::kReadWrite);
20 STATIC_ASSERT_ENUM(PageAllocator::kReadWriteExecute,
21 base::OS::MemoryPermission::kReadWriteExecute);
22 STATIC_ASSERT_ENUM(PageAllocator::kReadExecute,
23 base::OS::MemoryPermission::kReadExecute);
25 #undef STATIC_ASSERT_ENUM 27 PageAllocator::PageAllocator()
28 : allocate_page_size_(base::OS::AllocatePageSize()),
29 commit_page_size_(base::OS::CommitPageSize()) {}
31 void PageAllocator::SetRandomMmapSeed(
int64_t seed) {
32 base::OS::SetRandomMmapSeed(seed);
35 void* PageAllocator::GetRandomMmapAddr() {
36 return base::OS::GetRandomMmapAddr();
39 void* PageAllocator::AllocatePages(
void* address,
size_t size,
size_t alignment,
41 return base::OS::Allocate(address, size, alignment,
42 static_cast<base::OS::MemoryPermission>(access));
45 bool PageAllocator::FreePages(
void* address,
size_t size) {
46 return base::OS::Free(address, size);
49 bool PageAllocator::ReleasePages(
void* address,
size_t size,
size_t new_size) {
50 DCHECK_LT(new_size, size);
51 return base::OS::Release(reinterpret_cast<uint8_t*>(address) + new_size,
55 bool PageAllocator::SetPermissions(
void* address,
size_t size,
57 return base::OS::SetPermissions(
58 address, size, static_cast<base::OS::MemoryPermission>(access));
61 bool PageAllocator::DiscardSystemPages(
void* address,
size_t size) {
62 return base::OS::DiscardSystemPages(address, size);