VerifySubs.h revision 2e1ee50a08cc3dd07ce4e956b925c1f0f28cf329
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-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
32 */
33typedef 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 */
43bool 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 */
47bool dvmSetTryFlags(const Method* meth, InsnFlags* insnFlags);
48
49/* check switch targets and set the "branch target" flag for destinations */
50bool dvmCheckSwitchTargets(const Method* meth, InsnFlags* insnFlags,
51    int curOffset);
52
53/* verify branch target and set "branch target" flag on the destination */
54bool 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 */
62void dvmLogVerifyFailure(const Method* meth, const char* format, ...)
63#if defined(__GNUC__)
64    __attribute__ ((format(printf, 2, 3)))
65#endif
66    ;
67
68/* log verification failure due to resolution trouble */
69void dvmLogUnableToResolveClass(const char* missingClassDescr,
70    const Method* meth);
71
72/* extract the relative branch target from a branch instruction */
73bool 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 */
77char dvmDetermineCat1Const(s4 value);
78
79#endif /*_DALVIK_VERIFYSUBS*/
80