1 // Copyright 2018 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 #ifndef V8_BASE_SANITIZER_LSAN_PAGE_ALLOCATOR_H_ 6 #define V8_BASE_SANITIZER_LSAN_PAGE_ALLOCATOR_H_ 7 8 #include "include/v8-platform.h" 9 #include "src/base/base-export.h" 10 #include "src/base/compiler-specific.h" 11 12 namespace v8 { 13 namespace base { 14 15 // This is a v8::PageAllocator implementation that decorates provided page 16 // allocator object with leak sanitizer notifications when LEAK_SANITIZER 17 // is defined. 18 class V8_BASE_EXPORT LsanPageAllocator : public v8::PageAllocator { 19 public: 20 explicit LsanPageAllocator(v8::PageAllocator* page_allocator); 21 ~LsanPageAllocator() override = default; 22 AllocatePageSize()23 size_t AllocatePageSize() override { return allocate_page_size_; } 24 CommitPageSize()25 size_t CommitPageSize() override { return commit_page_size_; } 26 SetRandomMmapSeed(int64_t seed)27 void SetRandomMmapSeed(int64_t seed) override { 28 return page_allocator_->SetRandomMmapSeed(seed); 29 } 30 GetRandomMmapAddr()31 void* GetRandomMmapAddr() override { 32 return page_allocator_->GetRandomMmapAddr(); 33 } 34 35 void* AllocatePages(void* address, size_t size, size_t alignment, 36 PageAllocator::Permission access) override; 37 38 std::unique_ptr<SharedMemory> AllocateSharedPages( 39 size_t size, const void* original_address) override; 40 41 bool CanAllocateSharedPages() override; 42 43 bool FreePages(void* address, size_t size) override; 44 45 bool ReleasePages(void* address, size_t size, size_t new_size) override; 46 SetPermissions(void * address,size_t size,PageAllocator::Permission access)47 bool SetPermissions(void* address, size_t size, 48 PageAllocator::Permission access) override { 49 return page_allocator_->SetPermissions(address, size, access); 50 } 51 DecommitPages(void * address,size_t size)52 bool DecommitPages(void* address, size_t size) override { 53 return page_allocator_->DecommitPages(address, size); 54 } 55 56 private: 57 v8::PageAllocator* const page_allocator_; 58 const size_t allocate_page_size_; 59 const size_t commit_page_size_; 60 }; 61 62 } // namespace base 63 } // namespace v8 64 #endif // V8_BASE_SANITIZER_LSAN_PAGE_ALLOCATOR_H_ 65