1 /* 2 * Copyright (C) 2015 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_VERIFIER_ENUMS_H_ 18 #define ART_RUNTIME_VERIFIER_VERIFIER_ENUMS_H_ 19 20 #include <stdint.h> 21 22 namespace art { 23 namespace verifier { 24 25 // The mode that the verifier should run as. 26 enum class VerifyMode : int8_t { 27 kNone, // Everything is assumed verified. 28 kEnable, // Standard verification, try pre-verifying at compile-time. 29 kSoftFail, // Force a soft fail, punting to the interpreter with access checks. 30 }; 31 32 // The outcome of verification. 33 enum class FailureKind { 34 kNoFailure, 35 kAccessChecksFailure, 36 kSoftFailure, 37 kHardFailure, 38 }; 39 std::ostream& operator<<(std::ostream& os, FailureKind rhs); 40 41 // How to log hard failures during verification. 42 enum class HardFailLogMode { 43 kLogNone, // Don't log hard failures at all. 44 kLogVerbose, // Log with severity VERBOSE. 45 kLogWarning, // Log with severity WARNING. 46 kLogInternalFatal, // Log with severity FATAL_WITHOUT_ABORT 47 }; 48 49 /* 50 * "Direct" and "virtual" methods are stored independently. The type of call used to invoke the 51 * method determines which list we search, and whether we travel up into superclasses. 52 * 53 * (<clinit>, <init>, and methods declared "private" or "static" are stored in the "direct" list. 54 * All others are stored in the "virtual" list.) 55 */ 56 enum MethodType { 57 METHOD_UNKNOWN = 0, 58 METHOD_DIRECT, // <init>, private 59 METHOD_STATIC, // static 60 METHOD_VIRTUAL, // virtual 61 METHOD_SUPER, // super 62 METHOD_INTERFACE, // interface 63 METHOD_POLYMORPHIC // polymorphic 64 }; 65 std::ostream& operator<<(std::ostream& os, MethodType rhs); 66 67 /* 68 * An enumeration of problems that can turn up during verification. 69 * Both VERIFY_ERROR_BAD_CLASS_SOFT and VERIFY_ERROR_BAD_CLASS_HARD denote failures that cause 70 * the entire class to be rejected. However, VERIFY_ERROR_BAD_CLASS_SOFT denotes a soft failure 71 * that can potentially be corrected, and the verifier will try again at runtime. 72 * VERIFY_ERROR_BAD_CLASS_HARD denotes a hard failure that can't be corrected, and will cause 73 * the class to remain uncompiled. Other errors denote verification errors that cause bytecode 74 * to be rewritten to fail at runtime. 75 */ 76 enum VerifyError : uint32_t { 77 VERIFY_ERROR_BAD_CLASS_HARD = 1 << 0, // VerifyError; hard error that skips compilation. 78 VERIFY_ERROR_BAD_CLASS_SOFT = 1 << 1, // VerifyError; soft error that verifies again at 79 // runtime. 80 81 VERIFY_ERROR_NO_CLASS = 1 << 2, // NoClassDefFoundError. 82 VERIFY_ERROR_NO_FIELD = 1 << 3, // NoSuchFieldError. 83 VERIFY_ERROR_NO_METHOD = 1 << 4, // NoSuchMethodError. 84 VERIFY_ERROR_ACCESS_CLASS = 1 << 5, // IllegalAccessError. 85 VERIFY_ERROR_ACCESS_FIELD = 1 << 6, // IllegalAccessError. 86 VERIFY_ERROR_ACCESS_METHOD = 1 << 7, // IllegalAccessError. 87 VERIFY_ERROR_CLASS_CHANGE = 1 << 8, // IncompatibleClassChangeError. 88 VERIFY_ERROR_INSTANTIATION = 1 << 9, // InstantiationError. 89 // For opcodes that don't have complete verifier support, we need a way to continue 90 // execution at runtime without attempting to re-verify (since we know it will fail no 91 // matter what). Instead, run as the interpreter in a special "do access checks" mode 92 // which will perform verifier-like checking on the fly. 93 VERIFY_ERROR_FORCE_INTERPRETER = 1 << 10, // Skip the verification phase at runtime; 94 // force the interpreter to do access checks. 95 // (sets a soft fail at compile time). 96 VERIFY_ERROR_LOCKING = 1 << 11, // Could not guarantee balanced locking. This should be 97 // punted to the interpreter with access checks. 98 VERIFY_ERROR_SKIP_COMPILER = 1u << 31, // Flag to note that the failure should preclude 99 // optimization. Meant as a signal from the verifier 100 // to the compiler that there is unreachable unverified 101 // code. May be removed once the compiler handles 102 // unreachable code correctly. 103 }; 104 std::ostream& operator<<(std::ostream& os, VerifyError rhs); 105 106 } // namespace verifier 107 } // namespace art 108 109 #endif // ART_RUNTIME_VERIFIER_VERIFIER_ENUMS_H_ 110