VerifySubs.h revision 99409883d9c4c0ffb49b070ce307bb33a9dfe9f1
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:
25 *  0-15  instruction length (or 0 if this address doesn't hold an opcode)
26 *  16    opcode flag (indicating this address holds an opcode)
27 *  17    try block (indicating exceptions thrown here may be caught locally)
28 *  30    visited (verifier has examined this instruction at least once)
29 *  31    changed (set/cleared as bytecode verifier runs)
30 */
31typedef u4 InsnFlags;
32
33#define kInsnFlagWidthMask      0x0000ffff
34#define kInsnFlagInTry          (1 << 16)
35#define kInsnFlagBranchTarget   (1 << 17)
36#define kInsnFlagGcPoint        (1 << 18)
37#define kInsnFlagVisited        (1 << 30)
38#define kInsnFlagChanged        (1 << 31)
39
40/* add opcode widths to InsnFlags */
41bool dvmComputeCodeWidths(const Method* meth, InsnFlags* insnFlags,
42    int* pNewInstanceCount);
43
44/* set the "in try" flag for sections of code wrapped with a "try" block */
45bool dvmSetTryFlags(const Method* meth, InsnFlags* insnFlags);
46
47/* check switch targets and set the "branch target" flag for destinations */
48bool dvmCheckSwitchTargets(const Method* meth, InsnFlags* insnFlags,
49    int curOffset);
50
51/* verify branch target and set "branch target" flag on the destination */
52bool dvmCheckBranchTarget(const Method* meth, InsnFlags* insnFlags,
53    int curOffset, bool selfOkay);
54
55/* verification failure reporting */
56#define LOG_VFY(...)                dvmLogVerifyFailure(NULL, __VA_ARGS__)
57#define LOG_VFY_METH(_meth, ...)    dvmLogVerifyFailure(_meth, __VA_ARGS__)
58
59/* log verification failure with optional method info */
60void dvmLogVerifyFailure(const Method* meth, const char* format, ...)
61#if defined(__GNUC__)
62    __attribute__ ((format(printf, 2, 3)))
63#endif
64    ;
65
66/* log verification failure due to resolution trouble */
67void dvmLogUnableToResolveClass(const char* missingClassDescr,
68    const Method* meth);
69
70/* extract the relative branch target from a branch instruction */
71bool dvmGetBranchTarget(const Method* meth, InsnFlags* insnFlags,
72    int curOffset, int* pOffset, bool* pConditional);
73
74/* return a RegType enumeration value that "value" just fits into */
75char dvmDetermineCat1Const(s4 value);
76
77#endif /*_DALVIK_VERIFYSUBS*/
78