Loading...
Searching...
No Matches
v8-internal.h
Go to the documentation of this file.
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 <compare>
14#include <concepts>
15#include <iterator>
16#include <limits>
17#include <memory>
18#include <optional>
19#include <type_traits>
20
21#include "v8config.h" // NOLINT(build/include_directory)
22
23namespace v8 {
24
25class Array;
26class Context;
27class Data;
28class Isolate;
29
30namespace internal {
31
32class Heap;
33class LocalHeap;
34class Isolate;
35class IsolateGroup;
36class LocalIsolate;
37
38typedef uintptr_t Address;
39static constexpr Address kNullAddress = 0;
40
41constexpr int KB = 1024;
42constexpr int MB = KB * 1024;
43constexpr int GB = MB * 1024;
44#ifdef V8_TARGET_ARCH_X64
45constexpr size_t TB = size_t{GB} * 1024;
46#endif
47
51const int kApiSystemPointerSize = sizeof(void*);
52const int kApiDoubleSize = sizeof(double);
53const int kApiInt32Size = sizeof(int32_t);
54const int kApiInt64Size = sizeof(int64_t);
55const int kApiSizetSize = sizeof(size_t);
56
57// Tag information for HeapObject.
58const int kHeapObjectTag = 1;
59const int kWeakHeapObjectTag = 3;
60const int kHeapObjectTagSize = 2;
61const intptr_t kHeapObjectTagMask = (1 << kHeapObjectTagSize) - 1;
63
64// Tag information for fowarding pointers stored in object headers.
65// 0b00 at the lowest 2 bits in the header indicates that the map word is a
66// forwarding pointer.
67const int kForwardingTag = 0;
68const int kForwardingTagSize = 2;
69const intptr_t kForwardingTagMask = (1 << kForwardingTagSize) - 1;
70
71// Tag information for Smi.
72const int kSmiTag = 0;
73const int kSmiTagSize = 1;
74const intptr_t kSmiTagMask = (1 << kSmiTagSize) - 1;
75
76template <size_t tagged_ptr_size>
78
79constexpr intptr_t kIntptrAllBitsSet = intptr_t{-1};
80constexpr uintptr_t kUintptrAllBitsSet =
81 static_cast<uintptr_t>(kIntptrAllBitsSet);
82
83// Smi constants for systems where tagged pointer is a 32-bit value.
84template <>
85struct SmiTagging<4> {
86 enum { kSmiShiftSize = 0, kSmiValueSize = 31 };
87
88 static constexpr intptr_t kSmiMinValue =
89 static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
90 static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
91
92 V8_INLINE static constexpr int SmiToInt(Address value) {
93 int shift_bits = kSmiTagSize + kSmiShiftSize;
94 // Truncate and shift down (requires >> to be sign extending).
95 return static_cast<int32_t>(static_cast<uint32_t>(value)) >> shift_bits;
96 }
97
98 template <class T, typename std::enable_if_t<std::is_integral_v<T> &&
99 std::is_signed_v<T>>* = nullptr>
100 V8_INLINE static constexpr bool IsValidSmi(T value) {
101 // Is value in range [kSmiMinValue, kSmiMaxValue].
102 // Use unsigned operations in order to avoid undefined behaviour in case of
103 // signed integer overflow.
104 return (static_cast<uintptr_t>(value) -
105 static_cast<uintptr_t>(kSmiMinValue)) <=
106 (static_cast<uintptr_t>(kSmiMaxValue) -
107 static_cast<uintptr_t>(kSmiMinValue));
108 }
109
110 template <class T,
111 typename std::enable_if_t<std::is_integral_v<T> &&
112 std::is_unsigned_v<T>>* = nullptr>
113 V8_INLINE static constexpr bool IsValidSmi(T value) {
114 static_assert(kSmiMaxValue <= std::numeric_limits<uintptr_t>::max());
115 return value <= static_cast<uintptr_t>(kSmiMaxValue);
116 }
117
118 // Same as the `intptr_t` version but works with int64_t on 32-bit builds
119 // without slowing down anything else.
120 V8_INLINE static constexpr bool IsValidSmi(int64_t value) {
121 return (static_cast<uint64_t>(value) -
122 static_cast<uint64_t>(kSmiMinValue)) <=
123 (static_cast<uint64_t>(kSmiMaxValue) -
124 static_cast<uint64_t>(kSmiMinValue));
125 }
126
127 V8_INLINE static constexpr bool IsValidSmi(uint64_t value) {
128 static_assert(kSmiMaxValue <= std::numeric_limits<uint64_t>::max());
129 return value <= static_cast<uint64_t>(kSmiMaxValue);
130 }
131};
132
133// Smi constants for systems where tagged pointer is a 64-bit value.
134template <>
135struct SmiTagging<8> {
136 enum { kSmiShiftSize = 31, kSmiValueSize = 32 };
137
138 static constexpr intptr_t kSmiMinValue =
139 static_cast<intptr_t>(kUintptrAllBitsSet << (kSmiValueSize - 1));
140 static constexpr intptr_t kSmiMaxValue = -(kSmiMinValue + 1);
141
142 V8_INLINE static constexpr int SmiToInt(Address value) {
143 int shift_bits = kSmiTagSize + kSmiShiftSize;
144 // Shift down and throw away top 32 bits.
145 return static_cast<int>(static_cast<intptr_t>(value) >> shift_bits);
146 }
147
148 template <class T, typename std::enable_if_t<std::is_integral_v<T> &&
149 std::is_signed_v<T>>* = nullptr>
150 V8_INLINE static constexpr bool IsValidSmi(T value) {
151 // To be representable as a long smi, the value must be a 32-bit integer.
152 return std::numeric_limits<int32_t>::min() <= value &&
153 value <= std::numeric_limits<int32_t>::max();
154 }
155
156 template <class T,
157 typename std::enable_if_t<std::is_integral_v<T> &&
158 std::is_unsigned_v<T>>* = nullptr>
159 V8_INLINE static constexpr bool IsValidSmi(T value) {
160 return value <= std::numeric_limits<int32_t>::max();
161 }
162};
163
164#ifdef V8_COMPRESS_POINTERS
165// See v8:7703 or src/common/ptr-compr-inl.h for details about pointer
166// compression.
167constexpr size_t kPtrComprCageReservationSize = size_t{1} << 32;
168constexpr size_t kPtrComprCageBaseAlignment = size_t{1} << 32;
169
170static_assert(
172 "Pointer compression can be enabled only for 64-bit architectures");
173const int kApiTaggedSize = kApiInt32Size;
174#else
176#endif
177
180}
181
182#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
183using PlatformSmiTagging = SmiTagging<kApiInt32Size>;
184#else
186#endif
187
188// TODO(ishell): Consinder adding kSmiShiftBits = kSmiShiftSize + kSmiTagSize
189// since it's used much more often than the inividual constants.
190const int kSmiShiftSize = PlatformSmiTagging::kSmiShiftSize;
191const int kSmiValueSize = PlatformSmiTagging::kSmiValueSize;
192const int kSmiMinValue = static_cast<int>(PlatformSmiTagging::kSmiMinValue);
193const int kSmiMaxValue = static_cast<int>(PlatformSmiTagging::kSmiMaxValue);
194constexpr bool SmiValuesAre31Bits() { return kSmiValueSize == 31; }
195constexpr bool SmiValuesAre32Bits() { return kSmiValueSize == 32; }
196constexpr bool Is64() { return kApiSystemPointerSize == sizeof(int64_t); }
197
198V8_INLINE static constexpr Address IntToSmi(int value) {
199 return (static_cast<Address>(value) << (kSmiTagSize + kSmiShiftSize)) |
200 kSmiTag;
201}
202
203/*
204 * Sandbox related types, constants, and functions.
205 */
206constexpr bool SandboxIsEnabled() {
207#ifdef V8_ENABLE_SANDBOX
208 return true;
209#else
210 return false;
211#endif
212}
213
214// SandboxedPointers are guaranteed to point into the sandbox. This is achieved
215// for example by storing them as offset rather than as raw pointers.
217
218#ifdef V8_ENABLE_SANDBOX
219
220// Size of the sandbox, excluding the guard regions surrounding it.
221#if defined(V8_TARGET_OS_ANDROID)
222// On Android, most 64-bit devices seem to be configured with only 39 bits of
223// virtual address space for userspace. As such, limit the sandbox to 128GB (a
224// quarter of the total available address space).
225constexpr size_t kSandboxSizeLog2 = 37; // 128 GB
226#elif defined(V8_TARGET_OS_IOS)
227// On iOS, we only get 64 GB of usable virtual address space even with the
228// "jumbo" extended virtual addressing entitlement. Limit the sandbox size to
229// 16 GB so that the base address + size for the emulated virtual address space
230// lies within the 64 GB total virtual address space.
231constexpr size_t kSandboxSizeLog2 = 34; // 16 GB
232#else
233// Everywhere else use a 1TB sandbox.
234constexpr size_t kSandboxSizeLog2 = 40; // 1 TB
235#endif // V8_TARGET_OS_ANDROID
236constexpr size_t kSandboxSize = 1ULL << kSandboxSizeLog2;
237
238// Required alignment of the sandbox. For simplicity, we require the
239// size of the guard regions to be a multiple of this, so that this specifies
240// the alignment of the sandbox including and excluding surrounding guard
241// regions. The alignment requirement is due to the pointer compression cage
242// being located at the start of the sandbox.
243constexpr size_t kSandboxAlignment = kPtrComprCageBaseAlignment;
244
245// Sandboxed pointers are stored inside the heap as offset from the sandbox
246// base shifted to the left. This way, it is guaranteed that the offset is
247// smaller than the sandbox size after shifting it to the right again. This
248// constant specifies the shift amount.
249constexpr uint64_t kSandboxedPointerShift = 64 - kSandboxSizeLog2;
250
251// Size of the guard regions surrounding the sandbox. This assumes a worst-case
252// scenario of a 32-bit unsigned index used to access an array of 64-bit values
253// with an additional 4GB (compressed pointer) offset. In particular, accesses
254// to TypedArrays are effectively computed as
255// `entry_pointer = array->base + array->offset + index * array->element_size`.
256// See also https://crbug.com/40070746 for more details.
257constexpr size_t kSandboxGuardRegionSize = 32ULL * GB + 4ULL * GB;
258
259static_assert((kSandboxGuardRegionSize % kSandboxAlignment) == 0,
260 "The size of the guard regions around the sandbox must be a "
261 "multiple of its required alignment.");
262
263// On OSes where reserving virtual memory is too expensive to reserve the
264// entire address space backing the sandbox, notably Windows pre 8.1, we create
265// a partially reserved sandbox that doesn't actually reserve most of the
266// memory, and so doesn't have the desired security properties as unrelated
267// memory allocations could end up inside of it, but which still ensures that
268// objects that should be located inside the sandbox are allocated within
269// kSandboxSize bytes from the start of the sandbox. The minimum size of the
270// region that is actually reserved for such a sandbox is specified by this
271// constant and should be big enough to contain the pointer compression cage as
272// well as the ArrayBuffer partition.
273constexpr size_t kSandboxMinimumReservationSize = 8ULL * GB;
274
275static_assert(kSandboxMinimumReservationSize > kPtrComprCageReservationSize,
276 "The minimum reservation size for a sandbox must be larger than "
277 "the pointer compression cage contained within it.");
278
279// The maximum buffer size allowed inside the sandbox. This is mostly dependent
280// on the size of the guard regions around the sandbox: an attacker must not be
281// able to construct a buffer that appears larger than the guard regions and
282// thereby "reach out of" the sandbox.
283constexpr size_t kMaxSafeBufferSizeForSandbox = 32ULL * GB - 1;
284static_assert(kMaxSafeBufferSizeForSandbox <= kSandboxGuardRegionSize,
285 "The maximum allowed buffer size must not be larger than the "
286 "sandbox's guard regions");
287
288constexpr size_t kBoundedSizeShift = 29;
289static_assert(1ULL << (64 - kBoundedSizeShift) ==
290 kMaxSafeBufferSizeForSandbox + 1,
291 "The maximum size of a BoundedSize must be synchronized with the "
292 "kMaxSafeBufferSizeForSandbox");
293
294#endif // V8_ENABLE_SANDBOX
295
296#ifdef V8_COMPRESS_POINTERS
297
298#ifdef V8_TARGET_OS_ANDROID
299// The size of the virtual memory reservation for an external pointer table.
300// This determines the maximum number of entries in a table. Using a maximum
301// size allows omitting bounds checks on table accesses if the indices are
302// guaranteed (e.g. through shifting) to be below the maximum index. This
303// value must be a power of two.
304constexpr size_t kExternalPointerTableReservationSize = 256 * MB;
305
306// The external pointer table indices stored in HeapObjects as external
307// pointers are shifted to the left by this amount to guarantee that they are
308// smaller than the maximum table size even after the C++ compiler multiplies
309// them by 8 to be used as indexes into a table of 64 bit pointers.
310constexpr uint32_t kExternalPointerIndexShift = 7;
311#else
312constexpr size_t kExternalPointerTableReservationSize = 512 * MB;
313constexpr uint32_t kExternalPointerIndexShift = 6;
314#endif // V8_TARGET_OS_ANDROID
315
316// The maximum number of entries in an external pointer table.
317constexpr int kExternalPointerTableEntrySize = 8;
318constexpr int kExternalPointerTableEntrySizeLog2 = 3;
319constexpr size_t kMaxExternalPointers =
320 kExternalPointerTableReservationSize / kExternalPointerTableEntrySize;
321static_assert((1 << (32 - kExternalPointerIndexShift)) == kMaxExternalPointers,
322 "kExternalPointerTableReservationSize and "
323 "kExternalPointerIndexShift don't match");
324
325#else // !V8_COMPRESS_POINTERS
326
327// Needed for the V8.SandboxedExternalPointersCount histogram.
328constexpr size_t kMaxExternalPointers = 0;
329
330#endif // V8_COMPRESS_POINTERS
331
332constexpr uint64_t kExternalPointerMarkBit = 1ULL << 48;
333constexpr uint64_t kExternalPointerTagShift = 49;
334constexpr uint64_t kExternalPointerTagMask = 0x00fe000000000000ULL;
339constexpr uint64_t kExternalPointerTagAndMarkbitMask = 0x00ff000000000000ULL;
340constexpr uint64_t kExternalPointerPayloadMask = 0xff00ffffffffffffULL;
341
342// A ExternalPointerHandle represents a (opaque) reference to an external
343// pointer that can be stored inside the sandbox. A ExternalPointerHandle has
344// meaning only in combination with an (active) Isolate as it references an
345// external pointer stored in the currently active Isolate's
346// ExternalPointerTable. Internally, an ExternalPointerHandles is simply an
347// index into an ExternalPointerTable that is shifted to the left to guarantee
348// that it is smaller than the size of the table.
349using ExternalPointerHandle = uint32_t;
350
351// ExternalPointers point to objects located outside the sandbox. When the V8
352// sandbox is enabled, these are stored on heap as ExternalPointerHandles,
353// otherwise they are simply raw pointers.
354#ifdef V8_ENABLE_SANDBOX
356#else
358#endif
359
362
363// See `ExternalPointerHandle` for the main documentation. The difference to
364// `ExternalPointerHandle` is that the handle does not represent an arbitrary
365// external pointer but always refers to an object managed by `CppHeap`. The
366// handles are using in combination with a dedicated table for `CppHeap`
367// references.
368using CppHeapPointerHandle = uint32_t;
369
370// The actual pointer to objects located on the `CppHeap`. When pointer
371// compression is enabled these pointers are stored as `CppHeapPointerHandle`.
372// In non-compressed configurations the pointers are simply stored as raw
373// pointers.
374#ifdef V8_COMPRESS_POINTERS
376#else
378#endif
379
382
383constexpr uint64_t kCppHeapPointerMarkBit = 1ULL;
384constexpr uint64_t kCppHeapPointerTagShift = 1;
385constexpr uint64_t kCppHeapPointerPayloadShift = 16;
386
387#ifdef V8_COMPRESS_POINTERS
388// CppHeapPointers use a dedicated pointer table. These constants control the
389// size and layout of the table. See the corresponding constants for the
390// external pointer table for further details.
391constexpr size_t kCppHeapPointerTableReservationSize =
392 kExternalPointerTableReservationSize;
393constexpr uint32_t kCppHeapPointerIndexShift = kExternalPointerIndexShift;
394
395constexpr int kCppHeapPointerTableEntrySize = 8;
396constexpr int kCppHeapPointerTableEntrySizeLog2 = 3;
397constexpr size_t kMaxCppHeapPointers =
398 kCppHeapPointerTableReservationSize / kCppHeapPointerTableEntrySize;
399static_assert((1 << (32 - kCppHeapPointerIndexShift)) == kMaxCppHeapPointers,
400 "kCppHeapPointerTableReservationSize and "
401 "kCppHeapPointerIndexShift don't match");
402
403#else // !V8_COMPRESS_POINTERS
404
405// Needed for the V8.SandboxedCppHeapPointersCount histogram.
406constexpr size_t kMaxCppHeapPointers = 0;
407
408#endif // V8_COMPRESS_POINTERS
409
410// The number of tags reserved for embedder data stored in internal fields. The
411// value is picked arbitrarily, and is slightly larger than the number of tags
412// currently used in Chrome.
413#define V8_EMBEDDER_DATA_TAG_COUNT 15
414
415// The number of tags reserved for pointers stored in v8::External. The value is
416// picked arbitrarily, and is slightly larger than the number of tags currently
417// used in Chrome.
418#define V8_EXTERNAL_POINTER_TAG_COUNT 40
419
420// Generic tag range struct to represent ranges of type tags.
421//
422// When referencing external objects via pointer tables, type tags are
423// frequently necessary to guarantee type safety for the external objects. When
424// support for subtyping is necessary, range-based type checks are used in
425// which all subtypes of a given supertype use contiguous tags. This struct can
426// then be used to represent such a type range.
427//
428// As an example, consider the following type hierarchy:
429//
430// A F
431// / \
432// B E
433// / \
434// C D
435//
436// A potential type id assignment for range-based type checks is
437// {A: 0, B: 1, C: 2, D: 3, E: 4, F: 5}. With that, the type check for type A
438// would check for the range [A, E], while the check for B would check range
439// [B, D], and for F it would simply check [F, F].
440//
441// In addition, there is an option for performance tweaks: if the size of the
442// type range corresponding to a supertype is a power of two and starts at a
443// power of two (e.g. [0x100, 0x13f]), then the compiler can often optimize
444// the type check to use even fewer instructions (essentially replace a AND +
445// SUB with a single AND).
446//
447template <typename Tag>
448struct TagRange {
449 static_assert(std::is_enum_v<Tag> &&
450 std::is_same_v<std::underlying_type_t<Tag>, uint16_t>,
451 "Tag parameter must be an enum with base type uint16_t");
452
453 // Construct the inclusive tag range [first, last].
454 constexpr TagRange(Tag first, Tag last) : first(first), last(last) {}
455
456 // Construct a tag range consisting of a single tag.
457 //
458 // A single tag is always implicitly convertible to a tag range. This greatly
459 // increases readability as most of the time, the exact tag of a field is
460 // known and so no tag range needs to explicitly be created for it.
461 constexpr TagRange(Tag tag) // NOLINT(runtime/explicit)
462 : first(tag), last(tag) {}
463
464 // Construct an empty tag range.
465 constexpr TagRange() : TagRange(static_cast<Tag>(0)) {}
466
467 // A tag range is considered empty if it only contains the null tag.
468 constexpr bool IsEmpty() const { return first == 0 && last == 0; }
469
470 constexpr size_t Size() const {
471 if (IsEmpty()) {
472 return 0;
473 } else {
474 return last - first + 1;
475 }
476 }
477
478 constexpr bool Contains(Tag tag) const {
479 // Need to perform the math with uint32_t. Otherwise, the uint16_ts would
480 // be promoted to (signed) int, allowing the compiler to (wrongly) assume
481 // that an underflow cannot happen as that would be undefined behavior.
482 return static_cast<uint32_t>(tag) - first <=
483 static_cast<uint32_t>(last) - first;
484 }
485
486 constexpr bool Contains(TagRange tag_range) const {
487 return tag_range.first >= first && tag_range.last <= last;
488 }
489
490 constexpr bool operator==(const TagRange other) const {
491 return first == other.first && last == other.last;
492 }
493
494 constexpr size_t hash_value() const {
495 static_assert(std::is_same_v<std::underlying_type_t<Tag>, uint16_t>);
496 return (static_cast<size_t>(first) << 16) | last;
497 }
498
499 // Internally we represent tag ranges as closed ranges [first, last].
500 const Tag first;
501 const Tag last;
502};
503
504//
505// External Pointers.
506//
507// When the sandbox is enabled, external pointers are stored in an external
508// pointer table and are referenced from HeapObjects through an index (a
509// "handle"). When stored in the table, the pointers are tagged with per-type
510// tags to prevent type confusion attacks between different external objects.
511//
512// When loading an external pointer, a range of allowed tags can be specified.
513// This way, type hierarchies can be supported. The main requirement for that
514// is that all (transitive) child classes of a given parent class have type ids
515// in the same range, and that there are no unrelated types in that range. For
516// more details about how to assign type tags to types, see the TagRange class.
517//
518// The external pointer sandboxing mechanism ensures that every access to an
519// external pointer field will result in a valid pointer of the expected type
520// even in the presence of an attacker able to corrupt memory inside the
521// sandbox. However, if any data related to the external object is stored
522// inside the sandbox it may still be corrupted and so must be validated before
523// use or moved into the external object. Further, an attacker will always be
524// able to substitute different external pointers of the same type for each
525// other. Therefore, code using external pointers must be written in a
526// "substitution-safe" way, i.e. it must always be possible to substitute
527// external pointers of the same type without causing memory corruption outside
528// of the sandbox. Generally this is achieved by referencing any group of
529// related external objects through a single external pointer.
530//
531// Currently we use bit 62 for the marking bit which should always be unused as
532// it's part of the non-canonical address range. When Arm's top-byte ignore
533// (TBI) is enabled, this bit will be part of the ignored byte, and we assume
534// that the Embedder is not using this byte (really only this one bit) for any
535// other purpose. This bit also does not collide with the memory tagging
536// extension (MTE) which would use bits [56, 60).
537//
538// External pointer tables are also available even when the sandbox is off but
539// pointer compression is on. In that case, the mechanism can be used to ease
540// alignment requirements as it turns unaligned 64-bit raw pointers into
541// aligned 32-bit indices. To "opt-in" to the external pointer table mechanism
542// for this purpose, instead of using the ExternalPointer accessors one needs to
543// use ExternalPointerHandles directly and use them to access the pointers in an
544// ExternalPointerTable.
545//
546// The tag is currently in practice limited to 15 bits since it needs to fit
547// together with a marking bit into the unused parts of a pointer.
548enum ExternalPointerTag : uint16_t {
551
552 // When adding new tags, please ensure that the code using these tags is
553 // "substitution-safe", i.e. still operate safely if external pointers of the
554 // same type are swapped by an attacker. See comment above for more details.
555
556 // Shared external pointers are owned by the shared Isolate and stored in the
557 // shared external pointer table associated with that Isolate, where they can
558 // be accessed from multiple threads at the same time. The objects referenced
559 // in this way must therefore always be thread-safe.
565
566 // External pointers using these tags are kept in a per-Isolate external
567 // pointer table and can only be accessed when this Isolate is active.
569
570 // Placeholders for embedder data.
573
574 // Placeholders for pointers store in v8::External.
578 // This tag is used when a fast-api callback as a parameter of type
579 // `kPointer`. The V8 fast API is only able to use this generic tag, and is
580 // therefore not supposed to be used in Chrome.
586
587 // InterceptorInfo external pointers.
605
607
609
610 // Foreigns
613
623
624 // Managed
655 // External resources whose lifetime is tied to their entry in the external
656 // pointer table but which are not referenced via a Managed
659
663 // The tags are limited to 7 bits, so the last tag is 0x7f.
665};
666
668
685
686// True if the external pointer must be accessed from the shared isolate's
687// external pointer table.
688V8_INLINE static constexpr bool IsSharedExternalPointerType(
689 ExternalPointerTagRange tag_range) {
691}
692
693// True if the external pointer may live in a read-only object, in which case
694// the table entry will be in the shared read-only segment of the external
695// pointer table.
696V8_INLINE static constexpr bool IsMaybeReadOnlyExternalPointerType(
697 ExternalPointerTagRange tag_range) {
699}
700
701// True if the external pointer references an external object whose lifetime is
702// tied to the entry in the external pointer table.
703// In this case, the entry in the ExternalPointerTable always points to an
704// object derived from ExternalPointerTable::ManagedResource.
705V8_INLINE static constexpr bool IsManagedExternalPointerType(
706 ExternalPointerTagRange tag_range) {
708}
709
710// When an external poiner field can contain the null external pointer handle,
711// the type checking mechanism needs to also check for null.
712// TODO(saelo): this is mostly a temporary workaround to introduce range-based
713// type checks. In the future, we should either (a) change the type tagging
714// scheme so that null always passes or (b) (more likely) introduce dedicated
715// null entries for those tags that need them (similar to other well-known
716// empty value constants such as the empty fixed array).
717V8_INLINE static constexpr bool ExternalPointerCanBeEmpty(
718 ExternalPointerTagRange tag_range) {
719 return tag_range.Contains(kArrayBufferExtensionTag) ||
720 (tag_range.first <= kLastEmbedderDataTag &&
721 kFirstEmbedderDataTag <= tag_range.last) ||
723}
724
725// Indirect Pointers.
726//
727// When the sandbox is enabled, indirect pointers are used to reference
728// HeapObjects that live outside of the sandbox (but are still managed by V8's
729// garbage collector). When object A references an object B through an indirect
730// pointer, object A will contain a IndirectPointerHandle, i.e. a shifted
731// 32-bit index, which identifies an entry in a pointer table (either the
732// trusted pointer table for TrustedObjects, or the code pointer table if it is
733// a Code object). This table entry then contains the actual pointer to object
734// B. Further, object B owns this pointer table entry, and it is responsible
735// for updating the "self-pointer" in the entry when it is relocated in memory.
736// This way, in contrast to "normal" pointers, indirect pointers never need to
737// be tracked by the GC (i.e. there is no remembered set for them).
738// These pointers do not exist when the sandbox is disabled.
739
740// An IndirectPointerHandle represents a 32-bit index into a pointer table.
741using IndirectPointerHandle = uint32_t;
742
743// A null handle always references an entry that contains nullptr.
745
746// When the sandbox is enabled, indirect pointers are used to implement:
747// - TrustedPointers: an indirect pointer using the trusted pointer table (TPT)
748// and referencing a TrustedObject in one of the trusted heap spaces.
749// - CodePointers, an indirect pointer using the code pointer table (CPT) and
750// referencing a Code object together with its instruction stream.
751
752//
753// Trusted Pointers.
754//
755// A pointer to a TrustedObject.
756// When the sandbox is enabled, these are indirect pointers using the trusted
757// pointer table (TPT). They are used to reference trusted objects (located in
758// one of V8's trusted heap spaces, outside of the sandbox) from inside the
759// sandbox in a memory-safe way. When the sandbox is disabled, these are
760// regular tagged pointers.
762
763// The size of the virtual memory reservation for the trusted pointer table.
764// As with the external pointer table, a maximum table size in combination with
765// shifted indices allows omitting bounds checks.
767
768// The trusted pointer handles are stored shifted to the left by this amount
769// to guarantee that they are smaller than the maximum table size.
770constexpr uint32_t kTrustedPointerHandleShift = 9;
771
772// A null handle always references an entry that contains nullptr.
775
776// The maximum number of entries in an trusted pointer table.
779constexpr size_t kMaxTrustedPointers =
781static_assert((1 << (32 - kTrustedPointerHandleShift)) == kMaxTrustedPointers,
782 "kTrustedPointerTableReservationSize and "
783 "kTrustedPointerHandleShift don't match");
784
785//
786// Code Pointers.
787//
788// A pointer to a Code object.
789// Essentially a specialized version of a trusted pointer that (when the
790// sandbox is enabled) uses the code pointer table (CPT) instead of the TPT.
791// Each entry in the CPT contains both a pointer to a Code object as well as a
792// pointer to the Code's entrypoint. This allows calling/jumping into Code with
793// one fewer memory access (compared to the case where the entrypoint pointer
794// first needs to be loaded from the Code object). As such, a CodePointerHandle
795// can be used both to obtain the referenced Code object and to directly load
796// its entrypoint.
797//
798// When the sandbox is disabled, these are regular tagged pointers.
800
801// The size of the virtual memory reservation for the code pointer table.
802// As with the other tables, a maximum table size in combination with shifted
803// indices allows omitting bounds checks.
804constexpr size_t kCodePointerTableReservationSize = 128 * MB;
805
806// Code pointer handles are shifted by a different amount than indirect pointer
807// handles as the tables have a different maximum size.
808constexpr uint32_t kCodePointerHandleShift = 9;
809
810// A null handle always references an entry that contains nullptr.
812
813// It can sometimes be necessary to distinguish a code pointer handle from a
814// trusted pointer handle. A typical example would be a union trusted pointer
815// field that can refer to both Code objects and other trusted objects. To
816// support these use-cases, we use a simple marking scheme where some of the
817// low bits of a code pointer handle are set, while they will be unset on a
818// trusted pointer handle. This way, the correct table to resolve the handle
819// can be determined even in the absence of a type tag.
820constexpr uint32_t kCodePointerHandleMarker = 0x1;
821static_assert(kCodePointerHandleShift > 0);
822static_assert(kTrustedPointerHandleShift > 0);
823
824// The maximum number of entries in a code pointer table.
825constexpr int kCodePointerTableEntrySize = 16;
827constexpr size_t kMaxCodePointers =
829static_assert(
831 "kCodePointerTableReservationSize and kCodePointerHandleShift don't match");
832
835
836// Constants that can be used to mark places that should be modified once
837// certain types of objects are moved out of the sandbox and into trusted space.
843
844// {obj} must be the raw tagged pointer representation of a HeapObject
845// that's guaranteed to never be in ReadOnlySpace.
847 "Use GetCurrentIsolate() instead, which is guaranteed to return the same "
848 "isolate since https://crrev.com/c/6458560.")
850
851// Returns if we need to throw when an error occurs. This infers the language
852// mode based on the current context and the closure. This returns true if the
853// language mode is strict.
854V8_EXPORT bool ShouldThrowOnError(internal::Isolate* isolate);
855
856struct HandleScopeData final {
857 static constexpr uint32_t kSizeInBytes =
859
862 int level;
864
865 void Initialize() {
866 next = limit = nullptr;
867 sealed_level = level = 0;
868 }
869};
870
871static_assert(HandleScopeData::kSizeInBytes == sizeof(HandleScopeData));
872
879#ifdef V8_MAP_PACKING
880 V8_INLINE static constexpr Address UnpackMapWord(Address mapword) {
881 // TODO(wenyuzhao): Clear header metadata.
882 return mapword ^ kMapWordXorMask;
883 }
884#endif
885
886 public:
887 // These values match non-compiler-dependent values defined within
888 // the implementation of v8.
889 static const int kHeapObjectMapOffset = 0;
891 static const int kStringResourceOffset =
893
895 static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
896#ifdef V8_COMPRESS_POINTERS
899#else // !V8_COMPRESS_POINTERS
902#endif // !V8_COMPRESS_POINTERS
903 static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
906#ifdef V8_ENABLE_SANDBOX
908#else
910#endif
913 static const int kStringEncodingMask = 0x8;
914 static const int kExternalTwoByteRepresentationTag = 0x02;
915 static const int kExternalOneByteRepresentationTag = 0x0a;
916
917 // AccessorInfo::data and InterceptorInfo::data field.
919
920 static const uint32_t kNumIsolateDataSlots = 4;
922 static const int kNumberOfBooleanFlags = 6;
923 static const int kErrorMessageParamSize = 1;
924 static const int kTablesAlignmentPaddingSize = 1;
930 static const int kHandleScopeDataSize =
932
933 // ExternalPointerTable and TrustedPointerTable layout guarantees.
935 static const int kSegmentedTableSegmentPoolSize = 4;
936 static const int kExternalPointerTableSize =
938 kSegmentedTableSegmentPoolSize * sizeof(uint32_t);
939 static const int kTrustedPointerTableSize =
941 kSegmentedTableSegmentPoolSize * sizeof(uint32_t);
943
944 // IsolateData layout guarantees.
945 static const int kIsolateCageBaseOffset = 0;
946 static const int kIsolateStackGuardOffset =
948 static const int kVariousBooleanFlagsOffset =
950 static const int kErrorMessageParamOffset =
955 static const int kBuiltinTier0TableOffset =
957 static const int kNewAllocationInfoOffset =
959 static const int kOldAllocationInfoOffset =
961 static const int kLastYoungAllocationOffset =
963
980 static const int kIsolateEmbedderDataOffset =
982#ifdef V8_COMPRESS_POINTERS
983 static const int kIsolateExternalPointerTableOffset =
985 static const int kIsolateSharedExternalPointerTableAddressOffset =
986 kIsolateExternalPointerTableOffset + kExternalPointerTableSize;
987 static const int kIsolateCppHeapPointerTableOffset =
988 kIsolateSharedExternalPointerTableAddressOffset + kApiSystemPointerSize;
989#ifdef V8_ENABLE_SANDBOX
990 static const int kIsolateTrustedCageBaseOffset =
991 kIsolateCppHeapPointerTableOffset + kExternalPointerTableSize;
992 static const int kIsolateTrustedPointerTableOffset =
993 kIsolateTrustedCageBaseOffset + kApiSystemPointerSize;
994 static const int kIsolateSharedTrustedPointerTableAddressOffset =
995 kIsolateTrustedPointerTableOffset + kTrustedPointerTableSize;
996 static const int kIsolateTrustedPointerPublishingScopeOffset =
997 kIsolateSharedTrustedPointerTableAddressOffset + kApiSystemPointerSize;
998 static const int kIsolateCodePointerTableBaseAddressOffset =
999 kIsolateTrustedPointerPublishingScopeOffset + kApiSystemPointerSize;
1001 kIsolateCodePointerTableBaseAddressOffset + kApiSystemPointerSize;
1002#else
1004 kIsolateCppHeapPointerTableOffset + kExternalPointerTableSize;
1005#endif // V8_ENABLE_SANDBOX
1006#else
1009#endif // V8_COMPRESS_POINTERS
1010 static const int kJSDispatchTableOffset =
1016 static const int kIsolateRootsOffset =
1018
1019 // The mask for flags that might be encoded into kIsolateAndFlagsIndex
1020 // slot of v8::FunctionCallbackInfo<T> and v8::PropertyCallbackInfo<T>.
1021 // The least significant bit is excluded from the mask since it must
1022 // be zero to make the contents of the slot look like a Smi.
1026
1027 // Assert scopes
1028 static const int kDisallowGarbageCollectionAlign = alignof(uint32_t);
1029 static const int kDisallowGarbageCollectionSize = sizeof(uint32_t);
1030
1031#if V8_STATIC_ROOTS_BOOL
1032
1033// These constants are copied from static-roots.h and guarded by static asserts.
1034#define EXPORTED_STATIC_ROOTS_PTR_LIST(V) \
1035 V(UndefinedValue, 0x11) \
1036 V(NullValue, 0x2d) \
1037 V(TrueValue, 0x71) \
1038 V(FalseValue, 0x55) \
1039 V(EmptyString, 0x49) \
1040 /* The Hole moves around depending on build flags, so define it */ \
1041 /* separately inside StaticReadOnlyRoot using build macros */ \
1042 V(TheHoleValue, kBuildDependentTheHoleValue)
1043
1044 using Tagged_t = uint32_t;
1045 struct StaticReadOnlyRoot {
1046#ifdef V8_ENABLE_WEBASSEMBLY
1047 static constexpr Tagged_t kBuildDependentTheHoleValue = 0x20001;
1048#else
1049#ifdef V8_INTL_SUPPORT
1050 static constexpr Tagged_t kBuildDependentTheHoleValue = 0x6585;
1051#else
1052 static constexpr Tagged_t kBuildDependentTheHoleValue = 0x58d5;
1053#endif
1054#endif
1055
1056#define DEF_ROOT(name, value) static constexpr Tagged_t k##name = value;
1057 EXPORTED_STATIC_ROOTS_PTR_LIST(DEF_ROOT)
1058#undef DEF_ROOT
1059
1060 // Use 0 for kStringMapLowerBound since string maps are the first maps.
1061 static constexpr Tagged_t kStringMapLowerBound = 0;
1062 static constexpr Tagged_t kStringMapUpperBound = 0x425;
1063
1064#define PLUSONE(...) +1
1065 static constexpr size_t kNumberOfExportedStaticRoots =
1066 2 + EXPORTED_STATIC_ROOTS_PTR_LIST(PLUSONE);
1067#undef PLUSONE
1068 };
1069
1070#endif // V8_STATIC_ROOTS_BOOL
1071
1072 static const int kUndefinedValueRootIndex = 0;
1073 static const int kTheHoleValueRootIndex = 1;
1074 static const int kNullValueRootIndex = 2;
1075 static const int kTrueValueRootIndex = 3;
1076 static const int kFalseValueRootIndex = 4;
1077 static const int kEmptyStringRootIndex = 5;
1078
1080 static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3;
1081 static const int kNodeStateMask = 0x3;
1082 static const int kNodeStateIsWeakValue = 2;
1083
1084 static const int kFirstNonstringType = 0x80;
1085 static const int kOddballType = 0x83;
1086 static const int kForeignType = 0xcc;
1087 static const int kJSSpecialApiObjectType = 0x410;
1088 static const int kJSObjectType = 0x421;
1089 static const int kFirstJSApiObjectType = 0x422;
1090 static const int kLastJSApiObjectType = 0x80A;
1091 // Defines a range [kFirstEmbedderJSApiObjectType, kJSApiObjectTypesCount]
1092 // of JSApiObject instance type values that an embedder can use.
1093 static const int kFirstEmbedderJSApiObjectType = 0;
1096
1097 static const int kUndefinedOddballKind = 4;
1098 static const int kNullOddballKind = 3;
1099
1100 // Constants used by PropertyCallbackInfo to check if we should throw when an
1101 // error occurs.
1102 static const int kDontThrow = 0;
1103 static const int kThrowOnError = 1;
1104 static const int kInferShouldThrowMode = 2;
1105
1106 // Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an
1107 // incremental GC once the external memory reaches this limit.
1108 static constexpr size_t kExternalAllocationSoftLimit = 64 * 1024 * 1024;
1109
1110#ifdef V8_MAP_PACKING
1111 static const uintptr_t kMapWordMetadataMask = 0xffffULL << 48;
1112 // The lowest two bits of mapwords are always `0b10`
1113 static const uintptr_t kMapWordSignature = 0b10;
1114 // XORing a (non-compressed) map with this mask ensures that the two
1115 // low-order bits are 0b10. The 0 at the end makes this look like a Smi,
1116 // although real Smis have all lower 32 bits unset. We only rely on these
1117 // values passing as Smis in very few places.
1118 static const int kMapWordXorMask = 0b11;
1119#endif
1120
1123#ifdef V8_ENABLE_CHECKS
1124 CheckInitializedImpl(isolate);
1125#endif
1126 }
1127
1128 V8_INLINE static constexpr bool HasHeapObjectTag(Address value) {
1129 return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
1130 }
1131
1132 V8_INLINE static constexpr int SmiValue(Address value) {
1133 return PlatformSmiTagging::SmiToInt(value);
1134 }
1135
1136 V8_INLINE static constexpr Address AddressToSmi(Address value) {
1137 return (value << (kSmiTagSize + PlatformSmiTagging::kSmiShiftSize)) |
1138 kSmiTag;
1139 }
1140
1141 V8_INLINE static constexpr Address IntToSmi(int value) {
1142 return AddressToSmi(static_cast<Address>(value));
1143 }
1144
1145 template <typename T,
1146 typename std::enable_if_t<std::is_integral_v<T>>* = nullptr>
1147 V8_INLINE static constexpr Address IntegralToSmi(T value) {
1148 return AddressToSmi(static_cast<Address>(value));
1149 }
1150
1151 template <typename T,
1152 typename std::enable_if_t<std::is_integral_v<T>>* = nullptr>
1153 V8_INLINE static constexpr bool IsValidSmi(T value) {
1154 return PlatformSmiTagging::IsValidSmi(value);
1155 }
1156
1157 template <typename T,
1158 typename std::enable_if_t<std::is_integral_v<T>>* = nullptr>
1159 static constexpr std::optional<Address> TryIntegralToSmi(T value) {
1160 if (V8_LIKELY(PlatformSmiTagging::IsValidSmi(value))) {
1161 return {AddressToSmi(static_cast<Address>(value))};
1162 }
1163 return {};
1164 }
1165
1166#if V8_STATIC_ROOTS_BOOL
1167 V8_INLINE static bool is_identical(Address obj, Tagged_t constant) {
1168 return static_cast<Tagged_t>(obj) == constant;
1169 }
1170
1171 V8_INLINE static bool CheckInstanceMapRange(Address obj, Tagged_t first_map,
1172 Tagged_t last_map) {
1173 auto map = ReadRawField<Tagged_t>(obj, kHeapObjectMapOffset);
1174#ifdef V8_MAP_PACKING
1175 map = UnpackMapWord(map);
1176#endif
1177 return map >= first_map && map <= last_map;
1178 }
1179#endif
1180
1183#ifdef V8_MAP_PACKING
1184 map = UnpackMapWord(map);
1185#endif
1186 return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset);
1187 }
1188
1190 if (!HasHeapObjectTag(obj)) return kNullAddress;
1192#ifdef V8_MAP_PACKING
1193 map = UnpackMapWord(map);
1194#endif
1195 return map;
1196 }
1197
1200 }
1201
1202 V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
1203 int representation = (instance_type & kStringRepresentationAndEncodingMask);
1204 return representation == kExternalTwoByteRepresentationTag;
1205 }
1206
1207 V8_INLINE static constexpr bool CanHaveInternalField(int instance_type) {
1208 static_assert(kJSObjectType + 1 == kFirstJSApiObjectType);
1209 static_assert(kJSObjectType < kLastJSApiObjectType);
1211 // Check for IsJSObject() || IsJSSpecialApiObject() || IsJSApiObject()
1212 return instance_type == kJSSpecialApiObjectType ||
1213 // inlined version of base::IsInRange
1214 (static_cast<unsigned>(static_cast<unsigned>(instance_type) -
1215 static_cast<unsigned>(kJSObjectType)) <=
1216 static_cast<unsigned>(kLastJSApiObjectType - kJSObjectType));
1217 }
1218
1219 V8_INLINE static uint8_t GetNodeFlag(Address* obj, int shift) {
1220 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1221 return *addr & static_cast<uint8_t>(1U << shift);
1222 }
1223
1224 V8_INLINE static void UpdateNodeFlag(Address* obj, bool value, int shift) {
1225 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1226 uint8_t mask = static_cast<uint8_t>(1U << shift);
1227 *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
1228 }
1229
1230 V8_INLINE static uint8_t GetNodeState(Address* obj) {
1231 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1232 return *addr & kNodeStateMask;
1233 }
1234
1235 V8_INLINE static void UpdateNodeState(Address* obj, uint8_t value) {
1236 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1237 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
1238 }
1239
1240 V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot,
1241 void* data) {
1242 Address addr = reinterpret_cast<Address>(isolate) +
1244 *reinterpret_cast<void**>(addr) = data;
1245 }
1246
1247 V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
1248 uint32_t slot) {
1249 Address addr = reinterpret_cast<Address>(isolate) +
1251 return *reinterpret_cast<void* const*>(addr);
1252 }
1253
1255 Address addr =
1256 reinterpret_cast<Address>(isolate) + kIsolateHandleScopeDataOffset;
1257 return reinterpret_cast<HandleScopeData*>(addr);
1258 }
1259
1261 Address addr =
1262 reinterpret_cast<Address>(isolate) + kIsolateLongTaskStatsCounterOffset;
1263 ++(*reinterpret_cast<size_t*>(addr));
1264 }
1265
1266 V8_INLINE static Address* GetRootSlot(v8::Isolate* isolate, int index) {
1267 Address addr = reinterpret_cast<Address>(isolate) + kIsolateRootsOffset +
1268 index * kApiSystemPointerSize;
1269 return reinterpret_cast<Address*>(addr);
1270 }
1271
1272 V8_INLINE static Address GetRoot(v8::Isolate* isolate, int index) {
1273#if V8_STATIC_ROOTS_BOOL
1274 Address base = *reinterpret_cast<Address*>(
1275 reinterpret_cast<uintptr_t>(isolate) + kIsolateCageBaseOffset);
1276 switch (index) {
1277#define DECOMPRESS_ROOT(name, ...) \
1278 case k##name##RootIndex: \
1279 return base + StaticReadOnlyRoot::k##name;
1280 EXPORTED_STATIC_ROOTS_PTR_LIST(DECOMPRESS_ROOT)
1281#undef DECOMPRESS_ROOT
1282#undef EXPORTED_STATIC_ROOTS_PTR_LIST
1283 default:
1284 break;
1285 }
1286#endif // V8_STATIC_ROOTS_BOOL
1287 return *GetRootSlot(isolate, index);
1288 }
1289
1290#ifdef V8_ENABLE_SANDBOX
1291 V8_INLINE static Address* GetExternalPointerTableBase(v8::Isolate* isolate) {
1292 Address addr = reinterpret_cast<Address>(isolate) +
1293 kIsolateExternalPointerTableOffset +
1295 return *reinterpret_cast<Address**>(addr);
1296 }
1297
1298 V8_INLINE static Address* GetSharedExternalPointerTableBase(
1299 v8::Isolate* isolate) {
1300 Address addr = reinterpret_cast<Address>(isolate) +
1301 kIsolateSharedExternalPointerTableAddressOffset;
1302 addr = *reinterpret_cast<Address*>(addr);
1304 return *reinterpret_cast<Address**>(addr);
1305 }
1306#endif
1307
1308 template <typename T>
1309 V8_INLINE static T ReadRawField(Address heap_object_ptr, int offset) {
1310 Address addr = heap_object_ptr + offset - kHeapObjectTag;
1311#ifdef V8_COMPRESS_POINTERS
1312 if constexpr (sizeof(T) > kApiTaggedSize) {
1313 // TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
1314 // fields (external pointers, doubles and BigInt data) are only
1315 // kTaggedSize aligned so we have to use unaligned pointer friendly way of
1316 // accessing them in order to avoid undefined behavior in C++ code.
1317 T r;
1318 memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T));
1319 return r;
1320 }
1321#endif
1322 return *reinterpret_cast<const T*>(addr);
1323 }
1324
1326 int offset) {
1327#ifdef V8_COMPRESS_POINTERS
1328 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
1329 Address base = GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
1330 return base + static_cast<Address>(static_cast<uintptr_t>(value));
1331#else
1332 return ReadRawField<Address>(heap_object_ptr, offset);
1333#endif
1334 }
1335
1337 int offset) {
1338#ifdef V8_COMPRESS_POINTERS
1339 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
1340 return static_cast<Address>(static_cast<uintptr_t>(value));
1341#else
1342 return ReadRawField<Address>(heap_object_ptr, offset);
1343#endif
1344 }
1345
1346 // Returns v8::Isolate::Current(), but without needing to include the
1347 // v8-isolate.h header.
1349
1351#ifdef V8_ENABLE_SANDBOX
1352 return GetCurrentIsolate();
1353#else
1354 // Not used in non-sandbox mode.
1355 return nullptr;
1356#endif
1357 }
1358
1359 template <ExternalPointerTagRange tag_range>
1361 Address heap_object_ptr,
1362 int offset) {
1363#ifdef V8_ENABLE_SANDBOX
1364 static_assert(!tag_range.IsEmpty());
1365 // See src/sandbox/external-pointer-table.h. Logic duplicated here so
1366 // it can be inlined and doesn't require an additional call.
1367 Address* table = IsSharedExternalPointerType(tag_range)
1368 ? GetSharedExternalPointerTableBase(isolate)
1369 : GetExternalPointerTableBase(isolate);
1371 ReadRawField<ExternalPointerHandle>(heap_object_ptr, offset);
1372 uint32_t index = handle >> kExternalPointerIndexShift;
1373 std::atomic<Address>* ptr =
1374 reinterpret_cast<std::atomic<Address>*>(&table[index]);
1375 Address entry = std::atomic_load_explicit(ptr, std::memory_order_relaxed);
1376 ExternalPointerTag actual_tag = static_cast<ExternalPointerTag>(
1378 if (V8_LIKELY(tag_range.Contains(actual_tag))) {
1379 return entry & kExternalPointerPayloadMask;
1380 } else {
1381 return 0;
1382 }
1383 return entry;
1384#else
1385 return ReadRawField<Address>(heap_object_ptr, offset);
1386#endif // V8_ENABLE_SANDBOX
1387 }
1388
1390 v8::Isolate* isolate, Address heap_object_ptr, int offset,
1391 ExternalPointerTagRange tag_range) {
1392#ifdef V8_ENABLE_SANDBOX
1393 // See src/sandbox/external-pointer-table.h. Logic duplicated here so
1394 // it can be inlined and doesn't require an additional call.
1395 Address* table = IsSharedExternalPointerType(tag_range)
1396 ? GetSharedExternalPointerTableBase(isolate)
1397 : GetExternalPointerTableBase(isolate);
1399 ReadRawField<ExternalPointerHandle>(heap_object_ptr, offset);
1400 uint32_t index = handle >> kExternalPointerIndexShift;
1401 std::atomic<Address>* ptr =
1402 reinterpret_cast<std::atomic<Address>*>(&table[index]);
1403 Address entry = std::atomic_load_explicit(ptr, std::memory_order_relaxed);
1404 ExternalPointerTag actual_tag = static_cast<ExternalPointerTag>(
1406 if (V8_LIKELY(tag_range.Contains(actual_tag))) {
1407 return entry & kExternalPointerPayloadMask;
1408 } else {
1409 return 0;
1410 }
1411 return entry;
1412#else
1413 return ReadRawField<Address>(heap_object_ptr, offset);
1414#endif // V8_ENABLE_SANDBOX
1415 }
1416
1417#ifdef V8_COMPRESS_POINTERS
1418 V8_INLINE static Address GetPtrComprCageBaseFromOnHeapAddress(Address addr) {
1419 return addr & -static_cast<intptr_t>(kPtrComprCageBaseAlignment);
1420 }
1421
1422 V8_INLINE static uint32_t CompressTagged(Address value) {
1423 return static_cast<uint32_t>(value);
1424 }
1425
1426 V8_INLINE static Address DecompressTaggedField(Address heap_object_ptr,
1427 uint32_t value) {
1428 Address base = GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
1429 return base + static_cast<Address>(static_cast<uintptr_t>(value));
1430 }
1431
1432#endif // V8_COMPRESS_POINTERS
1433};
1434
1435// Only perform cast check for types derived from v8::Data since
1436// other types do not implement the Cast method.
1437template <bool PerformCheck>
1439 template <class T>
1440 static void Perform(T* data);
1441};
1442
1443template <>
1444template <class T>
1446 T::Cast(data);
1447}
1448
1449template <>
1450template <class T>
1452
1453template <class T>
1456 !std::is_same_v<Data, std::remove_cv_t<T>>>::Perform(data);
1457}
1458
1459// A base class for backing stores, which is needed due to vagaries of
1460// how static casts work with std::shared_ptr.
1462
1463// The maximum value in enum GarbageCollectionReason, defined in heap.h.
1464// This is needed for histograms sampling garbage collection reasons.
1466
1467// Base class for the address block allocator compatible with standard
1468// containers, which registers its allocated range as strong roots.
1470 public:
1471 Heap* heap() const { return heap_; }
1472
1473 constexpr bool operator==(const StrongRootAllocatorBase&) const = default;
1474
1475 protected:
1476 explicit StrongRootAllocatorBase(Heap* heap) : heap_(heap) {}
1477 explicit StrongRootAllocatorBase(LocalHeap* heap);
1480 explicit StrongRootAllocatorBase(LocalIsolate* isolate);
1481
1482 // Allocate/deallocate a range of n elements of type internal::Address.
1484 void deallocate_impl(Address* p, size_t n) noexcept;
1485
1486 private:
1487 Heap* heap_;
1488};
1489
1490// The general version of this template behaves just as std::allocator, with
1491// the exception that the constructor takes the isolate as parameter. Only
1492// specialized versions, e.g., internal::StrongRootAllocator<internal::Address>
1493// and internal::StrongRootAllocator<v8::Local<T>> register the allocated range
1494// as strong roots.
1495template <typename T>
1496class StrongRootAllocator : private std::allocator<T> {
1497 public:
1498 using value_type = T;
1499
1500 template <typename HeapOrIsolateT>
1501 explicit StrongRootAllocator(HeapOrIsolateT*) {}
1502 template <typename U>
1504
1505 using std::allocator<T>::allocate;
1506 using std::allocator<T>::deallocate;
1507};
1508
1509template <typename Iterator>
1510concept HasIteratorConcept = requires { typename Iterator::iterator_concept; };
1511
1512template <typename Iterator>
1514 requires { typename Iterator::iterator_category; };
1515
1516// Helper struct that contains an `iterator_concept` type alias only when either
1517// `Iterator` or `std::iterator_traits<Iterator>` do.
1518// Default: no alias.
1519template <typename Iterator>
1521// Use `Iterator::iterator_concept` if available.
1522template <HasIteratorConcept Iterator>
1524 using iterator_concept = typename Iterator::iterator_concept;
1525};
1526// Otherwise fall back to `std::iterator_traits<Iterator>` if possible.
1527template <typename Iterator>
1531 typename std::iterator_traits<Iterator>::iterator_concept;
1532};
1533
1534// A class of iterators that wrap some different iterator type.
1535// If specified, ElementType is the type of element accessed by the wrapper
1536// iterator; in this case, the actual reference and pointer types of Iterator
1537// must be convertible to ElementType& and ElementType*, respectively.
1538template <typename Iterator, typename ElementType = void>
1540 public:
1541 static_assert(
1542 std::is_void_v<ElementType> ||
1543 (std::is_convertible_v<typename std::iterator_traits<Iterator>::pointer,
1544 std::add_pointer_t<ElementType>> &&
1545 std::is_convertible_v<typename std::iterator_traits<Iterator>::reference,
1546 std::add_lvalue_reference_t<ElementType>>));
1547
1549 typename std::iterator_traits<Iterator>::difference_type;
1551 std::conditional_t<std::is_void_v<ElementType>,
1552 typename std::iterator_traits<Iterator>::value_type,
1553 ElementType>;
1554 using pointer =
1555 std::conditional_t<std::is_void_v<ElementType>,
1556 typename std::iterator_traits<Iterator>::pointer,
1557 std::add_pointer_t<ElementType>>;
1559 std::conditional_t<std::is_void_v<ElementType>,
1560 typename std::iterator_traits<Iterator>::reference,
1561 std::add_lvalue_reference_t<ElementType>>;
1563 typename std::iterator_traits<Iterator>::iterator_category;
1564
1565 constexpr WrappedIterator() noexcept = default;
1566 constexpr explicit WrappedIterator(Iterator it) noexcept : it_(it) {}
1567
1568 template <typename OtherIterator, typename OtherElementType>
1569 requires std::is_convertible_v<OtherIterator, Iterator>
1572 : it_(other.base()) {}
1573
1574 [[nodiscard]] constexpr reference operator*() const noexcept { return *it_; }
1575 [[nodiscard]] constexpr pointer operator->() const noexcept {
1576 if constexpr (std::is_pointer_v<Iterator>) {
1577 return it_;
1578 } else {
1579 return it_.operator->();
1580 }
1581 }
1582
1583 template <typename OtherIterator, typename OtherElementType>
1584 [[nodiscard]] constexpr bool operator==(
1586 const noexcept {
1587 return it_ == other.base();
1588 }
1589
1590 template <typename OtherIterator, typename OtherElementType>
1591 [[nodiscard]] constexpr auto operator<=>(
1593 const noexcept {
1594 if constexpr (std::three_way_comparable_with<Iterator, OtherIterator>) {
1595 return it_ <=> other.base();
1596 } else if constexpr (std::totally_ordered_with<Iterator, OtherIterator>) {
1597 if (it_ < other.base()) {
1598 return std::strong_ordering::less;
1599 }
1600 return (it_ > other.base()) ? std::strong_ordering::greater
1601 : std::strong_ordering::equal;
1602 } else {
1603 if (it_ < other.base()) {
1604 return std::partial_ordering::less;
1605 }
1606 if (other.base() < it_) {
1607 return std::partial_ordering::greater;
1608 }
1609 return (it_ == other.base()) ? std::partial_ordering::equivalent
1610 : std::partial_ordering::unordered;
1611 }
1612 }
1613
1614 constexpr WrappedIterator& operator++() noexcept {
1615 ++it_;
1616 return *this;
1617 }
1618 constexpr WrappedIterator operator++(int) noexcept {
1619 WrappedIterator result(*this);
1620 ++(*this);
1621 return result;
1622 }
1623
1624 constexpr WrappedIterator& operator--() noexcept {
1625 --it_;
1626 return *this;
1627 }
1628 constexpr WrappedIterator operator--(int) noexcept {
1629 WrappedIterator result(*this);
1630 --(*this);
1631 return result;
1632 }
1633 [[nodiscard]] constexpr WrappedIterator operator+(
1634 difference_type n) const noexcept {
1635 WrappedIterator result(*this);
1636 result += n;
1637 return result;
1638 }
1639 [[nodiscard]] friend constexpr WrappedIterator operator+(
1640 difference_type n, const WrappedIterator& x) noexcept {
1641 return x + n;
1642 }
1644 it_ += n;
1645 return *this;
1646 }
1647 [[nodiscard]] constexpr WrappedIterator operator-(
1648 difference_type n) const noexcept {
1649 return *this + -n;
1650 }
1652 return *this += -n;
1653 }
1654 template <typename OtherIterator, typename OtherElementType>
1655 [[nodiscard]] constexpr auto operator-(
1657 const noexcept {
1658 return it_ - other.base();
1659 }
1660 [[nodiscard]] constexpr reference operator[](
1661 difference_type n) const noexcept {
1662 return it_[n];
1663 }
1664
1665 [[nodiscard]] constexpr const Iterator& base() const noexcept { return it_; }
1666
1667 private:
1668 Iterator it_;
1669};
1670
1671// Helper functions about values contained in handles.
1672// A value is either an indirect pointer or a direct pointer, depending on
1673// whether direct local support is enabled.
1674class ValueHelper final {
1675 public:
1676 // ValueHelper::InternalRepresentationType is an abstract type that
1677 // corresponds to the internal representation of v8::Local and essentially
1678 // to what T* really is (these two are always in sync). This type is used in
1679 // methods like GetDataFromSnapshotOnce that need access to a handle's
1680 // internal representation. In particular, if `x` is a `v8::Local<T>`, then
1681 // `v8::Local<T>::FromRepr(x.repr())` gives exactly the same handle as `x`.
1682#ifdef V8_ENABLE_DIRECT_HANDLE
1683 static constexpr Address kTaggedNullAddress = 1;
1684
1686 static constexpr InternalRepresentationType kEmpty = kTaggedNullAddress;
1687#else
1689 static constexpr InternalRepresentationType kEmpty = nullptr;
1690#endif // V8_ENABLE_DIRECT_HANDLE
1691
1692 template <typename T>
1693 V8_INLINE static bool IsEmpty(T* value) {
1694 return ValueAsRepr(value) == kEmpty;
1695 }
1696
1697 // Returns a handle's "value" for all kinds of abstract handles. For Local,
1698 // it is equivalent to `*handle`. The variadic parameters support handle
1699 // types with extra type parameters, like `Persistent<T, M>`.
1700 template <template <typename T, typename... Ms> typename H, typename T,
1701 typename... Ms>
1702 V8_INLINE static T* HandleAsValue(const H<T, Ms...>& handle) {
1703 return handle.template value<T>();
1704 }
1705
1706#ifdef V8_ENABLE_DIRECT_HANDLE
1707
1708 template <typename T>
1709 V8_INLINE static Address ValueAsAddress(const T* value) {
1710 return reinterpret_cast<Address>(value);
1711 }
1712
1713 template <typename T, bool check_null = true, typename S>
1714 V8_INLINE static T* SlotAsValue(S* slot) {
1715 if (check_null && slot == nullptr) {
1716 return reinterpret_cast<T*>(kTaggedNullAddress);
1717 }
1718 return *reinterpret_cast<T**>(slot);
1719 }
1720
1721 template <typename T>
1722 V8_INLINE static InternalRepresentationType ValueAsRepr(const T* value) {
1723 return reinterpret_cast<InternalRepresentationType>(value);
1724 }
1725
1726 template <typename T>
1728 return reinterpret_cast<T*>(repr);
1729 }
1730
1731#else // !V8_ENABLE_DIRECT_HANDLE
1732
1733 template <typename T>
1734 V8_INLINE static Address ValueAsAddress(const T* value) {
1735 return *reinterpret_cast<const Address*>(value);
1736 }
1737
1738 template <typename T, bool check_null = true, typename S>
1739 V8_INLINE static T* SlotAsValue(S* slot) {
1740 return reinterpret_cast<T*>(slot);
1741 }
1742
1743 template <typename T>
1745 return const_cast<InternalRepresentationType>(
1746 reinterpret_cast<const Address*>(value));
1747 }
1748
1749 template <typename T>
1751 return reinterpret_cast<T*>(repr);
1752 }
1753
1754#endif // V8_ENABLE_DIRECT_HANDLE
1755};
1756
1760class HandleHelper final {
1761 public:
1772 template <typename T1, typename T2>
1773 V8_INLINE static bool EqualHandles(const T1& lhs, const T2& rhs) {
1774 if (lhs.IsEmpty()) return rhs.IsEmpty();
1775 if (rhs.IsEmpty()) return false;
1776 return lhs.ptr() == rhs.ptr();
1777 }
1778};
1779
1781
1782// These functions are here just to match friend declarations in
1783// XxxCallbackInfo classes allowing these functions to access the internals
1784// of the info objects. These functions are supposed to be called by debugger
1785// macros.
1786void PrintFunctionCallbackInfo(void* function_callback_info);
1787void PrintPropertyCallbackInfo(void* property_callback_info);
1788
1789} // namespace internal
1790} // namespace v8
1791
1792#endif // INCLUDE_V8_INTERNAL_H_
Definition: v8-isolate.h:291
Definition: v8-internal.h:1461
Definition: v8-internal.h:1760
static bool EqualHandles(const T1 &lhs, const T2 &rhs)
Definition: v8-internal.h:1773
Definition: v8-internal.h:878
static Address LoadMap(Address obj)
Definition: v8-internal.h:1189
static constexpr size_t kExternalAllocationSoftLimit
Definition: v8-internal.h:1108
static bool IsExternalTwoByteString(int instance_type)
Definition: v8-internal.h:1202
static const int kIsolateCageBaseOffset
Definition: v8-internal.h:945
static const int kEmbedderDataArrayHeaderSize
Definition: v8-internal.h:904
static const int kHeapObjectMapOffset
Definition: v8-internal.h:889
static const int kEmbedderDataSlotSize
Definition: v8-internal.h:905
static const int kIsolateApiCallbackThunkArgumentOffset
Definition: v8-internal.h:1007
static Address ReadExternalPointerField(v8::Isolate *isolate, Address heap_object_ptr, int offset)
Definition: v8-internal.h:1360
static const int kJSAPIObjectWithEmbedderSlotsHeaderSize
Definition: v8-internal.h:900
static constexpr bool HasHeapObjectTag(Address value)
Definition: v8-internal.h:1128
static Address ReadExternalPointerField(v8::Isolate *isolate, Address heap_object_ptr, int offset, ExternalPointerTagRange tag_range)
Definition: v8-internal.h:1389
static const int kOddballType
Definition: v8-internal.h:1085
static const int kInferShouldThrowMode
Definition: v8-internal.h:1104
static constexpr Address kCallbackInfoIsolateFlagsPayloadSize
Definition: v8-internal.h:1023
static const int kNewAllocationInfoOffset
Definition: v8-internal.h:957
static Address GetRoot(v8::Isolate *isolate, int index)
Definition: v8-internal.h:1272
static const int kStringEncodingMask
Definition: v8-internal.h:913
static const int kIsolateFastCCallCallerPcOffset
Definition: v8-internal.h:967
static uint8_t GetNodeFlag(Address *obj, int shift)
Definition: v8-internal.h:1219
static const int kIsolateThreadLocalTopOffset
Definition: v8-internal.h:976
static const uint32_t kNumIsolateDataSlots
Definition: v8-internal.h:920
static const int kForeignType
Definition: v8-internal.h:1086
static const int kJSDispatchTableOffset
Definition: v8-internal.h:1010
static const int kFirstEmbedderJSApiObjectType
Definition: v8-internal.h:1093
static const int kNumberOfBooleanFlags
Definition: v8-internal.h:922
static uint8_t GetNodeState(Address *obj)
Definition: v8-internal.h:1230
static const int kThreadLocalTopSize
Definition: v8-internal.h:929
static const int kIsolateRootsOffset
Definition: v8-internal.h:1016
static const int kExternalPointerTableSize
Definition: v8-internal.h:936
static const int kUndefinedOddballKind
Definition: v8-internal.h:1097
static const int kMapInstanceTypeOffset
Definition: v8-internal.h:890
static constexpr Address AddressToSmi(Address value)
Definition: v8-internal.h:1136
static const int kIsolateStackGuardOffset
Definition: v8-internal.h:946
static const int kLinearAllocationAreaSize
Definition: v8-internal.h:928
static const int kFastCCallAlignmentPaddingSize
Definition: v8-internal.h:964
static const int kDisallowGarbageCollectionAlign
Definition: v8-internal.h:1028
static const int kIsolateFastCCallCallerFpOffset
Definition: v8-internal.h:970
static const int kErrorMessageParamSize
Definition: v8-internal.h:923
static const int kSegmentedTableSegmentPoolSize
Definition: v8-internal.h:935
static void CheckInitialized(v8::Isolate *isolate)
Definition: v8-internal.h:1122
static void UpdateNodeState(Address *obj, uint8_t value)
Definition: v8-internal.h:1235
static constexpr Address IntegralToSmi(T value)
Definition: v8-internal.h:1147
static constexpr bool IsValidSmi(T value)
Definition: v8-internal.h:1153
static const int kJSObjectType
Definition: v8-internal.h:1088
static const int kBuiltinTier0TableOffset
Definition: v8-internal.h:955
static const int kIsolateLongTaskStatsCounterOffset
Definition: v8-internal.h:974
static const int kNativeContextEmbedderDataOffset
Definition: v8-internal.h:911
static const int kLastJSApiObjectType
Definition: v8-internal.h:1090
static constexpr bool CanHaveInternalField(int instance_type)
Definition: v8-internal.h:1207
static constexpr Address kCallbackInfoIsolateFlagsMask
Definition: v8-internal.h:1024
static const int kIsolateHandleScopeDataOffset
Definition: v8-internal.h:978
static const int kFirstNonstringType
Definition: v8-internal.h:1084
static const int kEmptyStringRootIndex
Definition: v8-internal.h:1077
static const int kBuiltinTier0EntryTableOffset
Definition: v8-internal.h:952
static const int kFixedArrayHeaderSize
Definition: v8-internal.h:903
static const int kNullOddballKind
Definition: v8-internal.h:1098
static const int kUndefinedValueRootIndex
Definition: v8-internal.h:1072
static const int kExternalTwoByteRepresentationTag
Definition: v8-internal.h:914
static constexpr Address IntToSmi(int value)
Definition: v8-internal.h:1141
static const int kDontThrow
Definition: v8-internal.h:1102
static void CheckInitializedImpl(v8::Isolate *isolate)
static void * GetEmbedderData(const v8::Isolate *isolate, uint32_t slot)
Definition: v8-internal.h:1247
static const int kStackGuardSize
Definition: v8-internal.h:921
static const int kNodeStateMask
Definition: v8-internal.h:1081
static HandleScopeData * GetHandleScopeData(v8::Isolate *isolate)
Definition: v8-internal.h:1254
static const int kNodeStateIsWeakValue
Definition: v8-internal.h:1082
static const int kFirstJSApiObjectType
Definition: v8-internal.h:1089
static const int kStringResourceOffset
Definition: v8-internal.h:891
static const int kErrorMessageParamOffset
Definition: v8-internal.h:950
static const int kExternalPointerTableBasePointerOffset
Definition: v8-internal.h:934
static const int kFalseValueRootIndex
Definition: v8-internal.h:1076
static const int kIsolateRegexpExecVectorArgumentOffset
Definition: v8-internal.h:1012
static const int kIsolateFastApiCallTargetOffset
Definition: v8-internal.h:972
static const int kTrueValueRootIndex
Definition: v8-internal.h:1075
static int GetInstanceType(Address obj)
Definition: v8-internal.h:1181
static const int kThrowOnError
Definition: v8-internal.h:1103
static Address ReadTaggedSignedField(Address heap_object_ptr, int offset)
Definition: v8-internal.h:1336
static const int kOddballKindOffset
Definition: v8-internal.h:894
static const int kBuiltinTier0TableSize
Definition: v8-internal.h:927
static const int kContinuationPreservedEmbedderDataOffset
Definition: v8-internal.h:1014
static const int kLastYoungAllocationOffset
Definition: v8-internal.h:961
static Address ReadTaggedPointerField(Address heap_object_ptr, int offset)
Definition: v8-internal.h:1325
static const int kNullValueRootIndex
Definition: v8-internal.h:1074
static void SetEmbedderData(v8::Isolate *isolate, uint32_t slot, void *data)
Definition: v8-internal.h:1240
static Address * GetRootSlot(v8::Isolate *isolate, int index)
Definition: v8-internal.h:1266
static const int kTrustedPointerTableSize
Definition: v8-internal.h:939
static const int kTheHoleValueRootIndex
Definition: v8-internal.h:1073
static constexpr int SmiValue(Address value)
Definition: v8-internal.h:1132
static const int kTablesAlignmentPaddingSize
Definition: v8-internal.h:924
static const int kHandleScopeDataSize
Definition: v8-internal.h:930
static const int kExternalOneByteRepresentationTag
Definition: v8-internal.h:915
static const int kBuiltinTier0EntryTableSize
Definition: v8-internal.h:926
static void UpdateNodeFlag(Address *obj, bool value, int shift)
Definition: v8-internal.h:1224
static const int kCallbackInfoDataOffset
Definition: v8-internal.h:918
static void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
Definition: v8-internal.h:1260
static const int kDisallowGarbageCollectionSize
Definition: v8-internal.h:1029
static const int kOldAllocationInfoOffset
Definition: v8-internal.h:959
static const int kIsolateEmbedderDataOffset
Definition: v8-internal.h:980
static T ReadRawField(Address heap_object_ptr, int offset)
Definition: v8-internal.h:1309
static v8::Isolate * GetCurrentIsolate()
static const int kEmbedderDataSlotExternalPointerOffset
Definition: v8-internal.h:909
static v8::Isolate * GetCurrentIsolateForSandbox()
Definition: v8-internal.h:1350
static int GetOddballKind(Address obj)
Definition: v8-internal.h:1198
static const int kNodeFlagsOffset
Definition: v8-internal.h:1080
static const int kTrustedPointerTableBasePointerOffset
Definition: v8-internal.h:942
static const int kRegExpStaticResultOffsetsVectorSize
Definition: v8-internal.h:925
static const int kLastEmbedderJSApiObjectType
Definition: v8-internal.h:1094
static const int kVariousBooleanFlagsOffset
Definition: v8-internal.h:948
static constexpr std::optional< Address > TryIntegralToSmi(T value)
Definition: v8-internal.h:1159
static const int kNodeClassIdOffset
Definition: v8-internal.h:1079
static const int kStringRepresentationAndEncodingMask
Definition: v8-internal.h:912
static const int kJSObjectHeaderSize
Definition: v8-internal.h:895
static const int kJSSpecialApiObjectType
Definition: v8-internal.h:1087
Definition: v8-internal.h:1469
constexpr bool operator==(const StrongRootAllocatorBase &) const =default
StrongRootAllocatorBase(Heap *heap)
Definition: v8-internal.h:1476
StrongRootAllocatorBase(v8::Isolate *isolate)
StrongRootAllocatorBase(LocalIsolate *isolate)
void deallocate_impl(Address *p, size_t n) noexcept
Heap * heap() const
Definition: v8-internal.h:1471
Definition: v8-internal.h:1496
StrongRootAllocator(HeapOrIsolateT *)
Definition: v8-internal.h:1501
T value_type
Definition: v8-internal.h:1498
StrongRootAllocator(const StrongRootAllocator< U > &other) noexcept
Definition: v8-internal.h:1503
Definition: v8-internal.h:1674
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1734
static T * ReprAsValue(InternalRepresentationType repr)
Definition: v8-internal.h:1750
internal::Address * InternalRepresentationType
Definition: v8-internal.h:1688
static T * SlotAsValue(S *slot)
Definition: v8-internal.h:1739
static T * HandleAsValue(const H< T, Ms... > &handle)
Definition: v8-internal.h:1702
static InternalRepresentationType ValueAsRepr(const T *value)
Definition: v8-internal.h:1744
static bool IsEmpty(T *value)
Definition: v8-internal.h:1693
static constexpr InternalRepresentationType kEmpty
Definition: v8-internal.h:1689
Definition: v8-internal.h:1539
constexpr WrappedIterator & operator-=(difference_type n) noexcept
Definition: v8-internal.h:1651
constexpr WrappedIterator operator--(int) noexcept
Definition: v8-internal.h:1628
constexpr WrappedIterator & operator+=(difference_type n) noexcept
Definition: v8-internal.h:1643
constexpr const Iterator & base() const noexcept
Definition: v8-internal.h:1665
std::conditional_t< std::is_void_v< ElementType >, typename std::iterator_traits< Iterator >::value_type, ElementType > value_type
Definition: v8-internal.h:1553
constexpr WrappedIterator & operator++() noexcept
Definition: v8-internal.h:1614
constexpr pointer operator->() const noexcept
Definition: v8-internal.h:1575
constexpr reference operator[](difference_type n) const noexcept
Definition: v8-internal.h:1660
typename std::iterator_traits< Iterator >::difference_type difference_type
Definition: v8-internal.h:1549
constexpr auto operator<=>(const WrappedIterator< OtherIterator, OtherElementType > &other) const noexcept
Definition: v8-internal.h:1591
std::conditional_t< std::is_void_v< ElementType >, typename std::iterator_traits< Iterator >::reference, std::add_lvalue_reference_t< ElementType > > reference
Definition: v8-internal.h:1561
constexpr WrappedIterator & operator--() noexcept
Definition: v8-internal.h:1624
constexpr WrappedIterator() noexcept=default
constexpr WrappedIterator(const WrappedIterator< OtherIterator, OtherElementType > &other) noexcept
Definition: v8-internal.h:1570
typename std::iterator_traits< Iterator >::iterator_category iterator_category
Definition: v8-internal.h:1563
constexpr reference operator*() const noexcept
Definition: v8-internal.h:1574
constexpr auto operator-(const WrappedIterator< OtherIterator, OtherElementType > &other) const noexcept
Definition: v8-internal.h:1655
friend constexpr WrappedIterator operator+(difference_type n, const WrappedIterator &x) noexcept
Definition: v8-internal.h:1639
constexpr WrappedIterator operator+(difference_type n) const noexcept
Definition: v8-internal.h:1633
constexpr WrappedIterator operator++(int) noexcept
Definition: v8-internal.h:1618
constexpr WrappedIterator operator-(difference_type n) const noexcept
Definition: v8-internal.h:1647
std::conditional_t< std::is_void_v< ElementType >, typename std::iterator_traits< Iterator >::pointer, std::add_pointer_t< ElementType > > pointer
Definition: v8-internal.h:1557
constexpr bool operator==(const WrappedIterator< OtherIterator, OtherElementType > &other) const noexcept
Definition: v8-internal.h:1584
Definition: v8-internal.h:1513
Definition: v8-internal.h:1510
const intptr_t kHeapObjectTagMask
Definition: v8-internal.h:61
constexpr uint64_t kCppHeapPointerMarkBit
Definition: v8-internal.h:383
constexpr int kCodePointerTableEntrySizeLog2
Definition: v8-internal.h:826
constexpr bool kRuntimeGeneratedCodeObjectsLiveInTrustedSpace
Definition: v8-internal.h:838
internal::Isolate * IsolateFromNeverReadOnlySpaceObject(Address obj)
constexpr uint64_t kExternalPointerTagShift
Definition: v8-internal.h:333
IndirectPointerHandle TrustedPointerHandle
Definition: v8-internal.h:761
const int kApiSystemPointerSize
Definition: v8-internal.h:51
constexpr bool SandboxIsEnabled()
Definition: v8-internal.h:206
const int kApiDoubleSize
Definition: v8-internal.h:52
constexpr size_t kMaxCppHeapPointers
Definition: v8-internal.h:406
constexpr intptr_t kIntptrAllBitsSet
Definition: v8-internal.h:79
constexpr int GB
Definition: v8-internal.h:43
void VerifyHandleIsNonEmpty(bool is_empty)
const int kApiInt32Size
Definition: v8-internal.h:53
const int kForwardingTagSize
Definition: v8-internal.h:68
uint32_t CppHeapPointerHandle
Definition: v8-internal.h:368
const intptr_t kForwardingTagMask
Definition: v8-internal.h:69
void PrintPropertyCallbackInfo(void *property_callback_info)
constexpr ExternalPointerTagRange kAnyManagedResourceExternalPointerTag(kFirstManagedResourceTag, kLastManagedResourceTag)
IndirectPointerHandle CodePointerHandle
Definition: v8-internal.h:799
constexpr uint64_t kExternalPointerPayloadMask
Definition: v8-internal.h:340
const int kSmiTagSize
Definition: v8-internal.h:73
const int kApiInt64Size
Definition: v8-internal.h:54
constexpr ExternalPointerTagRange kAnyExternalPointerTagRange(kFirstExternalPointerTag, kLastExternalPointerTag)
constexpr uint64_t kExternalPointerTagMask
Definition: v8-internal.h:334
constexpr int kCodePointerTableEntryCodeObjectOffset
Definition: v8-internal.h:834
constexpr int kTrustedPointerTableEntrySizeLog2
Definition: v8-internal.h:778
constexpr int kTrustedPointerTableEntrySize
Definition: v8-internal.h:777
constexpr uint64_t kCppHeapPointerPayloadShift
Definition: v8-internal.h:385
constexpr ExternalPointer_t kNullExternalPointer
Definition: v8-internal.h:360
Address ExternalPointer_t
Definition: v8-internal.h:357
uint32_t IndirectPointerHandle
Definition: v8-internal.h:741
constexpr CppHeapPointer_t kNullCppHeapPointer
Definition: v8-internal.h:380
constexpr ExternalPointerTagRange kAnySharedExternalPointerTagRange(kFirstSharedExternalPointerTag, kLastSharedExternalPointerTag)
const int kApiSizetSize
Definition: v8-internal.h:55
constexpr uint64_t kExternalPointerTagAndMarkbitMask
Definition: v8-internal.h:339
constexpr int kCodePointerTableEntryEntrypointOffset
Definition: v8-internal.h:833
constexpr size_t kMaxExternalPointers
Definition: v8-internal.h:328
constexpr size_t kCodePointerTableReservationSize
Definition: v8-internal.h:804
constexpr TrustedPointerHandle kNullTrustedPointerHandle
Definition: v8-internal.h:773
const int kWeakHeapObjectTag
Definition: v8-internal.h:59
constexpr ExternalPointerHandle kNullExternalPointerHandle
Definition: v8-internal.h:361
constexpr ExternalPointerTagRange kAnyMaybeReadOnlyExternalPointerTagRange(kFirstMaybeReadOnlyExternalPointerTag, kLastMaybeReadOnlyExternalPointerTag)
constexpr uintptr_t kUintptrAllBitsSet
Definition: v8-internal.h:80
const int kForwardingTag
Definition: v8-internal.h:67
const intptr_t kHeapObjectReferenceTagMask
Definition: v8-internal.h:62
constexpr bool SmiValuesAre31Bits()
Definition: v8-internal.h:194
constexpr size_t kMaxTrustedPointers
Definition: v8-internal.h:779
bool ShouldThrowOnError(internal::Isolate *isolate)
constexpr uint64_t kCppHeapPointerTagShift
Definition: v8-internal.h:384
constexpr ExternalPointerTagRange kAnyInterceptorInfoExternalPointerTagRange(kFirstInterceptorInfoExternalPointerTag, kLastInterceptorInfoExternalPointerTag)
constexpr int KB
Definition: v8-internal.h:41
constexpr bool kBuiltinCodeObjectsLiveInTrustedSpace
Definition: v8-internal.h:839
constexpr uint32_t kTrustedPointerHandleShift
Definition: v8-internal.h:770
constexpr uint32_t kCodePointerHandleShift
Definition: v8-internal.h:808
constexpr ExternalPointerTagRange kAnyManagedExternalPointerTagRange(kFirstManagedExternalPointerTag, kLastManagedExternalPointerTag)
const int kHeapObjectTag
Definition: v8-internal.h:58
const int kSmiShiftSize
Definition: v8-internal.h:190
constexpr size_t kMaxCodePointers
Definition: v8-internal.h:827
SmiTagging< kApiTaggedSize > PlatformSmiTagging
Definition: v8-internal.h:185
ExternalPointerTag
Definition: v8-internal.h:548
@ kLastForeignExternalPointerTag
Definition: v8-internal.h:653
@ kApiIndexedPropertyDescriptorCallbackTag
Definition: v8-internal.h:599
@ kGenericForeignTag
Definition: v8-internal.h:612
@ kFirstMaybeReadOnlyExternalPointerTag
Definition: v8-internal.h:582
@ kTemporalInstantTag
Definition: v8-internal.h:643
@ kTemporalPlainYearMonthTag
Definition: v8-internal.h:647
@ kExternalPointerEvacuationEntryTag
Definition: v8-internal.h:661
@ kFirstSharedExternalPointerTag
Definition: v8-internal.h:560
@ kApiNamedPropertyDefinerCallbackTag
Definition: v8-internal.h:593
@ kLastSharedExternalPointerTag
Definition: v8-internal.h:564
@ kD8WorkerTag
Definition: v8-internal.h:651
@ kApiIndexedPropertySetterCallbackTag
Definition: v8-internal.h:598
@ kWasmManagedDataTag
Definition: v8-internal.h:630
@ kLastExternalPointerTag
Definition: v8-internal.h:664
@ kIcuBreakIteratorTag
Definition: v8-internal.h:632
@ kLastExternalTypeTag
Definition: v8-internal.h:576
@ kMicrotaskCallbackDataTag
Definition: v8-internal.h:618
@ kWasmNativeModuleTag
Definition: v8-internal.h:631
@ kApiIndexedPropertyGetterCallbackTag
Definition: v8-internal.h:597
@ kApiNamedPropertyDescriptorCallbackTag
Definition: v8-internal.h:592
@ kAccessorInfoGetterTag
Definition: v8-internal.h:584
@ kTemporalPlainMonthDayTag
Definition: v8-internal.h:648
@ kIcuCollatorTag
Definition: v8-internal.h:641
@ kIcuSimpleDateFormatTag
Definition: v8-internal.h:636
@ kApiIndexedPropertyDefinerCallbackTag
Definition: v8-internal.h:600
@ kSyntheticModuleTag
Definition: v8-internal.h:616
@ kFirstExternalTypeTag
Definition: v8-internal.h:575
@ kD8ModuleEmbedderDataTag
Definition: v8-internal.h:652
@ kExternalStringResourceTag
Definition: v8-internal.h:562
@ kWasmFuncDataTag
Definition: v8-internal.h:629
@ kWaiterQueueForeignTag
Definition: v8-internal.h:622
@ kAccessorInfoSetterTag
Definition: v8-internal.h:585
@ kApiNamedPropertyDeleterCallbackTag
Definition: v8-internal.h:594
@ kApiAccessCheckCallbackTag
Definition: v8-internal.h:614
@ kApiAbortScriptExecutionCallbackTag
Definition: v8-internal.h:615
@ kMicrotaskCallbackTag
Definition: v8-internal.h:617
@ kIcuLocalizedNumberFormatterTag
Definition: v8-internal.h:639
@ kApiNamedPropertyGetterCallbackTag
Definition: v8-internal.h:590
@ kApiNamedPropertySetterCallbackTag
Definition: v8-internal.h:591
@ kApiIndexedPropertyEnumeratorCallbackTag
Definition: v8-internal.h:602
@ kExternalPointerFreeEntryTag
Definition: v8-internal.h:662
@ kFirstInterceptorInfoExternalPointerTag
Definition: v8-internal.h:588
@ kCFunctionTag
Definition: v8-internal.h:619
@ kIcuUnicodeStringTag
Definition: v8-internal.h:633
@ kLastManagedExternalPointerTag
Definition: v8-internal.h:654
@ kWaiterQueueNodeTag
Definition: v8-internal.h:561
@ kGenericManagedTag
Definition: v8-internal.h:627
@ kExternalPointerNullTag
Definition: v8-internal.h:550
@ kExternalStringResourceDataTag
Definition: v8-internal.h:563
@ kTemporalZonedDateTimeTag
Definition: v8-internal.h:649
@ kWasmStackMemoryTag
Definition: v8-internal.h:608
@ kLastManagedResourceTag
Definition: v8-internal.h:658
@ kFastApiExternalTypeTag
Definition: v8-internal.h:581
@ kExternalPointerZappedEntryTag
Definition: v8-internal.h:660
@ kApiNamedPropertyQueryCallbackTag
Definition: v8-internal.h:589
@ kFirstForeignExternalPointerTag
Definition: v8-internal.h:611
@ kTemporalPlainDateTimeTag
Definition: v8-internal.h:646
@ kIcuListFormatterTag
Definition: v8-internal.h:634
@ kDisplayNamesInternalTag
Definition: v8-internal.h:650
@ kFirstManagedResourceTag
Definition: v8-internal.h:625
@ kFirstManagedExternalPointerTag
Definition: v8-internal.h:626
@ kTemporalPlainTimeTag
Definition: v8-internal.h:645
@ kIcuPluralRulesTag
Definition: v8-internal.h:640
@ kFirstEmbedderDataTag
Definition: v8-internal.h:571
@ kApiIndexedPropertyQueryCallbackTag
Definition: v8-internal.h:596
@ kIcuLocaleTag
Definition: v8-internal.h:635
@ kMessageListenerTag
Definition: v8-internal.h:621
@ kApiIndexedPropertyDeleterCallbackTag
Definition: v8-internal.h:601
@ kTemporalDurationTag
Definition: v8-internal.h:642
@ kLastInterceptorInfoExternalPointerTag
Definition: v8-internal.h:603
@ kIcuRelativeDateTimeFormatterTag
Definition: v8-internal.h:638
@ kWasmWasmStreamingTag
Definition: v8-internal.h:628
@ kNativeContextMicrotaskQueueTag
Definition: v8-internal.h:568
@ kLastMaybeReadOnlyExternalPointerTag
Definition: v8-internal.h:606
@ kLastEmbedderDataTag
Definition: v8-internal.h:572
@ kArrayBufferExtensionTag
Definition: v8-internal.h:657
@ kIcuDateIntervalFormatTag
Definition: v8-internal.h:637
@ kCFunctionInfoTag
Definition: v8-internal.h:620
@ kFirstExternalPointerTag
Definition: v8-internal.h:549
@ kApiNamedPropertyEnumeratorCallbackTag
Definition: v8-internal.h:595
@ kFunctionTemplateInfoCallbackTag
Definition: v8-internal.h:583
@ kTemporalPlainDateTag
Definition: v8-internal.h:644
const int kSmiValueSize
Definition: v8-internal.h:191
constexpr ExternalPointerTagRange kAnyForeignExternalPointerTagRange(kFirstForeignExternalPointerTag, kLastForeignExternalPointerTag)
constexpr bool SmiValuesAre32Bits()
Definition: v8-internal.h:195
TagRange< ExternalPointerTag > ExternalPointerTagRange
Definition: v8-internal.h:667
constexpr IndirectPointerHandle kNullIndirectPointerHandle
Definition: v8-internal.h:744
uintptr_t Address
Definition: v8-internal.h:38
void PerformCastCheck(T *data)
Definition: v8-internal.h:1454
void PrintFunctionCallbackInfo(void *function_callback_info)
constexpr size_t kTrustedPointerTableReservationSize
Definition: v8-internal.h:766
uint32_t ExternalPointerHandle
Definition: v8-internal.h:349
const intptr_t kSmiTagMask
Definition: v8-internal.h:74
const int kHeapObjectTagSize
Definition: v8-internal.h:60
const int kSmiMaxValue
Definition: v8-internal.h:193
constexpr bool Is64()
Definition: v8-internal.h:196
constexpr bool kAllCodeObjectsLiveInTrustedSpace
Definition: v8-internal.h:840
const int kSmiTag
Definition: v8-internal.h:72
constexpr CodePointerHandle kNullCodePointerHandle
Definition: v8-internal.h:811
Address CppHeapPointer_t
Definition: v8-internal.h:377
constexpr CppHeapPointerHandle kNullCppHeapPointerHandle
Definition: v8-internal.h:381
constexpr int kGarbageCollectionReasonMaxValue
Definition: v8-internal.h:1465
constexpr int kCodePointerTableEntrySize
Definition: v8-internal.h:825
constexpr uint32_t kCodePointerHandleMarker
Definition: v8-internal.h:820
const int kSmiMinValue
Definition: v8-internal.h:192
constexpr int MB
Definition: v8-internal.h:42
constexpr uint64_t kExternalPointerShiftedTagMask
Definition: v8-internal.h:335
constexpr uint64_t kExternalPointerMarkBit
Definition: v8-internal.h:332
Address SandboxedPointer_t
Definition: v8-internal.h:216
const int kApiTaggedSize
Definition: v8-internal.h:175
constexpr bool PointerCompressionIsEnabled()
Definition: v8-internal.h:178
Definition: libplatform.h:15
Definition: v8-internal.h:1438
static void Perform(T *data)
Definition: v8-internal.h:856
Address * next
Definition: v8-internal.h:860
int level
Definition: v8-internal.h:862
Address * limit
Definition: v8-internal.h:861
int sealed_level
Definition: v8-internal.h:863
static constexpr uint32_t kSizeInBytes
Definition: v8-internal.h:857
void Initialize()
Definition: v8-internal.h:865
typename Iterator::iterator_concept iterator_concept
Definition: v8-internal.h:1524
Definition: v8-internal.h:1520
static constexpr bool IsValidSmi(uint64_t value)
Definition: v8-internal.h:127
static constexpr bool IsValidSmi(int64_t value)
Definition: v8-internal.h:120
static constexpr bool IsValidSmi(T value)
Definition: v8-internal.h:100
static constexpr int SmiToInt(Address value)
Definition: v8-internal.h:92
static constexpr bool IsValidSmi(T value)
Definition: v8-internal.h:150
static constexpr int SmiToInt(Address value)
Definition: v8-internal.h:142
Definition: v8-internal.h:77
Definition: v8-internal.h:448
constexpr size_t Size() const
Definition: v8-internal.h:470
constexpr bool IsEmpty() const
Definition: v8-internal.h:468
const Tag last
Definition: v8-internal.h:501
constexpr bool operator==(const TagRange other) const
Definition: v8-internal.h:490
constexpr bool Contains(Tag tag) const
Definition: v8-internal.h:478
const Tag first
Definition: v8-internal.h:500
constexpr TagRange()
Definition: v8-internal.h:465
constexpr TagRange(Tag tag)
Definition: v8-internal.h:461
constexpr size_t hash_value() const
Definition: v8-internal.h:494
constexpr TagRange(Tag first, Tag last)
Definition: v8-internal.h:454
constexpr bool Contains(TagRange tag_range) const
Definition: v8-internal.h:486
#define V8_EXTERNAL_POINTER_TAG_COUNT
Definition: v8-internal.h:418
#define V8_EMBEDDER_DATA_TAG_COUNT
Definition: v8-internal.h:413
#define V8_EXPORT
Definition: v8config.h:855
#define V8_INLINE
Definition: v8config.h:508
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:622
#define V8_LIKELY(condition)
Definition: v8config.h:669