v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
isolate-inl.h
Go to the documentation of this file.
1// Copyright 2023 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_SANDBOX_ISOLATE_INL_H_
6#define V8_SANDBOX_ISOLATE_INL_H_
7
9// Include the non-inl header before the rest of the headers.
10
16
17namespace v8::internal {
18
19#ifdef V8_ENABLE_SANDBOX
20
21ExternalPointerTable& IsolateForSandbox::GetExternalPointerTableFor(
22 ExternalPointerTagRange tag_range) {
23 IsolateForPointerCompression isolate(isolate_);
24 return isolate.GetExternalPointerTableFor(tag_range);
25}
26
27ExternalPointerTable::Space* IsolateForSandbox::GetExternalPointerTableSpaceFor(
28 ExternalPointerTagRange tag_range, Address host) {
29 IsolateForPointerCompression isolate(isolate_);
30 return isolate.GetExternalPointerTableSpaceFor(tag_range, host);
31}
32
33CodePointerTable::Space* IsolateForSandbox::GetCodePointerTableSpaceFor(
34 Address owning_slot) {
35 return ReadOnlyHeap::Contains(owning_slot)
36 ? isolate_->read_only_heap()->code_pointer_space()
37 : isolate_->heap()->code_pointer_space();
38}
39
40TrustedPointerTable& IsolateForSandbox::GetTrustedPointerTableFor(
43 ? isolate_->shared_trusted_pointer_table()
44 : isolate_->trusted_pointer_table();
45}
46
47TrustedPointerTable::Space* IsolateForSandbox::GetTrustedPointerTableSpaceFor(
50 ? isolate_->shared_trusted_pointer_space()
51 : isolate_->heap()->trusted_pointer_space();
52}
53
54ExternalPointerTag IsolateForSandbox::GetExternalPointerTableTagFor(
57 return isolate_->external_pointer_table().GetTag(handle);
58}
59
60bool IsolateForSandbox::SharesPointerTablesWith(IsolateForSandbox other) const {
61 return &isolate_->shared_trusted_pointer_table() ==
62 &other.isolate_->shared_trusted_pointer_table() &&
63 &isolate_->shared_external_pointer_table() ==
64 &other.isolate_->shared_external_pointer_table() &&
65 isolate_->shared_external_pointer_space() ==
66 other.isolate_->shared_external_pointer_space();
67}
68
69V8_INLINE IsolateForSandbox GetIsolateForSandbox(Tagged<HeapObject> object) {
70 // This method can be used on shared objects as opposed to
71 // GetHeapFromWritableObject because it only returns IsolateForSandbox instead
72 // of the Isolate. This is because shared objects will go to shared external
73 // pointer table which is the same for main and all worker isolates.
74 MemoryChunk* chunk = MemoryChunk::FromHeapObject(object);
75 Isolate* isolate = Isolate::FromHeap(chunk->GetHeap());
76 // Until we replace all GetIsolateForSandbox calls by
77 // GetCurrentIsolateForSandbox, do check that both return the same (or
78 // compatible, in case of shared isolate) isolates.
79 // See https://crbug.com/396607238 for context.
80 bool allow_isolate_sharing = V8_UNLIKELY(v8_flags.shared_heap);
82 // The only shared objects so far are shared strings, if enabled (off by
83 // default). Rethink this check once we have more shared objects.
84 CHECK(v8_flags.shared_string_table);
85 CHECK(IsString(object));
86 CHECK(isolate->is_shared_space_isolate());
87 allow_isolate_sharing = true;
88 }
89 if (allow_isolate_sharing) {
90 // TODO(396607238): Make this a `SBXCHECK`.
91 DCHECK(IsolateForSandbox{isolate}.SharesPointerTablesWith(
93 } else {
94 // TODO(396607238): Make this a `SBXCHECK`.
96 }
97 return isolate;
98}
99
100V8_INLINE IsolateForSandbox GetCurrentIsolateForSandbox() {
101 return Isolate::Current();
102}
103
104#endif // V8_ENABLE_SANDBOX
105
106#ifdef V8_COMPRESS_POINTERS
107
108ExternalPointerTable& IsolateForPointerCompression::GetExternalPointerTableFor(
109 ExternalPointerTagRange tag_range) {
110 DCHECK(!tag_range.IsEmpty());
111 return IsSharedExternalPointerType(tag_range)
112 ? isolate_->shared_external_pointer_table()
113 : isolate_->external_pointer_table();
114}
115
116ExternalPointerTable::Space*
117IsolateForPointerCompression::GetExternalPointerTableSpaceFor(
118 ExternalPointerTagRange tag_range, Address host) {
119 DCHECK(!tag_range.IsEmpty());
120
123 return isolate_->shared_external_pointer_space();
124 }
125
127 ReadOnlyHeap::Contains(host))) {
128 return isolate_->heap()->read_only_external_pointer_space();
129 }
130
132 return isolate_->heap()->young_external_pointer_space();
133 }
134
135 return isolate_->heap()->old_external_pointer_space();
136}
137
138CppHeapPointerTable& IsolateForPointerCompression::GetCppHeapPointerTable() {
139 return isolate_->cpp_heap_pointer_table();
140}
141
142CppHeapPointerTable::Space*
143IsolateForPointerCompression::GetCppHeapPointerTableSpace() {
144 return isolate_->heap()->cpp_heap_pointer_space();
145}
146
147#endif // V8_COMPRESS_POINTERS
148
149} // namespace v8::internal
150
151#endif // V8_SANDBOX_ISOLATE_INL_H_
Isolate * isolate_
static Isolate * TryGetCurrent()
Definition api.cc:9954
static V8_INLINE bool InYoungGeneration(Tagged< Object > object)
static V8_INLINE bool InWritableSharedSpace(Tagged< HeapObject > object)
static Tagged< HeapObject > FromAddress(Address address)
static V8_INLINE Isolate * Current()
Definition isolate-inl.h:35
static Isolate * FromHeap(const Heap *heap)
Definition isolate.h:1202
static V8_INLINE MemoryChunk * FromHeapObject(Tagged< HeapObject > object)
static V8_EXPORT_PRIVATE bool Contains(Address address)
Isolate * isolate
V8_INLINE IndirectHandle< T > handle(Tagged< T > object, Isolate *isolate)
Definition handles-inl.h:72
static V8_INLINE constexpr bool IsSharedExternalPointerType(ExternalPointerTagRange tag_range)
V8_INLINE IsolateForSandbox GetCurrentIsolateForSandbox()
Definition isolate.h:78
kInterpreterTrampolineOffset Tagged< HeapObject >
TagRange< ExternalPointerTag > ExternalPointerTagRange
V8_INLINE IsolateForSandbox GetIsolateForSandbox(Tagged< HeapObject >)
Definition isolate.h:75
static V8_INLINE constexpr bool IsMaybeReadOnlyExternalPointerType(ExternalPointerTagRange tag_range)
V8_EXPORT_PRIVATE FlagValues v8_flags
uint32_t ExternalPointerHandle
static V8_INLINE constexpr bool IsSharedTrustedPointerType(IndirectPointerTag tag)
#define CHECK(condition)
Definition logging.h:124
#define DCHECK(condition)
Definition logging.h:482
#define DCHECK_EQ(v1, v2)
Definition logging.h:485
#define V8_INLINE
Definition v8config.h:500
#define V8_UNLIKELY(condition)
Definition v8config.h:660