Path: blob/main/contrib/llvm-project/compiler-rt/include/sanitizer/hwasan_interface.h
35235 views
//===-- sanitizer/hwasan_interface.h ----------------------------*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of HWAddressSanitizer.9//10// Public interface header.11//===----------------------------------------------------------------------===//12#ifndef SANITIZER_HWASAN_INTERFACE_H13#define SANITIZER_HWASAN_INTERFACE_H1415#include <sanitizer/common_interface_defs.h>1617#ifdef __cplusplus18extern "C" {19#endif20// Libc hook for program startup in statically linked executables.21// Initializes enough of the runtime to run instrumented code. This function22// should only be called in statically linked executables because it modifies23// the GOT, which won't work in regular binaries because RELRO will already24// have been applied by the time the function is called. This also means that25// the function should be called before libc applies RELRO.26// Does not call libc unless there is an error.27// Can be called multiple times.28void SANITIZER_CDECL __hwasan_init_static(void);2930// This function may be optionally provided by user and should return31// a string containing HWASan runtime options. See asan_flags.h for details.32const char *SANITIZER_CDECL __hwasan_default_options(void);3334void SANITIZER_CDECL __hwasan_enable_allocator_tagging(void);35void SANITIZER_CDECL __hwasan_disable_allocator_tagging(void);3637// Mark region of memory with the given tag. Both address and size need to be38// 16-byte aligned.39void SANITIZER_CDECL __hwasan_tag_memory(const volatile void *p,40unsigned char tag, size_t size);4142/// Set pointer tag. Previous tag is lost.43void *SANITIZER_CDECL __hwasan_tag_pointer(const volatile void *p,44unsigned char tag);4546/// Get tag from the pointer.47unsigned char SANITIZER_CDECL48__hwasan_get_tag_from_pointer(const volatile void *p);4950// Set memory tag from the current SP address to the given address to zero.51// This is meant to annotate longjmp and other non-local jumps.52// This function needs to know the (almost) exact destination frame address;53// clearing shadow for the entire thread stack like __asan_handle_no_return54// does would cause false reports.55void SANITIZER_CDECL __hwasan_handle_longjmp(const void *sp_dst);5657// Set memory tag for the part of the current thread stack below sp_dst to58// zero. Call this in vfork() before returning in the parent process.59void SANITIZER_CDECL __hwasan_handle_vfork(const void *sp_dst);6061// Libc hook for thread creation. Should be called in the child thread before62// any instrumented code.63void SANITIZER_CDECL __hwasan_thread_enter();6465// Libc hook for thread destruction. No instrumented code should run after66// this call.67void SANITIZER_CDECL __hwasan_thread_exit();6869// Print shadow and origin for the memory range to stderr in a human-readable70// format.71void SANITIZER_CDECL __hwasan_print_shadow(const volatile void *x, size_t size);7273// Print one-line report about the memory usage of the current process.74void SANITIZER_CDECL __hwasan_print_memory_usage();7576/* Returns the offset of the first byte in the memory range that can not be77* accessed through the pointer in x, or -1 if the whole range is good. */78intptr_t SANITIZER_CDECL __hwasan_test_shadow(const volatile void *x,79size_t size);8081/* Sets the callback function to be called during HWASan error reporting. */82void SANITIZER_CDECL83__hwasan_set_error_report_callback(void (*callback)(const char *));8485int SANITIZER_CDECL __sanitizer_posix_memalign(void **memptr, size_t alignment,86size_t size);87void *SANITIZER_CDECL __sanitizer_memalign(size_t alignment, size_t size);88void *SANITIZER_CDECL __sanitizer_aligned_alloc(size_t alignment, size_t size);89void *SANITIZER_CDECL __sanitizer___libc_memalign(size_t alignment,90size_t size);91void *SANITIZER_CDECL __sanitizer_valloc(size_t size);92void *SANITIZER_CDECL __sanitizer_pvalloc(size_t size);93void SANITIZER_CDECL __sanitizer_free(void *ptr);94void SANITIZER_CDECL __sanitizer_cfree(void *ptr);95size_t SANITIZER_CDECL __sanitizer_malloc_usable_size(const void *ptr);96struct mallinfo SANITIZER_CDECL __sanitizer_mallinfo();97int SANITIZER_CDECL __sanitizer_mallopt(int cmd, int value);98void SANITIZER_CDECL __sanitizer_malloc_stats(void);99void *SANITIZER_CDECL __sanitizer_calloc(size_t nmemb, size_t size);100void *SANITIZER_CDECL __sanitizer_realloc(void *ptr, size_t size);101void *SANITIZER_CDECL __sanitizer_reallocarray(void *ptr, size_t nmemb,102size_t size);103void *SANITIZER_CDECL __sanitizer_malloc(size_t size);104#ifdef __cplusplus105} // extern "C"106#endif107108#endif // SANITIZER_HWASAN_INTERFACE_H109110111