• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2011 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_RUNTIME_VERIFIER_CLASS_VERIFIER_H_
18 #define ART_RUNTIME_VERIFIER_CLASS_VERIFIER_H_
19 
20 #include <string>
21 
22 #include <android-base/macros.h>
23 #include <android-base/thread_annotations.h>
24 
25 #include "base/locks.h"
26 #include "handle.h"
27 #include "obj_ptr.h"
28 #include "verifier/method_verifier.h"
29 #include "verifier/reg_type_cache.h"
30 #include "verifier_enums.h"
31 
32 namespace art {
33 
34 class ClassLinker;
35 class CompilerCallbacks;
36 class DexFile;
37 class RootVisitor;
38 class Thread;
39 
40 namespace dex {
41 struct ClassDef;
42 }  // namespace dex
43 
44 namespace mirror {
45 class Class;
46 class DexCache;
47 class ClassLoader;
48 }  // namespace mirror
49 
50 namespace verifier {
51 
52 // Verifier that ensures the complete class is OK.
53 class ClassVerifier {
54  public:
55   // Redo verification on a loaded class. This is for use by class redefinition. This must be called
56   // with all methods already having all of kAccDontCompile and kAccCountLocks and not having
57   // kAccSkipAccessChecks. This will remove some of these flags from the method. The caller must
58   // ensure this cannot race with other changes to the verification class flags.
59   static FailureKind ReverifyClass(Thread* self,
60                                    ObjPtr<mirror::Class> klass,
61                                    HardFailLogMode log_level,
62                                    uint32_t api_level,
63                                    std::string* error)
64       REQUIRES_SHARED(Locks::mutator_lock_);
65   // Verify a class. Returns "kNoFailure" on success.
66   static FailureKind VerifyClass(Thread* self,
67                                  ObjPtr<mirror::Class> klass,
68                                  CompilerCallbacks* callbacks,
69                                  bool allow_soft_failures,
70                                  HardFailLogMode log_level,
71                                  uint32_t api_level,
72                                  std::string* error)
73       REQUIRES_SHARED(Locks::mutator_lock_);
74   static FailureKind VerifyClass(Thread* self,
75                                  const DexFile* dex_file,
76                                  Handle<mirror::DexCache> dex_cache,
77                                  Handle<mirror::ClassLoader> class_loader,
78                                  const dex::ClassDef& class_def,
79                                  CompilerCallbacks* callbacks,
80                                  bool allow_soft_failures,
81                                  HardFailLogMode log_level,
82                                  uint32_t api_level,
83                                  std::string* error)
84       REQUIRES_SHARED(Locks::mutator_lock_);
85 
86   static void Init(ClassLinker* class_linker) REQUIRES_SHARED(Locks::mutator_lock_);
87   static void Shutdown();
88 
89   static void VisitStaticRoots(RootVisitor* visitor)
90       REQUIRES_SHARED(Locks::mutator_lock_);
91 
92  private:
93   static FailureKind CommonVerifyClass(Thread* self,
94                                        ObjPtr<mirror::Class> klass,
95                                        CompilerCallbacks* callbacks,
96                                        VerifierCallback* verifier_callback,
97                                        bool allow_soft_failures,
98                                        HardFailLogMode log_level,
99                                        uint32_t api_level,
100                                        std::string* error)
101       REQUIRES_SHARED(Locks::mutator_lock_);
102 
103   static FailureKind VerifyClass(Thread* self,
104                                  const DexFile* dex_file,
105                                  Handle<mirror::DexCache> dex_cache,
106                                  Handle<mirror::ClassLoader> class_loader,
107                                  const dex::ClassDef& class_def,
108                                  CompilerCallbacks* callbacks,
109                                  VerifierCallback* verifier_callback,
110                                  bool allow_soft_failures,
111                                  HardFailLogMode log_level,
112                                  uint32_t api_level,
113                                  std::string* error)
114       REQUIRES_SHARED(Locks::mutator_lock_);
115   DISALLOW_COPY_AND_ASSIGN(ClassVerifier);
116 };
117 
118 }  // namespace verifier
119 }  // namespace art
120 
121 #endif  // ART_RUNTIME_VERIFIER_CLASS_VERIFIER_H_
122