v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
trusted-pointer-scope.cc
Go to the documentation of this file.
1// Copyright 2025 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
6
8
9#ifdef V8_ENABLE_SANDBOX
10
11namespace v8::internal {
12
14 Isolate* isolate, const DisallowJavascriptExecution& no_js)
15 : isolate_(isolate) {
16 // Nesting TrustedPointerPublishingScopes is not supported for now.
17 DCHECK_NULL(isolate->trusted_pointer_publishing_scope());
18 isolate->set_trusted_pointer_publishing_scope(this);
19}
20
21TrustedPointerPublishingScope::~TrustedPointerPublishingScope() {
22 if (state_ == State::kFailure) {
23 if (storage_ == Storage::kSingleton) {
24 singleton_->OverwriteTag(kUnpublishedIndirectPointerTag);
25 } else if (storage_ == Storage::kVector) {
26 for (TrustedPointerTableEntry* entry : *vector_) {
27 entry->OverwriteTag(kUnpublishedIndirectPointerTag);
28 }
29 }
30 } else {
31 // If this DCHECK fails, you probably forgot to call {MarkSuccess()}.
32 DCHECK_EQ(state_, State::kSuccess);
33 }
34 if (storage_ == Storage::kVector) delete vector_;
35 DCHECK_EQ(this, isolate_->trusted_pointer_publishing_scope());
36 isolate_->set_trusted_pointer_publishing_scope(nullptr);
37}
38
39void TrustedPointerPublishingScope::TrackPointer(
40 TrustedPointerTableEntry* entry) {
41 if (storage_ == Storage::kEmpty) {
42 singleton_ = entry;
43 storage_ = Storage::kSingleton;
44 return;
45 }
46 if (storage_ == Storage::kSingleton) {
47 TrustedPointerTableEntry* previous = singleton_;
48 vector_ = new std::vector<TrustedPointerTableEntry*>();
49 vector_->reserve(4);
50 vector_->push_back(previous);
51 storage_ = Storage::kVector;
52 }
53 vector_->push_back(entry);
54}
55
56DisableTrustedPointerPublishingScope::DisableTrustedPointerPublishingScope(
57 Isolate* isolate)
58 : isolate_(isolate) {
59 saved_ = isolate->trusted_pointer_publishing_scope();
60 if (saved_) {
61 isolate->set_trusted_pointer_publishing_scope(nullptr);
62 }
63}
64DisableTrustedPointerPublishingScope::~DisableTrustedPointerPublishingScope() {
65 if (saved_) {
66 isolate_->set_trusted_pointer_publishing_scope(saved_);
67 }
68}
69
70} // namespace v8::internal
71
72#endif // V8_ENABLE_SANDBOX
Isolate * isolate_
TrustedPointerPublishingScope(Isolate *isolate, const DisallowJavascriptExecution &no_js)
std::vector< T > vector_
Definition sweeper.cc:212
enum v8::internal::@1270::DeoptimizableCodeIterator::@67 state_
LineAndColumn previous
digit_t * storage_
Definition mul-fft.cc:475
#define DCHECK_NULL(val)
Definition logging.h:491
#define DCHECK_EQ(v1, v2)
Definition logging.h:485