asan_interface_internal.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. //===-- asan_interface_internal.h -------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file is a part of AddressSanitizer, an address sanity checker.
  10. //
  11. // This header declares the AddressSanitizer runtime interface functions.
  12. // The runtime library has to define these functions so the instrumented program
  13. // could call them.
  14. //
  15. // See also include/sanitizer/asan_interface.h
  16. //===----------------------------------------------------------------------===//
  17. #ifndef ASAN_INTERFACE_INTERNAL_H
  18. #define ASAN_INTERFACE_INTERNAL_H
  19. #include "sanitizer_common/sanitizer_internal_defs.h"
  20. #include "asan_init_version.h"
  21. using __sanitizer::uptr;
  22. using __sanitizer::u64;
  23. using __sanitizer::u32;
  24. extern "C" {
  25. // This function should be called at the very beginning of the process,
  26. // before any instrumented code is executed and before any call to malloc.
  27. SANITIZER_INTERFACE_ATTRIBUTE void __asan_init();
  28. // This function exists purely to get a linker/loader error when using
  29. // incompatible versions of instrumentation and runtime library. Please note
  30. // that __asan_version_mismatch_check is a macro that is replaced with
  31. // __asan_version_mismatch_check_vXXX at compile-time.
  32. SANITIZER_INTERFACE_ATTRIBUTE void __asan_version_mismatch_check();
  33. // This structure is used to describe the source location of a place where
  34. // global was defined.
  35. struct __asan_global_source_location {
  36. const char *filename;
  37. int line_no;
  38. int column_no;
  39. };
  40. // This structure describes an instrumented global variable.
  41. struct __asan_global {
  42. uptr beg; // The address of the global.
  43. uptr size; // The original size of the global.
  44. uptr size_with_redzone; // The size with the redzone.
  45. const char *name; // Name as a C string.
  46. const char *module_name; // Module name as a C string. This pointer is a
  47. // unique identifier of a module.
  48. uptr has_dynamic_init; // Non-zero if the global has dynamic initializer.
  49. __asan_global_source_location *location; // Source location of a global,
  50. // or NULL if it is unknown.
  51. uptr odr_indicator; // The address of the ODR indicator symbol.
  52. };
  53. // These functions can be called on some platforms to find globals in the same
  54. // loaded image as `flag' and apply __asan_(un)register_globals to them,
  55. // filtering out redundant calls.
  56. SANITIZER_INTERFACE_ATTRIBUTE
  57. void __asan_register_image_globals(uptr *flag);
  58. SANITIZER_INTERFACE_ATTRIBUTE
  59. void __asan_unregister_image_globals(uptr *flag);
  60. SANITIZER_INTERFACE_ATTRIBUTE
  61. void __asan_register_elf_globals(uptr *flag, void *start, void *stop);
  62. SANITIZER_INTERFACE_ATTRIBUTE
  63. void __asan_unregister_elf_globals(uptr *flag, void *start, void *stop);
  64. // These two functions should be called by the instrumented code.
  65. // 'globals' is an array of structures describing 'n' globals.
  66. SANITIZER_INTERFACE_ATTRIBUTE
  67. void __asan_register_globals(__asan_global *globals, uptr n);
  68. SANITIZER_INTERFACE_ATTRIBUTE
  69. void __asan_unregister_globals(__asan_global *globals, uptr n);
  70. // These two functions should be called before and after dynamic initializers
  71. // of a single module run, respectively.
  72. SANITIZER_INTERFACE_ATTRIBUTE
  73. void __asan_before_dynamic_init(const char *module_name);
  74. SANITIZER_INTERFACE_ATTRIBUTE
  75. void __asan_after_dynamic_init();
  76. // Sets bytes of the given range of the shadow memory into specific value.
  77. SANITIZER_INTERFACE_ATTRIBUTE
  78. void __asan_set_shadow_00(uptr addr, uptr size);
  79. SANITIZER_INTERFACE_ATTRIBUTE
  80. void __asan_set_shadow_f1(uptr addr, uptr size);
  81. SANITIZER_INTERFACE_ATTRIBUTE
  82. void __asan_set_shadow_f2(uptr addr, uptr size);
  83. SANITIZER_INTERFACE_ATTRIBUTE
  84. void __asan_set_shadow_f3(uptr addr, uptr size);
  85. SANITIZER_INTERFACE_ATTRIBUTE
  86. void __asan_set_shadow_f5(uptr addr, uptr size);
  87. SANITIZER_INTERFACE_ATTRIBUTE
  88. void __asan_set_shadow_f8(uptr addr, uptr size);
  89. // These two functions are used by instrumented code in the
  90. // use-after-scope mode. They mark memory for local variables as
  91. // unaddressable when they leave scope and addressable before the
  92. // function exits.
  93. SANITIZER_INTERFACE_ATTRIBUTE
  94. void __asan_poison_stack_memory(uptr addr, uptr size);
  95. SANITIZER_INTERFACE_ATTRIBUTE
  96. void __asan_unpoison_stack_memory(uptr addr, uptr size);
  97. // Performs cleanup before a NoReturn function. Must be called before things
  98. // like _exit and execl to avoid false positives on stack.
  99. SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
  100. SANITIZER_INTERFACE_ATTRIBUTE
  101. void __asan_poison_memory_region(void const volatile *addr, uptr size);
  102. SANITIZER_INTERFACE_ATTRIBUTE
  103. void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
  104. SANITIZER_INTERFACE_ATTRIBUTE
  105. int __asan_address_is_poisoned(void const volatile *addr);
  106. SANITIZER_INTERFACE_ATTRIBUTE
  107. uptr __asan_region_is_poisoned(uptr beg, uptr size);
  108. SANITIZER_INTERFACE_ATTRIBUTE
  109. void __asan_describe_address(uptr addr);
  110. SANITIZER_INTERFACE_ATTRIBUTE
  111. int __asan_report_present();
  112. SANITIZER_INTERFACE_ATTRIBUTE
  113. uptr __asan_get_report_pc();
  114. SANITIZER_INTERFACE_ATTRIBUTE
  115. uptr __asan_get_report_bp();
  116. SANITIZER_INTERFACE_ATTRIBUTE
  117. uptr __asan_get_report_sp();
  118. SANITIZER_INTERFACE_ATTRIBUTE
  119. uptr __asan_get_report_address();
  120. SANITIZER_INTERFACE_ATTRIBUTE
  121. int __asan_get_report_access_type();
  122. SANITIZER_INTERFACE_ATTRIBUTE
  123. uptr __asan_get_report_access_size();
  124. SANITIZER_INTERFACE_ATTRIBUTE
  125. const char * __asan_get_report_description();
  126. SANITIZER_INTERFACE_ATTRIBUTE
  127. const char * __asan_locate_address(uptr addr, char *name, uptr name_size,
  128. uptr *region_address, uptr *region_size);
  129. SANITIZER_INTERFACE_ATTRIBUTE
  130. uptr __asan_get_alloc_stack(uptr addr, uptr *trace, uptr size,
  131. u32 *thread_id);
  132. SANITIZER_INTERFACE_ATTRIBUTE
  133. uptr __asan_get_free_stack(uptr addr, uptr *trace, uptr size,
  134. u32 *thread_id);
  135. SANITIZER_INTERFACE_ATTRIBUTE
  136. void __asan_get_shadow_mapping(uptr *shadow_scale, uptr *shadow_offset);
  137. SANITIZER_INTERFACE_ATTRIBUTE
  138. void __asan_report_error(uptr pc, uptr bp, uptr sp,
  139. uptr addr, int is_write, uptr access_size, u32 exp);
  140. SANITIZER_INTERFACE_ATTRIBUTE
  141. void __asan_set_death_callback(void (*callback)(void));
  142. SANITIZER_INTERFACE_ATTRIBUTE
  143. void __asan_set_error_report_callback(void (*callback)(const char*));
  144. SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
  145. void __asan_on_error();
  146. SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
  147. SANITIZER_INTERFACE_ATTRIBUTE
  148. const char *__asan_default_options();
  149. SANITIZER_INTERFACE_ATTRIBUTE
  150. extern uptr __asan_shadow_memory_dynamic_address;
  151. // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return
  152. SANITIZER_INTERFACE_ATTRIBUTE
  153. extern int __asan_option_detect_stack_use_after_return;
  154. SANITIZER_INTERFACE_ATTRIBUTE
  155. extern uptr *__asan_test_only_reported_buggy_pointer;
  156. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p);
  157. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p);
  158. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p);
  159. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p);
  160. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p);
  161. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p);
  162. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p);
  163. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p);
  164. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p);
  165. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
  166. SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
  167. SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
  168. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1_noabort(uptr p);
  169. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2_noabort(uptr p);
  170. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4_noabort(uptr p);
  171. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8_noabort(uptr p);
  172. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16_noabort(uptr p);
  173. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1_noabort(uptr p);
  174. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2_noabort(uptr p);
  175. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4_noabort(uptr p);
  176. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8_noabort(uptr p);
  177. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16_noabort(uptr p);
  178. SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN_noabort(uptr p, uptr size);
  179. SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN_noabort(uptr p, uptr size);
  180. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load1(uptr p, u32 exp);
  181. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load2(uptr p, u32 exp);
  182. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load4(uptr p, u32 exp);
  183. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load8(uptr p, u32 exp);
  184. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_load16(uptr p, u32 exp);
  185. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store1(uptr p, u32 exp);
  186. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store2(uptr p, u32 exp);
  187. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store4(uptr p, u32 exp);
  188. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store8(uptr p, u32 exp);
  189. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_store16(uptr p, u32 exp);
  190. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_loadN(uptr p, uptr size,
  191. u32 exp);
  192. SANITIZER_INTERFACE_ATTRIBUTE void __asan_exp_storeN(uptr p, uptr size,
  193. u32 exp);
  194. SANITIZER_INTERFACE_ATTRIBUTE
  195. void* __asan_memcpy(void *dst, const void *src, uptr size);
  196. SANITIZER_INTERFACE_ATTRIBUTE
  197. void* __asan_memset(void *s, int c, uptr n);
  198. SANITIZER_INTERFACE_ATTRIBUTE
  199. void* __asan_memmove(void* dest, const void* src, uptr n);
  200. SANITIZER_INTERFACE_ATTRIBUTE
  201. void __asan_poison_cxx_array_cookie(uptr p);
  202. SANITIZER_INTERFACE_ATTRIBUTE
  203. uptr __asan_load_cxx_array_cookie(uptr *p);
  204. SANITIZER_INTERFACE_ATTRIBUTE
  205. void __asan_poison_intra_object_redzone(uptr p, uptr size);
  206. SANITIZER_INTERFACE_ATTRIBUTE
  207. void __asan_unpoison_intra_object_redzone(uptr p, uptr size);
  208. SANITIZER_INTERFACE_ATTRIBUTE
  209. void __asan_alloca_poison(uptr addr, uptr size);
  210. SANITIZER_INTERFACE_ATTRIBUTE
  211. void __asan_allocas_unpoison(uptr top, uptr bottom);
  212. SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
  213. const char* __asan_default_suppressions();
  214. SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_vfork(void *sp);
  215. SANITIZER_INTERFACE_ATTRIBUTE int __asan_update_allocation_context(
  216. void *addr);
  217. } // extern "C"
  218. #endif // ASAN_INTERFACE_INTERNAL_H