split_verify.c
来自「This is a resource based on j2me embedde」· C语言 代码 · 共 1,985 行 · 第 1/5 页
C
1,985 行
"method flow falls off end", "invokeinterface byte 5 must be zero", "invokeinterface argument count wrong", "invokespecial references method not in a superclass", "<init> called with wrong object type", "fieldref constantpool entry expected", "override of final method", "method ends in mid-instruction", "'new' object doesn't reference new op", "malformed exception handler entry", "field access requires correct object type", "constant pool overindex", "direct call to <clinit>", "could not allocate working memory"};static const char *getMsg(int result){ int count = sizeof(verifierStatusInfo)/sizeof(verifierStatusInfo[0]); const char* info = (result > 0 && result < count) ? verifierStatusInfo[result] : "Unknown problem"; return info;}/* * If you add new errors to this list, be sure to also add * an explanation to KVM_MSG_VERIFIER_STATUS_INFO_INITIALIZER in * messages.h. *//* * ------------------------------------------------------------------------ * Stack map flags * ------------------------------------------------------------------------ *//* * Flags used to control how to match two stack maps. * One of the stack maps is derived as part of the type checking process. * The other stack map is recorded in the class file. */#define SM_CHECK 1 /* Check if derived types match recorded types. */#define SM_MERGE 2 /* Merge recorded types into derived types. */#define SM_EXIST 4 /* A recorded type attribute must exist. *//* * ------------------------------------------------------------------------ * General functions * ------------------------------------------------------------------------ */#define getCell(addr) \ ((((long)(((unsigned char *)(addr))[0])) << 24) | \ (((long)(((unsigned char *)(addr))[1])) << 16) | \ (((long)(((unsigned char *)(addr))[2])) << 8) | \ (((long)(((unsigned char *)(addr))[3])) << 0))/* Get an unsigned 16-bit value from the given memory location */#define getUShort(addr) \ ((((unsigned short)(((unsigned char *)(addr))[0])) << 8) | \ (((unsigned short)(((unsigned char *)(addr))[1])) << 0))/* Get a 16-bit value from the given memory location */#define getShort(addr) ((short)(getUShort(addr)))/* * Get an signed byte from the bytecode array */#define Vfy_getByte(cntxt,ip) \ (((signed char *)((cntxt)->bytecodesBeingVerified))[ip])/* * Get an unsigned byte from the bytecode array */#define Vfy_getUByte(cntxt, ip) (cntxt->bytecodesBeingVerified[ip])/* * Get an signed short from the bytecode array */#define Vfy_getShort(cntxt,ip) getShort(cntxt->bytecodesBeingVerified+(ip))/* * Get an unsigned short from the bytecode array */#define Vfy_getUShort(cntxt,ip) getUShort(cntxt->bytecodesBeingVerified+(ip))/* * Get an signed word from the bytecode array */#define Vfy_getCell(cntxt,ip) getCell(cntxt->bytecodesBeingVerified+(ip))/* * Get an opcode from the bytecode array. */static int Vfy_getOpcode(VfyContext* cntxt, IPINDEX ip);#if 0VERIFIERTYPE CVMvfy_makeVerifierType(CVMClassTypeID key);#endif/* * Convert a VERIFIERTYPE to a CVMClassTypeID * * In KVM the types are the same when the value is above 256 and the * verifier core never needs to convert values lower then this so it * is simply enough to check that this assumption is true. * * @param classKey A CVMClassTypeID * @return A VERIFIERTYPE *//*#define Vfy_toVerifierType(classKey) \ (CVMassert(CVMtypeidFieldIsRef(classKey)), \ (CVMtypeidGetArrayDepth(classKey)==0) ? VERIFY_MAKE_OBJECT(classKey) : \ CVMvfy_makeVerifierType(classKey))*/#define Vfy_toVerifierType(classKey) VERIFY_MAKE_OBJECT(classKey)/* * Convert a CVMClassTypeID to a VERIFIERTYPE * * In KVM the types are the same when the value is above 256 and the * verifier core never needs to convert values lower then this so it * is simply enough to check that this assumption is true. * * @param verifierType A VERIFIERTYPE * @return A CVMClassTypeID *//* Assert that this is really a class type, not an array or e.g. int */#define Vfy_toClassKey(verifierType) \ (CVMassert(WITH_ZERO_EXTRA_INFO(verifierType)==NULL_FULLINFO), \ GET_EXTRA_INFO(verifierType))/* Same, but with a more lenient assertion */#define Vfy_baseClassKey(verifierType) \ (CVMassert(GET_ITEM_TYPE(verifierType) == ITEM_Object), \ GET_EXTRA_INFO(verifierType))/* * Test to see if a type is a primitive type * * @param type A VERIFIERTYPE * @return CVMBool CVM_TRUE is type is a primitive#define Vfy_isPrimitive(type) ((type != ITEM_Null) && (type < 256)) *//* * Test to see if a type is an array * * @param type A VERIFIERTYPE * @return CVMBool CVM_TRUE is type is an array */#define Vfy_isArray(type) (GET_INDIRECTION(type) > 0)/* * Test to see if a type is an array or null * * @param type A VERIFIERTYPE * @return CVMBool CVM_TRUE is type is an array or null */#define Vfy_isArrayOrNull(type) (Vfy_isArray(type) || (type == ITEM_Null))/* * Vfy_vIsAssignable: factor out the most common case from vIsAssignable. * NOTE THAT this will not write the mergedCaseP result if the * shortcut is taken. */#define Vfy_vIsAssignable(cntxt, fromKey, toKey, mergedKeyP) \ ((((toKey) == ITEM_Bogus) || ((toKey) == (fromKey))) ? CVM_TRUE : \ vIsAssignable((cntxt), (fromKey), (toKey), (mergedKeyP)))/* * Test to see if one type can be assigned to another type * * @param fromKey A VERIFIERTYPE to assign from * @param toKey A VERIFIERTYPE to assign to * @return CVMBool CVM_TRUE if the assignment is legal */#define Vfy_isAssignable(fromKey, toKey) \ Vfy_vIsAssignable(cntxt, fromKey, toKey, NULL)/* * Test to see if a field of a class is "protected" * * @param clazz A CLASS * @param index The field index (offset in words) * @return CVM_TRUE if field is protected */#define Vfy_isProtectedField(clazz, index) vIsProtectedAccess((CLASS)clazz, index, CVM_FALSE)/* * Test to see if a method of a class is "protected" * * @param clazz A CLASS * @param index The method index (offset in words) * @return CVM_TRUE if method is protected */#define Vfy_isProtectedMethod(clazz, index) vIsProtectedAccess((CLASS)clazz, index, CVM_TRUE)/* * Check if the current state of the local variable and stack contents match * that of a stack map at a specific IP address * * @param cntxt Pointer to the current verification context * @param targetIP The IP address for the stack map * @param flags One or more of SM_CHECK, SM_MERGE, and SM_EXIST * @param throwCode A verification error code * @throw If the match is not correct *//* KILL ME #define Vfy_matchStackMap(cntxt, targetIP, flags, throwCode) { \ if (!matchStackMap(cntxt, targetIP, flags)){ \ Vfy_throw(cntxt, throwCode); \ } \ }*//* * Check stack maps can be merged at the current location * * @param cntxt Pointer to the current verification context * @param targetIP The IP address for the stack map * @param noControlFlow CVM_TRUE if the location cannot be reached from the previous instruction * @throw If the match is not correct */#define Vfy_checkCurrentTarget(cntxt, current_ip, noControlFlow) { \ Vfy_matchStackMap( cntxt, \ current_ip, \ SM_MERGE | (noControlFlow ? SM_EXIST : SM_CHECK), \ VE_SEQ_BAD_TYPE \ ); \}/* * Check stack maps match at an exception handler entry point * * @param cntxt Pointer to the current verification context * @param target_ip The IP address of the exception handler * @throw If the match is not correct */#define Vfy_checkHandlerTarget(cntxt, target_ip) { \ Vfy_trace1("Check exception handler at %ld:\n", (long)target_ip); \ Vfy_matchStackMap(cntxt, target_ip, SM_CHECK | SM_EXIST, \ VE_TARGET_BAD_TYPE); \}/* * Check stack maps match at a jump target * * @param cntxt Pointer to the current verification context * @param current_ip The current IP address * @param target_ip The IP address of the jump target * @throw If the match is not correct */#define Vfy_checkJumpTarget(cntxt, this_ip, target_ip) { \ Vfy_trace1("Check jump target at %ld\n", (long)target_ip); \ Vfy_matchStackMap(cntxt, target_ip, SM_CHECK | SM_EXIST, \ VE_TARGET_BAD_TYPE); \ if (!checkNewObject(cntxt, (IPINDEX)this_ip, target_ip)) { \ Vfy_throw(cntxt, VE_BACK_BRANCH_UNINIT); \ } \}/* * Check stack maps match at a jump target * * @param cntxt Pointer to the current verification context * @param current_ip The current IP address * @param target_ip The IP address of the jump target * @throw If the match is not correct */#define Vfy_markNewInstruction(cntxt, ip, length) { \ if (cntxt->NEWInstructions == NULL){ \ cntxt->NEWInstructions = callocNewBitmap(length); \ } \ SET_NTH_BIT(cntxt->NEWInstructions, ip); \}#undef Vfy_markNewInstruction#define Vfy_markNewInstruction(cntxt, ip, length) { \ SET_NTH_BIT(cntxt->NEWInstructions, ip); \}/* * Get the type of a local variable * * @param cntxt Pointer to the current verification context * @param i The slot index of the local variable * @param t The VERIFIERTYPE that must match * @return The actual VERIFIERTYPE found * @throw If the match is not correct or index is bad */static VERIFIERTYPE Vfy_getLocal(VfyContext* cntxt, SLOTINDEX i, VERIFIERTYPE t);/* * Set the type of a local variable * * @param cntxt Pointer to the current verification context * @param i The slot index of the local variable * @param t The new VERIFIERTYPE of the slot * @throw If index is bad */static void Vfy_setLocal(VfyContext* cntxt, SLOTINDEX i, VERIFIERTYPE t);/* * Push a type * * @param cntxt Pointer to the current verification context * @param t The new VERIFIERTYPE to be pushed * @throw If stack overflows */static void Vfy_push(VfyContext* cntxt, VERIFIERTYPE t);/* * Pop a type * * @param cntxt Pointer to the current verification context * @param t The VERIFIERTYPE that must match * @throw If the match is not correct or stack underflow */static VERIFIERTYPE Vfy_pop(VfyContext* cntxt, VERIFIERTYPE t);/* * Pop category1 type (ITEM_Null, ITEM_Integer, ITEM_Float, <init> object, * reference type, or array type * * @param cntxt Pointer to the current verification context * @throw If the match is not correct or stack underflow */static VERIFIERTYPE Vfy_popCategory1(VfyContext* cntxt);/* * Pop the first word of a category2 type * * @param cntxt Pointer to the current verification context * @throw If the match is not correct or stack underflow */static VERIFIERTYPE Vfy_popCategory2_firstWord(VfyContext* cntxt);/* * Pop the second word of a category2 type * * @param cntxt Pointer to the current verification context * @throw If the match is not correct or stack underflow */static VERIFIERTYPE Vfy_popCategory2_secondWord(VfyContext* cntxt);/* * Pop the first word of a DoubleWord type * * @param cntxt Pointer to the current verification context * @throw If the match is not correct or stack underflow */#define Vfy_popDoubleWord_firstWord(cntxt) Vfy_popCategory2_firstWord(cntxt)/* * Pop the second word of a DoubleWord type * * @param cntxt Pointer to the current verification context * @throw If the match is not correct or stack underflow */#define Vfy_popDoubleWord_secondWord(cntxt) Vfy_popCategory2_secondWord(cntxt)/* * Verify a void return * * @param cntxt Pointer to the current verification context * @throw If the method is not if type void, if the method * is <init> and super() was not called. */static void Vfy_returnVoid(VfyContext* cntxt);/* * Pop a type and verify a return * * @param cntxt Pointer to the current verification context * @param returnType The VERIFIERTYPE to be returned * @throw If the return type is incorrect */static void Vfy_popReturn(VfyContext* cntxt, VERIFIERTYPE returnType);/* * Push a CVMClassTypeID * * @param cntxt Pointer to the current verification context * @param returnType The CVMClassTypeID to be pushed * @throw If stack overflow, bad type. */static void Vfy_pushClassKey(VfyContext* cntxt, CVMClassTypeID fieldType);/*
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?