1245614Sandrew//===-- msan_interface.h --------------------------------------------------===//
2245614Sandrew//
3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4353358Sdim// See https://llvm.org/LICENSE.txt for license information.
5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6245614Sandrew//
7245614Sandrew//===----------------------------------------------------------------------===//
8245614Sandrew//
9245614Sandrew// This file is a part of MemorySanitizer.
10245614Sandrew//
11245614Sandrew// Public interface header.
12245614Sandrew//===----------------------------------------------------------------------===//
13245614Sandrew#ifndef MSAN_INTERFACE_H
14245614Sandrew#define MSAN_INTERFACE_H
15245614Sandrew
16245614Sandrew#include <sanitizer/common_interface_defs.h>
17245614Sandrew
18245614Sandrew#ifdef __cplusplus
19245614Sandrewextern "C" {
20245614Sandrew#endif
21251034Sed  /* Set raw origin for the memory range. */
22274201Sdim  void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
23245614Sandrew
24251034Sed  /* Get raw origin for an address. */
25274201Sdim  uint32_t __msan_get_origin(const volatile void *a);
26245614Sandrew
27288943Sdim  /* Test that this_id is a descendant of prev_id (or they are simply equal).
28288943Sdim   * "descendant" here means they are part of the same chain, created with
29288943Sdim   * __msan_chain_origin. */
30288943Sdim  int __msan_origin_is_descendant_or_same(uint32_t this_id, uint32_t prev_id);
31288943Sdim
32251034Sed  /* Returns non-zero if tracking origins. */
33327952Sdim  int __msan_get_track_origins(void);
34245614Sandrew
35251034Sed  /* Returns the origin id of the latest UMR in the calling thread. */
36327952Sdim  uint32_t __msan_get_umr_origin(void);
37245614Sandrew
38251034Sed  /* Make memory region fully initialized (without changing its contents). */
39274201Sdim  void __msan_unpoison(const volatile void *a, size_t size);
40245614Sandrew
41276789Sdim  /* Make a null-terminated string fully initialized (without changing its
42276789Sdim     contents). */
43276789Sdim  void __msan_unpoison_string(const volatile char *a);
44276789Sdim
45353358Sdim  /* Make first n parameters of the next function call fully initialized. */
46353358Sdim  void __msan_unpoison_param(size_t n);
47353358Sdim
48280031Sdim  /* Make memory region fully uninitialized (without changing its contents).
49280031Sdim     This is a legacy interface that does not update origin information. Use
50280031Sdim     __msan_allocated_memory() instead. */
51274201Sdim  void __msan_poison(const volatile void *a, size_t size);
52245614Sandrew
53251034Sed  /* Make memory region partially uninitialized (without changing its contents).
54251034Sed   */
55274201Sdim  void __msan_partial_poison(const volatile void *data, void *shadow,
56274201Sdim                             size_t size);
57245614Sandrew
58251034Sed  /* Returns the offset of the first (at least partially) poisoned byte in the
59251034Sed     memory range, or -1 if the whole range is good. */
60274201Sdim  intptr_t __msan_test_shadow(const volatile void *x, size_t size);
61245614Sandrew
62276789Sdim  /* Checks that memory range is fully initialized, and reports an error if it
63276789Sdim   * is not. */
64276789Sdim  void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
65276789Sdim
66251034Sed  /* For testing:
67251034Sed     __msan_set_expect_umr(1);
68251034Sed     ... some buggy code ...
69251034Sed     __msan_set_expect_umr(0);
70251034Sed     The last line will verify that a UMR happened. */
71251034Sed  void __msan_set_expect_umr(int expect_umr);
72245614Sandrew
73274201Sdim  /* Change the value of keep_going flag. Non-zero value means don't terminate
74274201Sdim     program execution when an error is detected. This will not affect error in
75274201Sdim     modules that were compiled without the corresponding compiler flag. */
76274201Sdim  void __msan_set_keep_going(int keep_going);
77274201Sdim
78276789Sdim  /* Print shadow and origin for the memory range to stderr in a human-readable
79251034Sed     format. */
80274201Sdim  void __msan_print_shadow(const volatile void *x, size_t size);
81245614Sandrew
82276789Sdim  /* Print shadow for the memory range to stderr in a minimalistic
83251034Sed     human-readable format. */
84276789Sdim  void __msan_dump_shadow(const volatile void *x, size_t size);
85245614Sandrew
86251034Sed  /* Returns true if running under a dynamic tool (DynamoRio-based). */
87327952Sdim  int  __msan_has_dynamic_component(void);
88245614Sandrew
89251034Sed  /* Tell MSan about newly allocated memory (ex.: custom allocator).
90251034Sed     Memory will be marked uninitialized, with origin at the call site. */
91274201Sdim  void __msan_allocated_memory(const volatile void* data, size_t size);
92251034Sed
93296417Sdim  /* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */
94296417Sdim  void __sanitizer_dtor_callback(const volatile void* data, size_t size);
95296417Sdim
96274201Sdim  /* This function may be optionally provided by user and should return
97274201Sdim     a string containing Msan runtime options. See msan_flags.h for details. */
98327952Sdim  const char* __msan_default_options(void);
99274201Sdim
100296417Sdim  /* Deprecated. Call __sanitizer_set_death_callback instead. */
101276789Sdim  void __msan_set_death_callback(void (*callback)(void));
102274201Sdim
103296417Sdim  /* Update shadow for the application copy of size bytes from src to dst.
104296417Sdim     Src and dst are application addresses. This function does not copy the
105296417Sdim     actual application memory, it only updates shadow and origin for such
106296417Sdim     copy. Source and destination regions can overlap. */
107296417Sdim  void __msan_copy_shadow(const volatile void *dst, const volatile void *src,
108296417Sdim                          size_t size);
109341825Sdim
110341825Sdim  /* Disables uninitialized memory checks in interceptors. */
111341825Sdim  void __msan_scoped_disable_interceptor_checks(void);
112341825Sdim
113341825Sdim  /* Re-enables uninitialized memory checks in interceptors after a previous
114341825Sdim     call to __msan_scoped_disable_interceptor_checks. */
115341825Sdim  void __msan_scoped_enable_interceptor_checks(void);
116341825Sdim
117245614Sandrew#ifdef __cplusplus
118245614Sandrew}  // extern "C"
119245614Sandrew#endif
120245614Sandrew
121245614Sandrew#endif
122