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
|
|
|
|
|
2014-04-14 19:16:53 +08:00
|
|
|
// Returns 1 if addr is poisoned (i.e. 1-byte read/write access to this
|
2011-11-30 09:07:02 +08:00
|
|
|
// address will result in error report from AddressSanitizer).
|
2014-04-14 19:16:53 +08:00
|
|
|
// Otherwise returns 0.
|
|
|
|
int __asan_address_is_poisoned(void const volatile *addr);
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2014-10-14 05:40:52 +08:00
|
|
|
// If at least one byte in [beg, beg+size) is poisoned, return the address
|
2012-12-28 23:28:19 +08:00
|
|
|
// 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
|
|
|
|
2014-09-27 03:15:32 +08:00
|
|
|
// Useful for calling from a debugger to get information about an ASan error.
|
|
|
|
// Returns 1 if an error has been (or is being) reported, otherwise returns 0.
|
|
|
|
int __asan_report_present();
|
|
|
|
|
|
|
|
// Useful for calling from a debugger to get information about an ASan error.
|
|
|
|
// If an error has been (or is being) reported, the following functions return
|
|
|
|
// the pc, bp, sp, address, access type (0 = read, 1 = write), access size and
|
|
|
|
// bug description (e.g. "heap-use-after-free"). Otherwise they return 0.
|
|
|
|
void *__asan_get_report_pc();
|
|
|
|
void *__asan_get_report_bp();
|
|
|
|
void *__asan_get_report_sp();
|
|
|
|
void *__asan_get_report_address();
|
|
|
|
int __asan_get_report_access_type();
|
|
|
|
size_t __asan_get_report_access_size();
|
|
|
|
const char *__asan_get_report_description();
|
|
|
|
|
|
|
|
// Useful for calling from the debugger to get information about a pointer.
|
|
|
|
// Returns the category of the given pointer as a constant string.
|
|
|
|
// Possible return values are "global", "stack", "stack-fake", "heap",
|
|
|
|
// "heap-invalid", "shadow-low", "shadow-gap", "shadow-high", "unknown".
|
|
|
|
// If global or stack, tries to also return the variable name, address and
|
|
|
|
// size. If heap, tries to return the chunk address and size. 'name' should
|
|
|
|
// point to an allocated buffer of size 'name_size'.
|
|
|
|
const char *__asan_locate_address(void *addr, char *name, size_t name_size,
|
|
|
|
void **region_address, size_t *region_size);
|
|
|
|
|
2014-07-16 01:33:23 +08:00
|
|
|
// Useful for calling from the debugger to get the allocation stack trace
|
|
|
|
// and thread ID for a heap address. Stores up to 'size' frames into 'trace',
|
|
|
|
// returns the number of stored frames or 0 on error.
|
|
|
|
size_t __asan_get_alloc_stack(void *addr, void **trace, size_t size,
|
|
|
|
int *thread_id);
|
|
|
|
|
|
|
|
// Useful for calling from the debugger to get the free stack trace
|
|
|
|
// and thread ID for a heap address. Stores up to 'size' frames into 'trace',
|
|
|
|
// returns the number of stored frames or 0 on error.
|
|
|
|
size_t __asan_get_free_stack(void *addr, void **trace, size_t size,
|
|
|
|
int *thread_id);
|
|
|
|
|
|
|
|
// Useful for calling from the debugger to get the current shadow memory
|
|
|
|
// mapping.
|
|
|
|
void __asan_get_shadow_mapping(size_t *shadow_scale, size_t *shadow_offset);
|
|
|
|
|
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,
|
2014-04-14 19:16:53 +08:00
|
|
|
void *addr, int is_write, size_t access_size);
|
2011-11-30 09:07:02 +08:00
|
|
|
|
2014-12-16 07:02:57 +08:00
|
|
|
// Deprecated. Call __sanitizer_set_death_callback instead.
|
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
|
|
|
// 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
|
|
|
|
2014-02-06 14:56:22 +08:00
|
|
|
// The following 2 functions facilitate garbage collection in presence of
|
|
|
|
// asan's fake stack.
|
|
|
|
|
|
|
|
// Returns an opaque handler to be used later in __asan_addr_is_in_fake_stack.
|
|
|
|
// Returns NULL if the current thread does not have a fake stack.
|
|
|
|
void *__asan_get_current_fake_stack();
|
|
|
|
|
|
|
|
// If fake_stack is non-NULL and addr belongs to a fake frame in
|
|
|
|
// fake_stack, returns the address on real stack that corresponds to
|
|
|
|
// the fake frame and sets beg/end to the boundaries of this fake frame.
|
|
|
|
// Otherwise returns NULL and does not touch beg/end.
|
|
|
|
// If beg/end are NULL, they are not touched.
|
|
|
|
// This function may be called from a thread other than the owner of
|
|
|
|
// fake_stack, but the owner thread need to be alive.
|
|
|
|
void *__asan_addr_is_in_fake_stack(void *fake_stack, void *addr, void **beg,
|
|
|
|
void **end);
|
|
|
|
|
2013-01-31 21:46:14 +08:00
|
|
|
#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
|