V8 API Reference, 7.2.502.16 (for Deno 0.2.4)
page-allocator.cc
1 // Copyright 2017 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "src/base/page-allocator.h"
6 
7 #include "src/base/platform/platform.h"
8 
9 namespace v8 {
10 namespace base {
11 
12 #define STATIC_ASSERT_ENUM(a, b) \
13  static_assert(static_cast<int>(a) == static_cast<int>(b), \
14  "mismatching enum: " #a)
15 
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);
24 
25 #undef STATIC_ASSERT_ENUM
26 
27 PageAllocator::PageAllocator()
28  : allocate_page_size_(base::OS::AllocatePageSize()),
29  commit_page_size_(base::OS::CommitPageSize()) {}
30 
31 void PageAllocator::SetRandomMmapSeed(int64_t seed) {
32  base::OS::SetRandomMmapSeed(seed);
33 }
34 
35 void* PageAllocator::GetRandomMmapAddr() {
36  return base::OS::GetRandomMmapAddr();
37 }
38 
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));
43 }
44 
45 bool PageAllocator::FreePages(void* address, size_t size) {
46  return base::OS::Free(address, size);
47 }
48 
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,
52  size - new_size);
53 }
54 
55 bool PageAllocator::SetPermissions(void* address, size_t size,
57  return base::OS::SetPermissions(
58  address, size, static_cast<base::OS::MemoryPermission>(access));
59 }
60 
61 bool PageAllocator::DiscardSystemPages(void* address, size_t size) {
62  return base::OS::DiscardSystemPages(address, size);
63 }
64 
65 } // namespace base
66 } // namespace v8
Definition: libplatform.h:13