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 using __sanitizer::uptr; 21 22 extern "C" { 23 // This function should be called at the very beginning of the process, 24 // before any instrumented code is executed and before any call to malloc. 25 // Everytime the asan ABI changes we also change the version number in this 26 // name. Objects build with incompatible asan ABI version 27 // will not link with run-time. 28 void __asan_init_v2() SANITIZER_INTERFACE_ATTRIBUTE; 29 #define __asan_init __asan_init_v2 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. 38 uptr has_dynamic_init; // Non-zero if the global has dynamic initializer. 39 }; 40 41 // These two functions should be called by the instrumented code. 42 // 'globals' is an array of structures describing 'n' globals. 43 void __asan_register_globals(__asan_global *globals, uptr n) 44 SANITIZER_INTERFACE_ATTRIBUTE; 45 void __asan_unregister_globals(__asan_global *globals, uptr n) 46 SANITIZER_INTERFACE_ATTRIBUTE; 47 48 // These two functions should be called before and after dynamic initializers 49 // run, respectively. They should be called with parameters describing all 50 // dynamically initialized globals defined in the calling TU. 51 void __asan_before_dynamic_init(uptr first_addr, uptr last_addr) 52 SANITIZER_INTERFACE_ATTRIBUTE; 53 void __asan_after_dynamic_init() 54 SANITIZER_INTERFACE_ATTRIBUTE; 55 56 // These two functions are used by the instrumented code in the 57 // use-after-return mode. __asan_stack_malloc allocates size bytes of 58 // fake stack and __asan_stack_free poisons it. real_stack is a pointer to 59 // the real stack region. 60 uptr __asan_stack_malloc(uptr size, uptr real_stack) 61 SANITIZER_INTERFACE_ATTRIBUTE; 62 void __asan_stack_free(uptr ptr, uptr size, uptr real_stack) 63 SANITIZER_INTERFACE_ATTRIBUTE; 64 65 // These two functions are used by instrumented code in the 66 // use-after-scope mode. They mark memory for local variables as 67 // unaddressable when they leave scope and addressable before the 68 // function exits. 69 void __asan_poison_stack_memory(uptr addr, uptr size) 70 SANITIZER_INTERFACE_ATTRIBUTE; 71 void __asan_unpoison_stack_memory(uptr addr, uptr size) 72 SANITIZER_INTERFACE_ATTRIBUTE; 73 74 // Performs cleanup before a NoReturn function. Must be called before things 75 // like _exit and execl to avoid false positives on stack. 76 void __asan_handle_no_return() SANITIZER_INTERFACE_ATTRIBUTE; 77 78 void __asan_poison_memory_region(void const volatile *addr, uptr size) 79 SANITIZER_INTERFACE_ATTRIBUTE; 80 void __asan_unpoison_memory_region(void const volatile *addr, uptr size) 81 SANITIZER_INTERFACE_ATTRIBUTE; 82 83 bool __asan_address_is_poisoned(void const volatile *addr) 84 SANITIZER_INTERFACE_ATTRIBUTE; 85 86 uptr __asan_region_is_poisoned(uptr beg, uptr size) 87 SANITIZER_INTERFACE_ATTRIBUTE; 88 89 void __asan_describe_address(uptr addr) 90 SANITIZER_INTERFACE_ATTRIBUTE; 91 92 void __asan_report_error(uptr pc, uptr bp, uptr sp, 93 uptr addr, bool is_write, uptr access_size) 94 SANITIZER_INTERFACE_ATTRIBUTE; 95 96 int __asan_set_error_exit_code(int exit_code) 97 SANITIZER_INTERFACE_ATTRIBUTE; 98 void __asan_set_death_callback(void (*callback)(void)) 99 SANITIZER_INTERFACE_ATTRIBUTE; 100 void __asan_set_error_report_callback(void (*callback)(const char*)) 101 SANITIZER_INTERFACE_ATTRIBUTE; 102 103 /* OPTIONAL */ void __asan_on_error() 104 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE; 105 106 /* OPTIONAL */ bool __asan_symbolize(const void *pc, char *out_buffer, 107 int out_size) 108 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE; 109 110 uptr __asan_get_estimated_allocated_size(uptr size) 111 SANITIZER_INTERFACE_ATTRIBUTE; 112 bool __asan_get_ownership(const void *p) 113 SANITIZER_INTERFACE_ATTRIBUTE; 114 uptr __asan_get_allocated_size(const void *p) 115 SANITIZER_INTERFACE_ATTRIBUTE; 116 uptr __asan_get_current_allocated_bytes() 117 SANITIZER_INTERFACE_ATTRIBUTE; 118 uptr __asan_get_heap_size() 119 SANITIZER_INTERFACE_ATTRIBUTE; 120 uptr __asan_get_free_bytes() 121 SANITIZER_INTERFACE_ATTRIBUTE; 122 uptr __asan_get_unmapped_bytes() 123 SANITIZER_INTERFACE_ATTRIBUTE; 124 void __asan_print_accumulated_stats() 125 SANITIZER_INTERFACE_ATTRIBUTE; 126 127 /* OPTIONAL */ const char* __asan_default_options() 128 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE; 129 130 /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size) 131 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE; 132 /* OPTIONAL */ void __asan_free_hook(void *ptr) 133 SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE; 134 } // extern "C" 135 136 #endif // ASAN_INTERFACE_INTERNAL_H 137