hwasan_interface.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. #include <sanitizer/common_interface_defs.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. // Libc hook for program startup in statically linked executables.
  20. // Initializes enough of the runtime to run instrumented code. This function
  21. // should only be called in statically linked executables because it modifies
  22. // the GOT, which won't work in regular binaries because RELRO will already
  23. // have been applied by the time the function is called. This also means that
  24. // the function should be called before libc applies RELRO.
  25. // Does not call libc unless there is an error.
  26. // Can be called multiple times.
  27. void SANITIZER_CDECL __hwasan_init_static(void);
  28. // This function may be optionally provided by user and should return
  29. // a string containing HWASan runtime options. See asan_flags.h for details.
  30. const char *SANITIZER_CDECL __hwasan_default_options(void);
  31. void SANITIZER_CDECL __hwasan_enable_allocator_tagging(void);
  32. void SANITIZER_CDECL __hwasan_disable_allocator_tagging(void);
  33. // Mark region of memory with the given tag. Both address and size need to be
  34. // 16-byte aligned.
  35. void SANITIZER_CDECL __hwasan_tag_memory(const volatile void *p,
  36. unsigned char tag, size_t size);
  37. /// Set pointer tag. Previous tag is lost.
  38. void *SANITIZER_CDECL __hwasan_tag_pointer(const volatile void *p,
  39. unsigned char tag);
  40. /// Get tag from the pointer.
  41. unsigned char SANITIZER_CDECL
  42. __hwasan_get_tag_from_pointer(const volatile void *p);
  43. // Set memory tag from the current SP address to the given address to zero.
  44. // This is meant to annotate longjmp and other non-local jumps.
  45. // This function needs to know the (almost) exact destination frame address;
  46. // clearing shadow for the entire thread stack like __asan_handle_no_return
  47. // does would cause false reports.
  48. void SANITIZER_CDECL __hwasan_handle_longjmp(const void *sp_dst);
  49. // Set memory tag for the part of the current thread stack below sp_dst to
  50. // zero. Call this in vfork() before returning in the parent process.
  51. void SANITIZER_CDECL __hwasan_handle_vfork(const void *sp_dst);
  52. // Libc hook for thread creation. Should be called in the child thread before
  53. // any instrumented code.
  54. void SANITIZER_CDECL __hwasan_thread_enter();
  55. // Libc hook for thread destruction. No instrumented code should run after
  56. // this call.
  57. void SANITIZER_CDECL __hwasan_thread_exit();
  58. // Print shadow and origin for the memory range to stderr in a human-readable
  59. // format.
  60. void SANITIZER_CDECL __hwasan_print_shadow(const volatile void *x, size_t size);
  61. // Print one-line report about the memory usage of the current process.
  62. void SANITIZER_CDECL __hwasan_print_memory_usage();
  63. /* Returns the offset of the first byte in the memory range that can not be
  64. * accessed through the pointer in x, or -1 if the whole range is good. */
  65. intptr_t SANITIZER_CDECL __hwasan_test_shadow(const volatile void *x,
  66. size_t size);
  67. /* Sets the callback function to be called during HWASan error reporting. */
  68. void SANITIZER_CDECL
  69. __hwasan_set_error_report_callback(void (*callback)(const char *));
  70. int SANITIZER_CDECL __sanitizer_posix_memalign(void **memptr, size_t alignment,
  71. size_t size);
  72. void *SANITIZER_CDECL __sanitizer_memalign(size_t alignment, size_t size);
  73. void *SANITIZER_CDECL __sanitizer_aligned_alloc(size_t alignment, size_t size);
  74. void *SANITIZER_CDECL __sanitizer___libc_memalign(size_t alignment,
  75. size_t size);
  76. void *SANITIZER_CDECL __sanitizer_valloc(size_t size);
  77. void *SANITIZER_CDECL __sanitizer_pvalloc(size_t size);
  78. void SANITIZER_CDECL __sanitizer_free(void *ptr);
  79. void SANITIZER_CDECL __sanitizer_cfree(void *ptr);
  80. size_t SANITIZER_CDECL __sanitizer_malloc_usable_size(const void *ptr);
  81. struct mallinfo SANITIZER_CDECL __sanitizer_mallinfo();
  82. int SANITIZER_CDECL __sanitizer_mallopt(int cmd, int value);
  83. void SANITIZER_CDECL __sanitizer_malloc_stats(void);
  84. void *SANITIZER_CDECL __sanitizer_calloc(size_t nmemb, size_t size);
  85. void *SANITIZER_CDECL __sanitizer_realloc(void *ptr, size_t size);
  86. void *SANITIZER_CDECL __sanitizer_reallocarray(void *ptr, size_t nmemb,
  87. size_t size);
  88. void *SANITIZER_CDECL __sanitizer_malloc(size_t size);
  89. #ifdef __cplusplus
  90. } // extern "C"
  91. #endif
  92. #endif // SANITIZER_HWASAN_INTERFACE_H