blob: f54bcaa3e157645237d639cba4c23b6b77f466dc [file] [log] [blame]
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +00001//===-- 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 Stepanov5cb0ca82012-12-11 12:44:43 +000019#ifdef __cplusplus
20extern "C" {
21#endif
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000022 /* Set raw origin for the memory range. */
Evgeniy Stepanov1e7a3d72013-09-10 11:54:51 +000023 void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000024
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000025 /* Get raw origin for an address. */
Evgeniy Stepanov1e7a3d72013-09-10 11:54:51 +000026 uint32_t __msan_get_origin(const volatile void *a);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000027
Stephen Hines86277eb2015-03-23 12:06:32 -070028 /* 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 Stepanov12c46932013-01-29 14:33:29 +000033 /* Returns non-zero if tracking origins. */
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000034 int __msan_get_track_origins();
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000035
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000036 /* Returns the origin id of the latest UMR in the calling thread. */
Evgeniy Stepanov250f2212013-01-30 13:12:08 +000037 uint32_t __msan_get_umr_origin();
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000038
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000039 /* Make memory region fully initialized (without changing its contents). */
Evgeniy Stepanov1e7a3d72013-09-10 11:54:51 +000040 void __msan_unpoison(const volatile void *a, size_t size);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000041
Stephen Hines2d1fdb22014-05-28 23:58:16 -070042 /* Make a null-terminated string fully initialized (without changing its
43 contents). */
44 void __msan_unpoison_string(const volatile char *a);
45
Stephen Hines86277eb2015-03-23 12:06:32 -070046 /* 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 Stepanov1e7a3d72013-09-10 11:54:51 +000049 void __msan_poison(const volatile void *a, size_t size);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000050
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000051 /* Make memory region partially uninitialized (without changing its contents).
52 */
Evgeniy Stepanov1e7a3d72013-09-10 11:54:51 +000053 void __msan_partial_poison(const volatile void *data, void *shadow,
54 size_t size);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000055
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000056 /* 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 Stepanov1e7a3d72013-09-10 11:54:51 +000058 intptr_t __msan_test_shadow(const volatile void *x, size_t size);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000059
Stephen Hines2d1fdb22014-05-28 23:58:16 -070060 /* 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 Stepanov12c46932013-01-29 14:33:29 +000064 /* Set exit code when error(s) were detected.
65 Value of 0 means don't change the program exit code. */
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000066 void __msan_set_exit_code(int exit_code);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000067
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000068 /* For testing:
69 __msan_set_expect_umr(1);
70 ... some buggy code ...
71 __msan_set_expect_umr(0);
72 The last line will verify that a UMR happened. */
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000073 void __msan_set_expect_umr(int expect_umr);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000074
Evgeniy Stepanovbb881c72013-06-21 12:37:58 +000075 /* Change the value of keep_going flag. Non-zero value means don't terminate
76 program execution when an error is detected. This will not affect error in
77 modules that were compiled without the corresponding compiler flag. */
78 void __msan_set_keep_going(int keep_going);
79
Stephen Hines2d1fdb22014-05-28 23:58:16 -070080 /* Print shadow and origin for the memory range to stderr in a human-readable
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000081 format. */
Evgeniy Stepanov1e7a3d72013-09-10 11:54:51 +000082 void __msan_print_shadow(const volatile void *x, size_t size);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000083
Stephen Hines2d1fdb22014-05-28 23:58:16 -070084 /* Print shadow for the memory range to stderr in a minimalistic
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000085 human-readable format. */
Stephen Hines2d1fdb22014-05-28 23:58:16 -070086 void __msan_dump_shadow(const volatile void *x, size_t size);
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +000087
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000088 /* Returns true if running under a dynamic tool (DynamoRio-based). */
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000089 int __msan_has_dynamic_component();
90
91 /* Tell MSan about newly allocated memory (ex.: custom allocator).
92 Memory will be marked uninitialized, with origin at the call site. */
Evgeniy Stepanov1e7a3d72013-09-10 11:54:51 +000093 void __msan_allocated_memory(const volatile void* data, size_t size);
Evgeniy Stepanov12c46932013-01-29 14:33:29 +000094
Evgeniy Stepanov5c48a8c2013-08-02 14:26:58 +000095 /* This function may be optionally provided by user and should return
96 a string containing Msan runtime options. See msan_flags.h for details. */
97 const char* __msan_default_options();
98
Stephen Hines6a211c52014-07-21 00:49:56 -070099 /* Sets the callback to be called right before death on error.
100 Passing 0 will unset the callback. */
Stephen Hines2d1fdb22014-05-28 23:58:16 -0700101 void __msan_set_death_callback(void (*callback)(void));
Evgeniy Stepanov5c48a8c2013-08-02 14:26:58 +0000102
Evgeniy Stepanov5cb0ca82012-12-11 12:44:43 +0000103#ifdef __cplusplus
104} // extern "C"
105#endif
106
107#endif