1 // Copyright 2021 The Chromium Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef GIN_V8_PLATFORM_PAGE_ALLOCATOR_H_
6 #define GIN_V8_PLATFORM_PAGE_ALLOCATOR_H_
8 #include "build/build_config.h"
9 #include "build/buildflag.h"
11 #include "base/allocator/partition_allocator/src/partition_alloc/partition_alloc_buildflags.h"
13 #if BUILDFLAG(USE_PARTITION_ALLOC)
15 #include "base/allocator/partition_allocator/src/partition_alloc/page_allocator.h"
16 #include "gin/gin_export.h"
17 #include "v8/include/v8-platform.h"
21 // A v8::PageAllocator implementation to use with gin.
22 class GIN_EXPORT PageAllocator final : public v8::PageAllocator {
24 ~PageAllocator() override;
26 size_t AllocatePageSize() override;
28 size_t CommitPageSize() override;
30 void SetRandomMmapSeed(int64_t seed) override;
32 void* GetRandomMmapAddr() override;
34 void* AllocatePages(void* address,
37 v8::PageAllocator::Permission permissions) override;
39 bool FreePages(void* address, size_t length) override;
41 bool ReleasePages(void* address, size_t length, size_t new_length) override;
43 bool SetPermissions(void* address,
45 Permission permissions) override;
47 bool RecommitPages(void* address,
49 Permission permissions) override;
51 bool DiscardSystemPages(void* address, size_t size) override;
53 bool DecommitPages(void* address, size_t size) override;
55 // For testing purposes only: Map the v8 page permissions into a page
56 // configuration from base.
57 ::partition_alloc::PageAccessibilityConfiguration::Permissions
58 GetPageConfigPermissionsForTesting(v8::PageAllocator::Permission permission);
62 #endif // BUILDFLAG(USE_PARTITION_ALLOC)
64 #endif // GIN_V8_PLATFORM_PAGE_ALLOCATOR_H_