1/* Declarations to interface gcj with bytecode verifier.
2   Copyright (C) 2003-2015 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GCC; see the file COPYING3.  If not see
18<http://www.gnu.org/licenses/>.
19
20Java and all Java-based marks are trademarks or registered trademarks
21of Sun Microsystems, Inc. in the United States and other countries.
22The Free Software Foundation is independent of Sun Microsystems, Inc.  */
23
24/* Written by Tom Tromey <tromey@redhat.com>.  */
25
26#ifndef GCC_VERIFY_H
27#define GCC_VERIFY_H
28
29#include "jcf.h"
30#include "tree.h"
31#include "java-tree.h"
32
33typedef JCF vfy_constants;
34
35/* For our purposes a string is the same as an identifier.  */
36typedef tree vfy_string;
37
38/* The TYPE_DECL for a class or primitive type.  */
39typedef tree vfy_jclass;
40
41/* An unsigned jshort.  */
42typedef uint16 vfy_uint_16;
43
44typedef struct
45{
46  int handler, start, end, type;
47} vfy_exception;
48
49typedef struct
50{
51  tree method;
52  vfy_string signature;
53  vfy_string name;
54  const unsigned char *bytes;
55  vfy_exception *exceptions;
56
57  /* These fields are referred to directly by the verifier.  */
58  vfy_jclass defining_class;
59  int max_stack;
60  int max_locals;
61  int code_length;
62  int exc_count;
63} vfy_method;
64
65/* Entry point to the verifier.  */
66int verify_jvm_instructions_new (JCF *jcf, const unsigned char *byte_ops,
67				 long length);
68
69void *vfy_alloc (size_t bytes);
70void vfy_free (void *mem);
71bool vfy_strings_equal (vfy_string one, vfy_string two);
72const char *vfy_string_bytes (vfy_string str);
73int vfy_string_length (vfy_string str);
74vfy_string vfy_get_string (const char *chars, int length);
75vfy_string vfy_init_name (void);
76vfy_string vfy_clinit_name (void);
77int vfy_count_arguments (vfy_string signature);
78vfy_string vfy_get_signature (vfy_method *method);
79vfy_string vfy_get_method_name (vfy_method *method);
80bool vfy_is_static (vfy_method *method);
81const unsigned char *vfy_get_bytecode (vfy_method *method);
82vfy_exception *vfy_get_exceptions (vfy_method *method);
83void vfy_get_exception (vfy_exception *, int index, int *handler,
84			int *start, int *end, int *handler_type);
85int vfy_tag (vfy_constants *pool, int index);
86void vfy_load_indexes (vfy_constants *pool, int index,
87		       vfy_uint_16 *index0, vfy_uint_16 *index1);
88vfy_constants *vfy_get_constants (vfy_jclass klass);
89int vfy_get_constants_size (vfy_jclass klass);
90vfy_string vfy_get_pool_string (vfy_constants *pool, int index);
91vfy_jclass vfy_get_pool_class (vfy_constants *pool, int index);
92vfy_string vfy_get_class_name (vfy_jclass klass);
93bool vfy_is_assignable_from (vfy_jclass target, vfy_jclass source);
94char vfy_get_primitive_char (vfy_jclass klass);
95int vfy_get_interface_count (vfy_jclass klass);
96vfy_jclass vfy_get_interface (vfy_jclass klass, int index);
97bool vfy_is_array (vfy_jclass klass);
98bool vfy_is_interface (vfy_jclass klass);
99bool vfy_is_primitive (vfy_jclass klass);
100vfy_jclass vfy_get_superclass (vfy_jclass klass);
101vfy_jclass vfy_get_array_class (vfy_jclass klass);
102vfy_jclass vfy_get_component_type (vfy_jclass klass);
103bool vfy_is_abstract (vfy_jclass klass);
104vfy_jclass vfy_find_class (vfy_jclass klass, vfy_string name);
105vfy_jclass vfy_object_type (void);
106vfy_jclass vfy_class_type (void);
107vfy_jclass vfy_string_type (void);
108vfy_jclass vfy_throwable_type (void);
109vfy_jclass vfy_unsuitable_type (void);
110vfy_jclass vfy_return_address_type (void);
111vfy_jclass vfy_null_type (void);
112int vfy_fail (const char *message, int pc, vfy_jclass ignore1,
113	      vfy_method *method);
114vfy_jclass vfy_get_primitive_type (int type);
115void vfy_note_stack_depth (vfy_method *method, int pc, int depth);
116void vfy_note_stack_type (vfy_method *method, int pc, int slot,
117			  vfy_jclass type);
118void vfy_note_local_type (vfy_method *method, int pc, int slot,
119			  vfy_jclass type);
120void vfy_note_instruction_seen (int pc);
121bool vfy_class_has_field (vfy_jclass klass, vfy_string name,
122			  vfy_string signature);
123
124#define GLOM(name, stuff) name ## stuff
125#define VFY_PRIMITIVE_CLASS(name) \
126  vfy_get_primitive_type ((int) (GLOM (name, _type)))
127
128typedef enum
129{
130#define JAVAOP(name, num, ignore1, ignore2, ignore3) \
131  GLOM (op_, name) = num,
132#include "javaop.def"
133  java_opcode_end
134} java_opcode;
135
136
137#define JV_CONSTANT_Class CONSTANT_Class
138#define JV_CONSTANT_ResolvedClass CONSTANT_ResolvedClass
139#define JV_CONSTANT_String CONSTANT_String
140#define JV_CONSTANT_ResolvedString CONSTANT_ResolvedString
141#define JV_CONSTANT_Integer CONSTANT_Integer
142#define JV_CONSTANT_Float CONSTANT_Float
143#define JV_CONSTANT_Long CONSTANT_Long
144#define JV_CONSTANT_Double CONSTANT_Double
145#define JV_CONSTANT_Fieldref CONSTANT_Fieldref
146#define JV_CONSTANT_InterfaceMethodref CONSTANT_InterfaceMethodref
147#define JV_CONSTANT_Methodref CONSTANT_Methodref
148
149int verify_method (vfy_method *meth);
150
151#endif /* ! GCC_VERIFY_H */
152