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