summaryrefslogtreecommitdiff
path: root/deps/v8/include/v8-internal.h
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/include/v8-internal.h')
-rw-r--r--deps/v8/include/v8-internal.h66
1 files changed, 49 insertions, 17 deletions
diff --git a/deps/v8/include/v8-internal.h b/deps/v8/include/v8-internal.h
index 0d9cce82b4..06846d7005 100644
--- a/deps/v8/include/v8-internal.h
+++ b/deps/v8/include/v8-internal.h
@@ -120,6 +120,23 @@ constexpr bool HeapSandboxIsEnabled() {
using ExternalPointer_t = Address;
+// If the heap sandbox is enabled, these tag values will be XORed with the
+// external pointers in the external pointer table to prevent use of pointers of
+// the wrong type.
+enum ExternalPointerTag : Address {
+ kExternalPointerNullTag = static_cast<Address>(0ULL),
+ kArrayBufferBackingStoreTag = static_cast<Address>(1ULL << 48),
+ kTypedArrayExternalPointerTag = static_cast<Address>(2ULL << 48),
+ kDataViewDataPointerTag = static_cast<Address>(3ULL << 48),
+ kExternalStringResourceTag = static_cast<Address>(4ULL << 48),
+ kExternalStringResourceDataTag = static_cast<Address>(5ULL << 48),
+ kForeignForeignAddressTag = static_cast<Address>(6ULL << 48),
+ kNativeContextMicrotaskQueueTag = static_cast<Address>(7ULL << 48),
+ // TODO(v8:10391, saelo): Currently has to be zero so that raw zero values are
+ // also nullptr
+ kEmbedderDataSlotPayloadTag = static_cast<Address>(0ULL << 48),
+};
+
#ifdef V8_31BIT_SMIS_ON_64BIT_ARCH
using PlatformSmiTagging = SmiTagging<kApiInt32Size>;
#else
@@ -140,6 +157,11 @@ V8_INLINE static constexpr internal::Address IntToSmi(int value) {
kSmiTag;
}
+// Converts encoded external pointer to address.
+V8_EXPORT Address DecodeExternalPointerImpl(const Isolate* isolate,
+ ExternalPointer_t pointer,
+ ExternalPointerTag tag);
+
// {obj} must be the raw tagged pointer representation of a HeapObject
// that's guaranteed to never be in ReadOnlySpace.
V8_EXPORT internal::Isolate* IsolateFromNeverReadOnlySpaceObject(Address obj);
@@ -168,6 +190,9 @@ class Internals {
static const int kFixedArrayHeaderSize = 2 * kApiTaggedSize;
static const int kEmbedderDataArrayHeaderSize = 2 * kApiTaggedSize;
static const int kEmbedderDataSlotSize = kApiSystemPointerSize;
+#ifdef V8_HEAP_SANDBOX
+ static const int kEmbedderDataSlotRawPayloadOffset = kApiTaggedSize;
+#endif
static const int kNativeContextEmbedderDataOffset = 6 * kApiTaggedSize;
static const int kFullStringRepresentationMask = 0x0f;
static const int kStringEncodingMask = 0x8;
@@ -187,6 +212,12 @@ class Internals {
static const int kIsolateRootsOffset =
kIsolateStackGuardOffset + 7 * kApiSystemPointerSize;
+ static const int kExternalPointerTableBufferOffset = 0;
+ static const int kExternalPointerTableLengthOffset =
+ kExternalPointerTableBufferOffset + kApiSystemPointerSize;
+ static const int kExternalPointerTableCapacityOffset =
+ kExternalPointerTableLengthOffset + kApiInt32Size;
+
static const int kUndefinedValueRootIndex = 4;
static const int kTheHoleValueRootIndex = 5;
static const int kNullValueRootIndex = 6;
@@ -352,15 +383,28 @@ class Internals {
#endif
}
+ V8_INLINE static Address DecodeExternalPointer(
+ const Isolate* isolate, ExternalPointer_t encoded_pointer,
+ ExternalPointerTag tag) {
+#ifdef V8_HEAP_SANDBOX
+ return internal::DecodeExternalPointerImpl(isolate, encoded_pointer, tag);
+#else
+ return encoded_pointer;
+#endif
+ }
+
V8_INLINE static internal::Address ReadExternalPointerField(
- internal::Isolate* isolate, internal::Address heap_object_ptr,
- int offset) {
- internal::Address value = ReadRawField<Address>(heap_object_ptr, offset);
+ internal::Isolate* isolate, internal::Address heap_object_ptr, int offset,
+ ExternalPointerTag tag) {
#ifdef V8_HEAP_SANDBOX
+ internal::ExternalPointer_t encoded_value =
+ ReadRawField<uint32_t>(heap_object_ptr, offset);
// We currently have to treat zero as nullptr in embedder slots.
- if (value) value = DecodeExternalPointer(isolate, value);
+ return encoded_value ? DecodeExternalPointer(isolate, encoded_value, tag)
+ : 0;
+#else
+ return ReadRawField<Address>(heap_object_ptr, offset);
#endif
- return value;
}
#ifdef V8_COMPRESS_POINTERS
@@ -368,10 +412,6 @@ class Internals {
static constexpr size_t kPtrComprHeapReservationSize = size_t{1} << 32;
static constexpr size_t kPtrComprIsolateRootAlignment = size_t{1} << 32;
- // See v8:10391 for details about V8 heap sandbox.
- static constexpr uint32_t kExternalPointerSalt =
- 0x7fffffff & ~static_cast<uint32_t>(kHeapObjectTagMask);
-
V8_INLINE static internal::Address GetRootFromOnHeapAddress(
internal::Address addr) {
return addr & -static_cast<intptr_t>(kPtrComprIsolateRootAlignment);
@@ -383,14 +423,6 @@ class Internals {
return root + static_cast<internal::Address>(static_cast<uintptr_t>(value));
}
- V8_INLINE static Address DecodeExternalPointer(
- const Isolate* isolate, ExternalPointer_t encoded_pointer) {
-#ifndef V8_HEAP_SANDBOX
- return encoded_pointer;
-#else
- return encoded_pointer ^ kExternalPointerSalt;
-#endif
- }
#endif // V8_COMPRESS_POINTERS
};