msan_interface.h 4.4 KB

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