Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 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_SRC_VERIFIER_METHOD_VERIFIER_H_ |
| 18 | #define ART_SRC_VERIFIER_METHOD_VERIFIER_H_ |
| 19 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 20 | #include <set> |
| 21 | #include <vector> |
| 22 | |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 23 | #include "base/casts.h" |
Elliott Hughes | 7616005 | 2012-12-12 16:31:20 -0800 | [diff] [blame] | 24 | #include "base/macros.h" |
Elliott Hughes | 1aa246d | 2012-12-13 09:29:36 -0800 | [diff] [blame] | 25 | #include "base/stl_util.h" |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 26 | #include "compiler/driver/compiler_driver.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 27 | #include "dex_file.h" |
| 28 | #include "dex_instruction.h" |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 29 | #include "instruction_flags.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 30 | #include "mirror/object.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 31 | #include "reg_type.h" |
| 32 | #include "reg_type_cache.h" |
| 33 | #include "register_line.h" |
| 34 | #include "safe_map.h" |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 35 | #include "UniquePtr.h" |
| 36 | |
| 37 | namespace art { |
| 38 | |
| 39 | struct ReferenceMap2Visitor; |
| 40 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 41 | namespace verifier { |
| 42 | |
| 43 | class MethodVerifier; |
Ian Rogers | 46c6bb2 | 2012-09-18 13:47:36 -0700 | [diff] [blame] | 44 | class DexPcToReferenceMap; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 45 | |
| 46 | /* |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 47 | * "Direct" and "virtual" methods are stored independently. The type of call used to invoke the |
| 48 | * method determines which list we search, and whether we travel up into superclasses. |
| 49 | * |
| 50 | * (<clinit>, <init>, and methods declared "private" or "static" are stored in the "direct" list. |
| 51 | * All others are stored in the "virtual" list.) |
| 52 | */ |
| 53 | enum MethodType { |
| 54 | METHOD_UNKNOWN = 0, |
| 55 | METHOD_DIRECT, // <init>, private |
| 56 | METHOD_STATIC, // static |
| 57 | METHOD_VIRTUAL, // virtual, super |
| 58 | METHOD_INTERFACE // interface |
| 59 | }; |
Ian Rogers | 2fc1427 | 2012-08-30 10:56:57 -0700 | [diff] [blame] | 60 | std::ostream& operator<<(std::ostream& os, const MethodType& rhs); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 61 | |
| 62 | /* |
| 63 | * An enumeration of problems that can turn up during verification. |
| 64 | * Both VERIFY_ERROR_BAD_CLASS_SOFT and VERIFY_ERROR_BAD_CLASS_HARD denote failures that cause |
| 65 | * the entire class to be rejected. However, VERIFY_ERROR_BAD_CLASS_SOFT denotes a soft failure |
| 66 | * that can potentially be corrected, and the verifier will try again at runtime. |
| 67 | * VERIFY_ERROR_BAD_CLASS_HARD denotes a hard failure that can't be corrected, and will cause |
| 68 | * the class to remain uncompiled. Other errors denote verification errors that cause bytecode |
| 69 | * to be rewritten to fail at runtime. |
| 70 | */ |
| 71 | enum VerifyError { |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 72 | VERIFY_ERROR_BAD_CLASS_HARD, // VerifyError; hard error that skips compilation. |
| 73 | VERIFY_ERROR_BAD_CLASS_SOFT, // VerifyError; soft error that verifies again at runtime. |
| 74 | |
| 75 | VERIFY_ERROR_NO_CLASS, // NoClassDefFoundError. |
| 76 | VERIFY_ERROR_NO_FIELD, // NoSuchFieldError. |
| 77 | VERIFY_ERROR_NO_METHOD, // NoSuchMethodError. |
| 78 | VERIFY_ERROR_ACCESS_CLASS, // IllegalAccessError. |
| 79 | VERIFY_ERROR_ACCESS_FIELD, // IllegalAccessError. |
| 80 | VERIFY_ERROR_ACCESS_METHOD, // IllegalAccessError. |
| 81 | VERIFY_ERROR_CLASS_CHANGE, // IncompatibleClassChangeError. |
| 82 | VERIFY_ERROR_INSTANTIATION, // InstantiationError. |
| 83 | }; |
| 84 | std::ostream& operator<<(std::ostream& os, const VerifyError& rhs); |
| 85 | |
| 86 | /* |
| 87 | * Identifies the type of reference in the instruction that generated the verify error |
| 88 | * (e.g. VERIFY_ERROR_ACCESS_CLASS could come from a method, field, or class reference). |
| 89 | * |
| 90 | * This must fit in two bits. |
| 91 | */ |
| 92 | enum VerifyErrorRefType { |
| 93 | VERIFY_ERROR_REF_CLASS = 0, |
| 94 | VERIFY_ERROR_REF_FIELD = 1, |
| 95 | VERIFY_ERROR_REF_METHOD = 2, |
| 96 | }; |
| 97 | const int kVerifyErrorRefTypeShift = 6; |
| 98 | |
| 99 | // We don't need to store the register data for many instructions, because we either only need |
| 100 | // it at branch points (for verification) or GC points and branches (for verification + |
| 101 | // type-precise register analysis). |
| 102 | enum RegisterTrackingMode { |
| 103 | kTrackRegsBranches, |
| 104 | kTrackRegsGcPoints, |
| 105 | kTrackRegsAll, |
| 106 | }; |
| 107 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 108 | // A mapping from a dex pc to the register line statuses as they are immediately prior to the |
| 109 | // execution of that instruction. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 110 | class PcToRegisterLineTable { |
| 111 | public: |
| 112 | PcToRegisterLineTable() {} |
| 113 | ~PcToRegisterLineTable() { |
| 114 | STLDeleteValues(&pc_to_register_line_); |
| 115 | } |
| 116 | |
| 117 | // Initialize the RegisterTable. Every instruction address can have a different set of information |
| 118 | // about what's in which register, but for verification purposes we only need to store it at |
| 119 | // branch target addresses (because we merge into that). |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 120 | void Init(RegisterTrackingMode mode, InstructionFlags* flags, uint32_t insns_size, |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 121 | uint16_t registers_size, MethodVerifier* verifier); |
| 122 | |
| 123 | RegisterLine* GetLine(size_t idx) { |
| 124 | Table::iterator result = pc_to_register_line_.find(idx); // TODO: C++0x auto |
| 125 | if (result == pc_to_register_line_.end()) { |
| 126 | return NULL; |
| 127 | } else { |
| 128 | return result->second; |
| 129 | } |
| 130 | } |
| 131 | |
| 132 | private: |
| 133 | typedef SafeMap<int32_t, RegisterLine*> Table; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 134 | Table pc_to_register_line_; |
| 135 | }; |
| 136 | |
| 137 | // The verifier |
| 138 | class MethodVerifier { |
| 139 | public: |
jeffhao | f1e6b7c | 2012-06-05 18:33:30 -0700 | [diff] [blame] | 140 | enum FailureKind { |
| 141 | kNoFailure, |
| 142 | kSoftFailure, |
| 143 | kHardFailure, |
| 144 | }; |
| 145 | |
| 146 | /* Verify a class. Returns "kNoFailure" on success. */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 147 | static FailureKind VerifyClass(const mirror::Class* klass, std::string& error) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 148 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 149 | static FailureKind VerifyClass(const DexFile* dex_file, mirror::DexCache* dex_cache, |
| 150 | mirror::ClassLoader* class_loader, uint32_t class_def_idx, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 151 | std::string& error) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 152 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 153 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 154 | static void VerifyMethodAndDump(std::ostream& os, uint32_t method_idx, const DexFile* dex_file, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 155 | mirror::DexCache* dex_cache, mirror::ClassLoader* class_loader, |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 156 | uint32_t class_def_idx, const DexFile::CodeItem* code_item, |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 157 | mirror::AbstractMethod* method, uint32_t method_access_flags) |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 158 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 159 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 160 | uint8_t EncodePcToReferenceMapData() const; |
| 161 | |
| 162 | uint32_t DexFileVersion() const { |
| 163 | return dex_file_->GetVersion(); |
| 164 | } |
| 165 | |
| 166 | RegTypeCache* GetRegTypeCache() { |
| 167 | return ®_types_; |
| 168 | } |
| 169 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 170 | // Log a verification failure. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 171 | std::ostream& Fail(VerifyError error); |
| 172 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 173 | // Log for verification information. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 174 | std::ostream& LogVerifyInfo() { |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 175 | return info_messages_ << "VFY: " << PrettyMethod(dex_method_idx_, *dex_file_) |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 176 | << '[' << reinterpret_cast<void*>(work_insn_idx_) << "] : "; |
| 177 | } |
| 178 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 179 | // Dump the failures encountered by the verifier. |
| 180 | std::ostream& DumpFailures(std::ostream& os); |
| 181 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 182 | // Dump the state of the verifier, namely each instruction, what flags are set on it, register |
| 183 | // information |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 184 | void Dump(std::ostream& os) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 185 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 186 | static const std::vector<uint8_t>* GetDexGcMap(CompilerDriver::MethodReference ref) |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 187 | LOCKS_EXCLUDED(dex_gc_maps_lock_); |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 188 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 189 | // Fills 'monitor_enter_dex_pcs' with the dex pcs of the monitor-enter instructions corresponding |
| 190 | // to the locks held at 'dex_pc' in 'm'. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 191 | static void FindLocksAtDexPc(mirror::AbstractMethod* m, uint32_t dex_pc, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 192 | std::vector<uint32_t>& monitor_enter_dex_pcs) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 193 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 194 | |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 195 | static void Init(); |
| 196 | static void Shutdown(); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 197 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 198 | static bool IsClassRejected(CompilerDriver::ClassReference ref) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 199 | LOCKS_EXCLUDED(rejected_classes_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 200 | |
Elliott Hughes | 4993bbc | 2013-01-10 15:41:25 -0800 | [diff] [blame] | 201 | bool CanLoadClasses() const { |
| 202 | return can_load_classes_; |
| 203 | } |
| 204 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 205 | MethodVerifier(const DexFile* dex_file, mirror::DexCache* dex_cache, |
| 206 | mirror::ClassLoader* class_loader, uint32_t class_def_idx, |
| 207 | const DexFile::CodeItem* code_item, |
| 208 | uint32_t method_idx, mirror::AbstractMethod* method, |
| 209 | uint32_t access_flags, bool can_load_classes) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 210 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 211 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 212 | // Run verification on the method. Returns true if verification completes and false if the input |
| 213 | // has an irrecoverable corruption. |
| 214 | bool Verify() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
| 215 | |
| 216 | // Describe VRegs at the given dex pc. |
| 217 | std::vector<int32_t> DescribeVRegs(uint32_t dex_pc); |
| 218 | |
| 219 | private: |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 220 | // Adds the given string to the beginning of the last failure message. |
| 221 | void PrependToLastFailMessage(std::string); |
| 222 | |
| 223 | // Adds the given string to the end of the last failure message. |
| 224 | void AppendToLastFailMessage(std::string); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 225 | |
| 226 | /* |
| 227 | * Perform verification on a single method. |
| 228 | * |
| 229 | * We do this in three passes: |
| 230 | * (1) Walk through all code units, determining instruction locations, |
| 231 | * widths, and other characteristics. |
| 232 | * (2) Walk through all code units, performing static checks on |
| 233 | * operands. |
| 234 | * (3) Iterate through the method, checking type safety and looking |
| 235 | * for code flow problems. |
Ian Rogers | e1758fe | 2012-04-19 11:31:15 -0700 | [diff] [blame] | 236 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 237 | static FailureKind VerifyMethod(uint32_t method_idx, const DexFile* dex_file, |
| 238 | mirror::DexCache* dex_cache, |
| 239 | mirror::ClassLoader* class_loader, uint32_t class_def_idx, |
| 240 | const DexFile::CodeItem* code_item, |
| 241 | mirror::AbstractMethod* method, uint32_t method_access_flags) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 242 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | e1758fe | 2012-04-19 11:31:15 -0700 | [diff] [blame] | 243 | |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 244 | void FindLocksAtDexPc() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 245 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 246 | /* |
| 247 | * Compute the width of the instruction at each address in the instruction stream, and store it in |
| 248 | * insn_flags_. Addresses that are in the middle of an instruction, or that are part of switch |
| 249 | * table data, are not touched (so the caller should probably initialize "insn_flags" to zero). |
| 250 | * |
| 251 | * The "new_instance_count_" and "monitor_enter_count_" fields in vdata are also set. |
| 252 | * |
| 253 | * Performs some static checks, notably: |
| 254 | * - opcode of first instruction begins at index 0 |
| 255 | * - only documented instructions may appear |
| 256 | * - each instruction follows the last |
| 257 | * - last byte of last instruction is at (code_length-1) |
| 258 | * |
| 259 | * Logs an error and returns "false" on failure. |
| 260 | */ |
| 261 | bool ComputeWidthsAndCountOps(); |
| 262 | |
| 263 | /* |
| 264 | * Set the "in try" flags for all instructions protected by "try" statements. Also sets the |
| 265 | * "branch target" flags for exception handlers. |
| 266 | * |
| 267 | * Call this after widths have been set in "insn_flags". |
| 268 | * |
| 269 | * Returns "false" if something in the exception table looks fishy, but we're expecting the |
| 270 | * exception table to be somewhat sane. |
| 271 | */ |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 272 | bool ScanTryCatchBlocks() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 273 | |
| 274 | /* |
| 275 | * Perform static verification on all instructions in a method. |
| 276 | * |
| 277 | * Walks through instructions in a method calling VerifyInstruction on each. |
| 278 | */ |
| 279 | bool VerifyInstructions(); |
| 280 | |
| 281 | /* |
| 282 | * Perform static verification on an instruction. |
| 283 | * |
| 284 | * As a side effect, this sets the "branch target" flags in InsnFlags. |
| 285 | * |
| 286 | * "(CF)" items are handled during code-flow analysis. |
| 287 | * |
| 288 | * v3 4.10.1 |
| 289 | * - target of each jump and branch instruction must be valid |
| 290 | * - targets of switch statements must be valid |
| 291 | * - operands referencing constant pool entries must be valid |
| 292 | * - (CF) operands of getfield, putfield, getstatic, putstatic must be valid |
| 293 | * - (CF) operands of method invocation instructions must be valid |
| 294 | * - (CF) only invoke-direct can call a method starting with '<' |
| 295 | * - (CF) <clinit> must never be called explicitly |
| 296 | * - operands of instanceof, checkcast, new (and variants) must be valid |
| 297 | * - new-array[-type] limited to 255 dimensions |
| 298 | * - can't use "new" on an array class |
| 299 | * - (?) limit dimensions in multi-array creation |
| 300 | * - local variable load/store register values must be in valid range |
| 301 | * |
| 302 | * v3 4.11.1.2 |
| 303 | * - branches must be within the bounds of the code array |
| 304 | * - targets of all control-flow instructions are the start of an instruction |
| 305 | * - register accesses fall within range of allocated registers |
| 306 | * - (N/A) access to constant pool must be of appropriate type |
| 307 | * - code does not end in the middle of an instruction |
| 308 | * - execution cannot fall off the end of the code |
| 309 | * - (earlier) for each exception handler, the "try" area must begin and |
| 310 | * end at the start of an instruction (end can be at the end of the code) |
| 311 | * - (earlier) for each exception handler, the handler must start at a valid |
| 312 | * instruction |
| 313 | */ |
| 314 | bool VerifyInstruction(const Instruction* inst, uint32_t code_offset); |
| 315 | |
| 316 | /* Ensure that the register index is valid for this code item. */ |
| 317 | bool CheckRegisterIndex(uint32_t idx); |
| 318 | |
| 319 | /* Ensure that the wide register index is valid for this code item. */ |
| 320 | bool CheckWideRegisterIndex(uint32_t idx); |
| 321 | |
| 322 | // Perform static checks on a field get or set instruction. All we do here is ensure that the |
| 323 | // field index is in the valid range. |
| 324 | bool CheckFieldIndex(uint32_t idx); |
| 325 | |
| 326 | // Perform static checks on a method invocation instruction. All we do here is ensure that the |
| 327 | // method index is in the valid range. |
| 328 | bool CheckMethodIndex(uint32_t idx); |
| 329 | |
| 330 | // Perform static checks on a "new-instance" instruction. Specifically, make sure the class |
| 331 | // reference isn't for an array class. |
| 332 | bool CheckNewInstance(uint32_t idx); |
| 333 | |
| 334 | /* Ensure that the string index is in the valid range. */ |
| 335 | bool CheckStringIndex(uint32_t idx); |
| 336 | |
| 337 | // Perform static checks on an instruction that takes a class constant. Ensure that the class |
| 338 | // index is in the valid range. |
| 339 | bool CheckTypeIndex(uint32_t idx); |
| 340 | |
| 341 | // Perform static checks on a "new-array" instruction. Specifically, make sure they aren't |
| 342 | // creating an array of arrays that causes the number of dimensions to exceed 255. |
| 343 | bool CheckNewArray(uint32_t idx); |
| 344 | |
| 345 | // Verify an array data table. "cur_offset" is the offset of the fill-array-data instruction. |
| 346 | bool CheckArrayData(uint32_t cur_offset); |
| 347 | |
| 348 | // Verify that the target of a branch instruction is valid. We don't expect code to jump directly |
| 349 | // into an exception handler, but it's valid to do so as long as the target isn't a |
| 350 | // "move-exception" instruction. We verify that in a later stage. |
| 351 | // The dex format forbids certain instructions from branching to themselves. |
Elliott Hughes | 24edeb5 | 2012-06-18 15:29:46 -0700 | [diff] [blame] | 352 | // Updates "insn_flags_", setting the "branch target" flag. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 353 | bool CheckBranchTarget(uint32_t cur_offset); |
| 354 | |
| 355 | // Verify a switch table. "cur_offset" is the offset of the switch instruction. |
Elliott Hughes | 24edeb5 | 2012-06-18 15:29:46 -0700 | [diff] [blame] | 356 | // Updates "insn_flags_", setting the "branch target" flag. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 357 | bool CheckSwitchTargets(uint32_t cur_offset); |
| 358 | |
| 359 | // Check the register indices used in a "vararg" instruction, such as invoke-virtual or |
| 360 | // filled-new-array. |
| 361 | // - vA holds word count (0-5), args[] have values. |
| 362 | // There are some tests we don't do here, e.g. we don't try to verify that invoking a method that |
| 363 | // takes a double is done with consecutive registers. This requires parsing the target method |
| 364 | // signature, which we will be doing later on during the code flow analysis. |
| 365 | bool CheckVarArgRegs(uint32_t vA, uint32_t arg[]); |
| 366 | |
| 367 | // Check the register indices used in a "vararg/range" instruction, such as invoke-virtual/range |
| 368 | // or filled-new-array/range. |
| 369 | // - vA holds word count, vC holds index of first reg. |
| 370 | bool CheckVarArgRangeRegs(uint32_t vA, uint32_t vC); |
| 371 | |
| 372 | // Extract the relative offset from a branch instruction. |
| 373 | // Returns "false" on failure (e.g. this isn't a branch instruction). |
| 374 | bool GetBranchOffset(uint32_t cur_offset, int32_t* pOffset, bool* pConditional, |
| 375 | bool* selfOkay); |
| 376 | |
| 377 | /* Perform detailed code-flow analysis on a single method. */ |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 378 | bool VerifyCodeFlow() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 379 | |
| 380 | // Set the register types for the first instruction in the method based on the method signature. |
| 381 | // This has the side-effect of validating the signature. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 382 | bool SetTypesFromSignature() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 383 | |
| 384 | /* |
| 385 | * Perform code flow on a method. |
| 386 | * |
| 387 | * The basic strategy is as outlined in v3 4.11.1.2: set the "changed" bit on the first |
| 388 | * instruction, process it (setting additional "changed" bits), and repeat until there are no |
| 389 | * more. |
| 390 | * |
| 391 | * v3 4.11.1.1 |
| 392 | * - (N/A) operand stack is always the same size |
| 393 | * - operand stack [registers] contain the correct types of values |
| 394 | * - local variables [registers] contain the correct types of values |
| 395 | * - methods are invoked with the appropriate arguments |
| 396 | * - fields are assigned using values of appropriate types |
| 397 | * - opcodes have the correct type values in operand registers |
| 398 | * - there is never an uninitialized class instance in a local variable in code protected by an |
| 399 | * exception handler (operand stack is okay, because the operand stack is discarded when an |
| 400 | * exception is thrown) [can't know what's a local var w/o the debug info -- should fall out of |
| 401 | * register typing] |
| 402 | * |
| 403 | * v3 4.11.1.2 |
| 404 | * - execution cannot fall off the end of the code |
| 405 | * |
| 406 | * (We also do many of the items described in the "static checks" sections, because it's easier to |
| 407 | * do them here.) |
| 408 | * |
| 409 | * We need an array of RegType values, one per register, for every instruction. If the method uses |
| 410 | * monitor-enter, we need extra data for every register, and a stack for every "interesting" |
| 411 | * instruction. In theory this could become quite large -- up to several megabytes for a monster |
| 412 | * function. |
| 413 | * |
| 414 | * NOTE: |
| 415 | * The spec forbids backward branches when there's an uninitialized reference in a register. The |
| 416 | * idea is to prevent something like this: |
| 417 | * loop: |
| 418 | * move r1, r0 |
| 419 | * new-instance r0, MyClass |
| 420 | * ... |
| 421 | * if-eq rN, loop // once |
| 422 | * initialize r0 |
| 423 | * |
| 424 | * This leaves us with two different instances, both allocated by the same instruction, but only |
| 425 | * one is initialized. The scheme outlined in v3 4.11.1.4 wouldn't catch this, so they work around |
| 426 | * it by preventing backward branches. We achieve identical results without restricting code |
| 427 | * reordering by specifying that you can't execute the new-instance instruction if a register |
| 428 | * contains an uninitialized instance created by that same instruction. |
| 429 | */ |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 430 | bool CodeFlowVerifyMethod() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 431 | |
| 432 | /* |
| 433 | * Perform verification for a single instruction. |
| 434 | * |
| 435 | * This requires fully decoding the instruction to determine the effect it has on registers. |
| 436 | * |
| 437 | * Finds zero or more following instructions and sets the "changed" flag if execution at that |
| 438 | * point needs to be (re-)evaluated. Register changes are merged into "reg_types_" at the target |
| 439 | * addresses. Does not set or clear any other flags in "insn_flags_". |
| 440 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 441 | bool CodeFlowVerifyInstruction(uint32_t* start_guess) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 442 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 443 | |
| 444 | // Perform verification of a new array instruction |
| 445 | void VerifyNewArray(const DecodedInstruction& dec_insn, bool is_filled, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 446 | bool is_range) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 447 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 448 | |
| 449 | // Perform verification of an aget instruction. The destination register's type will be set to |
| 450 | // be that of component type of the array unless the array type is unknown, in which case a |
| 451 | // bottom type inferred from the type of instruction is used. is_primitive is false for an |
| 452 | // aget-object. |
| 453 | void VerifyAGet(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 454 | bool is_primitive) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 455 | |
| 456 | // Perform verification of an aput instruction. |
| 457 | void VerifyAPut(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 458 | bool is_primitive) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 459 | |
| 460 | // Lookup instance field and fail for resolution violations |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 461 | mirror::Field* GetInstanceField(const RegType& obj_type, int field_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 462 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 463 | |
| 464 | // Lookup static field and fail for resolution violations |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 465 | mirror::Field* GetStaticField(int field_idx) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 466 | |
| 467 | // Perform verification of an iget or sget instruction. |
| 468 | void VerifyISGet(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 469 | bool is_primitive, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 470 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 471 | |
| 472 | // Perform verification of an iput or sput instruction. |
| 473 | void VerifyISPut(const DecodedInstruction& insn, const RegType& insn_type, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 474 | bool is_primitive, bool is_static) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 475 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 476 | |
| 477 | // Resolves a class based on an index and performs access checks to ensure the referrer can |
| 478 | // access the resolved class. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 479 | const RegType& ResolveClassAndCheckAccess(uint32_t class_idx) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 480 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 481 | |
| 482 | /* |
| 483 | * For the "move-exception" instruction at "work_insn_idx_", which must be at an exception handler |
| 484 | * address, determine the Join of all exceptions that can land here. Fails if no matching |
| 485 | * exception handler can be found or if the Join of exception types fails. |
| 486 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 487 | const RegType& GetCaughtExceptionType() |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 488 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 489 | |
| 490 | /* |
| 491 | * Resolves a method based on an index and performs access checks to ensure |
| 492 | * the referrer can access the resolved method. |
| 493 | * Does not throw exceptions. |
| 494 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 495 | mirror::AbstractMethod* ResolveMethodAndCheckAccess(uint32_t method_idx, MethodType method_type) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 496 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 497 | |
| 498 | /* |
| 499 | * Verify the arguments to a method. We're executing in "method", making |
| 500 | * a call to the method reference in vB. |
| 501 | * |
| 502 | * If this is a "direct" invoke, we allow calls to <init>. For calls to |
| 503 | * <init>, the first argument may be an uninitialized reference. Otherwise, |
| 504 | * calls to anything starting with '<' will be rejected, as will any |
| 505 | * uninitialized reference arguments. |
| 506 | * |
| 507 | * For non-static method calls, this will verify that the method call is |
| 508 | * appropriate for the "this" argument. |
| 509 | * |
| 510 | * The method reference is in vBBBB. The "is_range" parameter determines |
| 511 | * whether we use 0-4 "args" values or a range of registers defined by |
| 512 | * vAA and vCCCC. |
| 513 | * |
| 514 | * Widening conversions on integers and references are allowed, but |
| 515 | * narrowing conversions are not. |
| 516 | * |
| 517 | * Returns the resolved method on success, NULL on failure (with *failure |
| 518 | * set appropriately). |
| 519 | */ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 520 | mirror::AbstractMethod* VerifyInvocationArgs(const DecodedInstruction& dec_insn, |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 521 | MethodType method_type, bool is_range, bool is_super) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 522 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 523 | |
| 524 | /* |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 525 | * Verify that the target instruction is not "move-exception". It's important that the only way |
| 526 | * to execute a move-exception is as the first instruction of an exception handler. |
| 527 | * Returns "true" if all is well, "false" if the target instruction is move-exception. |
| 528 | */ |
| 529 | bool CheckNotMoveException(const uint16_t* insns, int insn_idx); |
| 530 | |
| 531 | /* |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 532 | * Control can transfer to "next_insn". Merge the registers from merge_line into the table at |
| 533 | * next_insn, and set the changed flag on the target address if any of the registers were changed. |
| 534 | * Returns "false" if an error is encountered. |
| 535 | */ |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 536 | bool UpdateRegisters(uint32_t next_insn, const RegisterLine* merge_line) |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 537 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 538 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 539 | // Is the method being verified a constructor? |
| 540 | bool IsConstructor() const { |
| 541 | return (method_access_flags_ & kAccConstructor) != 0; |
| 542 | } |
| 543 | |
| 544 | // Is the method verified static? |
| 545 | bool IsStatic() const { |
| 546 | return (method_access_flags_ & kAccStatic) != 0; |
| 547 | } |
| 548 | |
| 549 | // Return the register type for the method. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 550 | const RegType& GetMethodReturnType() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 551 | |
| 552 | // Get a type representing the declaring class of the method. |
Ian Rogers | b726dcb | 2012-09-05 08:57:23 -0700 | [diff] [blame] | 553 | const RegType& GetDeclaringClass() SHARED_LOCKS_REQUIRED(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 554 | |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 555 | /* |
| 556 | * Generate the GC map for a method that has just been verified (i.e. we're doing this as part of |
| 557 | * verification). For type-precise determination we have all the data we need, so we just need to |
| 558 | * encode it in some clever fashion. |
| 559 | * Returns a pointer to a newly-allocated RegisterMap, or NULL on failure. |
| 560 | */ |
| 561 | const std::vector<uint8_t>* GenerateGcMap(); |
| 562 | |
| 563 | // Verify that the GC map associated with method_ is well formed |
| 564 | void VerifyGcMap(const std::vector<uint8_t>& data); |
| 565 | |
| 566 | // Compute sizes for GC map data |
| 567 | void ComputeGcMapSizes(size_t* gc_points, size_t* ref_bitmap_bits, size_t* log2_max_gc_pc); |
| 568 | |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 569 | InstructionFlags* CurrentInsnFlags(); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 570 | |
| 571 | // All the GC maps that the verifier has created |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 572 | typedef SafeMap<const CompilerDriver::MethodReference, const std::vector<uint8_t>*> DexGcMapTable; |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 573 | static Mutex* dex_gc_maps_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
| 574 | static DexGcMapTable* dex_gc_maps_ GUARDED_BY(dex_gc_maps_lock_); |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 575 | static void SetDexGcMap(CompilerDriver::MethodReference ref, const std::vector<uint8_t>& dex_gc_map) |
Ian Rogers | 0c7abda | 2012-09-19 13:33:42 -0700 | [diff] [blame] | 576 | LOCKS_EXCLUDED(dex_gc_maps_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 577 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 578 | typedef std::set<CompilerDriver::ClassReference> RejectedClassesTable; |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 579 | static Mutex* rejected_classes_lock_ DEFAULT_MUTEX_ACQUIRED_AFTER; |
Elliott Hughes | 0a1038b | 2012-06-14 16:24:17 -0700 | [diff] [blame] | 580 | static RejectedClassesTable* rejected_classes_; |
| 581 | |
Ian Rogers | 1212a02 | 2013-03-04 10:48:41 -0800 | [diff] [blame^] | 582 | static void AddRejectedClass(CompilerDriver::ClassReference ref) |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 583 | LOCKS_EXCLUDED(rejected_classes_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 584 | |
| 585 | RegTypeCache reg_types_; |
| 586 | |
| 587 | PcToRegisterLineTable reg_table_; |
| 588 | |
| 589 | // Storage for the register status we're currently working on. |
| 590 | UniquePtr<RegisterLine> work_line_; |
| 591 | |
| 592 | // The address of the instruction we're currently working on, note that this is in 2 byte |
| 593 | // quantities |
| 594 | uint32_t work_insn_idx_; |
| 595 | |
| 596 | // Storage for the register status we're saving for later. |
| 597 | UniquePtr<RegisterLine> saved_line_; |
| 598 | |
Ian Rogers | 2bcb4a4 | 2012-11-08 10:39:18 -0800 | [diff] [blame] | 599 | uint32_t dex_method_idx_; // The method we're working on. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 600 | // Its object representation if known. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 601 | mirror::AbstractMethod* foo_method_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 602 | uint32_t method_access_flags_; // Method's access flags. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 603 | const DexFile* dex_file_; // The dex file containing the method. |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 604 | // The dex_cache for the declaring class of the method. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 605 | mirror::DexCache* dex_cache_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 00f7d0e | 2012-07-19 15:28:27 -0700 | [diff] [blame] | 606 | // The class loader for the declaring class of the method. |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 607 | mirror::ClassLoader* class_loader_ GUARDED_BY(Locks::mutator_lock_); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 608 | uint32_t class_def_idx_; // The class def index of the declaring class of the method. |
| 609 | const DexFile::CodeItem* code_item_; // The code item containing the code for the method. |
Ian Rogers | 7b3ddd2 | 2013-02-21 15:19:52 -0800 | [diff] [blame] | 610 | // Instruction widths and flags, one entry per code unit. |
| 611 | UniquePtr<InstructionFlags[]> insn_flags_; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 612 | |
Elliott Hughes | 08fc03a | 2012-06-26 17:34:00 -0700 | [diff] [blame] | 613 | // The dex PC of a FindLocksAtDexPc request, -1 otherwise. |
| 614 | uint32_t interesting_dex_pc_; |
| 615 | // The container into which FindLocksAtDexPc should write the registers containing held locks, |
| 616 | // NULL if we're not doing FindLocksAtDexPc. |
| 617 | std::vector<uint32_t>* monitor_enter_dex_pcs_; |
| 618 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 619 | // The types of any error that occurs. |
| 620 | std::vector<VerifyError> failures_; |
| 621 | // Error messages associated with failures. |
| 622 | std::vector<std::ostringstream*> failure_messages_; |
| 623 | // Is there a pending hard failure? |
| 624 | bool have_pending_hard_failure_; |
jeffhao | faf459e | 2012-08-31 15:32:47 -0700 | [diff] [blame] | 625 | // Is there a pending runtime throw failure? A runtime throw failure is when an instruction |
| 626 | // would fail at runtime throwing an exception. Such an instruction causes the following code |
| 627 | // to be unreachable. This is set by Fail and used to ensure we don't process unreachable |
| 628 | // instructions that would hard fail the verification. |
| 629 | bool have_pending_runtime_throw_failure_; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 630 | |
Ian Rogers | ad0b3a3 | 2012-04-16 14:50:24 -0700 | [diff] [blame] | 631 | // Info message log use primarily for verifier diagnostics. |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 632 | std::ostringstream info_messages_; |
| 633 | |
| 634 | // The number of occurrences of specific opcodes. |
| 635 | size_t new_instance_count_; |
| 636 | size_t monitor_enter_count_; |
Elliott Hughes | 80537bb | 2013-01-04 16:37:26 -0800 | [diff] [blame] | 637 | |
| 638 | const bool can_load_classes_; |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 639 | }; |
jeffhao | e4f0b2a | 2012-08-30 11:18:57 -0700 | [diff] [blame] | 640 | std::ostream& operator<<(std::ostream& os, const MethodVerifier::FailureKind& rhs); |
Ian Rogers | 776ac1f | 2012-04-13 23:36:36 -0700 | [diff] [blame] | 641 | |
| 642 | } // namespace verifier |
| 643 | } // namespace art |
| 644 | |
| 645 | #endif // ART_SRC_VERIFIER_METHOD_VERIFIER_H_ |