Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 1 | //===-- sanitizer/asan_interface.h ------------------------------*- C++ -*-===// |
| 2 | // |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
| 9 | // This file is a part of HWAddressSanitizer. |
| 10 | // |
| 11 | // Public interface header. |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | #ifndef SANITIZER_HWASAN_INTERFACE_H |
| 14 | #define SANITIZER_HWASAN_INTERFACE_H |
| 15 | |
| 16 | #include <sanitizer/common_interface_defs.h> |
| 17 | |
| 18 | #ifdef __cplusplus |
| 19 | extern "C" { |
| 20 | #endif |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 21 | // Libc hook for program startup in statically linked executables. |
| 22 | // Initializes enough of the runtime to run instrumented code. This function |
| 23 | // should only be called in statically linked executables because it modifies |
| 24 | // the GOT, which won't work in regular binaries because RELRO will already |
| 25 | // have been applied by the time the function is called. This also means that |
| 26 | // the function should be called before libc applies RELRO. |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 27 | // Does not call libc unless there is an error. |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 28 | // Can be called multiple times. |
| 29 | void __hwasan_init_static(void); |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 30 | |
| 31 | // This function may be optionally provided by user and should return |
| 32 | // a string containing HWASan runtime options. See asan_flags.h for details. |
| 33 | const char* __hwasan_default_options(void); |
| 34 | |
| 35 | void __hwasan_enable_allocator_tagging(void); |
| 36 | void __hwasan_disable_allocator_tagging(void); |
| 37 | |
| 38 | // Mark region of memory with the given tag. Both address and size need to be |
| 39 | // 16-byte aligned. |
| 40 | void __hwasan_tag_memory(const volatile void *p, unsigned char tag, |
| 41 | size_t size); |
| 42 | |
| 43 | /// Set pointer tag. Previous tag is lost. |
| 44 | void *__hwasan_tag_pointer(const volatile void *p, unsigned char tag); |
| 45 | |
| 46 | // Set memory tag from the current SP address to the given address to zero. |
| 47 | // This is meant to annotate longjmp and other non-local jumps. |
| 48 | // This function needs to know the (almost) exact destination frame address; |
| 49 | // clearing shadow for the entire thread stack like __asan_handle_no_return |
| 50 | // does would cause false reports. |
| 51 | void __hwasan_handle_longjmp(const void *sp_dst); |
| 52 | |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 53 | // Set memory tag for the part of the current thread stack below sp_dst to |
| 54 | // zero. Call this in vfork() before returning in the parent process. |
| 55 | void __hwasan_handle_vfork(const void *sp_dst); |
| 56 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 57 | // Libc hook for thread creation. Should be called in the child thread before |
| 58 | // any instrumented code. |
| 59 | void __hwasan_thread_enter(); |
| 60 | |
| 61 | // Libc hook for thread destruction. No instrumented code should run after |
| 62 | // this call. |
| 63 | void __hwasan_thread_exit(); |
| 64 | |
| 65 | // Print shadow and origin for the memory range to stderr in a human-readable |
| 66 | // format. |
| 67 | void __hwasan_print_shadow(const volatile void *x, size_t size); |
| 68 | |
Logan Chien | b0c8402 | 2018-11-09 16:19:54 +0800 | [diff] [blame] | 69 | // Print one-line report about the memory usage of the current process. |
| 70 | void __hwasan_print_memory_usage(); |
| 71 | |
Logan Chien | dbcf412 | 2019-03-21 10:50:25 +0800 | [diff] [blame] | 72 | /* Returns the offset of the first byte in the memory range that can not be |
| 73 | * accessed through the pointer in x, or -1 if the whole range is good. */ |
| 74 | intptr_t __hwasan_test_shadow(const volatile void *x, size_t size); |
| 75 | |
Sasha Smundak | 4b1f33a | 2021-01-11 15:05:07 -0800 | [diff] [blame] | 76 | /* Sets the callback function to be called during HWASan error reporting. */ |
| 77 | void __hwasan_set_error_report_callback(void (*callback)(const char *)); |
| 78 | |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 79 | int __sanitizer_posix_memalign(void **memptr, size_t alignment, size_t size); |
| 80 | void * __sanitizer_memalign(size_t alignment, size_t size); |
| 81 | void * __sanitizer_aligned_alloc(size_t alignment, size_t size); |
| 82 | void * __sanitizer___libc_memalign(size_t alignment, size_t size); |
| 83 | void * __sanitizer_valloc(size_t size); |
| 84 | void * __sanitizer_pvalloc(size_t size); |
| 85 | void __sanitizer_free(void *ptr); |
| 86 | void __sanitizer_cfree(void *ptr); |
| 87 | size_t __sanitizer_malloc_usable_size(const void *ptr); |
| 88 | struct mallinfo __sanitizer_mallinfo(); |
| 89 | int __sanitizer_mallopt(int cmd, int value); |
| 90 | void __sanitizer_malloc_stats(void); |
| 91 | void * __sanitizer_calloc(size_t nmemb, size_t size); |
| 92 | void * __sanitizer_realloc(void *ptr, size_t size); |
Logan Chien | df4f766 | 2019-09-04 16:45:23 -0700 | [diff] [blame] | 93 | void * __sanitizer_reallocarray(void *ptr, size_t nmemb, size_t size); |
Logan Chien | 55afb0a | 2018-10-15 10:42:14 +0800 | [diff] [blame] | 94 | void * __sanitizer_malloc(size_t size); |
| 95 | #ifdef __cplusplus |
| 96 | } // extern "C" |
| 97 | #endif |
| 98 | |
| 99 | #endif // SANITIZER_HWASAN_INTERFACE_H |