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