asan_interface_internal.h revision 251034
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  void __asan_init_v3() SANITIZER_INTERFACE_ATTRIBUTE;
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  void __asan_register_globals(__asan_global *globals, uptr n)
50      SANITIZER_INTERFACE_ATTRIBUTE;
51  void __asan_unregister_globals(__asan_global *globals, uptr n)
52      SANITIZER_INTERFACE_ATTRIBUTE;
53
54  // These two functions should be called before and after dynamic initializers
55  // of a single module run, respectively.
56  void __asan_before_dynamic_init(const char *module_name)
57      SANITIZER_INTERFACE_ATTRIBUTE;
58  void __asan_after_dynamic_init()
59      SANITIZER_INTERFACE_ATTRIBUTE;
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  uptr __asan_stack_malloc(uptr size, uptr real_stack)
66      SANITIZER_INTERFACE_ATTRIBUTE;
67  void __asan_stack_free(uptr ptr, uptr size, uptr real_stack)
68      SANITIZER_INTERFACE_ATTRIBUTE;
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  void __asan_poison_stack_memory(uptr addr, uptr size)
75      SANITIZER_INTERFACE_ATTRIBUTE;
76  void __asan_unpoison_stack_memory(uptr addr, uptr size)
77      SANITIZER_INTERFACE_ATTRIBUTE;
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  void __asan_handle_no_return() SANITIZER_INTERFACE_ATTRIBUTE;
82
83  void __asan_poison_memory_region(void const volatile *addr, uptr size)
84      SANITIZER_INTERFACE_ATTRIBUTE;
85  void __asan_unpoison_memory_region(void const volatile *addr, uptr size)
86      SANITIZER_INTERFACE_ATTRIBUTE;
87
88  bool __asan_address_is_poisoned(void const volatile *addr)
89      SANITIZER_INTERFACE_ATTRIBUTE;
90
91  uptr __asan_region_is_poisoned(uptr beg, uptr size)
92      SANITIZER_INTERFACE_ATTRIBUTE;
93
94  void __asan_describe_address(uptr addr)
95      SANITIZER_INTERFACE_ATTRIBUTE;
96
97  void __asan_report_error(uptr pc, uptr bp, uptr sp,
98                           uptr addr, bool is_write, uptr access_size)
99    SANITIZER_INTERFACE_ATTRIBUTE;
100
101  int __asan_set_error_exit_code(int exit_code)
102      SANITIZER_INTERFACE_ATTRIBUTE;
103  void __asan_set_death_callback(void (*callback)(void))
104      SANITIZER_INTERFACE_ATTRIBUTE;
105  void __asan_set_error_report_callback(void (*callback)(const char*))
106      SANITIZER_INTERFACE_ATTRIBUTE;
107
108  /* OPTIONAL */ void __asan_on_error()
109      SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
110
111  /* OPTIONAL */ bool __asan_symbolize(const void *pc, char *out_buffer,
112                                       int out_size)
113      SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
114
115  uptr __asan_get_estimated_allocated_size(uptr size)
116      SANITIZER_INTERFACE_ATTRIBUTE;
117  bool __asan_get_ownership(const void *p)
118      SANITIZER_INTERFACE_ATTRIBUTE;
119  uptr __asan_get_allocated_size(const void *p)
120      SANITIZER_INTERFACE_ATTRIBUTE;
121  uptr __asan_get_current_allocated_bytes()
122      SANITIZER_INTERFACE_ATTRIBUTE;
123  uptr __asan_get_heap_size()
124      SANITIZER_INTERFACE_ATTRIBUTE;
125  uptr __asan_get_free_bytes()
126      SANITIZER_INTERFACE_ATTRIBUTE;
127  uptr __asan_get_unmapped_bytes()
128      SANITIZER_INTERFACE_ATTRIBUTE;
129  void __asan_print_accumulated_stats()
130      SANITIZER_INTERFACE_ATTRIBUTE;
131
132  /* OPTIONAL */ const char* __asan_default_options()
133      SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
134
135  /* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size)
136      SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
137  /* OPTIONAL */ void __asan_free_hook(void *ptr)
138      SANITIZER_WEAK_ATTRIBUTE SANITIZER_INTERFACE_ATTRIBUTE;
139}  // extern "C"
140
141#endif  // ASAN_INTERFACE_INTERNAL_H
142