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