Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(297)

Side by Side Diff: src/api.cc

Issue 1312553003: [heap] Prevent direct access to ExternalStringTable. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@local_cleanup-heap-root-set-1
Patch Set: Addressed comments. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/extensions/externalize-string-extension.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/api.h" 5 #include "src/api.h"
6 6
7 #include <string.h> // For memcpy, strlen. 7 #include <string.h> // For memcpy, strlen.
8 #ifdef V8_USE_ADDRESS_SANITIZER 8 #ifdef V8_USE_ADDRESS_SANITIZER
9 #include <sanitizer/asan_interface.h> 9 #include <sanitizer/asan_interface.h>
10 #endif // V8_USE_ADDRESS_SANITIZER 10 #endif // V8_USE_ADDRESS_SANITIZER
(...skipping 5767 matching lines...) Expand 10 before | Expand all | Expand 10 after
5778 // TODO(dcarney): throw a context free exception. 5778 // TODO(dcarney): throw a context free exception.
5779 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) { 5779 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) {
5780 return MaybeLocal<String>(); 5780 return MaybeLocal<String>();
5781 } 5781 }
5782 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 5782 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5783 ENTER_V8(i_isolate); 5783 ENTER_V8(i_isolate);
5784 LOG_API(i_isolate, "String::NewExternalTwoByte"); 5784 LOG_API(i_isolate, "String::NewExternalTwoByte");
5785 i::Handle<i::String> string = i_isolate->factory() 5785 i::Handle<i::String> string = i_isolate->factory()
5786 ->NewExternalStringFromTwoByte(resource) 5786 ->NewExternalStringFromTwoByte(resource)
5787 .ToHandleChecked(); 5787 .ToHandleChecked();
5788 i_isolate->heap()->external_string_table()->AddString(*string); 5788 i_isolate->heap()->RegisterExternalString(*string);
5789 return Utils::ToLocal(string); 5789 return Utils::ToLocal(string);
5790 } 5790 }
5791 5791
5792 5792
5793 Local<String> v8::String::NewExternal( 5793 Local<String> v8::String::NewExternal(
5794 Isolate* isolate, v8::String::ExternalStringResource* resource) { 5794 Isolate* isolate, v8::String::ExternalStringResource* resource) {
5795 RETURN_TO_LOCAL_UNCHECKED(NewExternalTwoByte(isolate, resource), String); 5795 RETURN_TO_LOCAL_UNCHECKED(NewExternalTwoByte(isolate, resource), String);
5796 } 5796 }
5797 5797
5798 5798
5799 MaybeLocal<String> v8::String::NewExternalOneByte( 5799 MaybeLocal<String> v8::String::NewExternalOneByte(
5800 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { 5800 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
5801 CHECK(resource && resource->data()); 5801 CHECK(resource && resource->data());
5802 // TODO(dcarney): throw a context free exception. 5802 // TODO(dcarney): throw a context free exception.
5803 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) { 5803 if (resource->length() > static_cast<size_t>(i::String::kMaxLength)) {
5804 return MaybeLocal<String>(); 5804 return MaybeLocal<String>();
5805 } 5805 }
5806 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 5806 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
5807 ENTER_V8(i_isolate); 5807 ENTER_V8(i_isolate);
5808 LOG_API(i_isolate, "String::NewExternalOneByte"); 5808 LOG_API(i_isolate, "String::NewExternalOneByte");
5809 i::Handle<i::String> string = i_isolate->factory() 5809 i::Handle<i::String> string = i_isolate->factory()
5810 ->NewExternalStringFromOneByte(resource) 5810 ->NewExternalStringFromOneByte(resource)
5811 .ToHandleChecked(); 5811 .ToHandleChecked();
5812 i_isolate->heap()->external_string_table()->AddString(*string); 5812 i_isolate->heap()->RegisterExternalString(*string);
5813 return Utils::ToLocal(string); 5813 return Utils::ToLocal(string);
5814 } 5814 }
5815 5815
5816 5816
5817 Local<String> v8::String::NewExternal( 5817 Local<String> v8::String::NewExternal(
5818 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) { 5818 Isolate* isolate, v8::String::ExternalOneByteStringResource* resource) {
5819 RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String); 5819 RETURN_TO_LOCAL_UNCHECKED(NewExternalOneByte(isolate, resource), String);
5820 } 5820 }
5821 5821
5822 5822
5823 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) { 5823 bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
5824 i::Handle<i::String> obj = Utils::OpenHandle(this); 5824 i::Handle<i::String> obj = Utils::OpenHandle(this);
5825 i::Isolate* isolate = obj->GetIsolate(); 5825 i::Isolate* isolate = obj->GetIsolate();
5826 if (i::StringShape(*obj).IsExternal()) { 5826 if (i::StringShape(*obj).IsExternal()) {
5827 return false; // Already an external string. 5827 return false; // Already an external string.
5828 } 5828 }
5829 ENTER_V8(isolate); 5829 ENTER_V8(isolate);
5830 if (isolate->heap()->IsInGCPostProcessing()) { 5830 if (isolate->heap()->IsInGCPostProcessing()) {
5831 return false; 5831 return false;
5832 } 5832 }
5833 CHECK(resource && resource->data()); 5833 CHECK(resource && resource->data());
5834 5834
5835 bool result = obj->MakeExternal(resource); 5835 bool result = obj->MakeExternal(resource);
5836 // Assert that if CanMakeExternal(), then externalizing actually succeeds. 5836 // Assert that if CanMakeExternal(), then externalizing actually succeeds.
5837 DCHECK(!CanMakeExternal() || result); 5837 DCHECK(!CanMakeExternal() || result);
5838 if (result) { 5838 if (result) {
5839 DCHECK(obj->IsExternalString()); 5839 DCHECK(obj->IsExternalString());
5840 isolate->heap()->external_string_table()->AddString(*obj); 5840 isolate->heap()->RegisterExternalString(*obj);
5841 } 5841 }
5842 return result; 5842 return result;
5843 } 5843 }
5844 5844
5845 5845
5846 bool v8::String::MakeExternal( 5846 bool v8::String::MakeExternal(
5847 v8::String::ExternalOneByteStringResource* resource) { 5847 v8::String::ExternalOneByteStringResource* resource) {
5848 i::Handle<i::String> obj = Utils::OpenHandle(this); 5848 i::Handle<i::String> obj = Utils::OpenHandle(this);
5849 i::Isolate* isolate = obj->GetIsolate(); 5849 i::Isolate* isolate = obj->GetIsolate();
5850 if (i::StringShape(*obj).IsExternal()) { 5850 if (i::StringShape(*obj).IsExternal()) {
5851 return false; // Already an external string. 5851 return false; // Already an external string.
5852 } 5852 }
5853 ENTER_V8(isolate); 5853 ENTER_V8(isolate);
5854 if (isolate->heap()->IsInGCPostProcessing()) { 5854 if (isolate->heap()->IsInGCPostProcessing()) {
5855 return false; 5855 return false;
5856 } 5856 }
5857 CHECK(resource && resource->data()); 5857 CHECK(resource && resource->data());
5858 5858
5859 bool result = obj->MakeExternal(resource); 5859 bool result = obj->MakeExternal(resource);
5860 // Assert that if CanMakeExternal(), then externalizing actually succeeds. 5860 // Assert that if CanMakeExternal(), then externalizing actually succeeds.
5861 DCHECK(!CanMakeExternal() || result); 5861 DCHECK(!CanMakeExternal() || result);
5862 if (result) { 5862 if (result) {
5863 DCHECK(obj->IsExternalString()); 5863 DCHECK(obj->IsExternalString());
5864 isolate->heap()->external_string_table()->AddString(*obj); 5864 isolate->heap()->RegisterExternalString(*obj);
5865 } 5865 }
5866 return result; 5866 return result;
5867 } 5867 }
5868 5868
5869 5869
5870 bool v8::String::CanMakeExternal() { 5870 bool v8::String::CanMakeExternal() {
5871 i::Handle<i::String> obj = Utils::OpenHandle(this); 5871 i::Handle<i::String> obj = Utils::OpenHandle(this);
5872 i::Isolate* isolate = obj->GetIsolate(); 5872 i::Isolate* isolate = obj->GetIsolate();
5873 5873
5874 // Old space strings should be externalized. 5874 // Old space strings should be externalized.
(...skipping 2533 matching lines...) Expand 10 before | Expand all | Expand 10 after
8408 Address callback_address = 8408 Address callback_address =
8409 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); 8409 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback));
8410 VMState<EXTERNAL> state(isolate); 8410 VMState<EXTERNAL> state(isolate);
8411 ExternalCallbackScope call_scope(isolate, callback_address); 8411 ExternalCallbackScope call_scope(isolate, callback_address);
8412 callback(info); 8412 callback(info);
8413 } 8413 }
8414 8414
8415 8415
8416 } // namespace internal 8416 } // namespace internal
8417 } // namespace v8 8417 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/extensions/externalize-string-extension.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698