• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2021 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_VIRTUAL_ADDRESS_SPACE_H_
6 #define V8_BASE_SANITIZER_LSAN_VIRTUAL_ADDRESS_SPACE_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 using Address = uintptr_t;
16 
17 // This is a v8::VirtualAddressSpace implementation that decorates provided page
18 // allocator object with leak sanitizer notifications when LEAK_SANITIZER is
19 // defined.
20 class V8_BASE_EXPORT LsanVirtualAddressSpace final
21     : public v8::VirtualAddressSpace {
22  public:
23   explicit LsanVirtualAddressSpace(
24       std::unique_ptr<v8::VirtualAddressSpace> vas);
25   ~LsanVirtualAddressSpace() override = default;
26 
SetRandomSeed(int64_t seed)27   void SetRandomSeed(int64_t seed) override {
28     return vas_->SetRandomSeed(seed);
29   }
30 
RandomPageAddress()31   Address RandomPageAddress() override { return vas_->RandomPageAddress(); }
32 
33   Address AllocatePages(Address hint, size_t size, size_t alignment,
34                         PagePermissions permissions) override;
35 
36   void FreePages(Address address, size_t size) override;
37 
38   Address AllocateSharedPages(Address hint, size_t size,
39                               PagePermissions permissions,
40                               PlatformSharedMemoryHandle handle,
41                               uint64_t offset) override;
42 
43   void FreeSharedPages(Address address, size_t size) override;
44 
SetPagePermissions(Address address,size_t size,PagePermissions permissions)45   bool SetPagePermissions(Address address, size_t size,
46                           PagePermissions permissions) override {
47     return vas_->SetPagePermissions(address, size, permissions);
48   }
49 
AllocateGuardRegion(Address address,size_t size)50   bool AllocateGuardRegion(Address address, size_t size) override {
51     return vas_->AllocateGuardRegion(address, size);
52   }
53 
FreeGuardRegion(Address address,size_t size)54   void FreeGuardRegion(Address address, size_t size) override {
55     vas_->FreeGuardRegion(address, size);
56   }
57 
CanAllocateSubspaces()58   bool CanAllocateSubspaces() override { return vas_->CanAllocateSubspaces(); }
59 
60   std::unique_ptr<VirtualAddressSpace> AllocateSubspace(
61       Address hint, size_t size, size_t alignment,
62       PagePermissions max_page_permissions) override;
63 
DiscardSystemPages(Address address,size_t size)64   bool DiscardSystemPages(Address address, size_t size) override {
65     return vas_->DiscardSystemPages(address, size);
66   }
67 
DecommitPages(Address address,size_t size)68   bool DecommitPages(Address address, size_t size) override {
69     return vas_->DecommitPages(address, size);
70   }
71 
72  private:
73   std::unique_ptr<v8::VirtualAddressSpace> vas_;
74 };
75 
76 }  // namespace base
77 }  // namespace v8
78 #endif  // V8_BASE_SANITIZER_LSAN_VIRTUAL_ADDRESS_SPACE_H_
79