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. */ 22*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_set_origin(const volatile void *a, size_t size, 23*5f757f3fSDimitry Andric uint32_t origin); 240b57cec5SDimitry Andric 250b57cec5SDimitry Andric /* Get raw origin for an address. */ 26*5f757f3fSDimitry Andric uint32_t SANITIZER_CDECL __msan_get_origin(const volatile void *a); 270b57cec5SDimitry Andric 280b57cec5SDimitry Andric /* Test that this_id is a descendant of prev_id (or they are simply equal). 290b57cec5SDimitry Andric * "descendant" here means they are part of the same chain, created with 300b57cec5SDimitry Andric * __msan_chain_origin. */ 31*5f757f3fSDimitry Andric int SANITIZER_CDECL __msan_origin_is_descendant_or_same(uint32_t this_id, 32*5f757f3fSDimitry Andric uint32_t prev_id); 330b57cec5SDimitry Andric 340b57cec5SDimitry Andric /* Returns non-zero if tracking origins. */ 35*5f757f3fSDimitry Andric int SANITIZER_CDECL __msan_get_track_origins(void); 360b57cec5SDimitry Andric 370b57cec5SDimitry Andric /* Returns the origin id of the latest UMR in the calling thread. */ 38*5f757f3fSDimitry Andric uint32_t SANITIZER_CDECL __msan_get_umr_origin(void); 390b57cec5SDimitry Andric 400b57cec5SDimitry Andric /* Make memory region fully initialized (without changing its contents). */ 41*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_unpoison(const volatile void *a, size_t size); 420b57cec5SDimitry Andric 430b57cec5SDimitry Andric /* Make a null-terminated string fully initialized (without changing its 440b57cec5SDimitry Andric contents). */ 45*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_unpoison_string(const volatile char *a); 460b57cec5SDimitry Andric 470b57cec5SDimitry Andric /* Make first n parameters of the next function call fully initialized. */ 48*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_unpoison_param(size_t n); 490b57cec5SDimitry Andric 500b57cec5SDimitry Andric /* Make memory region fully uninitialized (without changing its contents). 510b57cec5SDimitry Andric This is a legacy interface that does not update origin information. Use 520b57cec5SDimitry Andric __msan_allocated_memory() instead. */ 53*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_poison(const volatile void *a, size_t size); 540b57cec5SDimitry Andric 550b57cec5SDimitry Andric /* Make memory region partially uninitialized (without changing its contents). 560b57cec5SDimitry Andric */ 57*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_partial_poison(const volatile void *data, 58*5f757f3fSDimitry Andric void *shadow, size_t size); 590b57cec5SDimitry Andric 600b57cec5SDimitry Andric /* Returns the offset of the first (at least partially) poisoned byte in the 610b57cec5SDimitry Andric memory range, or -1 if the whole range is good. */ 62*5f757f3fSDimitry Andric intptr_t SANITIZER_CDECL __msan_test_shadow(const volatile void *x, 63*5f757f3fSDimitry Andric size_t size); 640b57cec5SDimitry Andric 650b57cec5SDimitry Andric /* Checks that memory range is fully initialized, and reports an error if it 660b57cec5SDimitry Andric * is not. */ 67*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_check_mem_is_initialized(const volatile void *x, 68*5f757f3fSDimitry Andric size_t size); 690b57cec5SDimitry Andric 700b57cec5SDimitry Andric /* For testing: 710b57cec5SDimitry Andric __msan_set_expect_umr(1); 720b57cec5SDimitry Andric ... some buggy code ... 730b57cec5SDimitry Andric __msan_set_expect_umr(0); 740b57cec5SDimitry Andric The last line will verify that a UMR happened. */ 75*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_set_expect_umr(int expect_umr); 760b57cec5SDimitry Andric 770b57cec5SDimitry Andric /* Change the value of keep_going flag. Non-zero value means don't terminate 780b57cec5SDimitry Andric program execution when an error is detected. This will not affect error in 790b57cec5SDimitry Andric modules that were compiled without the corresponding compiler flag. */ 80*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_set_keep_going(int keep_going); 810b57cec5SDimitry Andric 820b57cec5SDimitry Andric /* Print shadow and origin for the memory range to stderr in a human-readable 830b57cec5SDimitry Andric format. */ 84*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_print_shadow(const volatile void *x, size_t size); 850b57cec5SDimitry Andric 860b57cec5SDimitry Andric /* Print shadow for the memory range to stderr in a minimalistic 870b57cec5SDimitry Andric human-readable format. */ 88*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_dump_shadow(const volatile void *x, size_t size); 890b57cec5SDimitry Andric 900b57cec5SDimitry Andric /* Returns true if running under a dynamic tool (DynamoRio-based). */ 91*5f757f3fSDimitry Andric int SANITIZER_CDECL __msan_has_dynamic_component(void); 920b57cec5SDimitry Andric 930b57cec5SDimitry Andric /* Tell MSan about newly allocated memory (ex.: custom allocator). 940b57cec5SDimitry Andric Memory will be marked uninitialized, with origin at the call site. */ 95*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_allocated_memory(const volatile void *data, 96*5f757f3fSDimitry Andric size_t size); 970b57cec5SDimitry Andric 980b57cec5SDimitry Andric /* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */ 99*5f757f3fSDimitry Andric void SANITIZER_CDECL __sanitizer_dtor_callback(const volatile void *data, 100*5f757f3fSDimitry Andric size_t size); 101*5f757f3fSDimitry Andric void SANITIZER_CDECL __sanitizer_dtor_callback_fields(const volatile void *data, 102*5f757f3fSDimitry Andric size_t size); 103*5f757f3fSDimitry Andric void SANITIZER_CDECL __sanitizer_dtor_callback_vptr(const volatile void *data); 1040b57cec5SDimitry Andric 1050b57cec5SDimitry Andric /* This function may be optionally provided by user and should return 1060b57cec5SDimitry Andric a string containing Msan runtime options. See msan_flags.h for details. */ 107*5f757f3fSDimitry Andric const char *SANITIZER_CDECL __msan_default_options(void); 1080b57cec5SDimitry Andric 1090b57cec5SDimitry Andric /* Deprecated. Call __sanitizer_set_death_callback instead. */ 110*5f757f3fSDimitry Andric void SANITIZER_CDECL 111*5f757f3fSDimitry Andric __msan_set_death_callback(void(SANITIZER_CDECL *callback)(void)); 1120b57cec5SDimitry Andric 1130b57cec5SDimitry Andric /* Update shadow for the application copy of size bytes from src to dst. 1140b57cec5SDimitry Andric Src and dst are application addresses. This function does not copy the 1150b57cec5SDimitry Andric actual application memory, it only updates shadow and origin for such 1160b57cec5SDimitry Andric copy. Source and destination regions can overlap. */ 117*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_copy_shadow(const volatile void *dst, 118*5f757f3fSDimitry Andric const volatile void *src, size_t size); 1190b57cec5SDimitry Andric 1200b57cec5SDimitry Andric /* Disables uninitialized memory checks in interceptors. */ 121*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_scoped_disable_interceptor_checks(void); 1220b57cec5SDimitry Andric 1230b57cec5SDimitry Andric /* Re-enables uninitialized memory checks in interceptors after a previous 1240b57cec5SDimitry Andric call to __msan_scoped_disable_interceptor_checks. */ 125*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_scoped_enable_interceptor_checks(void); 1260b57cec5SDimitry Andric 127*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_start_switch_fiber(const void *bottom, size_t size); 128*5f757f3fSDimitry Andric void SANITIZER_CDECL __msan_finish_switch_fiber(const void **bottom_old, 129*5f757f3fSDimitry Andric size_t *size_old); 130e8d8bef9SDimitry Andric 1310b57cec5SDimitry Andric #ifdef __cplusplus 1320b57cec5SDimitry Andric } // extern "C" 1330b57cec5SDimitry Andric #endif 1340b57cec5SDimitry Andric 1350b57cec5SDimitry Andric #endif 136