v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
emulated-virtual-address-subspace.h
Go to the documentation of this file.
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_EMULATED_VIRTUAL_ADDRESS_SUBSPACE_H_
6#define V8_BASE_EMULATED_VIRTUAL_ADDRESS_SUBSPACE_H_
7
14
15namespace v8 {
16namespace base {
17
32 : public NON_EXPORTED_BASE(::v8::VirtualAddressSpace) {
33 public:
34 // Construct an emulated virtual address subspace of the specified total size,
35 // potentially backed by a page allocation from the parent space. The newly
36 // created instance takes ownership of the page allocation (if any) and frees
37 // it during destruction.
39 Address base, size_t mapped_size,
40 size_t total_size);
41
43
44 void SetRandomSeed(int64_t seed) override;
45
46 Address RandomPageAddress() override;
47
48 Address AllocatePages(Address hint, size_t size, size_t alignment,
49 PagePermissions permissions) override;
50
51 void FreePages(Address address, size_t size) override;
52
53 Address AllocateSharedPages(Address hint, size_t size,
54 PagePermissions permissions,
56 uint64_t offset) override;
57
58 void FreeSharedPages(Address address, size_t size) override;
59
60 bool SetPagePermissions(Address address, size_t size,
61 PagePermissions permissions) override;
62
63 bool AllocateGuardRegion(Address address, size_t size) override;
64
65 void FreeGuardRegion(Address address, size_t size) override;
66
67 bool CanAllocateSubspaces() override;
68
69 std::unique_ptr<v8::VirtualAddressSpace> AllocateSubspace(
70 Address hint, size_t size, size_t alignment,
71 PagePermissions max_page_permissions) override;
72
73 bool RecommitPages(Address address, size_t size,
74 PagePermissions permissions) override;
75
76 bool DiscardSystemPages(Address address, size_t size) override;
77
78 bool DecommitPages(Address address, size_t size) override;
79
80 private:
81 size_t mapped_size() const { return mapped_size_; }
82 size_t unmapped_size() const { return size() - mapped_size_; }
83
84 Address mapped_base() const { return base(); }
85 Address unmapped_base() const { return base() + mapped_size_; }
86
87 bool Contains(Address outer_start, size_t outer_size, Address inner_start,
88 size_t inner_size) const {
89 return (inner_start >= outer_start) &&
90 ((inner_start + inner_size) <= (outer_start + outer_size));
91 }
92
93 bool Contains(Address addr, size_t length) const {
94 return Contains(base(), size(), addr, length);
95 }
96
97 bool MappedRegionContains(Address addr, size_t length) const {
98 return Contains(mapped_base(), mapped_size(), addr, length);
99 }
100
101 bool UnmappedRegionContains(Address addr, size_t length) const {
102 return Contains(unmapped_base(), unmapped_size(), addr, length);
103 }
104
105 // Helper function to define a limit for the size of allocations in the
106 // unmapped region. This limit makes it possible to estimate the expected
107 // runtime of some loops in the Allocate methods.
108 bool IsUsableSizeForUnmappedRegion(size_t size) const {
109 return size <= (unmapped_size() / 2);
110 }
111
112 // Size of the mapped region located at the beginning of this address space.
113 const size_t mapped_size_;
114
115 // Pointer to the parent space from which the backing pages were allocated.
116 // Must be kept alive by the owner of this instance.
118
119 // Mutex guarding the non-threadsafe RegionAllocator and
120 // RandomNumberGenerator.
122
123 // RegionAllocator to manage the page allocation and divide it into further
124 // regions as necessary.
126
127 // Random number generator for generating random addresses.
129};
130
131} // namespace base
132} // namespace v8
133
134#endif // V8_BASE_EMULATED_VIRTUAL_ADDRESS_SUBSPACE_H_
#define V8_BASE_EXPORT
Definition base-export.h:26
bool Contains(Address addr, size_t length) const
bool Contains(Address outer_start, size_t outer_size, Address inner_start, size_t inner_size) const
bool UnmappedRegionContains(Address addr, size_t length) const
bool MappedRegionContains(Address addr, size_t length) const
int32_t offset
uintptr_t Address
Definition memory.h:13
intptr_t PlatformSharedMemoryHandle
PagePermissions
#define NON_EXPORTED_BASE(code)