summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorAlexey Samsonov <vonosmas@gmail.com>2014-07-07 17:39:31 +0000
committerAlexey Samsonov <vonosmas@gmail.com>2014-07-07 17:39:31 +0000
commit2ef0c30d2101ca6521b7ecbdd17e4fbcca09a951 (patch)
tree362337877acfa4824664514a5a3b54216bc670c1 /include
parent58dd99ec88cc51a5a1adcd4eddff212576a9067c (diff)
Generalize sanitizer allocator public interface.
Introduce new public header <sanitizer/allocator_interface.h> and a set of functions __sanitizer_get_ownership(), __sanitizer_malloc_hook() etc. that will eventually replace their tool-specific equivalents (__asan_get_ownership(), __msan_get_ownership() etc.). Tool-specific functions are now deprecated and implemented as stubs redirecting to __sanitizer_ versions (which are implemented differently in each tool). Replace all uses of __xsan_ versions with __sanitizer_ versions in unit and lit tests. git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@212469 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/CMakeLists.txt1
-rw-r--r--include/sanitizer/allocator_interface.h66
-rw-r--r--include/sanitizer/asan_interface.h15
-rw-r--r--include/sanitizer/msan_interface.h13
4 files changed, 93 insertions, 2 deletions
diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt
index b5d98a805..7f8664e09 100644
--- a/include/CMakeLists.txt
+++ b/include/CMakeLists.txt
@@ -1,4 +1,5 @@
set(SANITIZER_HEADERS
+ sanitizer/allocator_interface.h
sanitizer/asan_interface.h
sanitizer/common_interface_defs.h
sanitizer/dfsan_interface.h
diff --git a/include/sanitizer/allocator_interface.h b/include/sanitizer/allocator_interface.h
new file mode 100644
index 000000000..ab251f89c
--- /dev/null
+++ b/include/sanitizer/allocator_interface.h
@@ -0,0 +1,66 @@
+//===-- allocator_interface.h ---------------------------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// Public interface header for allocator used in sanitizers (ASan/TSan/MSan).
+//===----------------------------------------------------------------------===//
+#ifndef SANITIZER_ALLOCATOR_INTERFACE_H
+#define SANITIZER_ALLOCATOR_INTERFACE_H
+
+#include <stddef.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+ /* Returns the estimated number of bytes that will be reserved by allocator
+ for request of "size" bytes. If allocator can't allocate that much
+ memory, returns the maximal possible allocation size, otherwise returns
+ "size". */
+ size_t __sanitizer_get_estimated_allocated_size(size_t size);
+
+ /* Returns true if p was returned by the allocator and
+ is not yet freed. */
+ int __sanitizer_get_ownership(const volatile void *p);
+
+ /* Returns the number of bytes reserved for the pointer p.
+ Requires (get_ownership(p) == true) or (p == 0). */
+ size_t __sanitizer_get_allocated_size(const volatile void *p);
+
+ /* Number of bytes, allocated and not yet freed by the application. */
+ size_t __sanitizer_get_current_allocated_bytes();
+
+ /* Number of bytes, mmaped by the 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). */
+ size_t __sanitizer_get_heap_size();
+
+ /* Number of bytes, mmaped by the 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 __sanitizer_get_free_bytes()
+ later. */
+ size_t __sanitizer_get_free_bytes();
+
+ /* Number of bytes in unmapped pages, that are released to OS. Currently,
+ always returns 0. */
+ size_t __sanitizer_get_unmapped_bytes();
+
+ /* Malloc hooks that may be optionally provided by user.
+ __sanitizer_malloc_hook(ptr, size) is called immediately after
+ allocation of "size" bytes, which returned "ptr".
+ __sanitizer_free_hook(ptr) is called immediately before
+ deallocation of "ptr". */
+ void __sanitizer_malloc_hook(const volatile void *ptr, size_t size);
+ void __sanitizer_free_hook(const volatile void *ptr);
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif
diff --git a/include/sanitizer/asan_interface.h b/include/sanitizer/asan_interface.h
index d244346e4..23fc1789f 100644
--- a/include/sanitizer/asan_interface.h
+++ b/include/sanitizer/asan_interface.h
@@ -87,28 +87,42 @@ extern "C" {
// for request of "size" bytes. If ASan allocator can't allocate that much
// memory, returns the maximal possible allocation size, otherwise returns
// "size".
+ /* DEPRECATED: Use __sanitizer_get_estimated_allocated_size instead. */
size_t __asan_get_estimated_allocated_size(size_t size);
+
// Returns 1 if p was returned by the ASan allocator and is not yet freed.
// Otherwise returns 0.
+ /* DEPRECATED: Use __sanitizer_get_ownership instead. */
int __asan_get_ownership(const void *p);
+
// Returns the number of bytes reserved for the pointer p.
// Requires (get_ownership(p) == true) or (p == 0).
+ /* DEPRECATED: Use __sanitizer_get_allocated_size instead. */
size_t __asan_get_allocated_size(const void *p);
+
// Number of bytes, allocated and not yet freed by the application.
+ /* DEPRECATED: Use __sanitizer_get_current_allocated_bytes instead. */
size_t __asan_get_current_allocated_bytes();
+
// 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).
+ /* DEPRECATED: Use __sanitizer_get_heap_size instead. */
size_t __asan_get_heap_size();
+
// 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.
+ /* DEPRECATED: Use __sanitizer_get_free_bytes instead. */
size_t __asan_get_free_bytes();
+
// Number of bytes in unmapped pages, that are released to OS. Currently,
// always returns 0.
+ /* DEPRECATED: Use __sanitizer_get_unmapped_bytes instead. */
size_t __asan_get_unmapped_bytes();
+
// Prints accumulated stats to stderr. Used for debugging.
void __asan_print_accumulated_stats();
@@ -121,6 +135,7 @@ extern "C" {
// allocation of "size" bytes, which returned "ptr".
// __asan_free_hook(ptr) is called immediately before
// deallocation of "ptr".
+ /* DEPRECATED: Use __sanitizer_malloc_hook / __sanitizer_free_hook instead. */
void __asan_malloc_hook(void *ptr, size_t size);
void __asan_free_hook(void *ptr);
diff --git a/include/sanitizer/msan_interface.h b/include/sanitizer/msan_interface.h
index e8c510be9..f6a62be5c 100644
--- a/include/sanitizer/msan_interface.h
+++ b/include/sanitizer/msan_interface.h
@@ -89,8 +89,8 @@ extern "C" {
a string containing Msan runtime options. See msan_flags.h for details. */
const char* __msan_default_options();
- // Sets the callback to be called right before death on error.
- // Passing 0 will unset the callback.
+ /* Sets the callback to be called right before death on error.
+ Passing 0 will unset the callback. */
void __msan_set_death_callback(void (*callback)(void));
/***********************************/
@@ -100,17 +100,21 @@ extern "C" {
for request of "size" bytes. If Msan allocator can't allocate that much
memory, returns the maximal possible allocation size, otherwise returns
"size". */
+ /* DEPRECATED: Use __sanitizer_get_estimated_allocated_size instead. */
size_t __msan_get_estimated_allocated_size(size_t size);
/* Returns true if p was returned by the Msan allocator and
is not yet freed. */
+ /* DEPRECATED: Use __sanitizer_get_ownership instead. */
int __msan_get_ownership(const volatile void *p);
/* Returns the number of bytes reserved for the pointer p.
Requires (get_ownership(p) == true) or (p == 0). */
+ /* DEPRECATED: Use __sanitizer_get_allocated_size instead. */
size_t __msan_get_allocated_size(const volatile void *p);
/* Number of bytes, allocated and not yet freed by the application. */
+ /* DEPRECATED: Use __sanitizer_get_current_allocated_bytes instead. */
size_t __msan_get_current_allocated_bytes();
/* Number of bytes, mmaped by msan allocator to fulfill allocation requests.
@@ -119,16 +123,19 @@ extern "C" {
All these chunks count toward the heap size. Currently, allocator never
releases memory to OS (instead, it just puts freed chunks to free
lists). */
+ /* DEPRECATED: Use __sanitizer_get_heap_size instead. */
size_t __msan_get_heap_size();
/* Number of bytes, mmaped by msan 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 __msan_get_free_bytes()
later. */
+ /* DEPRECATED: Use __sanitizer_get_free_bytes instead. */
size_t __msan_get_free_bytes();
/* Number of bytes in unmapped pages, that are released to OS. Currently,
always returns 0. */
+ /* DEPRECATED: Use __sanitizer_get_unmapped_bytes instead. */
size_t __msan_get_unmapped_bytes();
/* Malloc hooks that may be optionally provided by user.
@@ -136,8 +143,10 @@ extern "C" {
allocation of "size" bytes, which returned "ptr".
__msan_free_hook(ptr) is called immediately before
deallocation of "ptr". */
+ /* DEPRECATED: Use __sanitizer_malloc_hook / __sanitizer_free_hook instead. */
void __msan_malloc_hook(const volatile void *ptr, size_t size);
void __msan_free_hook(const volatile void *ptr);
+
#ifdef __cplusplus
} // extern "C"
#endif