v8_platform_page_allocator.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. // Copyright 2021 The Chromium 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. #ifndef GIN_V8_PLATFROM_PAGE_ALLOCATOR_H_
  5. #define GIN_V8_PLATFROM_PAGE_ALLOCATOR_H_
  6. #include "build/build_config.h"
  7. #include "build/buildflag.h"
  8. #include "base/allocator/buildflags.h"
  9. #if BUILDFLAG(USE_PARTITION_ALLOC)
  10. #include "base/allocator/partition_allocator/page_allocator.h"
  11. #include "gin/gin_export.h"
  12. #include "v8-platform.h"
  13. namespace gin {
  14. // A v8::PageAllocator implementation to use with gin.
  15. class GIN_EXPORT PageAllocator final : public v8::PageAllocator {
  16. public:
  17. ~PageAllocator() override;
  18. size_t AllocatePageSize() override;
  19. size_t CommitPageSize() override;
  20. void SetRandomMmapSeed(int64_t seed) override;
  21. void* GetRandomMmapAddr() override;
  22. void* AllocatePages(void* address,
  23. size_t length,
  24. size_t alignment,
  25. v8::PageAllocator::Permission permissions) override;
  26. bool FreePages(void* address, size_t length) override;
  27. bool ReleasePages(void* address, size_t length, size_t new_length) override;
  28. bool SetPermissions(void* address,
  29. size_t length,
  30. Permission permissions) override;
  31. bool RecommitPages(void* address,
  32. size_t length,
  33. Permission permissions) override;
  34. bool DiscardSystemPages(void* address, size_t size) override;
  35. bool DecommitPages(void* address, size_t size) override;
  36. // For testing purposes only: Map the v8 page permissions into a page
  37. // configuration from base.
  38. ::partition_alloc::PageAccessibilityConfiguration GetPageConfigForTesting(
  39. v8::PageAllocator::Permission permission);
  40. };
  41. } // namespace gin
  42. #endif // BUILDFLAG(USE_PARTITION_ALLOC)
  43. #endif // GIN_V8_PLATFROM_PAGE_ALLOCATOR_H_