| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2008 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 | /* |
| 18 | * Dalvik bytecode verification subroutines. |
| 19 | */ |
| 20 | #ifndef _DALVIK_VERIFYSUBS |
| 21 | #define _DALVIK_VERIFYSUBS |
| 22 | |
| 23 | /* |
| 24 | * InsnFlags is a 32-bit integer with the following layout: |
| Andy McFadden | 2e1ee50 | 2010-03-24 13:25:53 -0700 | [diff] [blame] | 25 | * 0-15 instruction length (or 0 if this address doesn't hold an opcode) |
| 26 | * 16-31 single bit flags: |
| 27 | * InTry: in "try" block; exceptions thrown here may be caught locally |
| 28 | * BranchTarget: other instructions can branch to this instruction |
| 29 | * GcPoint: this instruction is a GC safe point |
| 30 | * Visited: verifier has examined this instruction at least once |
| 31 | * Changed: set/cleared as bytecode verifier runs |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 32 | */ |
| 33 | typedef u4 InsnFlags; |
| 34 | |
| 35 | #define kInsnFlagWidthMask 0x0000ffff |
| 36 | #define kInsnFlagInTry (1 << 16) |
| 37 | #define kInsnFlagBranchTarget (1 << 17) |
| 38 | #define kInsnFlagGcPoint (1 << 18) |
| 39 | #define kInsnFlagVisited (1 << 30) |
| 40 | #define kInsnFlagChanged (1 << 31) |
| 41 | |
| 42 | /* add opcode widths to InsnFlags */ |
| 43 | bool dvmComputeCodeWidths(const Method* meth, InsnFlags* insnFlags, |
| 44 | int* pNewInstanceCount); |
| 45 | |
| 46 | /* set the "in try" flag for sections of code wrapped with a "try" block */ |
| 47 | bool dvmSetTryFlags(const Method* meth, InsnFlags* insnFlags); |
| 48 | |
| 49 | /* check switch targets and set the "branch target" flag for destinations */ |
| 50 | bool dvmCheckSwitchTargets(const Method* meth, InsnFlags* insnFlags, |
| 51 | int curOffset); |
| 52 | |
| 53 | /* verify branch target and set "branch target" flag on the destination */ |
| 54 | bool dvmCheckBranchTarget(const Method* meth, InsnFlags* insnFlags, |
| 55 | int curOffset, bool selfOkay); |
| 56 | |
| 57 | /* verification failure reporting */ |
| 58 | #define LOG_VFY(...) dvmLogVerifyFailure(NULL, __VA_ARGS__) |
| 59 | #define LOG_VFY_METH(_meth, ...) dvmLogVerifyFailure(_meth, __VA_ARGS__) |
| 60 | |
| 61 | /* log verification failure with optional method info */ |
| The Android Open Source Project | 9940988 | 2009-03-18 22:20:24 -0700 | [diff] [blame] | 62 | void dvmLogVerifyFailure(const Method* meth, const char* format, ...) |
| 63 | #if defined(__GNUC__) |
| 64 | __attribute__ ((format(printf, 2, 3))) |
| 65 | #endif |
| 66 | ; |
| The Android Open Source Project | f6c3871 | 2009-03-03 19:28:47 -0800 | [diff] [blame] | 67 | |
| 68 | /* log verification failure due to resolution trouble */ |
| 69 | void dvmLogUnableToResolveClass(const char* missingClassDescr, |
| 70 | const Method* meth); |
| 71 | |
| 72 | /* extract the relative branch target from a branch instruction */ |
| 73 | bool dvmGetBranchTarget(const Method* meth, InsnFlags* insnFlags, |
| 74 | int curOffset, int* pOffset, bool* pConditional); |
| 75 | |
| 76 | /* return a RegType enumeration value that "value" just fits into */ |
| 77 | char dvmDetermineCat1Const(s4 value); |
| 78 | |
| 79 | #endif /*_DALVIK_VERIFYSUBS*/ |