2012-08-29 10:27:54 +08:00
|
|
|
//===-- sanitizer/asan_interface.h ------------------------------*- C++ -*-===//
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
2013-01-31 21:46:14 +08:00
|
|
|
// This file is a part of AddressSanitizer.
|
2011-11-30 09:07:02 +08:00
|
|
|
//
|
2013-01-31 21:46:14 +08:00
|
|
|
// Public interface header.
|
2011-11-30 09:07:02 +08:00
|
|
|
//===----------------------------------------------------------------------===//
|
2012-08-29 10:27:54 +08:00
|
|
|
#ifndef SANITIZER_ASAN_INTERFACE_H
|
|
|
|
#define SANITIZER_ASAN_INTERFACE_H
|
|
|
|
|
|
|
|
#include <sanitizer/common_interface_defs.h>
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2013-01-31 21:46:14 +08:00
|
|
|
#ifdef __cplusplus
|
2011-11-30 09:07:02 +08:00
|
|
|
extern "C" {
|
2013-01-31 21:46:14 +08:00
|
|
|
#endif
|
2011-11-30 09:07:02 +08:00
|
|
|
// Marks memory region [addr, addr+size) as unaddressable.
|
|
|
|
// This memory must be previously allocated by the user program. Accessing
|
|
|
|
// addresses in this region from instrumented code is forbidden until
|
|
|
|
// this region is unpoisoned. This function is not guaranteed to poison
|
|
|
|
// the whole region - it may poison only subregion of [addr, addr+size) due
|
|
|
|
// to ASan alignment restrictions.
|
|
|
|
// Method is NOT thread-safe in the sense that no two threads can
|
|
|
|
// (un)poison memory in the same memory region simultaneously.
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_poison_memory_region(void const volatile *addr, size_t size);
|
2011-11-30 09:07:02 +08:00
|
|
|
// Marks memory region [addr, addr+size) as addressable.
|
|
|
|
// This memory must be previously allocated by the user program. Accessing
|
|
|
|
// addresses in this region is allowed until this region is poisoned again.
|
|
|
|
// This function may unpoison a superregion of [addr, addr+size) due to
|
|
|
|
// ASan alignment restrictions.
|
|
|
|
// Method is NOT thread-safe in the sense that no two threads can
|
|
|
|
// (un)poison memory in the same memory region simultaneously.
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
|
2012-02-09 05:33:27 +08:00
|
|
|
|
[asan] make asan work with 7fff8000 offset and prelink
When prelink is installed in the system, prelink-ed
libraries map between 0x003000000000 and 0x004000000000 thus occupying the shadow Gap,
so we need so split the address space even further, like this:
|| [0x10007fff8000, 0x7fffffffffff] || HighMem ||
|| [0x02008fff7000, 0x10007fff7fff] || HighShadow ||
|| [0x004000000000, 0x02008fff6fff] || ShadowGap3 ||
|| [0x003000000000, 0x003fffffffff] || MidMem ||
|| [0x00087fff8000, 0x002fffffffff] || ShadowGap2 ||
|| [0x00067fff8000, 0x00087fff7fff] || MidShadow ||
|| [0x00008fff7000, 0x00067fff7fff] || ShadowGap ||
|| [0x00007fff8000, 0x00008fff6fff] || LowShadow ||
|| [0x000000000000, 0x00007fff7fff] || LowMem ||
Do it only if necessary.
Also added a bit of profiling code to make sure that the
mapping code is efficient.
Added a lit test to simulate prelink-ed libraries.
Unfortunately, this test does not work with binutils-gold linker.
If gold is the default linker the test silently passes.
Also replaced
__has_feature(address_sanitizer)
with
__has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
in two places.
Patch partially by Jakub Jelinek.
llvm-svn: 175263
2013-02-15 20:00:24 +08:00
|
|
|
// User code should use macros instead of functions.
|
|
|
|
#if __has_feature(address_sanitizer) || defined(__SANITIZE_ADDRESS__)
|
2011-11-30 09:07:02 +08:00
|
|
|
#define ASAN_POISON_MEMORY_REGION(addr, size) \
|
|
|
|
__asan_poison_memory_region((addr), (size))
|
|
|
|
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
|
|
|
__asan_unpoison_memory_region((addr), (size))
|
|
|
|
#else
|
|
|
|
#define ASAN_POISON_MEMORY_REGION(addr, size) \
|
|
|
|
((void)(addr), (void)(size))
|
|
|
|
#define ASAN_UNPOISON_MEMORY_REGION(addr, size) \
|
|
|
|
((void)(addr), (void)(size))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// Returns true iff addr is poisoned (i.e. 1-byte read/write access to this
|
|
|
|
// address will result in error report from AddressSanitizer).
|
2013-01-31 21:46:14 +08:00
|
|
|
bool __asan_address_is_poisoned(void const volatile *addr);
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-12-28 23:28:19 +08:00
|
|
|
// If at least on byte in [beg, beg+size) is poisoned, return the address
|
|
|
|
// of the first such byte. Otherwise return 0.
|
2013-01-31 21:46:14 +08:00
|
|
|
void *__asan_region_is_poisoned(void *beg, size_t size);
|
2012-12-28 23:28:19 +08:00
|
|
|
|
2012-12-29 18:18:31 +08:00
|
|
|
// Print the description of addr (useful when debugging in gdb).
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_describe_address(void *addr);
|
2012-12-29 18:18:31 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
// This is an internal function that is called to report an error.
|
|
|
|
// However it is still a part of the interface because users may want to
|
|
|
|
// set a breakpoint on this function in a debugger.
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_report_error(void *pc, void *bp, void *sp,
|
|
|
|
void *addr, bool is_write, size_t access_size);
|
2011-11-30 09:07:02 +08:00
|
|
|
|
|
|
|
// Sets the exit code to use when reporting an error.
|
|
|
|
// Returns the old value.
|
2013-01-31 21:46:14 +08:00
|
|
|
int __asan_set_error_exit_code(int exit_code);
|
2012-02-14 05:24:29 +08:00
|
|
|
|
|
|
|
// Sets the callback to be called right before death on error.
|
2012-05-31 22:35:53 +08:00
|
|
|
// Passing 0 will unset the callback.
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_set_death_callback(void (*callback)(void));
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_set_error_report_callback(void (*callback)(const char*));
|
2012-02-27 22:06:48 +08:00
|
|
|
|
2012-10-02 22:06:39 +08:00
|
|
|
// User may provide function that would be called right when ASan detects
|
|
|
|
// an error. This can be used to notice cases when ASan detects an error, but
|
|
|
|
// the program crashes before ASan report is printed.
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_on_error();
|
2012-08-13 19:23:40 +08:00
|
|
|
|
2011-11-30 09:07:02 +08:00
|
|
|
// Returns the estimated number of bytes that will be reserved by allocator
|
|
|
|
// for request of "size" bytes. If ASan allocator can't allocate that much
|
|
|
|
// memory, returns the maximal possible allocation size, otherwise returns
|
|
|
|
// "size".
|
2013-01-31 21:46:14 +08:00
|
|
|
size_t __asan_get_estimated_allocated_size(size_t size);
|
2012-01-18 23:26:55 +08:00
|
|
|
// Returns true if p was returned by the ASan allocator and
|
2011-11-30 09:07:02 +08:00
|
|
|
// is not yet freed.
|
2013-01-31 21:46:14 +08:00
|
|
|
bool __asan_get_ownership(const void *p);
|
2011-11-30 09:07:02 +08:00
|
|
|
// Returns the number of bytes reserved for the pointer p.
|
2012-05-31 22:35:53 +08:00
|
|
|
// Requires (get_ownership(p) == true) or (p == 0).
|
2013-01-31 21:46:14 +08:00
|
|
|
size_t __asan_get_allocated_size(const void *p);
|
2011-11-30 09:07:02 +08:00
|
|
|
// Number of bytes, allocated and not yet freed by the application.
|
2013-01-31 21:46:14 +08:00
|
|
|
size_t __asan_get_current_allocated_bytes();
|
2011-11-30 09:07:02 +08:00
|
|
|
// Number of bytes, mmaped by asan allocator to fulfill allocation requests.
|
|
|
|
// Generally, for request of X bytes, allocator can reserve and add to free
|
|
|
|
// lists a large number of chunks of size X to use them for future requests.
|
|
|
|
// All these chunks count toward the heap size. Currently, allocator never
|
|
|
|
// releases memory to OS (instead, it just puts freed chunks to free lists).
|
2013-01-31 21:46:14 +08:00
|
|
|
size_t __asan_get_heap_size();
|
2011-11-30 09:07:02 +08:00
|
|
|
// Number of bytes, mmaped by asan allocator, which can be used to fulfill
|
|
|
|
// allocation requests. When a user program frees memory chunk, it can first
|
|
|
|
// fall into quarantine and will count toward __asan_get_free_bytes() later.
|
2013-01-31 21:46:14 +08:00
|
|
|
size_t __asan_get_free_bytes();
|
2011-11-30 09:07:02 +08:00
|
|
|
// Number of bytes in unmapped pages, that are released to OS. Currently,
|
|
|
|
// always returns 0.
|
2013-01-31 21:46:14 +08:00
|
|
|
size_t __asan_get_unmapped_bytes();
|
2011-11-30 09:07:02 +08:00
|
|
|
// Prints accumulated stats to stderr. Used for debugging.
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_print_accumulated_stats();
|
2012-08-15 15:11:14 +08:00
|
|
|
|
2012-12-08 06:01:28 +08:00
|
|
|
// This function may be optionally provided by user and should return
|
|
|
|
// a string containing ASan runtime options. See asan_flags.h for details.
|
2013-01-31 21:46:14 +08:00
|
|
|
const char* __asan_default_options();
|
2012-08-22 18:12:47 +08:00
|
|
|
|
2012-12-08 06:01:28 +08:00
|
|
|
// Malloc hooks that may be optionally provided by user.
|
2012-08-22 18:12:47 +08:00
|
|
|
// __asan_malloc_hook(ptr, size) is called immediately after
|
|
|
|
// allocation of "size" bytes, which returned "ptr".
|
|
|
|
// __asan_free_hook(ptr) is called immediately before
|
|
|
|
// deallocation of "ptr".
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_malloc_hook(void *ptr, size_t size);
|
|
|
|
void __asan_free_hook(void *ptr);
|
|
|
|
#ifdef __cplusplus
|
2012-08-15 15:11:14 +08:00
|
|
|
} // extern "C"
|
2013-01-31 21:46:14 +08:00
|
|
|
#endif
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2012-08-29 10:27:54 +08:00
|
|
|
#endif // SANITIZER_ASAN_INTERFACE_H
|