verify.h 5.2 KB

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