hwasan_interface.h revision 344779
1//===-- sanitizer/asan_interface.h ------------------------------*- C++ -*-===//
2//
3//                     The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// This file is a part of HWAddressSanitizer.
11//
12// Public interface header.
13//===----------------------------------------------------------------------===//
14#ifndef SANITIZER_HWASAN_INTERFACE_H
15#define SANITIZER_HWASAN_INTERFACE_H
16
17#include <sanitizer/common_interface_defs.h>
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22  // Initialize shadow but not the rest of the runtime.
23  // Does not call libc unless there is an error.
24  // Can be called multiple times, or not at all (in which case shadow will
25  // be initialized in compiler-inserted __hwasan_init() call).
26  void __hwasan_shadow_init(void);
27
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* __hwasan_default_options(void);
31
32  void __hwasan_enable_allocator_tagging(void);
33  void __hwasan_disable_allocator_tagging(void);
34
35  // Mark region of memory with the given tag. Both address and size need to be
36  // 16-byte aligned.
37  void __hwasan_tag_memory(const volatile void *p, unsigned char tag,
38                           size_t size);
39
40  /// Set pointer tag. Previous tag is lost.
41  void *__hwasan_tag_pointer(const volatile void *p, unsigned char tag);
42
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 __hwasan_handle_longjmp(const void *sp_dst);
49
50  // Libc hook for thread creation. Should be called in the child thread before
51  // any instrumented code.
52  void __hwasan_thread_enter();
53
54  // Libc hook for thread destruction. No instrumented code should run after
55  // this call.
56  void __hwasan_thread_exit();
57
58  // Print shadow and origin for the memory range to stderr in a human-readable
59  // format.
60  void __hwasan_print_shadow(const volatile void *x, size_t size);
61
62  // Print one-line report about the memory usage of the current process.
63  void __hwasan_print_memory_usage();
64
65  int __sanitizer_posix_memalign(void **memptr, size_t alignment, size_t size);
66  void * __sanitizer_memalign(size_t alignment, size_t size);
67  void * __sanitizer_aligned_alloc(size_t alignment, size_t size);
68  void * __sanitizer___libc_memalign(size_t alignment, size_t size);
69  void * __sanitizer_valloc(size_t size);
70  void * __sanitizer_pvalloc(size_t size);
71  void __sanitizer_free(void *ptr);
72  void __sanitizer_cfree(void *ptr);
73  size_t __sanitizer_malloc_usable_size(const void *ptr);
74  struct mallinfo __sanitizer_mallinfo();
75  int __sanitizer_mallopt(int cmd, int value);
76  void __sanitizer_malloc_stats(void);
77  void * __sanitizer_calloc(size_t nmemb, size_t size);
78  void * __sanitizer_realloc(void *ptr, size_t size);
79  void * __sanitizer_malloc(size_t size);
80#ifdef __cplusplus
81}  // extern "C"
82#endif
83
84#endif  // SANITIZER_HWASAN_INTERFACE_H
85