Skip to content

Commit

Permalink
[ubsan] Port Name/String/Symbol to the new design
Browse files Browse the repository at this point in the history
Bug: v8:3770
Change-Id: I4da6404aa968adca1fbb49029fc304622101d6c3
Reviewed-on: https://chromium-review.googlesource.com/c/1349112
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Yang Guo <yangguo@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Michael Starzinger <mstarzinger@chromium.org>
Cr-Commit-Position: refs/heads/master@{#57853}
  • Loading branch information
jakobkummerow authored and Commit Bot committed Nov 27, 2018
1 parent fe0d265 commit 0f581e4
Show file tree
Hide file tree
Showing 158 changed files with 1,043 additions and 1,001 deletions.
63 changes: 30 additions & 33 deletions src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2411,9 +2411,9 @@ class IsIdentifierHelper {
public:
IsIdentifierHelper() : is_identifier_(false), first_char_(true) {}

bool Check(i::String* string) {
i::ConsString* cons_string = i::String::VisitFlat(this, string, 0);
if (cons_string == nullptr) return is_identifier_;
bool Check(i::String string) {
i::ConsString cons_string = i::String::VisitFlat(this, string, 0);
if (cons_string.is_null()) return is_identifier_;
// We don't support cons strings here.
return false;
}
Expand Down Expand Up @@ -5203,9 +5203,9 @@ static inline const uint16_t* Align(const uint16_t* chars) {
class ContainsOnlyOneByteHelper {
public:
ContainsOnlyOneByteHelper() : is_one_byte_(true) {}
bool Check(i::String* string) {
i::ConsString* cons_string = i::String::VisitFlat(this, string, 0);
if (cons_string == nullptr) return is_one_byte_;
bool Check(i::String string) {
i::ConsString cons_string = i::String::VisitFlat(this, string, 0);
if (cons_string.is_null()) return is_one_byte_;
return CheckCons(cons_string);
}
void VisitOneByteString(const uint8_t* chars, int length) {
Expand Down Expand Up @@ -5244,20 +5244,18 @@ class ContainsOnlyOneByteHelper {
}

private:
bool CheckCons(i::ConsString* cons_string) {
bool CheckCons(i::ConsString cons_string) {
while (true) {
// Check left side if flat.
i::String* left = cons_string->first();
i::ConsString* left_as_cons =
i::String::VisitFlat(this, left, 0);
i::String left = cons_string->first();
i::ConsString left_as_cons = i::String::VisitFlat(this, left, 0);
if (!is_one_byte_) return false;
// Check right side if flat.
i::String* right = cons_string->second();
i::ConsString* right_as_cons =
i::String::VisitFlat(this, right, 0);
i::String right = cons_string->second();
i::ConsString right_as_cons = i::String::VisitFlat(this, right, 0);
if (!is_one_byte_) return false;
// Standard recurse/iterate trick.
if (left_as_cons != nullptr && right_as_cons != nullptr) {
if (!left_as_cons.is_null() && !right_as_cons.is_null()) {
if (left->length() < right->length()) {
CheckCons(left_as_cons);
cons_string = right_as_cons;
Expand All @@ -5270,12 +5268,12 @@ class ContainsOnlyOneByteHelper {
continue;
}
// Descend left in place.
if (left_as_cons != nullptr) {
if (!left_as_cons.is_null()) {
cons_string = left_as_cons;
continue;
}
// Descend right in place.
if (right_as_cons != nullptr) {
if (!right_as_cons.is_null()) {
cons_string = right_as_cons;
continue;
}
Expand Down Expand Up @@ -5499,16 +5497,16 @@ class Utf8WriterVisitor {
DISALLOW_IMPLICIT_CONSTRUCTORS(Utf8WriterVisitor);
};


static bool RecursivelySerializeToUtf8(i::String* current,
// TODO(yangguo): Simplify this. We can now expect the string to be flat.
static bool RecursivelySerializeToUtf8(i::String current,
Utf8WriterVisitor* writer,
int recursion_budget) {
while (!writer->IsDone()) {
i::ConsString* cons_string = i::String::VisitFlat(writer, current);
if (cons_string == nullptr) return true; // Leaf node.
i::ConsString cons_string = i::String::VisitFlat(writer, current);
if (cons_string.is_null()) return true; // Leaf node.
if (recursion_budget <= 0) return false;
// Must write the left branch first.
i::String* first = cons_string->first();
i::String first = cons_string->first();
bool success = RecursivelySerializeToUtf8(first,
writer,
recursion_budget - 1);
Expand Down Expand Up @@ -5615,7 +5613,7 @@ bool v8::String::IsExternalOneByte() const {
void v8::String::VerifyExternalStringResource(
v8::String::ExternalStringResource* value) const {
i::DisallowHeapAllocation no_allocation;
i::String* str = *Utils::OpenHandle(this);
i::String str = *Utils::OpenHandle(this);
const v8::String::ExternalStringResource* expected;

if (str->IsThinString()) {
Expand All @@ -5634,7 +5632,7 @@ void v8::String::VerifyExternalStringResource(
void v8::String::VerifyExternalStringResourceBase(
v8::String::ExternalStringResourceBase* value, Encoding encoding) const {
i::DisallowHeapAllocation no_allocation;
i::String* str = *Utils::OpenHandle(this);
i::String str = *Utils::OpenHandle(this);
const v8::String::ExternalStringResourceBase* expected;
Encoding expectedEncoding;

Expand Down Expand Up @@ -5662,15 +5660,14 @@ void v8::String::VerifyExternalStringResourceBase(
String::ExternalStringResource* String::GetExternalStringResourceSlow() const {
i::DisallowHeapAllocation no_allocation;
typedef internal::Internals I;
i::String* str = *Utils::OpenHandle(this);
i::String str = *Utils::OpenHandle(this);

if (str->IsThinString()) {
str = i::ThinString::cast(str)->actual();
}

if (i::StringShape(str).IsExternalTwoByte()) {
void* value = I::ReadField<void*>(reinterpret_cast<i::Address>(str),
I::kStringResourceOffset);
void* value = I::ReadField<void*>(str.ptr(), I::kStringResourceOffset);
return reinterpret_cast<String::ExternalStringResource*>(value);
}
return nullptr;
Expand All @@ -5681,13 +5678,13 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
i::DisallowHeapAllocation no_allocation;
typedef internal::Internals I;
ExternalStringResourceBase* resource = nullptr;
i::String* str = *Utils::OpenHandle(this);
i::String str = *Utils::OpenHandle(this);

if (str->IsThinString()) {
str = i::ThinString::cast(str)->actual();
}

internal::Address string = reinterpret_cast<internal::Address>(str);
internal::Address string = str.ptr();
int type = I::GetInstanceType(string) & I::kFullStringRepresentationMask;
*encoding_out = static_cast<Encoding>(type & I::kStringEncodingMask);
if (i::StringShape(str).IsExternalOneByte() ||
Expand All @@ -5701,7 +5698,7 @@ String::ExternalStringResourceBase* String::GetExternalStringResourceBaseSlow(
const v8::String::ExternalOneByteStringResource*
v8::String::GetExternalOneByteStringResource() const {
i::DisallowHeapAllocation no_allocation;
i::String* str = *Utils::OpenHandle(this);
i::String str = *Utils::OpenHandle(this);
if (i::StringShape(str).IsExternalOneByte()) {
return i::ExternalOneByteString::cast(str)->resource();
} else if (str->IsThinString()) {
Expand Down Expand Up @@ -6620,7 +6617,7 @@ Local<String> v8::String::NewExternal(
bool v8::String::MakeExternal(v8::String::ExternalStringResource* resource) {
i::DisallowHeapAllocation no_allocation;

i::String* obj = *Utils::OpenHandle(this);
i::String obj = *Utils::OpenHandle(this);

if (obj->IsThinString()) {
obj = i::ThinString::cast(obj)->actual();
Expand Down Expand Up @@ -6649,7 +6646,7 @@ bool v8::String::MakeExternal(
v8::String::ExternalOneByteStringResource* resource) {
i::DisallowHeapAllocation no_allocation;

i::String* obj = *Utils::OpenHandle(this);
i::String obj = *Utils::OpenHandle(this);

if (obj->IsThinString()) {
obj = i::ThinString::cast(obj)->actual();
Expand All @@ -6676,7 +6673,7 @@ bool v8::String::MakeExternal(

bool v8::String::CanMakeExternal() {
i::DisallowHeapAllocation no_allocation;
i::String* obj = *Utils::OpenHandle(this);
i::String obj = *Utils::OpenHandle(this);

if (obj->IsThinString()) {
obj = i::ThinString::cast(obj)->actual();
Expand Down Expand Up @@ -9762,7 +9759,7 @@ void debug::GlobalLexicalScopeNames(
i::Handle<i::ScopeInfo> scope_info(context->scope_info(), isolate);
int local_count = scope_info->ContextLocalCount();
for (int j = 0; j < local_count; ++j) {
i::String* name = scope_info->ContextLocalName(j);
i::String name = scope_info->ContextLocalName(j);
if (i::ScopeInfo::VariableIsSynthetic(name)) continue;
names->Append(Utils::ToLocal(handle(name, isolate)));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ast/scopes.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ Scope* Scope::DeserializeScopeChain(Isolate* isolate, Zone* zone,
DCHECK_EQ(scope_info->ContextLocalCount(), 1);
DCHECK_EQ(scope_info->ContextLocalMode(0), VariableMode::kVar);
DCHECK_EQ(scope_info->ContextLocalInitFlag(0), kCreatedInitialized);
String* name = scope_info->ContextLocalName(0);
String name = scope_info->ContextLocalName(0);
MaybeAssignedFlag maybe_assigned =
scope_info->ContextLocalMaybeAssignedFlag(0);
outer_scope = new (zone)
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void SourceCodeCache::Iterate(RootVisitor* v) {
bool SourceCodeCache::Lookup(Isolate* isolate, Vector<const char> name,
Handle<SharedFunctionInfo>* handle) {
for (int i = 0; i < cache_->length(); i += 2) {
SeqOneByteString* str = SeqOneByteString::cast(cache_->get(i));
SeqOneByteString str = SeqOneByteString::cast(cache_->get(i));
if (str->IsUtf8EqualTo(name)) {
*handle = Handle<SharedFunctionInfo>(
SharedFunctionInfo::cast(cache_->get(i + 1)), isolate);
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace v8 {
namespace internal {

// A SourceCodeCache uses a FixedArray to store pairs of
// (OneByteString*, JSFunction*), mapping names of native code files
// (OneByteString, JSFunction*), mapping names of native code files
// (array.js, etc.) to precompiled functions. Instead of mapping
// names to functions it might make sense to let the JS2C tool
// generate an index for each native JS file.
Expand Down
6 changes: 3 additions & 3 deletions src/builtins/builtins-array-gen.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ class ArrayBuiltinsAssembler : public CodeStubAssembler {
TNode<ExternalReference> isolate_ptr =
ExternalConstant(ExternalReference::isolate_address(isolate()));
return UncheckedCast<String>(
CallCFunction5(MachineType::AnyTagged(), // <return> String*
CallCFunction5(MachineType::AnyTagged(), // <return> String
MachineType::Pointer(), // Isolate*
MachineType::AnyTagged(), // FixedArray fixed_array
MachineType::IntPtr(), // intptr_t length
MachineType::AnyTagged(), // String* sep
MachineType::AnyTagged(), // String* dest
MachineType::AnyTagged(), // String sep
MachineType::AnyTagged(), // String dest
func, isolate_ptr, fixed_array, length, sep, dest));
}

Expand Down
10 changes: 3 additions & 7 deletions src/builtins/builtins-intl-gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,18 @@ TF_BUILTIN(StringToLowerCaseIntl, IntlBuiltinsAssembler) {
}

// Call into C for case conversion. The signature is:
// Object* ConvertOneByteToLower(String* src, String* dst, Isolate* isolate);
// String ConvertOneByteToLower(String src, String dst);
BIND(&call_c);
{
Node* const src = to_direct.string();

Node* const function_addr =
ExternalConstant(ExternalReference::intl_convert_one_byte_to_lower());
Node* const isolate_ptr =
ExternalConstant(ExternalReference::isolate_address(isolate()));

MachineType type_ptr = MachineType::Pointer();
MachineType type_tagged = MachineType::AnyTagged();

Node* const result =
CallCFunction3(type_tagged, type_tagged, type_tagged, type_ptr,
function_addr, src, dst, isolate_ptr);
Node* const result = CallCFunction2(type_tagged, type_tagged, type_tagged,
function_addr, src, dst);

Return(result);
}
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/builtins-string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ inline bool ToUpperOverflows(uc32 character) {

template <class Converter>
V8_WARN_UNUSED_RESULT static Object* ConvertCaseHelper(
Isolate* isolate, String* string, SeqString* result, int result_length,
Isolate* isolate, String string, SeqString result, int result_length,
unibrow::Mapping<Converter, 128>* mapping) {
DisallowHeapAllocation no_gc;
// We try this twice, once with the assumption that the result is no longer
Expand Down
30 changes: 16 additions & 14 deletions src/code-events.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "src/base/platform/mutex.h"
#include "src/globals.h"
#include "src/objects/code.h"
#include "src/objects/name.h"
#include "src/objects/string.h"
#include "src/vector.h"

namespace v8 {
Expand Down Expand Up @@ -72,18 +74,18 @@ class CodeEventListener {
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
const char* comment) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
Name* name) = 0;
Name name) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo* shared, Name* source) = 0;
SharedFunctionInfo* shared, Name source) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo* shared, Name* source,
SharedFunctionInfo* shared, Name source,
int line, int column) = 0;
virtual void CodeCreateEvent(LogEventsAndTags tag, const wasm::WasmCode* code,
wasm::WasmName name) = 0;
virtual void CallbackEvent(Name* name, Address entry_point) = 0;
virtual void GetterCallbackEvent(Name* name, Address entry_point) = 0;
virtual void SetterCallbackEvent(Name* name, Address entry_point) = 0;
virtual void RegExpCodeCreateEvent(AbstractCode code, String* source) = 0;
virtual void CallbackEvent(Name name, Address entry_point) = 0;
virtual void GetterCallbackEvent(Name name, Address entry_point) = 0;
virtual void SetterCallbackEvent(Name name, Address entry_point) = 0;
virtual void RegExpCodeCreateEvent(AbstractCode code, String source) = 0;
virtual void CodeMoveEvent(AbstractCode from, AbstractCode to) = 0;
virtual void SharedFunctionInfoMoveEvent(Address from, Address to) = 0;
virtual void CodeMovingGCEvent() = 0;
Expand Down Expand Up @@ -126,15 +128,15 @@ class CodeEventDispatcher {
const char* comment) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, comment));
}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code, Name* name) {
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code, Name name) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo* shared, Name* name) {
SharedFunctionInfo* shared, Name name) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, shared, name));
}
void CodeCreateEvent(LogEventsAndTags tag, AbstractCode code,
SharedFunctionInfo* shared, Name* source, int line,
SharedFunctionInfo* shared, Name source, int line,
int column) {
CODE_EVENT_DISPATCH(
CodeCreateEvent(tag, code, shared, source, line, column));
Expand All @@ -143,16 +145,16 @@ class CodeEventDispatcher {
wasm::WasmName name) {
CODE_EVENT_DISPATCH(CodeCreateEvent(tag, code, name));
}
void CallbackEvent(Name* name, Address entry_point) {
void CallbackEvent(Name name, Address entry_point) {
CODE_EVENT_DISPATCH(CallbackEvent(name, entry_point));
}
void GetterCallbackEvent(Name* name, Address entry_point) {
void GetterCallbackEvent(Name name, Address entry_point) {
CODE_EVENT_DISPATCH(GetterCallbackEvent(name, entry_point));
}
void SetterCallbackEvent(Name* name, Address entry_point) {
void SetterCallbackEvent(Name name, Address entry_point) {
CODE_EVENT_DISPATCH(SetterCallbackEvent(name, entry_point));
}
void RegExpCodeCreateEvent(AbstractCode code, String* source) {
void RegExpCodeCreateEvent(AbstractCode code, String source) {
CODE_EVENT_DISPATCH(RegExpCodeCreateEvent(code, source));
}
void CodeMoveEvent(AbstractCode from, AbstractCode to) {
Expand Down
12 changes: 6 additions & 6 deletions src/compiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ void LogFunctionCompilation(CodeEventListener::LogEventsAndTags tag,

int line_num = Script::GetLineNumber(script, shared->StartPosition()) + 1;
int column_num = Script::GetColumnNumber(script, shared->StartPosition()) + 1;
String* script_name = script->name()->IsString()
? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string();
String script_name = script->name()->IsString()
? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string();
CodeEventListener::LogEventsAndTags log_tag =
Logger::ToNativeByScript(tag, *script);
PROFILE(isolate, CodeCreateEvent(log_tag, *abstract_code, *shared,
Expand Down Expand Up @@ -331,9 +331,9 @@ void InstallBytecodeArray(Handle<BytecodeArray> bytecode_array,
Script::GetLineNumber(script, shared_info->StartPosition()) + 1;
int column_num =
Script::GetColumnNumber(script, shared_info->StartPosition()) + 1;
String* script_name = script->name()->IsString()
? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string();
String script_name = script->name()->IsString()
? String::cast(script->name())
: ReadOnlyRoots(isolate).empty_string();
CodeEventListener::LogEventsAndTags log_tag = Logger::ToNativeByScript(
CodeEventListener::INTERPRETED_FUNCTION_TAG, *script);
PROFILE(isolate, CodeCreateEvent(log_tag, *abstract_code, *shared_info,
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/code-assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1930,9 +1930,10 @@ CodeAssemblerScopedExceptionHandler::~CodeAssemblerScopedExceptionHandler() {

} // namespace compiler

Address CheckObjectType(Object* value, Address raw_type, String* location) {
Address CheckObjectType(Object* value, Address raw_type, Address raw_location) {
#ifdef DEBUG
Smi type(raw_type);
String location = String::cast(ObjectPtr(raw_location));
const char* expected;
switch (static_cast<ObjectType>(type->value())) {
#define TYPE_CASE(Name) \
Expand Down
7 changes: 5 additions & 2 deletions src/compiler/code-assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ namespace internal {
// Forward declarations.
class AsmWasmData;
class AsyncGeneratorRequest;
class BigInt;
class CallInterfaceDescriptor;
class Callable;
class Factory;
Expand Down Expand Up @@ -331,8 +332,10 @@ HEAP_OBJECT_TEMPLATE_TYPE_LIST(OBJECT_TYPE_TEMPLATE_CASE)
#undef OBJECT_TYPE_STRUCT_CASE
#undef OBJECT_TYPE_TEMPLATE_CASE

// {raw_type} must be a tagged Smi. The return value is also a tagged Smi.
Address CheckObjectType(Object* value, Address raw_type, String* location);
// {raw_type} must be a tagged Smi.
// {raw_location} must be a tagged String.
// Returns a tagged Smi.
Address CheckObjectType(Object* value, Address raw_type, Address raw_location);

namespace compiler {

Expand Down
Loading

0 comments on commit 0f581e4

Please sign in to comment.