v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
trusted-pointer-scope.h
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
5#ifndef V8_SANDBOX_TRUSTED_POINTER_SCOPE_H_
6#define V8_SANDBOX_TRUSTED_POINTER_SCOPE_H_
7
9
10namespace v8::internal {
11
12class DisallowJavascriptExecution;
13
14#ifdef V8_ENABLE_SANDBOX
15
16struct TrustedPointerTableEntry;
17
18// A TrustedPointerPublishingScope is an optional facility for tracking
19// (multiple) newly created TrustedPointerTable entries, and having the
20// ability to neuter them afterwards, e.g. if their initialization as a
21// group failed in such a way that they should not be made accessible to
22// untrusted code (not even via existing in-sandbox corruption).
23class TrustedPointerPublishingScope {
24 public:
25 TrustedPointerPublishingScope(Isolate* isolate,
26 const DisallowJavascriptExecution& no_js);
27 ~TrustedPointerPublishingScope();
28
29 // Decide whether the tracked pointers should be published or discarded.
30 void MarkSuccess() { state_ = State::kSuccess; }
31 void MarkFailure() { state_ = State::kFailure; }
32
33 void TrackPointer(TrustedPointerTableEntry* entry);
34
35 private:
36 enum class State : uint8_t { kInProgress, kSuccess, kFailure };
37 enum class Storage : uint8_t { kEmpty, kSingleton, kVector };
38
39 State state_{State::kInProgress};
40 Storage storage_{Storage::kEmpty};
41 // We could use a base::SmallVector here, but it'd make the object bigger.
42 union {
43 TrustedPointerTableEntry* singleton_{nullptr};
44 std::vector<TrustedPointerTableEntry*>* vector_;
45 };
46 Isolate* isolate_;
47};
48
49// Temporarily disables a TrustedPointerPublishingScope.
50class DisableTrustedPointerPublishingScope {
51 public:
52 explicit DisableTrustedPointerPublishingScope(Isolate* isolate);
53 ~DisableTrustedPointerPublishingScope();
54
55 private:
56 Isolate* isolate_;
57 TrustedPointerPublishingScope* saved_{nullptr};
58};
59
60#else // V8_ENABLE_SANDBOX
61
63 public:
65 const DisallowJavascriptExecution& no_js) {}
66 void MarkSuccess() {}
67 void MarkFailure() {}
68};
69
74
75#endif // V8_ENABLE_SANDBOX
76
77} // namespace v8::internal
78
79#endif // V8_SANDBOX_TRUSTED_POINTER_SCOPE_H_
Isolate * isolate_
TrustedPointerPublishingScope(Isolate *isolate, const DisallowJavascriptExecution &no_js)
std::vector< T > vector_
Definition sweeper.cc:212
enum v8::internal::@1270::DeoptimizableCodeIterator::@67 state_
digit_t * storage_
Definition mul-fft.cc:475