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