Index: vm/vmcore/src/verifier/ver_subroutine.h =================================================================== --- vm/vmcore/src/verifier/ver_subroutine.h (revision 542211) +++ vm/vmcore/src/verifier/ver_subroutine.h (working copy) @@ -14,6 +14,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +#ifndef _VF_SUBROUTINE_H_ +#define _VF_SUBROUTINE_H_ + #include "ver_graph.h" /** @@ -77,6 +80,10 @@ * A current duplication index. */ unsigned m_index; + /** + * An OUT stack map of the ret node. + */ + vf_MapVector *m_outmap; }; /** @@ -125,10 +132,12 @@ */ vf_NodeStackHandle m_path_start; /** - * After the ret is resolved a ctx->m_map contains a - * correct input map for a node which follows jsr call. This is - * a pointer to the corresponding node stack. If this pointer is - * NULL we start from m_path_start stack entry. + * Equals to true when the map gets initialized. */ - vf_NodeStackHandle m_path_fork; + bool m_path_map_initialized; + /** + * A temporary map for subroutine data flow analysis. + */ + vf_MapVector *m_tmpmap; }; +#endif // _VF_SUBROUTINE_H_ Index: vm/vmcore/src/verifier/Graph.cpp =================================================================== --- vm/vmcore/src/verifier/Graph.cpp (revision 542211) +++ vm/vmcore/src/verifier/Graph.cpp (working copy) @@ -29,16 +29,15 @@ /** * Prints graph structure in stderr. */ -void -vf_Graph::DumpGraph() +void vf_Graph::DumpGraph() { #if _VF_DEBUG - VF_DEBUG( "Method: " << class_get_name( m_ctx->m_class ) << "::" - << m_ctx->m_name << m_ctx->m_descriptor << endl ); - VF_DEBUG( "-- start --" ); + VF_DEBUG("Method: " << class_get_name(m_ctx->m_class) << "::" + << m_ctx->m_name << m_ctx->m_descriptor << endl); + VF_DEBUG("-- start --"); ResetNodeIterator(); - while( HasMoreElements() ) { - DumpNode( GetNextNode() ); + while (HasMoreElements()) { + DumpNode(GetNextNode()); } #endif // _VF_DEBUG } // vf_Graph::DumpGraph @@ -46,59 +45,57 @@ /** * Prints graph node in stderr. */ -void -vf_Graph::DumpNode( vf_NodeHandle node ) // a graph node +void vf_Graph::DumpNode(vf_NodeHandle node) // a graph node { #if _VF_DEBUG // print node incoming edges vf_EdgeHandle edge; - for( edge = node->m_inedge; edge; edge = edge->m_innext ) { - VF_DEBUG( " [" << GetNodeNum( edge->m_start ) << "] -->" ); + for (edge = node->m_inedge; edge; edge = edge->m_innext) { + VF_DEBUG(" [" << GetNodeNum(edge->m_start) << "] -->"); } - switch ( node->m_type ) { + switch (node->m_type) { case VF_NODE_START_ENTRY: - VF_DEBUG( "node[" << GetNodeNum( node ) << "]: start node" ); + VF_DEBUG("node[" << GetNodeNum(node) << "]: start node"); break; case VF_NODE_END_ENTRY: - VF_DEBUG( "node[" << GetNodeNum( node ) << "]: end node" ); + VF_DEBUG("node[" << GetNodeNum(node) << "]: end node"); break; case VF_NODE_HANDLER: - VF_DEBUG( "node[" << GetNodeNum( node ) << "]: exception handler" ); + VF_DEBUG("node[" << GetNodeNum(node) << "]: exception handler"); break; default: - DumpNodeInternal( node ); + DumpNodeInternal(node); } // print node outcoming edges - for( edge = node->m_outedge; edge; edge = edge->m_outnext ) { - VF_DEBUG( " --> [" << GetNodeNum( edge->m_end ) << "]" ); + for (edge = node->m_outedge; edge; edge = edge->m_outnext) { + VF_DEBUG(" --> [" << GetNodeNum(edge->m_end) << "]"); } - VF_DEBUG( "" ); + VF_DEBUG(""); #endif // _VF_DEBUG } // vf_Graph::DumpNode /** * Prints graph node instruction in stream. */ -void -vf_Graph::DumpNodeInternal( vf_NodeHandle node ) // graph node number +void vf_Graph::DumpNodeInternal(vf_NodeHandle node) // graph node number { #if _VF_DEBUG // print node header - VF_DEBUG( "Node #" << GetNodeNum( node ) ); - VF_DEBUG( "Stack mod: " << node->m_stack ); - DumpSub( node->m_sub ); + VF_DEBUG("Node #" << GetNodeNum(node)); + VF_DEBUG("Stack mod: " << node->m_stack); + DumpSub(node->m_sub); // get code instructions unsigned count = node->m_end - node->m_start + 1; vf_InstrHandle instr = node->m_start; // print node instructions - for( unsigned index = 0; index < count; index++, instr++ ) { - VF_DEBUG( index << ": " << ( ( instr->m_stack < 0 ) ? "[" : "[ " ) - << instr->m_stack << "| " << instr->m_minstack << "] " - << vf_opcode_names[*( instr->m_addr )] ); + for (unsigned index = 0; index < count; index++, instr++) { + VF_DEBUG(index << ": " << ((instr->m_stack < 0) ? "[" : "[ ") + << instr->m_stack << "| " << instr->m_minstack << "] " + << vf_opcode_names[*(instr->m_addr)]); } #endif // _VF_DEBUG } // vf_Graph::DumpNodeInternal @@ -107,8 +104,7 @@ /** * Dumps graph node in file in DOT format. */ -void -vf_Graph::DumpDotGraph() +void vf_Graph::DumpDotGraph() { #if _VF_DEBUG /** @@ -118,23 +114,23 @@ const int MAX_LABEL_LENGTH = 80; // get class and method name - const char *class_name = class_get_name( m_ctx->m_class ); + const char *class_name = class_get_name(m_ctx->m_class); // create file name - size_t len = strlen( class_name ) + strlen( m_ctx->m_name ) - + strlen( m_ctx->m_descriptor ) + 6; - char *fname = (char*)STD_ALLOCA( len ); - sprintf( fname, "%s_%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor ); + size_t len = strlen(class_name) + strlen(m_ctx->m_name) + + strlen(m_ctx->m_descriptor) + 6; + char *fname = (char *) STD_ALLOCA(len); + sprintf(fname, "%s_%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor); char *f_start; char *pointer; - if( len > MAX_LABEL_LENGTH ) { + if (len > MAX_LABEL_LENGTH) { f_start = fname + len - MAX_LABEL_LENGTH; // shift to the start of the nearest lexem - for( pointer = f_start;; pointer++ ) { - if( isalnum( *pointer ) ) { + for (pointer = f_start;; pointer++) { + if (isalnum(*pointer)) { continue; - } else if( !*pointer ) { // end of the string + } else if (!*pointer) { // end of the string break; } else { // record the first matching position @@ -146,34 +142,34 @@ f_start = fname; } - for( pointer = f_start;; pointer++ ) { - if( isalnum( *pointer ) ) { + for (pointer = f_start;; pointer++) { + if (isalnum(*pointer)) { continue; - } else if( !*pointer ) { // end of the string + } else if (!*pointer) { // end of the string break; } else { *pointer = '_'; } } // pointer currently points to the end of the string - sprintf( pointer, ".dot" ); + sprintf(pointer, ".dot"); // create .dot file - ofstream fout( f_start ); - if( fout.fail() ) { - VF_DEBUG( "vf_Graph::DumpDotGraph: error opening file: " << f_start ); + ofstream fout(f_start); + if (fout.fail()) { + VF_DEBUG("vf_Graph::DumpDotGraph: error opening file: " << f_start); return; } // create name of graph - sprintf( fname, "%s.%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor ); + sprintf(fname, "%s.%s%s", class_name, m_ctx->m_name, m_ctx->m_descriptor); // print graph to file - DumpDotHeader( f_start, fout ); + DumpDotHeader(f_start, fout); ResetNodeIterator(); - while( HasMoreElements() ) { - DumpDotNode( GetNextNode(), fout ); + while (HasMoreElements()) { + DumpDotNode(GetNextNode(), fout); } - DumpDotEnd( fout ); + DumpDotEnd(fout); // close file fout.flush(); @@ -184,9 +180,8 @@ /** * Dumps graph header in file in DOT format. */ -void -vf_Graph::DumpDotHeader( const char *graph_name, // graph name - ofstream &out ) // output file stream +void vf_Graph::DumpDotHeader(const char *graph_name, // graph name + ofstream &out) // output file stream { #if _VF_DEBUG out << "digraph dotgraph {" << endl @@ -206,39 +201,37 @@ /** * Dumps graph node in file in DOT format. */ -void -vf_Graph::DumpDotNode( vf_NodeHandle node, // graph node number - ofstream &out ) // output file stream +void vf_Graph::DumpDotNode(vf_NodeHandle node, // graph node number + ofstream &out) // output file stream { #if _VF_DEBUG // print node to dot file - out << "node" << GetNodeNum( node ); - if( VF_NODE_START_ENTRY == node->m_type ) { // start node + out << "node" << GetNodeNum(node); + if (VF_NODE_START_ENTRY == node->m_type) { // start node out << " [label=\"START\", color=limegreen]" << endl; - } else if( VF_NODE_END_ENTRY == node->m_type ) { // end node + } else if (VF_NODE_END_ENTRY == node->m_type) { // end node out << " [label=\"END\", color=orangered]" << endl; - } else if( VF_NODE_HANDLER == node->m_type ) { // handler node + } else if (VF_NODE_HANDLER == node->m_type) { // handler node out << " [label=\"Handler #" - << GetNodeNum( node ) << "\", shape=ellipse, color="; - if( node->m_sub ) { + << GetNodeNum(node) << "\", shape=ellipse, color="; + if (node->m_sub) { out << "\"#B7FFE" << hex - << ( vf_get_sub_num( node->m_sub, m_ctx ) % - 16 ) << dec << "\""; + << (vf_get_sub_num(node->m_sub, m_ctx) % 16) << dec << "\""; } else { out << "aquamarine"; } out << "]" << endl; } else { // other nodes - DumpDotNodeInternal( node, "\\n---------\\n", "\\l", out ); + DumpDotNodeInternal(node, "\\n---------\\n", "\\l", out); } // print node outcoming edges to dot file - for( vf_EdgeHandle edge = node->m_outedge; edge; edge = edge->m_outnext ) { - out << "node" << GetNodeNum( node ) << " -> " - << "node" << GetNodeNum( edge->m_end ); - if( VF_NODE_HANDLER == edge->m_end->m_type ) { + for (vf_EdgeHandle edge = node->m_outedge; edge; edge = edge->m_outnext) { + out << "node" << GetNodeNum(node) << " -> " + << "node" << GetNodeNum(edge->m_end); + if (VF_NODE_HANDLER == edge->m_end->m_type) { out << "[color=red]" << endl; - } else if( vf_is_jsr_branch( edge, m_ctx ) ) { + } else if (vf_is_jsr_branch(edge, m_ctx)) { out << "[color=blue]" << endl; } out << ";" << endl; @@ -249,16 +242,15 @@ /** * Dumps graph node instruction in file stream in DOT format. */ -void -vf_Graph::DumpDotNodeInternal( vf_NodeHandle node, // graph node number - char *next_node, // separator between nodes in stream - char *next_instr, // separator between instructions in stream - ofstream &out ) // output file stream +void vf_Graph::DumpDotNodeInternal(vf_NodeHandle node, // graph node number + char *next_node, // separator between nodes in stream + char *next_instr, // separator between instructions in stream + ofstream &out) // output file stream { #if _VF_DEBUG // print node header out << " [label=\""; - out << "Node " << GetNodeNum( node ) << next_node + out << "Node " << GetNodeNum(node) << next_node << "Stack mod: " << node->m_stack << next_node; // get code instructions @@ -266,16 +258,16 @@ vf_InstrHandle instr = node->m_start; // print node instructions - for( unsigned index = 0; index < count; index++, instr++ ) { - out << index << ": " << ( ( instr->m_stack < 0 ) ? "[" : "[ " ) + for (unsigned index = 0; index < count; index++, instr++) { + out << index << ": " << ((instr->m_stack < 0) ? "[" : "[ ") << instr->m_stack << "\\| " << instr->m_minstack << "] " - << vf_opcode_names[*( instr->m_addr )] << next_instr; + << vf_opcode_names[*(instr->m_addr)] << next_instr; } out << "\"" << endl; - if( node->m_sub ) { + if (node->m_sub) { out << ", color=\"#B2F" << hex - << ( vf_get_sub_num( node->m_sub, m_ctx ) % 16 ) << dec << "EE\""; + << (vf_get_sub_num(node->m_sub, m_ctx) % 16) << dec << "EE\""; } out << "]" << endl; #endif // _VF_DEBUG @@ -284,8 +276,7 @@ /** * Dumps graph end in file in DOT format. */ -void -vf_Graph::DumpDotEnd( ofstream &out ) // output file stream +void vf_Graph::DumpDotEnd(ofstream &out) // output file stream { #if _VF_DEBUG out << "}" << endl; @@ -299,8 +290,7 @@ /** * Creates bytecode control flow graph. */ -vf_Result -vf_create_graph( vf_Context *ctx ) // verification context +vf_Result vf_create_graph(vf_Context *ctx) // verification context { vf_BCode *bc = ctx->m_bc; @@ -310,17 +300,17 @@ */ unsigned edges = 0; unsigned short handler_count = ctx->m_handlers; - for( unsigned short handler_index = 0; handler_index < handler_count; - handler_index++ ) { + for (unsigned short handler_index = 0; handler_index < handler_count; + handler_index++) { unsigned short start_pc, end_pc, handler_pc, handler_cp_index, count; - method_get_exc_handler_info( ctx->m_method, handler_index, - &start_pc, &end_pc, &handler_pc, - &handler_cp_index ); + method_get_exc_handler_info(ctx->m_method, handler_index, + &start_pc, &end_pc, &handler_pc, + &handler_cp_index); // number of basic blocks in the exception range unsigned handler_edges = 0; - for( count = start_pc; count < end_pc; count++ ) { - if( bc[count].m_is_bb_start ) { + for (count = start_pc; count < end_pc; count++) { + if (bc[count].m_is_bb_start) { handler_edges++; } } @@ -337,23 +327,23 @@ /** * Check instruction offsets, count basic blocks and edges. */ - for( unsigned index = 0; index < ctx->m_len; index++ ) { + for (unsigned index = 0; index < ctx->m_len; index++) { vf_InstrHandle instr = bc[index].m_instr; - if( NULL == instr ) { - if( bc[index].m_is_bb_start ) { - VF_REPORT( ctx, "Illegal target of jump or branch" ); - return VER_ErrorBranch; + if (NULL == instr) { + if (bc[index].m_is_bb_start) { + VF_REPORT(ctx, "Illegal target of jump or branch"); + return VF_ErrorBranch; } else { continue; } } - if( bc[index].m_is_bb_start ) { - ( (vf_Instr*)instr )->m_is_bb_start = true; + if (bc[index].m_is_bb_start) { + ((vf_Instr *) instr)->m_is_bb_start = true; nodes++; } - if( instr->m_offcount ) { + if (instr->m_offcount) { // basic block should start next, so we will // count one branch anyway edges += instr->m_offcount - 1; @@ -367,107 +357,106 @@ edges += nodes - 1 - ctx->m_retnum; // allocate memory for graph structure - void *mem_graph = vf_palloc( ctx->m_pool, sizeof( vf_Graph ) ); + void *mem_graph = vf_palloc(ctx->m_pool, sizeof(vf_Graph)); // for graph creation use pre-calculated numbers - vf_Graph *graph = new( mem_graph ) vf_Graph( nodes, edges, ctx ); + vf_Graph *graph = new(mem_graph) vf_Graph(nodes, edges, ctx); ctx->m_graph = graph; /** * Create nodes. */ - graph->NewNode( VF_NODE_START_ENTRY ); + graph->NewNode(VF_NODE_START_ENTRY); // create handler nodes unsigned node_index; - for( node_index = 1; node_index <= ( unsigned )handler_count; - node_index++ ) { - graph->NewNode( VF_NODE_HANDLER ); + for (node_index = 1; node_index <= (unsigned) handler_count; node_index++) { + graph->NewNode(VF_NODE_HANDLER); } // create code range nodes right after the last handler node // a new node correspond to a subsequent basic block of instructions - for( vf_InstrHandle bb_start = ctx->m_instr; - bb_start < ctx->m_last_instr; node_index++ ) { + for (vf_InstrHandle bb_start = ctx->m_instr; + bb_start < ctx->m_last_instr; node_index++) { // find a basic block end vf_InstrHandle next_bb_start = bb_start + 1; - while( ( next_bb_start < ctx->m_last_instr ) - && ( !next_bb_start->m_is_bb_start ) ) { + while ((next_bb_start < ctx->m_last_instr) + && (!next_bb_start->m_is_bb_start)) { next_bb_start++; } - ( (vf_Instr*)bb_start )->m_node = - graph->NewNode( bb_start, next_bb_start - 1 ); + ((vf_Instr *) bb_start)->m_node = + graph->NewNode(bb_start, next_bb_start - 1); bb_start = next_bb_start; } // create exit-entry node graph->AddEndNode(); unsigned node_num = node_index + 1; - assert( 0 == graph->HasMoreNodeSpace() ); + assert(0 == graph->HasMoreNodeSpace()); /** * Create edges. */ - vf_Node *node = (vf_Node*)graph->GetNode( handler_count + 1 ); + vf_Node *node = (vf_Node *) graph->GetNode(handler_count + 1); // from start-entry node to the first code range node - graph->NewEdge( (vf_Node*)graph->GetStartNode(), node ); + graph->NewEdge((vf_Node *) graph->GetStartNode(), node); // create code range edges - for( ; VF_NODE_CODE_RANGE == node->m_type; node++ ) { + for (; VF_NODE_CODE_RANGE == node->m_type; node++) { vf_InstrHandle instr = node->m_end; // set control flow edges - if( instr->m_offcount ) { - for( unsigned count = 0; count < instr->m_offcount; count++ ) { - int offset = vf_get_instr_branch( instr, count ); + if (instr->m_offcount) { + for (unsigned count = 0; count < instr->m_offcount; count++) { + int offset = vf_get_instr_branch(instr, count); vf_Node *next_node = - (vf_Node*)graph->GetNodeFromBytecodeIndex( offset ); - assert( node ); + (vf_Node *) graph->GetNodeFromBytecodeIndex(offset); + assert(node); - graph->NewEdge( node, next_node ); - if( next_node < node ) { + graph->NewEdge(node, next_node); + if (next_node < node) { // node has a backward branch, thus any // object on the stack should be initialized node->m_initialized = true; } } - } else if( VF_INSTR_RETURN == instr->m_type - || VF_INSTR_THROW == instr->m_type ) { - graph->NewEdge( node, (vf_Node*)graph->GetEndNode() ); - } else if( VF_INSTR_RET == instr->m_type ) { + } else if (VF_INSTR_RETURN == instr->m_type + || VF_INSTR_THROW == instr->m_type) { + graph->NewEdge(node, (vf_Node *) graph->GetEndNode()); + } else if (VF_INSTR_RET == instr->m_type) { // no edges from ret - } else if( VF_NODE_CODE_RANGE == ( node + 1 )->m_type ) { - graph->NewEdge( node, node + 1 ); + } else if (VF_NODE_CODE_RANGE == (node + 1)->m_type) { + graph->NewEdge(node, node + 1); } else { - VF_REPORT( ctx, "Falling off the end of the code" ); - return VER_ErrorBranch; + VF_REPORT(ctx, "Falling off the end of the code"); + return VF_ErrorBranch; } } - assert( VF_NODE_END_ENTRY == node->m_type ); + assert(VF_NODE_END_ENTRY == node->m_type); // create OUT map vectors for handler nodes - unsigned char *start_bc = method_get_bytecode( ctx->m_method ); - for( unsigned short handler_index = 0; - handler_index < handler_count; handler_index++ ) { + unsigned char *start_bc = method_get_bytecode(ctx->m_method); + for (unsigned short handler_index = 0; + handler_index < handler_count; handler_index++) { unsigned short start_pc, end_pc, handler_pc, handler_cp_index; - method_get_exc_handler_info( ctx->m_method, - handler_index, &start_pc, &end_pc, - &handler_pc, &handler_cp_index ); + method_get_exc_handler_info(ctx->m_method, + handler_index, &start_pc, &end_pc, + &handler_pc, &handler_cp_index); vf_ValidType *type = NULL; - if( handler_cp_index ) { - const char *name = vf_get_cp_class_name( ctx->m_class, - handler_cp_index ); - assert( name ); - type = vf_create_class_valid_type( name, ctx ); + if (handler_cp_index) { + const char *name = vf_get_cp_class_name(ctx->m_class, + handler_cp_index); + assert(name); + type = vf_create_class_valid_type(name, ctx); // set restriction for handler class - if( ctx->m_vtype.m_throwable->string[0] != type->string[0] ) { - ctx->m_type->SetRestriction( ctx->m_vtype.m_throwable-> - string[0], type->string[0], 0, - VF_CHECK_SUPER ); + if (ctx->m_vtype.m_throwable->string[0] != type->string[0]) { + ctx->m_type->SetRestriction(ctx->m_vtype.m_throwable-> + string[0], type->string[0], 0, + VF_CHECK_SUPER); } } @@ -478,42 +467,41 @@ * incoming map vector, local variables map vector will be * created with during the process of merge. */ - vf_MapVector *p_outvector = (vf_MapVector*) - &graph->GetNode( handler_index + 1 )->m_outmap; + vf_MapVector *p_outvector = (vf_MapVector *) + &graph->GetNode(handler_index + 1)->m_outmap; p_outvector->m_stack = - (vf_MapEntry*)graph->AllocMemory( sizeof( vf_MapEntry ) * - ctx->m_maxstack ); + (vf_MapEntry *) graph->AllocMemory(sizeof(vf_MapEntry) * + ctx->m_maxstack); p_outvector->m_depth = 1; - vf_set_vector_stack_entry_ref( p_outvector->m_stack, 0, type ); + vf_set_vector_stack_entry_ref(p_outvector->m_stack, 0, type); // outcoming handler edge - vf_Node *handler_node = - (vf_Node*)graph->GetNode( handler_index + 1 ); - graph->NewEdge( handler_node, - (vf_Node*)graph-> - GetNodeFromBytecodeIndex( handler_pc ) ); + vf_Node *handler_node = (vf_Node *) graph->GetNode(handler_index + 1); + graph->NewEdge(handler_node, + (vf_Node *) graph-> + GetNodeFromBytecodeIndex(handler_pc)); // node range start - node = (vf_Node*)graph->GetNodeFromBytecodeIndex( start_pc ); + node = (vf_Node *) graph->GetNodeFromBytecodeIndex(start_pc); - vf_NodeHandle last_node = ( end_pc == ctx->m_len ) + vf_NodeHandle last_node = (end_pc == ctx->m_len) ? graph->GetEndNode() - : graph->GetNodeFromBytecodeIndex( end_pc ); + : graph->GetNodeFromBytecodeIndex(end_pc); - for( ; node < last_node; node++ ) { + for (; node < last_node; node++) { // node is protected by exception handler, thus the // reference in local variables have to be initialized node->m_initialized = true; - graph->NewEdge( node, handler_node ); + graph->NewEdge(node, handler_node); } } // one edge is reserved - assert( 0 == graph->HasMoreEdgeSpace() ); + assert(0 == graph->HasMoreEdgeSpace()); - VF_DUMP( DUMP_GRAPH, graph->DumpGraph() ); - VF_DUMP( DUMP_DOT, graph->DumpDotGraph() ); + VF_DUMP(DUMP_GRAPH, graph->DumpGraph()); + VF_DUMP(DUMP_DOT, graph->DumpDotGraph()); - return VER_OK; + return VF_OK; } // vf_create_graph /************************************************************ @@ -522,21 +510,20 @@ /** * Checks stack depth of a node. */ -vf_Result -vf_check_node_stack_depth( vf_Node *node, // a graph node - unsigned &depth, // initial stack depth - vf_Context *ctx ) // verification context +vf_Result vf_check_node_stack_depth(vf_Node *node, // a graph node + unsigned &depth, // initial stack depth + vf_Context *ctx) // verification context { - if( node->m_mark ) { - if( ( depth == node->m_inmap.m_depth ) - || ( VF_NODE_CODE_RANGE != node->m_type ) ) { + if (node->m_mark) { + if ((depth == node->m_inmap.m_depth) + || (VF_NODE_CODE_RANGE != node->m_type)) { // consistent stack depth in the node - return VER_OK; + return VF_OK; } else { // inconsistent stack depth - VF_REPORT( ctx, "Inconsistent stack depth: " - << node->m_inmap.m_depth << " != " << depth ); - return VER_ErrorStackDepth; + VF_REPORT(ctx, "Inconsistent stack depth: " + << node->m_inmap.m_depth << " != " << depth); + return VF_ErrorStackDepth; } } // mark the node @@ -547,110 +534,117 @@ graph->IncrementReachableCount(); node->m_inmap.m_depth = depth; - if( VF_NODE_CODE_RANGE != node->m_type ) { - if( VF_NODE_HANDLER == node->m_type ) { + if (VF_NODE_CODE_RANGE != node->m_type) { + if (VF_NODE_HANDLER == node->m_type) { depth = 1; node->m_stack = 1; node->m_outmap.m_depth = 1; - } else if( VF_NODE_END_ENTRY == node->m_type ) { - return VER_OK; + } else if (VF_NODE_END_ENTRY == node->m_type) { + return VF_OK; } - return VER_Continue; + return VF_Continue; } // calculate a stack depth after the last node instruction int stack_depth = 0; - for( vf_InstrHandle instr = node->m_start; instr <= node->m_end; instr++ ) { - if( instr->m_minstack > depth ) { - VF_REPORT( ctx, - "Unable to pop operands needed for an instruction" ); - return VER_ErrorStackUnderflow; + for (vf_InstrHandle instr = node->m_start; instr <= node->m_end; instr++) { + if (instr->m_minstack > depth) { + VF_REPORT(ctx, + "Unable to pop operands needed for an instruction"); + return VF_ErrorStackUnderflow; } stack_depth += instr->m_stack; depth += instr->m_stack; - assert( depth >= 0 ); - if( depth > ctx->m_maxstack ) { - VF_REPORT( ctx, "Instruction stack overflow" ); - return VER_ErrorStackOverflow; + assert(depth >= 0); + if (depth > ctx->m_maxstack) { + VF_REPORT(ctx, "Instruction stack overflow"); + return VF_ErrorStackOverflow; } } node->m_stack = stack_depth; node->m_outmap.m_depth = depth; - return VER_Continue; + return VF_Continue; } // vf_check_node_stack_depth /** * Checks graph nodes stack depth consistency recursively. * Returns result of a check. */ -static vf_Result -vf_check_stack_depth( vf_Node *node, // a graph node - unsigned stack_depth, // initial stack depth of node - vf_Context *ctx ) // verification context +static vf_Result vf_check_stack_depth(vf_Node *node, // a graph node + unsigned stack_depth, // initial stack depth of node + vf_Context *ctx) // verification context { // check for node stack overflow - vf_Result result = vf_check_node_stack_depth( node, stack_depth, ctx ); - if( result != VER_Continue ) { + vf_Result result = vf_check_node_stack_depth(node, stack_depth, ctx); + if (VF_Continue != result) { return result; } // iterate over out edges and set stack depth for out nodes - for( vf_EdgeHandle outedge = node->m_outedge; - outedge; outedge = outedge->m_outnext ) { + for (vf_EdgeHandle outedge = node->m_outedge; + outedge; outedge = outedge->m_outnext) { // get out node - vf_Node *outnode = (vf_Node*)outedge->m_end; + vf_Node *outnode = (vf_Node *) outedge->m_end; // mark out node with its out nodes - result = vf_check_stack_depth( outnode, stack_depth, ctx ); - if( VER_OK != result ) { + result = vf_check_stack_depth(outnode, stack_depth, ctx); + if (VF_OK != result) { return result; } } - return VER_OK; + return VF_OK; } // vf_check_stack_depth /** * Removes in edge from the list of the corresponding end node. */ -static void -vf_remove_inedge( vf_EdgeHandle edge ) // verification context +static void vf_remove_inedge(vf_EdgeHandle edge) // verification context { - vf_EdgeHandle *p_next_edge = (vf_EdgeHandle*) & edge->m_end->m_inedge; - vf_Edge *inedge = (vf_Edge*) edge->m_end->m_inedge; - while( inedge ) { - if( inedge == edge ) { + vf_EdgeHandle *p_next_edge = (vf_EdgeHandle *) & edge->m_end->m_inedge; + vf_Edge *inedge = (vf_Edge *) edge->m_end->m_inedge; + while (inedge) { + if (inedge == edge) { // remove the edge from the list *p_next_edge = inedge->m_innext; return; } p_next_edge = &inedge->m_innext; - inedge = (vf_Edge*) inedge->m_innext; + inedge = (vf_Edge *) inedge->m_innext; } - VF_DIE( "vf_remove_inedge: Cannot find an IN edge " << edge - << " from the list of the node " << edge->m_end ); + VF_DIE("vf_remove_inedge: Cannot find an IN edge " << edge + << " from the list of the node " << edge->m_end); } /** * Scans dead nodes, removes obsolete edges and fills corresponding bytecode by nop * instruction. */ -static void -vf_nullify_unreachable_bytecode( vf_ContextHandle ctx ) // verification context +static void vf_nullify_unreachable_bytecode(vf_ContextHandle ctx) // verification context { vf_Node *node = - (vf_Node*)ctx->m_graph->GetStartNode()->m_outedge->m_end; - for( ; node->m_type != VF_NODE_END_ENTRY; node++ ) { - assert( VF_NODE_CODE_RANGE == node->m_type ); - if( !node->m_mark ) { + (vf_Node *) ctx->m_graph->GetStartNode()->m_outedge->m_end; + for (; node->m_type != VF_NODE_END_ENTRY; node++) { + assert(VF_NODE_CODE_RANGE == node->m_type); + if (!node->m_mark) { + VF_TRACE("node", + "Cleaning unreachable node #" << ctx->m_graph-> + GetNodeNum(node)); unsigned char *instr = node->m_start->m_addr; - const unsigned char *end = vf_get_instr_end( node->m_end, ctx ); - while( instr < end ) { - *( instr++ ) = OPCODE_NOP; + const unsigned char *end = vf_get_instr_end(node->m_end, ctx); + while (instr < end) { + *(instr++) = OPCODE_NOP; } node->m_stack = 0; // we assume that java compiler generally doesn't generate a dead code, // so we rarely remove edges here is rare - for( vf_EdgeHandle edge = node->m_outedge; edge; - edge = edge->m_outnext ) { - vf_remove_inedge( edge ); + for (vf_EdgeHandle edge = node->m_outedge; edge; + edge = edge->m_outnext) { + assert(edge->m_start == node); + VF_TRACE("edge", "Cleaning unreachable edge #" + << ctx->m_graph->GetNodeNum(node) << " -> #" + << ctx->m_graph->GetNodeNum(edge->m_end)); + if (edge->m_end->m_mark) { + // remove edges to reachable nodes + vf_remove_inedge(edge); + } } node->m_inedge = node->m_outedge = NULL; node->m_sub = NULL; @@ -662,8 +656,7 @@ /** * Provides checks of control flow and data flow structures of graph. */ -vf_Result -vf_check_graph( vf_Context *ctx ) // verification context +vf_Result vf_check_graph(vf_Context *ctx) // verification context { vf_Graph *graph = ctx->m_graph; vf_InstrHandle instr = ctx->m_instr; @@ -671,70 +664,67 @@ vf_Result result; // allocate a current stack map vector - ctx->m_map = (vf_MapVector*)vf_palloc( ctx->m_pool, - sizeof( vf_MapVector ) ); - ctx->m_graph->AllocVector( ctx->m_map ); + ctx->m_map = (vf_MapVector *) vf_palloc(ctx->m_pool, + sizeof(vf_MapVector)); + ctx->m_graph->AllocVector(ctx->m_map); // create a buf stack map vector (max 4 entries) - ctx->m_buf = (vf_MapEntry*)vf_palloc( ctx->m_pool, - sizeof( vf_MapEntry ) - * ctx->m_maxstack ); + ctx->m_buf = (vf_MapEntry *) vf_palloc(ctx->m_pool, sizeof(vf_MapEntry) + * ctx->m_maxstack); - if( ctx->m_retnum ) { - result = vf_mark_subroutines( ctx ); + if (ctx->m_retnum) { + result = vf_mark_subroutines(ctx); } else { result = - vf_check_stack_depth( (vf_Node*)graph->GetStartNode(), 0, - ctx ); + vf_check_stack_depth((vf_Node *) graph->GetStartNode(), 0, ctx); } - if( VER_OK != result ) { + if (VF_OK != result) { return result; } // there could be only nop opcodes in the bytecode, in this case // the code is already checked during previous step - if( ctx->m_maxstack == 0 ) { - return VER_OK; + if (ctx->m_maxstack == 0) { + return VF_OK; } // override all dead nodes - assert( graph->GetReachableNodeCount() <= graph->GetNodeCount() ); - if( graph->GetReachableNodeCount() < graph->GetNodeCount() ) { - vf_nullify_unreachable_bytecode( ctx ); + assert(graph->GetReachableNodeCount() <= graph->GetNodeCount()); + if (graph->GetReachableNodeCount() < graph->GetNodeCount()) { + vf_nullify_unreachable_bytecode(ctx); } - if( ctx->m_retnum ) { - result = vf_inline_subroutines( ctx ); - if( VER_OK != result ) { + if (ctx->m_retnum) { + result = vf_inline_subroutines(ctx); + if (VF_OK != result) { return result; } } - VF_DUMP( DUMP_MOD, graph->DumpGraph() ); - VF_DUMP( DUMP_DOT_MOD, graph->DumpDotGraph() ); + VF_DUMP(DUMP_MOD, graph->DumpGraph()); + VF_DUMP(DUMP_DOT_MOD, graph->DumpDotGraph()); /** * Check that execution flow terminates with * return or athrow bytecodes. * Override all incoming edges to the end-entry node. */ - for( vf_EdgeHandle inedge = - graph->GetEndNode()->m_inedge; inedge; - inedge = inedge->m_innext ) { + for (vf_EdgeHandle inedge = + graph->GetEndNode()->m_inedge; inedge; inedge = inedge->m_innext) { // get incoming node vf_NodeHandle innode = inedge->m_start; // get node last instruction vf_InstrType type = innode->m_end->m_type; - if( ( VF_INSTR_RETURN != type ) && ( VF_INSTR_THROW != type ) ) { + if ((VF_INSTR_RETURN != type) && (VF_INSTR_THROW != type)) { // illegal instruction - VF_REPORT( ctx, "Falling off the end of the code" ); - return VER_ErrorCodeEnd; + VF_REPORT(ctx, "Falling off the end of the code"); + return VF_ErrorCodeEnd; } } /** * Make data flow analysis */ - result = vf_check_graph_data_flow( ctx ); + result = vf_check_graph_data_flow(ctx); return result; } // vf_check_graph @@ -742,13 +732,12 @@ /** * Frees memory allocated for graph, if any. */ -void -vf_free_graph( vf_Context *ctx ) // verification context +void vf_free_graph(vf_Context *ctx) // verification context { - if( ctx->m_graph ) { - VF_TRACE( "method", VF_REPORT_CTX( ctx ) << "method graph: " - << " nodes: " << ctx->m_graph->GetNodeCount() - << ", edges: " << ctx->m_graph->GetEdgeCount() ); + if (ctx->m_graph) { + VF_TRACE("method", VF_REPORT_CTX(ctx) << "method graph: " + << " nodes: " << ctx->m_graph->GetNodeCount() + << ", edges: " << ctx->m_graph->GetEdgeCount()); ctx->m_graph->~vf_Graph(); ctx->m_graph = NULL; } Index: vm/vmcore/src/verifier/ver_graph.h =================================================================== --- vm/vmcore/src/verifier/ver_graph.h (revision 542211) +++ vm/vmcore/src/verifier/ver_graph.h (working copy) @@ -20,8 +20,8 @@ */ -#ifndef _VERIFIER_GRAPH_H_ -#define _VERIFIER_GRAPH_H_ +#ifndef _VF_GRAPH_H_ +#define _VF_GRAPH_H_ /** * @file * Control flow graph structures. @@ -132,7 +132,7 @@ * @return a container */ static inline vf_ContainerHandle vf_get_container(vf_ContainerHandle - container, unsigned &n) + container, unsigned &n) { while (n >= container->m_max) { n -= container->m_max; @@ -149,7 +149,7 @@ * @param[in] new_container a new container to be placed at the end of the list */ static inline void vf_add_container(vf_ContainerHandle head, - vf_ContainerHandle new_container) + vf_ContainerHandle new_container) { while (head->m_next) { head = head->m_next; @@ -352,7 +352,8 @@ * @note Empty in release mode. */ void DumpDotNodeInternal(vf_NodeHandle node, - char *next_node, char *next_instr, ofstream &fout); + char *next_node, char *next_instr, + ofstream &fout); /** * Dumps graph end in file in DOT format. @@ -369,10 +370,8 @@ * @param edgenum a number of graph edges * @param ctx a verification context */ - - vf_Graph(unsigned nodenum, unsigned edgenum, - vf_ContextHandle ctx):m_nodes(NULL), m_edges(NULL), + vf_ContextHandle ctx):m_nodes(NULL), m_edges(NULL), m_pool(ctx->m_pool), m_enum(NULL), m_nodenum(0), m_edgenum(0), m_enumcount(0), m_ctx(ctx), m_free(false) { @@ -399,7 +398,7 @@ assert(count > 0); vf_NodeContainer *nodes = (vf_NodeContainer *) AllocMemory(sizeof(vf_NodeContainer) - + (count - 1) * sizeof(vf_Node)); + + (count - 1) * sizeof(vf_Node)); nodes->container.m_max = count; if (m_nodes == NULL) { @@ -418,7 +417,7 @@ assert(count > 0); vf_EdgeContainer *edges = (vf_EdgeContainer *) AllocMemory(sizeof(vf_EdgeContainer) - + (count - 1) * sizeof(vf_Edge)); + + (count - 1) * sizeof(vf_Edge)); edges->container.m_max = count; if (m_edges == NULL) { m_edges = edges; @@ -440,11 +439,10 @@ vf_NodeContainer *nodes = (vf_NodeContainer *) vf_get_container(&m_nodes->container, - node_num); + node_num); return nodes->m_node + node_num; } // GetNode - /** * Gets a graph node from a program counter. * @@ -455,10 +453,6 @@ { vf_InstrHandle instr = m_ctx->m_bc[pc].m_instr; assert(instr); - - - - assert(m_ctx->m_bc[pc].m_instr->m_addr - m_ctx->m_bytes == pc); vf_NodeHandle node = instr->m_node; assert(GetNodeNum(node) > m_ctx->m_handlers); @@ -575,8 +569,8 @@ assert(m_edges); VF_TRACE("graph", - "Creating a new edge from " << GetNodeNum(start_node) - << " to " << GetNodeNum(end_node)); + "Creating a new edge from " << GetNodeNum(start_node) + << " to " << GetNodeNum(end_node)); unsigned count = m_edgenum; vf_EdgeContainer *edges = (vf_EdgeContainer *) vf_get_container(&m_edges->container, count); @@ -682,7 +676,7 @@ // allocate memory m_enum = (vf_NodeHandle *) vf_palloc(m_pool, sizeof(vf_NodeHandle) - * m_nodenum); + * m_nodenum); // clean node enumeration ResetNodeIterator(); @@ -808,13 +802,15 @@ if (m_ctx->m_maxlocal && !vector->m_local) { vector->m_local = (vf_MapEntry *) vf_palloc(m_pool, - m_ctx->m_maxlocal * sizeof(vf_MapEntry)); + m_ctx->m_maxlocal * + sizeof(vf_MapEntry)); } // create and set stack vector if (m_ctx->m_maxstack && !vector->m_stack) { vector->m_stack = (vf_MapEntry *) vf_palloc(m_pool, - m_ctx->m_maxstack * sizeof(vf_MapEntry)); + m_ctx->m_maxstack * + sizeof(vf_MapEntry)); } } @@ -918,8 +914,8 @@ * error code otherwise */ vf_Result vf_check_node_stack_depth(vf_Node *node, // a graph node - unsigned &depth, // stack depth - vf_Context *ctx); // verification context + unsigned &depth, // stack depth + vf_Context *ctx); // verification context /** * Creates and sets graph node OUT vector. @@ -932,6 +928,16 @@ */ vf_Result vf_set_node_out_vector(vf_NodeHandle node, - vf_MapVector *invector, vf_Context *ctx); + vf_MapVector *invector, vf_Context *ctx); -#endif // _VERIFIER_GRAPH_H_ +/** + * Prints data flow vector into output stream. + * @param vector a data flow vector + * @param instr a code instruction + * @param stream an output stream (can be NULL) + */ +void vf_dump_vector(vf_MapVectorHandle vector, // data flow vector + vf_InstrHandle instr, // code instruction + ostream *stream); // output stream (can be NULL) + +#endif // _VF_GRAPH_H_ Index: vm/vmcore/src/verifier/ver_real.h =================================================================== --- vm/vmcore/src/verifier/ver_real.h (revision 542211) +++ vm/vmcore/src/verifier/ver_real.h (working copy) @@ -20,8 +20,8 @@ */ -#ifndef _VERIFIER_REAL_H_ -#define _VERIFIER_REAL_H_ +#ifndef _VF_REAL_H_ +#define _VF_REAL_H_ /** * @file @@ -149,61 +149,61 @@ #define CHECK_HANDLER_CONST_POOL_ID( id, len, ctx ) \ if( (id) >= (len) ) { \ VF_REPORT( ctx, "Illegal constant pool index in handler" ); \ - return VER_ErrorHandler; \ + return VF_ErrorHandler; \ } // for handler id = 0 is legal value #define CHECK_HANDLER_CONST_POOL_CLASS( ctx, id ) \ if( (id) && class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_Class ) { \ VF_REPORT( ctx, "Illegal type in constant pool for handler, " \ << id << ": CONSTANT_Class is expected" ); \ - return VER_ErrorHandler; \ + return VF_ErrorHandler; \ } #define CHECK_CONST_POOL_ID( id, len, ctx ) \ if( !(id) || (id) >= (len) ) { \ VF_REPORT( ctx, "Illegal constant pool index" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } #define CHECK_CONST_POOL_CLASS( ctx, id ) \ if( class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_Class ) { \ VF_REPORT( ctx, "Illegal type in constant pool, " \ << id << ": CONSTANT_Class is expected" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } #define CHECK_CONST_POOL_METHOD( ctx, id ) \ if( class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_Methodref ) { \ VF_REPORT( ctx, "Illegal type in constant pool, " \ << id << ": CONSTANT_Methodref is expected" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } #define CHECK_CONST_POOL_INTERFACE( ctx, id ) \ if( class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_InterfaceMethodref ) { \ VF_REPORT( ctx, "Illegal type in constant pool, " \ << id << ": CONSTANT_InterfaceMethodref is expected" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } #define CHECK_CONST_POOL_FIELD( ctx, id ) \ if( class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_Fieldref ) { \ VF_REPORT( ctx, "Illegal type in constant pool, " \ << id << ": CONSTANT_Fieldref is expected" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } #define CHECK_CONST_POOL_TYPE( ctx, id ) \ if( class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_NameAndType ) { \ VF_REPORT( ctx, "Illegal type in constant pool, " \ << id << ": CONSTANT_NameAndType is expected" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } #define CHECK_CONST_POOL_STRING( ctx, id ) \ if( class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_String ) { \ VF_REPORT( ctx, "Illegal type in constant pool, " \ << id << ": CONSTANT_String is expected" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } #define CHECK_CONST_POOL_UTF8( ctx, id ) \ if( class_get_cp_tag( (ctx)->m_class, (id) ) != _CONSTANT_Utf8) { \ VF_REPORT( ctx, "Illegal type in constant pool, " \ << id << ": CONSTANT_Utf8 is expected" ); \ - return VER_ErrorConstantPool; \ + return VF_ErrorConstantPool; \ } //=========================================================== @@ -211,11 +211,6 @@ //=========================================================== /** - * Verifier error codes. - */ -typedef Verifier_Result vf_Result; - -/** * Constraint check types enum. */ typedef enum @@ -337,6 +332,8 @@ { unsigned m_new; ///< program count of opcode new for uninitialized unsigned m_pc; ///< program count of return address for subroutine + unsigned m_mappos; ///< for SM_ANY a position in the initial stack map, + ///< positions in the stack start from ctx->m_maxlocal }; union { @@ -468,8 +465,7 @@ * are equal to zero or if out of memory error is arisen. * @note Trace is available with argument verifier:memory. */ -void *vf_calloc_func( unsigned number, size_t element_size, - VF_SOURCE_PARAMS ); +void *vf_calloc_func(unsigned number, size_t element_size, VF_SOURCE_PARAMS); /** * Function allocates memory blocks. @@ -482,7 +478,7 @@ * or if out of memory error is arisen. * @note Trace is available with argument verifier:memory. */ -void *vf_malloc_func( size_t size, VF_SOURCE_PARAMS ); +void *vf_malloc_func(size_t size, VF_SOURCE_PARAMS); /** * Function releases allocated memory blocks. @@ -493,7 +489,7 @@ * @note Assertion is raised if pointer is equal to null. * @note Trace is available with argument verifier:memory. */ -void vf_free_func( void *pointer, VF_SOURCE_PARAMS ); +void vf_free_func(void *pointer, VF_SOURCE_PARAMS); /** * Function reallocates memory blocks. @@ -508,7 +504,7 @@ * @note If pointer is equal to null function works like vf_malloc_func. * @note Trace is available with argument verifier:memory. */ -void *vf_realloc_func( void *pointer, size_t resize, VF_SOURCE_PARAMS ); +void *vf_realloc_func(void *pointer, size_t resize, VF_SOURCE_PARAMS); /** * Function creates memory pool structure. @@ -519,7 +515,7 @@ * @see vf_Pool * @note Trace is available with argument verifier:memory:pool. */ -vf_Pool *vf_create_pool_func( VF_SOURCE_PARAMS ); +vf_Pool *vf_create_pool_func(VF_SOURCE_PARAMS); /** * Function allocates memory blocks in current pool. @@ -532,7 +528,7 @@ * @see vf_Pool * @note Trace is available with argument verifier:memory:pool. */ -void *vf_palloc_func( vf_Pool *pool, size_t size, VF_SOURCE_PARAMS ); +void *vf_palloc_func(vf_Pool *pool, size_t size, VF_SOURCE_PARAMS); /** * Function cleans given pool. @@ -543,7 +539,7 @@ * @see vf_Pool * @note Trace is available with argument verifier:memory:pool. */ -void vf_clean_pool_func( vf_Pool *pool, VF_SOURCE_PARAMS ); +void vf_clean_pool_func(vf_Pool *pool, VF_SOURCE_PARAMS); /** * Function releases memory from given pool. @@ -554,7 +550,7 @@ * @see vf_Pool * @note Trace is available with argument verifier:memory:pool. */ -void vf_delete_pool_func( vf_Pool *pool, VF_SOURCE_PARAMS ); +void vf_delete_pool_func(vf_Pool *pool, VF_SOURCE_PARAMS); //=========================================================== // Verifier hash table structures. @@ -587,13 +583,13 @@ * @param pool - external memory pool * @note Function allocates memory for hash pool and hash table. */ - vf_Hash ( vf_Pool *pool ); + vf_Hash (vf_Pool *pool); /** * Hash table destructor. * @note Function release memory for hash pool and hash table. */ - ~vf_Hash (); + ~vf_Hash(); /** * Function looks up hash entry which is identical to given hash key. @@ -601,7 +597,7 @@ * @return Hash entry which is identical to given hash key. * @see vf_HashEntry */ - vf_HashEntry *Lookup( const char *key ); + vf_HashEntry *Lookup(const char *key); /** * Function looks up hash entry which is identical to given hash key. @@ -610,7 +606,7 @@ * @return Hash entry which is identical to given hash key. * @see vf_HashEntry */ - vf_HashEntry *Lookup( const char *key, size_t len ); + vf_HashEntry *Lookup(const char *key, size_t len); /** * Function creates hash entry which is identical to given hash key. @@ -619,7 +615,7 @@ * @see vf_HashEntry * @note Created hash key and hash entry is allocated into hash memory pool. */ - vf_HashEntry *NewHashEntry( const char *key ); + vf_HashEntry *NewHashEntry(const char *key); /** * Function creates hash entry which is identical to given hash key. @@ -629,7 +625,7 @@ * @see vf_HashEntry * @note Created hash key and hash entry is allocated into hash memory pool. */ - vf_HashEntry *NewHashEntry( const char *key, size_t len ); + vf_HashEntry *NewHashEntry(const char *key, size_t len); private: vf_Pool *m_pool; ///< hash memory pool @@ -645,7 +641,7 @@ * else returns false. * @see vf_HashEntry */ - bool CheckKey( vf_HashEntry *hash_entry, const char *key ); + bool CheckKey(vf_HashEntry *hash_entry, const char *key); /** * Checks key identity. @@ -656,14 +652,14 @@ * else returns false. * @see vf_HashEntry */ - bool CheckKey( vf_HashEntry *hash_entry, const char *key, size_t len ); + bool CheckKey(vf_HashEntry *hash_entry, const char *key, size_t len); /** * Hash function. * @param key - key for hash function * @return Hash index relevant to key. */ - unsigned HashFunc( const char *key ); + unsigned HashFunc(const char *key); /** * Hash function. @@ -671,7 +667,7 @@ * @param len - key length * @return Hash index relevant to key. */ - unsigned HashFunc( const char *key, size_t len ); + unsigned HashFunc(const char *key, size_t len); }; // struct vf_Hash //=========================================================== @@ -683,14 +679,14 @@ */ struct vf_TypeConstraint { - const char *m_source; ///< constraint source class name - const char *m_target; ///< constraint target class name - method_handler m_method; ///< constraint for method - const char *m_name; ///< constraint method name - const char *m_descriptor; ///< constraint method descriptor - vf_TypeConstraint *m_next; ///< next constraint - unsigned short m_index; ///< constant pool index - unsigned short m_check_type; ///< constraint check type @see vf_CheckConstraint + const char *m_source; ///< constraint source class name + const char *m_target; ///< constraint target class name + method_handler m_method; ///< constraint for method + const char *m_name; ///< constraint method name + const char *m_descriptor; ///< constraint method descriptor + vf_TypeConstraint *m_next; ///< next constraint + unsigned short m_index; ///< constant pool index + unsigned short m_check_type; ///< constraint check type @see vf_CheckConstraint }; /** @@ -709,7 +705,7 @@ * Type constraint collection destructor. * @note Function release memory for collection memory pool and hash table. */ - ~vf_TypePool (); + ~vf_TypePool(); /** * Function creates valid type which is identical to given class. @@ -718,7 +714,7 @@ * @return Created valid type structure. * @see vf_ValidType */ - vf_ValidType *NewType( const char *type, size_t len ); + vf_ValidType *NewType(const char *type, size_t len); /** * Function creates valid type which is identical to an element of a given array type. @@ -726,7 +722,7 @@ * @return Created valid type of a given array element. * @see vf_ValidType */ - vf_ValidType *NewArrayElemType( vf_ValidType *array ); + vf_ValidType *NewArrayElemType(vf_ValidType *array); /** * Checks types and create constraints if it's necessarily. @@ -740,9 +736,9 @@ * @see vf_ValidType * @see vf_CheckConstraint */ - bool CheckTypes( vf_ValidType *required, - vf_ValidType *available, - unsigned short index, vf_CheckConstraint check_type ); + bool CheckTypes(vf_ValidType *required, + vf_ValidType *available, + unsigned short index, vf_CheckConstraint check_type); /** * Function merges two valid types. @@ -752,14 +748,14 @@ * @return Function returns NULL if vector wasn't merged. * @see vf_ValidType */ - vf_ValidType *MergeTypes( vf_ValidType *first, vf_ValidType *second ); + vf_ValidType *MergeTypes(vf_ValidType *first, vf_ValidType *second); /** * Dumps constraint collection in stream. * @param out - pointer to output stream * @note If out is equal to null, output stream is cerr. */ - void DumpTypeConstraints( ostream *out ); + void DumpTypeConstraints(ostream *out); /** * Function returns the methods constraints array. @@ -772,7 +768,7 @@ * Sets current context method. * @param ctx - current verifier context */ - void SetMethod( vf_ContextHandle ctx ); + void SetMethod(vf_ContextHandle ctx); /** * Sets restriction from target class to source class. @@ -782,10 +778,9 @@ * @param check_type - constraint check type * @see vf_CheckConstraint */ - void SetRestriction( const char *target, - const char *source, - unsigned short index, - vf_CheckConstraint check_type ); + void SetRestriction(const char *target, + const char *source, + unsigned short index, vf_CheckConstraint check_type); private: vf_Pool *m_pool; ///< collection memory pool @@ -800,7 +795,7 @@ // Verifier type constraint structures. //=========================================================== -void vf_clean_pool_func( vf_Pool *pool, VF_SOURCE_PARAMS ); +void vf_clean_pool_func(vf_Pool *pool, VF_SOURCE_PARAMS); /** * Verification context. @@ -811,16 +806,16 @@ /** * Verifier context constructor */ - vf_Context ():m_class( NULL ), m_type( NULL ), m_error( NULL ), - m_method( NULL ), m_name(NULL), m_descriptor(NULL), m_graph( NULL ), - m_pool( NULL ), m_instr( NULL ), m_last_instr( NULL ), m_retnum( 0 ), - m_verify_all( false ) + vf_Context ():m_class(NULL), m_type(NULL), m_error(NULL), + m_method(NULL), m_name(NULL), m_descriptor(NULL), m_graph(NULL), + m_pool(NULL), m_instr(NULL), m_last_instr(NULL), m_retnum(0), + m_verify_all(false) { vf_ContextVType zero2 = { 0 }; m_vtype = zero2; } - void SetMethod( method_handler method ) + void SetMethod(method_handler method) { assert(method); m_method = method; @@ -828,27 +823,27 @@ m_descriptor = method_get_descriptor(method); // get method parameters - m_len = method_get_code_length( method ); - m_bytes = method_get_bytecode( method ); - m_handlers = method_get_exc_handler_number( method ); + m_len = method_get_code_length(method); + m_bytes = method_get_bytecode(method); + m_handlers = method_get_exc_handler_number(method); // get method limitations - m_maxlocal = method_get_max_local( method ); - m_maxstack = method_get_max_stack( method ); + m_maxlocal = method_get_max_local(method); + m_maxstack = method_get_max_stack(method); // cache in the context if the method is a constructor - m_is_constructor = (memcmp( m_name, "", 7 ) == 0); + m_is_constructor = (memcmp(m_name, "", 7) == 0); } /** * Verifier context destructor */ - ~vf_Context () + ~vf_Context() { - if( m_pool ) { - vf_delete_pool( m_pool ); + if (m_pool) { + vf_delete_pool(m_pool); } - if( m_type ) { + if (m_type) { delete m_type; } } @@ -867,7 +862,7 @@ m_bc = NULL; m_last_instr = NULL; m_retnum = 0; - vf_clean_pool( m_pool ); + vf_clean_pool(m_pool); } // vf_ClearContext public: @@ -892,13 +887,13 @@ unsigned short m_maxstack; ///< max stack length unsigned short m_maxlocal; ///< max local number bool m_is_constructor; ///< true if the - ///< method is a constructor + ///< method is a constructor // Subrotine info - vf_SubContext *m_sub_ctx; ///< aggregate subroutine info - vf_MapVector *m_map; ///< a stack map for control flow - ///< analysis, vectors themselves are - ///< allocated from the graph pool + vf_SubContext *m_sub_ctx; ///< aggregate subroutine info + vf_MapVector *m_map; ///< a stack map for control flow + ///< analysis, vectors themselves are + ///< allocated from the graph pool vf_MapEntry *m_method_invector; ///< method parameters unsigned short m_method_inlen; ///< a length of m_method_invector vf_MapEntry *m_method_outvector; ///< method return value @@ -906,7 +901,7 @@ // Data flow analisys info vf_MapEntry *m_buf; ///< used to store intermediate stack states - ///< during data flow analysis + ///< during data flow analysis bool m_verify_all; ///< if true need to verify more checks @@ -915,11 +910,11 @@ */ struct vf_ContextVType { - vf_ValidType *m_class; ///< a given class + vf_ValidType *m_class; ///< a given class vf_ValidType *m_throwable; ///< java/lang/Throwable - vf_ValidType *m_object; ///< java/lang/Object - vf_ValidType *m_array; ///< [Ljava/lang/Object; - vf_ValidType *m_clone; ///< java/lang/Cloneable + vf_ValidType *m_object; ///< java/lang/Object + vf_ValidType *m_array; ///< [Ljava/lang/Object; + vf_ValidType *m_clone; ///< java/lang/Cloneable vf_ValidType *m_serialize; ///< java/io/Serializable } m_vtype; @@ -961,7 +956,7 @@ * @see vf_Context * @see vf_Result */ -vf_Result vf_create_graph( vf_Context *ctx ); +vf_Result vf_create_graph(vf_Context *ctx); /** * Checks control flow and data flow of graph. @@ -970,7 +965,7 @@ * * @return a result of graph checks */ -vf_Result vf_check_graph( vf_Context *ctx ); +vf_Result vf_check_graph(vf_Context *ctx); /** * Provides data flow checks of verifier graph structure. @@ -979,7 +974,7 @@ * @see vf_Context * @see vf_Result */ -vf_Result vf_check_graph_data_flow( vf_Context *ctx ); +vf_Result vf_check_graph_data_flow(vf_Context *ctx); /** * Parses method, class or field descriptors. @@ -989,8 +984,8 @@ * @note Assertion is raised if descr or inlen are equal to NULL. * @note Parameter outlen may be equal to null (for class or field descriptor). */ -void vf_parse_description( const char *descr, unsigned short *inlen, - unsigned short *outlen ); +void vf_parse_description(const char *descr, unsigned short *inlen, + unsigned short *outlen); /** * Parses a descriptor and sets input and output data flow vectors. @@ -1008,12 +1003,12 @@ * if parameter outlen is equal to zero. */ void -vf_set_description_vector( const char *descr, - unsigned short inlen, - unsigned short add, - unsigned short outlen, - vf_MapEntry **invector, - vf_MapEntry **outvector, vf_ContextHandle ctx ); +vf_set_description_vector(const char *descr, + unsigned short inlen, + unsigned short add, + unsigned short outlen, + vf_MapEntry **invector, + vf_MapEntry **outvector, vf_ContextHandle ctx); /** * Gets a class name from a constant pool. @@ -1023,12 +1018,12 @@ * * @return a pointer to UTF8 constant pool entry */ -static inline const char * -vf_get_cp_class_name( class_handler klass, unsigned short index ) +static inline const char *vf_get_cp_class_name(class_handler klass, + unsigned short index) { unsigned short class_name_index = - class_get_cp_class_name_index( klass, index ); - const char *name = class_get_cp_utf8_bytes( klass, class_name_index ); + class_get_cp_class_name_index(klass, index); + const char *name = class_get_cp_utf8_bytes(klass, class_name_index); return name; } // vf_get_cp_class_name @@ -1038,8 +1033,8 @@ * @param ctx a verifier context * @return a valid type structure corresponding to the given class name */ -vf_ValidType *vf_create_class_valid_type( const char *class_name, - vf_ContextHandle ctx ); +vf_ValidType *vf_create_class_valid_type(const char *class_name, + vf_ContextHandle ctx); /** * Provides constraint checks for current class. @@ -1050,7 +1045,7 @@ * @see vf_Context * @see vf_Result */ -vf_Result vf_check_class_constraints( vf_Context *ctx ); +vf_Result vf_check_class_constraints(vf_Context *ctx); /** * Function compares two valid types. @@ -1059,7 +1054,7 @@ * @return If types are equal returns true, else returns false. * @see vf_ValidType */ -bool vf_is_types_equal( vf_ValidType *type1, vf_ValidType *type2 ); +bool vf_is_types_equal(vf_ValidType *type1, vf_ValidType *type2); /** * Checks access to protected field/method. @@ -1077,11 +1072,11 @@ * @see vf_Context * @see vf_Result */ -vf_Result vf_check_access_constraint( const char *super_name, // name of super class - const char *instance_name, // name of instance class - unsigned short index, // constant pool index - vf_CheckConstraint check_type, // access check type - vf_Context *ctx ); // verification context +vf_Result vf_check_access_constraint(const char *super_name, // name of super class + const char *instance_name, // name of instance class + unsigned short index, // constant pool index + vf_CheckConstraint check_type, // access check type + vf_Context *ctx); // verification context /** * Sets error message of a verifier. @@ -1090,17 +1085,17 @@ * @param[in] ctx a verifier context */ static inline void -vf_set_error_message( stringstream & stream, vf_Context *ctx ) +vf_set_error_message(stringstream & stream, vf_Context *ctx) { - if( ctx->m_error ) { + if (ctx->m_error) { // free old message - vf_free( ctx->m_error ); + vf_free(ctx->m_error); } // create message size_t len = stream.str().length(); - if( len ) { - ctx->m_error = (char*)vf_malloc( len + 1 ); - memcpy( ctx->m_error, stream.str().c_str(), len ); + if (len) { + ctx->m_error = (char *) vf_malloc(len + 1); + memcpy(ctx->m_error, stream.str().c_str(), len); ctx->m_error[len] = '\0'; } else { ctx->m_error = NULL; @@ -1114,10 +1109,9 @@ * * @return true if a class version is less than 1.4 */ -static inline bool -vf_is_class_version_14( vf_ContextHandle ctx ) +static inline bool vf_is_class_version_14(vf_ContextHandle ctx) { - return ( class_get_version( ctx->m_class ) < 49 ) ? true : false; + return (class_get_version(ctx->m_class) < 49) ? true : false; } // vf_is_class_version_14 /** @@ -1130,9 +1124,9 @@ * branches */ static inline int -vf_get_instr_branch( vf_InstrHandle instr, unsigned branch_num ) +vf_get_instr_branch(vf_InstrHandle instr, unsigned branch_num) { - assert( branch_num < instr->m_offcount ); + assert(branch_num < instr->m_offcount); return instr->m_off[branch_num]; } // vf_get_instruction_branch @@ -1144,11 +1138,10 @@ * @param[in] pool memory pool */ static inline void -vf_new_vector( vf_MapEntry **vector, unsigned len, vf_Pool *pool ) +vf_new_vector(vf_MapEntry **vector, unsigned len, vf_Pool *pool) { // create new vector - ( *vector ) = (vf_MapEntry*)vf_palloc( pool, - len * sizeof( vf_MapEntry ) ); + (*vector) = (vf_MapEntry *) vf_palloc(pool, len * sizeof(vf_MapEntry)); } // vf_new_vector /** @@ -1159,8 +1152,8 @@ * @param[in] type reference type */ static inline void -vf_set_vector_stack_entry_ref( vf_MapEntry *vector, - unsigned num, vf_ValidType *type ) +vf_set_vector_stack_entry_ref(vf_MapEntry *vector, + unsigned num, vf_ValidType *type) { // set a stack map vector entry by ref vector[num].m_type = SM_REF; @@ -1174,9 +1167,9 @@ * @return an instruction index */ static inline unsigned -vf_get_instr_index( vf_InstrHandle instr, vf_ContextHandle ctx ) +vf_get_instr_index(vf_InstrHandle instr, vf_ContextHandle ctx) { - return ( unsigned )( instr - ctx->m_instr ); + return (unsigned) (instr - ctx->m_instr); } /** @@ -1186,11 +1179,11 @@ * @return an instruction index */ static inline unsigned -vf_bc_to_instr_index( unsigned short pc, vf_ContextHandle ctx ) +vf_bc_to_instr_index(unsigned short pc, vf_ContextHandle ctx) { vf_InstrHandle instr = ctx->m_bc[pc].m_instr; - assert( instr ); - return vf_get_instr_index( instr, ctx ); + assert(instr); + return vf_get_instr_index(instr, ctx); } /** @@ -1200,13 +1193,13 @@ * @param[in] ctx a verification context * @return a pointer which follows a given instruction */ -static inline const unsigned char * -vf_get_instr_end( vf_InstrHandle instr, vf_ContextHandle ctx ) +static inline const unsigned char *vf_get_instr_end(vf_InstrHandle instr, + vf_ContextHandle ctx) { - if( instr + 1 == ctx->m_last_instr ) { + if (instr + 1 == ctx->m_last_instr) { return ctx->m_bytes + ctx->m_len; } - return ( instr + 1 )->m_addr; + return (instr + 1)->m_addr; } /** @@ -1214,7 +1207,7 @@ * * @param[in] context a context of verifier */ -void vf_free_graph( vf_Context *context ); +void vf_free_graph(vf_Context *context); /** * Mark subroutine code. @@ -1226,18 +1219,18 @@ * page.

* * @param ctx a verifier context - * @return VER_OK if no graph structure inconsistencies were detected during marking, + * @return VF_OK if no graph structure inconsistencies were detected during marking, * an error code otherwise */ -vf_Result vf_mark_subroutines( vf_Context *ctx ); +vf_Result vf_mark_subroutines(vf_Context *ctx); /** * Inline subroutines in the call graph. * * @param ctx a verifier context - * @return VER_OK if subroutines were inlined successfully, + * @return VF_OK if subroutines were inlined successfully, * an error code otherwise */ -vf_Result vf_inline_subroutines( vf_Context *ctx ); +vf_Result vf_inline_subroutines(vf_Context *ctx); -#endif // _VERIFIER_REAL_H_ +#endif // _VF_REAL_H_ Index: vm/vmcore/src/verifier/Verifier.cpp =================================================================== --- vm/vmcore/src/verifier/Verifier.cpp (revision 542211) +++ vm/vmcore/src/verifier/Verifier.cpp (working copy) @@ -34,13 +34,13 @@ * Parses bytecode, determines instruction boundaries and * provides checks of simple verifications. */ -static vf_Result vf_parse_bytecode( vf_Context *ctx ); // verification context +static vf_Result vf_parse_bytecode(vf_Context *ctx); // verification context #if _VF_DEBUG /** * Prints code instruction array in stream. */ -void vf_dump_bytecode( vf_ContextHandle ); // verification context +void vf_dump_bytecode(vf_ContextHandle); // verification context /** * Array of opcode names. Available in debug mode. @@ -87,46 +87,45 @@ /** * Provides method bytecode verifications. */ -static vf_Result -vf_verify_method_bytecode( vf_Context *ctx ) // verification context +static vf_Result vf_verify_method_bytecode(vf_Context *ctx) // verification context { - VF_TRACE( "method", VF_REPORT_CTX( ctx ) << "verifying method" ); + VF_TRACE("method", VF_REPORT_CTX(ctx) << "verifying method"); // set method for type pool - ctx->m_type->SetMethod( ctx ); + ctx->m_type->SetMethod(ctx); // parse method descriptor - vf_parse_description( ctx->m_descriptor, &ctx->m_method_inlen, - &ctx->m_method_outlen ); - vf_set_description_vector( ctx->m_descriptor, ctx->m_method_inlen, 0, - ctx->m_method_outlen, &ctx->m_method_invector, - &ctx->m_method_outvector, ctx ); + vf_parse_description(ctx->m_descriptor, &ctx->m_method_inlen, + &ctx->m_method_outlen); + vf_set_description_vector(ctx->m_descriptor, ctx->m_method_inlen, 0, + ctx->m_method_outlen, &ctx->m_method_invector, + &ctx->m_method_outvector, ctx); // parse bytecode, fill instruction instr - vf_Result result = vf_parse_bytecode( ctx ); - if( VER_OK != result ) { + vf_Result result = vf_parse_bytecode(ctx); + if (VF_OK != result) { goto labelEnd_verifyClassBytecode; } // build a control flow graph - result = vf_create_graph( ctx ); - if( VER_OK != result ) { + result = vf_create_graph(ctx); + if (VF_OK != result) { goto labelEnd_verifyClassBytecode; } - result = vf_check_graph( ctx ); - if( VER_OK != result ) { + result = vf_check_graph(ctx); + if (VF_OK != result) { goto labelEnd_verifyClassBytecode; } labelEnd_verifyClassBytecode: - VF_TRACE( "method", VF_REPORT_CTX( ctx ) << "method statistics: " - << " rets: " << ctx->m_retnum - << ", length: " << ctx->m_len - << ", handlers: " << ctx->m_handlers - << ", max stack: " << ctx->m_maxstack - << ", max locals: " << ctx->m_maxlocal ); - vf_free_graph( ctx ); + VF_TRACE("method", VF_REPORT_CTX(ctx) << "method statistics: " + << " rets: " << ctx->m_retnum + << ", length: " << ctx->m_len + << ", handlers: " << ctx->m_handlers + << ", max stack: " << ctx->m_maxstack + << ", max locals: " << ctx->m_maxlocal); + vf_free_graph(ctx); return result; } // vf_verify_method_bytecode @@ -137,39 +136,35 @@ /** * Creates array of instruction branch offsets. */ -static inline void -vf_create_instr_offset( vf_Instr *instr, // given instruction - unsigned offcount, // number of offets - vf_Pool *pool ) // memory pool +static inline void vf_create_instr_offset(vf_Instr *instr, // given instruction + unsigned offcount, // number of offets + vf_Pool *pool) // memory pool { - assert( !instr->m_off ); - instr->m_off = - ( unsigned * )vf_palloc( pool, offcount * sizeof( unsigned ) ); + assert(!instr->m_off); + instr->m_off = (unsigned *) vf_palloc(pool, offcount * sizeof(unsigned)); instr->m_offcount = offcount; } // vf_create_instruction_offset /** * Sets instruction branch offset. */ -static inline void -vf_set_instr_offset( vf_InstrHandle instr, // given instruction - unsigned offnum, // offset index in array - unsigned value ) // offset value +static inline void vf_set_instr_offset(vf_InstrHandle instr, // given instruction + unsigned offnum, // offset index in array + unsigned value) // offset value { - assert( instr->m_off && offnum < instr->m_offcount ); + assert(instr->m_off && offnum < instr->m_offcount); instr->m_off[offnum] = value; } // vf_set_instruction_offset /** * Function creates a single branch. */ -static inline void -vf_set_single_branch_offset( vf_Instr *instr, // given instruction - unsigned value, // offset value - vf_Pool *pool ) // memory pool +static inline void vf_set_single_branch_offset(vf_Instr *instr, // given instruction + unsigned value, // offset value + vf_Pool *pool) // memory pool { - vf_create_instr_offset( instr, 1, pool ); - vf_set_instr_offset( instr, 0, value ); + vf_create_instr_offset(instr, 1, pool); + vf_set_instr_offset(instr, 0, value); } // vf_set_single_instruction_offset /************************************************************ @@ -179,23 +174,21 @@ /** * Sets stack modifier attribute for given code instruction. */ -static inline void -vf_set_stack_modifier( vf_Instr *instr, // code instruction - int modify ) // stack modifier value +static inline void vf_set_stack_modifier(vf_Instr *instr, // code instruction + int modify) // stack modifier value { // set stack modifier for instruction - instr->m_stack = ( short )modify; + instr->m_stack = (short) modify; } // vf_set_stack_modifier /** * Sets minimal stack attribute for given code instruction. */ -static inline void -vf_set_min_stack( vf_Instr *instr, // code instruction - unsigned min_stack ) // minimal stack value +static inline void vf_set_min_stack(vf_Instr *instr, // code instruction + unsigned min_stack) // minimal stack value { // set minimal stack for instruction - instr->m_minstack = ( unsigned short )min_stack; + instr->m_minstack = (unsigned short) min_stack; } // vf_set_min_stack /** @@ -206,9 +199,9 @@ * Sets basic block attribute for instruction. */ static inline void -vf_set_basic_block_flag( unsigned short pc, vf_ContextHandle ctx ) +vf_set_basic_block_flag(unsigned short pc, vf_ContextHandle ctx) { - assert( pc < ctx->m_len + GOTO_W_LEN ); + assert(pc < ctx->m_len + GOTO_W_LEN); // set begin of basic block for instruction ctx->m_bc[pc].m_is_bb_start = true; } // vf_set_basic_block_flag @@ -217,9 +210,8 @@ /** * Sets flags for the instruction. */ -static inline void -vf_set_instr_type( vf_Instr *instr, // instruction - vf_InstrType type ) // given flags +static inline void vf_set_instr_type(vf_Instr *instr, // instruction + vf_InstrType type) // given flags { // set flag for instruction instr->m_type = type; @@ -228,56 +220,53 @@ /** * Checks local number. */ -static inline vf_Result -vf_check_local_var_number( unsigned local, // local number - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_local_var_number(unsigned local, // local number + vf_Context *ctx) // verification context { // check local variable number - if( local >= ctx->m_maxlocal ) { - VF_REPORT( ctx, "Incorrect usage of local variable" ); - return VER_ErrorLocals; + if (local >= ctx->m_maxlocal) { + VF_REPORT(ctx, "Incorrect usage of local variable"); + return VF_ErrorLocals; } - return VER_OK; + return VF_OK; } // vf_check_local_var_number /** * Checks branch offset. */ -static inline vf_Result -vf_check_branch_offset( int offset, // given instruction offset - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_branch_offset(int offset, // given instruction offset + vf_Context *ctx) // verification context { - if( offset < 0 || ( unsigned )offset >= ctx->m_len ) { - VF_REPORT( ctx, "Instruction branch offset is out of range" ); - return VER_ErrorBranch; + if (offset < 0 || (unsigned) offset >= ctx->m_len) { + VF_REPORT(ctx, "Instruction branch offset is out of range"); + return VF_ErrorBranch; } ctx->m_bc[offset].m_is_bb_start = true; - return VER_OK; + return VF_OK; } // vf_check_branch_offset /** * Function parses local variable number from instruction bytecode. */ -static inline unsigned short -vf_get_local_var_number( vf_InstrHandle instr, // code instruction - unsigned char *bytecode, // method bytecode - unsigned *index_p, // index in bytecode array - bool wide_flag ) // if this is a wide instruction +static inline unsigned short vf_get_local_var_number(vf_InstrHandle instr, // code instruction + unsigned char *bytecode, // method bytecode + unsigned *index_p, // index in bytecode array + bool wide_flag) // if this is a wide instruction { unsigned short local; - if( ( wide_flag ) ) { + if ((wide_flag)) { // get number of local variable local = - ( unsigned short )( ( bytecode[( *index_p )] << 8 ) | - ( bytecode[( *index_p ) + 1] ) ); + (unsigned short) ((bytecode[(*index_p)] << 8) | + (bytecode[(*index_p) + 1])); // skip parameter (u2) - ( *index_p ) += 2; + (*index_p) += 2; } else { // get number of local variable - local = ( unsigned short )bytecode[( *index_p )]; + local = (unsigned short) bytecode[(*index_p)]; // skip parameter (u1) - ( *index_p )++; + (*index_p)++; } return local; } // vf_get_local_var_number @@ -286,38 +275,33 @@ * Receives half word (2 bytes) instruction branch offset * value from bytecode array. */ -static inline int -vf_get_hword_offset( unsigned code_pc, // instruction offset in bytecode array - unsigned char *bytecode, // bytecode array - unsigned *index_p ) // offset index in bytecode array +static inline int vf_get_hword_offset(unsigned code_pc, // instruction offset in bytecode array + unsigned char *bytecode, // bytecode array + unsigned *index_p) // offset index in bytecode array { // get first branch offset - int offset = ( int )code_pc - + - ( short )( ( bytecode[( *index_p )] << 8 ) | - ( bytecode[( *index_p ) + 1] ) ); + int offset = (int) code_pc + + (short) ((bytecode[(*index_p)] << 8) | (bytecode[(*index_p) + 1])); // skip parameter (s2) - ( *index_p ) += 2; + (*index_p) += 2; return offset; } // vf_get_hword_offset /** * Receives word (4 bytes) instruction branch offset value from bytecode array. */ -static inline int -vf_get_word_offset( unsigned code_pc, // instruction offset in bytecode array - unsigned char *bytecode, // bytecode array - unsigned *index_p ) // offset index in bytecode array +static inline int vf_get_word_offset(unsigned code_pc, // instruction offset in bytecode array + unsigned char *bytecode, // bytecode array + unsigned *index_p) // offset index in bytecode array { // get switch branch offset - int offset = ( int )code_pc + int offset = (int) code_pc + - ( int )( ( bytecode[( *index_p )] << 24 ) | - ( bytecode[( *index_p ) + 1] << 16 ) - | ( bytecode[( *index_p ) + 2] << 8 ) | - ( bytecode[( *index_p ) + 3] ) ); + (int) ((bytecode[(*index_p)] << 24) | (bytecode[(*index_p) + 1] << 16) + | (bytecode[(*index_p) + 2] << 8) | + (bytecode[(*index_p) + 3])); // skip parameter (s4) - ( *index_p ) += 4; + (*index_p) += 4; return offset; } // vf_get_word_offset @@ -325,17 +309,16 @@ * Receives half word (2 bytes) branch offset from bytecode array, * sets into instruction and returns it. */ -static inline int -vf_get_single_hword_branch_offset( vf_Instr *instr, // instruction - unsigned code_pc, // offset in bytecode array - unsigned char *bytecode, // bytecode array - unsigned *index_p, // offset index in bytecode array - vf_Pool *pool ) // memory pool +static inline int vf_get_single_hword_branch_offset(vf_Instr *instr, // instruction + unsigned code_pc, // offset in bytecode array + unsigned char *bytecode, // bytecode array + unsigned *index_p, // offset index in bytecode array + vf_Pool *pool) // memory pool { // get first branch offset - int offset = vf_get_hword_offset( code_pc, bytecode, index_p ); + int offset = vf_get_hword_offset(code_pc, bytecode, index_p); // create and set edge branch for instruction - vf_set_single_branch_offset( instr, offset, pool ); + vf_set_single_branch_offset(instr, offset, pool); return offset; } // vf_get_single_hword_branch_offset @@ -343,17 +326,16 @@ * Receives word (4 bytes) branch offset from bytecode array, * sets into instruction and returns it. */ -static inline int -vf_get_single_word_branch_offset( vf_Instr *instr, // instruction - unsigned code_pc, // offset in bytecode array - unsigned char *bytecode, // bytecode array - unsigned *index_p, // offset index in bytecode array - vf_Pool *pool ) // memory pool +static inline int vf_get_single_word_branch_offset(vf_Instr *instr, // instruction + unsigned code_pc, // offset in bytecode array + unsigned char *bytecode, // bytecode array + unsigned *index_p, // offset index in bytecode array + vf_Pool *pool) // memory pool { // get first branch offset - int offset = vf_get_word_offset( code_pc, bytecode, index_p ); + int offset = vf_get_word_offset(code_pc, bytecode, index_p); // create and set edge branch for instruction - vf_set_single_branch_offset( instr, offset, pool ); + vf_set_single_branch_offset(instr, offset, pool); return offset; } // vf_get_single_word_branch_offset @@ -362,21 +344,20 @@ * sets received offset and next instruction offset into instruction. * Function returns received offset. */ -static inline int -vf_get_double_hword_branch_offset( vf_Instr *instr, // instruction - unsigned code_pc, // instruction offset in bytcode array - unsigned char *bytecode, // bytecode array - unsigned *index_p, // offset index in bytecode array - vf_Pool *pool ) // memory pool +static inline int vf_get_double_hword_branch_offset(vf_Instr *instr, // instruction + unsigned code_pc, // instruction offset in bytcode array + unsigned char *bytecode, // bytecode array + unsigned *index_p, // offset index in bytecode array + vf_Pool *pool) // memory pool { // get first branch offset - int offset = vf_get_hword_offset( code_pc, bytecode, index_p ); + int offset = vf_get_hword_offset(code_pc, bytecode, index_p); // create and set edge branches for instruction - vf_create_instr_offset( instr, 2, pool ); + vf_create_instr_offset(instr, 2, pool); // set first edge branch for instruction - vf_set_instr_offset( instr, 0, offset ); + vf_set_instr_offset(instr, 0, offset); // set second edge branch for instruction - vf_set_instr_offset( instr, 1, ( *index_p ) ); + vf_set_instr_offset(instr, 1, (*index_p)); return offset; } // vf_get_double_hword_branch_offset @@ -385,21 +366,20 @@ * sets received offset and next instruction offset into instruction. * Function returns received offset. */ -static inline int -vf_get_double_word_branch_offset( vf_Instr *instr, // instruction - unsigned code_pc, // instruction offset in bytcode array - unsigned char *bytecode, // bytecode array - unsigned *index_p, // offset index in bytecode array - vf_Pool *pool ) // memory pool +static inline int vf_get_double_word_branch_offset(vf_Instr *instr, // instruction + unsigned code_pc, // instruction offset in bytcode array + unsigned char *bytecode, // bytecode array + unsigned *index_p, // offset index in bytecode array + vf_Pool *pool) // memory pool { // get first branch offset - int offset = vf_get_word_offset( code_pc, bytecode, index_p ); + int offset = vf_get_word_offset(code_pc, bytecode, index_p); // create and set edge branches for instruction - vf_create_instr_offset( instr, 2, pool ); + vf_create_instr_offset(instr, 2, pool); // set first edge branch for instruction - vf_set_instr_offset( instr, 0, offset ); + vf_set_instr_offset(instr, 0, offset); // set second edge branch for instruction - vf_set_instr_offset( instr, 1, ( *index_p ) ); + vf_set_instr_offset(instr, 1, (*index_p)); return offset; } // vf_get_double_word_branch_offset @@ -408,17 +388,16 @@ * sets received offset into instruction. * Function returns received branch. */ -static inline int -vf_get_tableswitch_alternative( vf_InstrHandle instr, // instruction - unsigned code_pc, // offset in bytcode array - unsigned alternative, // number of tableswitch branch - unsigned char *bytecode, // bytecode array - unsigned *index_p ) // offset index in bytecode array +static inline int vf_get_tableswitch_alternative(vf_InstrHandle instr, // instruction + unsigned code_pc, // offset in bytcode array + unsigned alternative, // number of tableswitch branch + unsigned char *bytecode, // bytecode array + unsigned *index_p) // offset index in bytecode array { // get first branch offset - int offset = vf_get_word_offset( code_pc, bytecode, index_p ); + int offset = vf_get_word_offset(code_pc, bytecode, index_p); // set first edge branch for instruction - vf_set_instr_offset( instr, alternative, offset ); + vf_set_instr_offset(instr, alternative, offset); return offset; } // vf_get_tableswitch_alternative @@ -427,34 +406,32 @@ * sets them into instruction. * Function returns number of alternatives. */ -static inline int -vf_set_tableswitch_offsets( vf_Instr *instr, // instruction - unsigned code_pc, // instruction offset in bytecode array - unsigned *index_p, // offset index in bytecode array - unsigned char *bytecode, // bytecode array - vf_Pool *pool ) // memory pool +static inline int vf_set_tableswitch_offsets(vf_Instr *instr, // instruction + unsigned code_pc, // instruction offset in bytecode array + unsigned *index_p, // offset index in bytecode array + unsigned char *bytecode, // bytecode array + vf_Pool *pool) // memory pool { // skip padding - unsigned default_off = ( ( *index_p ) + 0x3 ) & ( ~0x3U ); + unsigned default_off = ((*index_p) + 0x3) & (~0x3U); unsigned index = default_off; // skip default offset index += 4; // get low and high tableswitch values - int low = vf_get_word_offset( code_pc, bytecode, &index ); - int high = vf_get_word_offset( code_pc, bytecode, &index ); + int low = vf_get_word_offset(code_pc, bytecode, &index); + int high = vf_get_word_offset(code_pc, bytecode, &index); int number = high - low + 2; // create tableswitch branches - vf_create_instr_offset( instr, number, pool ); + vf_create_instr_offset(instr, number, pool); // set default offset - vf_get_tableswitch_alternative( instr, code_pc, 0, bytecode, - &default_off ); + vf_get_tableswitch_alternative(instr, code_pc, 0, bytecode, &default_off); // set another instruction offsets - for( int count = 1; count < number; count++ ) { - vf_get_tableswitch_alternative( instr, code_pc, count, bytecode, - &index ); + for (int count = 1; count < number; count++) { + vf_get_tableswitch_alternative(instr, code_pc, count, bytecode, + &index); } // set index next instruction - ( *index_p ) = index; + (*index_p) = index; return number; } // vf_set_tableswitch_offsets @@ -463,46 +440,44 @@ * sets them into instruction. * Function returns number of alternatives. */ -static inline vf_Result -vf_set_lookupswitch_offsets( vf_Instr *instr, // instruction - unsigned code_pc, // instruction offset in bytecode - unsigned *index_p, // offset index in bytecode array - unsigned char *bytecode, // array of bytecode - unsigned *branch_p, // number of alternatives - vf_Context *ctx ) // verification context +static inline vf_Result vf_set_lookupswitch_offsets(vf_Instr *instr, // instruction + unsigned code_pc, // instruction offset in bytecode + unsigned *index_p, // offset index in bytecode array + unsigned char *bytecode, // array of bytecode + unsigned *branch_p, // number of alternatives + vf_Context *ctx) // verification context { // skip padding - unsigned default_off = ( ( *index_p ) + 0x3 ) & ( ~0x3U ); + unsigned default_off = ((*index_p) + 0x3) & (~0x3U); unsigned index = default_off; // skip default offset index += 4; // get alternative number of lookupswitch (add default alternative) - int number = vf_get_word_offset( 0, bytecode, &index ) + 1; + int number = vf_get_word_offset(0, bytecode, &index) + 1; *branch_p = number; // create and tableswitch branches - vf_create_instr_offset( instr, number, ctx->m_pool ); + vf_create_instr_offset(instr, number, ctx->m_pool); // set default offset - vf_get_tableswitch_alternative( instr, code_pc, 0, bytecode, - &default_off ); + vf_get_tableswitch_alternative(instr, code_pc, 0, bytecode, &default_off); // set another instruction offsets int old_key = INT_MIN; - for( int count = 1; count < number; count++ ) { + for (int count = 1; count < number; count++) { // get and check branch key value - int key = vf_get_word_offset( 0, bytecode, &index ); - if( old_key < key ) { + int key = vf_get_word_offset(0, bytecode, &index); + if (old_key < key) { old_key = key; - } else if( key != INT_MIN ) { - VF_REPORT( ctx, - "Instruction lookupswitch has unsorted key values" ); - return VER_ErrorInstruction; + } else if (key != INT_MIN) { + VF_REPORT(ctx, + "Instruction lookupswitch has unsorted key values"); + return VF_ErrorInstruction; } // get lookupswitch alternative and set offset to instruction - vf_get_tableswitch_alternative( instr, code_pc, count, bytecode, - &index ); + vf_get_tableswitch_alternative(instr, code_pc, count, bytecode, + &index); } // set index next instruction - ( *index_p ) = index; - return VER_OK; + (*index_p) = index; + return VF_OK; } // vf_set_lookupswitch_offsets /************************************************************ @@ -512,23 +487,21 @@ /** * Sets check type for a given stack map vector entry. */ -static inline void -vf_set_vector_check( vf_MapEntry *vector, // stack map vector - unsigned num, // vector entry number - vf_CheckConstraint check ) // constraint check type +static inline void vf_set_vector_check(vf_MapEntry *vector, // stack map vector + unsigned num, // vector entry number + vf_CheckConstraint check) // constraint check type { // set check for map vector entry - assert( check < VF_CHECK_NUM ); + assert(check < VF_CHECK_NUM); vector[num].m_ctype = check; } // vf_set_vector_check /** * Sets constraint pool index for a given stack map vector entry. */ -static inline void -vf_set_vector_check_index( vf_MapEntry *vector, // stack map vector - unsigned num, // vector entry number - unsigned short index ) // constraint pool index +static inline void vf_set_vector_check_index(vf_MapEntry *vector, // stack map vector + unsigned num, // vector entry number + unsigned short index) // constraint pool index { // set index for a map vector entry vector[num].m_index = index; @@ -537,21 +510,19 @@ /** * Sets a given data type to stack map vector entry. */ -static inline void -vf_set_vector_type( vf_MapEntry *vector, // stack map vector - unsigned num, // vector entry number - vf_MapType type ) // stack map entry type +static inline void vf_set_vector_type(vf_MapEntry *vector, // stack map vector + unsigned num, // vector entry number + vf_MapType type) // stack map entry type { - assert( type < SM_NUMBER ); + assert(type < SM_NUMBER); vector[num].m_type = type; } // vf_set_vector_type /** * Sets null data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_null( vf_MapEntry *vector, // stack map vector - unsigned num ) // vector entry number +static inline void vf_set_vector_stack_entry_null(vf_MapEntry *vector, // stack map vector + unsigned num) // vector entry number { // set stack map vector entry by null vector[num].m_type = SM_NULL; @@ -560,9 +531,8 @@ /** * Sets int data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_int( vf_MapEntry *vector, // stack map vector - unsigned num ) // vector entry number +static inline void vf_set_vector_stack_entry_int(vf_MapEntry *vector, // stack map vector + unsigned num) // vector entry number { // set stack map vector entry by int vector[num].m_type = SM_INT; @@ -571,9 +541,8 @@ /** * Sets float data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_float( vf_MapEntry *vector, // stack map vector - unsigned num ) // vector entry number +static inline void vf_set_vector_stack_entry_float(vf_MapEntry *vector, // stack map vector + unsigned num) // vector entry number { // set stack map vector entry by float vector[num].m_type = SM_FLOAT; @@ -582,9 +551,8 @@ /** * Sets long data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_long( vf_MapEntry *vector, // stack map vector - unsigned num ) // vector entry number +static inline void vf_set_vector_stack_entry_long(vf_MapEntry *vector, // stack map vector + unsigned num) // vector entry number { // set stack map vector entry by long vector[num].m_type = SM_LONG_HI; @@ -594,9 +562,8 @@ /** * Sets double data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_double( vf_MapEntry *vector, // stack map vector - unsigned num ) // vector entry number +static inline void vf_set_vector_stack_entry_double(vf_MapEntry *vector, // stack map vector + unsigned num) // vector entry number { // set stack map vector entry by double vector[num].m_type = SM_DOUBLE_HI; @@ -606,10 +573,9 @@ /** * Sets return address data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_addr( vf_MapEntry *vector, // stack map vector - unsigned num, // vector entry number - unsigned count ) // program count +static inline void vf_set_vector_stack_entry_addr(vf_MapEntry *vector, // stack map vector + unsigned num, // vector entry number + unsigned count) // program count { // set stack map vector entry by return address vector[num].m_type = SM_RETURN_ADDR; @@ -619,9 +585,8 @@ /** * Sets single word data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_word( vf_MapEntry *vector, // stack map vector - unsigned num ) // vector entry number +static inline void vf_set_vector_stack_entry_word(vf_MapEntry *vector, // stack map vector + unsigned num) // vector entry number { // set stack map vector entry by word vector[num].m_type = SM_WORD; @@ -630,9 +595,8 @@ /** * Sets double word data type for given stack map vector entry. */ -static inline void -vf_set_vector_stack_entry_word2( vf_MapEntry *vector, // stack map vector - unsigned num ) // vector entry number +static inline void vf_set_vector_stack_entry_word2(vf_MapEntry *vector, // stack map vector + unsigned num) // vector entry number { // set stack map vector entry by double word vector[num].m_type = SM_WORD2_HI; @@ -642,110 +606,103 @@ /** * Sets int data type for given local variable vector entry. */ -static inline void -vf_set_vector_local_var_int( vf_MapEntry *vector, // local variable vector - unsigned num, // vector entry number - unsigned local ) // number of local variable +static inline void vf_set_vector_local_var_int(vf_MapEntry *vector, // local variable vector + unsigned num, // vector entry number + unsigned local) // number of local variable { // set local variable vector entry by int vector[num].m_type = SM_INT; vector[num].m_is_local = true; - vector[num].m_local = ( unsigned short )local; + vector[num].m_local = (unsigned short) local; } // vf_set_vector_local_var_int /** * Sets float data type for given local variable vector entry. */ -static inline void -vf_set_vector_local_var_float( vf_MapEntry *vector, // local variable vector - unsigned num, // vector entry number - unsigned local ) // number of local variable +static inline void vf_set_vector_local_var_float(vf_MapEntry *vector, // local variable vector + unsigned num, // vector entry number + unsigned local) // number of local variable { // set local variable vector entry by float vector[num].m_type = SM_FLOAT; vector[num].m_is_local = true; - vector[num].m_local = ( unsigned short )local; + vector[num].m_local = (unsigned short) local; } // vf_set_vector_local_var_float /** * Sets long data type for given local variable vector entry. */ -static inline void -vf_set_vector_local_var_long( vf_MapEntry *vector, // local variable vector - unsigned num, // vector entry number - unsigned local ) // number of local variable +static inline void vf_set_vector_local_var_long(vf_MapEntry *vector, // local variable vector + unsigned num, // vector entry number + unsigned local) // number of local variable { // set local variable vector entry by long vector[num].m_type = SM_LONG_HI; vector[num].m_is_local = true; - vector[num].m_local = ( unsigned short )local; + vector[num].m_local = (unsigned short) local; vector[num + 1].m_type = SM_LONG_LO; vector[num + 1].m_is_local = true; - vector[num + 1].m_local = ( unsigned short )( local + 1 ); + vector[num + 1].m_local = (unsigned short) (local + 1); } // vf_set_vector_local_var_long /** * Sets double data type for given local variable vector entry. */ -static inline void -vf_set_vector_local_var_double( vf_MapEntry *vector, // local variable vector - unsigned num, // vector entry number - unsigned local ) // number of local variable +static inline void vf_set_vector_local_var_double(vf_MapEntry *vector, // local variable vector + unsigned num, // vector entry number + unsigned local) // number of local variable { // set local variable vector entry by double vector[num].m_type = SM_DOUBLE_HI; vector[num].m_is_local = true; - vector[num].m_local = ( unsigned short )local; + vector[num].m_local = (unsigned short) local; vector[num + 1].m_type = SM_DOUBLE_LO; vector[num + 1].m_is_local = true; - vector[num + 1].m_local = ( unsigned short )( local + 1 ); + vector[num + 1].m_local = (unsigned short) (local + 1); } // vf_set_vector_local_var_double /** * Sets reference data type for given local variable vector entry. */ -static inline void -vf_set_vector_local_var_ref( vf_MapEntry *vector, // local variable vector - unsigned num, // vector entry number - vf_ValidType *type, // reference type - unsigned local ) // number of local variable +static inline void vf_set_vector_local_var_ref(vf_MapEntry *vector, // local variable vector + unsigned num, // vector entry number + vf_ValidType *type, // reference type + unsigned local) // number of local variable { // set stack map vector entry by reference vector[num].m_type = SM_REF; vector[num].m_vtype = type; vector[num].m_is_local = true; - vector[num].m_local = ( unsigned short )local; + vector[num].m_local = (unsigned short) local; } // vf_set_vector_local_var_ref /** * Sets return address data type for given local variable vector entry. */ -static inline void -vf_set_vector_local_var_addr( vf_MapEntry *vector, // stack map vector - unsigned num, // vector entry number - unsigned count, // program count - unsigned local ) // number of local variable +static inline void vf_set_vector_local_var_addr(vf_MapEntry *vector, // stack map vector + unsigned num, // vector entry number + unsigned count, // program count + unsigned local) // number of local variable { // set local variable vector entry to return address vector[num].m_type = SM_RETURN_ADDR; vector[num].m_pc = count; vector[num].m_is_local = true; - vector[num].m_local = ( unsigned short )local; + vector[num].m_local = (unsigned short) local; } // vf_set_vector_local_var_addr /** * Sets a given data type for a given local variable vector entry. */ -static inline void -vf_set_vector_local_var_type( vf_MapEntry *vector, // local variable vector - unsigned num, // vector entry number - vf_MapType type, // stack map entry type - unsigned local ) // number of local variable +static inline void vf_set_vector_local_var_type(vf_MapEntry *vector, // local variable vector + unsigned num, // vector entry number + vf_MapType type, // stack map entry type + unsigned local) // number of local variable { // set stack map vector entry by reference vector[num].m_type = type; vector[num].m_is_local = true; - vector[num].m_local = ( unsigned short )local; + vector[num].m_local = (unsigned short) local; } // vf_set_vector_local_var_type /************************************************************ @@ -755,175 +712,159 @@ /** * Allocates memory for new code instruction in the IN stack map vector. */ -static inline void -vf_new_in_vector( vf_Instr *instr, // code instruction - unsigned len, // vector length - vf_Pool *pool ) // memory pool +static inline void vf_new_in_vector(vf_Instr *instr, // code instruction + unsigned len, // vector length + vf_Pool *pool) // memory pool { // create IN vector - instr->m_inlen = ( unsigned short )len; + instr->m_inlen = (unsigned short) len; instr->m_invector = - (vf_MapEntry*)vf_palloc( pool, len * sizeof( vf_MapEntry ) ); + (vf_MapEntry *) vf_palloc(pool, len * sizeof(vf_MapEntry)); } // vf_new_in_vector /** * Sets check attribute for a code instruction in the IN stack map vector entry. */ -static inline void -vf_set_in_vector_check( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - vf_CheckConstraint check ) // constraint check type +static inline void vf_set_in_vector_check(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + vf_CheckConstraint check) // constraint check type { - vf_set_vector_check( instr->m_invector, num, check ); + vf_set_vector_check(instr->m_invector, num, check); } // vf_set_in_vector_check /** * Sets constant pool index for a code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_check_index( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - unsigned short index ) // constraint pool index +static inline void vf_set_in_vector_check_index(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + unsigned short index) // constraint pool index { - vf_set_vector_check_index( instr->m_invector, num, index ); + vf_set_vector_check_index(instr->m_invector, num, index); } // vf_set_in_vector_check_index /** * Sets a given data type to stack map vector entry. */ -static inline void -vf_set_in_vector_type( vf_InstrHandle instr, // code instruction - unsigned num, // vector entry number - vf_MapType type ) // stack map entry type +static inline void vf_set_in_vector_type(vf_InstrHandle instr, // code instruction + unsigned num, // vector entry number + vf_MapType type) // stack map entry type { - vf_set_vector_type( instr->m_invector, num, type ); + vf_set_vector_type(instr->m_invector, num, type); } // vf_set_in_vector_type /** * Sets int data type for code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_stack_entry_int( vf_InstrHandle instr, // code instruction - unsigned num ) // IN vector entry number +static inline void vf_set_in_vector_stack_entry_int(vf_InstrHandle instr, // code instruction + unsigned num) // IN vector entry number { - vf_set_vector_stack_entry_int( instr->m_invector, num ); + vf_set_vector_stack_entry_int(instr->m_invector, num); } // vf_set_vector_stack_entry_int /** * Sets float data type for code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_stack_entry_float( vf_InstrHandle instr, // code instruction - unsigned num ) // IN vector entry number +static inline void vf_set_in_vector_stack_entry_float(vf_InstrHandle instr, // code instruction + unsigned num) // IN vector entry number { - vf_set_vector_stack_entry_float( instr->m_invector, num ); + vf_set_vector_stack_entry_float(instr->m_invector, num); } // vf_set_in_vector_stack_entry_float /** * Sets long data type for code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_stack_entry_long( vf_InstrHandle instr, // code instruction - unsigned num ) // IN vector entry number +static inline void vf_set_in_vector_stack_entry_long(vf_InstrHandle instr, // code instruction + unsigned num) // IN vector entry number { - vf_set_vector_stack_entry_long( instr->m_invector, num ); + vf_set_vector_stack_entry_long(instr->m_invector, num); } // vf_set_in_vector_stack_entry_long /** * Sets double data type for code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_stack_entry_double( vf_InstrHandle instr, // code instruction - unsigned num ) // IN vector entry number +static inline void vf_set_in_vector_stack_entry_double(vf_InstrHandle instr, // code instruction + unsigned num) // IN vector entry number { - vf_set_vector_stack_entry_double( instr->m_invector, num ); + vf_set_vector_stack_entry_double(instr->m_invector, num); } // vf_set_in_vector_stack_entry_double /** * Sets reference data type for code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_stack_entry_ref( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - vf_ValidType *type ) // reference type +static inline void vf_set_in_vector_stack_entry_ref(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + vf_ValidType *type) // reference type { - vf_set_vector_stack_entry_ref( instr->m_invector, num, type ); + vf_set_vector_stack_entry_ref(instr->m_invector, num, type); } // vf_set_in_vector_stack_entry_ref /** * Sets single word data type for code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_stack_entry_word( vf_InstrHandle instr, // code instruction - unsigned num ) // IN vector entry number +static inline void vf_set_in_vector_stack_entry_word(vf_InstrHandle instr, // code instruction + unsigned num) // IN vector entry number { - vf_set_vector_stack_entry_word( instr->m_invector, num ); + vf_set_vector_stack_entry_word(instr->m_invector, num); } // vf_set_in_vector_stack_entry_word /** * Sets double word data type for code instruction IN stack map vector entry. */ -static inline void -vf_set_in_vector_stack_entry_word2( vf_InstrHandle instr, // code instruction - unsigned num ) // IN vector entry number +static inline void vf_set_in_vector_stack_entry_word2(vf_InstrHandle instr, // code instruction + unsigned num) // IN vector entry number { - vf_set_vector_stack_entry_word2( instr->m_invector, num ); + vf_set_vector_stack_entry_word2(instr->m_invector, num); } // vf_set_in_vector_stack_entry_word2 /** * Sets int data type for code instruction IN local variable vector entry. */ -static inline void -vf_set_in_vector_local_var_int( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - unsigned local ) // local variable number +static inline void vf_set_in_vector_local_var_int(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_int( instr->m_invector, num, local ); + vf_set_vector_local_var_int(instr->m_invector, num, local); } // vf_set_in_vector_local_var_int /** * Sets float data type for code instruction IN local variable vector entry. */ -static inline void -vf_set_in_vector_local_var_float( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - unsigned local ) // local variable number +static inline void vf_set_in_vector_local_var_float(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_float( instr->m_invector, num, local ); + vf_set_vector_local_var_float(instr->m_invector, num, local); } // vf_set_in_vector_local_var_float /** * Sets long data type for code instruction IN local variable vector entry. */ -static inline void -vf_set_in_vector_local_var_long( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - unsigned local ) // local variable number +static inline void vf_set_in_vector_local_var_long(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_long( instr->m_invector, num, local ); + vf_set_vector_local_var_long(instr->m_invector, num, local); } // vf_set_in_vector_local_var_long /** * Sets double data type for code instruction IN local variable vector entry. */ -static inline void -vf_set_in_vector_local_var_double( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - unsigned local ) // local variable number +static inline void vf_set_in_vector_local_var_double(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_double( instr->m_invector, num, local ); + vf_set_vector_local_var_double(instr->m_invector, num, local); } // vf_set_in_vector_local_var_double /** * Sets reference data type for code instruction IN local variable vector entry. */ -static inline void -vf_set_in_vector_local_var_ref( vf_InstrHandle instr, // code instruction - unsigned num, // IN vector entry number - vf_ValidType *type, // reference type - unsigned local ) // local variable number +static inline void vf_set_in_vector_local_var_ref(vf_InstrHandle instr, // code instruction + unsigned num, // IN vector entry number + vf_ValidType *type, // reference type + unsigned local) // local variable number { - vf_set_vector_local_var_ref( instr->m_invector, num, type, local ); + vf_set_vector_local_var_ref(instr->m_invector, num, type, local); } // vf_set_in_vector_local_var_ref /************************************************************ @@ -933,35 +874,32 @@ /** * Function allocates memory for new code instruction OUT stack map vector. */ -static inline void -vf_new_out_vector( vf_Instr *instr, // code instruction - unsigned len, // vector length - vf_Pool *pool ) // memory pool +static inline void vf_new_out_vector(vf_Instr *instr, // code instruction + unsigned len, // vector length + vf_Pool *pool) // memory pool { // create stack map OUT vector - instr->m_outlen = ( unsigned short )len; + instr->m_outlen = (unsigned short) len; instr->m_outvector = - (vf_MapEntry*)vf_palloc( pool, len * sizeof( vf_MapEntry ) ); + (vf_MapEntry *) vf_palloc(pool, len * sizeof(vf_MapEntry)); } // vf_new_out_vector /** * Sets a given data type to stack map OUT vector entry. */ -static inline void -vf_set_out_vector_type( vf_InstrHandle instr, // code instruction - unsigned num, // vector entry number - vf_MapType type ) // stack map entry type +static inline void vf_set_out_vector_type(vf_InstrHandle instr, // code instruction + unsigned num, // vector entry number + vf_MapType type) // stack map entry type { - vf_set_vector_type( instr->m_outvector, num, type ); + vf_set_vector_type(instr->m_outvector, num, type); } // vf_set_out_vector_type /** * Sets a given program counter to stack map OUT vector entry. */ -static inline void -vf_set_out_vector_opcode_new( vf_InstrHandle instr, // code instruction - unsigned num, // vector entry number - unsigned opcode_new ) // new opcode +static inline void vf_set_out_vector_opcode_new(vf_InstrHandle instr, // code instruction + unsigned num, // vector entry number + unsigned opcode_new) // new opcode { instr->m_outvector[num].m_new = opcode_new; } // vf_set_out_vector_opcode_new @@ -969,108 +907,98 @@ /** * Sets int data type for code instruction OUT stack map vector entry. */ -static inline void -vf_set_out_vector_stack_entry_int( vf_InstrHandle instr, // code instruction - unsigned num ) // OUT vector entry number +static inline void vf_set_out_vector_stack_entry_int(vf_InstrHandle instr, // code instruction + unsigned num) // OUT vector entry number { - vf_set_vector_stack_entry_int( instr->m_outvector, num ); + vf_set_vector_stack_entry_int(instr->m_outvector, num); } // vf_set_vector_stack_entry_int /** * Sets float data type for code instruction OUT stack map vector entry. */ -static inline void -vf_set_out_vector_stack_entry_float( vf_InstrHandle instr, // code instruction - unsigned num ) // OUT vector entry number +static inline void vf_set_out_vector_stack_entry_float(vf_InstrHandle instr, // code instruction + unsigned num) // OUT vector entry number { - vf_set_vector_stack_entry_float( instr->m_outvector, num ); + vf_set_vector_stack_entry_float(instr->m_outvector, num); } // vf_set_out_vector_stack_entry_float /** * Sets long data type for code instruction OUT stack map vector entry. */ -static inline void -vf_set_out_vector_stack_entry_long( vf_InstrHandle instr, // code instruction - unsigned num ) // OUT vector entry number +static inline void vf_set_out_vector_stack_entry_long(vf_InstrHandle instr, // code instruction + unsigned num) // OUT vector entry number { - vf_set_vector_stack_entry_long( instr->m_outvector, num ); + vf_set_vector_stack_entry_long(instr->m_outvector, num); } // vf_set_out_vector_stack_entry_long /** * Sets double data type for code instruction OUT stack map vector entry. */ -static inline void -vf_set_out_vector_stack_entry_double( vf_InstrHandle instr, // code instruction - unsigned num ) // OUT vector entry number +static inline void vf_set_out_vector_stack_entry_double(vf_InstrHandle instr, // code instruction + unsigned num) // OUT vector entry number { - vf_set_vector_stack_entry_double( instr->m_outvector, num ); + vf_set_vector_stack_entry_double(instr->m_outvector, num); } // vf_set_out_vector_stack_entry_double /** * Sets reference data type for code instruction OUT stack map vector entry. */ -static inline void -vf_set_out_vector_stack_entry_ref( vf_InstrHandle instr, // code instruction - unsigned num, // OUT vector entry number - vf_ValidType *type ) // reference type +static inline void vf_set_out_vector_stack_entry_ref(vf_InstrHandle instr, // code instruction + unsigned num, // OUT vector entry number + vf_ValidType *type) // reference type { - vf_set_vector_stack_entry_ref( instr->m_outvector, num, type ); + vf_set_vector_stack_entry_ref(instr->m_outvector, num, type); } // vf_set_out_vector_stack_entry_ref /** * Sets int data type for code instruction OUT local variable vector entry. */ -static inline void -vf_set_out_vector_local_var_int( vf_InstrHandle instr, // code instruction - unsigned num, // OUT vector entry number - unsigned local ) // local variable number +static inline void vf_set_out_vector_local_var_int(vf_InstrHandle instr, // code instruction + unsigned num, // OUT vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_int( instr->m_outvector, num, local ); + vf_set_vector_local_var_int(instr->m_outvector, num, local); } // vf_set_out_vector_local_var_int /** * Sets float data type for code instruction OUT local variable vector entry. */ -static inline void -vf_set_out_vector_local_var_float( vf_InstrHandle instr, // code instruction - unsigned num, // OUT vector entry number - unsigned local ) // local variable number +static inline void vf_set_out_vector_local_var_float(vf_InstrHandle instr, // code instruction + unsigned num, // OUT vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_float( instr->m_outvector, num, local ); + vf_set_vector_local_var_float(instr->m_outvector, num, local); } // vf_set_out_vector_local_var_float /** * Sets long data type for code instruction OUT local variable vector entry. */ -static inline void -vf_set_out_vector_local_var_long( vf_InstrHandle instr, // code instruction - unsigned num, // OUT vector entry number - unsigned local ) // local variable number +static inline void vf_set_out_vector_local_var_long(vf_InstrHandle instr, // code instruction + unsigned num, // OUT vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_long( instr->m_outvector, num, local ); + vf_set_vector_local_var_long(instr->m_outvector, num, local); } // vf_set_out_vector_local_var_long /** * Sets double data type for code instruction OUT local variable vector entry. */ -static inline void -vf_set_out_vector_local_var_double( vf_InstrHandle instr, // code instruction - unsigned num, // OUT vector entry number - unsigned local ) // local variable number +static inline void vf_set_out_vector_local_var_double(vf_InstrHandle instr, // code instruction + unsigned num, // OUT vector entry number + unsigned local) // local variable number { - vf_set_vector_local_var_double( instr->m_outvector, num, local ); + vf_set_vector_local_var_double(instr->m_outvector, num, local); } // vf_set_out_vector_local_var_double /** * Sets a given data type for code instruction OUT local variable vector entry. */ -static inline void -vf_set_out_vector_local_var_type( vf_InstrHandle instr, // code instruction - unsigned num, // OUT vector entry number - vf_MapType type, // stack map entry - unsigned local ) // local variable number +static inline void vf_set_out_vector_local_var_type(vf_InstrHandle instr, // code instruction + unsigned num, // OUT vector entry number + vf_MapType type, // stack map entry + unsigned local) // local variable number { - vf_set_vector_local_var_type( instr->m_outvector, num, type, local ); + vf_set_vector_local_var_type(instr->m_outvector, num, type, local); } // vf_set_out_vector_local_var_type /************************************************************ @@ -1079,50 +1007,49 @@ /** * Parses method, class or field descriptions. */ -void -vf_parse_description( const char *descr, // descriptor of method, class or field - unsigned short *inlen, // returned number of IN descriptor parameters - unsigned short *outlen ) // returned number of OUT descriptor +void vf_parse_description(const char *descr, // descriptor of method, class or field + unsigned short *inlen, // returned number of IN descriptor parameters + unsigned short *outlen) // returned number of OUT descriptor // parameters (for method) { /** * Check parameters */ - assert( descr ); - assert( inlen ); + assert(descr); + assert(inlen); /** * Parse description for defining method stack */ *inlen = 0; - if( outlen ) { + if (outlen) { *outlen = 0; } bool array = false; // start parsing input parameters unsigned short *count = inlen; - for( unsigned short index = 0; descr[index]; index++ ) { - switch ( descr[index] ) { + for (unsigned short index = 0; descr[index]; index++) { + switch (descr[index]) { case 'L': // skip class name do { index++; #if _VF_DEBUG - if( !descr[index] ) { + if (!descr[index]) { VF_DIE - ( "vf_parse_description: incorrect structure of constant pool" ); + ("vf_parse_description: incorrect structure of constant pool"); } #endif // _VF_DEBUG - } while( descr[index] != ';' ); + } while (descr[index] != ';'); case 'B': case 'C': case 'F': case 'I': case 'S': case 'Z': - if( !array ) { - ( *count )++; // increase stack value + if (!array) { + (*count)++; // increase stack value } else { array = false; // reset array structure } @@ -1130,8 +1057,8 @@ break; case 'D': case 'J': - if( !array ) { - ( *count ) += 2; // increase stack value + if (!array) { + (*count) += 2; // increase stack value } else { array = false; // reset array structure } @@ -1142,14 +1069,14 @@ do { index++; #if _VF_DEBUG - if( !descr[index] ) { + if (!descr[index]) { VF_DIE - ( "vf_parse_description: incorrect structure of constant pool" ); + ("vf_parse_description: incorrect structure of constant pool"); } #endif // _VF_DEBUG - } while( descr[index] == '[' ); + } while (descr[index] == '['); index--; - ( *count )++; // increase stack value + (*count)++; // increase stack value break; case '(': // parse arguments @@ -1161,35 +1088,34 @@ break; default: VF_DIE - ( "vf_parse_description: incorrect structure of constant pool" ); + ("vf_parse_description: incorrect structure of constant pool"); break; } } } // vf_parse_description static inline void -vf_set_array_ref( const char *type, - unsigned len, - vf_MapEntry *vector, unsigned *index, vf_ContextHandle ctx ) +vf_set_array_ref(const char *type, + unsigned len, + vf_MapEntry *vector, unsigned *index, vf_ContextHandle ctx) { // set array reference entry - vf_ValidType *valid = ctx->m_type->NewType( type, len ); - vf_set_vector_stack_entry_ref( vector, *index, valid ); - ( *index )++; + vf_ValidType *valid = ctx->m_type->NewType(type, len); + vf_set_vector_stack_entry_ref(vector, *index, valid); + (*index)++; } // vf_set_array_ref /** * Function parses descriptor and sets input and output data flow vectors. */ -void -vf_set_description_vector( const char *descr, // descriptor - unsigned short inlen, // number of entries for IN vector - unsigned short add, // additional number of entries - // to IN data flow vector - unsigned short outlen, // number of entries for OUT vector - vf_MapEntry **invector, // pointer to IN vector - vf_MapEntry **outvector, // pointer to OUT vector - vf_ContextHandle ctx ) // verification context +void vf_set_description_vector(const char *descr, // descriptor + unsigned short inlen, // number of entries for IN vector + unsigned short add, // additional number of entries + // to IN data flow vector + unsigned short outlen, // number of entries for OUT vector + vf_MapEntry **invector, // pointer to IN vector + vf_MapEntry **outvector, // pointer to OUT vector + vf_ContextHandle ctx) // verification context { const char *type = 0; unsigned index, count = 0, vector_index; @@ -1200,18 +1126,18 @@ /** * Check parameters */ - assert( descr ); + assert(descr); /** * Create vectors */ - if( inlen + add ) { - assert( invector ); - vf_new_vector( invector, inlen + add, pool ); + if (inlen + add) { + assert(invector); + vf_new_vector(invector, inlen + add, pool); } - if( outlen ) { - assert( outvector ); - vf_new_vector( outvector, outlen, pool ); + if (outlen) { + assert(outvector); + vf_new_vector(outvector, outlen, pool); } /** @@ -1219,45 +1145,44 @@ */ bool array = false; vector_index = add; - for( index = 0, vector = invector; descr[index]; index++ ) { - switch ( descr[index] ) { + for (index = 0, vector = invector; descr[index]; index++) { + switch (descr[index]) { case 'L': // skip method name - if( !array ) { + if (!array) { count = index; type = &descr[count]; } do { index++; - } while( descr[index] != ';' ); - if( !array ) { + } while (descr[index] != ';'); + if (!array) { // set vector reference entry - valid = ctx->m_type->NewType( type, index - count ); - vf_set_vector_stack_entry_ref( *vector, vector_index, valid ); + valid = ctx->m_type->NewType(type, index - count); + vf_set_vector_stack_entry_ref(*vector, vector_index, valid); vector_index++; } else { - vf_set_array_ref( type, index - count, *vector, &vector_index, - ctx ); + vf_set_array_ref(type, index - count, *vector, &vector_index, + ctx); // reset array structure array = false; } break; case 'Z': - if( !array ) { + if (!array) { // set vector int entry - vf_set_vector_stack_entry_int( *vector, vector_index ); + vf_set_vector_stack_entry_int(*vector, vector_index); vector_index++; } else { // set integer array type unsigned iter; unsigned len = index - count + 1; - char *int_array = (char*)vf_palloc( pool, len ); - for( iter = 0; iter < len - 1; iter++ ) { + char *int_array = (char *) vf_palloc(pool, len); + for (iter = 0; iter < len - 1; iter++) { int_array[iter] = '['; } int_array[iter] = 'B'; - vf_set_array_ref( int_array, len, *vector, &vector_index, - ctx ); + vf_set_array_ref(int_array, len, *vector, &vector_index, ctx); // reset array structure array = false; } @@ -1266,49 +1191,49 @@ case 'B': case 'C': case 'S': - if( !array ) { + if (!array) { // set vector int entry - vf_set_vector_stack_entry_int( *vector, vector_index ); + vf_set_vector_stack_entry_int(*vector, vector_index); vector_index++; } else { - vf_set_array_ref( type, index - count + 1, *vector, - &vector_index, ctx ); + vf_set_array_ref(type, index - count + 1, *vector, + &vector_index, ctx); // reset array structure array = false; } break; case 'F': - if( !array ) { + if (!array) { // set vector float entry - vf_set_vector_stack_entry_float( *vector, vector_index ); + vf_set_vector_stack_entry_float(*vector, vector_index); vector_index++; } else { - vf_set_array_ref( type, index - count + 1, *vector, - &vector_index, ctx ); + vf_set_array_ref(type, index - count + 1, *vector, + &vector_index, ctx); // reset array structure array = false; } break; case 'D': - if( !array ) { + if (!array) { // set vector double entry - vf_set_vector_stack_entry_double( *vector, vector_index ); + vf_set_vector_stack_entry_double(*vector, vector_index); vector_index += 2; } else { - vf_set_array_ref( type, index - count + 1, *vector, - &vector_index, ctx ); + vf_set_array_ref(type, index - count + 1, *vector, + &vector_index, ctx); // reset array structure array = false; } break; case 'J': - if( !array ) { + if (!array) { // set vector long entry - vf_set_vector_stack_entry_long( *vector, vector_index ); + vf_set_vector_stack_entry_long(*vector, vector_index); vector_index += 2; } else { - vf_set_array_ref( type, index - count + 1, *vector, - &vector_index, ctx ); + vf_set_array_ref(type, index - count + 1, *vector, + &vector_index, ctx); // reset array structure array = false; } @@ -1321,7 +1246,7 @@ // skip array structure do { index++; - } while( descr[index] == '[' ); + } while (descr[index] == '['); index--; break; case '(': @@ -1348,15 +1273,14 @@ /** * Function returns name string from NameAndType constant pool entry. */ -static inline const char * -vf_get_name_from_cp_nameandtype( unsigned short index, // constant pool entry index - vf_ContextHandle ctx ) // verification context +static inline const char *vf_get_name_from_cp_nameandtype(unsigned short index, // constant pool entry index + vf_ContextHandle ctx) // verification context { // get name constant pool index unsigned short name_cp_index = - class_get_cp_name_index( ctx->m_class, index ); + class_get_cp_name_index(ctx->m_class, index); // get name string from NameAndType constant pool entry - const char *name = class_get_cp_utf8_bytes( ctx->m_class, name_cp_index ); + const char *name = class_get_cp_utf8_bytes(ctx->m_class, name_cp_index); return name; } // vf_get_name_from_cp_nameandtype @@ -1364,16 +1288,14 @@ /** * Function returns descriptor string from NameAndType constant pool entry. */ -static inline const char * -vf_get_decriptor_from_cp_nameandtype( unsigned short index, // constant pool entry index - vf_ContextHandle ctx ) // verification context +static inline const char *vf_get_decriptor_from_cp_nameandtype(unsigned short index, // constant pool entry index + vf_ContextHandle ctx) // verification context { // get description constant pool index unsigned short descr_cp_index = - class_get_cp_descriptor_index( ctx->m_class, index ); + class_get_cp_descriptor_index(ctx->m_class, index); // get descriptor from NameAndType constant pool entry - const char *descr = - class_get_cp_utf8_bytes( ctx->m_class, descr_cp_index ); + const char *descr = class_get_cp_utf8_bytes(ctx->m_class, descr_cp_index); return descr; } // vf_get_cp_nameandtype @@ -1381,44 +1303,43 @@ /** * Function returns valid type string by given class name. */ -static inline const char * -vf_get_class_valid_type( const char *class_name, // class name - size_t name_len, // class name length - size_t * len, // length of created string - vf_Pool *pool ) // memory pool +static inline const char *vf_get_class_valid_type(const char *class_name, // class name + size_t name_len, // class name length + size_t * len, // length of created string + vf_Pool *pool) // memory pool { char *result; // create valid type - if( class_name[0] == '[' ) { + if (class_name[0] == '[') { // copy array class name - if( class_name[name_len - 1] == ';' ) { + if (class_name[name_len - 1] == ';') { // object type array *len = name_len - 1; - result = (char*)class_name; + result = (char *) class_name; } else { // primitive type array *len = name_len; - result = (char*)class_name; - switch ( class_name[name_len - 1] ) { + result = (char *) class_name; + switch (class_name[name_len - 1]) { case 'Z': // set integer array type - result = (char*)vf_palloc( pool, ( *len ) + 1 ); - memcpy( result, class_name, name_len ); + result = (char *) vf_palloc(pool, (*len) + 1); + memcpy(result, class_name, name_len); result[name_len - 1] = 'B'; break; default: // don't need change type - result = (char*)class_name; + result = (char *) class_name; break; } } } else { // create class signature *len = name_len + 1; - result = (char*)vf_palloc( pool, ( *len ) + 1 ); + result = (char *) vf_palloc(pool, (*len) + 1); result[0] = 'L'; - memcpy( &result[1], class_name, name_len ); + memcpy(&result[1], class_name, name_len); } return result; } // vf_get_class_valid_type @@ -1426,19 +1347,18 @@ /** * Function creates valid type by given class name. */ -vf_ValidType * -vf_create_class_valid_type( const char *class_name, // class name - vf_ContextHandle ctx ) // verification context +vf_ValidType *vf_create_class_valid_type(const char *class_name, // class name + vf_ContextHandle ctx) // verification context { size_t len; vf_ValidType *result; // get class valid type - const char *type = vf_get_class_valid_type( class_name, - strlen( class_name ), - &len, ctx->m_pool ); + const char *type = vf_get_class_valid_type(class_name, + strlen(class_name), + &len, ctx->m_pool); // create valid type - result = ctx->m_type->NewType( type, len ); + result = ctx->m_type->NewType(type, len); return result; } // vf_create_class_valid_type @@ -1447,28 +1367,27 @@ * Function returns result of check and * name string, type descriptor string and class name string (if it's needed). */ -static inline void -vf_check_cp_ref( unsigned short index, // constant pool entry index - const char **name, // pointer to name - const char **descr, // pointer to descriptor - const char **class_name, // pointer to class name - vf_ContextHandle ctx ) // verification context +static inline void vf_check_cp_ref(unsigned short index, // constant pool entry index + const char **name, // pointer to name + const char **descr, // pointer to descriptor + const char **class_name, // pointer to class name + vf_ContextHandle ctx) // verification context { - assert( name ); - assert( descr ); + assert(name); + assert(descr); // get class name if it's needed - if( class_name ) { + if (class_name) { unsigned short class_cp_index = - class_get_cp_ref_class_index( ctx->m_class, index ); - *class_name = vf_get_cp_class_name( ctx->m_class, class_cp_index ); + class_get_cp_ref_class_index(ctx->m_class, index); + *class_name = vf_get_cp_class_name(ctx->m_class, class_cp_index); } // get name and descriptor from NameAndType constant pool entry unsigned short name_and_type_cp_index = - class_get_cp_ref_name_and_type_index( ctx->m_class, index ); - *name = vf_get_name_from_cp_nameandtype( name_and_type_cp_index, ctx ); + class_get_cp_ref_name_and_type_index(ctx->m_class, index); + *name = vf_get_name_from_cp_nameandtype(name_and_type_cp_index, ctx); *descr = - vf_get_decriptor_from_cp_nameandtype( name_and_type_cp_index, ctx ); + vf_get_decriptor_from_cp_nameandtype(name_and_type_cp_index, ctx); } // vf_check_cp_ref /** @@ -1476,60 +1395,59 @@ * Sets IN and OUT vectors for constant pool entries. * @return result of the check */ -static vf_Result -vf_check_cp_method( unsigned short index, // constant pool entry index - vf_Parse * cp_parse, // entry parse result structure - bool is_interface, // interface flag - bool stack_with_ref, // stack with this reference flag - vf_Context *ctx ) // verification context +static vf_Result vf_check_cp_method(unsigned short index, // constant pool entry index + vf_Parse * cp_parse, // entry parse result structure + bool is_interface, // interface flag + bool stack_with_ref, // stack with this reference flag + vf_Context *ctx) // verification context { // get constant pool length - unsigned short len = class_get_cp_size( ctx->m_class ); + unsigned short len = class_get_cp_size(ctx->m_class); // check constant pool index - CHECK_CONST_POOL_ID( index, len, ctx ); + CHECK_CONST_POOL_ID(index, len, ctx); // check constant pool type - if( is_interface ) { - CHECK_CONST_POOL_INTERFACE( ctx, index ); + if (is_interface) { + CHECK_CONST_POOL_INTERFACE(ctx, index); } else { - CHECK_CONST_POOL_METHOD( ctx, index ); + CHECK_CONST_POOL_METHOD(ctx, index); } // get method description and name const char *name = NULL; const char *descr = NULL; const char *class_name; - vf_check_cp_ref( index, &name, &descr, - ( stack_with_ref ? &class_name : NULL ), ctx ); + vf_check_cp_ref(index, &name, &descr, + (stack_with_ref ? &class_name : NULL), ctx); // check result - assert( name ); - assert( descr ); + assert(name); + assert(descr); // set method name cp_parse->method.m_name = name; // parse method description - vf_parse_description( descr, &cp_parse->method.m_inlen, - &cp_parse->method.m_outlen ); + vf_parse_description(descr, &cp_parse->method.m_inlen, + &cp_parse->method.m_outlen); // create instruction vectors - if( stack_with_ref ) { - vf_set_description_vector( descr, cp_parse->method.m_inlen, - 1 /* ref + vector */ , - cp_parse->method.m_outlen, - &cp_parse->method.m_invector, - &cp_parse->method.m_outvector, ctx ); + if (stack_with_ref) { + vf_set_description_vector(descr, cp_parse->method.m_inlen, + 1 /* ref + vector */ , + cp_parse->method.m_outlen, + &cp_parse->method.m_invector, + &cp_parse->method.m_outvector, ctx); // set first ref cp_parse->method.m_inlen += 1; - vf_ValidType *type = vf_create_class_valid_type( class_name, ctx ); - vf_set_vector_stack_entry_ref( cp_parse->method.m_invector, 0, type ); + vf_ValidType *type = vf_create_class_valid_type(class_name, ctx); + vf_set_vector_stack_entry_ref(cp_parse->method.m_invector, 0, type); } else { - vf_set_description_vector( descr, cp_parse->method.m_inlen, - 0 /* only vector */ , - cp_parse->method.m_outlen, - &cp_parse->method.m_invector, - &cp_parse->method.m_outvector, ctx ); + vf_set_description_vector(descr, cp_parse->method.m_inlen, + 0 /* only vector */ , + cp_parse->method.m_outlen, + &cp_parse->method.m_invector, + &cp_parse->method.m_outvector, ctx); } - return VER_OK; + return VF_OK; } // vf_check_cp_method /** @@ -1537,44 +1455,43 @@ * Sets data flow vector for constant pool entry. * @return result of the check */ -static vf_Result -vf_check_cp_field( unsigned short index, // constant pool entry index - vf_Parse * cp_parse, // entry parse result structure - bool stack_with_ref, // stack with this reference flag - vf_Context *ctx ) // verification context +static vf_Result vf_check_cp_field(unsigned short index, // constant pool entry index + vf_Parse * cp_parse, // entry parse result structure + bool stack_with_ref, // stack with this reference flag + vf_Context *ctx) // verification context { // check constant pool index and type - unsigned short len = class_get_cp_size( ctx->m_class ); - CHECK_CONST_POOL_ID( index, len, ctx ); - CHECK_CONST_POOL_FIELD( ctx, index ); + unsigned short len = class_get_cp_size(ctx->m_class); + CHECK_CONST_POOL_ID(index, len, ctx); + CHECK_CONST_POOL_FIELD(ctx, index); // get field description and name const char *name = NULL; const char *descr = NULL; const char *class_name; - vf_check_cp_ref( index, &name, &descr, - ( stack_with_ref ? &class_name : NULL ), ctx ); + vf_check_cp_ref(index, &name, &descr, + (stack_with_ref ? &class_name : NULL), ctx); // check result - assert( name ); - assert( descr ); + assert(name); + assert(descr); // parse field description - vf_parse_description( descr, &cp_parse->field.f_vlen, NULL ); + vf_parse_description(descr, &cp_parse->field.f_vlen, NULL); // create instruction vectors - if( stack_with_ref ) { - vf_set_description_vector( descr, cp_parse->field.f_vlen, - 1 /* ref + vector */ , - 0, &cp_parse->field.f_vector, NULL, ctx ); + if (stack_with_ref) { + vf_set_description_vector(descr, cp_parse->field.f_vlen, + 1 /* ref + vector */ , + 0, &cp_parse->field.f_vector, NULL, ctx); // set first ref cp_parse->field.f_vlen += 1; - vf_ValidType *type = vf_create_class_valid_type( class_name, ctx ); - vf_set_vector_stack_entry_ref( cp_parse->field.f_vector, 0, type ); + vf_ValidType *type = vf_create_class_valid_type(class_name, ctx); + vf_set_vector_stack_entry_ref(cp_parse->field.f_vector, 0, type); } else { - vf_set_description_vector( descr, cp_parse->field.f_vlen, - 0 /* only vector */ , - 0, &cp_parse->field.f_vector, NULL, ctx ); + vf_set_description_vector(descr, cp_parse->field.f_vlen, + 0 /* only vector */ , + 0, &cp_parse->field.f_vector, NULL, ctx); } - return VER_OK; + return VF_OK; } // vf_check_cp_field /** @@ -1582,51 +1499,49 @@ * Sets data flow vector for constant pool entry. * @return result of the check */ -static inline vf_Result -vf_check_cp_single_const( unsigned short index, // constant pool entry index - vf_Parse * cp_parse, // entry parse result structure - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_cp_single_const(unsigned short index, // constant pool entry index + vf_Parse * cp_parse, // entry parse result structure + vf_Context *ctx) // verification context { // check constant pool index - unsigned short len = class_get_cp_size( ctx->m_class ); - CHECK_CONST_POOL_ID( index, len, ctx ); + unsigned short len = class_get_cp_size(ctx->m_class); + CHECK_CONST_POOL_ID(index, len, ctx); // create stack map entry cp_parse->field.f_vlen = 1; - vf_new_vector( &( cp_parse->field.f_vector ), 1, ctx->m_pool ); + vf_new_vector(&(cp_parse->field.f_vector), 1, ctx->m_pool); // check constant pool type and set stack map entry vf_ValidType *type; - switch ( class_get_cp_tag( ctx->m_class, index ) ) { + switch (class_get_cp_tag(ctx->m_class, index)) { case _CONSTANT_Integer: - vf_set_vector_stack_entry_int( cp_parse->field.f_vector, 0 ); + vf_set_vector_stack_entry_int(cp_parse->field.f_vector, 0); break; case _CONSTANT_Float: - vf_set_vector_stack_entry_float( cp_parse->field.f_vector, 0 ); + vf_set_vector_stack_entry_float(cp_parse->field.f_vector, 0); break; case _CONSTANT_String: - type = ctx->m_type->NewType( "Ljava/lang/String", 17 ); - vf_set_vector_stack_entry_ref( cp_parse->field.f_vector, 0, type ); + type = ctx->m_type->NewType("Ljava/lang/String", 17); + vf_set_vector_stack_entry_ref(cp_parse->field.f_vector, 0, type); break; case _CONSTANT_Class: - if( !vf_is_class_version_14( ctx ) ) { - type = ctx->m_type->NewType( "Ljava/lang/Class", 16 ); - vf_set_vector_stack_entry_ref( cp_parse->field.f_vector, 0, - type ); + if (!vf_is_class_version_14(ctx)) { + type = ctx->m_type->NewType("Ljava/lang/Class", 16); + vf_set_vector_stack_entry_ref(cp_parse->field.f_vector, 0, type); break; } // if class version is 1.4 verifier fails in default default: - VF_REPORT( ctx, "Illegal type for constant pool entry #" - << index << ( vf_is_class_version_14( ctx ) - ? - ": CONSTANT_Integer, CONSTANT_Float or CONSTANT_String" - : - ": CONSTANT_Integer, CONSTANT_Float, CONSTANT_String " - "or CONSTANT_Class" ) - << " are expected for ldc/ldc_w instruction" ); - return VER_ErrorConstantPool; + VF_REPORT(ctx, "Illegal type for constant pool entry #" + << index << (vf_is_class_version_14(ctx) + ? + ": CONSTANT_Integer, CONSTANT_Float or CONSTANT_String" + : + ": CONSTANT_Integer, CONSTANT_Float, CONSTANT_String " + "or CONSTANT_Class") + << " are expected for ldc/ldc_w instruction"); + return VF_ErrorConstantPool; } - return VER_OK; + return VF_OK; } // vf_check_cp_single_const /** @@ -1634,33 +1549,32 @@ * Sets data flow vector for constant pool entry. * @return result of the check */ -static inline vf_Result -vf_check_cp_double_const( unsigned short index, // constant pool entry index - vf_Parse * cp_parse, // entry parse result structure - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_cp_double_const(unsigned short index, // constant pool entry index + vf_Parse * cp_parse, // entry parse result structure + vf_Context *ctx) // verification context { // check constant pool index - unsigned short len = class_get_cp_size( ctx->m_class ); - CHECK_CONST_POOL_ID( index, len, ctx ); + unsigned short len = class_get_cp_size(ctx->m_class); + CHECK_CONST_POOL_ID(index, len, ctx); // create stack map entry cp_parse->field.f_vlen = 2; - vf_new_vector( &( cp_parse->field.f_vector ), 2, ctx->m_pool ); + vf_new_vector(&(cp_parse->field.f_vector), 2, ctx->m_pool); // check constant pool type and set stack map entry - switch ( class_get_cp_tag( ctx->m_class, index ) ) { + switch (class_get_cp_tag(ctx->m_class, index)) { case _CONSTANT_Double: - vf_set_vector_stack_entry_double( cp_parse->field.f_vector, 0 ); + vf_set_vector_stack_entry_double(cp_parse->field.f_vector, 0); break; case _CONSTANT_Long: - vf_set_vector_stack_entry_long( cp_parse->field.f_vector, 0 ); + vf_set_vector_stack_entry_long(cp_parse->field.f_vector, 0); break; default: - VF_REPORT( ctx, "Illegal type in constant pool, " - << index << - ": CONSTANT_Double or CONSTANT_Long are expected" ); - return VER_ErrorConstantPool; + VF_REPORT(ctx, "Illegal type in constant pool, " + << index << + ": CONSTANT_Double or CONSTANT_Long are expected"); + return VF_ErrorConstantPool; } - return VER_OK; + return VF_OK; } // vf_check_cp_double_const /** @@ -1668,29 +1582,28 @@ * Sets data flow vector for constant pool entry (if it's needed). * @return result of the check */ -static vf_Result -vf_check_cp_class( unsigned short index, // constant pool entry index - vf_Parse * cp_parse, // entry parse result structure - vf_Context *ctx ) // verification context +static vf_Result vf_check_cp_class(unsigned short index, // constant pool entry index + vf_Parse * cp_parse, // entry parse result structure + vf_Context *ctx) // verification context { // check constant pool index and type - unsigned short len = class_get_cp_size( ctx->m_class ); - CHECK_CONST_POOL_ID( index, len, ctx ); - CHECK_CONST_POOL_CLASS( ctx, index ); - if( cp_parse ) { + unsigned short len = class_get_cp_size(ctx->m_class); + CHECK_CONST_POOL_ID(index, len, ctx); + CHECK_CONST_POOL_CLASS(ctx, index); + if (cp_parse) { // create valid type - const char *name = vf_get_cp_class_name( ctx->m_class, index ); + const char *name = vf_get_cp_class_name(ctx->m_class, index); // check result - assert( name ); + assert(name); // create valid type for class - vf_ValidType *type = vf_create_class_valid_type( name, ctx ); + vf_ValidType *type = vf_create_class_valid_type(name, ctx); // create stack map vector cp_parse->field.f_vlen = 1; - vf_new_vector( &cp_parse->field.f_vector, 1, ctx->m_pool ); - vf_set_vector_stack_entry_ref( cp_parse->field.f_vector, 0, type ); + vf_new_vector(&cp_parse->field.f_vector, 1, ctx->m_pool); + vf_set_vector_stack_entry_ref(cp_parse->field.f_vector, 0, type); } - return VER_OK; + return VF_OK; } // vf_check_cp_class /** @@ -1698,57 +1611,55 @@ * Sets data flow vectors for current constant pool entry. * Function returns parse result. */ -static vf_Result -vf_parse_const_pool( unsigned char instr, // opcode number - unsigned short index, // constant pool entry index - vf_Parse * cp_parse, // entry parse result structure - vf_Context *ctx ) // verification context +static vf_Result vf_parse_const_pool(unsigned char instr, // opcode number + unsigned short index, // constant pool entry index + vf_Parse * cp_parse, // entry parse result structure + vf_Context *ctx) // verification context { vf_Result result; - switch ( instr ) { + switch (instr) { case OPCODE_INVOKEVIRTUAL: - result = vf_check_cp_method( index, cp_parse, false, true, ctx ); + result = vf_check_cp_method(index, cp_parse, false, true, ctx); break; case OPCODE_INVOKESPECIAL: - result = vf_check_cp_method( index, cp_parse, false, true, ctx ); + result = vf_check_cp_method(index, cp_parse, false, true, ctx); break; case OPCODE_INVOKESTATIC: - result = vf_check_cp_method( index, cp_parse, false, false, ctx ); + result = vf_check_cp_method(index, cp_parse, false, false, ctx); break; case OPCODE_INVOKEINTERFACE: - result = vf_check_cp_method( index, cp_parse, true, true, ctx ); + result = vf_check_cp_method(index, cp_parse, true, true, ctx); break; case OPCODE_GETSTATIC: case OPCODE_PUTSTATIC: - result = vf_check_cp_field( index, cp_parse, false, ctx ); + result = vf_check_cp_field(index, cp_parse, false, ctx); break; case OPCODE_GETFIELD: case OPCODE_PUTFIELD: - result = vf_check_cp_field( index, cp_parse, true, ctx ); + result = vf_check_cp_field(index, cp_parse, true, ctx); break; case OPCODE_LDC: case OPCODE_LDC_W: - result = vf_check_cp_single_const( index, cp_parse, ctx ); + result = vf_check_cp_single_const(index, cp_parse, ctx); break; case OPCODE_LDC2_W: - result = vf_check_cp_double_const( index, cp_parse, ctx ); + result = vf_check_cp_double_const(index, cp_parse, ctx); break; case OPCODE_NEW: - result = vf_check_cp_class( index, cp_parse, ctx ); + result = vf_check_cp_class(index, cp_parse, ctx); break; case OPCODE_ANEWARRAY: case OPCODE_CHECKCAST: - result = vf_check_cp_class( index, cp_parse, ctx ); + result = vf_check_cp_class(index, cp_parse, ctx); break; case OPCODE_INSTANCEOF: case OPCODE_MULTIANEWARRAY: - result = vf_check_cp_class( index, NULL, ctx ); + result = vf_check_cp_class(index, NULL, ctx); break; default: - VF_DEBUG - ( "vf_parse_const_pool: incorrect parse of code instruction" ); - return VER_ErrorInternal; + VF_DEBUG("vf_parse_const_pool: incorrect parse of code instruction"); + return VF_ErrorInternal; } return result; } // vf_parse_const_pool @@ -1760,1859 +1671,1764 @@ /** * Sets instruction structure for opcode aconst_null. */ -static inline void -vf_opcode_aconst_null( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_aconst_null(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { - vf_set_stack_modifier( instr, 1 ); - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_ref( instr, 0, NULL ); + vf_set_stack_modifier(instr, 1); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_ref(instr, 0, NULL); } // vf_opcode_aconst_null /** * Sets instruction structure for opcode iconst_n. */ -static inline void -vf_opcode_iconst_n( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_iconst_n(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { - vf_set_stack_modifier( instr, 1 ); - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_set_stack_modifier(instr, 1); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_iconst_n /** * Sets instruction structure for opcode lconst_n. */ -static inline void -vf_opcode_lconst_n( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_lconst_n(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { - vf_set_stack_modifier( instr, 2 ); - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_set_stack_modifier(instr, 2); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_lconst_n /** * Sets instruction structure for opcode fconst_n. */ -static inline void -vf_opcode_fconst_n( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_fconst_n(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { - vf_set_stack_modifier( instr, 1 ); - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_set_stack_modifier(instr, 1); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_fconst_n /** * Sets instruction structure for opcode dconst_n. */ -static inline void -vf_opcode_dconst_n( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dconst_n(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { - vf_set_stack_modifier( instr, 2 ); - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_set_stack_modifier(instr, 2); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_dconst_n /** * Sets instruction structure for opcodes ldcx. */ -static inline vf_Result -vf_opcode_ldcx( vf_Instr *instr, // code instruction - int modifier, // instruction stack modifier - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_ldcx(vf_Instr *instr, // code instruction + int modifier, // instruction stack modifier + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = - vf_parse_const_pool( *( instr->m_addr ), cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(*(instr->m_addr), cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // set stack modifier for instruction - vf_set_stack_modifier( instr, modifier ); + vf_set_stack_modifier(instr, modifier); // set stack out vector instr->m_outvector = cp_parse.field.f_vector; - instr->m_outlen = ( unsigned short )cp_parse.field.f_vlen; - return VER_OK; + instr->m_outlen = (unsigned short) cp_parse.field.f_vlen; + return VF_OK; } // vf_opcode_ldcx /** * Sets instruction structure for opcodes iloadx. */ -static inline void -vf_opcode_iloadx( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_iloadx(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_local_var_int( instr, 0, local ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_local_var_int(instr, 0, local); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_iloadx /** * Sets instruction structure for opcodes lloadx. */ -static inline void -vf_opcode_lloadx( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_lloadx(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 2 ); + vf_set_stack_modifier(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_local_var_long( instr, 0, local ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_local_var_long(instr, 0, local); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_lloadx /** * Sets instruction structure for opcodes floadx. */ -static inline void -vf_opcode_floadx( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_floadx(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_local_var_float( instr, 0, local ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_local_var_float(instr, 0, local); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_floadx /** * Sets instruction structure for opcodes dloadx. */ -static inline void -vf_opcode_dloadx( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dloadx(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 2 ); + vf_set_stack_modifier(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_local_var_double( instr, 0, local ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_local_var_double(instr, 0, local); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_dloadx /** * Sets instruction structure for opcodes aloadx. */ -static inline void -vf_opcode_aloadx( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_aloadx(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_local_var_ref( instr, 0, NULL, local ); - vf_set_vector_check( instr->m_invector, 0, VF_CHECK_UNINITIALIZED_THIS ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_local_var_ref(instr, 0, NULL, local); + vf_set_vector_check(instr->m_invector, 0, VF_CHECK_UNINITIALIZED_THIS); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_0); } // vf_opcode_aloadx /** * Sets instruction structure for opcode iaload. */ -static inline void -vf_opcode_iaload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_iaload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[I", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_ValidType *type = ctx->m_type->NewType("[I", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_iaload /** * Sets instruction structure for opcode baload. */ -static inline void -vf_opcode_baload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_baload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[B", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_ValidType *type = ctx->m_type->NewType("[B", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_baload /** * Sets instruction structure for opcode caload. */ -static inline void -vf_opcode_caload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_caload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[C", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_ValidType *type = ctx->m_type->NewType("[C", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_caload /** * Sets instruction structure for opcode saload. */ -static inline void -vf_opcode_saload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_saload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[S", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_ValidType *type = ctx->m_type->NewType("[S", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_saload /** * Sets instruction structure for opcode laload. */ -static inline void -vf_opcode_laload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_laload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[J", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_ValidType *type = ctx->m_type->NewType("[J", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); // create out vector - vf_new_out_vector( instr, 2, ctx->m_pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, ctx->m_pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_laload /** * Sets instruction structure for opcode faload. */ -static inline void -vf_opcode_faload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_faload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[F", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_ValidType *type = ctx->m_type->NewType("[F", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_faload /** * Sets instruction structure for opcode daload. */ -static inline void -vf_opcode_daload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_daload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[D", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_ValidType *type = ctx->m_type->NewType("[D", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); // create out vector - vf_new_out_vector( instr, 2, ctx->m_pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_new_out_vector(instr, 2, ctx->m_pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_daload /** * Sets instruction structure for opcode aaload. */ -static inline void -vf_opcode_aaload( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_aaload(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); + vf_new_in_vector(instr, 2, ctx->m_pool); // create type - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); - vf_set_in_vector_check( instr, 0, VF_CHECK_REF_ARRAY ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); + vf_set_in_vector_check(instr, 0, VF_CHECK_REF_ARRAY); + vf_set_in_vector_stack_entry_int(instr, 1); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_type( instr, 0, SM_UP_ARRAY ); + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_type(instr, 0, SM_UP_ARRAY); } // vf_opcode_aaload /** * Sets instruction structure for opcodes istorex. */ -static inline void -vf_opcode_istorex( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_istorex(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_local_var_int( instr, 0, local ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_local_var_int(instr, 0, local); } // vf_opcode_istorex /** * Sets instruction structure for opcodes lstorex. */ -static inline void -vf_opcode_lstorex( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_lstorex(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_long(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_local_var_long( instr, 0, local ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_local_var_long(instr, 0, local); } // vf_opcode_lstorex /** * Sets instruction structure for opcodes fstorex. */ -static inline void -vf_opcode_fstorex( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_fstorex(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_float(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_local_var_float( instr, 0, local ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_local_var_float(instr, 0, local); } // vf_opcode_fstorex /** * Sets instruction structure for opcodes dstorex. */ -static inline void -vf_opcode_dstorex( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dstorex(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_double(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_local_var_double( instr, 0, local ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_local_var_double(instr, 0, local); } // vf_opcode_dstorex /** * Sets instruction structure for opcodes astorex. */ -static inline void -vf_opcode_astorex( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_astorex(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); - vf_set_vector_check( instr->m_invector, 0, VF_CHECK_UNINITIALIZED_THIS ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); + vf_set_vector_check(instr->m_invector, 0, VF_CHECK_UNINITIALIZED_THIS); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_local_var_type( instr, 0, SM_COPY_0, local ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_local_var_type(instr, 0, SM_COPY_0, local); } // vf_opcode_astorex /** * Sets instruction structure for opcode iastore. */ -static inline void -vf_opcode_iastore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_iastore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, ctx->m_pool ); + vf_new_in_vector(instr, 3, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[I", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_int( instr, 2 ); + vf_ValidType *type = ctx->m_type->NewType("[I", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_int(instr, 2); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); } // vf_opcode_iastore /** * Sets instruction structure for opcode bastore. */ -static inline void -vf_opcode_bastore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_bastore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, ctx->m_pool ); + vf_new_in_vector(instr, 3, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[B", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_int( instr, 2 ); + vf_ValidType *type = ctx->m_type->NewType("[B", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_int(instr, 2); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); } // vf_opcode_bastore /** * Sets instruction structure for opcode castore. */ -static inline void -vf_opcode_castore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_castore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, ctx->m_pool ); + vf_new_in_vector(instr, 3, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[C", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_int( instr, 2 ); + vf_ValidType *type = ctx->m_type->NewType("[C", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_int(instr, 2); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); } // vf_opcode_castore /** * Sets instruction structure for opcode sastore. */ -static inline void -vf_opcode_sastore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_sastore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, ctx->m_pool ); + vf_new_in_vector(instr, 3, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[S", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_int( instr, 2 ); + vf_ValidType *type = ctx->m_type->NewType("[S", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_int(instr, 2); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); } // vf_opcode_sastore /** * Sets instruction structure for opcode lastore. */ -static inline void -vf_opcode_lastore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_lastore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -4 ); + vf_set_stack_modifier(instr, -4); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, ctx->m_pool ); + vf_new_in_vector(instr, 4, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[J", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_long( instr, 2 ); + vf_ValidType *type = ctx->m_type->NewType("[J", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_long(instr, 2); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); } // vf_opcode_lastore /** * Sets instruction structure for opcode fastore. */ -static inline void -vf_opcode_fastore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_fastore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, ctx->m_pool ); + vf_new_in_vector(instr, 3, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[F", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_float( instr, 2 ); + vf_ValidType *type = ctx->m_type->NewType("[F", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_float(instr, 2); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); } // vf_opcode_fastore /** * Sets instruction structure for opcode dastore. */ -static inline void -vf_opcode_dastore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_dastore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -4 ); + vf_set_stack_modifier(instr, -4); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, ctx->m_pool ); + vf_new_in_vector(instr, 4, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "[D", 2 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_double( instr, 2 ); + vf_ValidType *type = ctx->m_type->NewType("[D", 2); + vf_set_in_vector_stack_entry_ref(instr, 0, type); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_double(instr, 2); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_EQUAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_EQUAL); } // vf_opcode_dastore /** * Sets instruction structure for opcode aastore. */ -static inline void -vf_opcode_aastore( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_aastore(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, ctx->m_pool ); + vf_new_in_vector(instr, 3, ctx->m_pool); // create type - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); - vf_set_in_vector_check( instr, 0, VF_CHECK_REF_ARRAY ); - vf_set_in_vector_stack_entry_int( instr, 1 ); - vf_set_in_vector_stack_entry_ref( instr, 2, NULL ); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); + vf_set_in_vector_check(instr, 0, VF_CHECK_REF_ARRAY); + vf_set_in_vector_stack_entry_int(instr, 1); + vf_set_in_vector_stack_entry_ref(instr, 2, NULL); } // vf_opcode_aastore /** * Sets instruction structure for opcode pop. */ -static inline void -vf_opcode_pop( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_pop(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_word( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_word(instr, 0); } // vf_opcode_pop /** * Sets instruction structure for opcode pop2. */ -static inline void -vf_opcode_pop2( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_pop2(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_word2( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_word2(instr, 0); } // vf_opcode_pop2 /** * Sets instruction structure for opcode dup. */ -static inline void -vf_opcode_dup( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dup(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_word( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_word(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_0 ); - vf_set_out_vector_type( instr, 1, SM_COPY_0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_0); + vf_set_out_vector_type(instr, 1, SM_COPY_0); } // vf_opcode_dup /** * Sets instruction structure for opcode dup_x1. */ -static inline void -vf_opcode_dup_x1( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dup_x1(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_word( instr, 0 ); - vf_set_in_vector_stack_entry_word( instr, 1 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_word(instr, 0); + vf_set_in_vector_stack_entry_word(instr, 1); // create out vector - vf_new_out_vector( instr, 3, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_1 ); - vf_set_out_vector_type( instr, 1, SM_COPY_0 ); - vf_set_out_vector_type( instr, 2, SM_COPY_1 ); + vf_new_out_vector(instr, 3, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_1); + vf_set_out_vector_type(instr, 1, SM_COPY_0); + vf_set_out_vector_type(instr, 2, SM_COPY_1); } // vf_opcode_dup_x1 /** * Sets instruction structure for opcode dup_x2. */ -static inline void -vf_opcode_dup_x2( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dup_x2(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, pool ); - vf_set_in_vector_stack_entry_word2( instr, 0 ); - vf_set_in_vector_stack_entry_word( instr, 2 ); + vf_new_in_vector(instr, 3, pool); + vf_set_in_vector_stack_entry_word2(instr, 0); + vf_set_in_vector_stack_entry_word(instr, 2); // create out vector - vf_new_out_vector( instr, 4, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_2 ); - vf_set_out_vector_type( instr, 1, SM_COPY_0 ); - vf_set_out_vector_type( instr, 2, SM_COPY_1 ); - vf_set_out_vector_type( instr, 3, SM_COPY_2 ); + vf_new_out_vector(instr, 4, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_2); + vf_set_out_vector_type(instr, 1, SM_COPY_0); + vf_set_out_vector_type(instr, 2, SM_COPY_1); + vf_set_out_vector_type(instr, 3, SM_COPY_2); } // vf_opcode_dup_x2 /** * Sets instruction structure for opcode dup2. */ -static inline void -vf_opcode_dup2( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dup2(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 2 ); + vf_set_stack_modifier(instr, 2); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_word2( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_word2(instr, 0); // create out vector - vf_new_out_vector( instr, 4, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_0 ); - vf_set_out_vector_type( instr, 1, SM_COPY_1 ); - vf_set_out_vector_type( instr, 2, SM_COPY_0 ); - vf_set_out_vector_type( instr, 3, SM_COPY_1 ); + vf_new_out_vector(instr, 4, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_0); + vf_set_out_vector_type(instr, 1, SM_COPY_1); + vf_set_out_vector_type(instr, 2, SM_COPY_0); + vf_set_out_vector_type(instr, 3, SM_COPY_1); } // vf_opcode_dup2 /** * Sets instruction structure for opcode dup2_x1. */ -static inline void -vf_opcode_dup2_x1( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dup2_x1(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 2 ); + vf_set_stack_modifier(instr, 2); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, pool ); - vf_set_in_vector_stack_entry_word( instr, 0 ); - vf_set_in_vector_stack_entry_word2( instr, 1 ); + vf_new_in_vector(instr, 3, pool); + vf_set_in_vector_stack_entry_word(instr, 0); + vf_set_in_vector_stack_entry_word2(instr, 1); // create out vector - vf_new_out_vector( instr, 5, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_1 ); - vf_set_out_vector_type( instr, 1, SM_COPY_2 ); - vf_set_out_vector_type( instr, 2, SM_COPY_0 ); - vf_set_out_vector_type( instr, 3, SM_COPY_1 ); - vf_set_out_vector_type( instr, 4, SM_COPY_2 ); + vf_new_out_vector(instr, 5, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_1); + vf_set_out_vector_type(instr, 1, SM_COPY_2); + vf_set_out_vector_type(instr, 2, SM_COPY_0); + vf_set_out_vector_type(instr, 3, SM_COPY_1); + vf_set_out_vector_type(instr, 4, SM_COPY_2); } // vf_opcode_dup2_x1 /** * Sets instruction structure for opcode dup2_x2. */ -static inline void -vf_opcode_dup2_x2( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dup2_x2(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 2 ); + vf_set_stack_modifier(instr, 2); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, pool ); - vf_set_in_vector_stack_entry_word2( instr, 0 ); - vf_set_in_vector_stack_entry_word2( instr, 2 ); + vf_new_in_vector(instr, 4, pool); + vf_set_in_vector_stack_entry_word2(instr, 0); + vf_set_in_vector_stack_entry_word2(instr, 2); // create out vector - vf_new_out_vector( instr, 6, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_2 ); - vf_set_out_vector_type( instr, 1, SM_COPY_3 ); - vf_set_out_vector_type( instr, 2, SM_COPY_0 ); - vf_set_out_vector_type( instr, 3, SM_COPY_1 ); - vf_set_out_vector_type( instr, 4, SM_COPY_2 ); - vf_set_out_vector_type( instr, 5, SM_COPY_3 ); + vf_new_out_vector(instr, 6, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_2); + vf_set_out_vector_type(instr, 1, SM_COPY_3); + vf_set_out_vector_type(instr, 2, SM_COPY_0); + vf_set_out_vector_type(instr, 3, SM_COPY_1); + vf_set_out_vector_type(instr, 4, SM_COPY_2); + vf_set_out_vector_type(instr, 5, SM_COPY_3); } // vf_opcode_dup2_x2 /** * Sets instruction structure for opcode swap. */ -static inline void -vf_opcode_swap( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_swap(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_word( instr, 0 ); - vf_set_in_vector_stack_entry_word( instr, 1 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_word(instr, 0); + vf_set_in_vector_stack_entry_word(instr, 1); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_type( instr, 0, SM_COPY_1 ); - vf_set_out_vector_type( instr, 1, SM_COPY_0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_type(instr, 0, SM_COPY_1); + vf_set_out_vector_type(instr, 1, SM_COPY_0); } // vf_opcode_swap /** * Sets instruction structure for opcode iadd. */ -static inline void -vf_opcode_iadd( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_iadd(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_int(instr, 0); + vf_set_in_vector_stack_entry_int(instr, 1); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_iadd /** * Sets instruction structure for opcode ladd. */ -static inline void -vf_opcode_ladd( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_ladd(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); - vf_set_in_vector_stack_entry_long( instr, 2 ); + vf_new_in_vector(instr, 4, pool); + vf_set_in_vector_stack_entry_long(instr, 0); + vf_set_in_vector_stack_entry_long(instr, 2); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_ladd /** * Sets instruction structure for opcode fadd. */ -static inline void -vf_opcode_fadd( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_fadd(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); - vf_set_in_vector_stack_entry_float( instr, 1 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_float(instr, 0); + vf_set_in_vector_stack_entry_float(instr, 1); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_fadd /** * Sets instruction structure for opcode dadd. */ -static inline void -vf_opcode_dadd( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dadd(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); - vf_set_in_vector_stack_entry_double( instr, 2 ); + vf_new_in_vector(instr, 4, pool); + vf_set_in_vector_stack_entry_double(instr, 0); + vf_set_in_vector_stack_entry_double(instr, 2); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_dadd /** * Sets instruction structure for opcode ineg. */ -static inline void -vf_opcode_ineg( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_ineg(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_ineg /** * Sets instruction structure for opcode lneg. */ -static inline void -vf_opcode_lneg( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_lneg(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_long(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_lneg /** * Sets instruction structure for opcode fneg. */ -static inline void -vf_opcode_fneg( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_fneg(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_float(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_fneg /** * Sets instruction structure for opcode dneg. */ -static inline void -vf_opcode_dneg( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dneg(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_double(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_dneg /** * Sets instruction structure for bit operation opcodes. */ -static inline void -vf_opcode_ibit( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_ibit(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_int(instr, 0); + vf_set_in_vector_stack_entry_int(instr, 1); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_ibit /** * Sets instruction structure for opcodes lshx. */ -static inline void -vf_opcode_lshx( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_lshx(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 3 ); + vf_set_min_stack(instr, 3); // create in vector - vf_new_in_vector( instr, 3, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); - vf_set_in_vector_stack_entry_int( instr, 2 ); + vf_new_in_vector(instr, 3, pool); + vf_set_in_vector_stack_entry_long(instr, 0); + vf_set_in_vector_stack_entry_int(instr, 2); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_lshx /** * Sets instruction structure for opcode land. */ -static inline void -vf_opcode_land( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_land(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); - vf_set_in_vector_stack_entry_long( instr, 2 ); + vf_new_in_vector(instr, 4, pool); + vf_set_in_vector_stack_entry_long(instr, 0); + vf_set_in_vector_stack_entry_long(instr, 2); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_land /** * Sets instruction structure for opcode iinc. */ -static inline void -vf_opcode_iinc( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_iinc(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_local_var_int( instr, 0, local ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_local_var_int(instr, 0, local); } // vf_opcode_iinc /** * Sets instruction structure for opcode i2l. */ -static inline void -vf_opcode_i2l( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_i2l(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_i2l /** * Sets instruction structure for opcode i2f. */ -static inline void -vf_opcode_i2f( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_i2f(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_i2f /** * Sets instruction structure for opcode i2d. */ -static inline void -vf_opcode_i2d( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_i2d(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_i2d /** * Sets instruction structure for opcode l2i. */ -static inline void -vf_opcode_l2i( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_l2i(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_long(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_l2i /** * Sets instruction structure for opcode l2f. */ -static inline void -vf_opcode_l2f( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_l2f(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_long(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_l2f /** * Sets instruction structure for opcode l2d. */ -static inline void -vf_opcode_l2d( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_l2d(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_long(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_l2d /** * Sets instruction structure for opcode f2i. */ -static inline void -vf_opcode_f2i( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_f2i(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_float(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_f2i /** * Sets instruction structure for opcode f2l. */ -static inline void -vf_opcode_f2l( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_f2l(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_float(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_f2l /** * Sets instruction structure for opcode f2d. */ -static inline void -vf_opcode_f2d( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_f2d(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_float(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_double( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_double(instr, 0); } // vf_opcode_f2d /** * Sets instruction structure for opcode d2i. */ -static inline void -vf_opcode_d2i( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_d2i(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_double(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_d2i /** * Sets instruction structure for opcode d2l. */ -static inline void -vf_opcode_d2l( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_d2l(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_double(instr, 0); // create out vector - vf_new_out_vector( instr, 2, pool ); - vf_set_out_vector_stack_entry_long( instr, 0 ); + vf_new_out_vector(instr, 2, pool); + vf_set_out_vector_stack_entry_long(instr, 0); } // vf_opcode_d2l /** * Sets instruction structure for opcode d2f. */ -static inline void -vf_opcode_d2f( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_d2f(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_double(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_float( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_float(instr, 0); } // vf_opcode_d2f /** * Sets instruction structure for opcode i2b. */ -static inline void -vf_opcode_i2b( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_i2b(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_i2b /** * Sets instruction structure for opcode lcmp. */ -static inline void -vf_opcode_lcmp( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_lcmp(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); - vf_set_in_vector_stack_entry_long( instr, 2 ); + vf_new_in_vector(instr, 4, pool); + vf_set_in_vector_stack_entry_long(instr, 0); + vf_set_in_vector_stack_entry_long(instr, 2); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_lcmp /** * Sets instruction structure for opcodes fcmpx. */ -static inline void -vf_opcode_fcmpx( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_fcmpx(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); - vf_set_in_vector_stack_entry_float( instr, 1 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_float(instr, 0); + vf_set_in_vector_stack_entry_float(instr, 1); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_fcmpx /** * Sets instruction structure for opcodes dcmpx. */ -static inline void -vf_opcode_dcmpx( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_dcmpx(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -3 ); + vf_set_stack_modifier(instr, -3); // set minimal stack for instruction - vf_set_min_stack( instr, 4 ); + vf_set_min_stack(instr, 4); // create in vector - vf_new_in_vector( instr, 4, pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); - vf_set_in_vector_stack_entry_double( instr, 2 ); + vf_new_in_vector(instr, 4, pool); + vf_set_in_vector_stack_entry_double(instr, 0); + vf_set_in_vector_stack_entry_double(instr, 2); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_dcmpx /** * Sets instruction structure for opcode ifeq. */ -static inline void -vf_opcode_ifeq( vf_Instr *instr, // code instruction - vf_BCode *icode1, // first branch instruction - vf_BCode *icode2, // second branch instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_ifeq(vf_Instr *instr, // code instruction + vf_BCode *icode1, // first branch instruction + vf_BCode *icode2, // second branch instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // set begin of basic block for branch instruction icode1->m_is_bb_start = true; // set begin of basic block for branch instruction icode2->m_is_bb_start = true; // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); } // vf_opcode_ifeq /** * Sets instruction structure for opcode if_icmpeq. */ -static inline void -vf_opcode_if_icmpeq( vf_Instr *instr, // code instruction - vf_BCode *icode1, // first branch instruction - vf_BCode *icode2, // second branch instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_if_icmpeq(vf_Instr *instr, // code instruction + vf_BCode *icode1, // first branch instruction + vf_BCode *icode2, // second branch instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // set begin of basic block for branch instruction icode1->m_is_bb_start = true; // set begin of basic block for branch instruction icode2->m_is_bb_start = true; // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); - vf_set_in_vector_stack_entry_int( instr, 1 ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_int(instr, 0); + vf_set_in_vector_stack_entry_int(instr, 1); } // vf_opcode_if_icmpeq /** * Sets instruction structure for opcode if_acmpeq. */ -static inline void -vf_opcode_if_acmpeq( vf_Instr *instr, // code instruction - vf_BCode *icode1, // first branch instruction - vf_BCode *icode2, // second branch instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_if_acmpeq(vf_Instr *instr, // code instruction + vf_BCode *icode1, // first branch instruction + vf_BCode *icode2, // second branch instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -2 ); + vf_set_stack_modifier(instr, -2); // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // set begin of basic block for branch instruction icode1->m_is_bb_start = true; // set begin of basic block for branch instruction icode2->m_is_bb_start = true; // create in vector - vf_new_in_vector( instr, 2, pool ); - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); - vf_set_in_vector_stack_entry_ref( instr, 1, NULL ); + vf_new_in_vector(instr, 2, pool); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); + vf_set_in_vector_stack_entry_ref(instr, 1, NULL); } // vf_opcode_if_acmpeq /** * Sets instruction structure for opcode switch. */ -static inline void -vf_opcode_switch( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_switch(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_int(instr, 0); } // vf_opcode_switch /** * Sets in vectors for return instruction. */ -static inline void -vf_opcode_return( vf_Instr *instr, // a return instruction - unsigned short next_pc, // a start of the next instruction - vf_Context *ctx ) // verification context +static inline void vf_opcode_return(vf_Instr *instr, // a return instruction + unsigned short next_pc, // a start of the next instruction + vf_Context *ctx) // verification context { // set instruction flag - vf_set_instr_type( instr, VF_INSTR_RETURN ); + vf_set_instr_type(instr, VF_INSTR_RETURN); // create and set edge branch to exit - vf_set_basic_block_flag( next_pc, ctx ); + vf_set_basic_block_flag(next_pc, ctx); } // vf_opcode_return /** * Sets instruction structure for opcode ireturn. */ -static inline void -vf_opcode_ireturn( vf_Instr *instr, // a return instruction - unsigned short next_pc, // a start of the next instruction - vf_Context *ctx ) // verification context +static inline void vf_opcode_ireturn(vf_Instr *instr, // a return instruction + unsigned short next_pc, // a start of the next instruction + vf_Context *ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, ctx->m_pool); + vf_set_in_vector_stack_entry_int(instr, 0); // set flag and make checks - vf_opcode_return( instr, next_pc, ctx ); + vf_opcode_return(instr, next_pc, ctx); } // vf_opcode_ireturn /** * Sets instruction structure for opcode lreturn. */ -static inline void -vf_opcode_lreturn( vf_Instr *instr, // a return instruction - unsigned short next_pc, // a start of the next instruction - vf_Context *ctx ) // verification context +static inline void vf_opcode_lreturn(vf_Instr *instr, // a return instruction + unsigned short next_pc, // a start of the next instruction + vf_Context *ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); - vf_set_in_vector_stack_entry_long( instr, 0 ); + vf_new_in_vector(instr, 2, ctx->m_pool); + vf_set_in_vector_stack_entry_long(instr, 0); // set flag and make checks - vf_opcode_return( instr, next_pc, ctx ); + vf_opcode_return(instr, next_pc, ctx); } // vf_opcode_lreturn /** * Sets instruction structure for opcode freturn. */ -static inline void -vf_opcode_freturn( vf_Instr *instr, // a return instruction - unsigned short next_pc, // a start of the next instruction - vf_Context *ctx ) // verification context +static inline void vf_opcode_freturn(vf_Instr *instr, // a return instruction + unsigned short next_pc, // a start of the next instruction + vf_Context *ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); - vf_set_in_vector_stack_entry_float( instr, 0 ); + vf_new_in_vector(instr, 1, ctx->m_pool); + vf_set_in_vector_stack_entry_float(instr, 0); // set flag and make checks - vf_opcode_return( instr, next_pc, ctx ); + vf_opcode_return(instr, next_pc, ctx); } // vf_opcode_freturn /** * Sets instruction structure for opcode dreturn. */ -static inline void -vf_opcode_dreturn( vf_Instr *instr, // a return instruction - unsigned short next_pc, // a start of the next instruction - vf_Context *ctx ) // verification context +static inline void vf_opcode_dreturn(vf_Instr *instr, // a return instruction + unsigned short next_pc, // a start of the next instruction + vf_Context *ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 2 ); + vf_set_min_stack(instr, 2); // create in vector - vf_new_in_vector( instr, 2, ctx->m_pool ); - vf_set_in_vector_stack_entry_double( instr, 0 ); + vf_new_in_vector(instr, 2, ctx->m_pool); + vf_set_in_vector_stack_entry_double(instr, 0); // set flag and make checks - vf_opcode_return( instr, next_pc, ctx ); + vf_opcode_return(instr, next_pc, ctx); } // vf_opcode_dreturn /** * Sets instruction structure for opcode areturn. */ -static inline void -vf_opcode_areturn( vf_Instr *instr, // a return instruction - unsigned short next_pc, // a start of the next instruction - vf_Context *ctx ) // verification context +static inline void vf_opcode_areturn(vf_Instr *instr, // a return instruction + unsigned short next_pc, // a start of the next instruction + vf_Context *ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); - vf_set_in_vector_stack_entry_ref( instr, 0, - ( ctx->m_method_outlen ) ? ctx-> - m_method_outvector->m_vtype : 0 ); + vf_new_in_vector(instr, 1, ctx->m_pool); + vf_set_in_vector_stack_entry_ref(instr, 0, + (ctx->m_method_outlen) ? ctx-> + m_method_outvector->m_vtype : 0); // set flag and make checks - vf_opcode_return( instr, next_pc, ctx ); + vf_opcode_return(instr, next_pc, ctx); } // vf_opcode_areturn /** * Sets instruction structure for opcode getstatic. */ -static inline vf_Result -vf_opcode_getstatic( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_getstatic(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = - vf_parse_const_pool( OPCODE_GETSTATIC, cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(OPCODE_GETSTATIC, cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // set stack modifier for instruction - vf_set_stack_modifier( instr, cp_parse.field.f_vlen ); + vf_set_stack_modifier(instr, cp_parse.field.f_vlen); // set stack out vector instr->m_outvector = cp_parse.field.f_vector; - instr->m_outlen = ( unsigned short )cp_parse.field.f_vlen; - return VER_OK; + instr->m_outlen = (unsigned short) cp_parse.field.f_vlen; + return VF_OK; } // vf_opcode_getstatic /** * Sets instruction structure for opcode putstatic. */ -static inline vf_Result -vf_opcode_putstatic( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_putstatic(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = - vf_parse_const_pool( OPCODE_PUTSTATIC, cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(OPCODE_PUTSTATIC, cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // set stack modifier for instruction - vf_set_stack_modifier( instr, -( int )cp_parse.field.f_vlen ); + vf_set_stack_modifier(instr, -(int) cp_parse.field.f_vlen); // set minimal stack for instruction - vf_set_min_stack( instr, cp_parse.field.f_vlen ); + vf_set_min_stack(instr, cp_parse.field.f_vlen); // set stack out vector instr->m_invector = cp_parse.field.f_vector; - instr->m_inlen = ( unsigned short )cp_parse.field.f_vlen; + instr->m_inlen = (unsigned short) cp_parse.field.f_vlen; // set assign check - vf_set_in_vector_check( instr, instr->m_inlen - 1, VF_CHECK_ASSIGN ); - return VER_OK; + vf_set_in_vector_check(instr, instr->m_inlen - 1, VF_CHECK_ASSIGN); + return VF_OK; } // vf_opcode_putstatic /** * Sets instruction structure for opcode getfield. */ -static inline vf_Result -vf_opcode_getfield( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_getfield(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = vf_parse_const_pool( OPCODE_GETFIELD, cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(OPCODE_GETFIELD, cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // set stack modifier for instruction, remove double this reference - vf_set_stack_modifier( instr, cp_parse.field.f_vlen - 2 ); + vf_set_stack_modifier(instr, cp_parse.field.f_vlen - 2); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // set stack in vector instr->m_invector = cp_parse.field.f_vector; instr->m_inlen = 1; // set field access check - vf_set_in_vector_check( instr, 0, VF_CHECK_ACCESS_FIELD ); - vf_set_in_vector_check_index( instr, 0, cp_index ); + vf_set_in_vector_check(instr, 0, VF_CHECK_ACCESS_FIELD); + vf_set_in_vector_check_index(instr, 0, cp_index); // set stack out vector, skip this reference instr->m_outvector = cp_parse.field.f_vector + 1; - instr->m_outlen = ( unsigned short )cp_parse.field.f_vlen - 1; - return VER_OK; + instr->m_outlen = (unsigned short) cp_parse.field.f_vlen - 1; + return VF_OK; } // vf_opcode_getfield /** * Sets instruction structure for opcode putfield. */ -static inline vf_Result -vf_opcode_putfield( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_putfield(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = vf_parse_const_pool( OPCODE_PUTFIELD, cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(OPCODE_PUTFIELD, cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // set stack modifier for instruction - vf_set_stack_modifier( instr, -cp_parse.field.f_vlen ); + vf_set_stack_modifier(instr, -cp_parse.field.f_vlen); // set minimal stack for instruction - vf_set_min_stack( instr, cp_parse.field.f_vlen ); + vf_set_min_stack(instr, cp_parse.field.f_vlen); // set stack in vector instr->m_invector = cp_parse.field.f_vector; - instr->m_inlen = ( unsigned short )cp_parse.field.f_vlen; + instr->m_inlen = (unsigned short) cp_parse.field.f_vlen; // set assign check - vf_set_in_vector_check( instr, instr->m_inlen - 1, VF_CHECK_ASSIGN ); + vf_set_in_vector_check(instr, instr->m_inlen - 1, VF_CHECK_ASSIGN); // set field access check - vf_set_in_vector_check( instr, 0, VF_CHECK_ACCESS_FIELD ); - vf_set_in_vector_check_index( instr, 0, cp_index ); - return VER_OK; + vf_set_in_vector_check(instr, 0, VF_CHECK_ACCESS_FIELD); + vf_set_in_vector_check_index(instr, 0, cp_index); + return VF_OK; } // vf_opcode_putfield /** * Sets instruction structure for invokes opcodes. */ -static inline vf_Result -vf_opcode_invoke( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_invoke(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = - vf_parse_const_pool( *( instr->m_addr ), cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(*(instr->m_addr), cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // check method name - if( cp_parse.method.m_name[0] == '<' ) { - VF_REPORT( ctx, "Must call initializers using invokespecial" ); - return VER_ErrorConstantPool; + if (cp_parse.method.m_name[0] == '<') { + VF_REPORT(ctx, "Must call initializers using invokespecial"); + return VF_ErrorConstantPool; } // check number of arguments - if( cp_parse.method.m_inlen > 255 ) { - VF_REPORT( ctx, "The number of method parameters is limited to 255" ); - return VER_ErrorInstruction; + if (cp_parse.method.m_inlen > 255) { + VF_REPORT(ctx, "The number of method parameters is limited to 255"); + return VF_ErrorInstruction; } // set stack modifier for instruction - vf_set_stack_modifier( instr, - cp_parse.method.m_outlen - - cp_parse.method.m_inlen ); + vf_set_stack_modifier(instr, + cp_parse.method.m_outlen - cp_parse.method.m_inlen); // set minimal stack for instruction - vf_set_min_stack( instr, cp_parse.method.m_inlen ); + vf_set_min_stack(instr, cp_parse.method.m_inlen); // set stack in vector instr->m_invector = cp_parse.method.m_invector; - instr->m_inlen = ( unsigned short )cp_parse.method.m_inlen; + instr->m_inlen = (unsigned short) cp_parse.method.m_inlen; // set stack out vector instr->m_outvector = cp_parse.method.m_outvector; - instr->m_outlen = ( unsigned short )cp_parse.method.m_outlen; + instr->m_outlen = (unsigned short) cp_parse.method.m_outlen; // set method access check for opcode invokevirtual - if( ( *instr->m_addr ) == OPCODE_INVOKEVIRTUAL ) { - vf_set_in_vector_check( instr, 0, VF_CHECK_ACCESS_METHOD ); - vf_set_in_vector_check_index( instr, 0, cp_index ); + if ((*instr->m_addr) == OPCODE_INVOKEVIRTUAL) { + vf_set_in_vector_check(instr, 0, VF_CHECK_ACCESS_METHOD); + vf_set_in_vector_check_index(instr, 0, cp_index); } - return VER_OK; + return VF_OK; } // vf_opcode_invoke /** * Sets instruction structure for invokes opcodes. */ -static inline vf_Result -vf_opcode_invokespecial( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_invokespecial(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = - vf_parse_const_pool( *( instr->m_addr ), cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(*(instr->m_addr), cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // check number of arguments - if( cp_parse.method.m_inlen > 255 ) { - VF_REPORT( ctx, "The number of method parameters is limited to 255" ); - return VER_ErrorInstruction; + if (cp_parse.method.m_inlen > 255) { + VF_REPORT(ctx, "The number of method parameters is limited to 255"); + return VF_ErrorInstruction; } // set stack modifier for instruction - vf_set_stack_modifier( instr, - cp_parse.method.m_outlen - - cp_parse.method.m_inlen ); + vf_set_stack_modifier(instr, + cp_parse.method.m_outlen - cp_parse.method.m_inlen); // set minimal stack for instruction - vf_set_min_stack( instr, cp_parse.method.m_inlen ); + vf_set_min_stack(instr, cp_parse.method.m_inlen); // set stack in vector instr->m_invector = cp_parse.method.m_invector; - instr->m_inlen = ( unsigned short )cp_parse.method.m_inlen; + instr->m_inlen = (unsigned short) cp_parse.method.m_inlen; // set stack out vector instr->m_outvector = cp_parse.method.m_outvector; - instr->m_outlen = ( unsigned short )cp_parse.method.m_outlen; + instr->m_outlen = (unsigned short) cp_parse.method.m_outlen; // set method check for opcode invokespecial - if( !strcmp( cp_parse.method.m_name, "" ) ) { + if (!strcmp(cp_parse.method.m_name, "")) { // set uninitialized check - vf_set_in_vector_type( instr, 0, SM_UNINITIALIZED ); - vf_set_in_vector_check( instr, 0, VF_CHECK_DIRECT_SUPER ); + vf_set_in_vector_type(instr, 0, SM_UNINITIALIZED); + vf_set_in_vector_check(instr, 0, VF_CHECK_DIRECT_SUPER); } else { // set method access check - vf_set_in_vector_check( instr, 0, VF_CHECK_INVOKESPECIAL ); + vf_set_in_vector_check(instr, 0, VF_CHECK_INVOKESPECIAL); } - vf_set_in_vector_check_index( instr, 0, cp_index ); - return VER_OK; + vf_set_in_vector_check_index(instr, 0, cp_index); + return VF_OK; } // vf_opcode_invokespecial /** * Sets instruction structure for opcode new. */ -static inline vf_Result -vf_opcode_new( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - unsigned opcode_new, // number of opcode new - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_new(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + unsigned opcode_new, // number of opcode new + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = vf_parse_const_pool( OPCODE_NEW, cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(OPCODE_NEW, cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // check created reference - assert( cp_parse.field.f_vector->m_vtype->number == 1 ); - if( cp_parse.field.f_vector->m_vtype->string[0][0] != 'L' ) { - VF_REPORT( ctx, "Illegal creation of array" ); - return VER_ErrorInstruction; + assert(cp_parse.field.f_vector->m_vtype->number == 1); + if (cp_parse.field.f_vector->m_vtype->string[0][0] != 'L') { + VF_REPORT(ctx, "Illegal creation of array"); + return VF_ErrorInstruction; } // set stack out vector instr->m_outvector = cp_parse.field.f_vector; - instr->m_outlen = ( unsigned short )cp_parse.field.f_vlen; + instr->m_outlen = (unsigned short) cp_parse.field.f_vlen; // set uninitialized reference - vf_set_out_vector_type( instr, 0, SM_UNINITIALIZED ); + vf_set_out_vector_type(instr, 0, SM_UNINITIALIZED); // set opcode program counter - vf_set_out_vector_opcode_new( instr, 0, opcode_new ); - return VER_OK; + vf_set_out_vector_opcode_new(instr, 0, opcode_new); + return VF_OK; } // vf_opcode_new /** * Sets instruction structure for opcode newarray. */ -static inline vf_Result -vf_opcode_newarray( vf_Instr *instr, // code instruction - unsigned char type, // array element type - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_newarray(vf_Instr *instr, // code instruction + unsigned char type, // array element type + vf_Context *ctx) // verification context { vf_ValidType *vtype; - switch ( type ) { + switch (type) { case 4: // boolean case 8: // byte - vtype = ctx->m_type->NewType( "[B", 2 ); + vtype = ctx->m_type->NewType("[B", 2); break; case 5: // char - vtype = ctx->m_type->NewType( "[C", 2 ); + vtype = ctx->m_type->NewType("[C", 2); break; case 9: // short - vtype = ctx->m_type->NewType( "[S", 2 ); + vtype = ctx->m_type->NewType("[S", 2); break; case 10: // int - vtype = ctx->m_type->NewType( "[I", 2 ); + vtype = ctx->m_type->NewType("[I", 2); break; case 6: // float - vtype = ctx->m_type->NewType( "[F", 2 ); + vtype = ctx->m_type->NewType("[F", 2); break; case 7: // double - vtype = ctx->m_type->NewType( "[D", 2 ); + vtype = ctx->m_type->NewType("[D", 2); break; case 11: // long - vtype = ctx->m_type->NewType( "[J", 2 ); + vtype = ctx->m_type->NewType("[J", 2); break; default: - VF_REPORT( ctx, "Incorrect type in newarray instruction" ); - return VER_ErrorInstruction; + VF_REPORT(ctx, "Incorrect type in newarray instruction"); + return VF_ErrorInstruction; } // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, ctx->m_pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_ref( instr, 0, vtype ); - return VER_OK; + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_ref(instr, 0, vtype); + return VF_OK; } // vf_opcode_newarray /** * Receives valid type string of array by array element name. */ -static inline const char * -vf_get_class_array_valid_type( const char *element_name, // array element name - size_t name_len, // element name length - unsigned dimension, // dimension of array - size_t * result_len, // pointer to result string length - vf_Pool *pool ) // memory pool +static inline const char *vf_get_class_array_valid_type(const char *element_name, // array element name + size_t name_len, // element name length + unsigned dimension, // dimension of array + size_t * result_len, // pointer to result string length + vf_Pool *pool) // memory pool { size_t len; unsigned index; char *result; // create valid type - if( element_name[0] == '[' ) { + if (element_name[0] == '[') { // copy array class name - if( element_name[name_len - 1] == ';' ) { + if (element_name[name_len - 1] == ';') { // object type array len = name_len + dimension - 1; name_len--; } else { // primitive type array len = name_len + dimension; - switch ( element_name[name_len - 1] ) { + switch (element_name[name_len - 1]) { case 'Z': // set integer array type - result = (char*)vf_palloc( pool, len + 1 ); - for( index = 0; index < dimension; index++ ) { + result = (char *) vf_palloc(pool, len + 1); + for (index = 0; index < dimension; index++) { result[index] = '['; } - memcpy( &result[dimension], element_name, name_len ); + memcpy(&result[dimension], element_name, name_len); result[len - 1] = 'B'; *result_len = len; return result; @@ -3621,20 +3437,20 @@ break; } } - result = (char*)vf_palloc( pool, len + 1 ); - for( index = 0; index < dimension; index++ ) { + result = (char *) vf_palloc(pool, len + 1); + for (index = 0; index < dimension; index++) { result[index] = '['; } - memcpy( &result[dimension], element_name, name_len ); + memcpy(&result[dimension], element_name, name_len); } else { // create class signature len = name_len + dimension + 1; - result = (char*)vf_palloc( pool, len + 1 ); - for( index = 0; index < dimension; index++ ) { + result = (char *) vf_palloc(pool, len + 1); + for (index = 0; index < dimension; index++) { result[index] = '['; } result[dimension] = 'L'; - memcpy( &result[dimension + 1], element_name, name_len ); + memcpy(&result[dimension + 1], element_name, name_len); } *result_len = len; return result; @@ -3643,267 +3459,256 @@ /** * Sets instruction structure for opcode anewarray. */ -static inline vf_Result -vf_opcode_anewarray( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_anewarray(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { // check constant pool for instruction - vf_Result result = vf_parse_const_pool( OPCODE_ANEWARRAY, - cp_index, NULL, ctx ); - if( VER_OK != result ) { + vf_Result result = vf_parse_const_pool(OPCODE_ANEWARRAY, + cp_index, NULL, ctx); + if (VF_OK != result) { return result; } // get array element type name - const char *name = vf_get_cp_class_name( ctx->m_class, cp_index ); - assert( name ); + const char *name = vf_get_cp_class_name(ctx->m_class, cp_index); + assert(name); // create valid type string size_t len; - const char *array = vf_get_class_array_valid_type( name, - strlen( name ), 1, - &len, ctx->m_pool ); + const char *array = vf_get_class_array_valid_type(name, + strlen(name), 1, + &len, ctx->m_pool); // check dimension unsigned short index; - for( index = 0; array[index] == '['; index++ ) { + for (index = 0; array[index] == '['; index++) { continue; } - if( index > 255 ) { - VF_REPORT( ctx, "Array with too many dimensions" ); - return VER_ErrorInstruction; + if (index > 255) { + VF_REPORT(ctx, "Array with too many dimensions"); + return VF_ErrorInstruction; } // create valid type - vf_ValidType *type = ctx->m_type->NewType( array, len ); + vf_ValidType *type = ctx->m_type->NewType(array, len); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); - vf_set_in_vector_stack_entry_int( instr, 0 ); + vf_new_in_vector(instr, 1, ctx->m_pool); + vf_set_in_vector_stack_entry_int(instr, 0); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_ref( instr, 0, type ); - return VER_OK; + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_ref(instr, 0, type); + return VF_OK; } // vf_opcode_anewarray /** * Sets instruction structure for opcode arraylength. */ -static inline void -vf_opcode_arraylength( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_arraylength(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); + vf_new_in_vector(instr, 1, ctx->m_pool); // create type - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); // set check - vf_set_in_vector_check( instr, 0, VF_CHECK_ARRAY ); + vf_set_in_vector_check(instr, 0, VF_CHECK_ARRAY); // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_int(instr, 0); } // vf_opcode_arraylength /** * Sets instruction structure for opcode athrow. */ -static inline void -vf_opcode_athrow( vf_Instr *instr, // code instruction - vf_ContextHandle ctx ) // verification context +static inline void vf_opcode_athrow(vf_Instr *instr, // code instruction + vf_ContextHandle ctx) // verification context { // set instruction flag - vf_set_instr_type( instr, VF_INSTR_THROW ); + vf_set_instr_type(instr, VF_INSTR_THROW); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); + vf_new_in_vector(instr, 1, ctx->m_pool); // create type - vf_ValidType *type = ctx->m_type->NewType( "Ljava/lang/Throwable", 20 ); - vf_set_in_vector_stack_entry_ref( instr, 0, type ); + vf_ValidType *type = ctx->m_type->NewType("Ljava/lang/Throwable", 20); + vf_set_in_vector_stack_entry_ref(instr, 0, type); } // vf_opcode_athrow /** * Sets instruction structure for opcode checkcast. */ -static inline vf_Result -vf_opcode_checkcast( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_checkcast(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { vf_Result result; vf_Parse cp_parse = { 0 }; // check constant pool for instruction - result = - vf_parse_const_pool( OPCODE_CHECKCAST, cp_index, &cp_parse, ctx ); - if( VER_OK != result ) { + result = vf_parse_const_pool(OPCODE_CHECKCAST, cp_index, &cp_parse, ctx); + if (VF_OK != result) { return result; } // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); + vf_new_in_vector(instr, 1, ctx->m_pool); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); // set stack out vector instr->m_outvector = cp_parse.field.f_vector; - instr->m_outlen = ( unsigned short )cp_parse.field.f_vlen; - return VER_OK; + instr->m_outlen = (unsigned short) cp_parse.field.f_vlen; + return VF_OK; } // vf_opcode_checkcast /** * Sets instruction structure for opcode instanceof. */ -static inline vf_Result -vf_opcode_instanceof( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_instanceof(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + vf_Context *ctx) // verification context { // check constant pool for instruction vf_Result result = - vf_parse_const_pool( OPCODE_INSTANCEOF, cp_index, NULL, ctx ); - if( VER_OK != result ) { + vf_parse_const_pool(OPCODE_INSTANCEOF, cp_index, NULL, ctx); + if (VF_OK != result) { return result; } // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, ctx->m_pool ); - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); + vf_new_in_vector(instr, 1, ctx->m_pool); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); // set stack out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_int( instr, 0 ); - return VER_OK; + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_int(instr, 0); + return VF_OK; } // vf_opcode_instanceof /** * Sets instruction structure for opcodes monitorx. */ -static inline void -vf_opcode_monitorx( vf_Instr *instr, // code instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_monitorx(vf_Instr *instr, // code instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); } // vf_opcode_monitorx /** * Sets instruction structure for opcode multianewarray. */ -static inline vf_Result -vf_opcode_multianewarray( vf_Instr *instr, // code instruction - unsigned short cp_index, // constant pool entry index - unsigned char dimensions, // dimension of array - vf_Context *ctx ) // verification context +static inline vf_Result vf_opcode_multianewarray(vf_Instr *instr, // code instruction + unsigned short cp_index, // constant pool entry index + unsigned char dimensions, // dimension of array + vf_Context *ctx) // verification context { // check constant pool for instruction vf_Result result = - vf_parse_const_pool( OPCODE_MULTIANEWARRAY, cp_index, NULL, ctx ); - if( VER_OK != result ) { + vf_parse_const_pool(OPCODE_MULTIANEWARRAY, cp_index, NULL, ctx); + if (VF_OK != result) { return result; } // get array element type name - const char *name = vf_get_cp_class_name( ctx->m_class, cp_index ); - assert( name ); + const char *name = vf_get_cp_class_name(ctx->m_class, cp_index); + assert(name); // get valid type string size_t len; - const char *array = vf_get_class_valid_type( name, - strlen( name ), - &len, ctx->m_pool ); + const char *array = vf_get_class_valid_type(name, + strlen(name), + &len, ctx->m_pool); // check dimension unsigned short index; - for( index = 0; array[index] == '['; index++ ) { + for (index = 0; array[index] == '['; index++) { continue; } - if( index > 255 ) { - VF_REPORT( ctx, "Array with too many dimensions" ); - return VER_ErrorInstruction; + if (index > 255) { + VF_REPORT(ctx, "Array with too many dimensions"); + return VF_ErrorInstruction; } - if( dimensions == 0 || index < dimensions ) { - VF_REPORT( ctx, "Illegal dimension argument" ); - return VER_ErrorInstruction; + if (dimensions == 0 || index < dimensions) { + VF_REPORT(ctx, "Illegal dimension argument"); + return VF_ErrorInstruction; } // create valid type - vf_ValidType *type = ctx->m_type->NewType( array, len ); + vf_ValidType *type = ctx->m_type->NewType(array, len); // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 - dimensions ); + vf_set_stack_modifier(instr, 1 - dimensions); // set minimal stack for instruction - vf_set_min_stack( instr, dimensions ); + vf_set_min_stack(instr, dimensions); // create in vector - vf_new_in_vector( instr, dimensions, ctx->m_pool ); - for( index = 0; index < dimensions; index++ ) { - vf_set_in_vector_stack_entry_int( instr, index ); + vf_new_in_vector(instr, dimensions, ctx->m_pool); + for (index = 0; index < dimensions; index++) { + vf_set_in_vector_stack_entry_int(instr, index); } // create out vector - vf_new_out_vector( instr, 1, ctx->m_pool ); - vf_set_out_vector_stack_entry_ref( instr, 0, type ); - return VER_OK; + vf_new_out_vector(instr, 1, ctx->m_pool); + vf_set_out_vector_stack_entry_ref(instr, 0, type); + return VF_OK; } // vf_opcode_multianewarray /** * Sets instruction structure for opcodes ifxnull. */ -static inline void -vf_opcode_ifxnull( vf_Instr *instr, // code instruction - vf_BCode *icode1, // first branch instruction - vf_BCode *icode2, // second branch instruction - vf_Pool *pool ) // memory pool +static inline void vf_opcode_ifxnull(vf_Instr *instr, // code instruction + vf_BCode *icode1, // first branch instruction + vf_BCode *icode2, // second branch instruction + vf_Pool *pool) // memory pool { // set stack modifier for instruction - vf_set_stack_modifier( instr, -1 ); + vf_set_stack_modifier(instr, -1); // set minimal stack for instruction - vf_set_min_stack( instr, 1 ); + vf_set_min_stack(instr, 1); // set begin of basic block for branch instruction icode1->m_is_bb_start = true; // set begin of basic block for branch instruction icode2->m_is_bb_start = true; // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_in_vector_stack_entry_ref( instr, 0, NULL ); + vf_new_in_vector(instr, 1, pool); + vf_set_in_vector_stack_entry_ref(instr, 0, NULL); } // vf_opcode_ifxnull /** * Sets instruction structure for opcodes jsr and jsr_w. */ -static inline void -vf_opcode_jsr( vf_Instr *instr, // code instruction - unsigned entry_point_pc, // an pc of subroutine entry point - vf_Pool *pool ) // memory pool +static inline void vf_opcode_jsr(vf_Instr *instr, // code instruction + unsigned entry_point_pc, // an pc of subroutine entry point + vf_Pool *pool) // memory pool { // set instruction flag - vf_set_instr_type( instr, VF_INSTR_JSR ); + vf_set_instr_type(instr, VF_INSTR_JSR); // set stack modifier for instruction - vf_set_stack_modifier( instr, 1 ); + vf_set_stack_modifier(instr, 1); // create out vector - vf_new_out_vector( instr, 1, pool ); - vf_set_vector_stack_entry_addr( instr->m_outvector, 0, entry_point_pc ); + vf_new_out_vector(instr, 1, pool); + vf_set_vector_stack_entry_addr(instr->m_outvector, 0, entry_point_pc); } // vf_opcode_jsr /** * Sets instruction structure for opcode ret. */ -static inline void -vf_opcode_ret( vf_Instr *instr, // code instruction - unsigned local, // local variable number - vf_Pool *pool ) // memory pool +static inline void vf_opcode_ret(vf_Instr *instr, // code instruction + unsigned local, // local variable number + vf_Pool *pool) // memory pool { // set instruction flag - vf_set_instr_type( instr, VF_INSTR_RET ); + vf_set_instr_type(instr, VF_INSTR_RET); // create in vector - vf_new_in_vector( instr, 1, pool ); - vf_set_vector_local_var_addr( instr->m_invector, 0, 0, local ); + vf_new_in_vector(instr, 1, pool); + vf_set_vector_local_var_addr(instr->m_invector, 0, 0, local); // create out vector, so the return address value cannot be reused - vf_new_out_vector( instr, 1, pool ); - vf_set_out_vector_local_var_type( instr, 0, SM_TOP, local ); + vf_new_out_vector(instr, 1, pool); + vf_set_out_vector_local_var_type(instr, 0, SM_TOP, local); } // vf_opcode_ret @@ -3911,8 +3716,7 @@ * Parses bytecode, determines code instructions, fills instruction and bytecode * arrays and provides simple verifications. */ -static vf_Result -vf_parse_bytecode( vf_Context *ctx ) +static vf_Result vf_parse_bytecode(vf_Context *ctx) { // get bytecode parameters unsigned len = ctx->m_len; @@ -3927,35 +3731,34 @@ * then bc[len + 4] will be marked with basic block end. */ vf_Pool *pool = ctx->m_pool; - vf_BCode *bc = (vf_BCode*)vf_palloc( pool, ( len + GOTO_W_LEN ) - * sizeof( vf_BCode ) ); + vf_BCode *bc = (vf_BCode *) vf_palloc(pool, (len + GOTO_W_LEN) + * sizeof(vf_BCode)); ctx->m_bc = bc; // first instruction is always begin of basic block bc[0].m_is_bb_start = true; // allocate memory for instructions - ctx->m_instr = - ( vf_InstrHandle )vf_palloc( pool, len * sizeof( vf_Instr ) ); + ctx->m_instr = (vf_InstrHandle) vf_palloc(pool, len * sizeof(vf_Instr)); int offset; unsigned index, count; unsigned short local, const_index; unsigned char u1; - vf_Result result = VER_OK; + vf_Result result = VF_OK; unsigned branches; unsigned ret_num = 0; - vf_Instr *instr = (vf_Instr*)ctx->m_instr; + vf_Instr *instr = (vf_Instr *) ctx->m_instr; // parse bytecode instructions and fill a instruction array - for( index = 0; index < len; instr++ ) { + for (index = 0; index < len; instr++) { instr->m_addr = &bytecode[index]; bc[index].m_instr = instr; - bool wide = ( OPCODE_WIDE == bytecode[index] ); /* 0xc4 */ - if( wide ) { - switch ( bytecode[++index] ) // check the next instruction + bool wide = (OPCODE_WIDE == bytecode[index]); /* 0xc4 */ + if (wide) { + switch (bytecode[++index]) // check the next instruction { case OPCODE_ILOAD: case OPCODE_FLOAD: @@ -3971,21 +3774,21 @@ case OPCODE_IINC: break; default: - VF_REPORT( ctx, - "Instruction wide should be followed " - "by iload, fload, aload, lload, dload, istore, fstore, astore, " - "lstore, dstore, ret or iinc" ); - return VER_ErrorInstruction; + VF_REPORT(ctx, + "Instruction wide should be followed " + "by iload, fload, aload, lload, dload, istore, fstore, astore, " + "lstore, dstore, ret or iinc"); + return VF_ErrorInstruction; } } unsigned prev_index = index; // remember offset of instruction index++; // skip bytecode - switch ( bytecode[prev_index] ) { + switch (bytecode[prev_index]) { case OPCODE_NOP: /* 0x00 */ break; case OPCODE_ACONST_NULL: /* 0x01 */ - vf_opcode_aconst_null( instr, pool ); + vf_opcode_aconst_null(instr, pool); break; case OPCODE_SIPUSH: /* 0x11 + s2 */ index++; // skip parameter (s2) @@ -3998,28 +3801,28 @@ case OPCODE_ICONST_3: /* 0x06 */ case OPCODE_ICONST_4: /* 0x07 */ case OPCODE_ICONST_5: /* 0x08 */ - vf_opcode_iconst_n( instr, pool ); + vf_opcode_iconst_n(instr, pool); break; case OPCODE_LCONST_0: /* 0x09 */ case OPCODE_LCONST_1: /* 0x0a */ - vf_opcode_lconst_n( instr, pool ); + vf_opcode_lconst_n(instr, pool); break; case OPCODE_FCONST_0: /* 0x0b */ case OPCODE_FCONST_1: /* 0x0c */ case OPCODE_FCONST_2: /* 0x0d */ - vf_opcode_fconst_n( instr, pool ); + vf_opcode_fconst_n(instr, pool); break; case OPCODE_DCONST_0: /* 0x0e */ case OPCODE_DCONST_1: /* 0x0f */ - vf_opcode_dconst_n( instr, pool ); + vf_opcode_dconst_n(instr, pool); break; case OPCODE_LDC: /* 0x12 + u1 */ // get constant pool index - const_index = ( unsigned short )bytecode[index]; + const_index = (unsigned short) bytecode[index]; // skip constant pool index (u1) index++; - result = vf_opcode_ldcx( instr, 1, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_ldcx(instr, 1, const_index, ctx); + if (VF_OK != result) { return result; } break; @@ -4027,341 +3830,331 @@ case OPCODE_LDC2_W: /* 0x14 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; result = - vf_opcode_ldcx( instr, bytecode[prev_index] - OPCODE_LDC, - const_index, ctx ); - if( VER_OK != result ) { + vf_opcode_ldcx(instr, bytecode[prev_index] - OPCODE_LDC, + const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_ILOAD: /* 0x15 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_iloadx( instr, local, pool ); + vf_opcode_iloadx(instr, local, pool); break; case OPCODE_LLOAD: /* 0x16 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_lloadx( instr, local, pool ); + vf_opcode_lloadx(instr, local, pool); break; case OPCODE_FLOAD: /* 0x17 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_floadx( instr, local, pool ); + vf_opcode_floadx(instr, local, pool); break; case OPCODE_DLOAD: /* 0x18 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_dloadx( instr, local, pool ); + vf_opcode_dloadx(instr, local, pool); break; case OPCODE_ALOAD: /* 0x19 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_aloadx( instr, local, pool ); + vf_opcode_aloadx(instr, local, pool); break; case OPCODE_ILOAD_0: /* 0x1a */ case OPCODE_ILOAD_1: /* 0x1b */ case OPCODE_ILOAD_2: /* 0x1c */ case OPCODE_ILOAD_3: /* 0x1d */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_ILOAD_0 ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_ILOAD_0); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_iloadx( instr, local, pool ); + vf_opcode_iloadx(instr, local, pool); break; case OPCODE_LLOAD_0: /* 0x1e */ case OPCODE_LLOAD_1: /* 0x1f */ case OPCODE_LLOAD_2: /* 0x20 */ case OPCODE_LLOAD_3: /* 0x21 */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_LLOAD_0 ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_LLOAD_0); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_lloadx( instr, local, pool ); + vf_opcode_lloadx(instr, local, pool); break; case OPCODE_FLOAD_0: /* 0x22 */ case OPCODE_FLOAD_1: /* 0x23 */ case OPCODE_FLOAD_2: /* 0x24 */ case OPCODE_FLOAD_3: /* 0x25 */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_FLOAD_0 ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_FLOAD_0); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_floadx( instr, local, pool ); + vf_opcode_floadx(instr, local, pool); break; case OPCODE_DLOAD_0: /* 0x26 */ case OPCODE_DLOAD_1: /* 0x27 */ case OPCODE_DLOAD_2: /* 0x28 */ case OPCODE_DLOAD_3: /* 0x29 */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_DLOAD_0 ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_DLOAD_0); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_dloadx( instr, local, pool ); + vf_opcode_dloadx(instr, local, pool); break; case OPCODE_ALOAD_0: /* 0x2a */ case OPCODE_ALOAD_1: /* 0x2b */ case OPCODE_ALOAD_2: /* 0x2c */ case OPCODE_ALOAD_3: /* 0x2d */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_ALOAD_0 ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_ALOAD_0); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_aloadx( instr, local, pool ); + vf_opcode_aloadx(instr, local, pool); break; case OPCODE_IALOAD: /* 0x2e */ - vf_opcode_iaload( instr, ctx ); + vf_opcode_iaload(instr, ctx); break; case OPCODE_BALOAD: /* 0x33 */ - vf_opcode_baload( instr, ctx ); + vf_opcode_baload(instr, ctx); break; case OPCODE_CALOAD: /* 0x34 */ - vf_opcode_caload( instr, ctx ); + vf_opcode_caload(instr, ctx); break; case OPCODE_SALOAD: /* 0x35 */ - vf_opcode_saload( instr, ctx ); + vf_opcode_saload(instr, ctx); break; case OPCODE_LALOAD: /* 0x2f */ - vf_opcode_laload( instr, ctx ); + vf_opcode_laload(instr, ctx); break; case OPCODE_FALOAD: /* 0x30 */ - vf_opcode_faload( instr, ctx ); + vf_opcode_faload(instr, ctx); break; case OPCODE_DALOAD: /* 0x31 */ - vf_opcode_daload( instr, ctx ); + vf_opcode_daload(instr, ctx); break; case OPCODE_AALOAD: /* 0x32 */ - vf_opcode_aaload( instr, ctx ); + vf_opcode_aaload(instr, ctx); break; case OPCODE_ISTORE: /* 0x36 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_istorex( instr, local, pool ); + vf_opcode_istorex(instr, local, pool); break; case OPCODE_LSTORE: /* 0x37 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_lstorex( instr, local, pool ); + vf_opcode_lstorex(instr, local, pool); break; case OPCODE_FSTORE: /* 0x38 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_fstorex( instr, local, pool ); + vf_opcode_fstorex(instr, local, pool); break; case OPCODE_DSTORE: /* 0x39 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_dstorex( instr, local, pool ); + vf_opcode_dstorex(instr, local, pool); break; case OPCODE_ASTORE: /* 0x3a + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_astorex( instr, local, pool ); + vf_opcode_astorex(instr, local, pool); break; case OPCODE_ISTORE_0: /* 0x3b */ case OPCODE_ISTORE_1: /* 0x3c */ case OPCODE_ISTORE_2: /* 0x3d */ case OPCODE_ISTORE_3: /* 0x3e */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_ISTORE_0 ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_ISTORE_0); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_istorex( instr, local, pool ); + vf_opcode_istorex(instr, local, pool); break; case OPCODE_LSTORE_0: /* 0x3f */ case OPCODE_LSTORE_1: /* 0x40 */ case OPCODE_LSTORE_2: /* 0x41 */ case OPCODE_LSTORE_3: /* 0x42 */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_LSTORE_0 ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_LSTORE_0); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_lstorex( instr, local, pool ); + vf_opcode_lstorex(instr, local, pool); break; case OPCODE_FSTORE_0: /* 0x43 */ case OPCODE_FSTORE_1: /* 0x44 */ case OPCODE_FSTORE_2: /* 0x45 */ case OPCODE_FSTORE_3: /* 0x46 */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_FSTORE_0 ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_FSTORE_0); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_fstorex( instr, local, pool ); + vf_opcode_fstorex(instr, local, pool); break; case OPCODE_DSTORE_0: /* 0x47 */ case OPCODE_DSTORE_1: /* 0x48 */ case OPCODE_DSTORE_2: /* 0x49 */ case OPCODE_DSTORE_3: /* 0x4a */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_DSTORE_0 ); - result = vf_check_local_var_number( local + 1, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_DSTORE_0); + result = vf_check_local_var_number(local + 1, ctx); + if (VF_OK != result) { return result; } - vf_opcode_dstorex( instr, local, pool ); + vf_opcode_dstorex(instr, local, pool); break; case OPCODE_ASTORE_0: /* 0x4b */ case OPCODE_ASTORE_1: /* 0x4c */ case OPCODE_ASTORE_2: /* 0x4d */ case OPCODE_ASTORE_3: /* 0x4e */ // get number of local variable - local = - ( unsigned short )( bytecode[prev_index] - OPCODE_ASTORE_0 ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = (unsigned short) (bytecode[prev_index] - OPCODE_ASTORE_0); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_astorex( instr, local, pool ); + vf_opcode_astorex(instr, local, pool); break; case OPCODE_IASTORE: /* 0x4f */ - vf_opcode_iastore( instr, ctx ); + vf_opcode_iastore(instr, ctx); break; case OPCODE_BASTORE: /* 0x54 */ - vf_opcode_bastore( instr, ctx ); + vf_opcode_bastore(instr, ctx); break; case OPCODE_CASTORE: /* 0x55 */ - vf_opcode_castore( instr, ctx ); + vf_opcode_castore(instr, ctx); break; case OPCODE_SASTORE: /* 0x56 */ - vf_opcode_sastore( instr, ctx ); + vf_opcode_sastore(instr, ctx); break; case OPCODE_LASTORE: /* 0x50 */ - vf_opcode_lastore( instr, ctx ); + vf_opcode_lastore(instr, ctx); break; case OPCODE_FASTORE: /* 0x51 */ - vf_opcode_fastore( instr, ctx ); + vf_opcode_fastore(instr, ctx); break; case OPCODE_DASTORE: /* 0x52 */ - vf_opcode_dastore( instr, ctx ); + vf_opcode_dastore(instr, ctx); break; case OPCODE_AASTORE: /* 0x53 */ - vf_opcode_aastore( instr, ctx ); + vf_opcode_aastore(instr, ctx); break; case OPCODE_POP: /* 0x57 */ - vf_opcode_pop( instr, pool ); + vf_opcode_pop(instr, pool); break; case OPCODE_POP2: /* 0x58 */ - vf_opcode_pop2( instr, pool ); + vf_opcode_pop2(instr, pool); break; case OPCODE_DUP: /* 0x59 */ - vf_opcode_dup( instr, pool ); + vf_opcode_dup(instr, pool); break; case OPCODE_DUP_X1: /* 0x5a */ - vf_opcode_dup_x1( instr, pool ); + vf_opcode_dup_x1(instr, pool); break; case OPCODE_DUP_X2: /* 0x5b */ - vf_opcode_dup_x2( instr, pool ); + vf_opcode_dup_x2(instr, pool); break; case OPCODE_DUP2: /* 0x5c */ - vf_opcode_dup2( instr, pool ); + vf_opcode_dup2(instr, pool); break; case OPCODE_DUP2_X1: /* 0x5d */ - vf_opcode_dup2_x1( instr, pool ); + vf_opcode_dup2_x1(instr, pool); break; case OPCODE_DUP2_X2: /* 0x5e */ - vf_opcode_dup2_x2( instr, pool ); + vf_opcode_dup2_x2(instr, pool); break; case OPCODE_SWAP: /* 0x5f */ - vf_opcode_swap( instr, pool ); + vf_opcode_swap(instr, pool); break; case OPCODE_IADD: /* 0x60 */ case OPCODE_ISUB: /* 0x64 */ case OPCODE_IMUL: /* 0x68 */ case OPCODE_IDIV: /* 0x6c */ case OPCODE_IREM: /* 0x70 */ - vf_opcode_iadd( instr, pool ); + vf_opcode_iadd(instr, pool); break; case OPCODE_LADD: /* 0x61 */ case OPCODE_LSUB: /* 0x65 */ case OPCODE_LMUL: /* 0x69 */ case OPCODE_LDIV: /* 0x6d */ case OPCODE_LREM: /* 0x71 */ - vf_opcode_ladd( instr, pool ); + vf_opcode_ladd(instr, pool); break; case OPCODE_FADD: /* 0x62 */ case OPCODE_FSUB: /* 0x66 */ case OPCODE_FMUL: /* 0x6a */ case OPCODE_FDIV: /* 0x6e */ case OPCODE_FREM: /* 0x72 */ - vf_opcode_fadd( instr, pool ); + vf_opcode_fadd(instr, pool); break; case OPCODE_DADD: /* 0x63 */ case OPCODE_DSUB: /* 0x67 */ case OPCODE_DMUL: /* 0x6b */ case OPCODE_DDIV: /* 0x6f */ case OPCODE_DREM: /* 0x73 */ - vf_opcode_dadd( instr, pool ); + vf_opcode_dadd(instr, pool); break; case OPCODE_INEG: /* 0x74 */ - vf_opcode_ineg( instr, pool ); + vf_opcode_ineg(instr, pool); break; case OPCODE_LNEG: /* 0x75 */ - vf_opcode_lneg( instr, pool ); + vf_opcode_lneg(instr, pool); break; case OPCODE_FNEG: /* 0x76 */ - vf_opcode_fneg( instr, pool ); + vf_opcode_fneg(instr, pool); break; case OPCODE_DNEG: /* 0x77 */ - vf_opcode_dneg( instr, pool ); + vf_opcode_dneg(instr, pool); break; case OPCODE_ISHL: /* 0x78 */ case OPCODE_ISHR: /* 0x7a */ @@ -4369,81 +4162,81 @@ case OPCODE_IAND: /* 0x7e */ case OPCODE_IOR: /* 0x80 */ case OPCODE_IXOR: /* 0x82 */ - vf_opcode_ibit( instr, pool ); + vf_opcode_ibit(instr, pool); break; case OPCODE_LSHL: /* 0x79 */ case OPCODE_LSHR: /* 0x7b */ case OPCODE_LUSHR: /* 0x7d */ - vf_opcode_lshx( instr, pool ); + vf_opcode_lshx(instr, pool); break; case OPCODE_LAND: /* 0x7f */ case OPCODE_LOR: /* 0x81 */ case OPCODE_LXOR: /* 0x83 */ - vf_opcode_land( instr, pool ); + vf_opcode_land(instr, pool); break; case OPCODE_IINC: /* 0x84 + u1|u2 + s1|s2 */ count = index; - local = vf_get_local_var_number( instr, bytecode, &index, wide ); + local = vf_get_local_var_number(instr, bytecode, &index, wide); count = index - count; - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_iinc( instr, local, pool ); + vf_opcode_iinc(instr, local, pool); // skip 2nd parameter (s1|s2) index += count; break; case OPCODE_I2L: /* 0x85 */ - vf_opcode_i2l( instr, pool ); + vf_opcode_i2l(instr, pool); break; case OPCODE_I2F: /* 0x86 */ - vf_opcode_i2f( instr, pool ); + vf_opcode_i2f(instr, pool); break; case OPCODE_I2D: /* 0x87 */ - vf_opcode_i2d( instr, pool ); + vf_opcode_i2d(instr, pool); break; case OPCODE_L2I: /* 0x88 */ - vf_opcode_l2i( instr, pool ); + vf_opcode_l2i(instr, pool); break; case OPCODE_L2F: /* 0x89 */ - vf_opcode_l2f( instr, pool ); + vf_opcode_l2f(instr, pool); break; case OPCODE_L2D: /* 0x8a */ - vf_opcode_l2d( instr, pool ); + vf_opcode_l2d(instr, pool); break; case OPCODE_F2I: /* 0x8b */ - vf_opcode_f2i( instr, pool ); + vf_opcode_f2i(instr, pool); break; case OPCODE_F2L: /* 0x8c */ - vf_opcode_f2l( instr, pool ); + vf_opcode_f2l(instr, pool); break; case OPCODE_F2D: /* 0x8d */ - vf_opcode_f2d( instr, pool ); + vf_opcode_f2d(instr, pool); break; case OPCODE_D2I: /* 0x8e */ - vf_opcode_d2i( instr, pool ); + vf_opcode_d2i(instr, pool); break; case OPCODE_D2L: /* 0x8f */ - vf_opcode_d2l( instr, pool ); + vf_opcode_d2l(instr, pool); break; case OPCODE_D2F: /* 0x90 */ - vf_opcode_d2f( instr, pool ); + vf_opcode_d2f(instr, pool); break; case OPCODE_I2B: /* 0x91 */ case OPCODE_I2C: /* 0x92 */ case OPCODE_I2S: /* 0x93 */ - vf_opcode_i2b( instr, pool ); + vf_opcode_i2b(instr, pool); break; case OPCODE_LCMP: /* 0x94 */ - vf_opcode_lcmp( instr, pool ); + vf_opcode_lcmp(instr, pool); break; case OPCODE_FCMPL: /* 0x95 */ case OPCODE_FCMPG: /* 0x96 */ - vf_opcode_fcmpx( instr, pool ); + vf_opcode_fcmpx(instr, pool); break; case OPCODE_DCMPL: /* 0x97 */ case OPCODE_DCMPG: /* 0x98 */ - vf_opcode_dcmpx( instr, pool ); + vf_opcode_dcmpx(instr, pool); break; case OPCODE_IFEQ: /* 0x99 + s2 */ case OPCODE_IFNE: /* 0x9a + s2 */ @@ -4451,18 +4244,18 @@ case OPCODE_IFGE: /* 0x9c + s2 */ case OPCODE_IFGT: /* 0x9d + s2 */ case OPCODE_IFLE: /* 0x9e + s2 */ - offset = vf_get_double_hword_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_double_hword_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - result = vf_check_branch_offset( index, ctx ); - if( VER_OK != result ) { + result = vf_check_branch_offset(index, ctx); + if (VF_OK != result) { return result; } - vf_opcode_ifeq( instr, &bc[offset], &bc[index], pool ); + vf_opcode_ifeq(instr, &bc[offset], &bc[index], pool); break; case OPCODE_IF_ICMPEQ: /* 0x9f + s2 */ case OPCODE_IF_ICMPNE: /* 0xa0 + s2 */ @@ -4470,221 +4263,221 @@ case OPCODE_IF_ICMPGE: /* 0xa2 + s2 */ case OPCODE_IF_ICMPGT: /* 0xa3 + s2 */ case OPCODE_IF_ICMPLE: /* 0xa4 + s2 */ - offset = vf_get_double_hword_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_double_hword_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - result = vf_check_branch_offset( index, ctx ); - if( VER_OK != result ) { + result = vf_check_branch_offset(index, ctx); + if (VF_OK != result) { return result; } - vf_opcode_if_icmpeq( instr, &bc[offset], &bc[index], pool ); + vf_opcode_if_icmpeq(instr, &bc[offset], &bc[index], pool); break; case OPCODE_IF_ACMPEQ: /* 0xa5 + s2 */ case OPCODE_IF_ACMPNE: /* 0xa6 + s2 */ - offset = vf_get_double_hword_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_double_hword_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - result = vf_check_branch_offset( index, ctx ); - if( VER_OK != result ) { + result = vf_check_branch_offset(index, ctx); + if (VF_OK != result) { return result; } - vf_opcode_if_acmpeq( instr, &bc[offset], &bc[index], pool ); + vf_opcode_if_acmpeq(instr, &bc[offset], &bc[index], pool); break; case OPCODE_GOTO: /* 0xa7 + s2 */ - offset = vf_get_single_hword_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_single_hword_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - vf_set_basic_block_flag( index, ctx ); + vf_set_basic_block_flag(index, ctx); break; case OPCODE_JSR: /* 0xa8 + s2 */ - offset = vf_get_single_hword_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_single_hword_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - vf_opcode_jsr( instr, offset, pool ); - vf_set_basic_block_flag( index, ctx ); + vf_opcode_jsr(instr, offset, pool); + vf_set_basic_block_flag(index, ctx); break; case OPCODE_RET: /* 0xa9 + u1|u2 */ - local = vf_get_local_var_number( instr, bytecode, &index, wide ); - result = vf_check_local_var_number( local, ctx ); - if( VER_OK != result ) { + local = vf_get_local_var_number(instr, bytecode, &index, wide); + result = vf_check_local_var_number(local, ctx); + if (VF_OK != result) { return result; } - vf_opcode_ret( instr, local, pool ); + vf_opcode_ret(instr, local, pool); // create and set edge branch to exit - vf_set_basic_block_flag( index, ctx ); + vf_set_basic_block_flag(index, ctx); ret_num++; break; case OPCODE_TABLESWITCH: /* 0xaa + pad + s4 * (3 + N) */ - vf_opcode_switch( instr, pool ); - branches = vf_set_tableswitch_offsets( instr, - prev_index, &index, - bytecode, pool ); + vf_opcode_switch(instr, pool); + branches = vf_set_tableswitch_offsets(instr, + prev_index, &index, + bytecode, pool); // check tableswitch branches and set begin of basic blocks - for( count = 0; count < branches; count++ ) { - offset = vf_get_instr_branch( instr, count ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + for (count = 0; count < branches; count++) { + offset = vf_get_instr_branch(instr, count); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } } - if( index < len ) { - vf_set_basic_block_flag( index, ctx ); + if (index < len) { + vf_set_basic_block_flag(index, ctx); } break; case OPCODE_LOOKUPSWITCH: /* 0xab + pad + s4 * 2 * (N + 1) */ - vf_opcode_switch( instr, pool ); - result = vf_set_lookupswitch_offsets( instr, - prev_index, &index, - bytecode, &branches, ctx ); - if( VER_OK != result ) { + vf_opcode_switch(instr, pool); + result = vf_set_lookupswitch_offsets(instr, + prev_index, &index, + bytecode, &branches, ctx); + if (VF_OK != result) { return result; } // check tableswitch branches and set begin of basic blocks - for( count = 0; count < branches; count++ ) { - offset = vf_get_instr_branch( instr, count ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + for (count = 0; count < branches; count++) { + offset = vf_get_instr_branch(instr, count); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } } - if( index < len ) { - vf_set_basic_block_flag( index, ctx ); + if (index < len) { + vf_set_basic_block_flag(index, ctx); } break; case OPCODE_IRETURN: /* 0xac */ - vf_opcode_ireturn( instr, index, ctx ); + vf_opcode_ireturn(instr, index, ctx); break; case OPCODE_LRETURN: /* 0xad */ - vf_opcode_lreturn( instr, index, ctx ); + vf_opcode_lreturn(instr, index, ctx); break; case OPCODE_FRETURN: /* 0xae */ - vf_opcode_freturn( instr, index, ctx ); + vf_opcode_freturn(instr, index, ctx); break; case OPCODE_DRETURN: /* 0xaf */ - vf_opcode_dreturn( instr, index, ctx ); + vf_opcode_dreturn(instr, index, ctx); break; case OPCODE_ARETURN: /* 0xb0 */ - vf_opcode_areturn( instr, index, ctx ); + vf_opcode_areturn(instr, index, ctx); break; case OPCODE_RETURN: /* 0xb1 */ - vf_opcode_return( instr, index, ctx ); + vf_opcode_return(instr, index, ctx); break; case OPCODE_GETSTATIC: /* 0xb2 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_getstatic( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_getstatic(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_PUTSTATIC: /* 0xb3 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_putstatic( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_putstatic(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_GETFIELD: /* 0xb4 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_getfield( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_getfield(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_PUTFIELD: /* 0xb5 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_putfield( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_putfield(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_INVOKEVIRTUAL: /* 0xb6 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_invoke( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_invoke(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_INVOKESPECIAL: /* 0xb7 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_invokespecial( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_invokespecial(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_INVOKESTATIC: /* 0xb8 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_invoke( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_invoke(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_INVOKEINTERFACE: /* 0xb9 + u2 + u1 + u1 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_invoke( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_invoke(instr, const_index, ctx); + if (VF_OK != result) { return result; } // check the number of arguments and last opcode byte - if( instr->m_inlen != ( unsigned short )bytecode[index] - || bytecode[index + 1] != 0 ) { - VF_REPORT( ctx, "Incorrect operand byte of invokeinterface" ); - return VER_ErrorInstruction; + if (instr->m_inlen != (unsigned short) bytecode[index] + || bytecode[index + 1] != 0) { + VF_REPORT(ctx, "Incorrect operand byte of invokeinterface"); + return VF_ErrorInstruction; } // skip 2 parameters (u1 + u1) index += 1 + 1; @@ -4692,175 +4485,174 @@ case OPCODE_NEW: /* 0xbb + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; // zero number of opcode new is reserved for "uninitialized this" result = - vf_opcode_new( instr, const_index, - vf_get_instr_index( instr, ctx ) + 1, ctx ); + vf_opcode_new(instr, const_index, + vf_get_instr_index(instr, ctx) + 1, ctx); - if( VER_OK != result ) { + if (VF_OK != result) { return result; } break; case OPCODE_NEWARRAY: /* 0xbc + u1 */ // get array type - u1 = ( unsigned char )bytecode[index]; + u1 = (unsigned char) bytecode[index]; // skip parameter (u1) index++; - result = vf_opcode_newarray( instr, u1, ctx ); - if( VER_OK != result ) { + result = vf_opcode_newarray(instr, u1, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_ANEWARRAY: /* 0xbd + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_anewarray( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_anewarray(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_ARRAYLENGTH: /* 0xbe */ - vf_opcode_arraylength( instr, ctx ); + vf_opcode_arraylength(instr, ctx); break; case OPCODE_ATHROW: /* 0xbf */ - vf_opcode_athrow( instr, ctx ); + vf_opcode_athrow(instr, ctx); // create and set edge branch to exit - vf_set_basic_block_flag( index, ctx ); + vf_set_basic_block_flag(index, ctx); break; case OPCODE_CHECKCAST: /* 0xc0 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_checkcast( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_checkcast(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_INSTANCEOF: /* 0xc1 + u2 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; - result = vf_opcode_instanceof( instr, const_index, ctx ); - if( VER_OK != result ) { + result = vf_opcode_instanceof(instr, const_index, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_MONITORENTER: /* 0xc2 */ case OPCODE_MONITOREXIT: /* 0xc3 */ - vf_opcode_monitorx( instr, pool ); + vf_opcode_monitorx(instr, pool); break; case OPCODE_MULTIANEWARRAY: /* 0xc5 + u2 + u1 */ // get constant pool index const_index = - ( unsigned short )( ( bytecode[index] << 8 ) | - ( bytecode[index + 1] ) ); + (unsigned short) ((bytecode[index] << 8) | + (bytecode[index + 1])); // skip constant pool index (u2) index += 2; // get dimensions of array u1 = bytecode[index]; // skip dimensions of array (u1) index++; - result = vf_opcode_multianewarray( instr, const_index, u1, ctx ); - if( VER_OK != result ) { + result = vf_opcode_multianewarray(instr, const_index, u1, ctx); + if (VF_OK != result) { return result; } break; case OPCODE_IFNULL: /* 0xc6 + s2 */ case OPCODE_IFNONNULL: /* 0xc7 + s2 */ - offset = vf_get_double_hword_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_double_hword_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - result = vf_check_branch_offset( index, ctx ); - if( VER_OK != result ) { + result = vf_check_branch_offset(index, ctx); + if (VF_OK != result) { return result; } - vf_opcode_ifxnull( instr, &bc[offset], &bc[index], pool ); + vf_opcode_ifxnull(instr, &bc[offset], &bc[index], pool); break; case OPCODE_GOTO_W: /* 0xc8 + s4 */ - offset = vf_get_single_word_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_single_word_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - vf_set_basic_block_flag( index, ctx ); + vf_set_basic_block_flag(index, ctx); break; case OPCODE_JSR_W: /* 0xc9 + s4 */ - offset = vf_get_single_word_branch_offset( instr, - prev_index, bytecode, - &index, pool ); - result = vf_check_branch_offset( offset, ctx ); - if( VER_OK != result ) { + offset = vf_get_single_word_branch_offset(instr, + prev_index, bytecode, + &index, pool); + result = vf_check_branch_offset(offset, ctx); + if (VF_OK != result) { return result; } - vf_opcode_jsr( instr, offset, pool ); - vf_set_basic_block_flag( index, ctx ); + vf_opcode_jsr(instr, offset, pool); + vf_set_basic_block_flag(index, ctx); break; case _OPCODE_UNDEFINED: /* 0xba */ default: - VF_REPORT( ctx, "Unknown bytecode instruction " ); - return VER_ErrorInstruction; + VF_REPORT(ctx, "Unknown bytecode instruction "); + return VF_ErrorInstruction; } - assert( instr->m_minstack + instr->m_stack >= 0 ); + assert(instr->m_minstack + instr->m_stack >= 0); } - if( index > len ) { - VF_REPORT( ctx, "The last instruction doesn't fit bytecode array" ); - return VER_ErrorInstruction; + if (index > len) { + VF_REPORT(ctx, "The last instruction doesn't fit bytecode array"); + return VF_ErrorInstruction; } /** * Set handler basic blocks. */ unsigned short handler_count = ctx->m_handlers; - unsigned short constLen = class_get_cp_size( ctx->m_class ); - for( unsigned short handler_index = 0; - handler_index < handler_count; handler_index++ ) { + unsigned short constLen = class_get_cp_size(ctx->m_class); + for (unsigned short handler_index = 0; + handler_index < handler_count; handler_index++) { unsigned short start_pc, end_pc, handler_pc, handler_cp_index; - method_get_exc_handler_info( ctx->m_method, - handler_index, &start_pc, &end_pc, - &handler_pc, &handler_cp_index ); + method_get_exc_handler_info(ctx->m_method, + handler_index, &start_pc, &end_pc, + &handler_pc, &handler_cp_index); // check instruction range - if( ( start_pc >= len ) - || ( end_pc > len ) - || ( handler_pc >= len ) ) { - VF_REPORT( ctx, "Exception handler pc is out of range" ); - return VER_ErrorHandler; + if ((start_pc >= len) + || (end_pc > len) + || (handler_pc >= len)) { + VF_REPORT(ctx, "Exception handler pc is out of range"); + return VF_ErrorHandler; } - if( start_pc >= end_pc ) { - VF_REPORT( ctx, - "Exception handler range starting point should be before ending point" ); - return VER_ErrorHandler; + if (start_pc >= end_pc) { + VF_REPORT(ctx, + "Exception handler range starting point should be before ending point"); + return VF_ErrorHandler; } // check that handlers point to instruction // boundaries - if( NULL == bc[start_pc].m_instr - || NULL == bc[end_pc].m_instr - || NULL == bc[handler_pc].m_instr ) { - VF_REPORT( ctx, - "At least one of exception handler parameters [" - << start_pc << ", " << end_pc << ", " << - handler_pc << "] are out of instruction set" ); - return VER_ErrorHandler; + if (NULL == bc[start_pc].m_instr + || NULL == bc[end_pc].m_instr || NULL == bc[handler_pc].m_instr) { + VF_REPORT(ctx, + "At least one of exception handler parameters [" + << start_pc << ", " << end_pc << ", " << + handler_pc << "] are out of instruction set"); + return VF_ErrorHandler; } bc[start_pc].m_is_bb_start = true; bc[end_pc].m_is_bb_start = true; @@ -4871,7 +4663,7 @@ ctx->m_last_instr = instr; ctx->m_retnum = ret_num; - VF_DUMP( DUMP_INSTR, vf_dump_bytecode( ctx ) ); + VF_DUMP(DUMP_INSTR, vf_dump_bytecode(ctx)); return result; } // vf_parse_bytecode @@ -4880,59 +4672,58 @@ /** * Prints code instruction array in stream. */ -void -vf_dump_bytecode( vf_ContextHandle ctx ) // verification context +void vf_dump_bytecode(vf_ContextHandle ctx) // verification context { VF_DEBUG - ( "======================== VERIFIER METHOD DUMP ========================" ); - VF_DEBUG( "Method: " << class_get_name( ctx->m_class ) - << "." << ctx->m_name << ctx->m_descriptor << endl ); - VF_DEBUG( "0 [-]: -> START-ENTRY" ); + ("======================== VERIFIER METHOD DUMP ========================"); + VF_DEBUG("Method: " << class_get_name(ctx->m_class) + << "." << ctx->m_name << ctx->m_descriptor << endl); + VF_DEBUG("0 [-]: -> START-ENTRY"); unsigned short handler_count = ctx->m_handlers; - for( unsigned short handler_index = 0; - handler_index < handler_count; handler_index++ ) { - VF_DEBUG( handler_index + - 1 << " [-]: -> HANDLER #" << handler_index + 1 ); + for (unsigned short handler_index = 0; + handler_index < handler_count; handler_index++) { + VF_DEBUG(handler_index + + 1 << " [-]: -> HANDLER #" << handler_index + 1); unsigned short start_pc, end_pc, handler_pc, handler_cp_index; - method_get_exc_handler_info( ctx->m_method, - handler_index, &start_pc, &end_pc, - &handler_pc, &handler_cp_index ); + method_get_exc_handler_info(ctx->m_method, + handler_index, &start_pc, &end_pc, + &handler_pc, &handler_cp_index); - VF_DEBUG( " from " << vf_bc_to_instr_index( start_pc, ctx ) + - handler_count << " [" << start_pc << "]" " to " << - vf_bc_to_instr_index( end_pc, - ctx ) + - handler_count << " [" << end_pc << "]" " --> " << - vf_bc_to_instr_index( handler_pc, - ctx ) + - handler_count << " [" << handler_pc << "]" ", CP type " - << handler_cp_index ); + VF_DEBUG(" from " << vf_bc_to_instr_index(start_pc, ctx) + + handler_count << " [" << start_pc << "]" " to " << + vf_bc_to_instr_index(end_pc, + ctx) + + handler_count << " [" << end_pc << "]" " --> " << + vf_bc_to_instr_index(handler_pc, + ctx) + + handler_count << " [" << handler_pc << "]" ", CP type " + << handler_cp_index); } - unsigned char *bytecode = method_get_bytecode( ctx->m_method ); + unsigned char *bytecode = method_get_bytecode(ctx->m_method); vf_InstrHandle instr = ctx->m_instr; unsigned index; - for( index = handler_count + 1; - instr < ctx->m_last_instr; index++, instr++ ) { - VF_DEBUG( index - << " [" << instr->m_addr - bytecode << "]:" - << ( ( instr->m_is_bb_start ) ? " -> " : " " ) - << ( ( instr->m_stack < 0 ) ? "" : " " ) - << instr->m_stack - << "|" << instr->m_minstack << " " - << vf_opcode_names[*( instr->m_addr )] ); - for( unsigned count = 0; count < instr->m_offcount; count++ ) { + for (index = handler_count + 1; + instr < ctx->m_last_instr; index++, instr++) { + VF_DEBUG(index + << " [" << instr->m_addr - bytecode << "]:" + << ((instr->m_is_bb_start) ? " -> " : " ") + << ((instr->m_stack < 0) ? "" : " ") + << instr->m_stack + << "|" << instr->m_minstack << " " + << vf_opcode_names[*(instr->m_addr)]); + for (unsigned count = 0; count < instr->m_offcount; count++) { unsigned offset = instr->m_off[count]; - VF_DEBUG( " --> " - << vf_bc_to_instr_index( offset, - ctx ) + - handler_count << " [" << offset << "]" ); + VF_DEBUG(" --> " + << vf_bc_to_instr_index(offset, + ctx) + + handler_count << " [" << offset << "]"); } } - VF_DEBUG( index << " [-]: -> END-ENTRY" << endl ); + VF_DEBUG(index << " [-]: -> END-ENTRY" << endl); VF_DEBUG - ( "======================================================================" ); + ("======================================================================"); } // vf_dump_bytecode #endif //_VF_DEBUG @@ -4940,20 +4731,19 @@ /** * Provides initial verification of class. */ -vf_Result -vf_verify_class( class_handler klass, // verified class - unsigned verifyAll, // verification level flag - char **message ) // verifier error message +vf_Result vf_verify_class(class_handler klass, // verified class + unsigned verifyAll, // verification level flag + char **message) // verifier error message { - assert( klass ); - assert( message ); + assert(klass); + assert(message); #if VF_CLASS - if( strcmp( class_get_name( klass ), "" ) ) { - return VER_OK; + if (strcmp(class_get_name(klass), "")) { + return VF_OK; } #endif // VF_CLASS - VF_TRACE( "class.bytecode", "verify class: " << class_get_name( klass ) ); + VF_TRACE("class.bytecode", "verify class: " << class_get_name(klass)); /** * Create context @@ -4978,22 +4768,20 @@ /** * Set valid types */ - const char *class_name = class_get_name( klass ); - size_t class_name_len = strlen( class_name ); - char *type_name = (char*)STD_ALLOCA( class_name_len + 1 + 1 ); + const char *class_name = class_get_name(klass); + size_t class_name_len = strlen(class_name); + char *type_name = (char *) STD_ALLOCA(class_name_len + 1 + 1); // it will be a funny name for array :) - memcpy( &type_name[1], class_name, class_name_len ); + memcpy(&type_name[1], class_name, class_name_len); type_name[0] = 'L'; type_name[class_name_len + 1] = '\0'; - ctx.m_vtype.m_class = - ctx.m_type->NewType( type_name, class_name_len + 1 ); - ctx.m_vtype.m_throwable = - ctx.m_type->NewType( "Ljava/lang/Throwable", 20 ); - ctx.m_vtype.m_object = ctx.m_type->NewType( "Ljava/lang/Object", 17 ); - ctx.m_vtype.m_array = ctx.m_type->NewType( "[Ljava/lang/Object", 18 ); - ctx.m_vtype.m_clone = ctx.m_type->NewType( "Ljava/lang/Cloneable", 20 ); + ctx.m_vtype.m_class = ctx.m_type->NewType(type_name, class_name_len + 1); + ctx.m_vtype.m_throwable = ctx.m_type->NewType("Ljava/lang/Throwable", 20); + ctx.m_vtype.m_object = ctx.m_type->NewType("Ljava/lang/Object", 17); + ctx.m_vtype.m_array = ctx.m_type->NewType("[Ljava/lang/Object", 18); + ctx.m_vtype.m_clone = ctx.m_type->NewType("Ljava/lang/Cloneable", 20); ctx.m_vtype.m_serialize = - ctx.m_type->NewType( "Ljava/io/Serializable", 21 ); + ctx.m_type->NewType("Ljava/io/Serializable", 21); /** * Set verification level flag @@ -5003,40 +4791,38 @@ /** * Verify bytecode of methods */ - vf_Result result = VER_OK; - unsigned short number = class_get_method_number( klass ); - for( unsigned short index = 0; index < number; index++ ) { + vf_Result result = VF_OK; + unsigned short number = class_get_method_number(klass); + for (unsigned short index = 0; index < number; index++) { #if VF_METHOD - if( !strcmp - ( method_get_name( class_get_method( klass, index ) ), "" ) ) + if (!strcmp(method_get_name(class_get_method(klass, index)), "")) #endif // VF_METHOD { /** * Set verified method */ - ctx.SetMethod( class_get_method( klass, index ) ); - result = vf_verify_method_bytecode( &ctx ); + ctx.SetMethod(class_get_method(klass, index)); + result = vf_verify_method_bytecode(&ctx); ctx.ClearContext(); } - if( VER_OK != result ) { + if (VF_OK != result) { goto labelEnd_verifyClass; } } - VF_DUMP( DUMP_CONSTRAINT, ctx.m_type->DumpTypeConstraints( NULL ) ); + VF_DUMP(DUMP_CONSTRAINT, ctx.m_type->DumpTypeConstraints(NULL)); // check and set class constraints - result = vf_check_class_constraints( &ctx ); - if( VER_OK != result ) { + result = vf_check_class_constraints(&ctx); + if (VF_OK != result) { goto labelEnd_verifyClass; } labelEnd_verifyClass: *message = ctx.m_error; #if _VF_DEBUG - if( VER_OK != result ) { - VF_TRACE( "", - "VerifyError: " << ( ctx.m_error ? ctx.m_error : "NULL" ) ); + if (VF_OK != result) { + VF_TRACE("", "VerifyError: " << (ctx.m_error ? ctx.m_error : "NULL")); } #endif // _VF_DEBUG Index: vm/vmcore/src/verifier/ver_subroutine.cpp =================================================================== --- vm/vmcore/src/verifier/ver_subroutine.cpp (revision 542211) +++ vm/vmcore/src/verifier/ver_subroutine.cpp (working copy) @@ -26,16 +26,17 @@ */ unsigned vf_get_sub_num(vf_SubHandle sub, vf_ContextHandle ctx) { - unsigned index = 0; for (vf_SubHandle s = ctx->m_sub_ctx->m_sub; s; s = s->m_next) { if (s == sub) { // subroutine found + unsigned index = 0; + while (s = s->m_next) + index++; return index; } - index++; } VF_DIE("vf_get_sub_num: Cannot find a subroutine " << sub << - " in a list"); - return 0; + " in a list"); + return ALL_BITS_SET; } void vf_Graph::DumpSub(vf_SubHandle sub) @@ -58,18 +59,12 @@ static void DumpNodeStack(vf_Context *ctx) { vf_NodeStackHandle p_element = ctx->m_sub_ctx->m_path_start; - bool fork_found = false; unsigned count = 0; VF_DEBUG("Dumping path: "); for (; p_element; p_element = p_element->m_next, count++) { - if (p_element == ctx->m_sub_ctx->m_path_fork) { - fork_found = true; - VF_DEBUG("Fork"); - } VF_DEBUG(" Node #" << ctx->m_graph->GetNodeNum(p_element->m_node)); } - assert(fork_found || !ctx->m_sub_ctx->m_path_fork); VF_DEBUG("Totally " << count << " nodes"); } // DumpNodeStack #endif // _VF_DEBUG @@ -84,9 +79,13 @@ vf_Pool *pool = ctx->m_pool; vf_SubContext *sub_ctx = (vf_SubContext *) vf_palloc(pool, - sizeof(vf_SubContext)); + sizeof + (vf_SubContext)); ctx->m_sub_ctx = sub_ctx; sub_ctx->m_pool = pool; + sub_ctx->m_tmpmap = (vf_MapVector *) vf_palloc(pool, + sizeof(vf_MapVector)); + ctx->m_graph->AllocVector(sub_ctx->m_tmpmap); } // AllocateSubContext @@ -96,7 +95,7 @@ * @param[in] sub_ctx a subroutine verification context * @return a sub handle */ -static vf_Sub *AddNewSub(vf_NodeHandle ret_node, vf_SubContext * sub_ctx) +static vf_Sub *AddNewSub(vf_NodeHandle ret_node, vf_SubContext *sub_ctx) { vf_Sub *sub = (vf_Sub *) vf_palloc(sub_ctx->m_pool, sizeof(vf_Sub)); sub->m_next = sub_ctx->m_sub; @@ -120,45 +119,158 @@ sub->m_out_edgenum += node->m_outnum; } // AddSubNode -static inline vf_Result ResolveSubroutineEntryPoint(vf_Node *node, - vf_Context *ctx) +/** + * Updates a stack map following a path through a subroutine. + * @param sub a sub to update a map + * @param ctx a verification context + */ +static inline void UpdateStackMapWithSub(vf_SubHandle sub, vf_Context *ctx) { - //initialize vector vf_MapVector *map = ctx->m_map; + vf_MapVector *outmap = sub->m_outmap; + vf_MapVector *tmpmap = ctx->m_sub_ctx->m_tmpmap; - // the path element node to iterate from - vf_NodeStackHandle p_element = ctx->m_sub_ctx->m_path_fork; - if (!p_element) { - p_element = ctx->m_sub_ctx->m_path_start; - map->m_number = ctx->m_maxlocal; - unsigned index; - for (index = 0; index < map->m_number; index++) { - map->m_local[index].m_type = SM_ANY; - map->m_local[index].m_is_local = true; - map->m_local[index].m_local = index; + tmpmap->m_number = outmap->m_number; + tmpmap->m_depth = outmap->m_depth; + + + VF_DUMP(DUMP_MERGE_MAP, { + // dump out vectors + cerr << "============== merging OUT map of subroutine #" + << vf_get_sub_num(sub, ctx) << endl; + cerr << "calling node IN vector:" << endl; + vf_dump_vector(map, NULL, &cerr); + cerr << "subroutine OUT vector:" << endl; + vf_dump_vector(outmap, NULL, &cerr); + } + ); + + unsigned short index; + vf_MapEntry *map_entry = map->m_local; + vf_MapEntry *outmap_entry = outmap->m_local; + vf_MapEntry *tmpmap_entry = tmpmap->m_local; + + // merge local variable vector + for (index = 0; index < outmap->m_number; + index++, map_entry++, outmap_entry++, tmpmap_entry++) { + // merge entries type + vf_MapEntry *result_entry; + if (SM_RETURN_ADDR == outmap_entry->m_type + && SM_RETURN_ADDR == map_entry->m_type) { + // the return address in local + // local variable might be overridden only using a value from + // the stack, and input stacks for the subroutine should be + // the same, hence in this case the value will be overridden + // with the same value + result_entry = map_entry; + } else if (SM_ANY != outmap_entry->m_type) { + result_entry = outmap_entry; + } else if (outmap_entry->m_mappos < ctx->m_maxlocal) { + result_entry = map->m_local + outmap_entry->m_mappos; + } else { + result_entry = + map->m_stack + (outmap_entry->m_mappos - ctx->m_maxlocal); } + tmpmap_entry->m_type = result_entry->m_type; + tmpmap_entry->m_vtype = result_entry->m_vtype; + tmpmap_entry->m_new = result_entry->m_new; + } - map->m_depth = p_element->m_node->m_inmap.m_depth; - // FIXME - stack depth should be greater then 0 - // assert(map->m_depth); - for (index = 0; index + 1 < map->m_depth; index++) { - map->m_stack[index].m_type = SM_ANY; + // merge stack map vector + map_entry = map->m_stack; + outmap_entry = outmap->m_stack; + tmpmap_entry = tmpmap->m_stack; + for (index = 0; index < outmap->m_depth; + index++, map_entry++, outmap_entry++, tmpmap_entry++) { + // merge entries type + vf_MapEntry *result_entry; + if (SM_ANY != outmap_entry->m_type) { + result_entry = outmap_entry; + } else if (outmap_entry->m_mappos < ctx->m_maxlocal) { + result_entry = map->m_local + outmap_entry->m_mappos; + } else { + result_entry = + map->m_stack + (outmap_entry->m_mappos - ctx->m_maxlocal); } - map->m_stack[index].m_type = SM_RETURN_ADDR; - map->m_stack[index++].m_pc = - (unsigned) (p_element->m_node->m_start->m_addr - ctx->m_bytes); - // FIXME - index should be equal to stack depth - // assert(index == map->m_depth); - for (; index < ctx->m_maxstack; index++) { - map->m_stack[index].m_type = SM_TOP; - } + tmpmap_entry->m_type = result_entry->m_type; + tmpmap_entry->m_vtype = result_entry->m_vtype; + tmpmap_entry->m_new = result_entry->m_new; } + VF_DUMP(DUMP_MERGE_MAP, { + // dump out vectors + cerr << "============== result map" << endl; + vf_dump_vector(tmpmap, NULL, &cerr); + } + ); + + ctx->m_graph->CopyFullVector(tmpmap, map); + return; +} + +/** + * Initializes path and a stack map with SM_RETURN_ADDR and + * SM_ANY values if the map is not yet initialized. + * @param stack a reference of a stack for the end node of the jsr edge + * @param ctx a verification context + */ +static inline void EnsureStackMapInitialized(vf_Context *ctx) +{ + if (ctx->m_sub_ctx->m_path_map_initialized) { + return; + } + vf_MapVector *map = ctx->m_map; + map->m_number = ctx->m_maxlocal; + unsigned mappos = 0; + unsigned index; + for (index = 0; index < map->m_number; index++) { + map->m_local[index].m_type = SM_ANY; + map->m_local[index].m_mappos = mappos++; + map->m_local[index].m_is_local = true; + map->m_local[index].m_local = index; + } + + map->m_depth = ctx->m_sub_ctx->m_path_start->m_node->m_inmap.m_depth; + assert(map->m_depth); + mappos = ctx->m_maxlocal; + for (index = 0; index + 1 < map->m_depth; index++) { + map->m_stack[index].m_type = SM_ANY; + map->m_stack[index].m_mappos = mappos++; + } + map->m_stack[index].m_type = SM_RETURN_ADDR; + map->m_stack[index++].m_pc = + (unsigned) (ctx->m_sub_ctx->m_path_start->m_node->m_start->m_addr - + ctx->m_bytes); + assert(index == map->m_depth); + for (; index < ctx->m_maxstack; index++) { + map->m_stack[index].m_type = SM_TOP; + } + ctx->m_sub_ctx->m_path_map_initialized = true; +} + +/** + * @param[in] node a node, which contains ret instruction + * @param[in] ctx a verification context + * @return VF_OK if marking was successful, an error code in case of data flow + * error + */ +static inline vf_Result ResolveSubroutineEntryPoint(vf_Node *node, + vf_Context *ctx) +{ + // initialize a vector shortcut + vf_MapVector *map = ctx->m_map; + + // the path element node to iterate from VF_DUMP(DUMP_NODESTACK, DumpNodeStack(ctx)); + + vf_NodeStackHandle p_element = ctx->m_sub_ctx->m_path_start; + + EnsureStackMapInitialized(ctx); for (; p_element; p_element = p_element->m_next) { + assert(p_element); vf_Result result = vf_set_node_out_vector(p_element->m_node, map, ctx); - if (result != VER_OK) { + if (VF_OK != result) { return result; } } @@ -166,12 +278,24 @@ // since a copy flag is set for SM_RETURN_ADDR entries, // ctx->m_buf contains the last processed entry, i. e. // an entry for ret - assert(ctx->m_buf->m_pc); + unsigned entry_pc = ctx->m_buf->m_pc; + // subroutine cannot start at zero instruction + assert(entry_pc); assert(SM_RETURN_ADDR == ctx->m_buf->m_type); assert(node->m_outmap.m_depth == ctx->m_map->m_depth); - ((vf_Sub *) node->m_sub)->m_entry = - ctx->m_graph->GetNodeFromBytecodeIndex(ctx->m_buf->m_pc); - return VER_OK; + + vf_NodeHandle entry = ctx->m_graph->GetNodeFromBytecodeIndex(entry_pc); + + vf_Sub *sub = (vf_Sub *) node->m_sub; + sub->m_entry = entry; + + // store the out map of the node + // TODO may be skipped for subroutines which have less than two calls to them + sub->m_outmap = (vf_MapVector *) vf_palloc(ctx->m_sub_ctx->m_pool, + sizeof(vf_MapVector)); + ctx->m_graph->AllocVector(sub->m_outmap); + ctx->m_graph->CopyVector(ctx->m_map, sub->m_outmap); + return VF_OK; } // ResolveSubroutineEntryPoint static vf_Result MarkNode(vf_NodeStack &stack, vf_Context *ctx); @@ -183,23 +307,23 @@ * @param[in] node a node which is a part of a subroutine * @param[in,out] ctx a verification context * @return if the mark of this node is already set and is not equal to - * sub, VER_ErrorJsrMultipleRet is reported + * sub, VF_ErrorJsrMultipleRet is reported */ static inline vf_Result SetSubMarks(vf_SubHandle sub, vf_Node *node, vf_Context *ctx) { assert(sub); VF_TRACE("sub.mark", "sub[" << ctx->m_graph->GetNodeNum(node) - << "] := sub[" << ctx->m_graph->GetNodeNum(sub->m_ret) - << "] (" << vf_get_sub_num(sub, ctx) << ")"); + << "] := sub[" << ctx->m_graph->GetNodeNum(sub->m_ret) + << "] (" << vf_get_sub_num(sub, ctx) << ")"); if (node->m_sub == sub) { - return VER_OK; // already marked + return VF_OK; // already marked } if (NULL == node->m_sub) { if (node == ctx->m_graph->GetStartNode()) { VF_REPORT(ctx, "Reached ret not using jsr branches"); - return VER_ErrorJsrOther; + return VF_ErrorJsrOther; } node->m_sub = sub; @@ -208,88 +332,146 @@ AddSubNode(node); } for (vf_EdgeHandle inedge = node->m_inedge; - inedge; inedge = inedge->m_innext) { + inedge; inedge = inedge->m_innext) { + VF_TRACE("edge", "Marking subroutines: following edge #" + << ctx->m_graph->GetNodeNum(inedge->m_start) << " -> #" + << ctx->m_graph->GetNodeNum(inedge->m_end)); if (vf_is_jsr_branch(inedge, ctx)) { + VF_TRACE("edge", " This is jsr edge, skipping"); continue; } vf_Result result = SetSubMarks(sub, (vf_Node *) inedge->m_start, ctx); - if (result != VER_OK) { + if (VF_OK != result) { return result; } } - return VER_OK; + return VF_OK; } assert(node->m_sub != sub); VF_REPORT(ctx, - "A subroutine splits execution into several ret instructions"); - return VER_ErrorJsrMultipleRet; + "A subroutine splits execution into several ret instructions"); + return VF_ErrorJsrMultipleRet; } // SetSubMarks /** * Marks a jsr edge end node. If the subroutine returns, marks a node, which * follows the edge start node. + * @param node a start node for the jsr edge + * @param stack a reference of a stack for the end node of the jsr edge + * @param ctx a verification context + * @return VF_OK if marking was successful, an error code in case of data flow + * error */ static inline vf_Result FollowJsrEdge(vf_Node *node, vf_NodeStack &stack, vf_Context *ctx) { vf_NodeStackHandle path_start = ctx->m_sub_ctx->m_path_start; - if (!path_start) { - ctx->m_sub_ctx->m_path_start = &stack; + + VF_TRACE("edge", "Following jsr edge #" + << ctx->m_graph->GetNodeNum(node) << " -> #" + << ctx->m_graph->GetNodeNum(stack.m_node)); + + if (stack.m_node->m_mark) { + // FIXME subroutine node copies might have different stack maps, though + // this is not a security threat, just incompatibility with RI. + if (path_start) { + if (!stack.m_node->m_sub) { + // we assume that the branch is to the top + // level code, or the same subroutine, so there + // is no return + return VF_OK; + } + + if (stack.m_node->m_sub->m_entry != stack.m_node) { + VF_REPORT(ctx, + "A subroutine splits execution into " + "several ret instructions"); + return VF_ErrorJsrMultipleRet; + } + + EnsureStackMapInitialized(ctx); + vf_NodeStackHandle &p_element = ctx->m_sub_ctx->m_path_start; + assert(p_element->m_node->m_inmap.m_depth == + stack.m_node->m_outmap.m_depth); + for (; p_element != &stack; p_element = p_element->m_next) { + assert(p_element); + vf_Result result = + vf_set_node_out_vector(p_element->m_node, ctx->m_map, + ctx); + if (VF_OK != result) { + return result; + } + } + UpdateStackMapWithSub(stack.m_node->m_sub, ctx); + } + } else { + if (!path_start) { + ctx->m_sub_ctx->m_path_start = &stack; + ctx->m_sub_ctx->m_path_map_initialized = false; + } } - vf_Result r = MarkNode(stack, ctx); - if (VER_OK != r) { - return r; + vf_Result result = MarkNode(stack, ctx); + if (VF_OK != result) { + return result; } - if (stack.m_node->m_sub->m_entry == stack.m_node) { + ctx->m_sub_ctx->m_path_start = path_start; + if (stack.m_node->m_sub && (stack.m_node->m_sub->m_entry == stack.m_node)) { // this jsr returns, and we need to process a node which // follows after edge start node - ctx->m_sub_ctx->m_path_fork = &stack; + // select and check the following node stack.Set(node + 1, stack.m_node->m_sub->m_ret->m_outmap.m_depth); if (VF_NODE_END_ENTRY == stack.m_node->m_type) { VF_REPORT(ctx, "Falling off the end of the code"); - return VER_ErrorBranch; + return VF_ErrorBranch; } assert(VF_NODE_CODE_RANGE == stack.m_node->m_type); - r = MarkNode(stack, ctx); - if (VER_OK != r) { - return r; + + if (path_start) { + // if this is not a top level code, + // continue path from this node + ctx->m_sub_ctx->m_path_start = &stack; + assert(!stack.m_node->m_mark + || (ctx->m_map->m_depth == stack.m_node->m_inmap.m_depth)); } - ctx->m_sub_ctx->m_path_fork = NULL; + result = MarkNode(stack, ctx); + if (VF_OK != result) { + return result; + } } - + // merge subroutines via jsr edge if (stack.m_node->m_sub) { - r = SetSubMarks(stack.m_node->m_sub, node, ctx); - if (VER_OK != r) { - return r; - } + VF_TRACE("edge", "Marking subroutines: node #" + << ctx->m_graph->GetNodeNum(node) << " is followed by #" + << ctx->m_graph->GetNodeNum(stack.m_node) + << " which belongs to the sub #" + << vf_get_sub_num(stack.m_node->m_sub, ctx)); + result = SetSubMarks(stack.m_node->m_sub, node, ctx); } - ctx->m_sub_ctx->m_path_start = path_start; - return r; + return result; } // FollowJsrEdge /** * Marks a given node and follows out edges. * @param[in] stack a reference to the stack element for the given node * @param[in] ctx a verification context - * @return VER_OK if marking was successful, an error code otherwise + * @return VF_OK if marking was successful, an error code otherwise */ static vf_Result MarkNode(vf_NodeStack &stack, vf_Context *ctx) { vf_Graph *graph = ctx->m_graph; - vf_Result r; vf_Result result = vf_check_node_stack_depth(stack.m_node, stack.m_depth, ctx); - if (result != VER_Continue) { + if (VF_Continue != result) { return result; } VF_TRACE("sub.mark", - "Processing node " << graph->GetNodeNum(stack.m_node)); + "Processing node " << graph->GetNodeNum(stack.m_node)); if (stack.m_node->m_sub) { AddSubNode(stack.m_node); } @@ -297,33 +479,32 @@ if ((VF_NODE_CODE_RANGE == stack.m_node->m_type) && (VF_INSTR_RET == stack.m_node->m_end->m_type)) { vf_Sub *sub = AddNewSub(stack.m_node, ctx->m_sub_ctx); - r = SetSubMarks(sub, stack.m_node, ctx); - if (VER_OK != r) { - return r; + result = SetSubMarks(sub, stack.m_node, ctx); + assert(ctx->m_sub_ctx->m_path_start); + if (VF_OK != result) { + return result; } - r = ResolveSubroutineEntryPoint(stack.m_node, ctx); - if (VER_OK != r) { - return r; + result = ResolveSubroutineEntryPoint(stack.m_node, ctx); + if (VF_OK != result) { + return result; } } vf_NodeStack next_stack; stack.m_next = &next_stack; for (vf_EdgeHandle outedge = stack.m_node->m_outedge; - outedge; outedge = outedge->m_outnext) { + outedge; outedge = outedge->m_outnext) { next_stack.Set(outedge->m_end, stack.m_depth); if (!vf_is_jsr_branch(outedge, ctx)) { - r = MarkNode(next_stack, ctx); + result = MarkNode(next_stack, ctx); } else { - assert(VF_NODE_CODE_RANGE == outedge->m_end->m_type); - assert(!outedge->m_outnext); - r = FollowJsrEdge(stack.m_node, next_stack, ctx); + result = FollowJsrEdge(stack.m_node, next_stack, ctx); } - if (VER_OK != r) { - return r; + if (VF_OK != result) { + return result; } } - return VER_OK; + return VF_OK; } // MarkNode @@ -334,25 +515,25 @@ vf_NodeStack bottom = { (vf_Node *) ctx->m_graph->GetStartNode(), 0, NULL }; - vf_Result r = MarkNode(bottom, ctx); - return r; + vf_Result result = MarkNode(bottom, ctx); + return result; } // vf_mark_subroutines static vf_Result AddDupCount(vf_Sub *sub, unsigned &count, vf_Context *ctx) { VF_TRACE("dupcount", - "Calculating a duplication count for a subroutine #" << - vf_get_sub_num(sub, ctx)); + "Calculating a duplication count for a subroutine #" << + vf_get_sub_num(sub, ctx)); if (ALL_BITS_SET == sub->m_dupcount) { VF_REPORT(ctx, "Found a recursive subroutine call sequence"); - return VER_ErrorJsrRecursive; + return VF_ErrorJsrRecursive; } if (!sub->m_dupcount) { sub->m_dupcount = ALL_BITS_SET; unsigned sum = 0; for (vf_EdgeHandle inedge = sub->m_entry->m_inedge; - inedge; inedge = inedge->m_innext) { + inedge; inedge = inedge->m_innext) { vf_NodeHandle node = inedge->m_start; if (vf_is_jsr_branch(inedge, ctx)) { assert(!inedge->m_outnext); @@ -363,19 +544,20 @@ } // else this call served as unconditional internal branch } else if (node->m_sub != sub) { VF_REPORT(ctx, - "A subroutine splits execution into " - "several ret instructions"); - return VER_ErrorJsrMultipleRet; + "A subroutine splits execution into " + "several ret instructions"); + return VF_ErrorJsrMultipleRet; } } sub->m_dupcount = sum; } VF_TRACE("dupcount", - "A duplication count for a subroutine #" << vf_get_sub_num(sub, - ctx) << " is " << sub->m_dupcount); + "A duplication count for a subroutine #" << vf_get_sub_num(sub, + ctx) + << " is " << sub->m_dupcount); count += sub->m_dupcount; - return VER_OK; + return VF_OK; } // AddSubDupCount static void InlineSubNodes(vf_ContextHandle ctx) @@ -385,7 +567,8 @@ for (sub = ctx->m_sub_ctx->m_sub; sub; sub = sub->m_next) { sub->m_nodes = (vf_NodeHandle *) vf_palloc(ctx->m_sub_ctx->m_pool, - sub->m_nodenum * sizeof(vf_NodeHandle)); + sub->m_nodenum * + sizeof(vf_NodeHandle)); } // populate subroutine node get the next node after the start node @@ -411,16 +594,16 @@ vf_Node *new_node = sub->m_copies = graph->AddNodes((sub->m_dupcount - 1) * sub->m_nodenum); for (unsigned node_index = 0; node_index < sub->m_nodenum; - node_index++, p_node++) { + node_index++, p_node++) { for (unsigned index = 1; index < sub->m_dupcount; - index++, new_node++) { + index++, new_node++) { *new_node = **p_node; // edges are outdated, delete them new_node->m_inedge = new_node->m_outedge = NULL; new_node->m_outnum = 0; VF_TRACE("sub.inline", - "Copied node " << graph->GetNodeNum(*p_node) - << " to " << graph->GetNodeNum(new_node)); + "Copied node " << graph->GetNodeNum(*p_node) + << " to " << graph->GetNodeNum(new_node)); } } } @@ -436,10 +619,10 @@ for (vf_SubHandle sub = ctx->m_sub_ctx->m_sub; sub; sub = sub->m_next) { ((vf_Sub *) sub)->m_following_nodes = (vf_Node **) vf_palloc(ctx->m_sub_ctx->m_pool, - sub->m_dupcount * sizeof(vf_Node *)); + sub->m_dupcount * sizeof(vf_Node *)); vf_NodeHandle sub_entry_copy = sub->m_copies + sub->m_entry->m_nodecount * (sub->m_dupcount - - 1) - 1; + 1) - 1; vf_EdgeHandle *p_next_edge = (vf_EdgeHandle *) & sub->m_entry->m_inedge; vf_Edge *inedge = (vf_Edge *) sub->m_entry->m_inedge; @@ -479,10 +662,10 @@ } vf_Node *copy = sub->m_copies; for (unsigned node_index = 0; node_index < sub->m_nodenum; - node_index++, copy += sub->m_dupcount - 1) { + node_index++, copy += sub->m_dupcount - 1) { vf_NodeHandle node = sub->m_nodes[node_index]; for (vf_EdgeHandle outedge = node->m_outedge; outedge; - outedge = outedge->m_outnext) { + outedge = outedge->m_outnext) { vf_NodeHandle end_node = outedge->m_end; vf_SubHandle end_sub = end_node->m_sub; vf_Node *c = copy; @@ -506,13 +689,13 @@ // a node next to the start node vf_Node *n = c + (sub->m_dupcount - 1); for (unsigned index = 1; - index < node->m_sub->m_dupcount; index++) { + index < node->m_sub->m_dupcount; index++) { // direct jsr edge to correspondent subroutine copy graph->NewEdge(c++, e + end_sub->m_index); // store return point assert(VF_NODE_CODE_RANGE == n->m_type); end_sub->m_following_nodes[((vf_Sub *) end_sub)-> - m_index++] = n++; + m_index++] = n++; } } } @@ -563,15 +746,15 @@ { if (NULL == ctx->m_sub_ctx->m_sub) { // subroutines are not reachable - return VER_OK; + return VF_OK; } unsigned count; unsigned nodes = 0, edges = 0; for (vf_Sub *sub = ctx->m_sub_ctx->m_sub; sub; sub = sub->m_next) { - vf_Result r = AddDupCount(sub, count, ctx); - if (VER_OK != r) { - return r; + vf_Result result = AddDupCount(sub, count, ctx); + if (VF_OK != result) { + return result; } // one copy already present in the graph nodes += (sub->m_dupcount - 1) * sub->m_nodenum; @@ -591,5 +774,5 @@ CheckDupCounts(ctx); InlineRetEdges(ctx); - return VER_OK; + return VF_OK; } // vf_inline_subroutines Index: vm/vmcore/src/verifier/ver_utils.cpp =================================================================== --- vm/vmcore/src/verifier/ver_utils.cpp (revision 542211) +++ vm/vmcore/src/verifier/ver_utils.cpp (working copy) @@ -35,25 +35,21 @@ /** * Hash table constructor. */ -vf_Hash::vf_Hash ():HASH_SIZE( 127 ), -m_free( true ) +vf_Hash::vf_Hash ():HASH_SIZE(127), m_free(true) { m_pool = vf_create_pool(); - m_hash = (vf_HashEntry**)vf_palloc( m_pool, - HASH_SIZE * - sizeof(vf_HashEntry*) ); + m_hash = (vf_HashEntry **) vf_palloc(m_pool, + HASH_SIZE * sizeof(vf_HashEntry *)); } // vf_Hash::vf_Hash /** * Hash table constructor. */ -vf_Hash::vf_Hash ( vf_Pool *pool ):HASH_SIZE( 127 ), -m_free( false ) +vf_Hash::vf_Hash (vf_Pool *pool):HASH_SIZE(127), m_free(false) { m_pool = pool; - m_hash = (vf_HashEntry**)vf_palloc( m_pool, - HASH_SIZE * - sizeof(vf_HashEntry*) ); + m_hash = (vf_HashEntry **) vf_palloc(m_pool, + HASH_SIZE * sizeof(vf_HashEntry *)); } // vf_Hash::vf_Hash /** @@ -61,18 +57,18 @@ */ vf_Hash::~vf_Hash () { - if( m_free ) { - vf_delete_pool( m_pool ); + if (m_free) { + vf_delete_pool(m_pool); } } // vf_Hash::vf_Hash /** * Checks key identity. */ -inline bool vf_Hash::CheckKey( vf_HashEntry *hash_entry, // checked hash entry - const char *key ) // checked key +inline bool vf_Hash::CheckKey(vf_HashEntry *hash_entry, // checked hash entry + const char *key) // checked key { - if( !strcmp( hash_entry->key, key ) ) { + if (!strcmp(hash_entry->key, key)) { return true; } return false; @@ -81,12 +77,12 @@ /** * Checks key identity. */ -inline bool vf_Hash::CheckKey( vf_HashEntry *hash_entry, // checked hash entry - const char *key, // checked key - size_t len ) // key length +inline bool vf_Hash::CheckKey(vf_HashEntry *hash_entry, // checked hash entry + const char *key, // checked key + size_t len) // key length { - if( !strncmp( hash_entry->key, key, len ) - && hash_entry->key[len] == '\0' ) { + if (!strncmp(hash_entry->key, key, len) + && hash_entry->key[len] == '\0') { return true; } return false; @@ -95,13 +91,13 @@ /** * Hash function. */ -inline unsigned vf_Hash::HashFunc( const char *key ) // key for hash function +inline unsigned vf_Hash::HashFunc(const char *key) // key for hash function { unsigned result = 0; unsigned char ch; - while( ( ch = ( unsigned char )( *key++ ) ) ) { - result = ( result * 16777619 ) ^ ch; + while ((ch = (unsigned char) (*key++))) { + result = (result * 16777619) ^ ch; } return result; } // vf_Hash::HashFunc( key ) @@ -109,13 +105,13 @@ /** * Hash function. */ -inline unsigned vf_Hash::HashFunc( const char *key, // key for hash function - size_t len ) // key length +inline unsigned vf_Hash::HashFunc(const char *key, // key for hash function + size_t len) // key length { unsigned result = 0; - for( unsigned index = 0; index < len; index++ ) { - result = ( result * 16777619 ) ^ ( unsigned char )( *key++ ); + for (unsigned index = 0; index < len; index++) { + result = (result * 16777619) ^ (unsigned char) (*key++); } return result; } // vf_Hash::HashFunc( key, len ) @@ -123,14 +119,14 @@ /** * Function looks up hash entry which is identical to current key. */ -inline vf_HashEntry *vf_Hash::Lookup( const char *key ) // hash key +inline vf_HashEntry *vf_Hash::Lookup(const char *key) // hash key { - assert( key ); - unsigned hash_index = HashFunc( key ); + assert(key); + unsigned hash_index = HashFunc(key); hash_index = hash_index % HASH_SIZE; vf_HashEntry *hash_entry = m_hash[hash_index]; - while( hash_entry != NULL ) { - if( CheckKey( hash_entry, key ) ) { + while (hash_entry != NULL) { + if (CheckKey(hash_entry, key)) { return hash_entry; } hash_entry = hash_entry->next; @@ -141,16 +137,16 @@ /** * Function looks up hash entry which is identical to current key. */ -inline vf_HashEntry *vf_Hash::Lookup( const char *key, // hash key - size_t len ) // key length +inline vf_HashEntry *vf_Hash::Lookup(const char *key, // hash key + size_t len) // key length { - assert( key ); - assert( len ); - unsigned hash_index = HashFunc( key, len ); + assert(key); + assert(len); + unsigned hash_index = HashFunc(key, len); hash_index = hash_index % HASH_SIZE; vf_HashEntry *hash_entry = m_hash[hash_index]; - while( hash_entry != NULL ) { - if( CheckKey( hash_entry, key, len ) ) { + while (hash_entry != NULL) { + if (CheckKey(hash_entry, key, len)) { return hash_entry; } hash_entry = hash_entry->next; @@ -161,28 +157,27 @@ /** * Function creates hash entry which is identical to current key. */ -inline vf_HashEntry *vf_Hash::NewHashEntry( const char *key ) // hash key +inline vf_HashEntry *vf_Hash::NewHashEntry(const char *key) // hash key { // lookup type in hash - assert( key ); - unsigned hash_index = HashFunc( key ); + assert(key); + unsigned hash_index = HashFunc(key); hash_index = hash_index % HASH_SIZE; vf_HashEntry *hash_entry = m_hash[hash_index]; - while( hash_entry != NULL ) { - if( CheckKey( hash_entry, key ) ) { + while (hash_entry != NULL) { + if (CheckKey(hash_entry, key)) { return hash_entry; } hash_entry = hash_entry->next; } // create key string - size_t len = strlen( key ); - char *hash_key = (char*)vf_palloc( m_pool, len + 1 ); - memcpy( hash_key, key, len ); + size_t len = strlen(key); + char *hash_key = (char *) vf_palloc(m_pool, len + 1); + memcpy(hash_key, key, len); // create hash entry - hash_entry = - (vf_HashEntry*)vf_palloc( m_pool, sizeof( vf_HashEntry ) ); + hash_entry = (vf_HashEntry *) vf_palloc(m_pool, sizeof(vf_HashEntry)); hash_entry->key = hash_key; hash_entry->next = m_hash[hash_index]; m_hash[hash_index] = hash_entry; @@ -193,29 +188,28 @@ /** * Function creates hash entry which is identical to current key. */ -inline vf_HashEntry *vf_Hash::NewHashEntry( const char *key, // hash key - size_t len ) // key length +inline vf_HashEntry *vf_Hash::NewHashEntry(const char *key, // hash key + size_t len) // key length { // lookup type in hash - assert( key ); - assert( len ); - unsigned hash_index = HashFunc( key, len ); + assert(key); + assert(len); + unsigned hash_index = HashFunc(key, len); hash_index = hash_index % HASH_SIZE; vf_HashEntry *hash_entry = m_hash[hash_index]; - while( hash_entry != NULL ) { - if( CheckKey( hash_entry, key, len ) ) { + while (hash_entry != NULL) { + if (CheckKey(hash_entry, key, len)) { return hash_entry; } hash_entry = hash_entry->next; } // create key string - char *hash_key = (char*)vf_palloc( m_pool, len + 1 ); - memcpy( hash_key, key, len ); + char *hash_key = (char *) vf_palloc(m_pool, len + 1); + memcpy(hash_key, key, len); // create hash entry - hash_entry = - (vf_HashEntry*)vf_palloc( m_pool, sizeof( vf_HashEntry ) ); + hash_entry = (vf_HashEntry *) vf_palloc(m_pool, sizeof(vf_HashEntry)); hash_entry->key = hash_key; hash_entry->next = m_hash[hash_index]; m_hash[hash_index] = hash_entry; @@ -231,10 +225,11 @@ * Type constraint collection constructor. */ vf_TypePool::vf_TypePool () - : m_method( NULL ), m_name(NULL), m_descriptor(NULL), m_restriction(NULL) +: m_method(NULL), m_name(NULL), m_descriptor(NULL), +m_restriction(NULL) { m_pool = vf_create_pool(); - m_Hash = new vf_Hash ( m_pool ); + m_Hash = new vf_Hash (m_pool); } // vf_TypePool::vf_TypePool /** @@ -243,26 +238,26 @@ vf_TypePool::~vf_TypePool () { delete m_Hash; - vf_delete_pool( m_pool ); + vf_delete_pool(m_pool); } // vf_TypePool::vf_TypePool /** * Function creates valid type which is identical to current class. */ -vf_ValidType *vf_TypePool::NewType( const char *type, // class name - size_t len ) // name length +vf_ValidType *vf_TypePool::NewType(const char *type, // class name + size_t len) // name length { vf_ValidType *result; vf_HashEntry *hash; // find type in hash - hash = m_Hash->NewHashEntry( type, len ); - if( hash->data ) { - assert( ( (vf_ValidType*)hash->data )->number == 1 ); - return (vf_ValidType*)hash->data; + hash = m_Hash->NewHashEntry(type, len); + if (hash->data) { + assert(((vf_ValidType *) hash->data)->number == 1); + return (vf_ValidType *) hash->data; } // create and set type - result = (vf_ValidType*)vf_palloc( m_pool, sizeof( vf_ValidType ) ); + result = (vf_ValidType *) vf_palloc(m_pool, sizeof(vf_ValidType)); result->number = 1; result->string[0] = hash->key; // set type in hash @@ -273,11 +268,11 @@ static int -vf_type_string_compare( const void *type_string1, const void *type_string2 ) +vf_type_string_compare(const void *type_string1, const void *type_string2) { - if( type_string1 < type_string2 ) { + if (type_string1 < type_string2) { return -1; - } else if( type_string1 > type_string2 ) { + } else if (type_string1 > type_string2) { return 1; } else { return 0; @@ -287,37 +282,37 @@ /** * Function creates valid type which is identical to an element of a given array type. */ -vf_ValidType *vf_TypePool::NewArrayElemType( vf_ValidType *array ) // array type +vf_ValidType *vf_TypePool::NewArrayElemType(vf_ValidType *array) // array type { vf_ValidType *result; vf_HashEntry *hash; // lookup type in hash - hash = m_Hash->NewHashEntry( &array->string[0][1] ); - if( array->number == 1 && hash->data ) { - assert( ( (vf_ValidType*)hash->data )->number == 1 ); - return (vf_ValidType*)hash->data; + hash = m_Hash->NewHashEntry(&array->string[0][1]); + if (array->number == 1 && hash->data) { + assert(((vf_ValidType *) hash->data)->number == 1); + return (vf_ValidType *) hash->data; } // create and set type - result = (vf_ValidType*)vf_palloc( m_pool, - sizeof( vf_ValidType ) + - ( array->number - - 1 ) * sizeof( const char * ) ); + result = (vf_ValidType *) vf_palloc(m_pool, + sizeof(vf_ValidType) + + (array->number - + 1) * sizeof(const char *)); result->number = array->number; // set sting type result->string[0] = hash->key; - if( result->number == 1 ) { + if (result->number == 1) { // set type in hash hash->data = result; } else { // set other string types - for( unsigned index = 1; index < array->number; index++ ) { - hash = m_Hash->NewHashEntry( &array->string[index][1] ); + for (unsigned index = 1; index < array->number; index++) { + hash = m_Hash->NewHashEntry(&array->string[index][1]); result->string[index] = hash->key; } // sort valid type - qsort( &result->string[0], result->number, sizeof( const char * ), - vf_type_string_compare ); + qsort(&result->string[0], result->number, sizeof(const char *), + vf_type_string_compare); } return result; @@ -326,17 +321,17 @@ /** * Dumps constraint collection in stream. */ -void vf_TypePool::DumpTypeConstraints( ostream *out ) // output stream +void vf_TypePool::DumpTypeConstraints(ostream *out) // output stream { - if( out == NULL ) { + if (out == NULL) { out = &cerr; } - for( vf_TypeConstraint *constraint = m_restriction; - constraint; constraint = constraint->m_next ) { + for (vf_TypeConstraint *constraint = m_restriction; + constraint; constraint = constraint->m_next) { *out << "CONSTRAINT: have \"" << constraint->m_source << "\" need \"" << constraint->m_target << "\" for method " - << class_get_name( method_get_class( m_method ) ) << "." + << class_get_name(method_get_class(m_method)) << "." << m_name << m_descriptor << endl; } } // vf_TypePool::DumpTypeConstraints @@ -352,7 +347,7 @@ /** * Sets current context method. */ -void vf_TypePool::SetMethod( vf_ContextHandle ctx ) +void vf_TypePool::SetMethod(vf_ContextHandle ctx) { // set method context m_method = ctx->m_method; @@ -363,29 +358,28 @@ /** * Sets restriction from target class to source class. */ -void vf_TypePool::SetRestriction( const char *target, // target class name - const char *source, // source class name - unsigned short index, // constant pool index - vf_CheckConstraint check_type ) // constraint check type +void vf_TypePool::SetRestriction(const char *target, // target class name + const char *source, // source class name + unsigned short index, // constant pool index + vf_CheckConstraint check_type) // constraint check type { vf_TypeConstraint *restriction; // lookup restriction - for( restriction = m_restriction; - restriction; restriction = restriction->m_next ) { - if( restriction->m_target == target + for (restriction = m_restriction; + restriction; restriction = restriction->m_next) { + if (restriction->m_target == target && restriction->m_source == source && restriction->m_index == index - && restriction->m_check_type == check_type ) { + && restriction->m_check_type == check_type) { // this restriction is already present return; } } // set restriction - restriction = (vf_TypeConstraint*)vf_palloc( m_pool, - sizeof - ( vf_TypeConstraint ) ); + restriction = (vf_TypeConstraint *) vf_palloc(m_pool, + sizeof(vf_TypeConstraint)); restriction->m_target = target; restriction->m_source = source; restriction->m_index = index; @@ -397,36 +391,36 @@ m_restriction = restriction; // trace restriction - if( index ) { - VF_TRACE( "constraint", "CONSTRAINT: for class \"" - << class_get_name( method_get_class( m_method ) ) - << "\" CP index #" << index << " check access: have \"" - << source << "\" need \"" << target << "\" for method " - << class_get_name( method_get_class( m_method ) ) << "." - << m_name << m_descriptor ); + if (index) { + VF_TRACE("constraint", "CONSTRAINT: for class \"" + << class_get_name(method_get_class(m_method)) + << "\" CP index #" << index << " check access: have \"" + << source << "\" need \"" << target << "\" for method " + << class_get_name(method_get_class(m_method)) << "." + << m_name << m_descriptor); } else { - VF_TRACE( "constraint", "CONSTRAINT: have \"" - << source << "\" need \"" << target << "\" for method " - << class_get_name( method_get_class( m_method ) ) << "." - << m_name << m_descriptor ); + VF_TRACE("constraint", "CONSTRAINT: have \"" + << source << "\" need \"" << target << "\" for method " + << class_get_name(method_get_class(m_method)) << "." + << m_name << m_descriptor); } } // vf_TypePool::SetRestriction /** * Checks types and create constraints if it's necessarily. */ -bool vf_TypePool::CheckTypes( vf_ValidType *required, // required type - vf_ValidType *available, // available type - unsigned short index, // constant pool index - vf_CheckConstraint check_type ) // constraint check type +bool vf_TypePool::CheckTypes(vf_ValidType *required, // required type + vf_ValidType *available, // available type + unsigned short index, // constant pool index + vf_CheckConstraint check_type) // constraint check type { unsigned index1, index2; - switch ( check_type ) { + switch (check_type) { case VF_CHECK_ARRAY: // provide array check // check if available types are array - for( index1 = 0; index1 < available->number; index1++ ) { - if( available->string[index1][0] != '[' ) { + for (index1 = 0; index1 < available->number; index1++) { + if (available->string[index1][0] != '[') { // type isn't array, return error return true; } @@ -434,10 +428,10 @@ return false; case VF_CHECK_REF_ARRAY: // provide reference array check - for( index1 = 0; index1 < available->number; index1++ ) { - if( available->string[index1][0] == '[' - && ( available->string[index1][1] == '[' - || available->string[index1][1] == 'L' ) ) { + for (index1 = 0; index1 < available->number; index1++) { + if (available->string[index1][0] == '[' + && (available->string[index1][1] == '[' + || available->string[index1][1] == 'L')) { // type is reference array, continue loop continue; } else { @@ -449,19 +443,18 @@ case VF_CHECK_EQUAL: // check equivalence // check if available types are equal - return !vf_is_types_equal( required, available ); + return !vf_is_types_equal(required, available); case VF_CHECK_PARAM: // check method invocation conversion case VF_CHECK_ASSIGN: // check assignment conversion case VF_CHECK_ASSIGN_WEAK: // check weak assignment conversion // compare types - for( index1 = 0; index1 < required->number; index1++ ) { - for( index2 = 0; index2 < available->number; index2++ ) { + for (index1 = 0; index1 < required->number; index1++) { + for (index2 = 0; index2 < available->number; index2++) { // set constraint for differing types - if( required->string[index1] != available->string[index2] ) { - SetRestriction( required->string[index1], - available->string[index2], 0, - check_type ); + if (required->string[index1] != available->string[index2]) { + SetRestriction(required->string[index1], + available->string[index2], 0, check_type); } } } @@ -469,69 +462,67 @@ case VF_CHECK_ACCESS_FIELD: // check field access // compare types - assert( required->number == 1 ); - for( index1 = 0; index1 < available->number; index1++ ) { + assert(required->number == 1); + for (index1 = 0; index1 < available->number; index1++) { // set access and type constraints for differing types - if( required->string[0] != available->string[index1] ) { - SetRestriction( required->string[0], - available->string[index1], 0, - VF_CHECK_ASSIGN ); + if (required->string[0] != available->string[index1]) { + SetRestriction(required->string[0], + available->string[index1], 0, VF_CHECK_ASSIGN); } - SetRestriction( required->string[0], available->string[index1], - index, VF_CHECK_ACCESS_FIELD ); + SetRestriction(required->string[0], available->string[index1], + index, VF_CHECK_ACCESS_FIELD); } return false; case VF_CHECK_ACCESS_METHOD: // check method access // compare types - assert( required->number == 1 ); - for( index1 = 0; index1 < available->number; index1++ ) { + assert(required->number == 1); + for (index1 = 0; index1 < available->number; index1++) { // set access and type constraints for differing types - if( required->string[0] != available->string[index1] ) { - SetRestriction( required->string[0], - available->string[index1], 0, - VF_CHECK_PARAM ); + if (required->string[0] != available->string[index1]) { + SetRestriction(required->string[0], + available->string[index1], 0, VF_CHECK_PARAM); } - SetRestriction( required->string[0], available->string[index1], - index, VF_CHECK_ACCESS_METHOD ); + SetRestriction(required->string[0], available->string[index1], + index, VF_CHECK_ACCESS_METHOD); } return false; case VF_CHECK_DIRECT_SUPER: - if( required->number == 1 && available->number == 1 ) { - if( required->string[0] != available->string[0] ) { - SetRestriction( required->string[0], available->string[0], - 0, VF_CHECK_DIRECT_SUPER ); + if (required->number == 1 && available->number == 1) { + if (required->string[0] != available->string[0]) { + SetRestriction(required->string[0], available->string[0], + 0, VF_CHECK_DIRECT_SUPER); } return false; } return true; case VF_CHECK_INVOKESPECIAL: - assert( required->number == 1 ); - for( index1 = 0; index1 < available->number; index1++ ) { - SetRestriction( required->string[0], available->string[index1], - index, VF_CHECK_INVOKESPECIAL ); + assert(required->number == 1); + for (index1 = 0; index1 < available->number; index1++) { + SetRestriction(required->string[0], available->string[index1], + index, VF_CHECK_INVOKESPECIAL); } return false; default: - VF_DIE( "CompareTypes: unknown check type in switch" ); + VF_DIE("CompareTypes: unknown check type in switch"); return true; } // unreachable instr - assert( 0 ); + assert(0); } // vf_TypePool::CheckTypes /** * Function merges two valid types. * Function returns NULL if vector wasn't merged. */ -vf_ValidType *vf_TypePool::MergeTypes( vf_ValidType *first, // first merged type - vf_ValidType *second ) // second merged type +vf_ValidType *vf_TypePool::MergeTypes(vf_ValidType *first, // first merged type + vf_ValidType *second) // second merged type { // check null reference - if( first == NULL ) { + if (first == NULL) { return second; - } else if( second == NULL ) { + } else if (second == NULL) { return first; } // count differ types @@ -539,42 +530,41 @@ unsigned index2; unsigned last_found; unsigned count = first->number + second->number; - for( index1 = last_found = 0; index1 < first->number; index1++ ) { + for (index1 = last_found = 0; index1 < first->number; index1++) { // find first type in second types - for( index2 = last_found; index2 < second->number; index2++ ) { - if( first->string[index1] == second->string[index2] ) { + for (index2 = last_found; index2 < second->number; index2++) { + if (first->string[index1] == second->string[index2]) { // found first type last_found = index2 + 1; count--; break; - } else if( first->string[index1] < second->string[index2] ) { + } else if (first->string[index1] < second->string[index2]) { break; } } } - if( first->number == second->number && count == first->number ) { + if (first->number == second->number && count == first->number) { // types are equal, no need to merge return NULL; } // create merged type - vf_ValidType *type = (vf_ValidType*)vf_palloc( m_pool, - sizeof( vf_ValidType ) - + ( count - - 1 ) * - sizeof - ( const char * ) ); + vf_ValidType *type = (vf_ValidType *) vf_palloc(m_pool, + sizeof(vf_ValidType) + + (count - + 1) * + sizeof(const char *)); type->number = count; // set type in ascending order of types string index1 = index2 = 0; - for( unsigned index = 0; index < count; index++ ) { - if( index1 >= first->number ) { + for (unsigned index = 0; index < count; index++) { + if (index1 >= first->number) { type->string[index] = second->string[index2++]; - } else if( index2 >= second->number ) { + } else if (index2 >= second->number) { type->string[index] = first->string[index1++]; - } else if( first->string[index1] < second->string[index2] ) { + } else if (first->string[index1] < second->string[index2]) { type->string[index] = first->string[index1++]; - } else if( first->string[index1] > second->string[index2] ) { + } else if (first->string[index1] > second->string[index2]) { type->string[index] = second->string[index2++]; } else { type->string[index] = first->string[index1++]; @@ -591,46 +581,44 @@ /** * Sets constraint for method in class loader verify data. */ -static void -vf_set_class_constraint( vf_TypeConstraint *collection, // constraint for the class - vf_ContextHandle ctx ) // verification context +static void vf_set_class_constraint(vf_TypeConstraint *collection, // constraint for the class + vf_ContextHandle ctx) // verification context { // get class loader of current class - classloader_handler class_loader = class_get_class_loader( ctx->m_class ); + classloader_handler class_loader = class_get_class_loader(ctx->m_class); // lock data modification - cl_acquire_lock( class_loader ); + cl_acquire_lock(class_loader); vf_ClassLoaderData *cl_data = - (vf_ClassLoaderData*) cl_get_verify_data_ptr( class_loader ); + (vf_ClassLoaderData *) cl_get_verify_data_ptr(class_loader); // create class loader data - if( cl_data == NULL ) { + if (cl_data == NULL) { vf_Pool *new_pool = vf_create_pool(); - cl_data = (vf_ClassLoaderData*) vf_palloc( new_pool, - sizeof - ( vf_ClassLoaderData ) ); + cl_data = (vf_ClassLoaderData *) vf_palloc(new_pool, + sizeof + (vf_ClassLoaderData)); cl_data->pool = new_pool; - cl_data->string = new vf_Hash ( new_pool ); + cl_data->string = new vf_Hash (new_pool); // set verify data for class loader - cl_set_verify_data_ptr( class_loader, cl_data ); + cl_set_verify_data_ptr(class_loader, cl_data); } vf_Pool *pool = cl_data->pool; vf_Hash *hash = cl_data->string; // create class constraints collection vf_TypeConstraint *save_collection = NULL; - for( vf_TypeConstraint *restriction = collection; - restriction; restriction = restriction->m_next ) { + for (vf_TypeConstraint *restriction = collection; + restriction; restriction = restriction->m_next) { // create constraint - vf_TypeConstraint *constraint = - (vf_TypeConstraint*)vf_palloc( pool, - sizeof( vf_TypeConstraint ) ); + vf_TypeConstraint *constraint = (vf_TypeConstraint *) vf_palloc(pool, + sizeof + (vf_TypeConstraint)); // create entry in string pool for target class - vf_HashEntry *hash_entry = - hash->NewHashEntry( restriction->m_target ); + vf_HashEntry *hash_entry = hash->NewHashEntry(restriction->m_target); constraint->m_target = hash_entry->key; // create entry in string pool for checked class - hash_entry = hash->NewHashEntry( restriction->m_source ); + hash_entry = hash->NewHashEntry(restriction->m_source); constraint->m_source = hash_entry->key; // set only method name and descriptor due to // method handle could be changed during class preparation phase @@ -640,26 +628,25 @@ constraint->m_next = save_collection; save_collection = constraint; } - assert( save_collection ); + assert(save_collection); // save method verify data - assert( class_get_verify_data_ptr( ctx->m_class ) == NULL ); - class_set_verify_data_ptr( ctx->m_class, save_collection ); + assert(class_get_verify_data_ptr(ctx->m_class) == NULL); + class_set_verify_data_ptr(ctx->m_class, save_collection); // unlock data modification - cl_release_lock( class_loader ); + cl_release_lock(class_loader); } // vf_set_class_constraint /** * Receives class by given class name, loads it if it's needed. */ -static class_handler -vf_resolve_class( const char *name, // resolved class name - bool need_load, // load flag - vf_ContextHandle ctx ) // verification context +static class_handler vf_resolve_class(const char *name, // resolved class name + bool need_load, // load flag + vf_ContextHandle ctx) // verification context { // get class name - if( name[0] == 'L' ) { + if (name[0] == 'L') { // class is class, skip 'L' name++; } else { @@ -667,12 +654,12 @@ unsigned index = 0; do { index++; - } while( name[index] == '[' ); - if( name[index] == 'L' ) { + } while (name[index] == '['); + if (name[index] == 'L') { // array of objects, construct array name - size_t len = strlen( name ); - char *buf = (char*)STD_ALLOCA( len + 2 ); - memcpy( buf, name, len ); + size_t len = strlen(name); + char *buf = (char *) STD_ALLOCA(len + 2); + memcpy(buf, name, len); buf[len] = ';'; buf[len + 1] = '\0'; name = buf; @@ -680,16 +667,16 @@ } // get class loader - classloader_handler class_loader = class_get_class_loader( ctx->m_class ); + classloader_handler class_loader = class_get_class_loader(ctx->m_class); // receive class class_handler result; - if( need_load ) { + if (need_load) { // trace verifier loads - VF_TRACE( "load", "verify load: class " << name ); - result = cl_load_class( class_loader, name ); + VF_TRACE("load", "verify load: class " << name); + result = cl_load_class(class_loader, name); } else { - result = cl_get_class( class_loader, name ); + result = cl_get_class(class_loader, name); } return result; @@ -698,13 +685,12 @@ /** * Checks if target class is super class of source class. */ -static inline bool -vf_is_super_class( class_handler source, // checked class - class_handler target ) // super class +static inline bool vf_is_super_class(class_handler source, // checked class + class_handler target) // super class { // check super class - for( ; source; source = class_get_super_class( source ) ) { - if( class_is_same_class( source, target ) ) { + for (; source; source = class_get_super_class(source)) { + if (class_is_same_class(source, target)) { return true; } } @@ -714,22 +700,21 @@ /** * Checks if target class is super interface of source class. */ -static inline bool -vf_is_super_interface( class_handler source, // checked class - class_handler target ) // super interface +static inline bool vf_is_super_interface(class_handler source, // checked class + class_handler target) // super interface { - assert( class_is_interface_( target ) ); + assert(class_is_interface_(target)); // classes are equal - if( class_is_same_class( source, target ) ) { + if (class_is_same_class(source, target)) { return true; } // check super interface - for( ; source; source = class_get_super_class( source ) ) { - for( unsigned index = 0; - index < class_get_superinterface_number( source ); index++ ) { - if( vf_is_super_interface - ( class_get_superinterface - ( source, ( unsigned short )index ), target ) ) { + for (; source; source = class_get_super_class(source)) { + for (unsigned index = 0; + index < class_get_superinterface_number(source); index++) { + if (vf_is_super_interface + (class_get_superinterface + (source, (unsigned short) index), target)) { return true; } } @@ -740,23 +725,22 @@ /** * Checks method invocation conversion between source ans target classes. */ -static bool -vf_is_param_valid( class_handler source, // checked class - class_handler target ) // required class +static bool vf_is_param_valid(class_handler source, // checked class + class_handler target) // required class { // check if target class is array - if( class_is_array( target ) && class_is_array( source ) ) { + if (class_is_array(target) && class_is_array(source)) { // get array element classes - return vf_is_param_valid( class_get_array_element_class( source ), - class_get_array_element_class( target ) ); + return vf_is_param_valid(class_get_array_element_class(source), + class_get_array_element_class(target)); } // check widening reference conversions - if( class_is_interface_( target ) ) { + if (class_is_interface_(target)) { // target class is interface - return vf_is_super_interface( source, target ); + return vf_is_super_interface(source, target); } else { // target class is class - return vf_is_super_class( source, target ); + return vf_is_super_class(source, target); } } // vf_is_param_valid @@ -766,30 +750,27 @@ * and methods are the same name and signature, function returns 1. * If methods have different return types, function returns 0. */ -static inline bool -vf_check_interface_methods( class_handler class1, // first interface class - class_handler class2 ) // second interface class +static inline bool vf_check_interface_methods(class_handler class1, // first interface class + class_handler class2) // second interface class { - assert( class_is_interface_( class1 ) ); - assert( class_is_interface_( class2 ) ); + assert(class_is_interface_(class1)); + assert(class_is_interface_(class2)); // check interfaces methods - for( unsigned index = 0; index < class_get_method_number( class2 ); - index++ ) { - method_handler method1 = class_get_method( class2, index ); - for( unsigned count = 0; count < class_get_method_number( class1 ); - count++ ) { - method_handler method2 = class_get_method( class1, count ); - if( !strcmp - ( method_get_name( method1 ), method_get_name( method2 ) ) ) { + for (unsigned index = 0; index < class_get_method_number(class2); index++) { + method_handler method1 = class_get_method(class2, index); + for (unsigned count = 0; count < class_get_method_number(class1); + count++) { + method_handler method2 = class_get_method(class1, count); + if (!strcmp(method_get_name(method1), method_get_name(method2))) { // interfaces have methods with the same name - const char *sig1 = method_get_descriptor( method1 ); - const char *sig2 = method_get_descriptor( method2 ); - char *end_params = (char*)strrchr( sig1, ')' ); - unsigned len = ( unsigned )( end_params - sig1 + 1 ); - if( !memcmp( sig1, sig2, len ) ) { + const char *sig1 = method_get_descriptor(method1); + const char *sig2 = method_get_descriptor(method2); + char *end_params = (char *) strrchr(sig1, ')'); + unsigned len = (unsigned) (end_params - sig1 + 1); + if (!memcmp(sig1, sig2, len)) { // methods arguments are the same - if( strcmp( &sig1[len], &sig2[len] ) ) { + if (strcmp(&sig1[len], &sig2[len])) { // methods have different return types return false; } @@ -804,32 +785,30 @@ /** * Checks casting conversion between classes. */ -static bool -vf_is_checkcast_valid( class_handler source, // checked class - class_handler target ) // required class +static bool vf_is_checkcast_valid(class_handler source, // checked class + class_handler target) // required class { // check if target class and source class are array - if( class_is_array( target ) && class_is_array( source ) ) { + if (class_is_array(target) && class_is_array(source)) { // get array element classes - return vf_is_checkcast_valid( class_get_array_element_class( source ), - class_get_array_element_class - ( target ) ); + return vf_is_checkcast_valid(class_get_array_element_class(source), + class_get_array_element_class(target)); } // check widening reference conversions - if( vf_is_param_valid( source, target ) ) { + if (vf_is_param_valid(source, target)) { return true; } // check narrowing reference conversions - if( class_is_interface_( source ) ) { + if (class_is_interface_(source)) { // source class is interface - if( class_is_interface_( target ) ) { + if (class_is_interface_(target)) { // target class is interface - return vf_check_interface_methods( source, target ); + return vf_check_interface_methods(source, target); } else { // target class is class - if( class_is_final_( target ) ) { + if (class_is_final_(target)) { // target class is final - return vf_is_super_interface( target, source ); + return vf_is_super_interface(target, source); } else { // target class isn't final return true; @@ -837,19 +816,19 @@ } } else { // source class is class - if( !memcmp( class_get_name( source ), "java/lang/Object", 17 ) ) { + if (!memcmp(class_get_name(source), "java/lang/Object", 17)) { // source class is Object return true; } - if( class_is_interface_( target ) ) { + if (class_is_interface_(target)) { // target class is interface - if( !class_is_final_( source ) ) { + if (!class_is_final_(source)) { // super class isn't final return true; } } else { // target class is class - return vf_is_super_class( target, source ); + return vf_is_super_class(target, source); } } return false; @@ -913,61 +892,60 @@ * * Test is invalid. */ -static bool -vf_is_assign_valid( class_handler source, // checked class - class_handler target, // required class - bool is_strict ) // strict condition flag +static bool vf_is_assign_valid(class_handler source, // checked class + class_handler target, // required class + bool is_strict) // strict condition flag { // check assignment reference conversions - if( class_is_array( source ) ) { + if (class_is_array(source)) { // source class is array - if( class_is_interface_( target ) ) { + if (class_is_interface_(target)) { // target class is interface - if( !memcmp( class_get_name( target ), "java/lang/Cloneable", 20 ) - || !memcmp( class_get_name( target ), "java/io/Serializable", - 21 ) ) { + if (!memcmp(class_get_name(target), "java/lang/Cloneable", 20) + || !memcmp(class_get_name(target), "java/io/Serializable", + 21)) { // target class is Cloneable or Serializable return true; } } else { // target class is class - if( !memcmp( class_get_name( target ), "java/lang/Object", 17 ) ) { + if (!memcmp(class_get_name(target), "java/lang/Object", 17)) { // target class is object return true; - } else if( class_is_array( target ) ) { + } else if (class_is_array(target)) { // get array element classes return - vf_is_assign_valid( class_get_array_element_class - ( source ), - class_get_array_element_class - ( target ), true ); + vf_is_assign_valid(class_get_array_element_class + (source), + class_get_array_element_class + (target), true); } } - } else if( class_is_interface_( source ) ) { + } else if (class_is_interface_(source)) { // source class is interface - if( class_is_interface_( target ) ) { + if (class_is_interface_(target)) { // target class is interface - return vf_is_super_interface( source, target ); + return vf_is_super_interface(source, target); } else { // target class is class - if( !memcmp( class_get_name( target ), "java/lang/Object", 17 ) ) { + if (!memcmp(class_get_name(target), "java/lang/Object", 17)) { // target class is object return true; } - if( !is_strict ) { + if (!is_strict) { /** * Strict correspondence is used only for element array compare. * Compare interface and class is weaker because it's impossible to * create pure interface. */ - return vf_is_super_interface( target, source ); + return vf_is_super_interface(target, source); } } } else { // source class is class - bool valid = vf_is_param_valid( source, target ); - if( !valid && !is_strict ) { - valid = vf_is_super_class( target, source ); + bool valid = vf_is_param_valid(source, target); + if (!valid && !is_strict) { + valid = vf_is_super_class(target, source); } return valid; } @@ -977,88 +955,85 @@ /** * Checks conversions between classes. */ -static bool -vf_is_valid( class_handler source, // checked class - class_handler target, // required class - class_handler current, // current class - unsigned check ) // checked class type +static bool vf_is_valid(class_handler source, // checked class + class_handler target, // required class + class_handler current, // current class + unsigned check) // checked class type { - switch ( check ) { + switch (check) { case VF_CHECK_PARAM: // method invocation conversion - return vf_is_param_valid( source, target ); + return vf_is_param_valid(source, target); case VF_CHECK_ASSIGN: // assignment conversion - return vf_is_assign_valid( source, target, true ); + return vf_is_assign_valid(source, target, true); case VF_CHECK_ASSIGN_WEAK: // weak assignment conversion - return vf_is_assign_valid( source, target, false ); + return vf_is_assign_valid(source, target, false); case VF_CHECK_CAST: // casting conversion - return vf_is_checkcast_valid( source, target ); + return vf_is_checkcast_valid(source, target); case VF_CHECK_SUPER: // check if target is super class of source - return vf_is_super_class( source, target ); + return vf_is_super_class(source, target); case VF_CHECK_DIRECT_SUPER: // check if target is a direct super class of source - return class_is_same_class( class_get_super_class( source ), target ); + return class_is_same_class(class_get_super_class(source), target); case VF_CHECK_ACCESS_FIELD: // protected field access case VF_CHECK_ACCESS_METHOD: // protected method access - return vf_is_super_class( source, current ); + return vf_is_super_class(source, current); case VF_CHECK_INVOKESPECIAL: // check object for invokespecial instruction - return vf_is_super_class( source, current ) - && vf_is_super_class( current, target ); + return vf_is_super_class(source, current) + && vf_is_super_class(current, target); } - VF_DIE( "vf_is_valid: invalid check type" ); + VF_DIE("vf_is_valid: invalid check type"); return false; } // vf_is_valid /** * Sets verifier error. */ -static inline void -vf_set_error( unsigned check, // failed check - vf_Context *ctx ) // verification context +static inline void vf_set_error(unsigned check, // failed check + vf_Context *ctx) // verification context { - switch ( check ) { + switch (check) { case VF_CHECK_PARAM: - VF_REPORT( ctx, "Incompatible argument for function" ); + VF_REPORT(ctx, "Incompatible argument for function"); return; case VF_CHECK_ASSIGN: - VF_REPORT( ctx, "Incompatible types for field assignment" ); + VF_REPORT(ctx, "Incompatible types for field assignment"); return; case VF_CHECK_ASSIGN_WEAK: - VF_REPORT( ctx, "Incompatible types for array assignment" ); + VF_REPORT(ctx, "Incompatible types for array assignment"); return; case VF_CHECK_SUPER: - VF_REPORT( ctx, "Exception class not a subclass of Throwable" ); + VF_REPORT(ctx, "Exception class not a subclass of Throwable"); return; case VF_CHECK_ACCESS_FIELD: - VF_REPORT( ctx, "Bad access to protected field" ); + VF_REPORT(ctx, "Bad access to protected field"); return; case VF_CHECK_ACCESS_METHOD: - VF_REPORT( ctx, "Bad access to protected method" ); + VF_REPORT(ctx, "Bad access to protected method"); return; case VF_CHECK_DIRECT_SUPER: - VF_REPORT( ctx, "Call to wrong initialization method" ); + VF_REPORT(ctx, "Call to wrong initialization method"); return; case VF_CHECK_INVOKESPECIAL: - VF_REPORT( ctx, "Incompatible object argument for invokespecial" ); + VF_REPORT(ctx, "Incompatible object argument for invokespecial"); return; } - VF_DIE( "vf_set_error: unknown check type" ); + VF_DIE("vf_set_error: unknown check type"); } // vf_set_error /** * Checks some constraints without loading of needed classes. */ -static inline vf_Result -vf_check_without_loading( vf_TypeConstraint *restriction, // checked constraint - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_without_loading(vf_TypeConstraint *restriction, // checked constraint + vf_Context *ctx) // verification context { - switch ( restriction->m_check_type ) { + switch (restriction->m_check_type) { case VF_CHECK_SUPER: /** * Extension for class java/lang/Object doesn't check * because it's expected all references extend it. */ - if( restriction->m_target == ctx->m_vtype.m_object->string[0] ) { + if (restriction->m_target == ctx->m_vtype.m_object->string[0]) { // no need to check - return VER_OK; + return VF_OK; } break; @@ -1067,9 +1042,9 @@ * Extension for class java/lang/Object doesn't check * because it's expected all references extend it. */ - if( restriction->m_target == ctx->m_vtype.m_object->string[0] ) { + if (restriction->m_target == ctx->m_vtype.m_object->string[0]) { // no need to check - return VER_OK; + return VF_OK; } /** @@ -1077,12 +1052,12 @@ * because it's expected all arrays extend it. * Just check is source array. */ - if( restriction->m_target == ctx->m_vtype.m_array->string[0] + if (restriction->m_target == ctx->m_vtype.m_array->string[0] && restriction->m_source[0] == '[' - && ( restriction->m_source[1] == '[' - || restriction->m_source[1] == 'L' ) ) { + && (restriction->m_source[1] == '[' + || restriction->m_source[1] == 'L')) { // no need to check - return VER_OK; + return VF_OK; } /** @@ -1090,53 +1065,51 @@ * interfaces doesn't check because it's expected all arrays extend it. * Just check is source array. */ - if( ( restriction->m_target == ctx->m_vtype.m_clone->string[0] - || restriction->m_target == - ctx->m_vtype.m_serialize->string[0] ) - && restriction->m_source[0] == '[' ) { + if ((restriction->m_target == ctx->m_vtype.m_clone->string[0] + || restriction->m_target == ctx->m_vtype.m_serialize->string[0]) + && restriction->m_source[0] == '[') { // no need to check - return VER_OK; + return VF_OK; } /** * If method invocation conversion takes place between array and * non-array reference, return error. */ - if( ( restriction->m_target[0] != '[' - && restriction->m_source[0] == '[' ) - || ( restriction->m_target[0] != '[' - && restriction->m_source[0] == '[' ) ) - { - vf_set_error( VF_CHECK_PARAM, ctx ); - return VER_ErrorIncompatibleArgument; + if ((restriction->m_target[0] != '[' + && restriction->m_source[0] == '[') + || (restriction->m_target[0] != '[' + && restriction->m_source[0] == '[')) { + vf_set_error(VF_CHECK_PARAM, ctx); + return VF_ErrorIncompatibleArgument; } break; case VF_CHECK_ASSIGN_WEAK: // check assignment weak reference conversions - if( restriction->m_source[0] == 'L' ) { - return VER_OK; + if (restriction->m_source[0] == 'L') { + return VF_OK; } - assert( restriction->m_source[0] == '[' ); + assert(restriction->m_source[0] == '['); // go to the next check... case VF_CHECK_ASSIGN: // check assignment reference conversions - if( restriction->m_source[0] == '[' ) { + if (restriction->m_source[0] == '[') { // source class is array - if( !memcmp( restriction->m_target, "Ljava/lang/Cloneable", 21 ) - || !memcmp( restriction->m_target, "Ljava/io/Serializable", - 22 ) ) { + if (!memcmp(restriction->m_target, "Ljava/lang/Cloneable", 21) + || !memcmp(restriction->m_target, "Ljava/io/Serializable", + 22)) { // target class is java/lang/Cloneable // or java/lang/Serializable interface - return VER_OK; - } else if( restriction->m_target == - ctx->m_vtype.m_object->string[0] ) { + return VF_OK; + } else if (restriction->m_target == + ctx->m_vtype.m_object->string[0]) { // target class is java/lang/Object - return VER_OK; - } else if( restriction->m_target[0] != '[' ) { + return VF_OK; + } else if (restriction->m_target[0] != '[') { // target class isn't array class - vf_set_error( restriction->m_check_type, ctx ); - return VER_ErrorIncompatibleArgument; + vf_set_error(restriction->m_check_type, ctx); + return VF_ErrorIncompatibleArgument; } } break; @@ -1145,7 +1118,7 @@ break; } // need to load classes for check - return VER_ClassNotLoaded; + return VF_ClassNotLoaded; } // vf_check_without_loading /** @@ -1153,29 +1126,28 @@ * If any class isn't loaded, function returns unloaded error * to store restriction to the class for future constraint check. */ -static inline vf_Result -vf_check_constraint( vf_TypeConstraint *restriction, // checked constraint - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_constraint(vf_TypeConstraint *restriction, // checked constraint + vf_Context *ctx) // verification context { /** * Try to provide some checks without classes loading */ - if( !ctx->m_verify_all ) { - vf_Result result = vf_check_without_loading( restriction, ctx ); - if( result != VER_ClassNotLoaded ) { + if (!ctx->m_verify_all) { + vf_Result result = vf_check_without_loading(restriction, ctx); + if (result != VF_ClassNotLoaded) { // no need to check return result; } } // get target class handler class_handler target = - vf_resolve_class( restriction->m_target, false, ctx ); + vf_resolve_class(restriction->m_target, false, ctx); // get checked class class_handler source = - vf_resolve_class( restriction->m_source, false, ctx ); + vf_resolve_class(restriction->m_source, false, ctx); // check classes are loaded? - if( !target || !source ) { - return VER_ClassNotLoaded; + if (!target || !source) { + return VF_ClassNotLoaded; } /** @@ -1185,18 +1157,17 @@ * To be compatible with those applications we should do full constraint * checks only if -Xverify:all option is present in command line. */ - if( !ctx->m_verify_all && class_is_interface_( target ) ) { + if (!ctx->m_verify_all && class_is_interface_(target)) { // skip constraint check - return VER_OK; + return VF_OK; } // check restriction - if( !vf_is_valid - ( source, target, ctx->m_class, restriction->m_check_type ) ) { + if (!vf_is_valid(source, target, ctx->m_class, restriction->m_check_type)) { // return error - vf_set_error( restriction->m_check_type, ctx ); - return VER_ErrorIncompatibleArgument; + vf_set_error(restriction->m_check_type, ctx); + return VF_ErrorIncompatibleArgument; } - return VER_OK; + return VF_OK; } // vf_check_constraint /** @@ -1205,110 +1176,106 @@ * function return unloaded error to store restriction to the class * for future constraint check. */ -vf_Result -vf_check_access_constraint( const char *super_name, // name of super class - const char *instance_name, // name of instance class - unsigned short index, // constant pool index - vf_CheckConstraint check_type, // access check type - vf_Context *ctx ) // verification context +vf_Result vf_check_access_constraint(const char *super_name, // name of super class + const char *instance_name, // name of instance class + unsigned short index, // constant pool index + vf_CheckConstraint check_type, // access check type + vf_Context *ctx) // verification context { // get class handler of super class - class_handler super_class = vf_resolve_class( super_name, false, ctx ); - if( !super_class || !vf_is_super_class( ctx->m_class, super_class ) ) { + class_handler super_class = vf_resolve_class(super_name, false, ctx); + if (!super_class || !vf_is_super_class(ctx->m_class, super_class)) { // obtained class isn't super class of a given class, no need to check - return VER_OK; + return VF_OK; } // check if a class and a parent class is in the same package - if( class_is_same_package( ctx->m_class, super_class ) ) { + if (class_is_same_package(ctx->m_class, super_class)) { // class and parent class is in the same package, // no need check access to protect members - return VER_OK; + return VF_OK; } // check is a member protected bool need_check = false; - if( check_type == VF_CHECK_ACCESS_FIELD ) { + if (check_type == VF_CHECK_ACCESS_FIELD) { field_handler field = - class_resolve_nonstatic_field( ctx->m_class, index ); - if( !field ) { + class_resolve_nonstatic_field(ctx->m_class, index); + if (!field) { // NoSuchFieldError or IllegalAccessError - nothing to check - VF_DEBUG( "verifying class " << class_get_name( ctx->m_class ) - << " (method " << ctx->m_name << ctx->m_descriptor - << ") couldn't resolve field with constant pool index #" - << index ); - return VER_OK; + VF_DEBUG("verifying class " << class_get_name(ctx->m_class) + << " (method " << ctx->m_name << ctx->m_descriptor + << ") couldn't resolve field with constant pool index #" + << index); + return VF_OK; } - if( field_is_protected( field ) ) { + if (field_is_protected(field)) { need_check = true; } } else { - method_handler method = class_resolve_method( ctx->m_class, index ); - if( !method || method_is_static( method ) ) { + method_handler method = class_resolve_method(ctx->m_class, index); + if (!method || method_is_static(method)) { // NoSuchMethodError or IllegalAccessError - nothing to check - VF_DEBUG( "verifying class " << class_get_name( ctx->m_class ) - << " (method " << ctx->m_name << ctx->m_descriptor - << ") couldn't resolve method with constant pool index #" - << index ); - return VER_OK; + VF_DEBUG("verifying class " << class_get_name(ctx->m_class) + << " (method " << ctx->m_name << ctx->m_descriptor + << ") couldn't resolve method with constant pool index #" + << index); + return VF_OK; } - if( method_is_protected( method ) ) { - if( instance_name[0] == '[' - && !memcmp( method_get_name( method ), "clone", 6 ) ) { + if (method_is_protected(method)) { + if (instance_name[0] == '[' + && !memcmp(method_get_name(method), "clone", 6)) { // for arrays function clone is public } else { need_check = true; } } } - if( !need_check ) { + if (!need_check) { // no need to check - return VER_OK; + return VF_OK; } // get instance class - class_handler instance = vf_resolve_class( instance_name, false, ctx ); - if( !instance ) { + class_handler instance = vf_resolve_class(instance_name, false, ctx); + if (!instance) { // instance class isn't loaded - return VER_ClassNotLoaded; + return VF_ClassNotLoaded; } // check access constraint - if( !vf_is_valid( instance, NULL, ctx->m_class, check_type ) ) { + if (!vf_is_valid(instance, NULL, ctx->m_class, check_type)) { // return error - vf_set_error( check_type, ctx ); - return VER_ErrorIncompatibleArgument; + vf_set_error(check_type, ctx); + return VF_ErrorIncompatibleArgument; } - return VER_OK; + return VF_OK; } // vf_check_access_constraint /** * Provides initial constraint checks for current class. * Checks only loaded classes, and stores restriction for unloaded ones. */ -vf_Result -vf_check_class_constraints( vf_Context *ctx ) // verification context +vf_Result vf_check_class_constraints(vf_Context *ctx) // verification context { // set class restriction collection vf_TypeConstraint *last = NULL; vf_TypeConstraint *collection = ctx->m_type->GetClassConstraint(); // check constraints - for( vf_TypeConstraint *constraint = collection; - constraint; - constraint = constraint->m_next ) - { + for (vf_TypeConstraint *constraint = collection; + constraint; constraint = constraint->m_next) { // set context method ctx->m_method = constraint->m_method; ctx->m_name = constraint->m_name; ctx->m_descriptor = constraint->m_descriptor; // check constraint - vf_Result result = vf_check_constraint( constraint, ctx ); - if( result == VER_OK ) { + vf_Result result = vf_check_constraint(constraint, ctx); + if (result == VF_OK) { // constraint checked, remove constraint from the collection - if( !last ) { + if (!last) { collection = constraint->m_next; } else { last->m_next = constraint->m_next; } - } else if( result != VER_ClassNotLoaded ) { + } else if (result != VF_ClassNotLoaded) { // return error return result; } else { @@ -1320,56 +1287,54 @@ last = constraint; } } - if( collection ) { + if (collection) { // set constraint for further checking - vf_set_class_constraint( collection, ctx ); + vf_set_class_constraint(collection, ctx); } - return VER_OK; + return VF_OK; } // vf_check_class_constraints /** * Checks a constraint for a given class. Loads classes if it's needed. */ -static inline vf_Result -vf_force_check_constraint( vf_TypeConstraint *constraint, // class constraint - vf_Context *ctx ) // verification context +static inline vf_Result vf_force_check_constraint(vf_TypeConstraint *constraint, // class constraint + vf_Context *ctx) // verification context { // check if constraint is already verified - if( VF_CHECK_NONE == constraint->m_check_type ) { + if (VF_CHECK_NONE == constraint->m_check_type) { // already verified - VF_TRACE( "constraint.checked", "verify constraint: have \"" - << constraint->m_source << "\" need \"" << constraint-> - m_target << "\" already done (check #1) for class " << - class_get_name( ctx->m_class ) ); - return VER_OK; + VF_TRACE("constraint.checked", "verify constraint: have \"" + << constraint->m_source << "\" need \"" << constraint-> + m_target << "\" already done (check #1) for class " << + class_get_name(ctx->m_class)); + return VF_OK; } // get target class - class_handler target = - vf_resolve_class( constraint->m_target, true, ctx ); - if( !target ) { - VF_DEBUG( "verifying class " << class_get_name( ctx->m_class ) - << " (method " << constraint->m_name - << constraint->m_descriptor << ") couldn't load class \"" - << ( ( constraint->m_target[0] == 'L' ) - ? &( constraint->m_target[1] ) : constraint->m_target ) - << "\"" ); + class_handler target = vf_resolve_class(constraint->m_target, true, ctx); + if (!target) { + VF_DEBUG("verifying class " << class_get_name(ctx->m_class) + << " (method " << constraint->m_name + << constraint->m_descriptor << ") couldn't load class \"" + << ((constraint->m_target[0] == 'L') + ? &(constraint->m_target[1]) : constraint->m_target) + << "\""); unsigned index = 0; - while( constraint->m_target[index++] != 'L' ) { - assert( constraint->m_target[index] != '\0' ); + while (constraint->m_target[index++] != 'L') { + assert(constraint->m_target[index] != '\0'); } - VF_SET_CTX( ctx, "Couldn't load class: " - << &( constraint->m_target[index] ) ); - return VER_ErrorLoadClass; + VF_SET_CTX(ctx, "Couldn't load class: " + << &(constraint->m_target[index])); + return VF_ErrorLoadClass; } // check if constraint is already verified - if( VF_CHECK_NONE == constraint->m_check_type ) { + if (VF_CHECK_NONE == constraint->m_check_type) { // already verified - VF_TRACE( "constraint.checked", "verify constraint: have \"" - << constraint->m_source << "\" need \"" << constraint-> - m_target << "\" already done (check #2) for class " << - class_get_name( ctx->m_class ) ); - return VER_OK; + VF_TRACE("constraint.checked", "verify constraint: have \"" + << constraint->m_source << "\" need \"" << constraint-> + m_target << "\" already done (check #2) for class " << + class_get_name(ctx->m_class)); + return VF_OK; } /** @@ -1379,87 +1344,84 @@ * To be compatible with those applications we should do full constraint * checks only if -Xverify:all option is present in command line. */ - if( !ctx->m_verify_all && class_is_interface_( target ) ) { + if (!ctx->m_verify_all && class_is_interface_(target)) { // skip constraint check // reset constraint to successful constraint->m_check_type = VF_CHECK_NONE; - return VER_OK; + return VF_OK; } // check if constraint is already verified - if( VF_CHECK_NONE == constraint->m_check_type ) { + if (VF_CHECK_NONE == constraint->m_check_type) { // already verified - VF_TRACE( "constraint.checked", "verify constraint: have \"" - << constraint->m_source << "\" need \"" << constraint-> - m_target << "\" already done (check #3) for class " << - class_get_name( ctx->m_class ) ); - return VER_OK; + VF_TRACE("constraint.checked", "verify constraint: have \"" + << constraint->m_source << "\" need \"" << constraint-> + m_target << "\" already done (check #3) for class " << + class_get_name(ctx->m_class)); + return VF_OK; } // get stack reference class - class_handler source = - vf_resolve_class( constraint->m_source, true, ctx ); - if( !source ) { - VF_DEBUG( "verifying class " << class_get_name( ctx->m_class ) - << " (method " << constraint->m_name - << constraint->m_descriptor << ") couldn't load class \"" - << ( ( constraint->m_source[0] == 'L' ) - ? &( constraint->m_source[1] ) : constraint->m_source ) - << "\"" ); + class_handler source = vf_resolve_class(constraint->m_source, true, ctx); + if (!source) { + VF_DEBUG("verifying class " << class_get_name(ctx->m_class) + << " (method " << constraint->m_name + << constraint->m_descriptor << ") couldn't load class \"" + << ((constraint->m_source[0] == 'L') + ? &(constraint->m_source[1]) : constraint->m_source) + << "\""); unsigned index = 0; - while( constraint->m_source[index++] != 'L' ) { - assert( constraint->m_source[index] != '\0' ); + while (constraint->m_source[index++] != 'L') { + assert(constraint->m_source[index] != '\0'); } - VF_SET_CTX( ctx, "Couldn't load class: " - << &( constraint->m_source[index] ) ); - return VER_ErrorLoadClass; + VF_SET_CTX(ctx, "Couldn't load class: " + << &(constraint->m_source[index])); + return VF_ErrorLoadClass; } // store constraint check type (it could be changed during validation check) - vf_CheckConstraint check = - ( vf_CheckConstraint ) constraint->m_check_type; + vf_CheckConstraint check = (vf_CheckConstraint) constraint->m_check_type; // check if constraint is already verified - if( check == VF_CHECK_NONE ) { + if (check == VF_CHECK_NONE) { // already verified - VF_TRACE( "constraint.checked", "verify constraint: have \"" - << constraint->m_source << "\" need \"" << constraint-> - m_target << "\" already done (check #4) for class " << - class_get_name( ctx->m_class ) ); - return VER_OK; + VF_TRACE("constraint.checked", "verify constraint: have \"" + << constraint->m_source << "\" need \"" << constraint-> + m_target << "\" already done (check #4) for class " << + class_get_name(ctx->m_class)); + return VF_OK; } // check restriction - if( !vf_is_valid( source, target, ctx->m_class, check ) ) { + if (!vf_is_valid(source, target, ctx->m_class, check)) { // return error ctx->m_method = constraint->m_method; ctx->m_name = constraint->m_name; ctx->m_descriptor = constraint->m_descriptor; - vf_set_error( check, ctx ); - return VER_ErrorIncompatibleArgument; + vf_set_error(check, ctx); + return VF_ErrorIncompatibleArgument; } // reset constraint to successful constraint->m_check_type = VF_CHECK_NONE; - return VER_OK; + return VF_OK; } // vf_force_check_constraint /** * Function verifies class constraints. */ -static vf_Result -vf_verify_class_constraints( vf_Context *ctx ) // verification context +static vf_Result vf_verify_class_constraints(vf_Context *ctx) // verification context { // get method verify data vf_TypeConstraint *constraint = - (vf_TypeConstraint*)class_get_verify_data_ptr( ctx->m_class ); - if( constraint == NULL ) { - return VER_OK; + (vf_TypeConstraint *) class_get_verify_data_ptr(ctx->m_class); + if (constraint == NULL) { + return VF_OK; } // trace verified class - VF_TRACE( "class.constraint", - "verify constraints: " << class_get_name( ctx->m_class ) ); + VF_TRACE("class.constraint", + "verify constraints: " << class_get_name(ctx->m_class)); // check method constraints - vf_Result result = VER_OK; - for( ; constraint; constraint = constraint->m_next ) { - result = vf_force_check_constraint( constraint, ctx ); - if( VER_OK != result ) { + vf_Result result = VF_OK; + for (; constraint; constraint = constraint->m_next) { + result = vf_force_check_constraint(constraint, ctx); + if (VF_OK != result) { break; } } @@ -1473,24 +1435,23 @@ /** * Function allocates an array in memory with elements initialized to zero. */ -void * -vf_calloc_func( unsigned num, // number of elements - size_t size, // size of element - VF_SOURCE_PARAMS ) // debug info +void *vf_calloc_func(unsigned num, // number of elements + size_t size, // size of element + VF_SOURCE_PARAMS) // debug info { - assert( num ); - assert( size ); - void *result = STD_CALLOC( num, size ); - if( result == NULL ) { + assert(num); + assert(size); + void *result = STD_CALLOC(num, size); + if (result == NULL) { // out of memory error - VF_DIE( "vf_calloc_func: out of memory" ); + VF_DIE("vf_calloc_func: out of memory"); } #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory", VF_REPORT_SOURCE - << "(calloc) allocate memory addr: " << result - << ", size: " << size * - num << " (" << num << " by " << size << ")" ); + VF_TRACE("memory", VF_REPORT_SOURCE + << "(calloc) allocate memory addr: " << result + << ", size: " << size * + num << " (" << num << " by " << size << ")"); #endif // VF_TRACE_MEMORY return result; @@ -1499,21 +1460,20 @@ /** * Function allocates memory blocks. */ -void * -vf_malloc_func( size_t size, // size of memory block - VF_SOURCE_PARAMS ) // debug info +void *vf_malloc_func(size_t size, // size of memory block + VF_SOURCE_PARAMS) // debug info { - assert( size ); - void *result = STD_MALLOC( size ); - if( result == NULL ) { + assert(size); + void *result = STD_MALLOC(size); + if (result == NULL) { // out of memory error - VF_DIE( "vf_malloc_func: out of memory" ); + VF_DIE("vf_malloc_func: out of memory"); } #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory", VF_REPORT_SOURCE - << "(malloc) allocate memory addr: " << result - << ", size: " << size ); + VF_TRACE("memory", VF_REPORT_SOURCE + << "(malloc) allocate memory addr: " << result + << ", size: " << size); #endif // VF_TRACE_MEMORY return result; @@ -1522,22 +1482,21 @@ /** * Function reallocates memory blocks. */ -void * -vf_realloc_func( void *pointer, // old pointer - size_t size, // size of memory block - VF_SOURCE_PARAMS ) // debug info +void *vf_realloc_func(void *pointer, // old pointer + size_t size, // size of memory block + VF_SOURCE_PARAMS) // debug info { - assert( size ); - void *result = STD_REALLOC( pointer, size ); - if( result == NULL ) { + assert(size); + void *result = STD_REALLOC(pointer, size); + if (result == NULL) { // out of memory error - VF_DIE( "vf_realloc_func: out of memory" ); + VF_DIE("vf_realloc_func: out of memory"); } #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory", VF_REPORT_SOURCE - << "(realloc) reallocate memory from addr: " << pointer - << " to addr: " << result << ", size: " << size ); + VF_TRACE("memory", VF_REPORT_SOURCE + << "(realloc) reallocate memory from addr: " << pointer + << " to addr: " << result << ", size: " << size); #endif // VF_TRACE_MEMORY return result; @@ -1546,20 +1505,19 @@ /** * Function releases allocated memory blocks. */ -void -vf_free_func( void *pointer, // free pointer - VF_SOURCE_PARAMS ) // debug info +void vf_free_func(void *pointer, // free pointer + VF_SOURCE_PARAMS) // debug info { - if( pointer ) { - STD_FREE( pointer ); + if (pointer) { + STD_FREE(pointer); } else { - VF_DIE( "vf_free_func: null pointer for free" ); + VF_DIE("vf_free_func: null pointer for free"); } #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory", VF_REPORT_SOURCE - << "(free) free memory addr: " << ( void * )pointer ); + VF_TRACE("memory", VF_REPORT_SOURCE + << "(free) free memory addr: " << (void *) pointer); #endif // VF_TRACE_MEMORY } // vf_free_func @@ -1567,27 +1525,26 @@ /** * Function creates wide memory pool structure. */ -static inline vf_PoolInternal * -vf_create_pool_element( size_t size, // initial pool size - VF_SOURCE_PARAMS ) // debug info +static inline vf_PoolInternal *vf_create_pool_element(size_t size, // initial pool size + VF_SOURCE_PARAMS) // debug info { vf_PoolInternal *result; // create pool new entry and allocate memory for it - result = (vf_PoolInternal*) - vf_malloc_func( sizeof( vf_PoolInternal ) + size, VF_SOURCE_ARGS1 ); - result->m_memory = (char*)result + sizeof( vf_PoolInternal ); - result->m_free = (char*)result->m_memory; + result = (vf_PoolInternal *) + vf_malloc_func(sizeof(vf_PoolInternal) + size, VF_SOURCE_ARGS1); + result->m_memory = (char *) result + sizeof(vf_PoolInternal); + result->m_free = (char *) result->m_memory; result->m_freesize = size; result->m_next = NULL; - memset( result->m_memory, 0, size ); + memset(result->m_memory, 0, size); #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory.pool.element", VF_REPORT_SOURCE - << "(pool) create pool element: " << result - << ", memory: " << result-> - m_memory << ", size: " << result->m_freesize ); + VF_TRACE("memory.pool.element", VF_REPORT_SOURCE + << "(pool) create pool element: " << result + << ", memory: " << result-> + m_memory << ", size: " << result->m_freesize); #endif // VF_TRACE_MEMORY return result; @@ -1596,28 +1553,27 @@ /** * Function creates memory pool structure. */ -vf_Pool * -vf_create_pool_func( VF_SOURCE_PARAMS ) +vf_Pool *vf_create_pool_func(VF_SOURCE_PARAMS) { // create new pool element vf_PoolInternal *pool = - vf_create_pool_element( sizeof( vf_Pool ) + VF_POOL_ENTRY_SIZE, - VF_SOURCE_ARGS1 ); + vf_create_pool_element(sizeof(vf_Pool) + VF_POOL_ENTRY_SIZE, + VF_SOURCE_ARGS1); // set head pool - vf_Pool *result = (vf_Pool*)pool->m_free; - pool->m_memory = pool->m_free + sizeof( vf_Pool ); - pool->m_free = (char*)pool->m_memory; + vf_Pool *result = (vf_Pool *) pool->m_free; + pool->m_memory = pool->m_free + sizeof(vf_Pool); + pool->m_free = (char *) pool->m_memory; pool->m_freesize = VF_POOL_ENTRY_SIZE; result->m_pool = pool; - result->m_memory = sizeof( vf_PoolInternal ) + sizeof( vf_Pool ) + result->m_memory = sizeof(vf_PoolInternal) + sizeof(vf_Pool) + VF_POOL_ENTRY_SIZE; result->m_used = 0; result->m_maxuse = 0; #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory.pool", VF_REPORT_SOURCE - << "(pool) create pool: " << result ); + VF_TRACE("memory.pool", VF_REPORT_SOURCE + << "(pool) create pool: " << result); #endif // VF_TRACE_MEMORY return result; @@ -1626,51 +1582,50 @@ /** * Function allocates memory block in current pool. */ -void * -vf_palloc_func( vf_Pool *hpool, // a given pool - size_t size, // memory size - VF_SOURCE_PARAMS ) // debug info +void *vf_palloc_func(vf_Pool *hpool, // a given pool + size_t size, // memory size + VF_SOURCE_PARAMS) // debug info { - const unsigned align = sizeof( void * ) - 1; + const unsigned align = sizeof(void *) - 1; void *result = NULL; vf_PoolInternal *pool = hpool->m_pool; // align allocate size - size = ( size + align ) & ( ~align ); + size = (size + align) & (~align); // find free space - if( size > VF_POOL_ENTRY_SIZE ) { + if (size > VF_POOL_ENTRY_SIZE) { // create new wide pool entry - pool = vf_create_pool_element( size, VF_SOURCE_ARGS1 ); + pool = vf_create_pool_element(size, VF_SOURCE_ARGS1); pool->m_next = hpool->m_pool; hpool->m_pool = pool; - hpool->m_memory += sizeof( vf_PoolInternal ) + size; - } else if( pool->m_freesize < size ) { + hpool->m_memory += sizeof(vf_PoolInternal) + size; + } else if (pool->m_freesize < size) { vf_PoolInternal *last = NULL; vf_PoolInternal *entry = pool->m_next; - while( entry ) { + while (entry) { last = pool; pool = entry; - if( pool->m_freesize >= size ) { + if (pool->m_freesize >= size) { // found free space break; } entry = pool->m_next; } - if( !entry ) { + if (!entry) { // create new pool element pool = - vf_create_pool_element( VF_POOL_ENTRY_SIZE, VF_SOURCE_ARGS1 ); + vf_create_pool_element(VF_POOL_ENTRY_SIZE, VF_SOURCE_ARGS1); pool->m_next = hpool->m_pool; hpool->m_pool = pool; - hpool->m_memory += sizeof( vf_PoolInternal ) + VF_POOL_ENTRY_SIZE; + hpool->m_memory += sizeof(vf_PoolInternal) + VF_POOL_ENTRY_SIZE; } else { - assert( last != NULL ); + assert(last != NULL); last->m_next = pool->m_next; pool->m_next = hpool->m_pool; hpool->m_pool = pool; } } - assert( hpool->m_used + size < hpool->m_memory ); + assert(hpool->m_used + size < hpool->m_memory); result = pool->m_free; pool->m_free += size; pool->m_freesize -= size; @@ -1678,10 +1633,10 @@ #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory.pool", VF_REPORT_SOURCE - << "(pool) allocate memory in pool: " << hpool - << ", memory: " << result << ", size: " << size - << ", element: " << pool << ", free: " << pool->m_freesize ); + VF_TRACE("memory.pool", VF_REPORT_SOURCE + << "(pool) allocate memory in pool: " << hpool + << ", memory: " << result << ", size: " << size + << ", element: " << pool << ", free: " << pool->m_freesize); #endif // VF_TRACE_MEMORY return result; @@ -1690,37 +1645,36 @@ /** * Function cleans given pool. */ -void -vf_clean_pool_func( vf_Pool *hpool, // memory pool - VF_SOURCE_PARAMS ) // debug info +void vf_clean_pool_func(vf_Pool *hpool, // memory pool + VF_SOURCE_PARAMS) // debug info { // set max used value - if( hpool->m_used > hpool->m_maxuse ) { + if (hpool->m_used > hpool->m_maxuse) { hpool->m_maxuse = hpool->m_used; } #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory.pool", VF_REPORT_SOURCE - << "(pool) clean pool: " << hpool - << ", allocated: " << hpool-> - m_memory << ", used: " << hpool->m_used ); + VF_TRACE("memory.pool", VF_REPORT_SOURCE + << "(pool) clean pool: " << hpool + << ", allocated: " << hpool-> + m_memory << ", used: " << hpool->m_used); #endif // VF_TRACE_MEMORY vf_PoolInternal *pool = hpool->m_pool; - while( pool ) { + while (pool) { // clean pool element space unsigned used_size = - ( unsigned )( pool->m_free - (char*)pool->m_memory ); - memset( pool->m_memory, 0, used_size ); - pool->m_free = (char*)pool->m_memory; + (unsigned) (pool->m_free - (char *) pool->m_memory); + memset(pool->m_memory, 0, used_size); + pool->m_free = (char *) pool->m_memory; pool->m_freesize += used_size; hpool->m_used -= used_size; #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory.pool.element", VF_REPORT_SOURCE - << "(pool) clean pool element: " << pool - << ", size: " << used_size ); + VF_TRACE("memory.pool.element", VF_REPORT_SOURCE + << "(pool) clean pool element: " << pool + << ", size: " << used_size); #endif // VF_TRACE_MEMORY // get next pool entry @@ -1731,26 +1685,25 @@ /** * Function releases memory from given pool. */ -void -vf_delete_pool_func( vf_Pool *hpool, // memory pool - VF_SOURCE_PARAMS ) // debug info +void vf_delete_pool_func(vf_Pool *hpool, // memory pool + VF_SOURCE_PARAMS) // debug info { #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory.pool", VF_REPORT_SOURCE - << "(pool) delete pool: " << hpool - << ", allocated: " << hpool->m_memory - << ", used: " - << ( hpool->m_used > - hpool->m_maxuse ? hpool->m_used : hpool->m_maxuse ) ); + VF_TRACE("memory.pool", VF_REPORT_SOURCE + << "(pool) delete pool: " << hpool + << ", allocated: " << hpool->m_memory + << ", used: " + << (hpool->m_used > + hpool->m_maxuse ? hpool->m_used : hpool->m_maxuse)); #endif // VF_TRACE_MEMORY vf_PoolInternal *pool = hpool->m_pool; - while( pool ) { + while (pool) { #if VF_TRACE_MEMORY // trace memory - VF_TRACE( "memory.pool.element", VF_REPORT_SOURCE - << "(pool) delete pool element: " << pool ); + VF_TRACE("memory.pool.element", VF_REPORT_SOURCE + << "(pool) delete pool element: " << pool); #endif // VF_TRACE_MEMORY // store pool element @@ -1758,20 +1711,19 @@ // get next pool element pool = pool->m_next; // free pool element - vf_free_func( entry, VF_SOURCE_ARGS1 ); + vf_free_func(entry, VF_SOURCE_ARGS1); } } // vf_delete_pool_func /** * Provides final constraint checks for a given class. */ -vf_Result -vf_verify_class_constraints( class_handler klass, // a given class - unsigned verifyAll, // verification level flag - char **message ) // verifier error message +vf_Result vf_verify_class_constraints(class_handler klass, // a given class + unsigned verifyAll, // verification level flag + char **message) // verifier error message { - assert( klass ); - assert( message ); + assert(klass); + assert(message); // create context vf_Context context; @@ -1779,12 +1731,12 @@ context.m_verify_all = verifyAll ? true : false; // verified constraint for a given method - vf_Result result = vf_verify_class_constraints( &context ); + vf_Result result = vf_verify_class_constraints(&context); *message = context.m_error; #if _VF_DEBUG - if( VER_OK != result ) { - VF_DEBUG( "VerifyError: " << context.m_error ); + if (VF_OK != result) { + VF_DEBUG("VerifyError: " << context.m_error); } #endif // _VF_DEBUG @@ -1794,11 +1746,10 @@ /** * Function releases verify data in class loader. */ -void -vf_release_verify_data( void *data ) +void vf_release_verify_data(void *data) { - vf_ClassLoaderData *cl_data = (vf_ClassLoaderData*) data; + vf_ClassLoaderData *cl_data = (vf_ClassLoaderData *) data; delete cl_data->string; - vf_delete_pool( cl_data->pool ); + vf_delete_pool(cl_data->pool); } // vf_release_verify_data Index: vm/vmcore/src/verifier/ver_dataflow.cpp =================================================================== --- vm/vmcore/src/verifier/ver_dataflow.cpp (revision 542211) +++ vm/vmcore/src/verifier/ver_dataflow.cpp (working copy) @@ -39,50 +39,49 @@ /** * Prints stack map entry into output stream. */ -static void -vf_dump_vector_entry( vf_MapEntry *entry, // stack map entry - ostream *stream ) // output stream +static void vf_dump_vector_entry(vf_MapEntry *entry, // stack map entry + ostream *stream) // output stream { - switch ( entry->m_type ) { + switch (entry->m_type) { case SM_TOP: - *stream << " [TOP ]"; + *stream << " [ TOP ]"; break; case SM_INT: - *stream << " [INT ]"; + *stream << " [ INT ]"; break; case SM_FLOAT: - *stream << " [FLT ]"; + *stream << " [FLOAT]"; break; case SM_LONG_LO: - *stream << " [LOLO]"; + *stream << " [L64 l]"; break; case SM_LONG_HI: - *stream << " [LOHI]"; + *stream << " [L64 h]"; break; case SM_DOUBLE_LO: - *stream << " [DOLO]"; + *stream << " [D64 l]"; break; case SM_DOUBLE_HI: - *stream << " [DOHI]"; + *stream << " [D64 h]"; break; case SM_NULL: - *stream << " [NULL]"; + *stream << " [NULL ]"; break; case SM_REF: - *stream << " [REF ]"; + *stream << " [ REF ]"; break; case SM_UNINITIALIZED: - if( entry->m_new ) { - *stream << " [UN " << entry->m_new % 10 << "]"; + if (entry->m_new) { + *stream << " [UN " << entry->m_new << "]"; } else { - *stream << " [THIS]"; + *stream << " [THIS ]"; } break; case SM_RETURN_ADDR: - *stream << " [RT " << entry->m_pc % 10 << "]"; + *stream << " [RT " << entry->m_pc << "]"; break; case SM_ANY: - *stream << " [ANY ]"; + *stream << " [ ANY ]"; break; default: *stream << " [? " << entry->m_type << "]"; @@ -92,28 +91,27 @@ /** * Prints data flow vector into output stream. */ -void -vf_dump_vector( vf_MapVectorHandle vector, // data flow vector - vf_InstrHandle instr, // code instruction - ostream *stream ) // output stream (can be NULL) +void vf_dump_vector(vf_MapVectorHandle vector, // data flow vector + vf_InstrHandle instr, // code instruction + ostream *stream) // output stream (can be NULL) { unsigned index, count; // set steam if it's needed - if( stream == NULL ) { + if (stream == NULL) { stream = &cerr; } // dump code instruction if it's needed - if( instr != NULL ) { - *stream << ( ( instr->m_stack < 0 ) ? "[" : "[ " ) + if (instr != NULL) { + *stream << ((instr->m_stack < 0) ? "[" : "[ ") << instr->m_stack << "| " << instr->m_minstack << "] " - << vf_opcode_names[*( instr->m_addr )] << endl; + << vf_opcode_names[*(instr->m_addr)] << endl; } // dump locals vector *stream << "L:"; - for( index = 0; index < vector->m_number; index++ ) { - vf_dump_vector_entry( &vector->m_local[index], stream ); - if( vector->m_local[index].m_is_local ) { + for (index = 0; index < vector->m_number; index++) { + vf_dump_vector_entry(&vector->m_local[index], stream); + if (vector->m_local[index].m_is_local) { *stream << " "; } else { *stream << "!"; @@ -121,11 +119,11 @@ } *stream << endl; // dump local references - for( index = 0; index < vector->m_number; index++ ) { - if( vector->m_local[index].m_type == SM_REF ) { + for (index = 0; index < vector->m_number; index++) { + if (vector->m_local[index].m_type == SM_REF) { *stream << " REF #" << index << ": "; - } else if( vector->m_local[index].m_type == SM_UNINITIALIZED ) { - if( vector->m_local[index].m_new ) { + } else if (vector->m_local[index].m_type == SM_UNINITIALIZED) { + if (vector->m_local[index].m_new) { *stream << "UREF #" << index << ": [" << vector-> m_local[index].m_new << "] "; } else { @@ -134,10 +132,10 @@ } else { continue; } - if( vector->m_local[index].m_vtype ) { + if (vector->m_local[index].m_vtype) { vf_ValidType *type = vector->m_local[index].m_vtype; *stream << type; - for( count = 0; count < type->number; count++ ) { + for (count = 0; count < type->number; count++) { *stream << " " << type->string[count]; } } else { @@ -147,9 +145,9 @@ } // dump stack vector *stream << "S:"; - for( index = 0; index < vector->m_depth; index++ ) { - vf_dump_vector_entry( &vector->m_stack[index], stream ); - if( vector->m_stack[index].m_is_local ) { + for (index = 0; index < vector->m_depth; index++) { + vf_dump_vector_entry(&vector->m_stack[index], stream); + if (vector->m_stack[index].m_is_local) { *stream << "!"; } else { *stream << " "; @@ -157,11 +155,11 @@ } *stream << endl; // dump stack references - for( index = 0; index < vector->m_depth; index++ ) { - if( vector->m_stack[index].m_type == SM_REF ) { + for (index = 0; index < vector->m_depth; index++) { + if (vector->m_stack[index].m_type == SM_REF) { *stream << " REF #" << index << ": "; - } else if( vector->m_stack[index].m_type == SM_UNINITIALIZED ) { - if( vector->m_stack[index].m_new ) { + } else if (vector->m_stack[index].m_type == SM_UNINITIALIZED) { + if (vector->m_stack[index].m_new) { *stream << "UREF #" << index << ": [" << vector-> m_stack[index].m_new << "] "; } else { @@ -170,10 +168,10 @@ } else { continue; } - if( vector->m_stack[index].m_vtype ) { + if (vector->m_stack[index].m_vtype) { vf_ValidType *type = vector->m_stack[index].m_vtype; *stream << type; - for( count = 0; count < type->number; count++ ) { + for (count = 0; count < type->number; count++) { *stream << " " << type->string[count]; } } else { @@ -188,18 +186,17 @@ /** * Function compares two valid types. */ -bool -vf_is_types_equal( vf_ValidType *type1, // first checked type - vf_ValidType *type2 ) // second checked type +bool vf_is_types_equal(vf_ValidType *type1, // first checked type + vf_ValidType *type2) // second checked type { - if( type1 == type2 ) { + if (type1 == type2) { return true; - } else if( type1 == NULL || type2 == NULL - || type1->number != type2->number ) { + } else if (type1 == NULL || type2 == NULL + || type1->number != type2->number) { return false; } - for( unsigned index = 0; index < type1->number; index++ ) { - if( type1->string[index] != type2->string[index] ) { + for (unsigned index = 0; index < type1->number; index++) { + if (type1->string[index] != type2->string[index]) { // types aren't equal return false; } @@ -212,144 +209,142 @@ * Sets is_changed to true if the first vector was * changed. */ -static inline vf_Result -vf_merge_vectors( vf_MapVector *first, // first vector - vf_MapVectorHandle second, // second vector - bool handler_flag, // if merged node is handler - bool &is_changed, // true if the first vector was changed - vf_Context *ctx ) // verification context +static inline vf_Result vf_merge_vectors(vf_MapVector *first, // first vector + vf_MapVectorHandle second, // second vector + bool handler_flag, // if merged node is handler + bool &is_changed, // true if the first vector was changed + vf_Context *ctx) // verification context { is_changed = false; vf_MapEntry zero = { 0 }; // merge local variable vector unsigned index; - for( index = 0; index < first->m_number; index++ ) { + for (index = 0; index < first->m_number; index++) { // merge entries type - if( first->m_local[index].m_type == SM_TOP ) { + if (first->m_local[index].m_type == SM_TOP) { // no need to merge continue; - } else if( first->m_local[index].m_type != - second->m_local[index].m_type ) { + } else if (first->m_local[index].m_type != + second->m_local[index].m_type) { // types are differ, reset result entry first->m_local[index].m_type = SM_TOP; first->m_local[index].m_vtype = NULL; first->m_local[index].m_is_local = 1; - first->m_local[index].m_local = ( unsigned short )index; + first->m_local[index].m_local = (unsigned short) index; is_changed = true; - } else if( first->m_local[index].m_type == SM_REF ) { + } else if (first->m_local[index].m_type == SM_REF) { // reference types, merge them vf_ValidType *type = - ctx->m_type->MergeTypes( first->m_local[index].m_vtype, - second->m_local[index].m_vtype ); - if( type ) { + ctx->m_type->MergeTypes(first->m_local[index].m_vtype, + second->m_local[index].m_vtype); + if (type) { // set merged type first->m_local[index].m_vtype = type; is_changed = true; } - } else if( first->m_local[index].m_type == SM_UNINITIALIZED ) { + } else if (first->m_local[index].m_type == SM_UNINITIALIZED) { // reference types, merge them vf_ValidType *type = - ctx->m_type->MergeTypes( first->m_local[index].m_vtype, - second->m_local[index].m_vtype ); - if( type + ctx->m_type->MergeTypes(first->m_local[index].m_vtype, + second->m_local[index].m_vtype); + if (type || first->m_local[index].m_new != - second->m_local[index].m_new ) { + second->m_local[index].m_new) { // types are differ, reset result entry first->m_local[index].m_type = SM_TOP; first->m_local[index].m_new = 0; first->m_local[index].m_vtype = NULL; first->m_local[index].m_is_local = 1; - first->m_local[index].m_local = ( unsigned short )index; + first->m_local[index].m_local = (unsigned short) index; is_changed = true; } } // check local variable entries - assert( first->m_local[index].m_is_local == 1 ); - assert( first->m_local[index].m_local == index ); + assert(first->m_local[index].m_is_local == 1); + assert(first->m_local[index].m_local == index); } // set maximal local variable number - if( first->m_number < second->m_number ) { - for( index = first->m_number; index < second->m_number; index++ ) { + if (first->m_number < second->m_number) { + for (index = first->m_number; index < second->m_number; index++) { first->m_local[index].m_is_local = 1; - first->m_local[index].m_local = ( unsigned short )index; + first->m_local[index].m_local = (unsigned short) index; } first->m_number = second->m_number; } // check handler flag - if( handler_flag ) { + if (handler_flag) { // no need merge stack for handler node - return VER_OK; + return VF_OK; } // merge stack map vector - assert( first->m_depth == second->m_depth ); - for( index = 0; index < second->m_depth; index++ ) { + assert(first->m_depth == second->m_depth); + for (index = 0; index < second->m_depth; index++) { // merge entries type - if( first->m_stack[index].m_type == SM_TOP ) { + if (first->m_stack[index].m_type == SM_TOP) { // no need to merge continue; - } else if( first->m_stack[index].m_type != - second->m_stack[index].m_type ) { + } else if (first->m_stack[index].m_type != + second->m_stack[index].m_type) { // types differ, verification should fail - VF_REPORT( ctx, "Type mismatch while merging a stack map" ); - return VER_ErrorDataFlow; - } else if( first->m_stack[index].m_type == SM_REF ) { + VF_REPORT(ctx, "Type mismatch while merging a stack map"); + return VF_ErrorDataFlow; + } else if (first->m_stack[index].m_type == SM_REF) { // reference types, merge them vf_ValidType *type = - ctx->m_type->MergeTypes( first->m_stack[index].m_vtype, - second->m_stack[index].m_vtype ); - if( type ) { + ctx->m_type->MergeTypes(first->m_stack[index].m_vtype, + second->m_stack[index].m_vtype); + if (type) { // set merged type first->m_stack[index].m_vtype = type; is_changed = true; } - } else if( first->m_stack[index].m_type == SM_UNINITIALIZED ) { + } else if (first->m_stack[index].m_type == SM_UNINITIALIZED) { // reference types, merge them vf_ValidType *type = - ctx->m_type->MergeTypes( first->m_stack[index].m_vtype, - second->m_stack[index].m_vtype ); - if( type + ctx->m_type->MergeTypes(first->m_stack[index].m_vtype, + second->m_stack[index].m_vtype); + if (type || first->m_stack[index].m_new != - second->m_stack[index].m_new ) { + second->m_stack[index].m_new) { // types are differ, reset result entry first->m_stack[index] = zero; is_changed = true; } } } - return VER_OK; + return VF_OK; } // vf_merge_vectors /** * Function compares two vectors. */ -static inline bool -vf_compare_vectors( vf_MapVectorHandle first, // first vector - vf_MapVectorHandle second ) // second vector +static inline bool vf_compare_vectors(vf_MapVectorHandle first, // first vector + vf_MapVectorHandle second) // second vector { // compare vector parameters - if( first->m_number != second->m_number - || first->m_depth != second->m_depth ) { + if (first->m_number != second->m_number + || first->m_depth != second->m_depth) { return false; } // compare locals unsigned index; - for( index = 0; index < first->m_number; index++ ) { - assert( first->m_local[index].m_is_local == 1 ); - assert( second->m_local[index].m_is_local == 1 ); - if( first->m_local[index].m_local != second->m_local[index].m_local + for (index = 0; index < first->m_number; index++) { + assert(first->m_local[index].m_is_local == 1); + assert(second->m_local[index].m_is_local == 1); + if (first->m_local[index].m_local != second->m_local[index].m_local || first->m_local[index].m_type != second->m_local[index].m_type || first->m_local[index].m_vtype != - second->m_local[index].m_vtype ) { + second->m_local[index].m_vtype) { return false; } } // compare stack - for( index = 0; index < first->m_depth; index++ ) { - if( first->m_stack[index].m_type != second->m_stack[index].m_type + for (index = 0; index < first->m_depth; index++) { + if (first->m_stack[index].m_type != second->m_stack[index].m_type || first->m_stack[index].m_vtype != - second->m_stack[index].m_vtype ) { + second->m_stack[index].m_vtype) { return false; } } @@ -359,96 +354,92 @@ /** * Function check access constraint for two stack map references. */ -static inline vf_Result -vf_check_access( vf_MapEntry *source, // stack map entry - vf_MapEntry *target, // required map entry - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_access(vf_MapEntry *source, // stack map entry + vf_MapEntry *target, // required map entry + vf_Context *ctx) // verification context { // compare types - assert( target->m_vtype->number == 1 ); - vf_CheckConstraint check = ( target->m_ctype == VF_CHECK_ACCESS_FIELD ) + assert(target->m_vtype->number == 1); + vf_CheckConstraint check = (target->m_ctype == VF_CHECK_ACCESS_FIELD) ? VF_CHECK_ASSIGN : VF_CHECK_PARAM; - for( unsigned index = 0; index < source->m_vtype->number; index++ ) { + for (unsigned index = 0; index < source->m_vtype->number; index++) { // set constraints for differing types - if( target->m_vtype->string[0] != source->m_vtype->string[index] ) { - ctx->m_type->SetRestriction( target->m_vtype->string[0], - source->m_vtype->string[index], 0, - check ); + if (target->m_vtype->string[0] != source->m_vtype->string[index]) { + ctx->m_type->SetRestriction(target->m_vtype->string[0], + source->m_vtype->string[index], 0, + check); } // set access constraints for differing types - if( ctx->m_vtype.m_class->string[0] != - source->m_vtype->string[index] ) { + if (ctx->m_vtype.m_class->string[0] != source->m_vtype->string[index]) { // not the same class vf_Result result = - vf_check_access_constraint( target->m_vtype->string[0], - source->m_vtype->string[index], - target->m_index, - ( vf_CheckConstraint ) - target->m_ctype, - ctx ); - if( result == VER_ClassNotLoaded ) { + vf_check_access_constraint(target->m_vtype->string[0], + source->m_vtype->string[index], + target->m_index, + (vf_CheckConstraint) + target->m_ctype, + ctx); + if (result == VF_ClassNotLoaded) { // cannot complete check, set restriction - ctx->m_type->SetRestriction( ctx->m_vtype.m_class-> - string[0], - source->m_vtype->string[index], - 0, ( vf_CheckConstraint ) - target->m_ctype ); - } else if( VER_OK != result ) { + ctx->m_type->SetRestriction(ctx->m_vtype.m_class-> + string[0], + source->m_vtype->string[index], + 0, (vf_CheckConstraint) + target->m_ctype); + } else if (VF_OK != result) { // return error return result; } } } - return VER_OK; + return VF_OK; } // vf_check_access /** * Checks two stack map references. */ -static inline vf_Result -vf_check_entry_refs( vf_MapEntry *source, // stack map entry - vf_MapEntry *target, // required map entry - bool local_init, // initialization flag of locals - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_entry_refs(vf_MapEntry *source, // stack map entry + vf_MapEntry *target, // required map entry + bool local_init, // initialization flag of locals + vf_Context *ctx) // verification context { // check local variable type - if( source->m_is_local - && ( !target->m_is_local || source->m_local != target->m_local ) ) { - return VER_ErrorDataFlow; + if (source->m_is_local + && (!target->m_is_local || source->m_local != target->m_local)) { + return VF_ErrorDataFlow; } // check entries type - if( !( SM_REF == source->m_type || SM_UNINITIALIZED == source->m_type ) - || !( SM_REF == target->m_type - || SM_UNINITIALIZED == target->m_type ) ) { - if( SM_ANY == source->m_type ) { - return VER_OK; + if (!(SM_REF == source->m_type || SM_UNINITIALIZED == source->m_type) + || !(SM_REF == target->m_type || SM_UNINITIALIZED == target->m_type)) { + if (SM_ANY == source->m_type) { + return VF_OK; } // only aload and astore get SM_REF/VF_CHECK_UNINITIALIZED_THIS - if( SM_RETURN_ADDR == source->m_type - && VF_CHECK_UNINITIALIZED_THIS == target->m_ctype ) { - if( source->m_is_local ) { + if (SM_RETURN_ADDR == source->m_type + && VF_CHECK_UNINITIALIZED_THIS == target->m_ctype) { + if (source->m_is_local) { // aload a return address - return VER_ErrorJsrLoadRetAddr; - } else if( !target->m_is_local ) { + return VF_ErrorJsrLoadRetAddr; + } else if (!target->m_is_local) { // astore a return address - return VER_OK; + return VF_OK; } } - return VER_ErrorDataFlow; + return VF_ErrorDataFlow; } // check available entry - if( source->m_vtype == NULL ) { + if (source->m_vtype == NULL) { // nothing to check - return VER_OK; + return VF_OK; } // check initialization - if( source->m_type == SM_UNINITIALIZED - && target->m_type != SM_UNINITIALIZED ) { - if( ( source->m_new == 0 && target->m_ctype == VF_CHECK_ACCESS_FIELD ) - || ( local_init == false - && target->m_ctype == VF_CHECK_UNINITIALIZED_THIS ) - || ( !ctx->m_verify_all && source->m_new == 0 - && target->m_ctype == VF_CHECK_UNINITIALIZED_THIS ) ) { + if (source->m_type == SM_UNINITIALIZED + && target->m_type != SM_UNINITIALIZED) { + if ((source->m_new == 0 && target->m_ctype == VF_CHECK_ACCESS_FIELD) + || (local_init == false + && target->m_ctype == VF_CHECK_UNINITIALIZED_THIS) + || (!ctx->m_verify_all && source->m_new == 0 + && target->m_ctype == VF_CHECK_UNINITIALIZED_THIS)) { // 1. In initialization method instance fields of this // that are declared in the current class may be assigned // before calling any instance initialization method. @@ -460,202 +451,116 @@ // can be stored in a local variable if backward branch is // taken or the code is protected by exception handler. } else { - VF_REPORT( ctx, "Uninitialized reference usage" ); - return VER_ErrorDataFlow; + VF_REPORT(ctx, "Uninitialized reference usage"); + return VF_ErrorDataFlow; } } // check references bool is_error = false; - switch ( target->m_ctype ) { + switch (target->m_ctype) { case VF_CHECK_NONE: case VF_CHECK_UNINITIALIZED_THIS: case VF_CHECK_PARAM: // check method invocation conversion - if( target->m_vtype != NULL ) { - is_error = ctx->m_type->CheckTypes( target->m_vtype, - source->m_vtype, 0, - VF_CHECK_PARAM ); + if (target->m_vtype != NULL) { + is_error = ctx->m_type->CheckTypes(target->m_vtype, + source->m_vtype, 0, + VF_CHECK_PARAM); } break; case VF_CHECK_ARRAY: // check if source reference is array is_error = - ctx->m_type->CheckTypes( NULL, source->m_vtype, 0, - VF_CHECK_ARRAY ); + ctx->m_type->CheckTypes(NULL, source->m_vtype, 0, VF_CHECK_ARRAY); break; case VF_CHECK_REF_ARRAY: is_error = - ctx->m_type->CheckTypes( NULL, source->m_vtype, 0, - VF_CHECK_REF_ARRAY ); + ctx->m_type->CheckTypes(NULL, source->m_vtype, 0, + VF_CHECK_REF_ARRAY); break; case VF_CHECK_EQUAL: // check if references are equal - is_error = ctx->m_type->CheckTypes( target->m_vtype, - source->m_vtype, 0, - VF_CHECK_EQUAL ); + is_error = ctx->m_type->CheckTypes(target->m_vtype, + source->m_vtype, 0, + VF_CHECK_EQUAL); break; case VF_CHECK_ASSIGN: // check assignment conversion case VF_CHECK_ASSIGN_WEAK: // check weak assignment conversion - assert( target->m_vtype != NULL ); - is_error = ctx->m_type->CheckTypes( target->m_vtype, - source->m_vtype, 0, - ( vf_CheckConstraint ) target-> - m_ctype ); + assert(target->m_vtype != NULL); + is_error = ctx->m_type->CheckTypes(target->m_vtype, + source->m_vtype, 0, + (vf_CheckConstraint) target-> + m_ctype); break; case VF_CHECK_ACCESS_FIELD: // check field access case VF_CHECK_ACCESS_METHOD: // check method access { - assert( target->m_vtype != NULL ); // not null reference - assert( target->m_local != 0 ); // constant pool index is set - vf_Result result = vf_check_access( source, target, ctx ); + assert(target->m_vtype != NULL); // not null reference + assert(target->m_local != 0); // constant pool index is set + vf_Result result = vf_check_access(source, target, ctx); return result; } break; case VF_CHECK_DIRECT_SUPER: // check is target class is direct super class of source is_error = - ctx->m_type->CheckTypes( target->m_vtype, source->m_vtype, 0, - VF_CHECK_DIRECT_SUPER ); + ctx->m_type->CheckTypes(target->m_vtype, source->m_vtype, 0, + VF_CHECK_DIRECT_SUPER); break; case VF_CHECK_INVOKESPECIAL: // check invokespecial object reference is_error = - ctx->m_type->CheckTypes( target->m_vtype, source->m_vtype, 0, - VF_CHECK_INVOKESPECIAL ); + ctx->m_type->CheckTypes(target->m_vtype, source->m_vtype, 0, + VF_CHECK_INVOKESPECIAL); break; default: - VF_DIE( "vf_check_entry_refs: unknown check in switch" ); + VF_DIE("vf_check_entry_refs: unknown check in switch"); } // check error - if( is_error ) { - return VER_ErrorDataFlow; + if (is_error) { + return VF_ErrorDataFlow; } - return VER_OK; + return VF_OK; } // vf_check_entry_refs /** - * Checks two stack map entries. - */ -static inline vf_Result -vf_check_entry_types( vf_MapEntry *entry1, // stack map entry - vf_MapEntry *entry2, // required map entry - bool local_init, // initialization flag of locals - bool *need_copy, // pointer to copy flag - vf_Context *ctx ) // verification context -{ - if( SM_ANY == entry1->m_type ) { - return VER_OK; - } - switch ( entry2->m_type ) { - case SM_REF: - // check reference entries - { - vf_Result result = - vf_check_entry_refs( entry1, entry2, local_init, ctx ); - *need_copy = true; - return result; - } - case SM_RETURN_ADDR: - if( entry1->m_type != entry2->m_type ) { - return VER_ErrorDataFlow; - } - *need_copy = true; - break; - case SM_TOP: - case SM_INT: - case SM_FLOAT: - case SM_LONG_LO: - case SM_DOUBLE_LO: - case SM_LONG_HI: - case SM_DOUBLE_HI: - // check entries type - if( entry1->m_type != entry2->m_type ) { - return VER_ErrorDataFlow; - } - break; - case SM_WORD: - // pop gets any single word - switch ( entry1->m_type ) { - case SM_INT: - case SM_FLOAT: - case SM_NULL: - break; - case SM_REF: - case SM_UNINITIALIZED: - case SM_RETURN_ADDR: - *need_copy = true; - break; - default: - return VER_ErrorDataFlow; - } - case SM_WORD2_LO: - // check not strict correspondence types - if( entry1->m_type >= SM_LONG_HI ) { - return VER_ErrorDataFlow; - } - *need_copy = true; - break; - case SM_WORD2_HI: - // check not strict correspondence types - if( entry1->m_type >= SM_LONG_LO && - entry1->m_type != SM_LONG_HI && entry1->m_type != SM_DOUBLE_HI ) { - return VER_ErrorDataFlow; - } - *need_copy = true; - break; - default: - return VER_ErrorDataFlow; - } - - // check local variable type - if( entry1->m_is_local - && ( !entry2->m_is_local || entry1->m_local != entry2->m_local ) ) { - return VER_ErrorDataFlow; - } - return VER_OK; -} // vf_check_entry_types - -/** * Function creates array element valid type. */ -static inline void -vf_set_array_element_type( vf_MapEntry *buf, // result data flow vector entry - vf_MapEntry *vector, // data flow vector entry - vf_MapEntry *array, // array data flow vector entry - vf_ContextHandle ctx ) // verification context +static inline void vf_set_array_element_type(vf_MapEntry *buf, // result data flow vector entry + vf_MapEntry *vector, // data flow vector entry + vf_MapEntry *array, // array data flow vector entry + vf_ContextHandle ctx) // verification context { - assert( SM_REF == array->m_type || SM_ANY == array->m_type ); + assert(SM_REF == array->m_type || SM_ANY == array->m_type); buf->m_type = array->m_type; buf->m_vtype = array->m_vtype; buf->m_local = vector->m_local; buf->m_is_local = vector->m_is_local; - if( buf->m_vtype ) { + if (buf->m_vtype) { // create cell array type - buf->m_vtype = ctx->m_type->NewArrayElemType( buf->m_vtype ); + buf->m_vtype = ctx->m_type->NewArrayElemType(buf->m_vtype); } } // vf_set_array_element_type /** * Receives IN data flow vector entry for code instruction. */ -static inline vf_MapEntry * -vf_set_new_in_vector( vf_InstrHandle instr, // code instruction - vf_MapEntry *vector, // data flow vector entry - vf_ContextHandle ctx ) // verification context +static inline vf_MapEntry *vf_set_new_in_vector(vf_InstrHandle instr, // code instruction + vf_MapEntry *vector, // data flow vector entry + vf_ContextHandle ctx) // verification context { - short number; + unsigned short number; vf_MapEntry *stack_buf = ctx->m_buf; vf_MapEntry *newvector; - switch ( vector->m_type ) { + switch (vector->m_type) { case SM_COPY_0: case SM_COPY_1: case SM_COPY_2: case SM_COPY_3: // it's a copy type, copy value from IN vector - number = ( short )( vector->m_type - SM_COPY_0 ); - assert( number < instr->m_inlen ); + number = (unsigned short) (vector->m_type - SM_COPY_0); + assert(number < instr->m_inlen); newvector = &instr->m_invector[number]; - if( newvector->m_type == SM_TOP + if (newvector->m_type == SM_TOP || newvector->m_type >= SM_WORD - || ( newvector->m_type == SM_REF - && newvector->m_vtype == NULL ) ) { + || (newvector->m_type == SM_REF && newvector->m_vtype == NULL)) { // copy value from saved stack entry newvector = &stack_buf[number]; newvector->m_local = vector->m_local; @@ -665,7 +570,7 @@ case SM_UP_ARRAY: // set reference array element newvector = &stack_buf[0]; - vf_set_array_element_type( newvector, vector, &stack_buf[0], ctx ); + vf_set_array_element_type(newvector, vector, &stack_buf[0], ctx); break; default: newvector = vector; @@ -677,30 +582,29 @@ /** * Sets OUT data flow vector for code instruction. */ -static inline void -vf_set_instruction_out_vector( vf_InstrHandle instr, // code instruction - vf_MapEntry *stack, // stack map vector - vf_MapEntry *locals, // local variable vector - unsigned short *number, // pointer to local variables number - vf_ContextHandle ctx ) // verification context +static inline void vf_set_instruction_out_vector(vf_InstrHandle instr, // code instruction + vf_MapEntry *stack, // stack map vector + vf_MapEntry *locals, // local variable vector + unsigned short *number, // pointer to local variables number + vf_ContextHandle ctx) // verification context { unsigned index; vf_MapEntry *entry, *vector; // set instruction out vector - for( index = 0, vector = instr->m_outvector; + for (index = 0, vector = instr->m_outvector; index < instr->m_outlen; - index++, vector = &instr->m_outvector[index] ) { - vf_MapEntry *newvector = vf_set_new_in_vector( instr, vector, ctx ); - if( newvector->m_is_local ) { + index++, vector = &instr->m_outvector[index]) { + vf_MapEntry *newvector = vf_set_new_in_vector(instr, vector, ctx); + if (newvector->m_is_local) { // get local variable entry = locals + newvector->m_local; // set local variable type entry->m_local = newvector->m_local; entry->m_is_local = 1; // set locals vector number - if( newvector->m_local + 1 > ( *number ) ) { - *number = ( unsigned short )( newvector->m_local + 1 ); + if (newvector->m_local + 1 > (*number)) { + *number = (unsigned short) (newvector->m_local + 1); } } else { // get stack entry @@ -716,13 +620,12 @@ /** * Function clears stack map vector. */ -static inline void -vf_clear_stack( vf_MapVector *vector ) // map vector +static inline void vf_clear_stack(vf_MapVector *vector) // map vector { vf_MapEntry zero_entry = { 0 }; // zero stack vector - for( unsigned index = 0; index < vector->m_depth; index++ ) { + for (unsigned index = 0; index < vector->m_depth; index++) { vector->m_stack[index] = zero_entry; } vector->m_depth = 0; @@ -732,171 +635,230 @@ /** * Checks that this instance was initialized. */ -static inline vf_Result -vf_check_initialized_this( vf_MapEntry *locals, // stack map vector - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_initialized_this(vf_MapEntry *locals, // stack map vector + vf_Context *ctx) // verification context { // check method - if( ctx->m_is_constructor - && ctx->m_vtype.m_class != ctx->m_vtype.m_object ) { - if( SM_REF == locals->m_type - && locals->m_vtype == ctx->m_vtype.m_class ) { + if (ctx->m_is_constructor + && ctx->m_vtype.m_class != ctx->m_vtype.m_object) { + if (SM_REF == locals->m_type + && locals->m_vtype == ctx->m_vtype.m_class) { // constructor returns initialized reference of a given class } else { - VF_REPORT( ctx, "Constructor must be invoked" ); - return VER_ErrorDataFlow; + VF_REPORT(ctx, "Constructor must be invoked"); + return VF_ErrorDataFlow; } } - return VER_OK; + return VF_OK; } // vf_check_initialized_this /** * Checks that return instruction matches function return type. The check * is delayed to match Sun's implementation. */ -static inline vf_Result -vf_check_return_instruction( vf_InstrHandle instr, // a return instruction - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_return_instruction(vf_InstrHandle instr, // a return instruction + vf_Context *ctx) // verification context { - if( instr->m_inlen != ctx->m_method_outlen ) { - VF_REPORT( ctx, - "Return instruction stack modifier doesn't match method return type" ); - return VER_ErrorInstruction; + if (instr->m_inlen != ctx->m_method_outlen) { + VF_REPORT(ctx, + "Return instruction stack modifier doesn't match method return type"); + return VF_ErrorInstruction; } - for( unsigned short index = 0; index < instr->m_inlen; index++ ) { - assert( instr->m_invector[index].m_is_local == 0 ); + for (unsigned short index = 0; index < instr->m_inlen; index++) { + assert(instr->m_invector[index].m_is_local == 0); // check entry types - if( instr->m_invector[index].m_type != - ctx->m_method_outvector[index].m_type ) { - VF_REPORT( ctx, - "Return instruction stack doesn't match function return type" ); - return VER_ErrorInstruction; + if (instr->m_invector[index].m_type != + ctx->m_method_outvector[index].m_type) { + VF_REPORT(ctx, + "Return instruction stack doesn't match function return type"); + return VF_ErrorInstruction; } } - return VER_OK; + return VF_OK; } // vf_check_return_instruction /** * Checks data flow for code instruction. */ -static inline vf_Result -vf_check_instruction_in_vector( vf_MapEntry *stack, // stack map vector - vf_MapEntry *locals, // local variable vector - vf_MapEntry *buf, // buf storage vector - vf_MapEntry *invector, // code instruction IN vector - unsigned len, // IN vector length - bool local_init, // initialization flag of locals - bool *need_init, // init uninitialized entry - vf_Context *ctx ) // verification context +static inline vf_Result vf_check_instruction_in_vector(vf_MapEntry *stack, // stack map vector + vf_MapEntry *locals, // local variable vector + vf_MapEntry *buf, // buf storage vector + vf_MapEntry *invector, // code instruction IN vector + unsigned len, // IN vector length + bool local_init, // initialization flag of locals + bool *need_init, // init uninitialized entry + vf_Context *ctx) // verification context { unsigned index; vf_MapEntry *entry, *vector, *newvector; vf_Result result; // check IN vector entries - for( index = 0, vector = invector; - index < len; index++, vector = &invector[index] ) { + for (index = 0, vector = invector; + index < len; index++, vector = &invector[index]) { // set copy flag - bool copy = false; + bool copy = true; // get check entry entry = vector->m_is_local ? locals + vector->m_local : stack + index; - switch ( vector->m_type ) { - case SM_TOP: - // copy entry - copy = true; - break; - case SM_UP_ARRAY: - // check reference array element - assert( index > 0 ); - newvector = &buf[index]; - // check assignment conversion - vf_set_array_element_type( newvector, vector, &buf[0], ctx ); - if( newvector->m_vtype ) { - newvector->m_ctype = VF_CHECK_ASSIGN_WEAK; - } else if( SM_ANY == newvector->m_type ) { - break; // anything can be assigned to such array - } else { - newvector->m_ctype = VF_CHECK_NONE; - } - // check entry types - result = vf_check_entry_refs( entry, newvector, local_init, ctx ); - if( VER_OK != result ) { - VF_REPORT( ctx, "Incompatible types for array assignment" ); - return result; - } - break; - case SM_REF: - // check entry references - result = vf_check_entry_refs( entry, vector, local_init, ctx ); - if( VER_OK != result ) { - if( VER_ErrorJsrLoadRetAddr == result ) { - VF_REPORT( ctx, - "Cannot load a return address from a local variable " - << entry->m_local ); + if (SM_ANY != entry->m_type) { + switch (vector->m_type) { + case SM_TOP: + // copy entry + break; + case SM_UP_ARRAY: + // check reference array element + assert(index > 0); + copy = false; + newvector = &buf[index]; + // check assignment conversion + vf_set_array_element_type(newvector, vector, &buf[0], ctx); + if (newvector->m_vtype) { + newvector->m_ctype = VF_CHECK_ASSIGN_WEAK; + } else if (SM_ANY == newvector->m_type) { + break; // anything can be assigned to such array + } else { + newvector->m_ctype = VF_CHECK_NONE; } - if( !ctx->m_error ) { - result = vf_check_entry_refs( entry, vector, local_init, ctx ); - VF_REPORT( ctx, "Data flow analysis error" ); + // check entry types + result = + vf_check_entry_refs(entry, newvector, local_init, ctx); + if (VF_OK != result) { + VF_REPORT(ctx, "Incompatible types for array assignment"); + return result; } - return result; - } - copy = true; - break; - case SM_UNINITIALIZED: - // check entry references - if( entry->m_type == SM_REF ) { - // double initialization - VF_REPORT( ctx, "Double initialization of object reference" ); - return VER_ErrorDataFlow; - } - result = vf_check_entry_refs( entry, vector, local_init, ctx ); - if( VER_OK != result ) { - VF_REPORT( ctx, "Data flow analysis error (uninitialized)" ); - return result; - } - // check initialization class in constructor - if( entry->m_type == SM_UNINITIALIZED && entry->m_new == 0 ) { - // initialization of this reference in class construction - assert( entry->m_vtype->number == 1 ); - if( vector->m_vtype->string[0] != entry->m_vtype->string[0] ) { - ctx->m_type->SetRestriction( vector->m_vtype-> - string[0], - entry->m_vtype->string[0], 0, - VF_CHECK_DIRECT_SUPER ); + break; + case SM_REF: + // check entry references + result = vf_check_entry_refs(entry, vector, local_init, ctx); + if (VF_OK != result) { + if (VF_ErrorJsrLoadRetAddr == result) { + VF_REPORT(ctx, + "Cannot load a return address from a local variable " + << entry->m_local); + } + if (!ctx->m_error) { + result = + vf_check_entry_refs(entry, vector, local_init, + ctx); + VF_REPORT(ctx, "Data flow analysis error"); + } + return result; } + break; + case SM_UNINITIALIZED: + // check entry references + if (entry->m_type == SM_REF) { + // double initialization + VF_REPORT(ctx, + "Double initialization of object reference"); + return VF_ErrorDataFlow; + } + result = vf_check_entry_refs(entry, vector, local_init, ctx); + if (VF_OK != result) { + VF_REPORT(ctx, + "Data flow analysis error (uninitialized)"); + return result; + } + // check initialization class in constructor + if (entry->m_type == SM_UNINITIALIZED && entry->m_new == 0) { + // initialization of this reference in class construction + assert(entry->m_vtype->number == 1); + if (vector->m_vtype->string[0] != + entry->m_vtype->string[0]) { + ctx->m_type->SetRestriction(vector->m_vtype-> + string[0], + entry->m_vtype-> + string[0], 0, + VF_CHECK_DIRECT_SUPER); + } + } + *need_init = true; + break; + case SM_INT: + case SM_FLOAT: + case SM_LONG_LO: + case SM_DOUBLE_LO: + case SM_LONG_HI: + case SM_DOUBLE_HI: + // check entries type + if (entry->m_type != vector->m_type) { + VF_REPORT(ctx, + "Data flow analysis error: simple type expected"); + return VF_ErrorDataFlow; + } + copy = false; + break; + case SM_RETURN_ADDR: + if (entry->m_type != vector->m_type) { + VF_REPORT(ctx, + "Data flow analysis error: return address expected"); + return VF_ErrorDataFlow; + } + break; + case SM_WORD: + // pop gets any single word + switch (entry->m_type) { + case SM_INT: + case SM_FLOAT: + case SM_NULL: + case SM_REF: + case SM_UNINITIALIZED: + case SM_RETURN_ADDR: + break; + default: + VF_REPORT(ctx, "Data flow analysis error: word expected"); + return VF_ErrorDataFlow; + } + break; + case SM_WORD2_LO: + // check not strict correspondence types + if (entry->m_type >= SM_LONG_HI) { + VF_REPORT(ctx, + "Data flow analysis error: low word expected"); + return VF_ErrorDataFlow; + } + break; + case SM_WORD2_HI: + // check not strict correspondence types + if (entry->m_type >= SM_LONG_LO && + entry->m_type != SM_LONG_HI + && entry->m_type != SM_DOUBLE_HI) { + VF_REPORT(ctx, + "Data flow analysis error: high word expected"); + return VF_ErrorDataFlow; + } + break; + default: + VF_DIE("Unexpected instruction stack map value"); } - *need_init = true; - copy = true; - break; - default: - // check entry types - result = - vf_check_entry_types( entry, vector, local_init, ©, ctx ); - if( VER_OK != result ) { - VF_REPORT( ctx, "Data flow analysis error" ); - return result; - } + } // if SM_ANY != entry->m_type + + if (entry->m_is_local + && (!vector->m_is_local || entry->m_local != vector->m_local)) { + VF_REPORT(ctx, + "Data flow analysis error: incorrect operation with local variable " + << entry->m_local); + return VF_ErrorDataFlow; } // copy entry - if( copy ) { + if (copy) { buf[index].m_type = entry->m_type; buf[index].m_new = entry->m_new; buf[index].m_vtype = entry->m_vtype; } } - return VER_OK; + return VF_OK; } // vf_check_instruction_in_vector /** * Receives code instruction OUT data flow vector. */ -static vf_Result -vf_get_instruction_out_vector( vf_NodeHandle node, // graph node - vf_InstrHandle instr, // code instruction - vf_MapVector *invector, // incoming data flow vector - vf_Context *ctx ) // verification context +static vf_Result vf_get_instruction_out_vector(vf_NodeHandle node, // graph node + vf_InstrHandle instr, // code instruction + vf_MapVector *invector, // incoming data flow vector + vf_Context *ctx) // verification context { unsigned index; bool need_init = false; @@ -904,90 +866,88 @@ vf_MapEntry zero_entry = { 0 }; // set stack vector - assert( invector->m_depth - instr->m_minstack >= 0 ); + assert(invector->m_depth - instr->m_minstack >= 0); vf_MapEntry *stack = invector->m_stack + invector->m_depth - instr->m_minstack; // set locals vector vf_MapEntry *locals = invector->m_local; // check instruction in vector - vf_Result result = vf_check_instruction_in_vector( stack, locals, buf, - instr->m_invector, - instr->m_inlen, - node->m_initialized, - &need_init, ctx ); - if( VER_OK != result ) { + vf_Result result = vf_check_instruction_in_vector(stack, locals, buf, + instr->m_invector, + instr->m_inlen, + node->m_initialized, + &need_init, ctx); + if (VF_OK != result) { return result; } // don't create out vector for return instructions and athrow - if( VF_INSTR_RETURN == instr->m_type ) { - result = vf_check_initialized_this( locals, ctx ); - if( VER_OK != result ) { + if (VF_INSTR_RETURN == instr->m_type) { + result = vf_check_initialized_this(locals, ctx); + if (VF_OK != result) { return result; } - return vf_check_return_instruction( instr, ctx ); - } else if( VF_INSTR_THROW == instr->m_type ) { - return VER_OK; + return vf_check_return_instruction(instr, ctx); + } else if (VF_INSTR_THROW == instr->m_type) { + return VF_OK; } // zero stack entries - for( index = 0; index < instr->m_minstack; index++ ) { + for (index = 0; index < instr->m_minstack; index++) { stack[index] = zero_entry; } // init uninitialized entry - if( need_init ) { - assert( buf[0].m_type == SM_UNINITIALIZED ); + if (need_init) { + assert(buf[0].m_type == SM_UNINITIALIZED); // init local variables reference - for( index = 0; index < invector->m_number; index++ ) { - if( invector->m_local[index].m_type == SM_UNINITIALIZED - && invector->m_local[index].m_new == buf[0].m_new ) { - assert( invector->m_local[index].m_vtype == buf[0].m_vtype ); + for (index = 0; index < invector->m_number; index++) { + if (invector->m_local[index].m_type == SM_UNINITIALIZED + && invector->m_local[index].m_new == buf[0].m_new) { + assert(invector->m_local[index].m_vtype == buf[0].m_vtype); invector->m_local[index].m_type = SM_REF; } } // init stack reference - for( index = 0; - index < ( unsigned )invector->m_depth - instr->m_minstack; - index++ ) { - if( invector->m_stack[index].m_type == SM_UNINITIALIZED - && invector->m_stack[index].m_new == buf[0].m_new ) { - assert( invector->m_stack[index].m_vtype == buf[0].m_vtype ); + for (index = 0; + index < (unsigned) invector->m_depth - instr->m_minstack; + index++) { + if (invector->m_stack[index].m_type == SM_UNINITIALIZED + && invector->m_stack[index].m_new == buf[0].m_new) { + assert(invector->m_stack[index].m_vtype == buf[0].m_vtype); invector->m_stack[index].m_type = SM_REF; } } } // set instruction OUT vector vf_GraphHandle graph = ctx->m_graph; - invector->m_depth = - ( unsigned short )( invector->m_depth + instr->m_stack ); - assert( invector->m_depth <= ctx->m_maxstack ); + invector->m_depth = (unsigned short) (invector->m_depth + instr->m_stack); + assert(invector->m_depth <= ctx->m_maxstack); index = invector->m_number; - vf_set_instruction_out_vector( instr, stack, locals, &invector->m_number, - ctx ); - assert( invector->m_number <= ctx->m_maxlocal ); + vf_set_instruction_out_vector(instr, stack, locals, &invector->m_number, + ctx); + assert(invector->m_number <= ctx->m_maxlocal); // set local variable numbers - for( ; index < invector->m_number; index++ ) { - if( !locals[index].m_is_local ) { + for (; index < invector->m_number; index++) { + if (!locals[index].m_is_local) { locals[index].m_is_local = 1; locals[index].m_local = index; } } - return VER_OK; + return VF_OK; } // vf_get_instruction_out_vector /** * Copies a stored handler vector to the out vector. */ -static inline vf_Result -vf_get_handler_out_vector( vf_MapVector *invector, // IN handler vector - vf_MapVectorHandle handler_vector ) // stored handler vector +static inline vf_Result vf_get_handler_out_vector(vf_MapVector *invector, // IN handler vector + vf_MapVectorHandle handler_vector) // stored handler vector { // assert( 0 == invector->m_depth ); FIXME - assert( 1 == handler_vector->m_depth ); - assert( SM_REF == handler_vector->m_stack->m_type ); + assert(1 == handler_vector->m_depth); + assert(SM_REF == handler_vector->m_stack->m_type); // clear stack for exception handler - vf_clear_stack( invector ); + vf_clear_stack(invector); // set handler out vector invector->m_stack->m_type = handler_vector->m_stack->m_type; @@ -995,16 +955,15 @@ // set modify vector value invector->m_depth = 1; - return VER_OK; + return VF_OK; } // vf_get_handler_out_vector /** * Sets graph node OUT data flow vector. */ -vf_Result -vf_set_node_out_vector( vf_NodeHandle node, // a graph node - vf_MapVector *invector, // incoming data flow vector - vf_Context *ctx ) // verification context +vf_Result vf_set_node_out_vector(vf_NodeHandle node, // a graph node + vf_MapVector *invector, // incoming data flow vector + vf_Context *ctx) // verification context { vf_Result result; @@ -1014,34 +973,41 @@ /** * For start-entry node doesn't need to check data flow */ - if( VF_NODE_START_ENTRY == node->m_type ) { - return VER_OK; + if (VF_NODE_START_ENTRY == node->m_type) { + return VF_OK; } - if( VF_NODE_HANDLER == node->m_type ) { + if (VF_NODE_HANDLER == node->m_type) { // set OUT vector for a handler node - return vf_get_handler_out_vector( invector, &node->m_outmap ); + return vf_get_handler_out_vector(invector, &node->m_outmap); } // set out vector for each instruction - for( vf_InstrHandle instr = node->m_start; instr <= node->m_end; instr++ ) { - if( ( 0 == instr->m_inlen + instr->m_outlen ) - && ( VF_INSTR_NONE == instr->m_type ) ) { + for (vf_InstrHandle instr = node->m_start; instr <= node->m_end; instr++) { + VF_DUMP(DUMP_INSTR_MAP, { + // dump instruction OUT vector + cerr << "-------------- instruction #" + << (instr - node->m_start) + << ", node #" << ctx->m_graph->GetNodeNum(node) + << " in: " << endl; vf_dump_vector(invector, instr, &cerr);} + ); + if ((0 == instr->m_inlen + instr->m_outlen) + && (VF_INSTR_NONE == instr->m_type)) { continue; } - result = vf_get_instruction_out_vector( node, instr, invector, ctx ); - if( VER_OK != result ) { + result = vf_get_instruction_out_vector(node, instr, invector, ctx); + if (VF_OK != result) { return result; } - VF_DUMP( DUMP_INSTR_MAP, { - // dump instruction OUT vector - cerr << "-------------- instruction #" - << ( instr - node->m_start ) - << ", node #" << ctx->m_graph->GetNodeNum(node) - << " out: " << endl; - vf_dump_vector( invector, instr, &cerr );} - ); + VF_DUMP(DUMP_INSTR_MAP, { + // dump instruction OUT vector + cerr << "-------------- instruction #" + << (instr - node->m_start) + << ", node #" << ctx->m_graph->GetNodeNum(node) + << " out: " << endl; + vf_dump_vector(invector, instr, &cerr);} + ); } - return VER_OK; + return VF_OK; } // vf_set_node_out_vector struct vf_MapMark @@ -1051,126 +1017,122 @@ bool out_updated:1; }; -static inline vf_MapMark * -vf_get_node_mapmark( vf_NodeHandle node ) +static inline vf_MapMark *vf_get_node_mapmark(vf_NodeHandle node) { - assert( sizeof( vf_MapMark ) <= sizeof( node->m_mark ) ); - return (vf_MapMark*) & node->m_mark; + assert(sizeof(vf_MapMark) <= sizeof(node->m_mark)); + return (vf_MapMark *) & node->m_mark; } /** * Creates and sets graph node OUT vector. */ -static vf_Result -vf_create_node_vectors( vf_NodeHandle node, // a graph node - vf_MapVector *incoming, // a vector for instruction data flow change - vf_Context *ctx ) // a verifier context +static vf_Result vf_create_node_vectors(vf_NodeHandle node, // a graph node + vf_MapVector *incoming, // a vector for instruction data flow change + vf_Context *ctx) // a verifier context { vf_Graph *graph = ctx->m_graph; - assert( vf_get_node_mapmark( node )->in_set ); - graph->CopyFullVector( &node->m_inmap, incoming ); + assert(vf_get_node_mapmark(node)->in_set); + graph->CopyFullVector(&node->m_inmap, incoming); - VF_DUMP( DUMP_NODE_MAP, { - // dump node number - cerr << endl << "-------------- Node #" - << ctx->m_graph->GetNodeNum(node) << endl; - // dump in vector - cerr << "IN vector :" << endl; - vf_dump_vector( incoming, NULL, &cerr );} ); + VF_DUMP(DUMP_NODE_MAP, { + // dump node number + cerr << endl << "-------------- Node #" + << ctx->m_graph->GetNodeNum(node) << endl; + // dump in vector + cerr << "IN vector :" << endl; + vf_dump_vector(incoming, NULL, &cerr);}); // calculate OUT node vector - vf_Result result = vf_set_node_out_vector( node, incoming, ctx ); - if( VER_OK != result ) { + vf_Result result = vf_set_node_out_vector(node, incoming, ctx); + if (VF_OK != result) { return result; } // set node OUT vector - vf_MapVector *outcoming = (vf_MapVector*)&node->m_outmap; + vf_MapVector *outcoming = (vf_MapVector *) &node->m_outmap; bool is_out_changed = false; - if( !vf_get_node_mapmark( node )->out_set ) { + if (!vf_get_node_mapmark(node)->out_set) { // create node OUT vector - vf_get_node_mapmark( node )->out_set = true; - graph->AllocVector( outcoming ); - graph->CopyVector( incoming, outcoming ); + vf_get_node_mapmark(node)->out_set = true; + graph->AllocVector(outcoming); + graph->CopyVector(incoming, outcoming); is_out_changed = true; - } else if( !vf_compare_vectors( outcoming, incoming ) ) { + } else if (!vf_compare_vectors(outcoming, incoming)) { // vectors differ - graph->CopyFullVector( incoming, outcoming ); + graph->CopyFullVector(incoming, outcoming); is_out_changed = true; } - VF_DUMP( DUMP_NODE_MAP, { - // dump out vector - cerr << "-------------- Node #" - << ctx->m_graph->GetNodeNum(node) - << endl << "OUT vector:" << endl; - vf_dump_vector( outcoming, NULL, &cerr );} - ); + VF_DUMP(DUMP_NODE_MAP, { + // dump out vector + cerr << "-------------- Node #" << ctx->m_graph->GetNodeNum(node) + << endl << "OUT vector:" << endl; + vf_dump_vector(outcoming, NULL, &cerr);} + ); // check stack modifier - assert( ( int )( node->m_outmap.m_depth - - node->m_inmap.m_depth ) == node->m_stack ); + assert((int) (node->m_outmap.m_depth + - node->m_inmap.m_depth) == node->m_stack); - return ( is_out_changed ) ? VER_Continue : VER_OK; + return (is_out_changed) ? VF_Continue : VF_OK; } // vf_create_node_vectors /** * Checks data flow for a graph node. */ -static vf_Result -vf_check_node_data_flow( vf_NodeHandle node, // a graph node - unsigned *node_count, // last graph node in recursion - bool *need_recheck, // set to true if need to recheck previous nodes - vf_Context *ctx ) // verification context +static vf_Result vf_check_node_data_flow(vf_NodeHandle node, // a graph node + unsigned *node_count, // last graph node in recursion + bool *need_recheck, // set to true if need to recheck previous nodes + vf_Context *ctx) // verification context { // get graph vf_Graph *graph = ctx->m_graph; vf_MapVector *incoming = ctx->m_map; // incoming data flow vector // skip end-entry node - if( VF_NODE_END_ENTRY == node->m_type ) { - return VER_OK; + if (VF_NODE_END_ENTRY == node->m_type) { + return VF_OK; } - if( vf_get_node_mapmark( node )->out_updated ) { - return VER_OK; + if (vf_get_node_mapmark(node)->out_updated) { + return VF_OK; } - vf_Result result = vf_create_node_vectors( node, incoming, ctx ); - vf_get_node_mapmark( node )->out_updated = true; - if( VER_Continue != result ) { + vf_Result result = vf_create_node_vectors(node, incoming, ctx); + vf_get_node_mapmark(node)->out_updated = true; + if (VF_Continue != result) { return result; } // set incoming vector for following nodes vf_MapVectorHandle innode_vector = &node->m_outmap; - for( vf_EdgeHandle outedge = node->m_outedge; - outedge; outedge = outedge->m_outnext ) { + for (vf_EdgeHandle outedge = node->m_outedge; + outedge; outedge = outedge->m_outnext) { // get an edge end node vf_NodeHandle outnode = outedge->m_end; // skip an end entry - if( VF_NODE_END_ENTRY == outnode->m_type ) { + if (VF_NODE_END_ENTRY == outnode->m_type) { continue; } // get out node IN vector - vf_MapVector *outnode_vector = (vf_MapVector*)&outnode->m_inmap; + vf_MapVector *outnode_vector = (vf_MapVector *) &outnode->m_inmap; - if( !vf_get_node_mapmark( outnode )->in_set ) { - vf_get_node_mapmark( outnode )->in_set = true; - graph->AllocVector( outnode_vector ); + if (!vf_get_node_mapmark(outnode)->in_set) { + vf_get_node_mapmark(outnode)->in_set = true; + graph->AllocVector(outnode_vector); // node's IN vector is invalid, set it - if( VF_NODE_HANDLER == outnode->m_type ) { + if (VF_NODE_HANDLER == outnode->m_type) { // it's exception node, create IN vector for it - graph->CopyFullVector( innode_vector, incoming ); - vf_clear_stack( incoming ); - graph->CopyVector( incoming, outnode_vector ); + graph->CopyFullVector(innode_vector, incoming); + vf_clear_stack(incoming); + graph->CopyVector(incoming, outnode_vector); } else { // other nodes - graph->CopyVector( innode_vector, outnode_vector ); + graph->CopyVector(innode_vector, outnode_vector); } } else { // copy out node IN vector for dump - VF_DUMP( DUMP_MERGE_MAP, - graph->CopyFullVector( outnode_vector, incoming ) ); + VF_DUMP(DUMP_MERGE_MAP, + graph->CopyFullVector(outnode_vector, incoming)); // node's IN vector is valid, merge them bool is_handler = VF_NODE_HANDLER == outnode->m_type; @@ -1178,69 +1140,68 @@ // FIXME instruction since a jump can happen anywhere bool is_changed; - result = vf_merge_vectors( outnode_vector, innode_vector, - is_handler, is_changed, ctx ); - if( VER_OK != result ) { + result = vf_merge_vectors(outnode_vector, innode_vector, + is_handler, is_changed, ctx); + if (VF_OK != result) { return result; } - if( is_changed ) { + if (is_changed) { // node IN vector is changed, reset node OUT vector results - vf_get_node_mapmark( outnode )->out_updated = false; + vf_get_node_mapmark(outnode)->out_updated = false; // set node for re-verification if it's needed. unsigned count = outnode->m_nodecount; - if( count <= ( *node_count ) ) { + if (count <= (*node_count)) { *node_count = count; *need_recheck = true; } } - VF_DUMP( DUMP_MERGE_MAP, if( is_changed ) { - // dump out vectors - cerr << "============== merge IN vector for Node #" - << ctx->m_graph->GetNodeNum(outnode) << endl; - cerr << "IN vectors:" << endl; - cerr << "1: --------------" << endl; - vf_dump_vector( incoming, NULL, &cerr ); - cerr << "2: --------------" << endl; - vf_dump_vector( innode_vector, NULL, &cerr ); - // dump out vector - cerr << "result: --------------" << endl; - vf_dump_vector( outnode_vector, NULL, &cerr ); - cerr << "### Recount from " << *node_count - << " (now " << ctx->m_graph->GetNodeNum(node) - << ")" << endl;} - ); + VF_DUMP(DUMP_MERGE_MAP, if (is_changed) { + // dump out vectors + cerr << "============== merge IN vector for Node #" + << ctx->m_graph->GetNodeNum(outnode) << endl; + cerr << "IN vectors:" << endl; + cerr << "1: --------------" << endl; + vf_dump_vector(incoming, NULL, &cerr); + cerr << "2: --------------" << endl; + vf_dump_vector(innode_vector, NULL, &cerr); + // dump out vector + cerr << "result: --------------" << endl; + vf_dump_vector(outnode_vector, NULL, &cerr); + cerr << "### Recount from " << *node_count + << " (now " << ctx->m_graph->GetNodeNum(node) + << ")" << endl;} + ); } } - return VER_OK; + return VF_OK; } // vf_check_node_data_flow /** * Creates a map for a start node. */ -static void -vf_create_start_map( vf_Context *ctx ) // verification context +static void vf_create_start_map(vf_Context *ctx) // verification context { vf_Graph *graph = ctx->m_graph; // alloc memory for vector structure - vf_Node *start_node = (vf_Node*)graph->GetStartNode(); - vf_MapVector *vector = (vf_MapVector*)&start_node->m_inmap; - graph->AllocVector( vector ); - vf_get_node_mapmark( start_node )->in_set = true; + vf_Node *start_node = (vf_Node *) graph->GetStartNode(); + vf_MapVector *vector = (vf_MapVector *) &start_node->m_inmap; + graph->AllocVector(vector); + vf_get_node_mapmark(start_node)->in_set = true; // set "this" reference in a local variable unsigned short start; - if( method_is_static( ctx->m_method ) ) { + if (method_is_static(ctx->m_method)) { start = 0; } else { start = 1; // fill "this" entry - const char *name = class_get_name( ctx->m_class ); - vf_ValidType *type = vf_create_class_valid_type( name, ctx ); - if( ctx->m_is_constructor ) { + const char *name = class_get_name(ctx->m_class); + vf_ValidType *type = vf_create_class_valid_type(name, ctx); + if (ctx->m_is_constructor) { vector->m_local->m_type = SM_UNINITIALIZED; } else { vector->m_local->m_type = SM_REF; @@ -1255,11 +1216,11 @@ vf_MapEntry *invector = ctx->m_method_invector; unsigned short index, count; - for( index = start, count = 0; count < inlen; index++, count++ ) { + for (index = start, count = 0; count < inlen; index++, count++) { vector->m_local[index].m_type = invector[count].m_type; vector->m_local[index].m_vtype = invector[count].m_vtype; vector->m_local[index].m_is_local = 1; - vector->m_local[index].m_local = ( unsigned short )index; + vector->m_local[index].m_local = (unsigned short) index; } vector->m_number = index; } // vf_create_start_map @@ -1267,37 +1228,35 @@ /** * Function enumerates graph nodes by wave numeration. */ -void -vf_enumerate_graph_node( vf_ContextHandle ctx ) +void vf_enumerate_graph_node(vf_ContextHandle ctx) { // clear graph node marks vf_Graph *graph = ctx->m_graph; graph->CleanNodeMarks(); // set first enumeration node - vf_Node *start_node = (vf_Node*)graph->GetStartNode(); - graph->SetStartCountNode( start_node ); + vf_Node *start_node = (vf_Node *) graph->GetStartNode(); + graph->SetStartCountNode(start_node); start_node->m_mark = VF_START_MARK; // enumerate graph nodes - for( unsigned index = 0; index < graph->GetReachableNodeCount(); - index++ ) { + for (unsigned index = 0; index < graph->GetReachableNodeCount(); index++) { // get node by count element - vf_NodeHandle node = graph->GetReachableNode( index ); - assert( node ); + vf_NodeHandle node = graph->GetReachableNode(index); + assert(node); // get node mark int mark = node->m_mark; // override all out edges of node - for( vf_EdgeHandle outedge = node->m_outedge; - outedge; outedge = outedge->m_outnext ) { + for (vf_EdgeHandle outedge = node->m_outedge; + outedge; outedge = outedge->m_outnext) { // get out node and its mark - vf_Node *outnode = (vf_Node*)outedge->m_end; + vf_Node *outnode = (vf_Node *) outedge->m_end; int out_node_mark = outnode->m_mark; - if( !out_node_mark ) { + if (!out_node_mark) { // it's unnumerated node, enumerate it - graph->AddReachableNode( outnode ); + graph->AddReachableNode(outnode); outnode->m_mark = mark + 1; } } @@ -1307,11 +1266,10 @@ /** * Provides data flow checks of verifier graph structure. */ -vf_Result -vf_check_graph_data_flow( vf_Context *ctx ) // verification context +vf_Result vf_check_graph_data_flow(vf_Context *ctx) // verification context { // enumerate graph - vf_enumerate_graph_node( ctx ); + vf_enumerate_graph_node(ctx); // clean node marks, set a mark bit when IN or OUT node stack maps // get initialized @@ -1319,26 +1277,26 @@ graph->CleanNodeMarks(); // set a map for a start node - vf_create_start_map( ctx ); + vf_create_start_map(ctx); // check graph data flow bool need_recheck = false; unsigned count = 0; do { - vf_NodeHandle node = graph->GetReachableNode( count ); + vf_NodeHandle node = graph->GetReachableNode(count); vf_Result result = - vf_check_node_data_flow( node, &count, &need_recheck, ctx ); - if( VER_OK != result ) { + vf_check_node_data_flow(node, &count, &need_recheck, ctx); + if (VF_OK != result) { return result; } - if( !need_recheck ) { + if (!need_recheck) { // check next node count++; } else { need_recheck = false; } } - while( count < graph->GetReachableNodeCount() ); + while (count < graph->GetReachableNodeCount()); - return VER_OK; + return VF_OK; } // vf_check_graph_data_flow