2013-01-31 21:46:14 +08:00
|
|
|
//===-- asan_interface_internal.h -------------------------------*- C++ -*-===//
|
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// This file is a part of AddressSanitizer, an address sanity checker.
|
|
|
|
//
|
|
|
|
// This header can be included by the instrumented program to fetch
|
|
|
|
// data (mostly allocator statistics) from ASan runtime library.
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef ASAN_INTERFACE_INTERNAL_H
|
|
|
|
#define ASAN_INTERFACE_INTERNAL_H
|
|
|
|
|
|
|
|
#include "sanitizer_common/sanitizer_internal_defs.h"
|
|
|
|
|
|
|
|
using __sanitizer::uptr;
|
|
|
|
|
|
|
|
extern "C" {
|
|
|
|
// This function should be called at the very beginning of the process,
|
|
|
|
// before any instrumented code is executed and before any call to malloc.
|
2014-05-15 10:22:34 +08:00
|
|
|
// Every time the asan ABI changes we also change the version number in this
|
2013-02-13 14:07:50 +08:00
|
|
|
// name. Objects build with incompatible asan ABI version
|
2013-02-12 19:11:58 +08:00
|
|
|
// will not link with run-time.
|
[asan] Change the way we report the alloca frame on stack-buff-overflow.
Before: the function name was stored by the compiler as a constant string
and the run-time was printing it.
Now: the PC is stored instead and the run-time prints the full symbolized frame.
This adds a couple of instructions into every function with non-empty stack frame,
but also reduces the binary size because we store less strings (I saw 2% size reduction).
This change bumps the asan ABI version to v3.
compiler-rt part, llvm part will follow.
Example of report (now):
==31711==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffa77cf1c5 at pc 0x41feb0 bp 0x7fffa77cefb0 sp 0x7fffa77cefa8
READ of size 1 at 0x7fffa77cf1c5 thread T0
#0 0x41feaf in Frame0(int, char*, char*, char*) stack-oob-frames.cc:20
#1 0x41f7ff in Frame1(int, char*, char*) stack-oob-frames.cc:24
#2 0x41f477 in Frame2(int, char*) stack-oob-frames.cc:28
#3 0x41f194 in Frame3(int) stack-oob-frames.cc:32
#4 0x41eee0 in main stack-oob-frames.cc:38
#5 0x7f0c5566f76c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
#6 0x41eb1c (/usr/local/google/kcc/llvm_cmake/a.out+0x41eb1c)
Address 0x7fffa77cf1c5 is located in stack of thread T0 at offset 293 in frame
#0 0x41f87f in Frame0(int, char*, char*, char*) stack-oob-frames.cc:12 <<<<<<<<<<<<<< this is new
This frame has 6 object(s):
[32, 36) 'frame.addr'
[96, 104) 'a.addr'
[160, 168) 'b.addr'
[224, 232) 'c.addr'
[288, 292) 's'
[352, 360) 'd'
llvm-svn: 177723
2013-03-22 18:36:24 +08:00
|
|
|
// Changes between ABI versions:
|
|
|
|
// v1=>v2: added 'module_name' to __asan_global
|
|
|
|
// v2=>v3: stack frame description (created by the compiler)
|
|
|
|
// contains the function PC as the 3-rd field (see
|
|
|
|
// DescribeAddressIfStack).
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_init_v3();
|
[asan] Change the way we report the alloca frame on stack-buff-overflow.
Before: the function name was stored by the compiler as a constant string
and the run-time was printing it.
Now: the PC is stored instead and the run-time prints the full symbolized frame.
This adds a couple of instructions into every function with non-empty stack frame,
but also reduces the binary size because we store less strings (I saw 2% size reduction).
This change bumps the asan ABI version to v3.
compiler-rt part, llvm part will follow.
Example of report (now):
==31711==ERROR: AddressSanitizer: stack-buffer-overflow on address 0x7fffa77cf1c5 at pc 0x41feb0 bp 0x7fffa77cefb0 sp 0x7fffa77cefa8
READ of size 1 at 0x7fffa77cf1c5 thread T0
#0 0x41feaf in Frame0(int, char*, char*, char*) stack-oob-frames.cc:20
#1 0x41f7ff in Frame1(int, char*, char*) stack-oob-frames.cc:24
#2 0x41f477 in Frame2(int, char*) stack-oob-frames.cc:28
#3 0x41f194 in Frame3(int) stack-oob-frames.cc:32
#4 0x41eee0 in main stack-oob-frames.cc:38
#5 0x7f0c5566f76c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)
#6 0x41eb1c (/usr/local/google/kcc/llvm_cmake/a.out+0x41eb1c)
Address 0x7fffa77cf1c5 is located in stack of thread T0 at offset 293 in frame
#0 0x41f87f in Frame0(int, char*, char*, char*) stack-oob-frames.cc:12 <<<<<<<<<<<<<< this is new
This frame has 6 object(s):
[32, 36) 'frame.addr'
[96, 104) 'a.addr'
[160, 168) 'b.addr'
[224, 232) 'c.addr'
[288, 292) 's'
[352, 360) 'd'
llvm-svn: 177723
2013-03-22 18:36:24 +08:00
|
|
|
#define __asan_init __asan_init_v3
|
2013-01-31 21:46:14 +08:00
|
|
|
|
|
|
|
// This structure describes an instrumented global variable.
|
|
|
|
struct __asan_global {
|
|
|
|
uptr beg; // The address of the global.
|
|
|
|
uptr size; // The original size of the global.
|
|
|
|
uptr size_with_redzone; // The size with the redzone.
|
|
|
|
const char *name; // Name as a C string.
|
2013-03-26 21:06:12 +08:00
|
|
|
const char *module_name; // Module name as a C string. This pointer is a
|
|
|
|
// unique identifier of a module.
|
2013-01-31 21:46:14 +08:00
|
|
|
uptr has_dynamic_init; // Non-zero if the global has dynamic initializer.
|
|
|
|
};
|
|
|
|
|
|
|
|
// These two functions should be called by the instrumented code.
|
|
|
|
// 'globals' is an array of structures describing 'n' globals.
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_register_globals(__asan_global *globals, uptr n);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_unregister_globals(__asan_global *globals, uptr n);
|
2013-01-31 21:46:14 +08:00
|
|
|
|
|
|
|
// These two functions should be called before and after dynamic initializers
|
2013-03-26 21:06:12 +08:00
|
|
|
// of a single module run, respectively.
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_before_dynamic_init(const char *module_name);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_after_dynamic_init();
|
2013-01-31 21:46:14 +08:00
|
|
|
|
|
|
|
// These two functions are used by instrumented code in the
|
|
|
|
// use-after-scope mode. They mark memory for local variables as
|
|
|
|
// unaddressable when they leave scope and addressable before the
|
|
|
|
// function exits.
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_poison_stack_memory(uptr addr, uptr size);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_unpoison_stack_memory(uptr addr, uptr size);
|
2013-01-31 21:46:14 +08:00
|
|
|
|
|
|
|
// Performs cleanup before a NoReturn function. Must be called before things
|
|
|
|
// like _exit and execl to avoid false positives on stack.
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_handle_no_return();
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_poison_memory_region(void const volatile *addr, uptr size);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_unpoison_memory_region(void const volatile *addr, uptr size);
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2014-04-14 19:16:53 +08:00
|
|
|
int __asan_address_is_poisoned(void const volatile *addr);
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
uptr __asan_region_is_poisoned(uptr beg, uptr size);
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_describe_address(uptr addr);
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
2013-01-31 21:46:14 +08:00
|
|
|
void __asan_report_error(uptr pc, uptr bp, uptr sp,
|
2014-04-14 19:16:53 +08:00
|
|
|
uptr addr, int is_write, uptr access_size);
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
int __asan_set_error_exit_code(int exit_code);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_set_death_callback(void (*callback)(void));
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void __asan_set_error_report_callback(void (*callback)(const char*));
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
/* OPTIONAL */ void __asan_on_error();
|
2013-01-31 21:46:14 +08:00
|
|
|
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
uptr __asan_get_estimated_allocated_size(uptr size);
|
|
|
|
|
2014-04-14 19:16:53 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE int __asan_get_ownership(const void *p);
|
2013-08-13 19:42:45 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_allocated_size(const void *p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_current_allocated_bytes();
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_heap_size();
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_free_bytes();
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE uptr __asan_get_unmapped_bytes();
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_print_accumulated_stats();
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
/* OPTIONAL */ const char* __asan_default_options();
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
/* OPTIONAL */ void __asan_malloc_hook(void *ptr, uptr size);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
|
|
|
|
/* OPTIONAL */ void __asan_free_hook(void *ptr);
|
2013-09-18 18:35:12 +08:00
|
|
|
|
|
|
|
// Global flag, copy of ASAN_OPTIONS=detect_stack_use_after_return
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
extern int __asan_option_detect_stack_use_after_return;
|
2014-04-16 21:52:28 +08:00
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
extern uptr *__asan_test_only_reported_buggy_pointer;
|
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_load1(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_load2(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_load4(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_load8(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_load16(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_store1(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_store2(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_store4(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_store8(uptr p);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_store16(uptr p);
|
2014-04-21 15:09:01 +08:00
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_loadN(uptr p, uptr size);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE void __asan_storeN(uptr p, uptr size);
|
2014-04-21 19:58:25 +08:00
|
|
|
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void* __asan_memcpy(void *dst, const void *src, uptr size);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void* __asan_memset(void *s, int c, uptr n);
|
|
|
|
SANITIZER_INTERFACE_ATTRIBUTE
|
|
|
|
void* __asan_memmove(void* dest, const void* src, uptr n);
|
2013-01-31 21:46:14 +08:00
|
|
|
} // extern "C"
|
|
|
|
|
|
|
|
#endif // ASAN_INTERFACE_INTERNAL_H
|