1f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 2f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Copyright (C) 2008 The Android Open Source Project 3f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 4f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * you may not use this file except in compliance with the License. 6f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * You may obtain a copy of the License at 7f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 8f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * 10f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * See the License for the specific language governing permissions and 14f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * limitations under the License. 15f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 16f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 17f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 18f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * Dalvik bytecode verification subroutines. 19f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 20f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#ifndef _DALVIK_VERIFYSUBS 21f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define _DALVIK_VERIFYSUBS 22f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 23f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* 24f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project * InsnFlags is a 32-bit integer with the following layout: 252e1ee50a08cc3dd07ce4e956b925c1f0f28cf329Andy McFadden * 0-15 instruction length (or 0 if this address doesn't hold an opcode) 262e1ee50a08cc3dd07ce4e956b925c1f0f28cf329Andy McFadden * 16-31 single bit flags: 272e1ee50a08cc3dd07ce4e956b925c1f0f28cf329Andy McFadden * InTry: in "try" block; exceptions thrown here may be caught locally 282e1ee50a08cc3dd07ce4e956b925c1f0f28cf329Andy McFadden * BranchTarget: other instructions can branch to this instruction 292e1ee50a08cc3dd07ce4e956b925c1f0f28cf329Andy McFadden * GcPoint: this instruction is a GC safe point 302e1ee50a08cc3dd07ce4e956b925c1f0f28cf329Andy McFadden * Visited: verifier has examined this instruction at least once 312e1ee50a08cc3dd07ce4e956b925c1f0f28cf329Andy McFadden * Changed: set/cleared as bytecode verifier runs 32f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project */ 33f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projecttypedef u4 InsnFlags; 34f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 35f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define kInsnFlagWidthMask 0x0000ffff 36f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define kInsnFlagInTry (1 << 16) 37f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define kInsnFlagBranchTarget (1 << 17) 38f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define kInsnFlagGcPoint (1 << 18) 39f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define kInsnFlagVisited (1 << 30) 40f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define kInsnFlagChanged (1 << 31) 41f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 42f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* add opcode widths to InsnFlags */ 43f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmComputeCodeWidths(const Method* meth, InsnFlags* insnFlags, 44f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project int* pNewInstanceCount); 45f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 46f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* set the "in try" flag for sections of code wrapped with a "try" block */ 47f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmSetTryFlags(const Method* meth, InsnFlags* insnFlags); 48f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 49f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* check switch targets and set the "branch target" flag for destinations */ 50f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmCheckSwitchTargets(const Method* meth, InsnFlags* insnFlags, 51f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project int curOffset); 52f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 53f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* verify branch target and set "branch target" flag on the destination */ 54f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmCheckBranchTarget(const Method* meth, InsnFlags* insnFlags, 55f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project int curOffset, bool selfOkay); 56f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 57f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* verification failure reporting */ 58f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define LOG_VFY(...) dvmLogVerifyFailure(NULL, __VA_ARGS__) 59f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#define LOG_VFY_METH(_meth, ...) dvmLogVerifyFailure(_meth, __VA_ARGS__) 60f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 61f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* log verification failure with optional method info */ 6299409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Projectvoid dvmLogVerifyFailure(const Method* meth, const char* format, ...) 6399409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project#if defined(__GNUC__) 6499409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project __attribute__ ((format(printf, 2, 3))) 6599409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project#endif 6699409883d9c4c0ffb49b070ce307bb33a9dfe9f1The Android Open Source Project ; 67f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 68f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* log verification failure due to resolution trouble */ 69f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectvoid dvmLogUnableToResolveClass(const char* missingClassDescr, 70f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project const Method* meth); 71f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 72f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* extract the relative branch target from a branch instruction */ 73f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectbool dvmGetBranchTarget(const Method* meth, InsnFlags* insnFlags, 74f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project int curOffset, int* pOffset, bool* pConditional); 75f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 76f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project/* return a RegType enumeration value that "value" just fits into */ 77f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Projectchar dvmDetermineCat1Const(s4 value); 78f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project 79f6c387128427e121477c1b32ad35cdcaa5101ba3The Android Open Source Project#endif /*_DALVIK_VERIFYSUBS*/ 80