Home | History | Annotate | Download | only in base
      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 size_t PageAllocator::AllocatePageSize() {
     28   return base::OS::AllocatePageSize();
     29 }
     30 
     31 size_t PageAllocator::CommitPageSize() { return base::OS::CommitPageSize(); }
     32 
     33 void PageAllocator::SetRandomMmapSeed(int64_t seed) {
     34   base::OS::SetRandomMmapSeed(seed);
     35 }
     36 
     37 void* PageAllocator::GetRandomMmapAddr() {
     38   return base::OS::GetRandomMmapAddr();
     39 }
     40 
     41 void* PageAllocator::AllocatePages(void* address, size_t size, size_t alignment,
     42                                    PageAllocator::Permission access) {
     43   return base::OS::Allocate(address, size, alignment,
     44                             static_cast<base::OS::MemoryPermission>(access));
     45 }
     46 
     47 bool PageAllocator::FreePages(void* address, size_t size) {
     48   return base::OS::Free(address, size);
     49 }
     50 
     51 bool PageAllocator::ReleasePages(void* address, size_t size, size_t new_size) {
     52   DCHECK_LT(new_size, size);
     53   return base::OS::Release(reinterpret_cast<uint8_t*>(address) + new_size,
     54                            size - new_size);
     55 }
     56 
     57 bool PageAllocator::SetPermissions(void* address, size_t size,
     58                                    PageAllocator::Permission access) {
     59   return base::OS::SetPermissions(
     60       address, size, static_cast<base::OS::MemoryPermission>(access));
     61 }
     62 
     63 }  // namespace base
     64 }  // namespace v8
     65