msan_interface_internal.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. //===-- msan_interface_internal.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 MemorySanitizer.
  10. //
  11. // Private MSan interface header.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef MSAN_INTERFACE_INTERNAL_H
  14. #define MSAN_INTERFACE_INTERNAL_H
  15. #include "sanitizer_common/sanitizer_internal_defs.h"
  16. extern "C" {
  17. // FIXME: document all interface functions.
  18. SANITIZER_INTERFACE_ATTRIBUTE
  19. int __msan_get_track_origins();
  20. SANITIZER_INTERFACE_ATTRIBUTE
  21. void __msan_init();
  22. // Print a warning and maybe return.
  23. // This function can die based on common_flags()->exitcode.
  24. SANITIZER_INTERFACE_ATTRIBUTE
  25. void __msan_warning();
  26. // Print a warning and die.
  27. // Instrumentation inserts calls to this function when building in "fast" mode
  28. // (i.e. -mllvm -msan-keep-going)
  29. SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn))
  30. void __msan_warning_noreturn();
  31. using __sanitizer::uptr;
  32. using __sanitizer::sptr;
  33. using __sanitizer::uu64;
  34. using __sanitizer::uu32;
  35. using __sanitizer::uu16;
  36. using __sanitizer::u64;
  37. using __sanitizer::u32;
  38. using __sanitizer::u16;
  39. using __sanitizer::u8;
  40. // Versions of the above which take Origin as a parameter
  41. SANITIZER_INTERFACE_ATTRIBUTE
  42. void __msan_warning_with_origin(u32 origin);
  43. SANITIZER_INTERFACE_ATTRIBUTE __attribute__((noreturn)) void
  44. __msan_warning_with_origin_noreturn(u32 origin);
  45. SANITIZER_INTERFACE_ATTRIBUTE
  46. void __msan_maybe_warning_1(u8 s, u32 o);
  47. SANITIZER_INTERFACE_ATTRIBUTE
  48. void __msan_maybe_warning_2(u16 s, u32 o);
  49. SANITIZER_INTERFACE_ATTRIBUTE
  50. void __msan_maybe_warning_4(u32 s, u32 o);
  51. SANITIZER_INTERFACE_ATTRIBUTE
  52. void __msan_maybe_warning_8(u64 s, u32 o);
  53. SANITIZER_INTERFACE_ATTRIBUTE
  54. void __msan_maybe_store_origin_1(u8 s, void *p, u32 o);
  55. SANITIZER_INTERFACE_ATTRIBUTE
  56. void __msan_maybe_store_origin_2(u16 s, void *p, u32 o);
  57. SANITIZER_INTERFACE_ATTRIBUTE
  58. void __msan_maybe_store_origin_4(u32 s, void *p, u32 o);
  59. SANITIZER_INTERFACE_ATTRIBUTE
  60. void __msan_maybe_store_origin_8(u64 s, void *p, u32 o);
  61. SANITIZER_INTERFACE_ATTRIBUTE
  62. void __msan_unpoison(const void *a, uptr size);
  63. SANITIZER_INTERFACE_ATTRIBUTE
  64. void __msan_unpoison_string(const char *s);
  65. SANITIZER_INTERFACE_ATTRIBUTE
  66. void __msan_unpoison_param(uptr n);
  67. SANITIZER_INTERFACE_ATTRIBUTE
  68. void __msan_clear_and_unpoison(void *a, uptr size);
  69. SANITIZER_INTERFACE_ATTRIBUTE
  70. void* __msan_memcpy(void *dst, const void *src, uptr size);
  71. SANITIZER_INTERFACE_ATTRIBUTE
  72. void* __msan_memset(void *s, int c, uptr n);
  73. SANITIZER_INTERFACE_ATTRIBUTE
  74. void* __msan_memmove(void* dest, const void* src, uptr n);
  75. SANITIZER_INTERFACE_ATTRIBUTE
  76. void __msan_poison(const void *a, uptr size);
  77. SANITIZER_INTERFACE_ATTRIBUTE
  78. void __msan_poison_stack(void *a, uptr size);
  79. // Copy size bytes from src to dst and unpoison the result.
  80. // Useful to implement unsafe loads.
  81. SANITIZER_INTERFACE_ATTRIBUTE
  82. void __msan_load_unpoisoned(void *src, uptr size, void *dst);
  83. // Returns the offset of the first (at least partially) poisoned byte,
  84. // or -1 if the whole range is good.
  85. SANITIZER_INTERFACE_ATTRIBUTE
  86. sptr __msan_test_shadow(const void *x, uptr size);
  87. SANITIZER_INTERFACE_ATTRIBUTE
  88. void __msan_check_mem_is_initialized(const void *x, uptr size);
  89. SANITIZER_INTERFACE_ATTRIBUTE
  90. void __msan_set_origin(const void *a, uptr size, u32 origin);
  91. SANITIZER_INTERFACE_ATTRIBUTE
  92. void __msan_set_alloca_origin(void *a, uptr size, char *descr);
  93. SANITIZER_INTERFACE_ATTRIBUTE
  94. void __msan_set_alloca_origin4(void *a, uptr size, char *descr, uptr pc);
  95. SANITIZER_INTERFACE_ATTRIBUTE
  96. void __msan_set_alloca_origin_with_descr(void *a, uptr size, u32 *id_ptr,
  97. char *descr);
  98. SANITIZER_INTERFACE_ATTRIBUTE
  99. void __msan_set_alloca_origin_no_descr(void *a, uptr size, u32 *id_ptr);
  100. SANITIZER_INTERFACE_ATTRIBUTE
  101. u32 __msan_chain_origin(u32 id);
  102. SANITIZER_INTERFACE_ATTRIBUTE
  103. u32 __msan_get_origin(const void *a);
  104. // Test that this_id is a descendant of prev_id (or they are simply equal).
  105. // "descendant" here means that are part of the same chain, created with
  106. // __msan_chain_origin.
  107. SANITIZER_INTERFACE_ATTRIBUTE
  108. int __msan_origin_is_descendant_or_same(u32 this_id, u32 prev_id);
  109. SANITIZER_INTERFACE_ATTRIBUTE
  110. void __msan_clear_on_return();
  111. SANITIZER_INTERFACE_ATTRIBUTE
  112. void __msan_set_keep_going(int keep_going);
  113. SANITIZER_INTERFACE_ATTRIBUTE
  114. int __msan_set_poison_in_malloc(int do_poison);
  115. SANITIZER_INTERFACE_ATTRIBUTE
  116. const char *__msan_default_options();
  117. // For testing.
  118. SANITIZER_INTERFACE_ATTRIBUTE
  119. void __msan_set_expect_umr(int expect_umr);
  120. SANITIZER_INTERFACE_ATTRIBUTE
  121. void __msan_print_shadow(const void *x, uptr size);
  122. SANITIZER_INTERFACE_ATTRIBUTE
  123. void __msan_dump_shadow(const void *x, uptr size);
  124. SANITIZER_INTERFACE_ATTRIBUTE
  125. int __msan_has_dynamic_component();
  126. // For testing.
  127. SANITIZER_INTERFACE_ATTRIBUTE
  128. u32 __msan_get_umr_origin();
  129. SANITIZER_INTERFACE_ATTRIBUTE
  130. void __msan_partial_poison(const void* data, void* shadow, uptr size);
  131. // Tell MSan about newly allocated memory (ex.: custom allocator).
  132. // Memory will be marked uninitialized, with origin at the call site.
  133. SANITIZER_INTERFACE_ATTRIBUTE
  134. void __msan_allocated_memory(const void* data, uptr size);
  135. // Tell MSan about newly destroyed memory. Memory will be marked
  136. // uninitialized.
  137. SANITIZER_INTERFACE_ATTRIBUTE
  138. void __sanitizer_dtor_callback(const void* data, uptr size);
  139. SANITIZER_INTERFACE_ATTRIBUTE
  140. void __sanitizer_dtor_callback_fields(const void *data, uptr size);
  141. SANITIZER_INTERFACE_ATTRIBUTE
  142. void __sanitizer_dtor_callback_vptr(const void *data);
  143. SANITIZER_INTERFACE_ATTRIBUTE
  144. u16 __sanitizer_unaligned_load16(const uu16 *p);
  145. SANITIZER_INTERFACE_ATTRIBUTE
  146. u32 __sanitizer_unaligned_load32(const uu32 *p);
  147. SANITIZER_INTERFACE_ATTRIBUTE
  148. u64 __sanitizer_unaligned_load64(const uu64 *p);
  149. SANITIZER_INTERFACE_ATTRIBUTE
  150. void __sanitizer_unaligned_store16(uu16 *p, u16 x);
  151. SANITIZER_INTERFACE_ATTRIBUTE
  152. void __sanitizer_unaligned_store32(uu32 *p, u32 x);
  153. SANITIZER_INTERFACE_ATTRIBUTE
  154. void __sanitizer_unaligned_store64(uu64 *p, u64 x);
  155. SANITIZER_INTERFACE_ATTRIBUTE
  156. void __msan_set_death_callback(void (*callback)(void));
  157. SANITIZER_INTERFACE_ATTRIBUTE
  158. void __msan_copy_shadow(void *dst, const void *src, uptr size);
  159. SANITIZER_INTERFACE_ATTRIBUTE
  160. void __msan_scoped_disable_interceptor_checks();
  161. SANITIZER_INTERFACE_ATTRIBUTE
  162. void __msan_scoped_enable_interceptor_checks();
  163. SANITIZER_INTERFACE_ATTRIBUTE
  164. void __msan_start_switch_fiber(const void *bottom, uptr size);
  165. SANITIZER_INTERFACE_ATTRIBUTE
  166. void __msan_finish_switch_fiber(const void **bottom_old, uptr *size_old);
  167. } // extern "C"
  168. #endif // MSAN_INTERFACE_INTERNAL_H