5 #ifndef INCLUDE_V8_INTERNAL_H_
6 #define INCLUDE_V8_INTERNAL_H_
11 #include <type_traits>
30 static const Address kNullAddress = 0;
32 constexpr int KB = 1024;
33 constexpr int MB =
KB * 1024;
34 constexpr int GB =
MB * 1024;
35 #ifdef V8_TARGET_ARCH_X64
66 template <size_t tagged_ptr_size>
75 struct SmiTagging<4> {
85 return static_cast<int32_t>(
static_cast<uint32_t>(value)) >> shift_bits;
91 return (
static_cast<uintptr_t>(value) -
100 struct SmiTagging<8> {
110 return static_cast<
int>(
static_cast<intptr_t>(value) >> shift_bits);
114 return (value ==
static_cast<int32_t>(value));
118 #ifdef V8_COMPRESS_POINTERS
126 "Pointer compression can be enabled only for 64-bit architectures");
136 #ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
168 #ifdef V8_SANDBOXED_EXTERNAL_POINTERS
182 #ifdef V8_SANDBOXED_EXTERNAL_POINTERS
188 #ifdef V8_SANDBOX_IS_AVAILABLE
213 "The size of the guard regions around the sandbox must be a "
214 "multiple of its required alignment.");
227 "The minimal size of the sandbox must be smaller or equal to the "
243 "The sandbox must be larger than the pointer compression cage "
244 "contained within it.");
246 "The minimum reservation size for a sandbox must be larger than "
247 "the pointer compression cage contained within it.");
253 #ifdef V8_SANDBOXED_POINTERS
276 "kExternalPointerTableReservationSize and "
277 "kExternalPointerIndexShift don't match");
298 #define MAKE_TAG(v) (static_cast<uint64_t>(v) << kExternalPointerTagShift)
316 ExternalPointer_t pointer,
336 #ifdef V8_MAP_PACKING
357 #ifdef V8_SANDBOXED_EXTERNAL_POINTERS
432 #ifdef V8_MAP_PACKING
445 #ifdef V8_ENABLE_CHECKS
446 CheckInitializedImpl(isolate);
469 #ifdef V8_MAP_PACKING
470 map = UnpackMapWord(map);
486 return *addr &
static_cast<uint8_t>(1U << shift);
492 uint8_t mask =
static_cast<uint8_t>(1U << shift);
493 *addr =
static_cast<uint8_t>((*addr & ~mask) | (value << shift));
511 *
reinterpret_cast<
void**>(addr) = data;
519 return *
reinterpret_cast<
void*
const*>(addr);
525 ++(*
reinterpret_cast<size_t*>(addr));
535 template <
typename T>
539 #ifdef V8_COMPRESS_POINTERS
540 if (
sizeof(T) > kApiTaggedSize) {
546 memcpy(&r,
reinterpret_cast<
void*>(addr),
sizeof(T));
550 return *
reinterpret_cast<
const T*>(addr);
555 #ifdef V8_COMPRESS_POINTERS
556 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
557 internal::Address base =
558 GetPtrComprCageBaseFromOnHeapAddress(heap_object_ptr);
559 return base +
static_cast<internal::Address>(
static_cast<uintptr_t>(value));
567 #ifdef V8_COMPRESS_POINTERS
568 uint32_t value = ReadRawField<uint32_t>(heap_object_ptr, offset);
569 return static_cast<internal::Address>(
static_cast<uintptr_t>(value));
577 #ifdef V8_SANDBOXED_EXTERNAL_POINTERS
578 return internal::IsolateFromNeverReadOnlySpaceObject(obj);
586 const Isolate* isolate, ExternalPointer_t encoded_pointer,
588 #ifdef V8_SANDBOXED_EXTERNAL_POINTERS
589 return internal::DecodeExternalPointerImpl(isolate, encoded_pointer, tag);
591 return encoded_pointer;
598 #ifdef V8_SANDBOXED_EXTERNAL_POINTERS
599 internal::ExternalPointer_t encoded_value =
600 ReadRawField<uint32_t>(heap_object_ptr, offset);
602 return encoded_value ? DecodeExternalPointer(isolate, encoded_value, tag)
609 #ifdef V8_COMPRESS_POINTERS
627 template <
bool PerformCheck>
646 !std::is_same<
Data, std::remove_cv_t<T>>::value>::Perform(data);