@babylonjs/v8-android-jit-nointl-nosnapshot 11.110.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (126) hide show
  1. package/dist/include/APIDesign.md +72 -0
  2. package/dist/include/DEPS +10 -0
  3. package/dist/include/DIR_METADATA +11 -0
  4. package/dist/include/OWNERS +23 -0
  5. package/dist/include/cppgc/DEPS +8 -0
  6. package/dist/include/cppgc/OWNERS +2 -0
  7. package/dist/include/cppgc/README.md +135 -0
  8. package/dist/include/cppgc/allocation.h +310 -0
  9. package/dist/include/cppgc/common.h +28 -0
  10. package/dist/include/cppgc/cross-thread-persistent.h +464 -0
  11. package/dist/include/cppgc/custom-space.h +97 -0
  12. package/dist/include/cppgc/default-platform.h +67 -0
  13. package/dist/include/cppgc/ephemeron-pair.h +30 -0
  14. package/dist/include/cppgc/explicit-management.h +100 -0
  15. package/dist/include/cppgc/garbage-collected.h +106 -0
  16. package/dist/include/cppgc/heap-consistency.h +309 -0
  17. package/dist/include/cppgc/heap-handle.h +48 -0
  18. package/dist/include/cppgc/heap-state.h +82 -0
  19. package/dist/include/cppgc/heap-statistics.h +120 -0
  20. package/dist/include/cppgc/heap.h +202 -0
  21. package/dist/include/cppgc/internal/api-constants.h +65 -0
  22. package/dist/include/cppgc/internal/atomic-entry-flag.h +48 -0
  23. package/dist/include/cppgc/internal/base-page-handle.h +45 -0
  24. package/dist/include/cppgc/internal/caged-heap-local-data.h +111 -0
  25. package/dist/include/cppgc/internal/caged-heap.h +61 -0
  26. package/dist/include/cppgc/internal/compiler-specific.h +38 -0
  27. package/dist/include/cppgc/internal/finalizer-trait.h +93 -0
  28. package/dist/include/cppgc/internal/gc-info.h +155 -0
  29. package/dist/include/cppgc/internal/logging.h +50 -0
  30. package/dist/include/cppgc/internal/member-storage.h +236 -0
  31. package/dist/include/cppgc/internal/name-trait.h +137 -0
  32. package/dist/include/cppgc/internal/persistent-node.h +214 -0
  33. package/dist/include/cppgc/internal/pointer-policies.h +207 -0
  34. package/dist/include/cppgc/internal/write-barrier.h +477 -0
  35. package/dist/include/cppgc/liveness-broker.h +78 -0
  36. package/dist/include/cppgc/macros.h +26 -0
  37. package/dist/include/cppgc/member.h +566 -0
  38. package/dist/include/cppgc/name-provider.h +65 -0
  39. package/dist/include/cppgc/object-size-trait.h +58 -0
  40. package/dist/include/cppgc/persistent.h +366 -0
  41. package/dist/include/cppgc/platform.h +158 -0
  42. package/dist/include/cppgc/prefinalizer.h +75 -0
  43. package/dist/include/cppgc/process-heap-statistics.h +36 -0
  44. package/dist/include/cppgc/sentinel-pointer.h +32 -0
  45. package/dist/include/cppgc/source-location.h +92 -0
  46. package/dist/include/cppgc/testing.h +106 -0
  47. package/dist/include/cppgc/trace-trait.h +120 -0
  48. package/dist/include/cppgc/type-traits.h +249 -0
  49. package/dist/include/cppgc/visitor.h +411 -0
  50. package/dist/include/js_protocol-1.2.json +997 -0
  51. package/dist/include/js_protocol-1.3.json +1159 -0
  52. package/dist/include/js_protocol.pdl +1766 -0
  53. package/dist/include/libplatform/DEPS +9 -0
  54. package/dist/include/libplatform/libplatform-export.h +29 -0
  55. package/dist/include/libplatform/libplatform.h +106 -0
  56. package/dist/include/libplatform/v8-tracing.h +333 -0
  57. package/dist/include/v8-array-buffer.h +512 -0
  58. package/dist/include/v8-callbacks.h +412 -0
  59. package/dist/include/v8-container.h +129 -0
  60. package/dist/include/v8-context.h +415 -0
  61. package/dist/include/v8-cppgc.h +231 -0
  62. package/dist/include/v8-data.h +80 -0
  63. package/dist/include/v8-date.h +48 -0
  64. package/dist/include/v8-debug.h +168 -0
  65. package/dist/include/v8-embedder-heap.h +223 -0
  66. package/dist/include/v8-embedder-state-scope.h +51 -0
  67. package/dist/include/v8-exception.h +217 -0
  68. package/dist/include/v8-extension.h +62 -0
  69. package/dist/include/v8-external.h +37 -0
  70. package/dist/include/v8-fast-api-calls.h +957 -0
  71. package/dist/include/v8-forward.h +81 -0
  72. package/dist/include/v8-function-callback.h +475 -0
  73. package/dist/include/v8-function.h +133 -0
  74. package/dist/include/v8-initialization.h +289 -0
  75. package/dist/include/v8-inspector-protocol.h +13 -0
  76. package/dist/include/v8-inspector.h +397 -0
  77. package/dist/include/v8-internal.h +851 -0
  78. package/dist/include/v8-isolate.h +1695 -0
  79. package/dist/include/v8-json.h +47 -0
  80. package/dist/include/v8-local-handle.h +455 -0
  81. package/dist/include/v8-locker.h +138 -0
  82. package/dist/include/v8-maybe.h +160 -0
  83. package/dist/include/v8-memory-span.h +43 -0
  84. package/dist/include/v8-message.h +214 -0
  85. package/dist/include/v8-metrics.h +311 -0
  86. package/dist/include/v8-microtask-queue.h +157 -0
  87. package/dist/include/v8-microtask.h +28 -0
  88. package/dist/include/v8-object.h +768 -0
  89. package/dist/include/v8-persistent-handle.h +588 -0
  90. package/dist/include/v8-platform.h +1130 -0
  91. package/dist/include/v8-primitive-object.h +118 -0
  92. package/dist/include/v8-primitive.h +866 -0
  93. package/dist/include/v8-profiler.h +1277 -0
  94. package/dist/include/v8-promise.h +174 -0
  95. package/dist/include/v8-proxy.h +50 -0
  96. package/dist/include/v8-regexp.h +106 -0
  97. package/dist/include/v8-script.h +803 -0
  98. package/dist/include/v8-snapshot.h +196 -0
  99. package/dist/include/v8-statistics.h +217 -0
  100. package/dist/include/v8-template.h +1018 -0
  101. package/dist/include/v8-traced-handle.h +420 -0
  102. package/dist/include/v8-typed-array.h +282 -0
  103. package/dist/include/v8-unwinder-state.h +31 -0
  104. package/dist/include/v8-unwinder.h +132 -0
  105. package/dist/include/v8-util.h +656 -0
  106. package/dist/include/v8-value-serializer-version.h +24 -0
  107. package/dist/include/v8-value-serializer.h +302 -0
  108. package/dist/include/v8-value.h +531 -0
  109. package/dist/include/v8-version-string.h +38 -0
  110. package/dist/include/v8-version.h +20 -0
  111. package/dist/include/v8-wasm-trap-handler-posix.h +31 -0
  112. package/dist/include/v8-wasm-trap-handler-win.h +28 -0
  113. package/dist/include/v8-wasm.h +200 -0
  114. package/dist/include/v8-weak-callback-info.h +80 -0
  115. package/dist/include/v8.h +88 -0
  116. package/dist/include/v8config.h +904 -0
  117. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar +0 -0
  118. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar.md5 +1 -0
  119. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.aar.sha1 +1 -0
  120. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom +10 -0
  121. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom.md5 +1 -0
  122. package/dist/org/chromium/v8-android/11.110.1/v8-android-11.110.1.pom.sha1 +1 -0
  123. package/dist/org/chromium/v8-android/maven-metadata.xml +12 -0
  124. package/dist/org/chromium/v8-android/maven-metadata.xml.md5 +1 -0
  125. package/dist/org/chromium/v8-android/maven-metadata.xml.sha1 +1 -0
  126. package/package.json +24 -0
@@ -0,0 +1,851 @@
1
+ // Copyright 2018 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 INCLUDE_V8_INTERNAL_H_
6
+ #define INCLUDE_V8_INTERNAL_H_
7
+
8
+ #include <stddef.h>
9
+ #include <stdint.h>
10
+ #include <string.h>
11
+
12
+ #include <atomic>
13
+ #include <type_traits>
14
+
15
+ #include "v8-version.h" // NOLINT(build/include_directory)
16
+ #include "v8config.h" // NOLINT(build/include_directory)
17
+
18
+ namespace v8 {
19
+
20
+ class Array;
21
+ class Context;
22
+ class Data;
23
+ class Isolate;
24
+ template <typename T>
25
+ class Local;
26
+
27
+ namespace internal {
28
+
29
+ class Isolate;
30
+
31
+ typedef uintptr_t Address;
32
+ static const Address kNullAddress = 0;
33
+
34
+ constexpr int KB = 1024;
35
+ constexpr int MB = KB * 1024;
36
+ constexpr int GB = MB * 1024;
37
+ #ifdef V8_TARGET_ARCH_X64
38
+ constexpr size_t TB = size_t{GB} * 1024;
39
+ #endif
40
+
41
+ /**
42
+ * Configuration of tagging scheme.
43
+ */
44
+ const int kApiSystemPointerSize = sizeof(void*);
45
+ const int kApiDoubleSize = sizeof(double);
46
+ const int kApiInt32Size = sizeof(int32_t);
47
+ const int kApiInt64Size = sizeof(int64_t);
48
+ const int kApiSizetSize = sizeof(size_t);
49
+
50
+ // Tag information for HeapObject.
51
+ const int kHeapObjectTag = 1;
52
+ const int kWeakHeapObjectTag = 3;
53
+ const int kHeapObjectTagSize = 2;
54
+ const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
55
+ const intptr_t kHeapObjectReferenceTagMask = 1 << (kHeapObjectTagSize - 1);
56
+
57
+ // Tag information for fowarding pointers stored in object headers.
58
+ // 0b00 at the lowest 2 bits in the header indicates that the map word is a
59
+ // forwarding pointer.
60
+ const int kForwardingTag = 0;
61
+ const int kForwardingTagSize = 2;
62
+ const intptr_t kForwardingTagMask = (1 << kForwardingTagSize) - 1;
63
+
64
+ // Tag information for Smi.
65
+ const int kSmiTag = 0;
66
+ const int kSmiTagSize = 1;
67
+ const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
68
+
69
+ template <size_t tagged_ptr_size>
70
+ struct SmiTagging;
71
+
72
+ constexpr intptr_t kIntptrAllBitsSet = intptr_t{-1};
73
+ constexpr uintptr_t kUintptrAllBitsSet =
74
+ static_cast<uintptr_t>(kIntptrAllBitsSet);
75
+
76
+ // Smi constants for systems where tagged pointer is a 32-bit value.
77
+ template <>
78
+ struct SmiTagging<4> {
79
+ enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
80
+
81
+ static constexpr intptr_t kSmiMinValue =
82
+ static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
83
+ static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
84
+
85
+ V8_INLINE static int SmiToInt(const internal::Address value) {
86
+ int shift_bits = kSmiTagSize + kSmiShiftSize;
87
+ // Truncate and shift down (requires >> to be sign extending).
88
+ return static_cast<int32_t>(static_cast<uint32_t>(value)) >> shift_bits;
89
+ }
90
+ V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
91
+ // Is value in range [kSmiMinValue, kSmiMaxValue].
92
+ // Use unsigned operations in order to avoid undefined behaviour in case of
93
+ // signed integer overflow.
94
+ return (static_cast<uintptr_t>(value) -
95
+ static_cast<uintptr_t>(kSmiMinValue)) <=
96
+ (static_cast<uintptr_t>(kSmiMaxValue) -
97
+ static_cast<uintptr_t>(kSmiMinValue));
98
+ }
99
+ };
100
+
101
+ // Smi constants for systems where tagged pointer is a 64-bit value.
102
+ template <>
103
+ struct SmiTagging<8> {
104
+ enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
105
+
106
+ static constexpr intptr_t kSmiMinValue =
107
+ static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
108
+ static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
109
+
110
+ V8_INLINE static int SmiToInt(const internal::Address value) {
111
+ int shift_bits = kSmiTagSize + kSmiShiftSize;
112
+ // Shift down and throw away top 32 bits.
113
+ return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits);
114
+ }
115
+ V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
116
+ // To be representable as a long smi, the value must be a 32-bit integer.
117
+ return (value == static_cast<int32_t>(value));
118
+ }
119
+ };
120
+
121
+ #ifdef V8_COMPRESS_POINTERS
122
+ // See v8:7703 or src/common/ptr-compr-inl.h for details about pointer
123
+ // compression.
124
+ constexpr size_t kPtrComprCageReservationSize = size_t{1} << 32;
125
+ constexpr size_t kPtrComprCageBaseAlignment = size_t{1} << 32;
126
+
127
+ static_assert(
128
+ kApiSystemPointerSize == kApiInt64Size,
129
+ "Pointer compression can be enabled only for 64-bit architectures");
130
+ const int kApiTaggedSize = kApiInt32Size;
131
+ #else
132
+ const int kApiTaggedSize = kApiSystemPointerSize;
133
+ #endif
134
+
135
+ constexpr bool PointerCompressionIsEnabled() {
136
+ return kApiTaggedSize != kApiSystemPointerSize;
137
+ }
138
+
139
+ #ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
140
+ using PlatformSmiTagging = SmiTagging<kApiInt32Size>;
141
+ #else
142
+ using PlatformSmiTagging = SmiTagging<kApiTaggedSize>;
143
+ #endif
144
+
145
+ // TODO(ishell): Consinder adding kSmiShiftBits = kSmiShiftSize + kSmiTagSize
146
+ // since it's used much more often than the inividual constants.
147
+ const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
148
+ const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
149
+ const int kSmiMinValue = static_cast<int>(PlatformSmiTagging::kSmiMinValue);
150
+ const int kSmiMaxValue = static_cast<int>(PlatformSmiTagging::kSmiMaxValue);
151
+ constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
152
+ constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
153
+
154
+ V8_INLINE static constexpr internal::Address IntToSmi(int value) {
155
+ return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) |
156
+ kSmiTag;
157
+ }
158
+
159
+ /*
160
+ * Sandbox related types, constants, and functions.
161
+ */
162
+ constexpr bool SandboxIsEnabled() {
163
+ #ifdef V8_ENABLE_SANDBOX
164
+ return true;
165
+ #else
166
+ return false;
167
+ #endif
168
+ }
169
+
170
+ // SandboxedPointers are guaranteed to point into the sandbox. This is achieved
171
+ // for example by storing them as offset rather than as raw pointers.
172
+ using SandboxedPointer_t = Address;
173
+
174
+ #ifdef V8_ENABLE_SANDBOX
175
+
176
+ // Size of the sandbox, excluding the guard regions surrounding it.
177
+ #ifdef V8_TARGET_OS_ANDROID
178
+ // On Android, most 64-bit devices seem to be configured with only 39 bits of
179
+ // virtual address space for userspace. As such, limit the sandbox to 128GB (a
180
+ // quarter of the total available address space).
181
+ constexpr size_t kSandboxSizeLog2 = 37; // 128 GB
182
+ #else
183
+ // Everywhere else use a 1TB sandbox.
184
+ constexpr size_t kSandboxSizeLog2 = 40; // 1 TB
185
+ #endif // V8_TARGET_OS_ANDROID
186
+ constexpr size_t kSandboxSize = 1ULL << kSandboxSizeLog2;
187
+
188
+ // Required alignment of the sandbox. For simplicity, we require the
189
+ // size of the guard regions to be a multiple of this, so that this specifies
190
+ // the alignment of the sandbox including and excluding surrounding guard
191
+ // regions. The alignment requirement is due to the pointer compression cage
192
+ // being located at the start of the sandbox.
193
+ constexpr size_t kSandboxAlignment = kPtrComprCageBaseAlignment;
194
+
195
+ // Sandboxed pointers are stored inside the heap as offset from the sandbox
196
+ // base shifted to the left. This way, it is guaranteed that the offset is
197
+ // smaller than the sandbox size after shifting it to the right again. This
198
+ // constant specifies the shift amount.
199
+ constexpr uint64_t kSandboxedPointerShift = 64 - kSandboxSizeLog2;
200
+
201
+ // Size of the guard regions surrounding the sandbox. This assumes a worst-case
202
+ // scenario of a 32-bit unsigned index used to access an array of 64-bit
203
+ // values.
204
+ constexpr size_t kSandboxGuardRegionSize = 32ULL * GB;
205
+
206
+ static_assert((kSandboxGuardRegionSize % kSandboxAlignment) == 0,
207
+ "The size of the guard regions around the sandbox must be a "
208
+ "multiple of its required alignment.");
209
+
210
+ // On OSes where reserving virtual memory is too expensive to reserve the
211
+ // entire address space backing the sandbox, notably Windows pre 8.1, we create
212
+ // a partially reserved sandbox that doesn't actually reserve most of the
213
+ // memory, and so doesn't have the desired security properties as unrelated
214
+ // memory allocations could end up inside of it, but which still ensures that
215
+ // objects that should be located inside the sandbox are allocated within
216
+ // kSandboxSize bytes from the start of the sandbox. The minimum size of the
217
+ // region that is actually reserved for such a sandbox is specified by this
218
+ // constant and should be big enough to contain the pointer compression cage as
219
+ // well as the ArrayBuffer partition.
220
+ constexpr size_t kSandboxMinimumReservationSize = 8ULL * GB;
221
+
222
+ static_assert(kSandboxMinimumReservationSize > kPtrComprCageReservationSize,
223
+ "The minimum reservation size for a sandbox must be larger than "
224
+ "the pointer compression cage contained within it.");
225
+
226
+ // The maximum buffer size allowed inside the sandbox. This is mostly dependent
227
+ // on the size of the guard regions around the sandbox: an attacker must not be
228
+ // able to construct a buffer that appears larger than the guard regions and
229
+ // thereby "reach out of" the sandbox.
230
+ constexpr size_t kMaxSafeBufferSizeForSandbox = 32ULL * GB - 1;
231
+ static_assert(kMaxSafeBufferSizeForSandbox <= kSandboxGuardRegionSize,
232
+ "The maximum allowed buffer size must not be larger than the "
233
+ "sandbox's guard regions");
234
+
235
+ constexpr size_t kBoundedSizeShift = 29;
236
+ static_assert(1ULL << (64 - kBoundedSizeShift) ==
237
+ kMaxSafeBufferSizeForSandbox + 1,
238
+ "The maximum size of a BoundedSize must be synchronized with the "
239
+ "kMaxSafeBufferSizeForSandbox");
240
+
241
+ #endif // V8_ENABLE_SANDBOX
242
+
243
+ #ifdef V8_COMPRESS_POINTERS
244
+
245
+ // The size of the virtual memory reservation for an external pointer table.
246
+ // This determines the maximum number of entries in a table. Using a maximum
247
+ // size allows omitting bounds checks on table accesses if the indices are
248
+ // guaranteed (e.g. through shifting) to be below the maximum index. This
249
+ // value must be a power of two.
250
+ static const size_t kExternalPointerTableReservationSize = 512 * MB;
251
+
252
+ // The maximum number of entries in an external pointer table.
253
+ static const size_t kMaxExternalPointers =
254
+ kExternalPointerTableReservationSize / kApiSystemPointerSize;
255
+
256
+ // The external pointer table indices stored in HeapObjects as external
257
+ // pointers are shifted to the left by this amount to guarantee that they are
258
+ // smaller than the maximum table size.
259
+ static const uint32_t kExternalPointerIndexShift = 6;
260
+ static_assert((1 << (32 - kExternalPointerIndexShift)) == kMaxExternalPointers,
261
+ "kExternalPointerTableReservationSize and "
262
+ "kExternalPointerIndexShift don't match");
263
+
264
+ #else // !V8_COMPRESS_POINTERS
265
+
266
+ // Needed for the V8.SandboxedExternalPointersCount histogram.
267
+ static const size_t kMaxExternalPointers = 0;
268
+
269
+ #endif // V8_COMPRESS_POINTERS
270
+
271
+ // A ExternalPointerHandle represents a (opaque) reference to an external
272
+ // pointer that can be stored inside the sandbox. A ExternalPointerHandle has
273
+ // meaning only in combination with an (active) Isolate as it references an
274
+ // external pointer stored in the currently active Isolate's
275
+ // ExternalPointerTable. Internally, an ExternalPointerHandles is simply an
276
+ // index into an ExternalPointerTable that is shifted to the left to guarantee
277
+ // that it is smaller than the size of the table.
278
+ using ExternalPointerHandle = uint32_t;
279
+
280
+ // ExternalPointers point to objects located outside the sandbox. When
281
+ // sandboxed external pointers are enabled, these are stored on heap as
282
+ // ExternalPointerHandles, otherwise they are simply raw pointers.
283
+ #ifdef V8_ENABLE_SANDBOX
284
+ using ExternalPointer_t = ExternalPointerHandle;
285
+ #else
286
+ using ExternalPointer_t = Address;
287
+ #endif
288
+
289
+ // When the sandbox is enabled, external pointers are stored in an external
290
+ // pointer table and are referenced from HeapObjects through an index (a
291
+ // "handle"). When stored in the table, the pointers are tagged with per-type
292
+ // tags to prevent type confusion attacks between different external objects.
293
+ // Besides type information bits, these tags also contain the GC marking bit
294
+ // which indicates whether the pointer table entry is currently alive. When a
295
+ // pointer is written into the table, the tag is ORed into the top bits. When
296
+ // that pointer is later loaded from the table, it is ANDed with the inverse of
297
+ // the expected tag. If the expected and actual type differ, this will leave
298
+ // some of the top bits of the pointer set, rendering the pointer inaccessible.
299
+ // The AND operation also removes the GC marking bit from the pointer.
300
+ //
301
+ // The tags are constructed such that UNTAG(TAG(0, T1), T2) != 0 for any two
302
+ // (distinct) tags T1 and T2. In practice, this is achieved by generating tags
303
+ // that all have the same number of zeroes and ones but different bit patterns.
304
+ // With N type tag bits, this allows for (N choose N/2) possible type tags.
305
+ // Besides the type tag bits, the tags also have the GC marking bit set so that
306
+ // the marking bit is automatically set when a pointer is written into the
307
+ // external pointer table (in which case it is clearly alive) and is cleared
308
+ // when the pointer is loaded. The exception to this is the free entry tag,
309
+ // which doesn't have the mark bit set, as the entry is not alive. This
310
+ // construction allows performing the type check and removing GC marking bits
311
+ // from the pointer in one efficient operation (bitwise AND). The number of
312
+ // available bits is limited in the following way: on x64, bits [47, 64) are
313
+ // generally available for tagging (userspace has 47 address bits available).
314
+ // On Arm64, userspace typically has a 40 or 48 bit address space. However, due
315
+ // to top-byte ignore (TBI) and memory tagging (MTE), the top byte is unusable
316
+ // for type checks as type-check failures would go unnoticed or collide with
317
+ // MTE bits. Some bits of the top byte can, however, still be used for the GC
318
+ // marking bit. The bits available for the type tags are therefore limited to
319
+ // [48, 56), i.e. (8 choose 4) = 70 different types.
320
+ // The following options exist to increase the number of possible types:
321
+ // - Using multiple ExternalPointerTables since tags can safely be reused
322
+ // across different tables
323
+ // - Using "extended" type checks, where additional type information is stored
324
+ // either in an adjacent pointer table entry or at the pointed-to location
325
+ // - Using a different tagging scheme, for example based on XOR which would
326
+ // allow for 2**8 different tags but require a separate operation to remove
327
+ // the marking bit
328
+ //
329
+ // The external pointer sandboxing mechanism ensures that every access to an
330
+ // external pointer field will result in a valid pointer of the expected type
331
+ // even in the presence of an attacker able to corrupt memory inside the
332
+ // sandbox. However, if any data related to the external object is stored
333
+ // inside the sandbox it may still be corrupted and so must be validated before
334
+ // use or moved into the external object. Further, an attacker will always be
335
+ // able to substitute different external pointers of the same type for each
336
+ // other. Therefore, code using external pointers must be written in a
337
+ // "substitution-safe" way, i.e. it must always be possible to substitute
338
+ // external pointers of the same type without causing memory corruption outside
339
+ // of the sandbox. Generally this is achieved by referencing any group of
340
+ // related external objects through a single external pointer.
341
+ //
342
+ // Currently we use bit 62 for the marking bit which should always be unused as
343
+ // it's part of the non-canonical address range. When Arm's top-byte ignore
344
+ // (TBI) is enabled, this bit will be part of the ignored byte, and we assume
345
+ // that the Embedder is not using this byte (really only this one bit) for any
346
+ // other purpose. This bit also does not collide with the memory tagging
347
+ // extension (MTE) which would use bits [56, 60).
348
+ //
349
+ // External pointer tables are also available even when the sandbox is off but
350
+ // pointer compression is on. In that case, the mechanism can be used to easy
351
+ // alignment requirements as it turns unaligned 64-bit raw pointers into
352
+ // aligned 32-bit indices. To "opt-in" to the external pointer table mechanism
353
+ // for this purpose, instead of using the ExternalPointer accessors one needs to
354
+ // use ExternalPointerHandles directly and use them to access the pointers in an
355
+ // ExternalPointerTable.
356
+ constexpr uint64_t kExternalPointerMarkBit = 1ULL << 62;
357
+ constexpr uint64_t kExternalPointerTagMask = 0x40ff000000000000;
358
+ constexpr uint64_t kExternalPointerTagShift = 48;
359
+
360
+ // All possible 8-bit type tags.
361
+ // These are sorted so that tags can be grouped together and it can efficiently
362
+ // be checked if a tag belongs to a given group. See for example the
363
+ // IsSharedExternalPointerType routine.
364
+ constexpr uint64_t kAllExternalPointerTypeTags[] = {
365
+ 0b00001111, 0b00010111, 0b00011011, 0b00011101, 0b00011110, 0b00100111,
366
+ 0b00101011, 0b00101101, 0b00101110, 0b00110011, 0b00110101, 0b00110110,
367
+ 0b00111001, 0b00111010, 0b00111100, 0b01000111, 0b01001011, 0b01001101,
368
+ 0b01001110, 0b01010011, 0b01010101, 0b01010110, 0b01011001, 0b01011010,
369
+ 0b01011100, 0b01100011, 0b01100101, 0b01100110, 0b01101001, 0b01101010,
370
+ 0b01101100, 0b01110001, 0b01110010, 0b01110100, 0b01111000, 0b10000111,
371
+ 0b10001011, 0b10001101, 0b10001110, 0b10010011, 0b10010101, 0b10010110,
372
+ 0b10011001, 0b10011010, 0b10011100, 0b10100011, 0b10100101, 0b10100110,
373
+ 0b10101001, 0b10101010, 0b10101100, 0b10110001, 0b10110010, 0b10110100,
374
+ 0b10111000, 0b11000011, 0b11000101, 0b11000110, 0b11001001, 0b11001010,
375
+ 0b11001100, 0b11010001, 0b11010010, 0b11010100, 0b11011000, 0b11100001,
376
+ 0b11100010, 0b11100100, 0b11101000, 0b11110000};
377
+
378
+ #define TAG(i) \
379
+ ((kAllExternalPointerTypeTags[i] << kExternalPointerTagShift) | \
380
+ kExternalPointerMarkBit)
381
+
382
+ // clang-format off
383
+
384
+ // When adding new tags, please ensure that the code using these tags is
385
+ // "substitution-safe", i.e. still operate safely if external pointers of the
386
+ // same type are swapped by an attacker. See comment above for more details.
387
+
388
+ // Shared external pointers are owned by the shared Isolate and stored in the
389
+ // shared external pointer table associated with that Isolate, where they can
390
+ // be accessed from multiple threads at the same time. The objects referenced
391
+ // in this way must therefore always be thread-safe.
392
+ #define SHARED_EXTERNAL_POINTER_TAGS(V) \
393
+ V(kFirstSharedTag, TAG(0)) \
394
+ V(kWaiterQueueNodeTag, TAG(0)) \
395
+ V(kExternalStringResourceTag, TAG(1)) \
396
+ V(kExternalStringResourceDataTag, TAG(2)) \
397
+ V(kLastSharedTag, TAG(2))
398
+
399
+ // External pointers using these tags are kept in a per-Isolate external
400
+ // pointer table and can only be accessed when this Isolate is active.
401
+ #define PER_ISOLATE_EXTERNAL_POINTER_TAGS(V) \
402
+ V(kForeignForeignAddressTag, TAG(10)) \
403
+ V(kNativeContextMicrotaskQueueTag, TAG(11)) \
404
+ V(kEmbedderDataSlotPayloadTag, TAG(12)) \
405
+ /* This tag essentially stands for a `void*` pointer in the V8 API, and */ \
406
+ /* it is the Embedder's responsibility to ensure type safety (against */ \
407
+ /* substitution) and lifetime validity of these objects. */ \
408
+ V(kExternalObjectValueTag, TAG(13)) \
409
+ V(kCallHandlerInfoCallbackTag, TAG(14)) \
410
+ V(kAccessorInfoGetterTag, TAG(15)) \
411
+ V(kAccessorInfoSetterTag, TAG(16)) \
412
+ V(kWasmInternalFunctionCallTargetTag, TAG(17)) \
413
+ V(kWasmTypeInfoNativeTypeTag, TAG(18)) \
414
+ V(kWasmExportedFunctionDataSignatureTag, TAG(19)) \
415
+ V(kWasmContinuationJmpbufTag, TAG(20)) \
416
+ V(kArrayBufferExtensionTag, TAG(21))
417
+
418
+ // All external pointer tags.
419
+ #define ALL_EXTERNAL_POINTER_TAGS(V) \
420
+ SHARED_EXTERNAL_POINTER_TAGS(V) \
421
+ PER_ISOLATE_EXTERNAL_POINTER_TAGS(V)
422
+
423
+ #define EXTERNAL_POINTER_TAG_ENUM(Name, Tag) Name = Tag,
424
+ #define MAKE_TAG(HasMarkBit, TypeTag) \
425
+ ((static_cast<uint64_t>(TypeTag) << kExternalPointerTagShift) | \
426
+ (HasMarkBit ? kExternalPointerMarkBit : 0))
427
+ enum ExternalPointerTag : uint64_t {
428
+ // Empty tag value. Mostly used as placeholder.
429
+ kExternalPointerNullTag = MAKE_TAG(0, 0b00000000),
430
+ // External pointer tag that will match any external pointer. Use with care!
431
+ kAnyExternalPointerTag = MAKE_TAG(1, 0b11111111),
432
+ // The free entry tag has all type bits set so every type check with a
433
+ // different type fails. It also doesn't have the mark bit set as free
434
+ // entries are (by definition) not alive.
435
+ kExternalPointerFreeEntryTag = MAKE_TAG(0, 0b11111111),
436
+ // Evacuation entries are used during external pointer table compaction.
437
+ kExternalPointerEvacuationEntryTag = MAKE_TAG(1, 0b11100111),
438
+
439
+ ALL_EXTERNAL_POINTER_TAGS(EXTERNAL_POINTER_TAG_ENUM)
440
+ };
441
+
442
+ #undef MAKE_TAG
443
+ #undef TAG
444
+ #undef EXTERNAL_POINTER_TAG_ENUM
445
+
446
+ // clang-format on
447
+
448
+ // True if the external pointer must be accessed from the shared isolate's
449
+ // external pointer table.
450
+ V8_INLINE static constexpr bool IsSharedExternalPointerType(
451
+ ExternalPointerTag tag) {
452
+ return tag >= kFirstSharedTag && tag <= kLastSharedTag;
453
+ }
454
+
455
+ // Sanity checks.
456
+ #define CHECK_SHARED_EXTERNAL_POINTER_TAGS(Tag, ...) \
457
+ static_assert(IsSharedExternalPointerType(Tag));
458
+ #define CHECK_NON_SHARED_EXTERNAL_POINTER_TAGS(Tag, ...) \
459
+ static_assert(!IsSharedExternalPointerType(Tag));
460
+
461
+ SHARED_EXTERNAL_POINTER_TAGS(CHECK_SHARED_EXTERNAL_POINTER_TAGS)
462
+ PER_ISOLATE_EXTERNAL_POINTER_TAGS(CHECK_NON_SHARED_EXTERNAL_POINTER_TAGS)
463
+
464
+ #undef CHECK_NON_SHARED_EXTERNAL_POINTER_TAGS
465
+ #undef CHECK_SHARED_EXTERNAL_POINTER_TAGS
466
+
467
+ #undef SHARED_EXTERNAL_POINTER_TAGS
468
+ #undef EXTERNAL_POINTER_TAGS
469
+
470
+ // {obj} must be the raw tagged pointer representation of a HeapObject
471
+ // that's guaranteed to never be in ReadOnlySpace.
472
+ V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj);
473
+
474
+ // Returns if we need to throw when an error occurs. This infers the language
475
+ // mode based on the current context and the closure. This returns true if the
476
+ // language mode is strict.
477
+ V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate);
478
+ /**
479
+ * This class exports constants and functionality from within v8 that
480
+ * is necessary to implement inline functions in the v8 api. Don't
481
+ * depend on functions and constants defined here.
482
+ */
483
+ class Internals {
484
+ #ifdef V8_MAP_PACKING
485
+ V8_INLINE static constexpr internal::Address UnpackMapWord(
486
+ internal::Address mapword) {
487
+ // TODO(wenyuzhao): Clear header metadata.
488
+ return mapword ^ kMapWordXorMask;
489
+ }
490
+ #endif
491
+
492
+ public:
493
+ // These values match non-compiler-dependent values defined within
494
+ // the implementation of v8.
495
+ static const int kHeapObjectMapOffset = 0;
496
+ static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size;
497
+ static const int kStringResourceOffset =
498
+ 1 * kApiTaggedSize + 2 * kApiInt32Size;
499
+
500
+ static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize;
501
+ static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
502
+ static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
503
+ static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize;
504
+ static const int kEmbedderDataSlotSize = kApiSystemPointerSize;
505
+ #ifdef V8_ENABLE_SANDBOX
506
+ static const int kEmbedderDataSlotExternalPointerOffset = kApiTaggedSize;
507
+ #else
508
+ static const int kEmbedderDataSlotExternalPointerOffset = 0;
509
+ #endif
510
+ static const int kNativeContextEmbedderDataOffset = 6 * kApiTaggedSize;
511
+ static const int kStringRepresentationAndEncodingMask = 0x0f;
512
+ static const int kStringEncodingMask = 0x8;
513
+ static const int kExternalTwoByteRepresentationTag = 0x02;
514
+ static const int kExternalOneByteRepresentationTag = 0x0a;
515
+
516
+ static const uint32_t kNumIsolateDataSlots = 4;
517
+ static const int kStackGuardSize = 7 * kApiSystemPointerSize;
518
+ static const int kBuiltinTier0EntryTableSize = 7 * kApiSystemPointerSize;
519
+ static const int kBuiltinTier0TableSize = 7 * kApiSystemPointerSize;
520
+
521
+ // ExternalPointerTable layout guarantees.
522
+ static const int kExternalPointerTableBufferOffset = 0;
523
+ static const int kExternalPointerTableSize = 4 * kApiSystemPointerSize;
524
+
525
+ // IsolateData layout guarantees.
526
+ static const int kIsolateCageBaseOffset = 0;
527
+ static const int kIsolateStackGuardOffset =
528
+ kIsolateCageBaseOffset + kApiSystemPointerSize;
529
+ static const int kVariousBooleanFlagsOffset =
530
+ kIsolateStackGuardOffset + kStackGuardSize;
531
+ static const int kBuiltinTier0EntryTableOffset =
532
+ kVariousBooleanFlagsOffset + 8;
533
+ static const int kBuiltinTier0TableOffset =
534
+ kBuiltinTier0EntryTableOffset + kBuiltinTier0EntryTableSize;
535
+ static const int kIsolateEmbedderDataOffset =
536
+ kBuiltinTier0TableOffset + kBuiltinTier0TableSize;
537
+ static const int kIsolateFastCCallCallerFpOffset =
538
+ kIsolateEmbedderDataOffset + kNumIsolateDataSlots * kApiSystemPointerSize;
539
+ static const int kIsolateFastCCallCallerPcOffset =
540
+ kIsolateFastCCallCallerFpOffset + kApiSystemPointerSize;
541
+ static const int kIsolateFastApiCallTargetOffset =
542
+ kIsolateFastCCallCallerPcOffset + kApiSystemPointerSize;
543
+ static const int kIsolateLongTaskStatsCounterOffset =
544
+ kIsolateFastApiCallTargetOffset + kApiSystemPointerSize;
545
+ #ifdef V8_COMPRESS_POINTERS
546
+ static const int kIsolateExternalPointerTableOffset =
547
+ kIsolateLongTaskStatsCounterOffset + kApiSizetSize;
548
+ static const int kIsolateSharedExternalPointerTableAddressOffset =
549
+ kIsolateExternalPointerTableOffset + kExternalPointerTableSize;
550
+ static const int kIsolateRootsOffset =
551
+ kIsolateSharedExternalPointerTableAddressOffset + kApiSystemPointerSize;
552
+ #else
553
+ static const int kIsolateRootsOffset =
554
+ kIsolateLongTaskStatsCounterOffset + kApiSizetSize;
555
+ #endif
556
+
557
+ static const int kUndefinedValueRootIndex = 4;
558
+ static const int kTheHoleValueRootIndex = 5;
559
+ static const int kNullValueRootIndex = 6;
560
+ static const int kTrueValueRootIndex = 7;
561
+ static const int kFalseValueRootIndex = 8;
562
+ static const int kEmptyStringRootIndex = 9;
563
+
564
+ static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize;
565
+ static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3;
566
+ static const int kNodeStateMask = 0x3;
567
+ static const int kNodeStateIsWeakValue = 2;
568
+
569
+ static const int kTracedNodeClassIdOffset = kApiSystemPointerSize;
570
+
571
+ static const int kFirstNonstringType = 0x80;
572
+ static const int kOddballType = 0x83;
573
+ static const int kForeignType = 0xcc;
574
+ static const int kJSSpecialApiObjectType = 0x410;
575
+ static const int kJSObjectType = 0x421;
576
+ static const int kFirstJSApiObjectType = 0x422;
577
+ static const int kLastJSApiObjectType = 0x80A;
578
+
579
+ static const int kUndefinedOddballKind = 5;
580
+ static const int kNullOddballKind = 3;
581
+
582
+ // Constants used by PropertyCallbackInfo to check if we should throw when an
583
+ // error occurs.
584
+ static const int kThrowOnError = 0;
585
+ static const int kDontThrow = 1;
586
+ static const int kInferShouldThrowMode = 2;
587
+
588
+ // Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an
589
+ // incremental GC once the external memory reaches this limit.
590
+ static constexpr int kExternalAllocationSoftLimit = 64 * 1024 * 1024;
591
+
592
+ #ifdef V8_MAP_PACKING
593
+ static const uintptr_t kMapWordMetadataMask = 0xffffULL << 48;
594
+ // The lowest two bits of mapwords are always `0b10`
595
+ static const uintptr_t kMapWordSignature = 0b10;
596
+ // XORing a (non-compressed) map with this mask ensures that the two
597
+ // low-order bits are 0b10. The 0 at the end makes this look like a Smi,
598
+ // although real Smis have all lower 32 bits unset. We only rely on these
599
+ // values passing as Smis in very few places.
600
+ static const int kMapWordXorMask = 0b11;
601
+ #endif
602
+
603
+ V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
604
+ V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
605
+ #ifdef V8_ENABLE_CHECKS
606
+ CheckInitializedImpl(isolate);
607
+ #endif
608
+ }
609
+
610
+ V8_INLINE static bool HasHeapObjectTag(const internal::Address value) {
611
+ return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
612
+ }
613
+
614
+ V8_INLINE static int SmiValue(const internal::Address value) {
615
+ return PlatformSmiTagging::SmiToInt(value);
616
+ }
617
+
618
+ V8_INLINE static constexpr internal::Address IntToSmi(int value) {
619
+ return internal::IntToSmi(value);
620
+ }
621
+
622
+ V8_INLINE static constexpr bool IsValidSmi(intptr_t value) {
623
+ return PlatformSmiTagging::IsValidSmi(value);
624
+ }
625
+
626
+ V8_INLINE static int GetInstanceType(const internal::Address obj) {
627
+ typedef internal::Address A;
628
+ A map = ReadTaggedPointerField(obj, kHeapObjectMapOffset);
629
+ #ifdef V8_MAP_PACKING
630
+ map = UnpackMapWord(map);
631
+ #endif
632
+ return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset);
633
+ }
634
+
635
+ V8_INLINE static int GetOddballKind(const internal::Address obj) {
636
+ return SmiValue(ReadTaggedSignedField(obj, kOddballKindOffset));
637
+ }
638
+
639
+ V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
640
+ int representation = (instance_type & kStringRepresentationAndEncodingMask);
641
+ return representation == kExternalTwoByteRepresentationTag;
642
+ }
643
+
644
+ V8_INLINE static constexpr bool CanHaveInternalField(int instance_type) {
645
+ static_assert(kJSObjectType + 1 == kFirstJSApiObjectType);
646
+ static_assert(kJSObjectType < kLastJSApiObjectType);
647
+ static_assert(kFirstJSApiObjectType < kLastJSApiObjectType);
648
+ // Check for IsJSObject() || IsJSSpecialApiObject() || IsJSApiObject()
649
+ return instance_type == kJSSpecialApiObjectType ||
650
+ // inlined version of base::IsInRange
651
+ (static_cast<unsigned>(static_cast<unsigned>(instance_type) -
652
+ static_cast<unsigned>(kJSObjectType)) <=
653
+ static_cast<unsigned>(kLastJSApiObjectType - kJSObjectType));
654
+ }
655
+
656
+ V8_INLINE static uint8_t GetNodeFlag(internal::Address* obj, int shift) {
657
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
658
+ return *addr & static_cast<uint8_t>(1U << shift);
659
+ }
660
+
661
+ V8_INLINE static void UpdateNodeFlag(internal::Address* obj, bool value,
662
+ int shift) {
663
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
664
+ uint8_t mask = static_cast<uint8_t>(1U << shift);
665
+ *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
666
+ }
667
+
668
+ V8_INLINE static uint8_t GetNodeState(internal::Address* obj) {
669
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
670
+ return *addr & kNodeStateMask;
671
+ }
672
+
673
+ V8_INLINE static void UpdateNodeState(internal::Address* obj, uint8_t value) {
674
+ uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
675
+ *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
676
+ }
677
+
678
+ V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot,
679
+ void* data) {
680
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
681
+ kIsolateEmbedderDataOffset +
682
+ slot * kApiSystemPointerSize;
683
+ *reinterpret_cast<void**>(addr) = data;
684
+ }
685
+
686
+ V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
687
+ uint32_t slot) {
688
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
689
+ kIsolateEmbedderDataOffset +
690
+ slot * kApiSystemPointerSize;
691
+ return *reinterpret_cast<void* const*>(addr);
692
+ }
693
+
694
+ V8_INLINE static void IncrementLongTasksStatsCounter(v8::Isolate* isolate) {
695
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
696
+ kIsolateLongTaskStatsCounterOffset;
697
+ ++(*reinterpret_cast<size_t*>(addr));
698
+ }
699
+
700
+ V8_INLINE static internal::Address* GetRoot(v8::Isolate* isolate, int index) {
701
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
702
+ kIsolateRootsOffset +
703
+ index * kApiSystemPointerSize;
704
+ return reinterpret_cast<internal::Address*>(addr);
705
+ }
706
+
707
+ #ifdef V8_ENABLE_SANDBOX
708
+ V8_INLINE static internal::Address* GetExternalPointerTableBase(
709
+ v8::Isolate* isolate) {
710
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
711
+ kIsolateExternalPointerTableOffset +
712
+ kExternalPointerTableBufferOffset;
713
+ return *reinterpret_cast<internal::Address**>(addr);
714
+ }
715
+
716
+ V8_INLINE static internal::Address* GetSharedExternalPointerTableBase(
717
+ v8::Isolate* isolate) {
718
+ internal::Address addr = reinterpret_cast<internal::Address>(isolate) +
719
+ kIsolateSharedExternalPointerTableAddressOffset;
720
+ addr = *reinterpret_cast<internal::Address*>(addr);
721
+ addr += kExternalPointerTableBufferOffset;
722
+ return *reinterpret_cast<internal::Address**>(addr);
723
+ }
724
+ #endif
725
+
726
+ template <typename T>
727
+ V8_INLINE static T ReadRawField(internal::Address heap_object_ptr,
728
+ int offset) {
729
+ internal::Address addr = heap_object_ptr + offset - kHeapObjectTag;
730
+ #ifdef V8_COMPRESS_POINTERS
731
+ if (sizeof(T) > kApiTaggedSize) {
732
+ // TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
733
+ // fields (external pointers, doubles and BigInt data) are only
734
+ // kTaggedSize aligned so we have to use unaligned pointer friendly way of
735
+ // accessing them in order to avoid undefined behavior in C++ code.
736
+ T r;
737
+ memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T));
738
+ return r;
739
+ }
740
+ #endif
741
+ return *reinterpret_cast<const T*>(addr);
742
+ }
743
+
744
+ V8_INLINE static internal::Address ReadTaggedPointerField(
745
+ internal::Address heap_object_ptr, int offset) {
746
+ #ifdef V8_COMPRESS_POINTERS
747
+ uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
748
+ internal::Address base =
749
+ GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
750
+ return base + static_cast<internal::Address>(static_cast<uintptr_t>(value));
751
+ #else
752
+ return ReadRawField<internal::Address>(heap_object_ptr, offset);
753
+ #endif
754
+ }
755
+
756
+ V8_INLINE static internal::Address ReadTaggedSignedField(
757
+ internal::Address heap_object_ptr, int offset) {
758
+ #ifdef V8_COMPRESS_POINTERS
759
+ uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
760
+ return static_cast<internal::Address>(static_cast<uintptr_t>(value));
761
+ #else
762
+ return ReadRawField<internal::Address>(heap_object_ptr, offset);
763
+ #endif
764
+ }
765
+
766
+ V8_INLINE static v8::Isolate* GetIsolateForSandbox(internal::Address obj) {
767
+ #ifdef V8_ENABLE_SANDBOX
768
+ return reinterpret_cast<v8::Isolate*>(
769
+ internal::IsolateFromNeverReadOnlySpaceObject(obj));
770
+ #else
771
+ // Not used in non-sandbox mode.
772
+ return nullptr;
773
+ #endif
774
+ }
775
+
776
+ template <ExternalPointerTag tag>
777
+ V8_INLINE static internal::Address ReadExternalPointerField(
778
+ v8::Isolate* isolate, internal::Address heap_object_ptr, int offset) {
779
+ #ifdef V8_ENABLE_SANDBOX
780
+ static_assert(tag != kExternalPointerNullTag);
781
+ // See src/sandbox/external-pointer-table-inl.h. Logic duplicated here so
782
+ // it can be inlined and doesn't require an additional call.
783
+ internal::Address* table = IsSharedExternalPointerType(tag)
784
+ ? GetSharedExternalPointerTableBase(isolate)
785
+ : GetExternalPointerTableBase(isolate);
786
+ internal::ExternalPointerHandle handle =
787
+ ReadRawField<ExternalPointerHandle>(heap_object_ptr, offset);
788
+ uint32_t index = handle >> kExternalPointerIndexShift;
789
+ std::atomic<internal::Address>* ptr =
790
+ reinterpret_cast<std::atomic<internal::Address>*>(&table[index]);
791
+ internal::Address entry =
792
+ std::atomic_load_explicit(ptr, std::memory_order_relaxed);
793
+ return entry & ~tag;
794
+ #else
795
+ return ReadRawField<Address>(heap_object_ptr, offset);
796
+ #endif // V8_ENABLE_SANDBOX
797
+ }
798
+
799
+ #ifdef V8_COMPRESS_POINTERS
800
+ V8_INLINE static internal::Address GetPtrComprCageBaseFromOnHeapAddress(
801
+ internal::Address addr) {
802
+ return addr & -static_cast<intptr_t>(kPtrComprCageBaseAlignment);
803
+ }
804
+
805
+ V8_INLINE static internal::Address DecompressTaggedAnyField(
806
+ internal::Address heap_object_ptr, uint32_t value) {
807
+ internal::Address base =
808
+ GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
809
+ return base + static_cast<internal::Address>(static_cast<uintptr_t>(value));
810
+ }
811
+
812
+ #endif // V8_COMPRESS_POINTERS
813
+ };
814
+
815
+ // Only perform cast check for types derived from v8::Data since
816
+ // other types do not implement the Cast method.
817
+ template <bool PerformCheck>
818
+ struct CastCheck {
819
+ template <class T>
820
+ static void Perform(T* data);
821
+ };
822
+
823
+ template <>
824
+ template <class T>
825
+ void CastCheck<true>::Perform(T* data) {
826
+ T::Cast(data);
827
+ }
828
+
829
+ template <>
830
+ template <class T>
831
+ void CastCheck<false>::Perform(T* data) {}
832
+
833
+ template <class T>
834
+ V8_INLINE void PerformCastCheck(T* data) {
835
+ CastCheck<std::is_base_of<Data, T>::value &&
836
+ !std::is_same<Data, std::remove_cv_t<T>>::value>::Perform(data);
837
+ }
838
+
839
+ // A base class for backing stores, which is needed due to vagaries of
840
+ // how static casts work with std::shared_ptr.
841
+ class BackingStoreBase {};
842
+
843
+ // The maximum value in enum GarbageCollectionReason, defined in heap.h.
844
+ // This is needed for histograms sampling garbage collection reasons.
845
+ constexpr int kGarbageCollectionReasonMaxValue = 27;
846
+
847
+ } // namespace internal
848
+
849
+ } // namespace v8
850
+
851
+ #endif // INCLUDE_V8_INTERNAL_H_