asan_interface_internal.h revision 274201
1226584Sdim//===-- asan_interface_internal.h -------------------------------*- C++ -*-===// 2226584Sdim// 3226584Sdim// The LLVM Compiler Infrastructure 4226584Sdim// 5226584Sdim// This file is distributed under the University of Illinois Open Source 6226584Sdim// License. See LICENSE.TXT for details. 7226584Sdim// 8226584Sdim//===----------------------------------------------------------------------===// 9226584Sdim// 10226584Sdim// This file is a part of AddressSanitizer, an address sanity checker. 11226584Sdim// 12226584Sdim// This header can be included by the instrumented program to fetch 13226584Sdim// data (mostly allocator statistics) from ASan runtime library. 14226584Sdim//===----------------------------------------------------------------------===// 15226584Sdim#ifndef ASAN_INTERFACE_INTERNAL_H 16226584Sdim#define ASAN_INTERFACE_INTERNAL_H 17249423Sdim 18226584Sdim#include "sanitizer_common/sanitizer_internal_defs.h" 19249423Sdim 20263508Sdimusing __sanitizer::uptr; 21249423Sdim 22226584Sdimextern "C" { 23226584Sdim // This function should be called at the very beginning of the process, 24226584Sdim // before any instrumented code is executed and before any call to malloc. 25249423Sdim // Everytime the asan ABI changes we also change the version number in this 26249423Sdim // name. Objects build with incompatible asan ABI version 27249423Sdim // will not link with run-time. 28249423Sdim // Changes between ABI versions: 29249423Sdim // v1=>v2: added 'module_name' to __asan_global 30249423Sdim // v2=>v3: stack frame description (created by the compiler) 31249423Sdim // contains the function PC as the 3-rd field (see 32249423Sdim // DescribeAddressIfStack). 33226584Sdim SANITIZER_INTERFACE_ATTRIBUTE void __asan_init_v3(); 34263508Sdim #define __asan_init __asan_init_v3 35263508Sdim 36249423Sdim // This structure describes an instrumented global variable. 37263508Sdim struct __asan_global { 38263508Sdim uptr beg; // The address of the global. 39263508Sdim uptr size; // The original size of the global. 40263508Sdim uptr size_with_redzone; // The size with the redzone. 41263508Sdim const char *name; // Name as a C string. 42263508Sdim const char *module_name; // Module name as a C string. This pointer is a 43263508Sdim // unique identifier of a module. 44249423Sdim uptr has_dynamic_init; // Non-zero if the global has dynamic initializer. 45249423Sdim }; 46226584Sdim 47234353Sdim // These two functions should be called by the instrumented code. 48226584Sdim // 'globals' is an array of structures describing 'n' globals. 49226584Sdim SANITIZER_INTERFACE_ATTRIBUTE 50226584Sdim void __asan_register_globals(__asan_global *globals, uptr n); 51249423Sdim SANITIZER_INTERFACE_ATTRIBUTE 52226584Sdim void __asan_unregister_globals(__asan_global *globals, uptr n); 53249423Sdim 54249423Sdim // These two functions should be called before and after dynamic initializers 55226584Sdim // of a single module run, respectively. 56263508Sdim SANITIZER_INTERFACE_ATTRIBUTE 57263508Sdim void __asan_before_dynamic_init(const char *module_name); 58249423Sdim SANITIZER_INTERFACE_ATTRIBUTE 59226584Sdim void __asan_after_dynamic_init(); 60263508Sdim 61263508Sdim // These two functions are used by instrumented code in the 62263508Sdim // use-after-scope mode. They mark memory for local variables as 63226584Sdim // unaddressable when they leave scope and addressable before the 64263508Sdim // function exits. 65263508Sdim SANITIZER_INTERFACE_ATTRIBUTE 66226584Sdim void __asan_poison_stack_memory(uptr addr, uptr size); 67226584Sdim SANITIZER_INTERFACE_ATTRIBUTE 68234353Sdim void __asan_unpoison_stack_memory(uptr addr, uptr size); 69234353Sdim 70234353Sdim // Performs cleanup before a NoReturn function. Must be called before things 71234353Sdim // like _exit and execl to avoid false positives on stack. 72263508Sdim SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return(); 73249423Sdim 74263508Sdim SANITIZER_INTERFACE_ATTRIBUTE 75263508Sdim void __asan_poison_memory_region(void const volatile *addr, uptr size); 76263508Sdim SANITIZER_INTERFACE_ATTRIBUTE 77263508Sdim void __asan_unpoison_memory_region(void const volatile *addr, uptr size); 78249423Sdim 79263508Sdim SANITIZER_INTERFACE_ATTRIBUTE 80263508Sdim bool __asan_address_is_poisoned(void const volatile *addr); 81263508Sdim 82263508Sdim SANITIZER_INTERFACE_ATTRIBUTE 83263508Sdim uptr __asan_region_is_poisoned(uptr beg, uptr size); 84249423Sdim 85249423Sdim SANITIZER_INTERFACE_ATTRIBUTE 86226584Sdim void __asan_describe_address(uptr addr); 87249423Sdim 88249423Sdim SANITIZER_INTERFACE_ATTRIBUTE 89249423Sdim void __asan_report_error(uptr pc, uptr bp, uptr sp, 90249423Sdim uptr addr, bool is_write, uptr access_size); 91249423Sdim 92263508Sdim SANITIZER_INTERFACE_ATTRIBUTE 93249423Sdim int __asan_set_error_exit_code(int exit_code); 94226584Sdim SANITIZER_INTERFACE_ATTRIBUTE 95226584Sdim void __asan_set_death_callback(void (*callback)(void)); 96226584Sdim SANITIZER_INTERFACE_ATTRIBUTE 97226584Sdim void __asan_set_error_report_callback(void (*callback)(const char*)); 98226584Sdim 99226584Sdim SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 100263508Sdim /* OPTIONAL */ void __asan_on_error(); 101226584Sdim 102226584Sdim SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 103226584Sdim /* OPTIONAL */ bool __asan_symbolize(const void *pc, char *out_buffer, 104226584Sdim int out_size); 105226584Sdim 106226584Sdim SANITIZER_INTERFACE_ATTRIBUTE 107226584Sdim uptr __asan_get_estimated_allocated_size(uptr size); 108226584Sdim 109226584Sdim SANITIZER_INTERFACE_ATTRIBUTE bool __asan_get_ownership(const void *p); 110226584Sdim SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_allocated_size(const void *p); 111226584Sdim SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_current_allocated_bytes(); 112226584Sdim SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_heap_size(); 113226584Sdim SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_free_bytes(); 114234353Sdim SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_unmapped_bytes(); 115234353Sdim SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats(); 116234353Sdim 117234353Sdim SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 118226584Sdim /* OPTIONAL */ const char* __asan_default_options(); 119226584Sdim 120226584Sdim SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 121226584Sdim /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size); 122226584Sdim SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 123226584Sdim /* OPTIONAL */ void __asan_free_hook(void *ptr); 124234353Sdim 125234353Sdim // Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return 126234353Sdim SANITIZER_INTERFACE_ATTRIBUTE 127234353Sdim extern int __asan_option_detect_stack_use_after_return; 128234353Sdim} // extern "C" 129234353Sdim 130234353Sdim#endif // ASAN_INTERFACE_INTERNAL_H 131234353Sdim