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