asan_interface_internal.h revision 34e3ed1db94c5ce9784d7ffb8d66a54cf523e09c
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 20using __sanitizer::uptr; 21 22extern "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 // Changes between ABI versions: 29 // v1=>v2: added 'module_name' to __asan_global 30 // v2=>v3: stack frame description (created by the compiler) 31 // contains the function PC as the 3-rd field (see 32 // DescribeAddressIfStack). 33 SANITIZER_INTERFACE_ATTRIBUTE void __asan_init_v3(); 34 #define __asan_init __asan_init_v3 35 36 // This structure describes an instrumented global variable. 37 struct __asan_global { 38 uptr beg; // The address of the global. 39 uptr size; // The original size of the global. 40 uptr size_with_redzone; // The size with the redzone. 41 const char *name; // Name as a C string. 42 const char *module_name; // Module name as a C string. This pointer is a 43 // unique identifier of a module. 44 uptr has_dynamic_init; // Non-zero if the global has dynamic initializer. 45 }; 46 47 // These two functions should be called by the instrumented code. 48 // 'globals' is an array of structures describing 'n' globals. 49 SANITIZER_INTERFACE_ATTRIBUTE 50 void __asan_register_globals(__asan_global *globals, uptr n); 51 SANITIZER_INTERFACE_ATTRIBUTE 52 void __asan_unregister_globals(__asan_global *globals, uptr n); 53 54 // These two functions should be called before and after dynamic initializers 55 // of a single module run, respectively. 56 SANITIZER_INTERFACE_ATTRIBUTE 57 void __asan_before_dynamic_init(const char *module_name); 58 SANITIZER_INTERFACE_ATTRIBUTE 59 void __asan_after_dynamic_init(); 60 61 // These two functions are used by instrumented code in the 62 // use-after-scope mode. They mark memory for local variables as 63 // unaddressable when they leave scope and addressable before the 64 // function exits. 65 SANITIZER_INTERFACE_ATTRIBUTE 66 void __asan_poison_stack_memory(uptr addr, uptr size); 67 SANITIZER_INTERFACE_ATTRIBUTE 68 void __asan_unpoison_stack_memory(uptr addr, uptr size); 69 70 // Performs cleanup before a NoReturn function. Must be called before things 71 // like _exit and execl to avoid false positives on stack. 72 SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return(); 73 74 SANITIZER_INTERFACE_ATTRIBUTE 75 void __asan_poison_memory_region(void const volatile *addr, uptr size); 76 SANITIZER_INTERFACE_ATTRIBUTE 77 void __asan_unpoison_memory_region(void const volatile *addr, uptr size); 78 79 SANITIZER_INTERFACE_ATTRIBUTE 80 bool __asan_address_is_poisoned(void const volatile *addr); 81 82 SANITIZER_INTERFACE_ATTRIBUTE 83 uptr __asan_region_is_poisoned(uptr beg, uptr size); 84 85 SANITIZER_INTERFACE_ATTRIBUTE 86 void __asan_describe_address(uptr addr); 87 88 SANITIZER_INTERFACE_ATTRIBUTE 89 void __asan_report_error(uptr pc, uptr bp, uptr sp, 90 uptr addr, bool is_write, uptr access_size); 91 92 SANITIZER_INTERFACE_ATTRIBUTE 93 int __asan_set_error_exit_code(int exit_code); 94 SANITIZER_INTERFACE_ATTRIBUTE 95 void __asan_set_death_callback(void (*callback)(void)); 96 SANITIZER_INTERFACE_ATTRIBUTE 97 void __asan_set_error_report_callback(void (*callback)(const char*)); 98 99 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 100 /* OPTIONAL */ void __asan_on_error(); 101 102 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 103 /* OPTIONAL */ bool __asan_symbolize(const void *pc, char *out_buffer, 104 int out_size); 105 106 SANITIZER_INTERFACE_ATTRIBUTE 107 uptr __asan_get_estimated_allocated_size(uptr size); 108 109 SANITIZER_INTERFACE_ATTRIBUTE bool __asan_get_ownership(const void *p); 110 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_allocated_size(const void *p); 111 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_current_allocated_bytes(); 112 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_heap_size(); 113 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_free_bytes(); 114 SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_unmapped_bytes(); 115 SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats(); 116 117 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 118 /* OPTIONAL */ const char* __asan_default_options(); 119 120 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 121 /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size); 122 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 123 /* OPTIONAL */ void __asan_free_hook(void *ptr); 124} // extern "C" 125 126#endif // ASAN_INTERFACE_INTERNAL_H 127