diff options
Diffstat (limited to 'runtime/verifier')
| -rw-r--r-- | runtime/verifier/method_verifier.cc | 58 | ||||
| -rw-r--r-- | runtime/verifier/method_verifier.h | 23 | ||||
| -rw-r--r-- | runtime/verifier/method_verifier_test.cc | 2 | ||||
| -rw-r--r-- | runtime/verifier/verifier_deps.cc | 22 |
4 files changed, 55 insertions, 50 deletions
diff --git a/runtime/verifier/method_verifier.cc b/runtime/verifier/method_verifier.cc index 0b33a0b3c0..167982124c 100644 --- a/runtime/verifier/method_verifier.cc +++ b/runtime/verifier/method_verifier.cc @@ -158,7 +158,7 @@ FailureKind MethodVerifier::VerifyClass(Thread* self, bool early_failure = false; std::string failure_message; const DexFile& dex_file = klass->GetDexFile(); - const DexFile::ClassDef* class_def = klass->GetClassDef(); + const dex::ClassDef* class_def = klass->GetClassDef(); ObjPtr<mirror::Class> super = klass->GetSuperClass(); std::string temp; if (super == nullptr && strcmp("Ljava/lang/Object;", klass->GetDescriptor(&temp)) != 0) { @@ -210,7 +210,7 @@ FailureKind MethodVerifier::VerifyClass(Thread* self, const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def, + const dex::ClassDef& class_def, CompilerCallbacks* callbacks, bool allow_soft_failures, HardFailLogMode log_level, @@ -319,8 +319,8 @@ MethodVerifier::FailureData MethodVerifier::VerifyMethod(Thread* self, const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def, - const DexFile::CodeItem* code_item, + const dex::ClassDef& class_def, + const dex::CodeItem* code_item, ArtMethod* method, uint32_t method_access_flags, CompilerCallbacks* callbacks, @@ -462,8 +462,8 @@ MethodVerifier* MethodVerifier::VerifyMethodAndDump(Thread* self, const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def, - const DexFile::CodeItem* code_item, + const dex::ClassDef& class_def, + const dex::CodeItem* code_item, ArtMethod* method, uint32_t method_access_flags, uint32_t api_level) { @@ -500,8 +500,8 @@ MethodVerifier::MethodVerifier(Thread* self, const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def, - const DexFile::CodeItem* code_item, + const dex::ClassDef& class_def, + const dex::CodeItem* code_item, uint32_t dex_method_idx, ArtMethod* method, uint32_t method_access_flags, @@ -602,7 +602,7 @@ void MethodVerifier::FindLocksAtDexPc() { bool MethodVerifier::Verify() { // Some older code doesn't correctly mark constructors as such. Test for this case by looking at // the name. - const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); + const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); const char* method_name = dex_file_->StringDataByIdx(method_id.name_idx_); bool instance_constructor_by_name = strcmp("<init>", method_name) == 0; bool static_constructor_by_name = strcmp("<clinit>", method_name) == 0; @@ -917,7 +917,7 @@ bool MethodVerifier::ScanTryCatchBlocks() { return true; } const uint32_t insns_size = code_item_accessor_.InsnsSizeInCodeUnits(); - for (const DexFile::TryItem& try_item : code_item_accessor_.TryItems()) { + for (const dex::TryItem& try_item : code_item_accessor_.TryItems()) { const uint32_t start = try_item.start_addr_; const uint32_t end = start + try_item.insn_count_; if ((start >= end) || (start >= insns_size) || (end > insns_size)) { @@ -1637,7 +1637,7 @@ bool MethodVerifier::SetTypesFromSignature() { cur_arg++; } - const DexFile::ProtoId& proto_id = + const dex::ProtoId& proto_id = dex_file_->GetMethodPrototype(dex_file_->GetMethodId(dex_method_idx_)); DexFileParameterIterator iterator(*dex_file_, proto_id); @@ -1876,7 +1876,7 @@ bool MethodVerifier::CodeFlowVerifyMethod() { // Returns the index of the first final instance field of the given class, or kDexNoIndex if there // is no such field. static uint32_t GetFirstFinalInstanceFieldIndex(const DexFile& dex_file, dex::TypeIndex type_idx) { - const DexFile::ClassDef* class_def = dex_file.FindClassDef(type_idx); + const dex::ClassDef* class_def = dex_file.FindClassDef(type_idx); DCHECK(class_def != nullptr); ClassAccessor accessor(dex_file, *class_def); for (const ClassAccessor::Field& field : accessor.GetInstanceFields()) { @@ -2885,7 +2885,7 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { } if (return_type == nullptr) { uint32_t method_idx = GetMethodIdxOfInvoke(inst); - const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); + const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx); dex::TypeIndex return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; const char* descriptor = dex_file_->StringByTypeIdx(return_type_idx); @@ -2908,7 +2908,7 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { const RegType* return_type = nullptr; if (called_method == nullptr) { uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); - const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); + const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx); is_constructor = strcmp("<init>", dex_file_->StringDataByIdx(method_id.name_idx_)) == 0; dex::TypeIndex return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; @@ -2986,7 +2986,7 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { const char* descriptor; if (called_method == nullptr) { uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); - const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); + const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx); dex::TypeIndex return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; descriptor = dex_file_->StringByTypeIdx(return_type_idx); @@ -3041,7 +3041,7 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { const char* descriptor; if (abs_method == nullptr) { uint32_t method_idx = (is_range) ? inst->VRegB_3rc() : inst->VRegB_35c(); - const DexFile::MethodId& method_id = dex_file_->GetMethodId(method_idx); + const dex::MethodId& method_id = dex_file_->GetMethodId(method_idx); dex::TypeIndex return_type_idx = dex_file_->GetProtoId(method_id.proto_idx_).return_type_idx_; descriptor = dex_file_->StringByTypeIdx(return_type_idx); @@ -3106,7 +3106,7 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { // method handle produced by step 1. The dex file verifier has checked ranges for // the first three arguments and CheckCallSite has checked the method handle type. const dex::ProtoIndex proto_idx = dex_file_->GetProtoIndexForCallSite(call_site_idx); - const DexFile::ProtoId& proto_id = dex_file_->GetProtoId(proto_idx); + const dex::ProtoId& proto_id = dex_file_->GetProtoId(proto_idx); DexFileParameterIterator param_it(*dex_file_, proto_id); // Treat method as static as it has yet to be determined. VerifyInvocationArgsFromIterator(¶m_it, inst, METHOD_STATIC, is_range, nullptr); @@ -3497,7 +3497,7 @@ bool MethodVerifier::CodeFlowVerifyInstruction(uint32_t* start_guess) { */ if ((opcode_flags & Instruction::kThrow) != 0 && GetInstructionFlags(work_insn_idx_).IsInTry()) { bool has_catch_all_handler = false; - const DexFile::TryItem* try_item = code_item_accessor_.FindTryItem(work_insn_idx_); + const dex::TryItem* try_item = code_item_accessor_.FindTryItem(work_insn_idx_); CHECK(try_item != nullptr); CatchHandlerIterator iterator(code_item_accessor_, *try_item); @@ -3749,7 +3749,7 @@ const RegType& MethodVerifier::GetCaughtExceptionType() { ArtMethod* MethodVerifier::ResolveMethodAndCheckAccess( uint32_t dex_method_idx, MethodType method_type) { - const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx); + const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx); const RegType& klass_type = ResolveClass<CheckAccess::kYes>(method_id.class_idx_); if (klass_type.IsConflict()) { std::string append(" in attempt to access method "); @@ -4093,7 +4093,7 @@ bool MethodVerifier::CheckCallSite(uint32_t call_site_idx) { } // Check method handle kind is valid. - const DexFile::MethodHandleItem& mh = dex_file_->GetMethodHandle(index[0]); + const dex::MethodHandleItem& mh = dex_file_->GetMethodHandle(index[0]); if (mh.method_handle_type_ != static_cast<uint16_t>(DexFile::MethodHandleType::kInvokeStatic)) { Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Call site #" << call_site_idx << " argument 0 method handle type is not InvokeStatic: " @@ -4125,7 +4125,7 @@ class MethodParamListDescriptorIterator { private: ArtMethod* res_method_; size_t pos_; - const DexFile::TypeList* params_; + const dex::TypeList* params_; const size_t params_size_; }; @@ -4231,7 +4231,7 @@ bool MethodVerifier::CheckSignaturePolymorphicMethod(ArtMethod* method) { return false; } - const DexFile::TypeList* types = method->GetParameterTypeList(); + const dex::TypeList* types = method->GetParameterTypeList(); if (types->Size() != 1) { Fail(VERIFY_ERROR_BAD_CLASS_HARD) << "Signature polymorphic method has too many arguments " << types->Size() << " != 1"; @@ -4553,7 +4553,7 @@ void MethodVerifier::VerifyAPut(const Instruction* inst, } ArtField* MethodVerifier::GetStaticField(int field_idx) { - const DexFile::FieldId& field_id = dex_file_->GetFieldId(field_idx); + const dex::FieldId& field_id = dex_file_->GetFieldId(field_idx); // Check access to class const RegType& klass_type = ResolveClass<CheckAccess::kYes>(field_id.class_idx_); if (klass_type.IsConflict()) { // bad class @@ -4596,7 +4596,7 @@ ArtField* MethodVerifier::GetStaticField(int field_idx) { } ArtField* MethodVerifier::GetInstanceField(const RegType& obj_type, int field_idx) { - const DexFile::FieldId& field_id = dex_file_->GetFieldId(field_idx); + const dex::FieldId& field_id = dex_file_->GetFieldId(field_idx); // Check access to class. const RegType& klass_type = ResolveClass<CheckAccess::kYes>(field_id.class_idx_); if (klass_type.IsConflict()) { @@ -4756,7 +4756,7 @@ void MethodVerifier::VerifyISFieldAccess(const Instruction* inst, const RegType& // // Note: see b/34966607. This and above may be changed in the future. if (kAccType == FieldAccessType::kAccPut) { - const DexFile::FieldId& field_id = dex_file_->GetFieldId(field_idx); + const dex::FieldId& field_id = dex_file_->GetFieldId(field_idx); const char* field_class_descriptor = dex_file_->GetFieldDeclaringClassDescriptor(field_id); const RegType* field_class_type = ®_types_.FromDescriptor(GetClassLoader(), field_class_descriptor, @@ -4772,7 +4772,7 @@ void MethodVerifier::VerifyISFieldAccess(const Instruction* inst, const RegType& } } if (field_type == nullptr) { - const DexFile::FieldId& field_id = dex_file_->GetFieldId(field_idx); + const dex::FieldId& field_id = dex_file_->GetFieldId(field_idx); const char* descriptor = dex_file_->GetFieldTypeDescriptor(field_id); field_type = ®_types_.FromDescriptor(GetClassLoader(), descriptor, false); } @@ -4935,8 +4935,8 @@ const RegType& MethodVerifier::GetMethodReturnType() { } } if (return_type_ == nullptr) { - const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); - const DexFile::ProtoId& proto_id = dex_file_->GetMethodPrototype(method_id); + const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); + const dex::ProtoId& proto_id = dex_file_->GetMethodPrototype(method_id); dex::TypeIndex return_type_idx = proto_id.return_type_idx_; const char* descriptor = dex_file_->GetTypeDescriptor(dex_file_->GetTypeId(return_type_idx)); return_type_ = ®_types_.FromDescriptor(GetClassLoader(), descriptor, false); @@ -4947,7 +4947,7 @@ const RegType& MethodVerifier::GetMethodReturnType() { const RegType& MethodVerifier::GetDeclaringClass() { if (declaring_class_ == nullptr) { - const DexFile::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); + const dex::MethodId& method_id = dex_file_->GetMethodId(dex_method_idx_); const char* descriptor = dex_file_->GetTypeDescriptor(dex_file_->GetTypeId(method_id.class_idx_)); if (method_being_verified_ != nullptr) { diff --git a/runtime/verifier/method_verifier.h b/runtime/verifier/method_verifier.h index eef22807ec..c178df05a4 100644 --- a/runtime/verifier/method_verifier.h +++ b/runtime/verifier/method_verifier.h @@ -26,7 +26,6 @@ #include "base/scoped_arena_containers.h" #include "base/value_object.h" #include "dex/code_item_accessors.h" -#include "dex/dex_file.h" #include "dex/dex_file_types.h" #include "dex/method_reference.h" #include "handle.h" @@ -39,11 +38,17 @@ namespace art { class ClassLinker; class CompilerCallbacks; +class DexFile; class Instruction; struct ReferenceMap2Visitor; class Thread; class VariableIndentationOutputStream; +namespace dex { +struct ClassDef; +struct CodeItem; +} // namespace dex + namespace mirror { class DexCache; } // namespace mirror @@ -107,7 +112,7 @@ class MethodVerifier { const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def, + const dex::ClassDef& class_def, CompilerCallbacks* callbacks, bool allow_soft_failures, HardFailLogMode log_level, @@ -121,8 +126,8 @@ class MethodVerifier { const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def, - const DexFile::CodeItem* code_item, ArtMethod* method, + const dex::ClassDef& class_def, + const dex::CodeItem* code_item, ArtMethod* method, uint32_t method_access_flags, uint32_t api_level) REQUIRES_SHARED(Locks::mutator_lock_); @@ -238,8 +243,8 @@ class MethodVerifier { const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def, - const DexFile::CodeItem* code_item, + const dex::ClassDef& class_def, + const dex::CodeItem* code_item, uint32_t method_idx, ArtMethod* method, uint32_t access_flags, @@ -297,8 +302,8 @@ class MethodVerifier { const DexFile* dex_file, Handle<mirror::DexCache> dex_cache, Handle<mirror::ClassLoader> class_loader, - const DexFile::ClassDef& class_def_idx, - const DexFile::CodeItem* code_item, + const dex::ClassDef& class_def_idx, + const dex::CodeItem* code_item, ArtMethod* method, uint32_t method_access_flags, CompilerCallbacks* callbacks, @@ -716,7 +721,7 @@ class MethodVerifier { Handle<mirror::DexCache> dex_cache_ GUARDED_BY(Locks::mutator_lock_); // The class loader for the declaring class of the method. Handle<mirror::ClassLoader> class_loader_ GUARDED_BY(Locks::mutator_lock_); - const DexFile::ClassDef& class_def_; // The class def of the declaring class of the method. + const dex::ClassDef& class_def_; // The class def of the declaring class of the method. const CodeItemDataAccessor code_item_accessor_; const RegType* declaring_class_; // Lazily computed reg type of the method's declaring class. // Instruction widths and flags, one entry per code unit. diff --git a/runtime/verifier/method_verifier_test.cc b/runtime/verifier/method_verifier_test.cc index 7519257cae..36890a6382 100644 --- a/runtime/verifier/method_verifier_test.cc +++ b/runtime/verifier/method_verifier_test.cc @@ -57,7 +57,7 @@ class MethodVerifierTest : public CommonRuntimeTest { REQUIRES_SHARED(Locks::mutator_lock_) { // Verify all the classes defined in this file for (size_t i = 0; i < dex.NumClassDefs(); i++) { - const DexFile::ClassDef& class_def = dex.GetClassDef(i); + const dex::ClassDef& class_def = dex.GetClassDef(i); const char* descriptor = dex.GetClassDescriptor(class_def); VerifyClass(descriptor); } diff --git a/runtime/verifier/verifier_deps.cc b/runtime/verifier/verifier_deps.cc index d346a95e82..bdcadd9fa6 100644 --- a/runtime/verifier/verifier_deps.cc +++ b/runtime/verifier/verifier_deps.cc @@ -99,9 +99,9 @@ dex::StringIndex VerifierDeps::GetClassDescriptorStringId(const DexFile& dex_fil DCHECK(dex_cache != nullptr) << klass->PrettyClass(); if (dex_cache->GetDexFile() == &dex_file) { // FindStringId is slow, try to go through the class def if we have one. - const DexFile::ClassDef* class_def = klass->GetClassDef(); + const dex::ClassDef* class_def = klass->GetClassDef(); DCHECK(class_def != nullptr) << klass->PrettyClass(); - const DexFile::TypeId& type_id = dex_file.GetTypeId(class_def->class_idx_); + const dex::TypeId& type_id = dex_file.GetTypeId(class_def->class_idx_); if (kIsDebugBuild) { std::string temp; CHECK_EQ(GetIdFromString(dex_file, klass->GetDescriptor(&temp)), type_id.descriptor_idx_); @@ -119,9 +119,9 @@ static dex::StringIndex TryGetClassDescriptorStringId(const DexFile& dex_file, ObjPtr<mirror::Class> klass) REQUIRES_SHARED(Locks::mutator_lock_) { if (!klass->IsArrayClass()) { - const DexFile::TypeId& type_id = dex_file.GetTypeId(type_idx); + const dex::TypeId& type_id = dex_file.GetTypeId(type_idx); const DexFile& klass_dex = klass->GetDexFile(); - const DexFile::TypeId& klass_type_id = klass_dex.GetTypeId(klass->GetClassDef()->class_idx_); + const dex::TypeId& klass_type_id = klass_dex.GetTypeId(klass->GetClassDef()->class_idx_); if (strcmp(dex_file.GetTypeDescriptor(type_id), klass_dex.GetTypeDescriptor(klass_type_id)) == 0) { return type_id.descriptor_idx_; @@ -201,7 +201,7 @@ static bool FindExistingStringId(const std::vector<std::string>& strings, } dex::StringIndex VerifierDeps::GetIdFromString(const DexFile& dex_file, const std::string& str) { - const DexFile::StringId* string_id = dex_file.FindStringId(str.c_str()); + const dex::StringId* string_id = dex_file.FindStringId(str.c_str()); if (string_id != nullptr) { // String is in the DEX file. Return its ID. return dex_file.GetIndexForStringId(*string_id); @@ -805,7 +805,7 @@ void VerifierDeps::Dump(VariableIndentationOutputStream* vios) const { } for (const FieldResolution& entry : dep.second->fields_) { - const DexFile::FieldId& field_id = dex_file.GetFieldId(entry.GetDexFieldIndex()); + const dex::FieldId& field_id = dex_file.GetFieldId(entry.GetDexFieldIndex()); vios->Stream() << dex_file.GetFieldDeclaringClassDescriptor(field_id) << "->" << dex_file.GetFieldName(field_id) << ":" @@ -823,7 +823,7 @@ void VerifierDeps::Dump(VariableIndentationOutputStream* vios) const { } for (const MethodResolution& method : dep.second->methods_) { - const DexFile::MethodId& method_id = dex_file.GetMethodId(method.GetDexMethodIndex()); + const dex::MethodId& method_id = dex_file.GetMethodId(method.GetDexMethodIndex()); vios->Stream() << dex_file.GetMethodDeclaringClassDescriptor(method_id) << "->" << dex_file.GetMethodName(method_id) @@ -949,7 +949,7 @@ bool VerifierDeps::VerifyClasses(Handle<mirror::ClassLoader> class_loader, } static std::string GetFieldDescription(const DexFile& dex_file, uint32_t index) { - const DexFile::FieldId& field_id = dex_file.GetFieldId(index); + const dex::FieldId& field_id = dex_file.GetFieldId(index); return std::string(dex_file.GetFieldDeclaringClassDescriptor(field_id)) + "->" + dex_file.GetFieldName(field_id) @@ -965,7 +965,7 @@ bool VerifierDeps::VerifyFields(Handle<mirror::ClassLoader> class_loader, // and have the same recorded flags. ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); for (const auto& entry : fields) { - const DexFile::FieldId& field_id = dex_file.GetFieldId(entry.GetDexFieldIndex()); + const dex::FieldId& field_id = dex_file.GetFieldId(entry.GetDexFieldIndex()); StringPiece name(dex_file.StringDataByIdx(field_id.name_idx_)); StringPiece type(dex_file.StringDataByIdx(dex_file.GetTypeId(field_id.type_idx_).descriptor_idx_)); // Only use field_id.class_idx_ when the entry is unresolved, which is rare. @@ -1011,7 +1011,7 @@ bool VerifierDeps::VerifyFields(Handle<mirror::ClassLoader> class_loader, } static std::string GetMethodDescription(const DexFile& dex_file, uint32_t index) { - const DexFile::MethodId& method_id = dex_file.GetMethodId(index); + const dex::MethodId& method_id = dex_file.GetMethodId(index); return std::string(dex_file.GetMethodDeclaringClassDescriptor(method_id)) + "->" + dex_file.GetMethodName(method_id) @@ -1026,7 +1026,7 @@ bool VerifierDeps::VerifyMethods(Handle<mirror::ClassLoader> class_loader, PointerSize pointer_size = class_linker->GetImagePointerSize(); for (const auto& entry : methods) { - const DexFile::MethodId& method_id = dex_file.GetMethodId(entry.GetDexMethodIndex()); + const dex::MethodId& method_id = dex_file.GetMethodId(entry.GetDexMethodIndex()); const char* name = dex_file.GetMethodName(method_id); const Signature signature = dex_file.GetMethodSignature(method_id); |
