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) {
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
* is necessary to implement inline functions in the v8 api. Don't
......@@ -339,17 +348,25 @@ class Internals {
#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(
internal::Isolate* isolate, internal::Address heap_object_ptr,
int offset) {
#ifdef V8_COMPRESS_POINTERS
internal::Address value = ReadRawField<Address>(heap_object_ptr, offset);
#ifdef V8_HEAP_SANDBOX
// We currently have to treat zero as nullptr in embedder slots.
if (value) value = DecodeExternalPointer(isolate, value);
return value;
#else
return ReadRawField<internal::Address>(heap_object_ptr, offset);
#endif
return value;
}
#ifdef V8_COMPRESS_POINTERS
......@@ -406,15 +423,6 @@ V8_INLINE void PerformCastCheck(T* 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
// how static casts work with std::shared_ptr.
class BackingStoreBase {};
......
......@@ -11359,8 +11359,7 @@ void* Object::GetAlignedPointerFromInternalField(int index) {
instance_type == I::kJSApiObjectType ||
instance_type == I::kJSSpecialApiObjectType)) {
int offset = I::kJSObjectHeaderSize + (I::kEmbedderDataSlotSize * index);
internal::Isolate* isolate =
internal::IsolateFromNeverReadOnlySpaceObject(obj);
internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj);
A value = I::ReadExternalPointerField(isolate, obj, offset);
return reinterpret_cast<void*>(value);
}
......@@ -11392,8 +11391,7 @@ String::ExternalStringResource* String::GetExternalStringResource() const {
ExternalStringResource* result;
if (I::IsExternalTwoByteString(I::GetInstanceType(obj))) {
internal::Isolate* isolate =
internal::IsolateFromNeverReadOnlySpaceObject(obj);
internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj);
A value =
I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset);
result = reinterpret_cast<String::ExternalStringResource*>(value);
......@@ -11417,8 +11415,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBase(
ExternalStringResourceBase* resource;
if (type == I::kExternalOneByteRepresentationTag ||
type == I::kExternalTwoByteRepresentationTag) {
internal::Isolate* isolate =
internal::IsolateFromNeverReadOnlySpaceObject(obj);
internal::Isolate* isolate = I::GetIsolateForHeapSandbox(obj);
A value =
I::ReadExternalPointerField(isolate, obj, I::kStringResourceOffset);
resource = reinterpret_cast<ExternalStringResourceBase*>(value);
......@@ -12000,8 +11997,7 @@ void* Context::GetAlignedPointerFromEmbedderData(int index) {
I::ReadTaggedPointerField(ctx, I::kNativeContextEmbedderDataOffset);
int value_offset =
I::kEmbedderDataArrayHeaderSize + (I::kEmbedderDataSlotSize * index);
internal::Isolate* isolate = internal::IsolateFromNeverReadOnlySpaceObject(
*reinterpret_cast<A*>(this));
internal::Isolate* isolate = I::GetIsolateForHeapSandbox(ctx);
return reinterpret_cast<void*>(
I::ReadExternalPointerField(isolate, embedder_data, value_offset));
#else
......
......@@ -5410,8 +5410,7 @@ String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
}
if (i::StringShape(str).IsExternalTwoByte()) {
internal::Isolate* isolate =
internal::IsolateFromNeverReadOnlySpaceObject(str.ptr());
internal::Isolate* isolate = I::GetIsolateForHeapSandbox(str.ptr());
internal::Address value = I::ReadExternalPointerField(
isolate, str.ptr(), I::kStringResourceOffset);
return reinterpret_cast<String::ExternalStringResource*>(value);
......@@ -5435,8 +5434,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
if (i::StringShape(str).IsExternalOneByte() ||
i::StringShape(str).IsExternalTwoByte()) {
internal::Isolate* isolate =
internal::IsolateFromNeverReadOnlySpaceObject(string);
internal::Isolate* isolate = I::GetIsolateForHeapSandbox(string);
internal::Address value =
I::ReadExternalPointerField(isolate, string, I::kStringResourceOffset);
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