msan_interface.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. //===-- msan_interface.h --------------------------------------------------===//
  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. // Public interface header.
  12. //===----------------------------------------------------------------------===//
  13. #ifndef MSAN_INTERFACE_H
  14. #define MSAN_INTERFACE_H
  15. #include <sanitizer/common_interface_defs.h>
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /* Set raw origin for the memory range. */
  20. void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
  21. /* Get raw origin for an address. */
  22. uint32_t __msan_get_origin(const volatile void *a);
  23. /* Test that this_id is a descendant of prev_id (or they are simply equal).
  24. * "descendant" here means they are part of the same chain, created with
  25. * __msan_chain_origin. */
  26. int __msan_origin_is_descendant_or_same(uint32_t this_id, uint32_t prev_id);
  27. /* Returns non-zero if tracking origins. */
  28. int __msan_get_track_origins(void);
  29. /* Returns the origin id of the latest UMR in the calling thread. */
  30. uint32_t __msan_get_umr_origin(void);
  31. /* Make memory region fully initialized (without changing its contents). */
  32. void __msan_unpoison(const volatile void *a, size_t size);
  33. /* Make a null-terminated string fully initialized (without changing its
  34. contents). */
  35. void __msan_unpoison_string(const volatile char *a);
  36. /* Make first n parameters of the next function call fully initialized. */
  37. void __msan_unpoison_param(size_t n);
  38. /* Make memory region fully uninitialized (without changing its contents).
  39. This is a legacy interface that does not update origin information. Use
  40. __msan_allocated_memory() instead. */
  41. void __msan_poison(const volatile void *a, size_t size);
  42. /* Make memory region partially uninitialized (without changing its contents).
  43. */
  44. void __msan_partial_poison(const volatile void *data, void *shadow,
  45. size_t size);
  46. /* Returns the offset of the first (at least partially) poisoned byte in the
  47. memory range, or -1 if the whole range is good. */
  48. intptr_t __msan_test_shadow(const volatile void *x, size_t size);
  49. /* Checks that memory range is fully initialized, and reports an error if it
  50. * is not. */
  51. void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
  52. /* For testing:
  53. __msan_set_expect_umr(1);
  54. ... some buggy code ...
  55. __msan_set_expect_umr(0);
  56. The last line will verify that a UMR happened. */
  57. void __msan_set_expect_umr(int expect_umr);
  58. /* Change the value of keep_going flag. Non-zero value means don't terminate
  59. program execution when an error is detected. This will not affect error in
  60. modules that were compiled without the corresponding compiler flag. */
  61. void __msan_set_keep_going(int keep_going);
  62. /* Print shadow and origin for the memory range to stderr in a human-readable
  63. format. */
  64. void __msan_print_shadow(const volatile void *x, size_t size);
  65. /* Print shadow for the memory range to stderr in a minimalistic
  66. human-readable format. */
  67. void __msan_dump_shadow(const volatile void *x, size_t size);
  68. /* Returns true if running under a dynamic tool (DynamoRio-based). */
  69. int __msan_has_dynamic_component(void);
  70. /* Tell MSan about newly allocated memory (ex.: custom allocator).
  71. Memory will be marked uninitialized, with origin at the call site. */
  72. void __msan_allocated_memory(const volatile void* data, size_t size);
  73. /* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */
  74. void __sanitizer_dtor_callback(const volatile void* data, size_t size);
  75. /* This function may be optionally provided by user and should return
  76. a string containing Msan runtime options. See msan_flags.h for details. */
  77. const char* __msan_default_options(void);
  78. /* Deprecated. Call __sanitizer_set_death_callback instead. */
  79. void __msan_set_death_callback(void (*callback)(void));
  80. /* Update shadow for the application copy of size bytes from src to dst.
  81. Src and dst are application addresses. This function does not copy the
  82. actual application memory, it only updates shadow and origin for such
  83. copy. Source and destination regions can overlap. */
  84. void __msan_copy_shadow(const volatile void *dst, const volatile void *src,
  85. size_t size);
  86. /* Disables uninitialized memory checks in interceptors. */
  87. void __msan_scoped_disable_interceptor_checks(void);
  88. /* Re-enables uninitialized memory checks in interceptors after a previous
  89. call to __msan_scoped_disable_interceptor_checks. */
  90. void __msan_scoped_enable_interceptor_checks(void);
  91. void __msan_start_switch_fiber(const void *bottom, size_t size);
  92. void __msan_finish_switch_fiber(const void **bottom_old, size_t *size_old);
  93. #ifdef __cplusplus
  94. } // extern "C"
  95. #endif
  96. #endif