Commit f67131e5 authored by Igor Sheludko's avatar Igor Sheludko Committed by Commit Bot

[sandbox][api] Introduce Internals::GetIsolateForHeapSandbox()

... for the cases when the Isolate is necessary only for external
pointers decoding. This will avoid unnecessary calls to non-inlined
IsolateFromNeverReadOnlySpaceObject().

Bug: v8:10391
Change-Id: I0a299c8a44d5845f26cf704ce53555bf07c93f8d
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2198978Reviewed-by: 's avatarMichael Lippautz <mlippautz@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#67771}
parent 20945ef7
...@@ -140,6 +140,15 @@ V8_INLINE static constexpr internal::Address IntToSmi(int value) { ...@@ -140,6 +140,15 @@ V8_INLINE static constexpr internal::Address IntToSmi(int value) {
kSmiTag; kSmiTag;
} }
// {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);
// Returns if we need to throw when an error occurs. This infers the language
// mode based on the current context and the closure. This returns true if the
// language mode is strict.
V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate);
/** /**
* This class exports constants and functionality from within v8 that * This class exports constants and functionality from within v8 that
* is necessary to implement inline functions in the v8 api. Don't * is necessary to implement inline functions in the v8 api. Don't
...@@ -339,17 +348,25 @@ class Internals { ...@@ -339,17 +348,25 @@ class Internals {
#endif #endif
} }
V8_INLINE static internal::Isolate* GetIsolateForHeapSandbox(
internal::Address obj) {
#ifdef V8_HEAP_SANDBOX
return internal::IsolateFromNeverReadOnlySpaceObject(obj);
#else
// Not used in non-sandbox mode.
return nullptr;
#endif
}
V8_INLINE static internal::Address ReadExternalPointerField( V8_INLINE static internal::Address ReadExternalPointerField(
internal::Isolate* isolate, internal::Address heap_object_ptr, internal::Isolate* isolate, internal::Address heap_object_ptr,
int offset) { int offset) {
#ifdef V8_COMPRESS_POINTERS
internal::Address value = ReadRawField<Address>(heap_object_ptr, offset); internal::Address value = ReadRawField<Address>(heap_object_ptr, offset);
#ifdef V8_HEAP_SANDBOX
// We currently have to treat zero as nullptr in embedder slots. // We currently have to treat zero as nullptr in embedder slots.
if (value) value = DecodeExternalPointer(isolate, value); if (value) value = DecodeExternalPointer(isolate, value);
return value;
#else
return ReadRawField<internal::Address>(heap_object_ptr, offset);
#endif #endif
return value;
} }
#ifdef V8_COMPRESS_POINTERS #ifdef V8_COMPRESS_POINTERS
...@@ -406,15 +423,6 @@ V8_INLINE void PerformCastCheck(T* data) { ...@@ -406,15 +423,6 @@ V8_INLINE void PerformCastCheck(T* data) {
CastCheck<std::is_base_of<Data, T>::value>::Perform(data); CastCheck<std::is_base_of<Data, T>::value>::Perform(data);
} }
// {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);
// Returns if we need to throw when an error occurs. This infers the language
// mode based on the current context and the closure. This returns true if the
// language mode is strict.
V8_EXPORT bool ShouldThrowOnError(v8::internal::Isolate* isolate);
// A base class for backing stores, which is needed due to vagaries of // A base class for backing stores, which is needed due to vagaries of
// how static casts work with std::shared_ptr. // how static casts work with std::shared_ptr.
class BackingStoreBase {}; class BackingStoreBase {};
......
...@@ -11359,8 +11359,7 @@ void* Object::GetAlignedPointerFromInternalField(int index) { ...@@ -11359,8 +11359,7 @@ void* Object::GetAlignedPointerFromInternalField(int index) {
instance_type == I::kJSApiObjectType || instance_type == I::kJSApiObjectType ||
instance_type == I::kJSSpecialApiObjectType)) { instance_type == I::kJSSpecialApiObjectType)) {
int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index); int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
internal::Isolate* isolate = internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj);
internal::IsolateFromNeverReadOnlySpaceObject(obj);
A value = I::ReadExternalPointerField(isolate, obj, offset); A value = I::ReadExternalPointerField(isolate, obj, offset);
return reinterpret_cast<void*>(value); return reinterpret_cast<void*>(value);
} }
...@@ -11392,8 +11391,7 @@ String::ExternalStringResource* String::GetExternalStringResource() const { ...@@ -11392,8 +11391,7 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
ExternalStringResource* result; ExternalStringResource* result;
if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) { if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
internal::Isolate* isolate = internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj);
internal::IsolateFromNeverReadOnlySpaceObject(obj);
A value = A value =
I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset); I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset);
result = reinterpret_cast<String::ExternalStringResource*>(value); result = reinterpret_cast<String::ExternalStringResource*>(value);
...@@ -11417,8 +11415,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBase( ...@@ -11417,8 +11415,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
ExternalStringResourceBase* resource; ExternalStringResourceBase* resource;
if (type == I::kExternalOneByteRepresentationTag || if (type == I::kExternalOneByteRepresentationTag ||
type == I::kExternalTwoByteRepresentationTag) { type == I::kExternalTwoByteRepresentationTag) {
internal::Isolate* isolate = internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj);
internal::IsolateFromNeverReadOnlySpaceObject(obj);
A value = A value =
I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset); I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset);
resource = reinterpret_cast<ExternalStringResourceBase*>(value); resource = reinterpret_cast<ExternalStringResourceBase*>(value);
...@@ -12000,8 +11997,7 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) { ...@@ -12000,8 +11997,7 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) {
I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset); I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
int value_offset = int value_offset =
I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index); I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject( internal::Isolate* isolate = I::GetIsolateForHeapSandbox(ctx);
*reinterpret_cast<A*>(this));
return reinterpret_cast<void*>( return reinterpret_cast<void*>(
I::ReadExternalPointerField(isolate, embedder_data, value_offset)); I::ReadExternalPointerField(isolate, embedder_data, value_offset));
#else #else
......
...@@ -5410,8 +5410,7 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const { ...@@ -5410,8 +5410,7 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
} }
if (i::StringShape(str).IsExternalTwoByte()) { if (i::StringShape(str).IsExternalTwoByte()) {
internal::Isolate* isolate = internal::Isolate* isolate = I::GetIsolateForHeapSandbox(str.ptr());
internal::IsolateFromNeverReadOnlySpaceObject(str.ptr());
internal::Address value = I::ReadExternalPointerField( internal::Address value = I::ReadExternalPointerField(
isolate, str.ptr(), I::kStringResourceOffset); isolate, str.ptr(), I::kStringResourceOffset);
return reinterpret_cast<String::ExternalStringResource*>(value); return reinterpret_cast<String::ExternalStringResource*>(value);
...@@ -5435,8 +5434,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow( ...@@ -5435,8 +5434,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask); *encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
if (i::StringShape(str).IsExternalOneByte() || if (i::StringShape(str).IsExternalOneByte() ||
i::StringShape(str).IsExternalTwoByte()) { i::StringShape(str).IsExternalTwoByte()) {
internal::Isolate* isolate = internal::Isolate* isolate = I::GetIsolateForHeapSandbox(string);
internal::IsolateFromNeverReadOnlySpaceObject(string);
internal::Address value = internal::Address value =
I::ReadExternalPointerField(isolate, string, I::kStringResourceOffset); I::ReadExternalPointerField(isolate, string, I::kStringResourceOffset);
resource = reinterpret_cast<ExternalStringResourceBase*>(value); resource = reinterpret_cast<ExternalStringResourceBase*>(value);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment