⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 verifierutil.h

📁 java 1.1 gemini 08_16
💻 H
📖 第 1 页 / 共 3 页
字号:
/*****************************************************************************
*  Copyright Statement:
*  --------------------
*  This software is protected by Copyright and the information contained
*  herein is confidential. The software may not be copied and the information
*  contained herein may not be used or disclosed except with the written
*  permission of MediaTek Inc. (C) 2005
*
*  BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
*  THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
*  RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
*  AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
*  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
*  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
*  NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
*  SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
*  SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
*  THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
*  NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
*  SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
*  BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
*  LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
*  AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
*  OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
*  MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE. 
*
*  THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
*  WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
*  LAWS PRINCIPLES.  ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
*  RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
*  THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/

/*******************************************************************************
 * Filename:
 * ---------
 *  verifierUtil.h
 *
 * Project:
 * --------
 *  MAUI
 *
 * Description:
 * ------------
 *  
 *
 * Author:
 * -------
 *  
 *
 *==============================================================================
 * 				HISTORY
 * Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *------------------------------------------------------------------------------
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 * removed!
 * removed!
 * removed!
 *
 *------------------------------------------------------------------------------
 * Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!! 
 *==============================================================================
 *******************************************************************************/


/*
 * Copyright (c) 1998-2001 Sun Microsystems, Inc. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of Sun
 * Microsystems, Inc. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Sun.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
 * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
 * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
 * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
 * THIS SOFTWARE OR ITS DERIVATIVES.
 *
 * Use is subject to license terms.
 */

/*=========================================================================
 * SYSTEM:    KVM
 * SUBSYSTEM: Class file verifier
 * FILE:      verifierUtil.h
 * OVERVIEW:  Implementation-specific parts of the KVM verifier.
 * AUTHOR:    Nik Shaylor
 *=======================================================================*/

/*=========================================================================
 * Include files
 *=======================================================================*/

#include <global.h>

/* ------------------------------------------------------------------------ *\
 *                               General types                              *
\* ------------------------------------------------------------------------ */

/*
 * In order to split the verifier into a KVM part and a VM
 * independent part the verifier uses a variable typing 
 * system that is slightly different from the KVM.
 *
 * The following types are use and have the same meaning as they do in KVM
 *
 *      CLASS           A reference to a class data structure
 *      METHOD          A reference to a method data structure
 *      CONSTANTPOOL    A reference to a constant pool data structure
 *      TRUE            A boolean value
 *      FALSE           A boolean value
 */

/*
 * The following are type definitions that are only used by the
 * verifier core.
 *
 * In KVM a VERIFIERTYPE and a CLASSKEY are fairly similar.
 * The difference lies in the encoding of primitive data types.
 * For example, a CLASSKEY for an Integer is an ASCII 'I', while
 * a VERIFIERTYPE for an Integer is ITEM_Integer. In both
 * cases values less than 256 are primitive data types and
 * those above 256 are reference types and array types.
 * In KVM the encoding above 256 are the same for CLASSKEY
 * and VERIFIERTYPE. The are two conversion functions
 * Vfy_toVerifierType() and Vfy_toClassKey() that will
 * convert between these types. Currently verifierCore
 * never needs to convert primitive data types this way,
 * so these functions simply pass the input to the output
 *
 * Another small complexity exists with VERIFIERTYPE.
 * This is that the value pushed by the NEW bytecode
 * is an encoding of the IP address of the NEW instruction
 * that will create the object when executed (this encoding
 * is the same as that done in the stack maps). This is done in
 * order to distinguish initialized from uninitialized
 * references of the same type. For instance:
 *
 *      new Foo
 *      new Foo
 *      invokespecial <init>
 *
 * This results in the stack containing one initialized Foo
 * and one uninitialized Foo. The verifier needs to keep track
 * of these so after the invokespecial <init> the verifier
 * changes all occurences of the second Foo from being type
 * "New from bytecode-n" to being type "Foo".
 */

/*
 * This represents a class type in the VM. It could be the same
 * as a CLASS, but in KVM it is a 16 bit data structure that
 * contains an encoded key that represents a CLASS. Its format is
 * described in the function change_FieldSignature_to_Key().
 */
#define CLASSKEY unsigned short

/*
 * This represents a class type in the verifier. Again it could
 * the same as a CLASS and/or CLASSKEY, but in KVM it is another
 * 16 bit data structure that matches the format the loader produces
 * for the stack map tables.
 */
#define VERIFIERTYPE unsigned short

/*
 * This represents the name of a method. It could be the same as METHOD,
 * but in KVM it is 16 value that is used get the name from a table of
 * interned UTF8 strings.
 */
#define METHODNAMEKEY unsigned short

/*
 * This represents the type of a method. It could be the same as METHOD,
 * but in KVM it is 16 value that is used get the name from a table of
 * interned strings that have the method signature encoded as described
 * in the function change_MethodSignature_to_Key()
 */
#define METHODTYPEKEY unsigned short

/*
 * Index in to a bytecode array
 */
#define IPINDEX unsigned short

/*
 * Index into the local variable array maintained by the verifier
 */
#define SLOTINDEX int

/*
 * Index into the constant pool
 */
#define POOLINDEX int

/*
 * Tag from the constant pool
 */
#define POOLTAG unsigned char

/* ------------------------------------------------------------------------ *\
 *                           Manifest Class types                           *
\* ------------------------------------------------------------------------ */

/*
 * All these functions produce a VERIFIERTYPE corresponding to an array type.
 */

#define Vfy_getBooleanArrayVerifierType()   ((1 << FIELD_KEY_ARRAY_SHIFT) + 'Z')
#define Vfy_getByteArrayVerifierType()      ((1 << FIELD_KEY_ARRAY_SHIFT) + 'B')
#define Vfy_getCharArrayVerifierType()      ((1 << FIELD_KEY_ARRAY_SHIFT) + 'C')
#define Vfy_getShortArrayVerifierType()     ((1 << FIELD_KEY_ARRAY_SHIFT) + 'S')
#define Vfy_getIntArrayVerifierType()       ((1 << FIELD_KEY_ARRAY_SHIFT) + 'I')
#define Vfy_getLongArrayVerifierType()      ((1 << FIELD_KEY_ARRAY_SHIFT) + 'J')

#if IMPLEMENTS_FLOAT
#define Vfy_getFloatArrayVerifierType()     ((1 << FIELD_KEY_ARRAY_SHIFT) + 'F')
#define Vfy_getDoubleArrayVerifierType()    ((1 << FIELD_KEY_ARRAY_SHIFT) + 'D')
#endif

#define Vfy_getObjectVerifierType()         (JavaLangObject->clazz.key)
#define Vfy_getStringVerifierType()         (JavaLangString->clazz.key)
#define Vfy_getThrowableVerifierType()      (JavaLangThrowable->clazz.key)
#define Vfy_getObjectArrayVerifierType()    ((VERIFIERTYPE)(Vfy_getObjectVerifierType() + (1 << FIELD_KEY_ARRAY_SHIFT)))

/* ------------------------------------------------------------------------ *\
 *                           Dynamic Class types                            *
\* ------------------------------------------------------------------------ */

/*
 * Get a class array from a CLASSKEY data type that some kind of object
 * reference. It is used for ANEWARRAY
 */
extern VERIFIERTYPE Vfy_getClassArrayVerifierType(CLASSKEY typeKey);

/*
 * Gets the VERIFIERTYPE that represents the element type of an array
 */
extern VERIFIERTYPE Vfy_getReferenceArrayElementType(VERIFIERTYPE arrayTypeKey);

/*
 * Gets the VERIFIERTYPE that represents the element type of an array
 */
extern bool_t   Vfy_isArrayClassKey(CLASSKEY typeKey, int dim);

/* ------------------------------------------------------------------------ *\
 *                          "NEW" object data types                         *
\* ------------------------------------------------------------------------ */

/*
 * This will encode an IP address into a special kind of VERIFIERTYPE such
 * that it will not be confused with other types.
 */
#define Vfy_createVerifierTypeForNewAt(ip)      Vfy_toVerifierType((CLASSKEY)(ENCODE_NEWOBJECT(ip)))

/*
 * Tests a VERIFIERTYPE to see if it was created using
 * Vfy_createVerifierTypeForNewAt()
 */
#define Vfy_isVerifierTypeForNew(verifierType)  (verifierType & ITEM_NewObject_Flag)

/*
 * Translates a VERIFIERTYPE encoded using Vfy_createVerifierTypeForNewAt()
 * back into the IP address that was used to create it.
 */
#define Vfy_retrieveIpForNew(verifierType)      DECODE_NEWOBJECT(verifierType)

/* ------------------------------------------------------------------------ *\
 *                               Error codes                                *
\* ------------------------------------------------------------------------ */

#define VE_STACK_OVERFLOW               1
#define VE_STACK_UNDERFLOW              2
#define VE_STACK_EXPECT_CAT1            3
#define VE_STACK_BAD_TYPE               4
#define VE_LOCALS_OVERFLOW              5
#define VE_LOCALS_BAD_TYPE              6
#define VE_LOCALS_UNDERFLOW             7
#define VE_TARGET_BAD_TYPE              8
#define VE_BACK_BRANCH_UNINIT           9
#define VE_SEQ_BAD_TYPE                10
#define VE_EXPECT_CLASS                11
#define VE_EXPECT_THROWABLE            12
#define VE_BAD_LOOKUPSWITCH            13
#define VE_BAD_LDC                     14
#define VE_BALOAD_BAD_TYPE             15
#define VE_AALOAD_BAD_TYPE             16
#define VE_BASTORE_BAD_TYPE            17
#define VE_AASTORE_BAD_TYPE            18
#define VE_FIELD_BAD_TYPE              19
#define VE_EXPECT_METHODREF            20
#define VE_ARGS_NOT_ENOUGH             21
#define VE_ARGS_BAD_TYPE               22
#define VE_EXPECT_INVOKESPECIAL        23
#define VE_EXPECT_NEW                  24
#define VE_EXPECT_UNINIT               25
#define VE_BAD_INSTR                   26
#define VE_EXPECT_ARRAY                27
#define VE_MULTIANEWARRAY              28
#define VE_EXPECT_NO_RETVAL            29
#define VE_RETVAL_BAD_TYPE             30
#define VE_EXPECT_RETVAL               31
#define VE_RETURN_UNINIT_THIS          32
#define VE_BAD_STACKMAP                33
#define VE_FALL_THROUGH                34
#define VE_EXPECT_ZERO                 35
#define VE_NARGS_MISMATCH              36
#define VE_INVOKESPECIAL               37
#define VE_BAD_INIT_CALL               38
#define VE_EXPECT_FIELDREF             39
#define VE_FINAL_METHOD_OVERRIDE       40
#define VE_MIDDLE_OF_BYTE_CODE         41
#define VE_BAD_NEW_OFFSET              42
#define VE_BAD_EXCEPTION_HANDLER_RANGE 43
#define VE_EXPECTING_OBJ_OR_ARR_ON_STK 44

/*
 * 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. */

/* ------------------------------------------------------------------------ *\
 *                         Global data definitions                          *
\* ------------------------------------------------------------------------ */

/*
 * This is always the method being verified.
 */
extern METHOD methodBeingVerified;

/*
 * Pointer to the bytecodes for the above method
 */
extern unsigned char *bytecodesBeingVerified;

/*
 * ByteCode table for debugging purposes (included
 * only if certain tracing modes are enabled).
 *
 */
extern const char* const byteCodeNames[];

/* ------------------------------------------------------------------------ *\
 *                             General functions                            *
\* ------------------------------------------------------------------------ */

/*
 * Print fatal error message and exit
 */
#define Vfy_fatal(message)  fatalError(message)

/*
 * Get an signed byte from the bytecode array

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -