asan_interface_internal.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. //===-- asan_interface_internal.h -------------------------------*- C++ -*-===//
  2. //
  3. // This file is distributed under the University of Illinois Open Source
  4. // License. See LICENSE.TXT for details.
  5. //
  6. //===----------------------------------------------------------------------===//
  7. //
  8. // This file is a part of AddressSanitizer, an address sanity checker.
  9. //
  10. // This header can be included by the instrumented program to fetch
  11. // data (mostly allocator statistics) from ASan runtime library.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef ASAN_INTERFACE_INTERNAL_H
  14. #define ASAN_INTERFACE_INTERNAL_H
  15. #include "sanitizer_common/sanitizer_internal_defs.h"
  16. #include "asan_init_version.h"
  17. using __sanitizer::uptr;
  18. extern "C" {
  19. // This function should be called at the very beginning of the process,
  20. // before any instrumented code is executed and before any call to malloc.
  21. // Please note that __asan_init is a macro that is replaced with
  22. // __asan_init_vXXX at compile-time.
  23. SANITIZER_INTERFACE_ATTRIBUTE void __asan_init();
  24. // This structure is used to describe the source location of a place where
  25. // global was defined.
  26. struct __asan_global_source_location {
  27. const char *filename;
  28. int line_no;
  29. int column_no;
  30. };
  31. // This structure describes an instrumented global variable.
  32. struct __asan_global {
  33. uptr beg; // The address of the global.
  34. uptr size; // The original size of the global.
  35. uptr size_with_redzone; // The size with the redzone.
  36. const char *name; // Name as a C string.
  37. const char *module_name; // Module name as a C string. This pointer is a
  38. // unique identifier of a module.
  39. uptr has_dynamic_init; // Non-zero if the global has dynamic initializer.
  40. __asan_global_source_location *location; // Source location of a global,
  41. // or NULL if it is unknown.
  42. };
  43. // These two functions should be called by the instrumented code.
  44. // 'globals' is an array of structures describing 'n' globals.
  45. SANITIZER_INTERFACE_ATTRIBUTE
  46. void __asan_register_globals(__asan_global *globals, uptr n);
  47. SANITIZER_INTERFACE_ATTRIBUTE
  48. void __asan_unregister_globals(__asan_global *globals, uptr n);
  49. // These two functions should be called before and after dynamic initializers
  50. // of a single module run, respectively.
  51. SANITIZER_INTERFACE_ATTRIBUTE
  52. void __asan_before_dynamic_init(const char *module_name);
  53. SANITIZER_INTERFACE_ATTRIBUTE
  54. void __asan_after_dynamic_init();
  55. // These two functions are used by instrumented code in the
  56. // use-after-scope mode. They mark memory for local variables as
  57. // unaddressable when they leave scope and addressable before the
  58. // function exits.
  59. SANITIZER_INTERFACE_ATTRIBUTE
  60. void __asan_poison_stack_memory(uptr addr, uptr size);
  61. SANITIZER_INTERFACE_ATTRIBUTE
  62. void __asan_unpoison_stack_memory(uptr addr, uptr size);
  63. // Performs cleanup before a NoReturn function. Must be called before things
  64. // like _exit and execl to avoid false positives on stack.
  65. SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
  66. SANITIZER_INTERFACE_ATTRIBUTE
  67. void __asan_poison_memory_region(void const volatile *addr, uptr size);
  68. SANITIZER_INTERFACE_ATTRIBUTE
  69. void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
  70. SANITIZER_INTERFACE_ATTRIBUTE
  71. int __asan_address_is_poisoned(void const volatile *addr);
  72. SANITIZER_INTERFACE_ATTRIBUTE
  73. uptr __asan_region_is_poisoned(uptr beg, uptr size);
  74. SANITIZER_INTERFACE_ATTRIBUTE
  75. void __asan_describe_address(uptr addr);
  76. SANITIZER_INTERFACE_ATTRIBUTE
  77. int __asan_report_present();
  78. SANITIZER_INTERFACE_ATTRIBUTE
  79. uptr __asan_get_report_pc();
  80. SANITIZER_INTERFACE_ATTRIBUTE
  81. uptr __asan_get_report_bp();
  82. SANITIZER_INTERFACE_ATTRIBUTE
  83. uptr __asan_get_report_sp();
  84. SANITIZER_INTERFACE_ATTRIBUTE
  85. uptr __asan_get_report_address();
  86. SANITIZER_INTERFACE_ATTRIBUTE
  87. int __asan_get_report_access_type();
  88. SANITIZER_INTERFACE_ATTRIBUTE
  89. uptr __asan_get_report_access_size();
  90. SANITIZER_INTERFACE_ATTRIBUTE
  91. const char * __asan_get_report_description();
  92. SANITIZER_INTERFACE_ATTRIBUTE
  93. const char * __asan_locate_address(uptr addr, char *name, uptr name_size,
  94. uptr *region_address, uptr *region_size);
  95. SANITIZER_INTERFACE_ATTRIBUTE
  96. uptr __asan_get_alloc_stack(uptr addr, uptr *trace, uptr size,
  97. u32 *thread_id);
  98. SANITIZER_INTERFACE_ATTRIBUTE
  99. uptr __asan_get_free_stack(uptr addr, uptr *trace, uptr size,
  100. u32 *thread_id);
  101. SANITIZER_INTERFACE_ATTRIBUTE
  102. void __asan_get_shadow_mapping(uptr *shadow_scale, uptr *shadow_offset);
  103. SANITIZER_INTERFACE_ATTRIBUTE
  104. void __asan_report_error(uptr pc, uptr bp, uptr sp,
  105. uptr addr, int is_write, uptr access_size);
  106. SANITIZER_INTERFACE_ATTRIBUTE
  107. int __asan_set_error_exit_code(int exit_code);
  108. SANITIZER_INTERFACE_ATTRIBUTE
  109. void __asan_set_death_callback(void (*callback)(void));
  110. SANITIZER_INTERFACE_ATTRIBUTE
  111. void __asan_set_error_report_callback(void (*callback)(const char*));
  112. SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
  113. /* OPTIONAL */ void __asan_on_error();
  114. SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
  115. SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
  116. /* OPTIONAL */ const char* __asan_default_options();
  117. // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return
  118. SANITIZER_INTERFACE_ATTRIBUTE
  119. extern int __asan_option_detect_stack_use_after_return;
  120. SANITIZER_INTERFACE_ATTRIBUTE
  121. extern uptr *__asan_test_only_reported_buggy_pointer;
  122. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p);
  123. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p);
  124. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p);
  125. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p);
  126. SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p);
  127. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p);
  128. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p);
  129. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p);
  130. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p);
  131. SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
  132. SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
  133. SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
  134. SANITIZER_INTERFACE_ATTRIBUTE
  135. void* __asan_memcpy(void *dst, const void *src, uptr size);
  136. SANITIZER_INTERFACE_ATTRIBUTE
  137. void* __asan_memset(void *s, int c, uptr n);
  138. SANITIZER_INTERFACE_ATTRIBUTE
  139. void* __asan_memmove(void* dest, const void* src, uptr n);
  140. SANITIZER_INTERFACE_ATTRIBUTE
  141. void __asan_poison_cxx_array_cookie(uptr p);
  142. SANITIZER_INTERFACE_ATTRIBUTE
  143. uptr __asan_load_cxx_array_cookie(uptr *p);
  144. SANITIZER_INTERFACE_ATTRIBUTE
  145. void __asan_poison_intra_object_redzone(uptr p, uptr size);
  146. SANITIZER_INTERFACE_ATTRIBUTE
  147. void __asan_unpoison_intra_object_redzone(uptr p, uptr size);
  148. } // extern "C"
  149. #endif // ASAN_INTERFACE_INTERNAL_H