Main Page | Namespace List | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals | Related Pages

cfattrib.c File Reference


Detailed Description

Implementation of The Java Virtual Machine Specification, version 2, Chapter 4, the Class File Format.

This file contains the attribute manipulation functions. All other work is performed in classfile.c.

Control

$URL: https://svn.apache.org/path/name/cfattrib.c $ $Id: cfattrib.c 0 09/28/2005 dlydick $

Copyright 2005 The Apache Software Foundation or its licensors, as applicable.

Licensed under the Apache License, Version 2.0 ("the License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and limitations under the License.

Version:
$LastChangedRevision: 0 $
Date:
$LastChangedDate: 09/28/2005 $
Author:
$LastChangedBy: dlydick $ Original code contributed by Daniel Lydick on 09/28/2005.

Reference

Definition in file cfattrib.c.

#include "arch.h"
#include <string.h>
#include "jvmcfg.h"
#include "cfmacros.h"
#include "classfile.h"
#include "util.h"
#include "utf.h"

Go to the source code of this file.

Code_attribute deferencing support.

#define DST_AI(dst)   ((Code_attribute *) &dst->ai)
 Conveniently reference the Code_attribute contained in a attribute_info_dup *dst, namely, with less pointer indirection.
#define PTR_DST_AI(dst)   ((Code_attribute *) &(*dst)->ai)
 Conveniently reference the Code_attribute contained in an indirect attribute_info_dup **dst.

Attribute test utilities.

Parameters:
pcfs ClassFile structure containing attribute xxx.
attribute_name_index Constant pool index of xxx attribute in this class file structure.
Todo:
Both in this group of functions and probably numerous places around the code, the u2 parameters that reference constant_pool entries should be changed to become type jvm_constant_pool_index instead as a more accurate reflection of their purpose. This type was a later addition to the code and is therefore not reflected in the earlier portions that were written.


classfile_attribute_enum cfattrib_atr2enum (ClassFile *pcfs, u2 attribute_name_index)
 Map UTF8 string names for attributes in a constant_pool to LOCAL_xxx_ATTRIBUTE constants for the purpose of switch(int) instead of switch("string") code constructions.
rboolean cfattrib_iscodeattribute (ClassFile *pcfs, u2 attribute_name_index)
 Short version of cfattrib_atr2enum(), but only check if an index refers to a Code_attribute area.

Defines

#define CMP_ATTRIBUTE(string)   utf_prchar_pcfs_strcmp(string, pcfs, attribute_name_index)
 Convenient shorthand for attribute string comparison.

Functions

static void cfattrib_c_dummy (void)
u1cfattrib_loadattribute (ClassFile *pcfs, attribute_info_dup **dst, attribute_info *src)
 Load an attribute and verify that it has either valid contents or is ignored as an unknown attribute.
rvoid cfattrib_unloadattribute (ClassFile *pcfs, attribute_info_dup *dst)
 UnLoad an attribute and free its heap area.

Variables

static char * cfattrib_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/cfattrib.c $ $Id: cfattrib.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable."


Define Documentation

#define CMP_ATTRIBUTE string   )     utf_prchar_pcfs_strcmp(string, pcfs, attribute_name_index)
 

Convenient shorthand for attribute string comparison.

Parameters:
string Attribute string for comparison against ClassFile attribute_info value.
Returns:
integer from utf_prchar_pcfs_strcmp()

Definition at line 68 of file cfattrib.c.

Referenced by cfattrib_atr2enum(), and cfattrib_iscodeattribute().

#define PTR_DST_AI dst   )     ((Code_attribute *) &(*dst)->ai)
 

Conveniently reference the Code_attribute contained in an indirect attribute_info_dup **dst.

After putting in the 4-byte access alignment changes, it became obvious that what was once (*dst)->member had become quite cumbersome. Therefore, in order to simplify access through (attribute_info_dup *)->ai.member constructions, including appropriate casting, the following macro is offered to take care of the most common usage. The few other references are unchanged, and the code is easier to understand.

Notice that DST_AI() references a attribute_info_dup *dst, while this macro references a attribute_info_dup **dst.

Definition at line 257 of file cfattrib.c.

Referenced by cfattrib_loadattribute().

#define DST_AI dst   )     ((Code_attribute *) &dst->ai)
 

Conveniently reference the Code_attribute contained in a attribute_info_dup *dst, namely, with less pointer indirection.

This is a counterpart for cfattrib_unloadattribute() where no indirection is needed. Notice that PTR_DST_AI() references a attribute_info_dup **dst, while this macro references a attribute_info_dup *dst.

Definition at line 271 of file cfattrib.c.


Function Documentation

static void cfattrib_c_dummy void   )  [static]
 

Definition at line 45 of file cfattrib.c.

classfile_attribute_enum cfattrib_atr2enum ClassFile pcfs,
u2  attribute_name_index
 

Map UTF8 string names for attributes in a constant_pool to LOCAL_xxx_ATTRIBUTE constants for the purpose of switch(int) instead of switch("string") code constructions.

Returns:
enumeration constant from classfile_attribute_enum

Definition at line 106 of file cfattrib.c.

References CMP_ATTRIBUTE, CONSTANT_UTF8_ANNOTATIONDEFAULT_ATTRIBUTE, CONSTANT_UTF8_CODE_ATTRIBUTE, CONSTANT_UTF8_CONSTANTVALUE_ATTRIBUTE, CONSTANT_UTF8_DEPRECATED_ATTRIBUTE, CONSTANT_UTF8_ENCLOSINGMETHOD_ATTRIBUTE, CONSTANT_UTF8_EXCEPTIONS_ATTRIBUTE, CONSTANT_UTF8_INNERCLASSES_ATTRIBUTE, CONSTANT_UTF8_LINENUMBERTABLE_ATTRIBUTE, CONSTANT_UTF8_LOCALVARIABLETABLE_ATTRIBUTE, CONSTANT_UTF8_LOCALVARIABLETYPETABLE_ATTRIBUTE, CONSTANT_UTF8_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE, CONSTANT_UTF8_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, CONSTANT_UTF8_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE, CONSTANT_UTF8_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, CONSTANT_UTF8_SIGNATURE_ATTRIBUTE, CONSTANT_UTF8_SOURCEFILE_ATTRIBUTE, CONSTANT_UTF8_SYNTHETIC_ATTRIBUTE, LOCAL_ANNOTATIONDEFAULT_ATTRIBUTE, LOCAL_CODE_ATTRIBUTE, LOCAL_CONSTANTVALUE_ATTRIBUTE, LOCAL_DEPRECATED_ATTRIBUTE, LOCAL_ENCLOSINGMETHOD_ATTRIBUTE, LOCAL_EXCEPTIONS_ATTRIBUTE, LOCAL_INNERCLASSES_ATTRIBUTE, LOCAL_LINENUMBERTABLE_ATTRIBUTE, LOCAL_LOCALVARIABLETABLE_ATTRIBUTE, LOCAL_LOCALVARIABLETYPETABLE_ATTRIBUTE, LOCAL_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, LOCAL_SIGNATURE_ATTRIBUTE, LOCAL_SOURCEFILE_ATTRIBUTE, LOCAL_SYNTHETIC_ATTRIBUTE, and LOCAL_UNKNOWN_ATTRIBUTE.

Referenced by attribute_enum_common_find(), cfattrib_loadattribute(), and classfile_loadclassdata().

rboolean cfattrib_iscodeattribute ClassFile pcfs,
u2  attribute_name_index
 

Short version of cfattrib_atr2enum(), but only check if an index refers to a Code_attribute area.

Returns:
rtrue if this attribute is indeed a CONSTANT_UTF8_CODE_ATTRIBUTE, otherwise rfalse.

Definition at line 217 of file cfattrib.c.

References CMP_ATTRIBUTE, CONSTANT_UTF8_CODE_ATTRIBUTE, rfalse, and rtrue.

u1* cfattrib_loadattribute ClassFile pcfs,
attribute_info_dup **  dst,
attribute_info src
 

Load an attribute and verify that it has either valid contents or is ignored as an unknown attribute.

If the attribute index is valid at all (for either a known or even an unknown but properly formed attribute), it will be copied into its destination area.

Parameters:
pcfs Pointer to (partially) parsed ClassFile area
dst Pointer to a attribute_info_dup[] address telling where in the heap this attribute will be copied from the source area.
src Pointer to an attribute in class file image. This data will be stored in the heap at location *dst .
Returns:
Point to first byte past this attribute, or rnull if parsing problem. If there is a problem, dst will contain a valid heap pointer only if there is a valid attribute_name_index, else it will also be rnull.
< Convenient alias for DML5

< Convenient alias for DML5

< Convenient alias for DML1

Todo:
Delete this when TODO: items below satisfied
Todo:
Verify "ConstantValue" attribute contents
Todo:
Verify "Code" attribute contents
Todo:
Verify "Exceptions" attribute contents
Todo:
Verify "InnerClasses" attribute contents
Todo:
"EnclosingMethod" attribute has nothing to verify
Todo:
"Signature" attribute has nothing to verify
Todo:
"Synthetic" attribute has nothing to verify
Todo:
Verify "SourceFile" attribute contents
Todo:
Verify "LineNumberTable" attribute contents
Todo:
Verify "LocalVariableTable" attribute contents
Todo:
Verify "LocalVariableTypeTable" attribute contents
Todo:
"Deprecated" attribute has nothing to verify
Todo:
Verify "RuntimeVisibleAnnotations" attribute contents
Todo:
Verify "RuntimeInvisibleAnnotations" attribute contents
Todo:
Verify "RuntimeVisibleParameterAnnotations" contents
Todo:
Verify "RuntimeInvisibleParameterAnnotations" contents
Todo:
"AnnotationDefault" attribute has nothing to verify

Todo:
Ignore unrecognized attribute. There really should not be anything to do here since the return value already points to the next attribute.

Definition at line 304 of file cfattrib.c.

References attribute_info::attribute_length, attribute_info::attribute_name_index, cfattrib_atr2enum(), cfattrib_loadattribute(), cfmsgs_typemsg(), ClassFile::constant_pool_count, DMLNORM, FILL_INFO_DUP0, FILL_INFO_DUP1, GENERIC_FAILURE_PTR, GETRI4, GETRS2, HEAP_GET_METHOD, attribute_info::info, LOAD_SYSCALL_FAILURE_ATTRIB, LOCAL_ANNOTATIONDEFAULT_ATTRIBUTE, LOCAL_CODE_ATTRIBUTE, LOCAL_CONSTANTVALUE_ATTRIBUTE, LOCAL_DEPRECATED_ATTRIBUTE, LOCAL_ENCLOSINGMETHOD_ATTRIBUTE, LOCAL_EXCEPTIONS_ATTRIBUTE, LOCAL_INNERCLASSES_ATTRIBUTE, LOCAL_LINENUMBERTABLE_ATTRIBUTE, LOCAL_LOCALVARIABLETABLE_ATTRIBUTE, LOCAL_LOCALVARIABLETYPETABLE_ATTRIBUTE, LOCAL_RUNTIMEINVISIBLEANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEINVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEVISIBLEANNOTATIONS_ATTRIBUTE, LOCAL_RUNTIMEVISIBLEPARAMETERANNOTATIONS_ATTRIBUTE, LOCAL_SIGNATURE_ATTRIBUTE, LOCAL_SOURCEFILE_ATTRIBUTE, LOCAL_SYNTHETIC_ATTRIBUTE, LOCAL_UNKNOWN_ATTRIBUTE, MACHINE_JINT_SWAP, MACHINE_JSHORT_SWAP, MAKE_PU2, PTR_DST_AI, rfalse, rnull, rtrue, and sysDbgMsg().

Referenced by cfattrib_loadattribute(), and classfile_loadclassdata().

rvoid cfattrib_unloadattribute ClassFile pcfs,
attribute_info_dup dst
 

UnLoad an attribute and free its heap area.

Parameters:
pcfs Pointer to (partially) parsed ClassFile area
dst Pointer to a attribute_info_dup allocation where this attribute is stored in the heap
Returns:
rvoid Whether it succeeds or fails, returning anything does not make much sense. This is similar to free(3) not returning anything even when a bad pointer was passed in.

Definition at line 705 of file cfattrib.c.


Variable Documentation

char* cfattrib_c_copyright = "\0" "$URL: https://svn.apache.org/path/name/cfattrib.c $ $Id: cfattrib.c 0 09/28/2005 dlydick $" " " "Copyright 2005 The Apache Software Foundation or its licensors, as applicable." [static]
 

Definition at line 45 of file cfattrib.c.


Generated on Fri Sep 30 18:49:29 2005 by  doxygen 1.4.4