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