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_ARCH_ARM64) && defined(V8_TARGET_OS_CHROMEOS)
227// On ARM64 ChromeOS, kernel config is 39 bits of virtual address space for
228// userspace, limit the sandbox to 128GB (a quarter of the total available
229// address space).
230constexpr size_t kSandboxSizeLog2 = 37; // 128 GB
231#elif defined(V8_TARGET_OS_IOS)
232// On iOS, we only get 64 GB of usable virtual address space even with the
233// "jumbo" extended virtual addressing entitlement. Limit the sandbox size to
234// 16 GB so that the base address + size for the emulated virtual address space
235// lies within the 64 GB total virtual address space.
236constexpr size_t kSandboxSizeLog2 = 34; // 16 GB
237#elif defined(V8_HOST_ARCH_RISCV64)
238// Most RISC-V hardware currently uses Sv39 (39-bit VA, 256GB userspace).
239// Limit the sandbox to 128GB (a quarter of Sv39 userspace) to avoid exceeding
240// the available virtual address space. Uses V8_HOST_ARCH so that simulator
241// builds on x64 are not unnecessarily constrained.
242constexpr size_t kSandboxSizeLog2 = 37; // 128 GB
243#elif defined(V8_TARGET_ARCH_LOONG64)
244// Some hardwares like 2k3000 only have 40-bit virtual address space, 39 bits
245// userspace and kernel each.
246constexpr size_t kSandboxSizeLog2 = 37; // 128 GB
247#else
248// Everywhere else use a 1TB sandbox.
249constexpr size_t kSandboxSizeLog2 = 40; // 1 TB
250#endif // V8_TARGET_OS_ANDROID
251constexpr size_t kSandboxSize = 1ULL << kSandboxSizeLog2;
252
253// Required alignment of the sandbox. For simplicity, we require the
254// size of the guard regions to be a multiple of this, so that this specifies
255// the alignment of the sandbox including and excluding surrounding guard
256// regions. The alignment requirement is due to the pointer compression cage
257// being located at the start of the sandbox.
258constexpr size_t kSandboxAlignment = kPtrComprCageBaseAlignment;
259
260// Sandboxed pointers are stored inside the heap as offset from the sandbox
261// base shifted to the left. This way, it is guaranteed that the offset is
262// smaller than the sandbox size after shifting it to the right again. This
263// constant specifies the shift amount.
264constexpr uint64_t kSandboxedPointerShift = 64 - kSandboxSizeLog2;
265
266// On OSes where reserving virtual memory is too expensive to reserve the
267// entire address space backing the sandbox, notably Windows pre 8.1, we create
268// a partially reserved sandbox that doesn't actually reserve most of the
269// memory, and so doesn't have the desired security properties as unrelated
270// memory allocations could end up inside of it, but which still ensures that
271// objects that should be located inside the sandbox are allocated within
272// kSandboxSize bytes from the start of the sandbox. The minimum size of the
273// region that is actually reserved for such a sandbox is specified by this
274// constant and should be big enough to contain the pointer compression cage as
275// well as the ArrayBuffer partition.
276constexpr size_t kSandboxMinimumReservationSize = 8ULL * GB;
277
278static_assert(kSandboxMinimumReservationSize > kPtrComprCageReservationSize,
279 "The minimum reservation size for a sandbox must be larger than "
280 "the pointer compression cage contained within it.");
281
282// The maximum buffer size allowed inside the sandbox. This is mostly dependent
283// on the size of the guard regions around the sandbox: an attacker must not be
284// able to construct a buffer that appears larger than the guard regions and
285// thereby "reach out of" the sandbox.
286constexpr size_t kMaxSafeBufferSizeForSandbox = 32ULL * GB - 1;
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");
293constexpr size_t kBoundedSizeMask = (1ULL << (64 - kBoundedSizeShift)) - 1;
294
295// Size of the guard regions surrounding the sandbox. This assumes a worst-case
296// scenario of a 32-bit unsigned index used to access an array of 64-bit values
297// with an additional 32GB (bounded size) offset. In particular, accesses to
298// TypedArrays are effectively computed as
299// `entry_pointer = array->base + array->offset + index * array->element_size`.
300// See also https://crbug.com/40070746 for more details.
301constexpr size_t kSandboxGuardRegionSize =
302 32ULL * GB + (kMaxSafeBufferSizeForSandbox + 1);
303
304static_assert((kSandboxGuardRegionSize % kSandboxAlignment) == 0,
305 "The size of the guard regions around the sandbox must be a "
306 "multiple of its required alignment.");
307static_assert(kMaxSafeBufferSizeForSandbox <= kSandboxGuardRegionSize,
308 "The maximum allowed buffer size must not be larger than the "
309 "sandbox's guard regions");
310
311#if defined(V8_TARGET_OS_ANDROID)
312// On Android, we often won't have sufficient virtual address space available.
313constexpr size_t kAdditionalTrailingGuardRegionSize = 0;
314#elif defined(V8_TARGET_ARCH_ARM64) && defined(V8_TARGET_OS_CHROMEOS)
315// On ARM64 ChromeOS, kernel configs 39 bits of virtual address space.
316constexpr size_t kAdditionalTrailingGuardRegionSize = 0;
317#elif defined(V8_TARGET_ARCH_LOONG64)
318// Some hardwares like 2K3000 does not have sufficient virtual address space
319// available.
320constexpr size_t kAdditionalTrailingGuardRegionSize = 0;
321#else
322// Worst-case, we need 8 (max element size) * 32GB (max ArrayBuffer size) +
323// 32GB (additional bounded size offset for TypedArray access).
324constexpr size_t kAdditionalTrailingGuardRegionSize =
325 288ULL * GB - kSandboxGuardRegionSize;
326#endif
327
328constexpr bool kRequiresTypedArrayAccessMasks =
329 kAdditionalTrailingGuardRegionSize == 0;
330
331#endif // V8_ENABLE_SANDBOX
332
333#ifdef V8_COMPRESS_POINTERS
334
335#ifdef V8_TARGET_OS_ANDROID
336// The size of the virtual memory reservation for an external pointer table.
337// This determines the maximum number of entries in a table. Using a maximum
338// size allows omitting bounds checks on table accesses if the indices are
339// guaranteed (e.g. through shifting) to be below the maximum index. This
340// value must be a power of two.
341constexpr size_t kExternalPointerTableReservationSize = 256 * MB;
342
343// The external pointer table indices stored in HeapObjects as external
344// pointers are shifted to the left by this amount to guarantee that they are
345// smaller than the maximum table size even after the C++ compiler multiplies
346// them by 8 to be used as indexes into a table of 64 bit pointers.
347constexpr uint32_t kExternalPointerIndexShift = 7;
348#elif defined(V8_TARGET_OS_IOS)
349// iOS restricts large memory allocations, with 128 MB being the maximum size we
350// can configure. If we exceed this, SegmentedTable::Initialize will throw a V8
351// out-of-memory error when running the JetStream benchmark
352// (https://browserbench.org/JetStream/).
353constexpr size_t kExternalPointerTableReservationSize = 128 * MB;
354constexpr uint32_t kExternalPointerIndexShift = 8;
355#else
356constexpr size_t kExternalPointerTableReservationSize = 512 * MB;
357constexpr uint32_t kExternalPointerIndexShift = 6;
358#endif // V8_TARGET_OS_ANDROID
359
360// The byte size of an entry in an external pointer table.
361constexpr int kExternalPointerTableEntrySize = 8;
362constexpr int kExternalPointerTableEntrySizeLog2 = 3;
363// The maximum number of entries in an external pointer table.
364constexpr size_t kMaxExternalPointers =
365 kExternalPointerTableReservationSize / kExternalPointerTableEntrySize;
366static_assert((1 << (32 - kExternalPointerIndexShift)) == kMaxExternalPointers,
367 "kExternalPointerTableReservationSize and "
368 "kExternalPointerIndexShift don't match");
369
370#else // !V8_COMPRESS_POINTERS
371
372// Needed for the V8.SandboxedExternalPointersCount histogram.
373constexpr size_t kMaxExternalPointers = 0;
374
375#endif // V8_COMPRESS_POINTERS
376
377#if V8_TARGET_ARCH_X64 && V8_SUPPORT_LA57
378constexpr uint64_t kExternalPointerMarkBit = 1ULL << 56;
379constexpr uint64_t kExternalPointerTagShift = 57;
380constexpr uint64_t kExternalPointerTagMask = 0xfe00000000000000ULL;
381constexpr uint64_t kExternalPointerTagAndMarkbitMask = 0xff00000000000000ULL;
382constexpr uint64_t kExternalPointerPayloadMask = 0x00ffffffffffffffULL;
383#else // !(V8_TARGET_ARCH_X64 && V8_SUPPORT_LA57)
384constexpr uint64_t kExternalPointerMarkBit = 1ULL << 48;
385constexpr uint64_t kExternalPointerTagShift = 49;
386constexpr uint64_t kExternalPointerTagMask = 0x00fe000000000000ULL;
387constexpr uint64_t kExternalPointerTagAndMarkbitMask = 0x00ff000000000000ULL;
388constexpr uint64_t kExternalPointerPayloadMask = 0xff00ffffffffffffULL;
389#endif // !(V8_TARGET_ARCH_X64 && V8_SUPPORT_LA57)
394
395// A ExternalPointerHandle represents a (opaque) reference to an external
396// pointer that can be stored inside the sandbox. A ExternalPointerHandle has
397// meaning only in combination with an (active) Isolate as it references an
398// external pointer stored in the currently active Isolate's
399// ExternalPointerTable. Internally, an ExternalPointerHandles is simply an
400// index into an ExternalPointerTable that is shifted to the left to guarantee
401// that it is smaller than the size of the table.
402using ExternalPointerHandle = uint32_t;
403
404// ExternalPointers point to objects located outside the V8 heap. When pointer
405// compression is enabled, these are stored on heap as ExternalPointerHandles,
406// otherwise they are simply raw pointers.
407#ifdef V8_COMPRESS_POINTERS
409#else
411#endif
412
415
416// See `ExternalPointerHandle` for the main documentation. The difference to
417// `ExternalPointerHandle` is that the handle does not represent an arbitrary
418// external pointer but always refers to an object managed by `CppHeap`. The
419// handles are using in combination with a dedicated table for `CppHeap`
420// references.
421using CppHeapPointerHandle = uint32_t;
422
423// The actual pointer to objects located on the `CppHeap`. When pointer
424// compression is enabled these pointers are stored as `CppHeapPointerHandle`.
425// In non-compressed configurations the pointers are simply stored as raw
426// pointers.
427#ifdef V8_COMPRESS_POINTERS
429#else
431#endif
432
435
436constexpr uint64_t kCppHeapPointerMarkBit = 1ULL;
437constexpr uint64_t kCppHeapPointerTagShift = 1;
438constexpr uint64_t kCppHeapPointerPayloadShift = 16;
439constexpr uint64_t kCppHeapPointerTagMask =
442
443#ifdef V8_COMPRESS_POINTERS
444// CppHeapPointers use a dedicated pointer table. These constants control the
445// size and layout of the table. See the corresponding constants for the
446// external pointer table for further details.
447constexpr size_t kCppHeapPointerTableReservationSize =
448 kExternalPointerTableReservationSize;
449constexpr uint32_t kCppHeapPointerIndexShift = kExternalPointerIndexShift;
450
451constexpr int kCppHeapPointerTableEntrySize = 8;
452constexpr int kCppHeapPointerTableEntrySizeLog2 = 3;
453constexpr size_t kMaxCppHeapPointers =
454 kCppHeapPointerTableReservationSize / kCppHeapPointerTableEntrySize;
455static_assert((1 << (32 - kCppHeapPointerIndexShift)) == kMaxCppHeapPointers,
456 "kCppHeapPointerTableReservationSize and "
457 "kCppHeapPointerIndexShift don't match");
458
459#else // !V8_COMPRESS_POINTERS
460
461// Needed for the V8.SandboxedCppHeapPointersCount histogram.
462constexpr size_t kMaxCppHeapPointers = 0;
463
464#endif // V8_COMPRESS_POINTERS
465
466// The number of tags reserved for embedder data stored in internal fields. The
467// value is picked arbitrarily, and is slightly larger than the number of tags
468// currently used in Chrome.
469#define V8_EMBEDDER_DATA_TAG_COUNT 15
470
471// The number of tags reserved for pointers stored in v8::External. The value is
472// picked arbitrarily, and is slightly larger than the number of tags currently
473// used in Chrome.
474#define V8_EXTERNAL_POINTER_TAG_COUNT 40
475
476// Generic tag range struct to represent ranges of type tags.
477//
478// When referencing external objects via pointer tables, type tags are
479// frequently necessary to guarantee type safety for the external objects. When
480// support for subtyping is necessary, range-based type checks are used in
481// which all subtypes of a given supertype use contiguous tags. This struct can
482// then be used to represent such a type range.
483//
484// As an example, consider the following type hierarchy:
485//
486// A
487// +-- B
488// | +-- C
489// | +-- D
490//. |
491// +-- E
492//
493// F
494//
495// A potential type id assignment for range-based type checks is
496// {A: 0, B: 1, C: 2, D: 3, E: 4, F: 5}. With that, the type check for type A
497// would check for the range [A, E], while the check for B would check range
498// [B, D], and for F it would simply check [F, F].
499//
500// In addition, there is an option for performance tweaks: if the size of the
501// type range corresponding to a supertype is a power of two and starts at a
502// power of two (e.g. [0x100, 0x13f]), then the compiler can often optimize
503// the type check to use even fewer instructions (essentially replace a AND +
504// SUB with a single AND).
505//
506// Tag ranges can also to a limited degree be used for union types. For
507// example, with the type graph as above, it would be possible to specify a
508// Union(D, E, F) as the tag range [D, F]. However, this only works as long as
509// the (otherwise independent) types that form the union have adjacent tags.
510//
511//
512// There are broadly speaking two options for performing the type check when
513// given the expected type range and the actual tag of the entry.
514//
515// The first option is to simply have the equivalent of
516//
517// CHECK(expected_tag_range.Contains(actual_tag))
518//
519// This is nice and simple, and friendly to both the branch-predictor and the
520// user/developer as it produces clear error messages. However, this approach
521// may result in quite a bit of code being generated, for example for calling
522// RuntimeAbort from generated code or similar.
523//
524// The second option is to generate code such as
525//
526// if (!expected_tag_range.Contains(actual_tag)) return nullptr;
527//
528// With this, we are also guaranteed to crash safely when the returned pointer
529// is used, but this may result in significantly less code being generated, for
530// example because the compiler can implement this with a single conditional
531// select in combination with the zero register (e.g. on Arm).
532//
533// The choice of which approach to use therefore depends on the use case, the
534// performance and code size constraints, and the importance of debuggability.
535template <typename Tag>
536struct TagRange {
537 static_assert(std::is_enum_v<Tag> &&
538 std::is_same_v<std::underlying_type_t<Tag>, uint16_t>,
539 "Tag parameter must be an enum with base type uint16_t");
540
541 // Construct the inclusive tag range [first, last].
542 constexpr TagRange(Tag first, Tag last) : first(first), last(last) {
543#if defined(V8_ENABLE_CHECKS) && V8_HAS_BUILTIN_UNREACHABLE
544 // This would typically be a DCHECK, but that's not available here.
545 if (first > last) __builtin_unreachable(); // Invalid tag range.
546#endif
547 }
548
549 // Construct a tag range consisting of a single tag.
550 //
551 // A single tag is always implicitly convertible to a tag range. This greatly
552 // increases readability as most of the time, the exact tag of a field is
553 // known and so no tag range needs to explicitly be created for it.
554 constexpr TagRange(Tag tag) // NOLINT(runtime/explicit)
555 : first(tag), last(tag) {}
556
557 // Construct an empty tag range.
558 constexpr TagRange() : TagRange(static_cast<Tag>(0)) {}
559
560 // A tag range is considered empty if it only contains the null tag.
561 constexpr bool IsEmpty() const { return first == 0 && last == 0; }
562
563 constexpr size_t Size() const {
564 if (IsEmpty()) {
565 return 0;
566 } else {
567 return last - first + 1;
568 }
569 }
570
571 constexpr bool Contains(Tag tag) const {
572 // Need to perform the math with uint32_t. Otherwise, the uint16_ts would
573 // be promoted to (signed) int, allowing the compiler to (wrongly) assume
574 // that an underflow cannot happen as that would be undefined behavior.
575 return static_cast<uint32_t>(tag) - static_cast<uint32_t>(first) <=
576 static_cast<uint32_t>(last) - static_cast<uint32_t>(first);
577 }
578
579 constexpr bool Contains(TagRange tag_range) const {
580 return tag_range.first >= first && tag_range.last <= last;
581 }
582
583 constexpr bool operator==(const TagRange other) const {
584 return first == other.first && last == other.last;
585 }
586
587 constexpr size_t hash_value() const {
588 static_assert(std::is_same_v<std::underlying_type_t<Tag>, uint16_t>);
589 return (static_cast<size_t>(first) << 16) | last;
590 }
591
592 // Internally we represent tag ranges as closed ranges [first, last].
593 Tag first;
594 Tag last;
595};
596
597enum class ManagedTypeId : uint32_t {
616 kD8Worker,
620};
621
622#define SHARED_MANAGED_TAG_LIST(V) V(WasmFutexManagedObjectWaitListTag)
623
624#define MANAGED_TAG_LIST(V) \
625 SHARED_MANAGED_TAG_LIST(V) \
626 V(IcuBreakIteratorTag) \
627 V(IcuListFormatterTag) \
628 V(IcuLocaleTag) \
629 V(IcuSimpleDateFormatTag) \
630 V(IcuDateIntervalFormatTag) \
631 V(IcuRelativeDateTimeFormatterTag) \
632 V(IcuLocalizedNumberFormatterTag) \
633 V(IcuCollatorTag)
634
635#define FOREIGN_TAG_LIST(V) \
636 V(GenericForeignTag) \
637 V(ApiAccessCheckCallbackTag) \
638 V(ApiAbortScriptExecutionCallbackTag) \
639 V(ApiTemporalHostSystemUTCEpochNanosecondsCallbackTag) \
640 V(CFunctionTag) \
641 V(SyntheticModuleTag) \
642 V(MicrotaskCallbackTag) \
643 V(MicrotaskCallbackDataTag) \
644 V(MessageListenerTag) \
645 V(WaiterQueueForeignTag) \
646 /* Needs to stay last to form a range for resources. */ \
647 MANAGED_TAG_LIST(V)
648
649//
650// External Pointers.
651//
652// When pointer compression is enabled, external pointers are stored in an
653// external pointer table and are referenced from HeapObjects through an index
654// (a "handle"). When stored in the table, the pointers are tagged with per-type
655// tags to prevent type confusion attacks between different external objects.
656//
657// When loading an external pointer, a range of allowed tags can be specified.
658// This way, type hierarchies can be supported. The main requirement for that
659// is that all (transitive) child classes of a given parent class have type ids
660// in the same range, and that there are no unrelated types in that range. For
661// more details about how to assign type tags to types, see the TagRange class.
662//
663// The external pointer sandboxing mechanism ensures that every access to an
664// external pointer field will result in a valid pointer of the expected type
665// even in the presence of an attacker able to corrupt memory inside the
666// sandbox. However, if any data related to the external object is stored
667// inside the sandbox it may still be corrupted and so must be validated before
668// use or moved into the external object. Further, an attacker will always be
669// able to substitute different external pointers of the same type for each
670// other. Therefore, code using external pointers must be written in a
671// "substitution-safe" way, i.e. it must always be possible to substitute
672// external pointers of the same type without causing memory corruption outside
673// of the sandbox. Generally this is achieved by referencing any group of
674// related external objects through a single external pointer.
675//
676// Currently we use bit 62 for the marking bit which should always be unused as
677// it's part of the non-canonical address range. When Arm's top-byte ignore
678// (TBI) is enabled, this bit will be part of the ignored byte, and we assume
679// that the Embedder is not using this byte (really only this one bit) for any
680// other purpose. This bit also does not collide with the memory tagging
681// extension (MTE) which would use bits [56, 60).
682//
683// The tag is limited to 7 bits since it needs to fit together with a marking
684// bit into the unused parts of a 57-bit pointer to support LA57 on x64.
685enum ExternalPointerTag : uint16_t {
688
689 // When adding new tags, please ensure that the code using these tags is
690 // "substitution-safe", i.e. still operate safely if external pointers of the
691 // same type are swapped by an attacker. See comment above for more details.
692
693 // Shared external pointers are owned by the shared Isolate and stored in the
694 // shared external pointer table associated with that Isolate, where they can
695 // be accessed from multiple threads at the same time. The objects referenced
696 // in this way must therefore always be thread-safe.
700
701 // External pointers using these tags are kept in a per-Isolate external
702 // pointer table and can only be accessed when this Isolate is active.
704
705 // Placeholders for embedder data.
708
709 // Placeholders for pointers store in v8::External.
713 // This tag is used when a fast-api callback as a parameter of type
714 // `kPointer`. The V8 fast API is only able to use this generic tag, and is
715 // therefore not supposed to be used in Chrome.
721
722 // InterceptorInfo external pointers.
742
744
745#define AS_ENUM(name) k##name,
747
748#undef AS_ENUM
749
750 // External resources whose lifetime is tied to their entry in the
751 // external pointer table but which are not referenced via a Managed
759 // The tags are limited to 7 bits, so the last tag is 0x7f.
761};
762
763// All tags must fit into the 7 tag bits of an external pointer table entry.
764static_assert(kLastExternalPointerTag <= 0x7f);
765
766constexpr const char* ToString(ExternalPointerTag tag) {
767 switch (tag) {
768#define ENUM_CASE(name) \
769 case ExternalPointerTag::k##name: \
770 return #name;
771
773
774#undef ENUM_CASE
775 default:
776 return "Unknown tag";
777 }
779
780using ExternalPointerTagRange = TagRange<ExternalPointerTag>;
781
782#define AS_LIST(name) ExternalPointerTag::k##name,
783
784#define GET_FIRST(LIST) \
785 []() { \
786 ExternalPointerTag items[] = {LIST(AS_LIST)}; \
787 return items[0]; \
788 }()
789
790#define GET_LAST(LIST) \
791 []() { \
792 ExternalPointerTag items[] = {LIST(AS_LIST)}; \
793 return items[(sizeof(items) / sizeof(items[0])) - 1]; \
794 }()
798
808
815
822// kLastManagedResourceTag defined in the enum.
825
833
834#undef AS_LIST
835#undef GET_FIRST
836#undef GET_LAST
837
838// True if the external pointer must be accessed from the shared isolate's
839// external pointer table.
840V8_INLINE static constexpr bool IsSharedExternalPointerType(
841 ExternalPointerTagRange tag_range) {
842 // This range should only be used together with
843 // kAnySharedManagedExternalPointerTagRange in this predicate. Therefore
844 // it is defined in this scope.
845 constexpr ExternalPointerTagRange kAnySharedExternalPointerTagRange(
847 return kAnySharedExternalPointerTagRange.Contains(tag_range) ||
849}
850
851// True if the external pointer may live in a read-only object, in which case
852// the table entry will be in the shared read-only segment of the external
853// pointer table.
854V8_INLINE static constexpr bool IsMaybeReadOnlyExternalPointerType(
855 ExternalPointerTagRange tag_range) {
857}
858
859// True if the external pointer references an external object whose lifetime is
860// tied to the entry in the external pointer table.
861// In this case, the entry in the ExternalPointerTable always points to an
862// object derived from ExternalPointerTable::ManagedResource.
863V8_INLINE static constexpr bool IsManagedExternalPointerType(
864 ExternalPointerTagRange tag_range) {
866}
867
868// When an external poiner field can contain the null external pointer handle,
869// the type checking mechanism needs to also check for null.
870// TODO(saelo): this is mostly a temporary workaround to introduce range-based
871// type checks. In the future, we should either (a) change the type tagging
872// scheme so that null always passes or (b) (more likely) introduce dedicated
873// null entries for those tags that need them (similar to other well-known
874// empty value constants such as the empty fixed array).
875V8_INLINE static constexpr bool ExternalPointerCanBeEmpty(
876 ExternalPointerTagRange tag_range) {
877 return tag_range.Contains(kArrayBufferExtensionTag) ||
878 (tag_range.first <= kLastEmbedderDataTag &&
879 kFirstEmbedderDataTag <= tag_range.last) ||
881}
882
883//
884// Trusted Pointers.
885//
886// A pointer to a TrustedObject.
887// When the sandbox is enabled, these are indirect pointers using the trusted
888// pointer table (TPT). They are used to reference trusted objects (located in
889// one of V8's trusted heap spaces, outside of the sandbox) from inside the
890// sandbox in a memory-safe way. When object A references an object B through a
891// trusted pointer, object A will contain a TrustedPointerHandle, i.e. a shifted
892// 32-bit index, which identifies an entry in the trusted pointer table. This
893// table entry then contains the actual pointer to object B. Further, object B
894// owns this pointer table entry, and it is responsible for updating the
895// "self-pointer" in the entry when it is relocated in memory. This way, in
896// contrast to "normal" pointers, trusted pointers never need to be tracked by
897// the GC (i.e. there is no remembered set for them).
898// When the sandbox is disabled, these are regular tagged pointers.
899
900// A TrustedPointerHandle represents a 32-bit index into a trusted pointer
901// table.
902using TrustedPointerHandle = uint32_t;
904// The size of the virtual memory reservation for the trusted pointer table.
905// As with the external pointer table, a maximum table size in combination with
906// shifted indices allows omitting bounds checks.
908
909// The trusted pointer handles are stored shifted to the left by this amount
910// to guarantee that they are smaller than the maximum table size.
911constexpr uint32_t kTrustedPointerHandleShift = 9;
912
913// A null handle always references an entry that contains nullptr.
915
916// The byte size of an entry in the trusted pointer table.
917constexpr int kTrustedPointerTableEntrySize = 8;
918constexpr int kTrustedPointerTableEntrySizeLog2 = 3;
919// The maximum number of entries in the trusted pointer table.
920constexpr size_t kMaxTrustedPointers =
922static_assert((1 << (32 - kTrustedPointerHandleShift)) == kMaxTrustedPointers,
923 "kTrustedPointerTableReservationSize and "
924 "kTrustedPointerHandleShift don't match");
926// The size of the virtual memory reservation for the Wasm code pointer table.
927// As with the other tables, a maximum table size in combination with shifted
928// indices allows omitting bounds checks.
931// Constants that can be used to mark places that should be modified once
932// certain types of objects are moved out of the sandbox and into trusted space.
934constexpr bool kBuiltinCodeObjectsLiveInTrustedSpace = false;
938
939// {obj} must be the raw tagged pointer representation of a HeapObject
940// that's guaranteed to never be in ReadOnlySpace.
942 "Use GetCurrentIsolate() instead, which is guaranteed to return the same "
943 "isolate since https://crrev.com/c/6458560.")
946// Returns if we need to throw when an error occurs. This infers the language
947// mode based on the current context and the closure. This returns true if the
948// language mode is strict.
949V8_EXPORT bool ShouldThrowOnError(internal::Isolate* isolate);
950
951struct HandleScopeData final {
952 static constexpr uint32_t kSizeInBytes =
955 Address* next;
956 Address* limit;
957 int level;
958 int sealed_level;
959
960 void Initialize() {
961 next = limit = nullptr;
962 sealed_level = level = 0;
963 }
964};
965
966static_assert(HandleScopeData::kSizeInBytes == sizeof(HandleScopeData));
967
973class Internals {
974#ifdef V8_MAP_PACKING
975 V8_INLINE static constexpr Address UnpackMapWord(Address mapword) {
976 // TODO(wenyuzhao): Clear header metadata.
977 return mapword ^ kMapWordXorMask;
978 }
979#endif
981 public:
982 // These values match non-compiler-dependent values defined within
983 // the implementation of v8.
984 static const int kHeapObjectMapOffset = 0;
985 static const int kMapInstanceTypeOffset = 1 * kApiTaggedSize + kApiInt32Size;
986 static const int kStringResourceOffset =
988 // The resource field of an external string references a cppgc object
989 // (ExternalStringResourceWrapper) which stores the resource pointer at this
990 // offset.
992
993 static const int kOddballKindOffset = 4 * kApiTaggedSize + kApiDoubleSize;
994 static const int kJSObjectHeaderSize = 3 * kApiTaggedSize;
995#ifdef V8_COMPRESS_POINTERS
998#else // !V8_COMPRESS_POINTERS
1001#endif // !V8_COMPRESS_POINTERS
1007 static const int kStringRepresentationAndEncodingMask = 0x0f;
1008 static const int kStringEncodingMask = 0x8;
1009 static const int kExternalTwoByteRepresentationTag = 0x02;
1010 static const int kExternalOneByteRepresentationTag = 0x0a;
1012 // AccessorInfo::data and InterceptorInfo::data field.
1015 static const uint32_t kNumIsolateDataSlots = 4;
1017 static const int kNumberOfBooleanFlags = 6;
1018 static const int kErrorMessageParamSize = 1;
1019 static const int kTablesAlignmentPaddingSize = 1;
1022 static const int kBuiltinTier0TableSize = 7 * kApiSystemPointerSize;
1024 static const int kThreadLocalTopSize = 28 * kApiSystemPointerSize;
1025 static const int kHandleScopeDataSize =
1027 static const int kHandleScopeImplementerSize =
1030 // ExternalPointerTable, CppHeapPointerTable and TrustedPointerTable layout
1031 // guarantees.
1034
1035 // IsolateData layout guarantees.
1036 static const int kIsolateCageBaseOffset = 0;
1037 static const int kIsolateStackGuardOffset =
1041 static const int kErrorMessageParamOffset =
1043 static const int kBuiltinTier0EntryTableOffset =
1046 static const int kBuiltinTier0TableOffset =
1048 static const int kNewAllocationInfoOffset =
1050 static const int kOldAllocationInfoOffset =
1052 static const int kLastYoungAllocationOffset =
1055 static const int kFastCCallAlignmentPaddingSize =
1058 static const int kIsolateFastCCallCallerPcOffset =
1071 static const int kIsolateHandleScopeImplementerOffset =
1073 static const int kIsolateEmbedderDataOffset =
1075#ifdef V8_COMPRESS_POINTERS
1076 static const int kIsolateExternalPointerTableOffset =
1078 static const int kIsolateSharedExternalPointerTableAddressOffset =
1079 kIsolateExternalPointerTableOffset + kExternalEntityTableSize;
1080 static const int kIsolateCppHeapPointerTableOffset =
1081 kIsolateSharedExternalPointerTableAddressOffset + kApiSystemPointerSize;
1082#ifdef V8_ENABLE_SANDBOX
1083 static const int kIsolateTrustedCageBaseOffset =
1084 kIsolateCppHeapPointerTableOffset + kExternalEntityTableSize;
1085 static const int kIsolateTrustedPointerTableOffset =
1086 kIsolateTrustedCageBaseOffset + kApiSystemPointerSize;
1087 static const int kIsolateSharedTrustedPointerTableAddressOffset =
1088 kIsolateTrustedPointerTableOffset + kExternalEntityTableSize;
1089 static const int kIsolateTrustedPointerPublishingScopeOffset =
1090 kIsolateSharedTrustedPointerTableAddressOffset + kApiSystemPointerSize;
1091 static const int kIsolateJSDispatchTableOffset =
1092 kIsolateTrustedPointerPublishingScopeOffset + kApiSystemPointerSize;
1093#else
1095 kIsolateCppHeapPointerTableOffset + kExternalEntityTableSize;
1096#endif // V8_ENABLE_SANDBOX
1097#else
1098 static const int kIsolateJSDispatchTableOffset =
1100#endif // V8_COMPRESS_POINTERS
1111 static const int kAllocationSiteCacheOffset =
1113 static const int kIsolateRootsOffset =
1116#if V8_TARGET_ARCH_PPC64
1117 static constexpr int kFrameCPSlotCount = 1;
1118#else
1119 static constexpr int kFrameCPSlotCount = 0;
1120#endif
1121
1122#if V8_TARGET_ARCH_ARM64
1123 // The padding required to keep SP 16-byte aligned.
1124 static constexpr int kSPAlignmentSlotCount = 1;
1125#else
1126 static constexpr int kSPAlignmentSlotCount = 0;
1127#endif
1129 static const int kFrameTypeApiCallExit = 18;
1130 static const int kFrameTypeApiConstructExit = 19;
1131 static const int kFrameTypeApiNamedAccessorExit = 20;
1133
1134 // Assert scopes
1135 static const int kDisallowGarbageCollectionAlign = alignof(uint32_t);
1136 static const int kDisallowGarbageCollectionSize = sizeof(uint32_t);
1137
1138#if V8_STATIC_ROOTS_BOOL
1139
1140// These constants are copied from static-roots.h and guarded by static asserts.
1141#define EXPORTED_STATIC_ROOTS_PTR_LIST(V) \
1142 V(UndefinedValue, 0x11) \
1143 V(NullValue, 0x2d) \
1144 V(TrueValue, 0x71) \
1145 V(FalseValue, 0x55) \
1146 V(EmptyString, 0x49) \
1147 V(TheHoleValue, 0xfffd)
1148
1149 using Tagged_t = uint32_t;
1150 struct StaticReadOnlyRoot {
1151#define DEF_ROOT(name, value) static constexpr Tagged_t k##name = value;
1152 EXPORTED_STATIC_ROOTS_PTR_LIST(DEF_ROOT)
1153#undef DEF_ROOT
1154
1155 // Use 0 for kStringMapLowerBound since string maps are the first maps.
1156 static constexpr Tagged_t kStringMapLowerBound = 0;
1157 static constexpr Tagged_t kStringMapUpperBound = 0x425;
1158
1159#define PLUSONE(...) +1
1160 static constexpr size_t kNumberOfExportedStaticRoots =
1161 2 + EXPORTED_STATIC_ROOTS_PTR_LIST(PLUSONE);
1162#undef PLUSONE
1165#endif // V8_STATIC_ROOTS_BOOL
1167 static const int kUndefinedValueRootIndex = 0;
1168 static const int kTheHoleValueRootIndex = 1;
1169 static const int kNullValueRootIndex = 2;
1170 static const int kTrueValueRootIndex = 3;
1171 static const int kFalseValueRootIndex = 4;
1172 static const int kEmptyStringRootIndex = 5;
1174 static const int kNodeClassIdOffset = 1 * kApiSystemPointerSize;
1175 static const int kNodeFlagsOffset = 1 * kApiSystemPointerSize + 3;
1176 static const int kNodeStateMask = 0x3;
1177 static const int kNodeStateIsWeakValue = 2;
1179 static const int kFirstNonstringType = 0x80;
1180 static const int kOddballType = 0x83;
1181 static const int kForeignType = 0xcc;
1182 static const int kJSSpecialApiObjectType = 0x410;
1183 static const int kJSObjectType = 0x421;
1184 static const int kFirstJSApiObjectType = 0x422;
1185 static const int kLastJSApiObjectType = 0x80A;
1186 // Defines a range [kFirstEmbedderJSApiObjectType, kJSApiObjectTypesCount]
1187 // of JSApiObject instance type values that an embedder can use.
1188 static const int kFirstEmbedderJSApiObjectType = 0;
1191
1192 static const int kUndefinedOddballKind = 4;
1193 static const int kNullOddballKind = 3;
1195 // Constants used by PropertyCallbackInfo to check if we should throw when an
1196 // error occurs.
1197 static const int kDontThrow = 0;
1198 static const int kThrowOnError = 1;
1199 static const int kInferShouldThrowMode = 2;
1200
1201 // Soft limit for AdjustAmountofExternalAllocatedMemory. Trigger an
1202 // incremental GC once the external memory reaches this limit.
1203 static constexpr size_t kExternalAllocationSoftLimit = 64 * 1024 * 1024;
1204
1205#ifdef V8_MAP_PACKING
1206 static const uintptr_t kMapWordMetadataMask = 0xffffULL << 48;
1207 // The lowest two bits of mapwords are always `0b10`
1208 static const uintptr_t kMapWordSignature = 0b10;
1209 // XORing a (non-compressed) map with this mask ensures that the two
1210 // low-order bits are 0b10. The 0 at the end makes this look like a Smi,
1211 // although real Smis have all lower 32 bits unset. We only rely on these
1212 // values passing as Smis in very few places.
1213 static const int kMapWordXorMask = 0b11;
1214#endif
1215
1216 V8_EXPORT static void CheckInitializedImpl(v8::Isolate* isolate);
1217 V8_INLINE static void CheckInitialized(v8::Isolate* isolate) {
1218#ifdef V8_ENABLE_CHECKS
1220#endif
1221 }
1222
1223 V8_INLINE static constexpr bool HasHeapObjectTag(Address value) {
1224 return (value & kHeapObjectTagMask) == static_cast<Address>(kHeapObjectTag);
1225 }
1226
1227 V8_INLINE static constexpr int SmiValue(Address value) {
1228 return PlatformSmiTagging::SmiToInt(value);
1229 }
1230
1231 V8_INLINE static constexpr Address AddressToSmi(Address value) {
1232 return (value << (kSmiTagSize + PlatformSmiTagging::kSmiShiftSize)) |
1233 kSmiTag;
1234 }
1235
1236 V8_INLINE static constexpr Address IntToSmi(int value) {
1237 return AddressToSmi(static_cast<Address>(value));
1239
1240 template <typename T,
1241 typename std::enable_if_t<std::is_integral_v<T>>* = nullptr>
1242 V8_INLINE static constexpr Address IntegralToSmi(T value) {
1243 return AddressToSmi(static_cast<Address>(value));
1245
1246 template <typename T,
1247 typename std::enable_if_t<std::is_integral_v<T>>* = nullptr>
1248 V8_INLINE static constexpr bool IsValidSmi(T value) {
1249 return PlatformSmiTagging::IsValidSmi(value);
1251
1252 template <typename T,
1253 typename std::enable_if_t<std::is_integral_v<T>>* = nullptr>
1254 static constexpr std::optional<Address> TryIntegralToSmi(T value) {
1255 if (V8_LIKELY(PlatformSmiTagging::IsValidSmi(value))) {
1256 return {AddressToSmi(static_cast<Address>(value))};
1257 }
1258 return {};
1259 }
1260
1261#if V8_STATIC_ROOTS_BOOL
1262 V8_INLINE static bool is_identical(Address obj, Tagged_t constant) {
1263 return static_cast<Tagged_t>(obj) == constant;
1264 }
1265
1266 V8_INLINE static bool CheckInstanceMapRange(Address obj, Tagged_t first_map,
1267 Tagged_t last_map) {
1268 auto map = ReadRawField<Tagged_t>(obj, kHeapObjectMapOffset);
1269#ifdef V8_MAP_PACKING
1270 map = UnpackMapWord(map);
1271#endif
1272 return map >= first_map && map <= last_map;
1273 }
1274#endif
1275
1276 V8_INLINE static int GetInstanceType(Address obj) {
1278#ifdef V8_MAP_PACKING
1279 map = UnpackMapWord(map);
1280#endif
1281 return ReadRawField<uint16_t>(map, kMapInstanceTypeOffset);
1282 }
1283
1284 V8_INLINE static Address LoadMap(Address obj) {
1285 if (!HasHeapObjectTag(obj)) return kNullAddress;
1287#ifdef V8_MAP_PACKING
1288 map = UnpackMapWord(map);
1289#endif
1290 return map;
1291 }
1292
1295 }
1296
1297 V8_INLINE static bool IsExternalTwoByteString(int instance_type) {
1298 int representation = (instance_type & kStringRepresentationAndEncodingMask);
1299 return representation == kExternalTwoByteRepresentationTag;
1300 }
1301
1302 V8_INLINE static bool IsExternalOneByteString(int instance_type) {
1303 int representation = (instance_type & kStringRepresentationAndEncodingMask);
1304 return representation == kExternalOneByteRepresentationTag;
1305 }
1306
1307 V8_INLINE static constexpr bool CanHaveInternalField(int instance_type) {
1308 static_assert(kJSObjectType + 1 == kFirstJSApiObjectType);
1309 static_assert(kJSObjectType < kLastJSApiObjectType);
1311 // Check for IsJSObject() || IsJSSpecialApiObject() || IsJSApiObject()
1312 return instance_type == kJSSpecialApiObjectType ||
1313 // inlined version of base::IsInRange
1314 (static_cast<unsigned>(static_cast<unsigned>(instance_type) -
1315 static_cast<unsigned>(kJSObjectType)) <=
1316 static_cast<unsigned>(kLastJSApiObjectType - kJSObjectType));
1317 }
1318
1319 V8_INLINE static uint8_t GetNodeFlag(Address* obj, int shift) {
1320 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1321 return *addr & static_cast<uint8_t>(1U << shift);
1322 }
1323
1324 V8_INLINE static void UpdateNodeFlag(Address* obj, bool value, int shift) {
1325 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1326 uint8_t mask = static_cast<uint8_t>(1U << shift);
1327 *addr = static_cast<uint8_t>((*addr & ~mask) | (value << shift));
1328 }
1329
1330 V8_INLINE static uint8_t GetNodeState(Address* obj) {
1331 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1332 return *addr & kNodeStateMask;
1333 }
1334
1335 V8_INLINE static void UpdateNodeState(Address* obj, uint8_t value) {
1336 uint8_t* addr = reinterpret_cast<uint8_t*>(obj) + kNodeFlagsOffset;
1337 *addr = static_cast<uint8_t>((*addr & ~kNodeStateMask) | value);
1338 }
1339
1340 V8_INLINE static void SetEmbedderData(v8::Isolate* isolate, uint32_t slot,
1341 void* data) {
1342 Address addr = reinterpret_cast<Address>(isolate) +
1344 *reinterpret_cast<void**>(addr) = data;
1345 }
1346
1347 V8_INLINE static void* GetEmbedderData(const v8::Isolate* isolate,
1348 uint32_t slot) {
1349 Address addr = reinterpret_cast<Address>(isolate) +
1351 return *reinterpret_cast<void* const*>(addr);
1352 }
1353
1355 Address addr =
1356 reinterpret_cast<Address>(isolate) + kIsolateHandleScopeDataOffset;
1357 return reinterpret_cast<HandleScopeData*>(addr);
1358 }
1359
1361 Address addr =
1362 reinterpret_cast<Address>(isolate) + kIsolateLongTaskStatsCounterOffset;
1363 ++(*reinterpret_cast<size_t*>(addr));
1364 }
1365
1366 V8_INLINE static Address* GetRootSlot(v8::Isolate* isolate, int index) {
1367 Address addr = reinterpret_cast<Address>(isolate) + kIsolateRootsOffset +
1369 return reinterpret_cast<Address*>(addr);
1370 }
1371
1372 V8_INLINE static Address GetRoot(v8::Isolate* isolate, int index) {
1373#if V8_STATIC_ROOTS_BOOL
1374 Address base = *reinterpret_cast<Address*>(
1375 reinterpret_cast<uintptr_t>(isolate) + kIsolateCageBaseOffset);
1376 switch (index) {
1377#define DECOMPRESS_ROOT(name, ...) \
1378 case k##name##RootIndex: \
1379 return base + StaticReadOnlyRoot::k##name;
1380 EXPORTED_STATIC_ROOTS_PTR_LIST(DECOMPRESS_ROOT)
1381#undef DECOMPRESS_ROOT
1382#undef EXPORTED_STATIC_ROOTS_PTR_LIST
1383 default:
1384 break;
1385 }
1386#endif // V8_STATIC_ROOTS_BOOL
1387 return *GetRootSlot(isolate, index);
1388 }
1389
1390#ifdef V8_COMPRESS_POINTERS
1391 V8_INLINE static Address* GetExternalPointerTableBase(v8::Isolate* isolate) {
1392 Address addr = reinterpret_cast<Address>(isolate) +
1393 kIsolateExternalPointerTableOffset +
1395 return *reinterpret_cast<Address**>(addr);
1396 }
1397
1398 V8_INLINE static Address* GetSharedExternalPointerTableBase(
1399 v8::Isolate* isolate) {
1400 Address addr = reinterpret_cast<Address>(isolate) +
1401 kIsolateSharedExternalPointerTableAddressOffset;
1402 addr = *reinterpret_cast<Address*>(addr);
1404 return *reinterpret_cast<Address**>(addr);
1406#endif
1407
1408 template <typename T>
1409 V8_INLINE static T ReadRawField(Address heap_object_ptr, int offset) {
1410 Address addr = heap_object_ptr + offset - kHeapObjectTag;
1411#ifdef V8_COMPRESS_POINTERS
1412 if constexpr (sizeof(T) > kApiTaggedSize) {
1413 // TODO(ishell, v8:8875): When pointer compression is enabled 8-byte size
1414 // fields (external pointers, doubles and BigInt data) are only
1415 // kTaggedSize aligned so we have to use unaligned pointer friendly way of
1416 // accessing them in order to avoid undefined behavior in C++ code.
1417 T r;
1418 memcpy(&r, reinterpret_cast<void*>(addr), sizeof(T));
1419 return r;
1420 }
1421#endif
1422 return *reinterpret_cast<const T*>(addr);
1423 }
1424
1425 V8_INLINE static Address ReadTaggedPointerField(Address heap_object_ptr,
1426 int offset) {
1427#ifdef V8_COMPRESS_POINTERS
1428 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
1429 Address base = GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
1430 return base + static_cast<Address>(static_cast<uintptr_t>(value));
1431#else
1432 return ReadRawField<Address>(heap_object_ptr, offset);
1433#endif
1434 }
1435
1436 V8_INLINE static Address ReadTaggedSignedField(Address heap_object_ptr,
1437 int offset) {
1438#ifdef V8_COMPRESS_POINTERS
1439 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
1440 return static_cast<Address>(static_cast<uintptr_t>(value));
1441#else
1442 return ReadRawField<Address>(heap_object_ptr, offset);
1443#endif
1445
1446 // Returns v8::Isolate::Current(), but without needing to include the
1447 // v8-isolate.h header.
1449
1451#ifdef V8_COMPRESS_POINTERS
1452 return GetCurrentIsolate();
1453#else
1454 // Not used in non-pointer-compression mode.
1455 return nullptr;
1456#endif
1457 }
1458
1459 template <ExternalPointerTagRange tag_range>
1461 Address heap_object_ptr,
1462 int offset) {
1463#ifdef V8_COMPRESS_POINTERS
1464 static_assert(!tag_range.IsEmpty());
1465 // See src/sandbox/external-pointer-table.h. Logic duplicated here so
1466 // it can be inlined and doesn't require an additional call.
1467 Address* table = IsSharedExternalPointerType(tag_range)
1468 ? GetSharedExternalPointerTableBase(isolate)
1469 : GetExternalPointerTableBase(isolate);
1471 ReadRawField<ExternalPointerHandle>(heap_object_ptr, offset);
1472 uint32_t index = handle >> kExternalPointerIndexShift;
1473 std::atomic<Address>* ptr =
1474 reinterpret_cast<std::atomic<Address>*>(&table[index]);
1475 Address entry = std::atomic_load_explicit(ptr, std::memory_order_relaxed);
1476 ExternalPointerTag actual_tag = static_cast<ExternalPointerTag>(
1478 volatile Address safe_entry;
1479 if (V8_LIKELY(tag_range.Contains(actual_tag))) {
1480 safe_entry = entry & kExternalPointerPayloadMask;
1481 } else {
1482 safe_entry = 0;
1483 }
1484 return safe_entry;
1485#else
1486 return ReadRawField<Address>(heap_object_ptr, offset);
1487#endif // V8_COMPRESS_POINTERS
1488 }
1489
1491 v8::Isolate* isolate, Address heap_object_ptr, int offset,
1492 ExternalPointerTagRange tag_range) {
1493#ifdef V8_COMPRESS_POINTERS
1494 // See src/sandbox/external-pointer-table.h. Logic duplicated here so
1495 // it can be inlined and doesn't require an additional call.
1496 Address* table = IsSharedExternalPointerType(tag_range)
1497 ? GetSharedExternalPointerTableBase(isolate)
1498 : GetExternalPointerTableBase(isolate);
1500 ReadRawField<ExternalPointerHandle>(heap_object_ptr, offset);
1501 uint32_t index = handle >> kExternalPointerIndexShift;
1502 std::atomic<Address>* ptr =
1503 reinterpret_cast<std::atomic<Address>*>(&table[index]);
1504 Address entry = std::atomic_load_explicit(ptr, std::memory_order_relaxed);
1505 ExternalPointerTag actual_tag = static_cast<ExternalPointerTag>(
1507 // Avoid DCE of the entry logic using volatile.
1508 volatile Address safe_entry;
1509 if (V8_LIKELY(tag_range.Contains(actual_tag))) {
1510 safe_entry = entry & kExternalPointerPayloadMask;
1511 } else {
1512 safe_entry = 0;
1513 }
1514 return safe_entry;
1515#else
1516 return ReadRawField<Address>(heap_object_ptr, offset);
1517#endif // V8_COMPRESS_POINTERS
1518 }
1519
1520#ifdef V8_COMPRESS_POINTERS
1521 V8_INLINE static Address GetPtrComprCageBaseFromOnHeapAddress(Address addr) {
1522 return addr & -static_cast<intptr_t>(kPtrComprCageBaseAlignment);
1523 }
1524
1525 V8_INLINE static uint32_t CompressTagged(Address value) {
1526 return static_cast<uint32_t>(value);
1527 }
1528
1529 V8_INLINE static Address DecompressTaggedField(Address heap_object_ptr,
1530 uint32_t value) {
1531 Address base = GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
1532 return base + static_cast<Address>(static_cast<uintptr_t>(value));
1533 }
1534
1535#endif // V8_COMPRESS_POINTERS
1536};
1538// Only perform cast check for types derived from v8::Data since
1539// other types do not implement the Cast method.
1540template <bool PerformCheck>
1541struct CastCheck {
1542 template <class T>
1543 static void Perform(T* data);
1545
1546template <>
1547template <class T>
1548void CastCheck<true>::Perform(T* data) {
1549 T::Cast(data);
1551
1552template <>
1553template <class T>
1554void CastCheck<false>::Perform(T* data) {}
1555
1556template <class T>
1557V8_INLINE void PerformCastCheck(T* data) {
1558 CastCheck<std::is_base_of_v<Data, T> &&
1559 !std::is_same_v<Data, std::remove_cv_t<T>>>::Perform(data);
1561
1562// A base class for backing stores, which is needed due to vagaries of
1563// how static casts work with std::shared_ptr.
1565
1566// The maximum value in enum GarbageCollectionReason, defined in heap.h.
1567// This is needed for histograms sampling garbage collection reasons.
1569
1570// Base class for the address block allocator compatible with standard
1571// containers, which registers its allocated range as strong roots.
1573 public:
1574 Heap* heap() const { return heap_; }
1576 constexpr bool operator==(const StrongRootAllocatorBase&) const = default;
1578 protected:
1579 explicit StrongRootAllocatorBase(Heap* heap) : heap_(heap) {}
1580 explicit StrongRootAllocatorBase(LocalHeap* heap);
1581 explicit StrongRootAllocatorBase(Isolate* isolate);
1583 explicit StrongRootAllocatorBase(LocalIsolate* isolate);
1584
1585 // Allocate/deallocate a range of n elements of type internal::Address.
1586 Address* allocate_impl(size_t n);
1587 void deallocate_impl(Address* p, size_t n) noexcept;
1588
1589 private:
1590 Heap* heap_;
1591};
1592
1593// The general version of this template behaves just as std::allocator, with
1594// the exception that the constructor takes the isolate as parameter. Only
1595// specialized versions, e.g., internal::StrongRootAllocator<internal::Address>
1596// and internal::StrongRootAllocator<v8::Local<T>> register the allocated range
1597// as strong roots.
1598template <typename T>
1599class StrongRootAllocator : private std::allocator<T> {
1600 public:
1601 using value_type = T;
1603 template <typename HeapOrIsolateT>
1604 explicit StrongRootAllocator(HeapOrIsolateT*) {}
1605 template <typename U>
1606 StrongRootAllocator(const StrongRootAllocator<U>& other) noexcept {}
1607
1608 using std::allocator<T>::allocate;
1609 using std::allocator<T>::deallocate;
1610};
1611
1612template <typename Iterator>
1613concept HasIteratorConcept = requires { typename Iterator::iterator_concept; };
1614
1615template <typename Iterator>
1616concept HasIteratorCategory =
1617 requires { typename Iterator::iterator_category; };
1618
1619// Helper struct that contains an `iterator_concept` type alias only when either
1620// `Iterator` or `std::iterator_traits<Iterator>` do.
1621// Default: no alias.
1622template <typename Iterator>
1624// Use `Iterator::iterator_concept` if available.
1625template <HasIteratorConcept Iterator>
1626struct MaybeDefineIteratorConcept<Iterator> {
1627 using iterator_concept = typename Iterator::iterator_concept;
1628};
1629// Otherwise fall back to `std::iterator_traits<Iterator>` if possible.
1630template <typename Iterator>
1633 using iterator_concept =
1634 typename std::iterator_traits<Iterator>::iterator_concept;
1636
1637template <typename T>
1638struct MaybeDefineIteratorConcept<T*> {
1639 using iterator_concept = std::contiguous_iterator_tag;
1640};
1641
1642// A class of iterators that wrap some different iterator type.
1643// If specified, ElementType is the type of element accessed by the wrapper
1644// iterator; in this case, the actual reference and pointer types of Iterator
1645// must be convertible to ElementType& and ElementType*, respectively.
1646template <typename Iterator, typename ElementType = void>
1647class WrappedIterator : public MaybeDefineIteratorConcept<Iterator> {
1648 public:
1649 static_assert(
1650 std::is_void_v<ElementType> ||
1651 (std::is_convertible_v<typename std::iterator_traits<Iterator>::pointer,
1652 std::add_pointer_t<ElementType>> &&
1653 std::is_convertible_v<typename std::iterator_traits<Iterator>::reference,
1654 std::add_lvalue_reference_t<ElementType>>));
1655
1656 using difference_type =
1657 typename std::iterator_traits<Iterator>::difference_type;
1659 std::conditional_t<std::is_void_v<ElementType>,
1660 typename std::iterator_traits<Iterator>::value_type,
1661 ElementType>;
1662 using pointer =
1663 std::conditional_t<std::is_void_v<ElementType>,
1664 typename std::iterator_traits<Iterator>::pointer,
1665 std::add_pointer_t<ElementType>>;
1667 std::conditional_t<std::is_void_v<ElementType>,
1668 typename std::iterator_traits<Iterator>::reference,
1669 std::add_lvalue_reference_t<ElementType>>;
1671 typename std::iterator_traits<Iterator>::iterator_category;
1672
1673 constexpr WrappedIterator() noexcept = default;
1674 constexpr explicit WrappedIterator(Iterator it) noexcept : it_(it) {}
1675
1676 template <typename OtherIterator, typename OtherElementType>
1677 requires std::is_convertible_v<OtherIterator, Iterator>
1680 : it_(other.base()) {}
1681
1682 [[nodiscard]] constexpr reference operator*() const noexcept { return *it_; }
1683 [[nodiscard]] constexpr pointer operator->() const noexcept {
1684 if constexpr (std::is_pointer_v<Iterator>) {
1685 return it_;
1686 } else {
1687 return it_.operator->();
1689 }
1690
1691 template <typename OtherIterator, typename OtherElementType>
1692 [[nodiscard]] constexpr bool operator==(
1693 const WrappedIterator<OtherIterator, OtherElementType>& other)
1694 const noexcept {
1695 return it_ == other.base();
1696 }
1697
1698 template <typename OtherIterator, typename OtherElementType>
1699 [[nodiscard]] constexpr auto operator<=>(
1701 const noexcept {
1702 if constexpr (std::three_way_comparable_with<Iterator, OtherIterator>) {
1703 return it_ <=> other.base();
1704 } else if constexpr (std::totally_ordered_with<Iterator, OtherIterator>) {
1705 if (it_ < other.base()) {
1706 return std::strong_ordering::less;
1707 }
1708 return (it_ > other.base()) ? std::strong_ordering::greater
1709 : std::strong_ordering::equal;
1710 } else {
1711 if (it_ < other.base()) {
1712 return std::partial_ordering::less;
1713 }
1714 if (other.base() < it_) {
1715 return std::partial_ordering::greater;
1716 }
1717 return (it_ == other.base()) ? std::partial_ordering::equivalent
1718 : std::partial_ordering::unordered;
1719 }
1720 }
1721
1722 constexpr WrappedIterator& operator++() noexcept {
1723 ++it_;
1724 return *this;
1725 }
1726 constexpr WrappedIterator operator++(int) noexcept {
1727 WrappedIterator result(*this);
1728 ++(*this);
1729 return result;
1730 }
1731
1732 constexpr WrappedIterator& operator--() noexcept {
1733 --it_;
1734 return *this;
1735 }
1736 constexpr WrappedIterator operator--(int) noexcept {
1737 WrappedIterator result(*this);
1738 --(*this);
1739 return result;
1740 }
1741 [[nodiscard]] constexpr WrappedIterator operator+(
1742 difference_type n) const noexcept {
1743 WrappedIterator result(*this);
1744 result += n;
1745 return result;
1746 }
1747 [[nodiscard]] friend constexpr WrappedIterator operator+(
1748 difference_type n, const WrappedIterator& x) noexcept {
1749 return x + n;
1750 }
1752 it_ += n;
1753 return *this;
1754 }
1755 [[nodiscard]] constexpr WrappedIterator operator-(
1756 difference_type n) const noexcept {
1757 return *this + -n;
1758 }
1760 return *this += -n;
1761 }
1762 template <typename OtherIterator, typename OtherElementType>
1763 [[nodiscard]] constexpr auto operator-(
1765 const noexcept {
1766 return it_ - other.base();
1767 }
1768 [[nodiscard]] constexpr reference operator[](
1769 difference_type n) const noexcept {
1770 return it_[n];
1771 }
1772
1773 [[nodiscard]] constexpr const Iterator& base() const noexcept { return it_; }
1774
1775 private:
1776 Iterator it_;
1777};
1779// Helper functions about values contained in handles.
1780// A value is either an indirect pointer or a direct pointer, depending on
1781// whether direct local support is enabled.
1782class ValueHelper final {
1783 public:
1784 // ValueHelper::InternalRepresentationType is an abstract type that
1785 // corresponds to the internal representation of v8::Local and essentially
1786 // to what T* really is (these two are always in sync). This type is used in
1787 // methods like GetDataFromSnapshotOnce that need access to a handle's
1788 // internal representation. In particular, if `x` is a `v8::Local<T>`, then
1789 // `v8::Local<T>::FromRepr(x.repr())` gives exactly the same handle as `x`.
1790#ifdef V8_ENABLE_DIRECT_HANDLE
1791 static constexpr Address kTaggedNullAddress = 1;
1794 static constexpr InternalRepresentationType kEmpty = kTaggedNullAddress;
1795#else
1797 static constexpr InternalRepresentationType kEmpty = nullptr;
1798#endif // V8_ENABLE_DIRECT_HANDLE
1799
1800 template <typename T>
1801 V8_INLINE static bool IsEmpty(T* value) {
1802 return ValueAsRepr(value) == kEmpty;
1803 }
1804
1805 // Returns a handle's "value" for all kinds of abstract handles. For Local,
1806 // it is equivalent to `*handle`. The variadic parameters support handle
1807 // types with extra type parameters, like `Persistent<T, M>`.
1808 template <template <typename T, typename... Ms> typename H, typename T,
1809 typename... Ms>
1810 V8_INLINE static T* HandleAsValue(const H<T, Ms...>& handle) {
1811 return handle.template value<T>();
1812 }
1813
1814#ifdef V8_ENABLE_DIRECT_HANDLE
1815
1816 template <typename T>
1817 V8_INLINE static Address ValueAsAddress(const T* value) {
1818 return reinterpret_cast<Address>(value);
1819 }
1820
1821 template <typename T, bool check_null = true, typename S>
1822 V8_INLINE static T* SlotAsValue(S* slot) {
1823 if (check_null && slot == nullptr) {
1824 return reinterpret_cast<T*>(kTaggedNullAddress);
1825 }
1826 return *reinterpret_cast<T**>(slot);
1827 }
1828
1829 template <typename T>
1830 V8_INLINE static InternalRepresentationType ValueAsRepr(const T* value) {
1831 return reinterpret_cast<InternalRepresentationType>(value);
1832 }
1833
1834 template <typename T>
1836 return reinterpret_cast<T*>(repr);
1837 }
1839#else // !V8_ENABLE_DIRECT_HANDLE
1840
1841 template <typename T>
1842 V8_INLINE static Address ValueAsAddress(const T* value) {
1843 return *reinterpret_cast<const Address*>(value);
1844 }
1845
1846 template <typename T, bool check_null = true, typename S>
1847 V8_INLINE static T* SlotAsValue(S* slot) {
1848 return reinterpret_cast<T*>(slot);
1849 }
1850
1851 template <typename T>
1852 V8_INLINE static InternalRepresentationType ValueAsRepr(const T* value) {
1853 return const_cast<InternalRepresentationType>(
1854 reinterpret_cast<const Address*>(value));
1855 }
1856
1857 template <typename T>
1859 return reinterpret_cast<T*>(repr);
1860 }
1861
1862#endif // V8_ENABLE_DIRECT_HANDLE
1863};
1868class HandleHelper final {
1869 public:
1880 template <typename T1, typename T2>
1881 V8_INLINE static bool EqualHandles(const T1& lhs, const T2& rhs) {
1882 if (lhs.IsEmpty()) return rhs.IsEmpty();
1883 if (rhs.IsEmpty()) return false;
1884 return lhs.ptr() == rhs.ptr();
1885 }
1886};
1887
1888V8_EXPORT void VerifyHandleIsNonEmpty(bool is_empty);
1889
1890// These functions are here just to match friend declarations in
1891// XxxCallbackInfo classes allowing these functions to access the internals
1892// of the info objects. These functions are supposed to be called by debugger
1893// macros.
1894void PrintFunctionCallbackInfo(void* function_callback_info);
1895void PrintPropertyCallbackInfo(void* property_callback_info);
1896
1897} // namespace internal
1898} // namespace v8
1899
1900#endif // INCLUDE_V8_INTERNAL_H_
Definition: v8-isolate.h:305
Definition: v8-internal.h:1560
Definition: v8-internal.h:1864
static bool EqualHandles(const T1 &lhs, const T2 &rhs)
Definition: v8-internal.h:1877
static Address LoadMap(Address obj)
Definition: v8-internal.h:1280
static constexpr size_t kExternalAllocationSoftLimit
Definition: v8-internal.h:1199
static bool IsExternalTwoByteString(int instance_type)
Definition: v8-internal.h:1293
static const int kIsolateCageBaseOffset
Definition: v8-internal.h:1032
static const int kEmbedderDataArrayHeaderSize
Definition: v8-internal.h:999
static const int kHeapObjectMapOffset
Definition: v8-internal.h:980
static const int kEmbedderDataSlotSize
Definition: v8-internal.h:1000
static const int kIsolateApiCallbackThunkArgumentOffset
Definition: v8-internal.h:1097
static const int kAllocationSiteCacheOffset
Definition: v8-internal.h:1107
static Address ReadExternalPointerField(v8::Isolate *isolate, Address heap_object_ptr, int offset)
Definition: v8-internal.h:1456
static const int kJSAPIObjectWithEmbedderSlotsHeaderSize
Definition: v8-internal.h:995
static constexpr bool HasHeapObjectTag(Address value)
Definition: v8-internal.h:1219
static const int kIsolateHandleScopeImplementerOffset
Definition: v8-internal.h:1067
static const int kOddballType
Definition: v8-internal.h:1176
static const int kInferShouldThrowMode
Definition: v8-internal.h:1195
static const int kNewAllocationInfoOffset
Definition: v8-internal.h:1044
static Address GetRoot(v8::Isolate *isolate, int index)
Definition: v8-internal.h:1368
static const int kStringEncodingMask
Definition: v8-internal.h:1004
static const int kIsolateFastCCallCallerPcOffset
Definition: v8-internal.h:1054
static uint8_t GetNodeFlag(Address *obj, int shift)
Definition: v8-internal.h:1315
static const int kIsolateThreadLocalTopOffset
Definition: v8-internal.h:1063
static const uint32_t kNumIsolateDataSlots
Definition: v8-internal.h:1011
static const int kForeignType
Definition: v8-internal.h:1177
static const int kFirstEmbedderJSApiObjectType
Definition: v8-internal.h:1184
static const int kNumberOfBooleanFlags
Definition: v8-internal.h:1013
static uint8_t GetNodeState(Address *obj)
Definition: v8-internal.h:1326
static const int kThreadLocalTopSize
Definition: v8-internal.h:1020
static const int kIsolateRootsOffset
Definition: v8-internal.h:1109
static const int kFrameTypeApiCallExit
Definition: v8-internal.h:1125
static const int kUndefinedOddballKind
Definition: v8-internal.h:1188
static const int kMapInstanceTypeOffset
Definition: v8-internal.h:981
static constexpr Address AddressToSmi(Address value)
Definition: v8-internal.h:1227
static const int kIsolateStackGuardOffset
Definition: v8-internal.h:1033
static const int kLinearAllocationAreaSize
Definition: v8-internal.h:1019
static const int kFastCCallAlignmentPaddingSize
Definition: v8-internal.h:1051
static const int kDisallowGarbageCollectionAlign
Definition: v8-internal.h:1131
static const int kIsolateFastCCallCallerFpOffset
Definition: v8-internal.h:1057
static const int kErrorMessageParamSize
Definition: v8-internal.h:1014
static void CheckInitialized(v8::Isolate *isolate)
Definition: v8-internal.h:1213
static void UpdateNodeState(Address *obj, uint8_t value)
Definition: v8-internal.h:1331
static constexpr Address IntegralToSmi(T value)
Definition: v8-internal.h:1238
static constexpr bool IsValidSmi(T value)
Definition: v8-internal.h:1244
static const int kJSObjectType
Definition: v8-internal.h:1179
static const int kExternalStringResourceWrapperResourceOffset
Definition: v8-internal.h:987
static const int kExternalEntityTableBasePointerOffset
Definition: v8-internal.h:1028
static const int kBuiltinTier0TableOffset
Definition: v8-internal.h:1042
static const int kIsolateLongTaskStatsCounterOffset
Definition: v8-internal.h:1061
static const int kNativeContextEmbedderDataOffset
Definition: v8-internal.h:1002
static const int kLastJSApiObjectType
Definition: v8-internal.h:1181
static constexpr bool CanHaveInternalField(int instance_type)
Definition: v8-internal.h:1303
static constexpr int kSPAlignmentSlotCount
Definition: v8-internal.h:1122
static const int kIsolateHandleScopeDataOffset
Definition: v8-internal.h:1065
static const int kFirstNonstringType
Definition: v8-internal.h:1175
static const int kEmptyStringRootIndex
Definition: v8-internal.h:1168
static const int kBuiltinTier0EntryTableOffset
Definition: v8-internal.h:1039
static const int kFrameTypeApiIndexedAccessorExit
Definition: v8-internal.h:1128
static const int kFixedArrayHeaderSize
Definition: v8-internal.h:998
static const int kNullOddballKind
Definition: v8-internal.h:1189
static const int kUndefinedValueRootIndex
Definition: v8-internal.h:1163
static const int kExternalTwoByteRepresentationTag
Definition: v8-internal.h:1005
static constexpr Address IntToSmi(int value)
Definition: v8-internal.h:1232
static const int kDontThrow
Definition: v8-internal.h:1193
static void CheckInitializedImpl(v8::Isolate *isolate)
static void * GetEmbedderData(const v8::Isolate *isolate, uint32_t slot)
Definition: v8-internal.h:1343
static const int kStackGuardSize
Definition: v8-internal.h:1012
static const int kNodeStateMask
Definition: v8-internal.h:1172
static HandleScopeData * GetHandleScopeData(v8::Isolate *isolate)
Definition: v8-internal.h:1350
static const int kEmbedderDataSlotCppHeapPointerOffset
Definition: v8-internal.h:1001
static const int kNodeStateIsWeakValue
Definition: v8-internal.h:1173
static const int kFirstJSApiObjectType
Definition: v8-internal.h:1180
static const int kStringResourceOffset
Definition: v8-internal.h:982
static bool IsExternalOneByteString(int instance_type)
Definition: v8-internal.h:1298
static const int kErrorMessageParamOffset
Definition: v8-internal.h:1037
static const int kCurrentMicrotaskNativeContextOffset
Definition: v8-internal.h:1105
static const int kFalseValueRootIndex
Definition: v8-internal.h:1167
static const int kIsolateRegexpExecVectorArgumentOffset
Definition: v8-internal.h:1099
static const int kIsolateFastApiCallTargetOffset
Definition: v8-internal.h:1059
static const int kTrueValueRootIndex
Definition: v8-internal.h:1166
static int GetInstanceType(Address obj)
Definition: v8-internal.h:1272
static const int kThrowOnError
Definition: v8-internal.h:1194
static Address ReadTaggedSignedField(Address heap_object_ptr, int offset)
Definition: v8-internal.h:1432
static const int kOddballKindOffset
Definition: v8-internal.h:989
static const int kBuiltinTier0TableSize
Definition: v8-internal.h:1018
static const int kExternalEntityTableSize
Definition: v8-internal.h:1029
static const int kFrameTypeApiConstructExit
Definition: v8-internal.h:1126
static const int kContinuationPreservedEmbedderDataOffset
Definition: v8-internal.h:1101
static const int kHandleScopeImplementerSize
Definition: v8-internal.h:1023
static const int kLastYoungAllocationOffset
Definition: v8-internal.h:1048
static const int kCurrentMicrotaskQueueOffset
Definition: v8-internal.h:1103
static Address ReadTaggedPointerField(Address heap_object_ptr, int offset)
Definition: v8-internal.h:1421
static const int kFrameTypeApiNamedAccessorExit
Definition: v8-internal.h:1127
static const int kNullValueRootIndex
Definition: v8-internal.h:1165
static void SetEmbedderData(v8::Isolate *isolate, uint32_t slot, void *data)
Definition: v8-internal.h:1336
static Address * GetRootSlot(v8::Isolate *isolate, int index)
Definition: v8-internal.h:1362
static const int kIsolateJSDispatchTableOffset
Definition: v8-internal.h:1094
static const int kTheHoleValueRootIndex
Definition: v8-internal.h:1164
static constexpr int SmiValue(Address value)
Definition: v8-internal.h:1223
static const int kTablesAlignmentPaddingSize
Definition: v8-internal.h:1015
static const int kHandleScopeDataSize
Definition: v8-internal.h:1021
static const int kExternalOneByteRepresentationTag
Definition: v8-internal.h:1006
static const int kBuiltinTier0EntryTableSize
Definition: v8-internal.h:1017
static void UpdateNodeFlag(Address *obj, bool value, int shift)
Definition: v8-internal.h:1320
static const int kCallbackInfoDataOffset
Definition: v8-internal.h:1009
static void IncrementLongTasksStatsCounter(v8::Isolate *isolate)
Definition: v8-internal.h:1356
static const int kDisallowGarbageCollectionSize
Definition: v8-internal.h:1132
static const int kOldAllocationInfoOffset
Definition: v8-internal.h:1046
static const int kIsolateEmbedderDataOffset
Definition: v8-internal.h:1069
static T ReadRawField(Address heap_object_ptr, int offset)
Definition: v8-internal.h:1405
static v8::Isolate * GetCurrentIsolate()
static constexpr int kFrameCPSlotCount
Definition: v8-internal.h:1115
static v8::Isolate * GetCurrentIsolateForSandbox()
Definition: v8-internal.h:1446
static int GetOddballKind(Address obj)
Definition: v8-internal.h:1289
static const int kNodeFlagsOffset
Definition: v8-internal.h:1171
static const int kRegExpStaticResultOffsetsVectorSize
Definition: v8-internal.h:1016
static const int kLastEmbedderJSApiObjectType
Definition: v8-internal.h:1185
static const int kVariousBooleanFlagsOffset
Definition: v8-internal.h:1035
static constexpr std::optional< Address > TryIntegralToSmi(T value)
Definition: v8-internal.h:1250
static const int kNodeClassIdOffset
Definition: v8-internal.h:1170
static const int kStringRepresentationAndEncodingMask
Definition: v8-internal.h:1003
static const int kJSObjectHeaderSize
Definition: v8-internal.h:990
static const int kJSSpecialApiObjectType
Definition: v8-internal.h:1178
Definition: v8-internal.h:1568
StrongRootAllocatorBase(LocalIsolate *isolate)
Definition: v8-internal.h:1595
T value_type
Definition: v8-internal.h:1597
Definition: v8-internal.h:1778
static Address ValueAsAddress(const T *value)
Definition: v8-internal.h:1838
static T * ReprAsValue(InternalRepresentationType repr)
Definition: v8-internal.h:1854
internal::Address * InternalRepresentationType
Definition: v8-internal.h:1792
static T * SlotAsValue(S *slot)
Definition: v8-internal.h:1843
static T * HandleAsValue(const H< T, Ms... > &handle)
Definition: v8-internal.h:1806
static InternalRepresentationType ValueAsRepr(const T *value)
Definition: v8-internal.h:1848
static bool IsEmpty(T *value)
Definition: v8-internal.h:1797
static constexpr InternalRepresentationType kEmpty
Definition: v8-internal.h:1793
Definition: v8-internal.h:1643
constexpr WrappedIterator & operator-=(difference_type n) noexcept
Definition: v8-internal.h:1755
constexpr WrappedIterator operator--(int) noexcept
Definition: v8-internal.h:1732
constexpr WrappedIterator & operator+=(difference_type n) noexcept
Definition: v8-internal.h:1747
constexpr const Iterator & base() const noexcept
Definition: v8-internal.h:1769
std::conditional_t< std::is_void_v< ElementType >, typename std::iterator_traits< Iterator >::value_type, ElementType > value_type
Definition: v8-internal.h:1657
constexpr WrappedIterator & operator++() noexcept
Definition: v8-internal.h:1718
constexpr pointer operator->() const noexcept
Definition: v8-internal.h:1679
constexpr reference operator[](difference_type n) const noexcept
Definition: v8-internal.h:1764
typename std::iterator_traits< Iterator >::difference_type difference_type
Definition: v8-internal.h:1653
constexpr auto operator<=>(const WrappedIterator< OtherIterator, OtherElementType > &other) const noexcept
Definition: v8-internal.h:1695
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:1665
constexpr WrappedIterator & operator--() noexcept
Definition: v8-internal.h:1728
constexpr WrappedIterator() noexcept=default
typename std::iterator_traits< Iterator >::iterator_category iterator_category
Definition: v8-internal.h:1667
constexpr reference operator*() const noexcept
Definition: v8-internal.h:1678
friend constexpr WrappedIterator operator+(difference_type n, const WrappedIterator &x) noexcept
Definition: v8-internal.h:1743
constexpr WrappedIterator operator++(int) noexcept
Definition: v8-internal.h:1722
constexpr WrappedIterator operator-(difference_type n) const noexcept
Definition: v8-internal.h:1751
std::conditional_t< std::is_void_v< ElementType >, typename std::iterator_traits< Iterator >::pointer, std::add_pointer_t< ElementType > > pointer
Definition: v8-internal.h:1661
constexpr bool operator==(const WrappedIterator< OtherIterator, OtherElementType > &other) const noexcept
Definition: v8-internal.h:1688
Definition: v8-internal.h:1612
Definition: v8-internal.h:1609
const intptr_t kHeapObjectTagMask
Definition: v8-internal.h:61
constexpr uint64_t kCppHeapPointerMarkBit
Definition: v8-internal.h:436
constexpr bool kRuntimeGeneratedCodeObjectsLiveInTrustedSpace
Definition: v8-internal.h:929
internal::Isolate * IsolateFromNeverReadOnlySpaceObject(Address obj)
constexpr uint64_t kExternalPointerTagShift
Definition: v8-internal.h:385
const int kApiSystemPointerSize
Definition: v8-internal.h:51
constexpr const char * ToString(ExternalPointerTag tag)
Definition: v8-internal.h:764
constexpr bool SandboxIsEnabled()
Definition: v8-internal.h:206
const int kApiDoubleSize
Definition: v8-internal.h:52
constexpr size_t kMaxCppHeapPointers
Definition: v8-internal.h:462
constexpr intptr_t kIntptrAllBitsSet
Definition: v8-internal.h:79
constexpr int GB
Definition: v8-internal.h:43
void VerifyHandleIsNonEmpty(bool is_empty)
uint32_t TrustedPointerHandle
Definition: v8-internal.h:898
const int kApiInt32Size
Definition: v8-internal.h:53
const int kForwardingTagSize
Definition: v8-internal.h:68
uint32_t CppHeapPointerHandle
Definition: v8-internal.h:421
const intptr_t kForwardingTagMask
Definition: v8-internal.h:69
void PrintPropertyCallbackInfo(void *property_callback_info)
constexpr ExternalPointerTagRange kAnyManagedResourceExternalPointerTag(kFirstManagedResourceTag, kLastManagedResourceTag)
constexpr uint64_t kExternalPointerPayloadMask
Definition: v8-internal.h:388
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:386
constexpr uint64_t kCppHeapPointerTagMask
Definition: v8-internal.h:439
constexpr int kTrustedPointerTableEntrySizeLog2
Definition: v8-internal.h:914
constexpr int kTrustedPointerTableEntrySize
Definition: v8-internal.h:913
constexpr uint64_t kCppHeapPointerPayloadShift
Definition: v8-internal.h:438
constexpr ExternalPointer_t kNullExternalPointer
Definition: v8-internal.h:413
Address ExternalPointer_t
Definition: v8-internal.h:410
constexpr CppHeapPointer_t kNullCppHeapPointer
Definition: v8-internal.h:433
const int kApiSizetSize
Definition: v8-internal.h:55
constexpr uint64_t kExternalPointerTagAndMarkbitMask
Definition: v8-internal.h:387
constexpr size_t kMaxExternalPointers
Definition: v8-internal.h:373
constexpr ExternalPointerTagRange kAnySharedManagedExternalPointerTagRange(kFirstSharedManagedExternalPointerTag, kLastSharedManagedExternalPointerTag)
constexpr size_t kWasmCodePointerTableReservationSize
Definition: v8-internal.h:925
constexpr TrustedPointerHandle kNullTrustedPointerHandle
Definition: v8-internal.h:910
const int kWeakHeapObjectTag
Definition: v8-internal.h:59
constexpr ExternalPointerHandle kNullExternalPointerHandle
Definition: v8-internal.h:414
constexpr ExternalPointerTagRange kAnyMaybeReadOnlyExternalPointerTagRange(kFirstMaybeReadOnlyExternalPointerTag, kLastMaybeReadOnlyExternalPointerTag)
constexpr ExternalPointerTag kFirstSharedManagedExternalPointerTag
Definition: v8-internal.h:822
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:916
bool ShouldThrowOnError(internal::Isolate *isolate)
constexpr uint64_t kCppHeapPointerTagShift
Definition: v8-internal.h:437
constexpr ExternalPointerTagRange kAnyInterceptorInfoExternalPointerTagRange(kFirstInterceptorInfoExternalPointerTag, kLastInterceptorInfoExternalPointerTag)
constexpr ExternalPointerTag kFirstManagedExternalPointerTag
Definition: v8-internal.h:805
constexpr int KB
Definition: v8-internal.h:41
constexpr bool kBuiltinCodeObjectsLiveInTrustedSpace
Definition: v8-internal.h:930
constexpr uint32_t kTrustedPointerHandleShift
Definition: v8-internal.h:907
constexpr ExternalPointerTagRange kAnyManagedExternalPointerTagRange(kFirstManagedExternalPointerTag, kLastManagedExternalPointerTag)
const int kHeapObjectTag
Definition: v8-internal.h:58
const int kSmiShiftSize
Definition: v8-internal.h:190
SmiTagging< kApiTaggedSize > PlatformSmiTagging
Definition: v8-internal.h:185
ExternalPointerTag
Definition: v8-internal.h:685
@ kApiIndexedPropertyDescriptorCallbackTag
Definition: v8-internal.h:734
@ kFirstMaybeReadOnlyExternalPointerTag
Definition: v8-internal.h:717
@ kExternalPointerEvacuationEntryTag
Definition: v8-internal.h:755
@ kFirstSharedExternalPointerTag
Definition: v8-internal.h:697
@ kApiNamedPropertyDefinerCallbackTag
Definition: v8-internal.h:728
@ kLastSharedExternalPointerTag
Definition: v8-internal.h:699
@ kApiIndexedPropertySetterCallbackTag
Definition: v8-internal.h:733
@ kLastExternalPointerTag
Definition: v8-internal.h:758
@ kLastExternalTypeTag
Definition: v8-internal.h:711
@ kApiIndexedPropertyGetterCallbackTag
Definition: v8-internal.h:732
@ kApiNamedPropertyDescriptorCallbackTag
Definition: v8-internal.h:727
@ kAccessorInfoGetterTag
Definition: v8-internal.h:719
@ kApiIndexedPropertyDefinerCallbackTag
Definition: v8-internal.h:735
@ kFirstExternalTypeTag
Definition: v8-internal.h:710
@ kAccessorInfoSetterTag
Definition: v8-internal.h:720
@ kApiNamedPropertyDeleterCallbackTag
Definition: v8-internal.h:729
@ kApiNamedPropertyGetterCallbackTag
Definition: v8-internal.h:725
@ kApiNamedPropertySetterCallbackTag
Definition: v8-internal.h:726
@ kApiIndexedPropertyIndexOfCallbackTag
Definition: v8-internal.h:738
@ kApiIndexedPropertyEnumeratorCallbackTag
Definition: v8-internal.h:737
@ kExternalPointerFreeEntryTag
Definition: v8-internal.h:756
@ kFirstInterceptorInfoExternalPointerTag
Definition: v8-internal.h:723
@ kExternalPointerNullTag
Definition: v8-internal.h:687
@ kExternalStringResourceDataTag
Definition: v8-internal.h:698
@ kWasmStackMemoryTag
Definition: v8-internal.h:750
@ kLastManagedResourceTag
Definition: v8-internal.h:752
@ kFastApiExternalTypeTag
Definition: v8-internal.h:716
@ kExternalPointerZappedEntryTag
Definition: v8-internal.h:754
@ kApiNamedPropertyQueryCallbackTag
Definition: v8-internal.h:724
@ kFirstEmbedderDataTag
Definition: v8-internal.h:706
@ kApiIndexedPropertyQueryCallbackTag
Definition: v8-internal.h:731
@ kApiIndexedPropertyDeleterCallbackTag
Definition: v8-internal.h:736
@ kLastInterceptorInfoExternalPointerTag
Definition: v8-internal.h:740
@ kNativeContextMicrotaskQueueTag
Definition: v8-internal.h:703
@ kLastMaybeReadOnlyExternalPointerTag
Definition: v8-internal.h:743
@ kLastEmbedderDataTag
Definition: v8-internal.h:707
@ kArrayBufferExtensionTag
Definition: v8-internal.h:751
@ kFirstExternalPointerTag
Definition: v8-internal.h:686
@ kApiNamedPropertyEnumeratorCallbackTag
Definition: v8-internal.h:730
@ kFunctionTemplateInfoCallbackTag
Definition: v8-internal.h:718
@ kApiIndexedPropertyIterableToListCallbackTag
Definition: v8-internal.h:739
const int kSmiValueSize
Definition: v8-internal.h:191
constexpr ExternalPointerTag kLastSharedManagedExternalPointerTag
Definition: v8-internal.h:824
constexpr ExternalPointerTagRange kAnyForeignExternalPointerTagRange(kFirstForeignExternalPointerTag, kLastForeignExternalPointerTag)
constexpr bool SmiValuesAre32Bits()
Definition: v8-internal.h:195
constexpr ExternalPointerTag kLastManagedExternalPointerTag
Definition: v8-internal.h:807
TagRange< ExternalPointerTag > ExternalPointerTagRange
Definition: v8-internal.h:776
constexpr ExternalPointerTag kFirstForeignExternalPointerTag
Definition: v8-internal.h:795
uintptr_t Address
Definition: v8-internal.h:38
void PerformCastCheck(T *data)
Definition: v8-internal.h:1553
void PrintFunctionCallbackInfo(void *function_callback_info)
constexpr size_t kTrustedPointerTableReservationSize
Definition: v8-internal.h:903
uint32_t ExternalPointerHandle
Definition: v8-internal.h:402
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:931
const int kSmiTag
Definition: v8-internal.h:72
constexpr ExternalPointerTag kFirstManagedResourceTag
Definition: v8-internal.h:816
Address CppHeapPointer_t
Definition: v8-internal.h:430
constexpr CppHeapPointerHandle kNullCppHeapPointerHandle
Definition: v8-internal.h:434
constexpr int kGarbageCollectionReasonMaxValue
Definition: v8-internal.h:1564
const int kSmiMinValue
Definition: v8-internal.h:192
ManagedTypeId
Definition: v8-internal.h:597
constexpr int MB
Definition: v8-internal.h:42
constexpr uint64_t kExternalPointerShiftedTagMask
Definition: v8-internal.h:390
constexpr uint64_t kExternalPointerMarkBit
Definition: v8-internal.h:384
Address SandboxedPointer_t
Definition: v8-internal.h:216
const int kApiTaggedSize
Definition: v8-internal.h:175
constexpr bool PointerCompressionIsEnabled()
Definition: v8-internal.h:178
constexpr ExternalPointerTag kLastForeignExternalPointerTag
Definition: v8-internal.h:797
Definition: libplatform.h:15
Definition: v8-internal.h:1537
static void Perform(T *data)
Definition: v8-internal.h:947
static constexpr uint32_t kSizeInBytes
Definition: v8-internal.h:948
typename Iterator::iterator_concept iterator_concept
Definition: v8-internal.h:1623
Definition: v8-internal.h:1619
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:536
constexpr size_t Size() const
Definition: v8-internal.h:563
constexpr bool IsEmpty() const
Definition: v8-internal.h:561
Tag last
Definition: v8-internal.h:594
Tag first
Definition: v8-internal.h:593
constexpr bool operator==(const TagRange other) const
Definition: v8-internal.h:583
constexpr bool Contains(Tag tag) const
Definition: v8-internal.h:571
constexpr TagRange()
Definition: v8-internal.h:558
constexpr TagRange(Tag tag)
Definition: v8-internal.h:554
constexpr size_t hash_value() const
Definition: v8-internal.h:587
constexpr TagRange(Tag first, Tag last)
Definition: v8-internal.h:542
constexpr bool Contains(TagRange tag_range) const
Definition: v8-internal.h:579
#define FOREIGN_TAG_LIST(V)
Definition: v8-internal.h:635
#define AS_ENUM(name)
Definition: v8-internal.h:745
#define V8_EXTERNAL_POINTER_TAG_COUNT
Definition: v8-internal.h:474
#define MANAGED_TAG_LIST(V)
Definition: v8-internal.h:624
#define SHARED_MANAGED_TAG_LIST(V)
Definition: v8-internal.h:622
#define ENUM_CASE(name)
#define GET_FIRST(LIST)
Definition: v8-internal.h:780
#define V8_EMBEDDER_DATA_TAG_COUNT
Definition: v8-internal.h:469
#define GET_LAST(LIST)
Definition: v8-internal.h:786
#define V8_EXPORT
Definition: v8config.h:875
#define V8_INLINE
Definition: v8config.h:519
#define V8_DEPRECATE_SOON(message)
Definition: v8config.h:632
#define V8_LIKELY(condition)
Definition: v8config.h:679