1//===-- sanitizer/hwasan_interface.h ----------------------------*- C++ -*-===// 2// 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 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 19extern "C" { 20#endif 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. 27// Does not call libc unless there is an error. 28// Can be called multiple times. 29void SANITIZER_CDECL __hwasan_init_static(void); 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. 33const char *SANITIZER_CDECL __hwasan_default_options(void); 34 35void SANITIZER_CDECL __hwasan_enable_allocator_tagging(void); 36void SANITIZER_CDECL __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. 40void SANITIZER_CDECL __hwasan_tag_memory(const volatile void *p, 41 unsigned char tag, size_t size); 42 43/// Set pointer tag. Previous tag is lost. 44void *SANITIZER_CDECL __hwasan_tag_pointer(const volatile void *p, 45 unsigned char tag); 46 47/// Get tag from the pointer. 48unsigned char SANITIZER_CDECL 49__hwasan_get_tag_from_pointer(const volatile void *p); 50 51// Set memory tag from the current SP address to the given address to zero. 52// This is meant to annotate longjmp and other non-local jumps. 53// This function needs to know the (almost) exact destination frame address; 54// clearing shadow for the entire thread stack like __asan_handle_no_return 55// does would cause false reports. 56void SANITIZER_CDECL __hwasan_handle_longjmp(const void *sp_dst); 57 58// Set memory tag for the part of the current thread stack below sp_dst to 59// zero. Call this in vfork() before returning in the parent process. 60void SANITIZER_CDECL __hwasan_handle_vfork(const void *sp_dst); 61 62// Libc hook for thread creation. Should be called in the child thread before 63// any instrumented code. 64void SANITIZER_CDECL __hwasan_thread_enter(); 65 66// Libc hook for thread destruction. No instrumented code should run after 67// this call. 68void SANITIZER_CDECL __hwasan_thread_exit(); 69 70// Print shadow and origin for the memory range to stderr in a human-readable 71// format. 72void SANITIZER_CDECL __hwasan_print_shadow(const volatile void *x, size_t size); 73 74// Print one-line report about the memory usage of the current process. 75void SANITIZER_CDECL __hwasan_print_memory_usage(); 76 77/* Returns the offset of the first byte in the memory range that can not be 78 * accessed through the pointer in x, or -1 if the whole range is good. */ 79intptr_t SANITIZER_CDECL __hwasan_test_shadow(const volatile void *x, 80 size_t size); 81 82/* Sets the callback function to be called during HWASan error reporting. */ 83void SANITIZER_CDECL 84__hwasan_set_error_report_callback(void (*callback)(const char *)); 85 86int SANITIZER_CDECL __sanitizer_posix_memalign(void **memptr, size_t alignment, 87 size_t size); 88void *SANITIZER_CDECL __sanitizer_memalign(size_t alignment, size_t size); 89void *SANITIZER_CDECL __sanitizer_aligned_alloc(size_t alignment, size_t size); 90void *SANITIZER_CDECL __sanitizer___libc_memalign(size_t alignment, 91 size_t size); 92void *SANITIZER_CDECL __sanitizer_valloc(size_t size); 93void *SANITIZER_CDECL __sanitizer_pvalloc(size_t size); 94void SANITIZER_CDECL __sanitizer_free(void *ptr); 95void SANITIZER_CDECL __sanitizer_cfree(void *ptr); 96size_t SANITIZER_CDECL __sanitizer_malloc_usable_size(const void *ptr); 97struct mallinfo SANITIZER_CDECL __sanitizer_mallinfo(); 98int SANITIZER_CDECL __sanitizer_mallopt(int cmd, int value); 99void SANITIZER_CDECL __sanitizer_malloc_stats(void); 100void *SANITIZER_CDECL __sanitizer_calloc(size_t nmemb, size_t size); 101void *SANITIZER_CDECL __sanitizer_realloc(void *ptr, size_t size); 102void *SANITIZER_CDECL __sanitizer_reallocarray(void *ptr, size_t nmemb, 103 size_t size); 104void *SANITIZER_CDECL __sanitizer_malloc(size_t size); 105#ifdef __cplusplus 106} // extern "C" 107#endif 108 109#endif // SANITIZER_HWASAN_INTERFACE_H 110