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