asan_interface_internal.h revision 3c80c6c574850106481f82b9e23d1c728458d4a9
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 the instrumented code in the
62  // use-after-return mode. __asan_stack_malloc allocates size bytes of
63  // fake stack and __asan_stack_free poisons it. real_stack is a pointer to
64  // the real stack region.
65  SANITIZER_INTERFACE_ATTRIBUTE
66  uptr __asan_stack_malloc(uptr size, uptr real_stack);
67  SANITIZER_INTERFACE_ATTRIBUTE
68  void __asan_stack_free(uptr ptr, uptr size, uptr real_stack);
69
70  // These two functions are used by instrumented code in the
71  // use-after-scope mode. They mark memory for local variables as
72  // unaddressable when they leave scope and addressable before the
73  // function exits.
74  SANITIZER_INTERFACE_ATTRIBUTE
75  void __asan_poison_stack_memory(uptr addr, uptr size);
76  SANITIZER_INTERFACE_ATTRIBUTE
77  void __asan_unpoison_stack_memory(uptr addr, uptr size);
78
79  // Performs cleanup before a NoReturn function. Must be called before things
80  // like _exit and execl to avoid false positives on stack.
81  SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
82
83  SANITIZER_INTERFACE_ATTRIBUTE
84  void __asan_poison_memory_region(void const volatile *addr, uptr size);
85  SANITIZER_INTERFACE_ATTRIBUTE
86  void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
87
88  SANITIZER_INTERFACE_ATTRIBUTE
89  bool __asan_address_is_poisoned(void const volatile *addr);
90
91  SANITIZER_INTERFACE_ATTRIBUTE
92  uptr __asan_region_is_poisoned(uptr beg, uptr size);
93
94  SANITIZER_INTERFACE_ATTRIBUTE
95  void __asan_describe_address(uptr addr);
96
97  SANITIZER_INTERFACE_ATTRIBUTE
98  void __asan_report_error(uptr pc, uptr bp, uptr sp,
99                           uptr addr, bool is_write, uptr access_size);
100
101  SANITIZER_INTERFACE_ATTRIBUTE
102  int __asan_set_error_exit_code(int exit_code);
103  SANITIZER_INTERFACE_ATTRIBUTE
104  void __asan_set_death_callback(void (*callback)(void));
105  SANITIZER_INTERFACE_ATTRIBUTE
106  void __asan_set_error_report_callback(void (*callback)(const char*));
107
108  SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
109  /* OPTIONAL */ void __asan_on_error();
110
111  SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
112  /* OPTIONAL */ bool __asan_symbolize(const void *pc, char *out_buffer,
113                                       int out_size);
114
115  SANITIZER_INTERFACE_ATTRIBUTE
116  uptr __asan_get_estimated_allocated_size(uptr size);
117
118  SANITIZER_INTERFACE_ATTRIBUTE bool __asan_get_ownership(const void *p);
119  SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_allocated_size(const void *p);
120  SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_current_allocated_bytes();
121  SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_heap_size();
122  SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_free_bytes();
123  SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_unmapped_bytes();
124  SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
125
126  SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
127  /* OPTIONAL */ const char* __asan_default_options();
128
129  SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
130  /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size);
131  SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
132  /* OPTIONAL */ void __asan_free_hook(void *ptr);
133}  // extern "C"
134
135#endif  // ASAN_INTERFACE_INTERNAL_H
136