msan_interface.h revision 288943
1245614Sandrew//===-- msan_interface.h --------------------------------------------------===//
2245614Sandrew//
3245614Sandrew//                     The LLVM Compiler Infrastructure
4245614Sandrew//
5245614Sandrew// This file is distributed under the University of Illinois Open Source
6245614Sandrew// License. See LICENSE.TXT for details.
7245614Sandrew//
8245614Sandrew//===----------------------------------------------------------------------===//
9245614Sandrew//
10245614Sandrew// This file is a part of MemorySanitizer.
11245614Sandrew//
12245614Sandrew// Public interface header.
13245614Sandrew//===----------------------------------------------------------------------===//
14245614Sandrew#ifndef MSAN_INTERFACE_H
15245614Sandrew#define MSAN_INTERFACE_H
16245614Sandrew
17245614Sandrew#include <sanitizer/common_interface_defs.h>
18245614Sandrew
19245614Sandrew#ifdef __cplusplus
20245614Sandrewextern "C" {
21245614Sandrew#endif
22251034Sed  /* Set raw origin for the memory range. */
23274201Sdim  void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
24245614Sandrew
25251034Sed  /* Get raw origin for an address. */
26274201Sdim  uint32_t __msan_get_origin(const volatile void *a);
27245614Sandrew
28288943Sdim  /* Test that this_id is a descendant of prev_id (or they are simply equal).
29288943Sdim   * "descendant" here means they are part of the same chain, created with
30288943Sdim   * __msan_chain_origin. */
31288943Sdim  int __msan_origin_is_descendant_or_same(uint32_t this_id, uint32_t prev_id);
32288943Sdim
33251034Sed  /* Returns non-zero if tracking origins. */
34251034Sed  int __msan_get_track_origins();
35245614Sandrew
36251034Sed  /* Returns the origin id of the latest UMR in the calling thread. */
37251034Sed  uint32_t __msan_get_umr_origin();
38245614Sandrew
39251034Sed  /* Make memory region fully initialized (without changing its contents). */
40274201Sdim  void __msan_unpoison(const volatile void *a, size_t size);
41245614Sandrew
42276789Sdim  /* Make a null-terminated string fully initialized (without changing its
43276789Sdim     contents). */
44276789Sdim  void __msan_unpoison_string(const volatile char *a);
45276789Sdim
46280031Sdim  /* Make memory region fully uninitialized (without changing its contents).
47280031Sdim     This is a legacy interface that does not update origin information. Use
48280031Sdim     __msan_allocated_memory() instead. */
49274201Sdim  void __msan_poison(const volatile void *a, size_t size);
50245614Sandrew
51251034Sed  /* Make memory region partially uninitialized (without changing its contents).
52251034Sed   */
53274201Sdim  void __msan_partial_poison(const volatile void *data, void *shadow,
54274201Sdim                             size_t size);
55245614Sandrew
56251034Sed  /* Returns the offset of the first (at least partially) poisoned byte in the
57251034Sed     memory range, or -1 if the whole range is good. */
58274201Sdim  intptr_t __msan_test_shadow(const volatile void *x, size_t size);
59245614Sandrew
60276789Sdim  /* Checks that memory range is fully initialized, and reports an error if it
61276789Sdim   * is not. */
62276789Sdim  void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
63276789Sdim
64251034Sed  /* Set exit code when error(s) were detected.
65251034Sed     Value of 0 means don't change the program exit code. */
66251034Sed  void __msan_set_exit_code(int exit_code);
67245614Sandrew
68251034Sed  /* For testing:
69251034Sed     __msan_set_expect_umr(1);
70251034Sed     ... some buggy code ...
71251034Sed     __msan_set_expect_umr(0);
72251034Sed     The last line will verify that a UMR happened. */
73251034Sed  void __msan_set_expect_umr(int expect_umr);
74245614Sandrew
75274201Sdim  /* Change the value of keep_going flag. Non-zero value means don't terminate
76274201Sdim     program execution when an error is detected. This will not affect error in
77274201Sdim     modules that were compiled without the corresponding compiler flag. */
78274201Sdim  void __msan_set_keep_going(int keep_going);
79274201Sdim
80276789Sdim  /* Print shadow and origin for the memory range to stderr in a human-readable
81251034Sed     format. */
82274201Sdim  void __msan_print_shadow(const volatile void *x, size_t size);
83245614Sandrew
84276789Sdim  /* Print shadow for the memory range to stderr in a minimalistic
85251034Sed     human-readable format. */
86276789Sdim  void __msan_dump_shadow(const volatile void *x, size_t size);
87245614Sandrew
88251034Sed  /* Returns true if running under a dynamic tool (DynamoRio-based). */
89251034Sed  int  __msan_has_dynamic_component();
90245614Sandrew
91251034Sed  /* Tell MSan about newly allocated memory (ex.: custom allocator).
92251034Sed     Memory will be marked uninitialized, with origin at the call site. */
93274201Sdim  void __msan_allocated_memory(const volatile void* data, size_t size);
94251034Sed
95274201Sdim  /* This function may be optionally provided by user and should return
96274201Sdim     a string containing Msan runtime options. See msan_flags.h for details. */
97274201Sdim  const char* __msan_default_options();
98274201Sdim
99276789Sdim  /* Sets the callback to be called right before death on error.
100276789Sdim     Passing 0 will unset the callback. */
101276789Sdim  void __msan_set_death_callback(void (*callback)(void));
102274201Sdim
103245614Sandrew#ifdef __cplusplus
104245614Sandrew}  // extern "C"
105245614Sandrew#endif
106245614Sandrew
107245614Sandrew#endif
108