xref: /freebsd/contrib/llvm-project/compiler-rt/include/sanitizer/msan_interface.h (revision e8d8bef961a50d4dc22501cde4fb9fb0be1b2532)
10b57cec5SDimitry Andric //===-- msan_interface.h --------------------------------------------------===//
20b57cec5SDimitry Andric //
30b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
40b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
50b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
60b57cec5SDimitry Andric //
70b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
80b57cec5SDimitry Andric //
90b57cec5SDimitry Andric // This file is a part of MemorySanitizer.
100b57cec5SDimitry Andric //
110b57cec5SDimitry Andric // Public interface header.
120b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
130b57cec5SDimitry Andric #ifndef MSAN_INTERFACE_H
140b57cec5SDimitry Andric #define MSAN_INTERFACE_H
150b57cec5SDimitry Andric 
160b57cec5SDimitry Andric #include <sanitizer/common_interface_defs.h>
170b57cec5SDimitry Andric 
180b57cec5SDimitry Andric #ifdef __cplusplus
190b57cec5SDimitry Andric extern "C" {
200b57cec5SDimitry Andric #endif
210b57cec5SDimitry Andric   /* Set raw origin for the memory range. */
220b57cec5SDimitry Andric   void __msan_set_origin(const volatile void *a, size_t size, uint32_t origin);
230b57cec5SDimitry Andric 
240b57cec5SDimitry Andric   /* Get raw origin for an address. */
250b57cec5SDimitry Andric   uint32_t __msan_get_origin(const volatile void *a);
260b57cec5SDimitry Andric 
270b57cec5SDimitry Andric   /* Test that this_id is a descendant of prev_id (or they are simply equal).
280b57cec5SDimitry Andric    * "descendant" here means they are part of the same chain, created with
290b57cec5SDimitry Andric    * __msan_chain_origin. */
300b57cec5SDimitry Andric   int __msan_origin_is_descendant_or_same(uint32_t this_id, uint32_t prev_id);
310b57cec5SDimitry Andric 
320b57cec5SDimitry Andric   /* Returns non-zero if tracking origins. */
330b57cec5SDimitry Andric   int __msan_get_track_origins(void);
340b57cec5SDimitry Andric 
350b57cec5SDimitry Andric   /* Returns the origin id of the latest UMR in the calling thread. */
360b57cec5SDimitry Andric   uint32_t __msan_get_umr_origin(void);
370b57cec5SDimitry Andric 
380b57cec5SDimitry Andric   /* Make memory region fully initialized (without changing its contents). */
390b57cec5SDimitry Andric   void __msan_unpoison(const volatile void *a, size_t size);
400b57cec5SDimitry Andric 
410b57cec5SDimitry Andric   /* Make a null-terminated string fully initialized (without changing its
420b57cec5SDimitry Andric      contents). */
430b57cec5SDimitry Andric   void __msan_unpoison_string(const volatile char *a);
440b57cec5SDimitry Andric 
450b57cec5SDimitry Andric   /* Make first n parameters of the next function call fully initialized. */
460b57cec5SDimitry Andric   void __msan_unpoison_param(size_t n);
470b57cec5SDimitry Andric 
480b57cec5SDimitry Andric   /* Make memory region fully uninitialized (without changing its contents).
490b57cec5SDimitry Andric      This is a legacy interface that does not update origin information. Use
500b57cec5SDimitry Andric      __msan_allocated_memory() instead. */
510b57cec5SDimitry Andric   void __msan_poison(const volatile void *a, size_t size);
520b57cec5SDimitry Andric 
530b57cec5SDimitry Andric   /* Make memory region partially uninitialized (without changing its contents).
540b57cec5SDimitry Andric    */
550b57cec5SDimitry Andric   void __msan_partial_poison(const volatile void *data, void *shadow,
560b57cec5SDimitry Andric                              size_t size);
570b57cec5SDimitry Andric 
580b57cec5SDimitry Andric   /* Returns the offset of the first (at least partially) poisoned byte in the
590b57cec5SDimitry Andric      memory range, or -1 if the whole range is good. */
600b57cec5SDimitry Andric   intptr_t __msan_test_shadow(const volatile void *x, size_t size);
610b57cec5SDimitry Andric 
620b57cec5SDimitry Andric   /* Checks that memory range is fully initialized, and reports an error if it
630b57cec5SDimitry Andric    * is not. */
640b57cec5SDimitry Andric   void __msan_check_mem_is_initialized(const volatile void *x, size_t size);
650b57cec5SDimitry Andric 
660b57cec5SDimitry Andric   /* For testing:
670b57cec5SDimitry Andric      __msan_set_expect_umr(1);
680b57cec5SDimitry Andric      ... some buggy code ...
690b57cec5SDimitry Andric      __msan_set_expect_umr(0);
700b57cec5SDimitry Andric      The last line will verify that a UMR happened. */
710b57cec5SDimitry Andric   void __msan_set_expect_umr(int expect_umr);
720b57cec5SDimitry Andric 
730b57cec5SDimitry Andric   /* Change the value of keep_going flag. Non-zero value means don't terminate
740b57cec5SDimitry Andric      program execution when an error is detected. This will not affect error in
750b57cec5SDimitry Andric      modules that were compiled without the corresponding compiler flag. */
760b57cec5SDimitry Andric   void __msan_set_keep_going(int keep_going);
770b57cec5SDimitry Andric 
780b57cec5SDimitry Andric   /* Print shadow and origin for the memory range to stderr in a human-readable
790b57cec5SDimitry Andric      format. */
800b57cec5SDimitry Andric   void __msan_print_shadow(const volatile void *x, size_t size);
810b57cec5SDimitry Andric 
820b57cec5SDimitry Andric   /* Print shadow for the memory range to stderr in a minimalistic
830b57cec5SDimitry Andric      human-readable format. */
840b57cec5SDimitry Andric   void __msan_dump_shadow(const volatile void *x, size_t size);
850b57cec5SDimitry Andric 
860b57cec5SDimitry Andric   /* Returns true if running under a dynamic tool (DynamoRio-based). */
870b57cec5SDimitry Andric   int  __msan_has_dynamic_component(void);
880b57cec5SDimitry Andric 
890b57cec5SDimitry Andric   /* Tell MSan about newly allocated memory (ex.: custom allocator).
900b57cec5SDimitry Andric      Memory will be marked uninitialized, with origin at the call site. */
910b57cec5SDimitry Andric   void __msan_allocated_memory(const volatile void* data, size_t size);
920b57cec5SDimitry Andric 
930b57cec5SDimitry Andric   /* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */
940b57cec5SDimitry Andric   void __sanitizer_dtor_callback(const volatile void* data, size_t size);
950b57cec5SDimitry Andric 
960b57cec5SDimitry Andric   /* This function may be optionally provided by user and should return
970b57cec5SDimitry Andric      a string containing Msan runtime options. See msan_flags.h for details. */
980b57cec5SDimitry Andric   const char* __msan_default_options(void);
990b57cec5SDimitry Andric 
1000b57cec5SDimitry Andric   /* Deprecated. Call __sanitizer_set_death_callback instead. */
1010b57cec5SDimitry Andric   void __msan_set_death_callback(void (*callback)(void));
1020b57cec5SDimitry Andric 
1030b57cec5SDimitry Andric   /* Update shadow for the application copy of size bytes from src to dst.
1040b57cec5SDimitry Andric      Src and dst are application addresses. This function does not copy the
1050b57cec5SDimitry Andric      actual application memory, it only updates shadow and origin for such
1060b57cec5SDimitry Andric      copy. Source and destination regions can overlap. */
1070b57cec5SDimitry Andric   void __msan_copy_shadow(const volatile void *dst, const volatile void *src,
1080b57cec5SDimitry Andric                           size_t size);
1090b57cec5SDimitry Andric 
1100b57cec5SDimitry Andric   /* Disables uninitialized memory checks in interceptors. */
1110b57cec5SDimitry Andric   void __msan_scoped_disable_interceptor_checks(void);
1120b57cec5SDimitry Andric 
1130b57cec5SDimitry Andric   /* Re-enables uninitialized memory checks in interceptors after a previous
1140b57cec5SDimitry Andric      call to __msan_scoped_disable_interceptor_checks. */
1150b57cec5SDimitry Andric   void __msan_scoped_enable_interceptor_checks(void);
1160b57cec5SDimitry Andric 
117*e8d8bef9SDimitry Andric   void __msan_start_switch_fiber(const void *bottom, size_t size);
118*e8d8bef9SDimitry Andric   void __msan_finish_switch_fiber(const void **bottom_old, size_t *size_old);
119*e8d8bef9SDimitry Andric 
1200b57cec5SDimitry Andric #ifdef __cplusplus
1210b57cec5SDimitry Andric }  // extern "C"
1220b57cec5SDimitry Andric #endif
1230b57cec5SDimitry Andric 
1240b57cec5SDimitry Andric #endif
125