Home | History | Annotate | Download | only in analysis
      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_H_
     21 #define DALVIK_VERIFYSUBS_H_
     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  */
     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 /* verification failure reporting */
     50 #define LOG_VFY(...)                dvmLogVerifyFailure(NULL, __VA_ARGS__)
     51 #define LOG_VFY_METH(_meth, ...)    dvmLogVerifyFailure(_meth, __VA_ARGS__)
     52 
     53 /* log verification failure with optional method info */
     54 void dvmLogVerifyFailure(const Method* meth, const char* format, ...)
     55 #if defined(__GNUC__)
     56     __attribute__ ((format(printf, 2, 3)))
     57 #endif
     58     ;
     59 
     60 /* log verification failure due to resolution trouble */
     61 void dvmLogUnableToResolveClass(const char* missingClassDescr,
     62     const Method* meth);
     63 
     64 /* extract the relative branch offset from a branch instruction */
     65 bool dvmGetBranchOffset(const Method* meth, const InsnFlags* insnFlags,
     66     int curOffset, s4* pOffset, bool* pConditional);
     67 
     68 /* return a RegType enumeration value that "value" just fits into */
     69 char dvmDetermineCat1Const(s4 value);
     70 
     71 /* debugging */
     72 bool dvmWantVerboseVerification(const Method* meth);
     73 
     74 #endif  // DALVIK_VERIFYSUBS_H_
     75