Path: blob/main/contrib/llvm-project/compiler-rt/include/sanitizer/msan_interface.h
35235 views
//===-- msan_interface.h --------------------------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file is a part of MemorySanitizer.9//10// Public interface header.11//===----------------------------------------------------------------------===//12#ifndef MSAN_INTERFACE_H13#define MSAN_INTERFACE_H1415#include <sanitizer/common_interface_defs.h>1617#ifdef __cplusplus18extern "C" {19#endif20/* Set raw origin for the memory range. */21void SANITIZER_CDECL __msan_set_origin(const volatile void *a, size_t size,22uint32_t origin);2324/* Get raw origin for an address. */25uint32_t SANITIZER_CDECL __msan_get_origin(const volatile void *a);2627/* Test that this_id is a descendant of prev_id (or they are simply equal).28* "descendant" here means they are part of the same chain, created with29* __msan_chain_origin. */30int SANITIZER_CDECL __msan_origin_is_descendant_or_same(uint32_t this_id,31uint32_t prev_id);3233/* Returns non-zero if tracking origins. */34int SANITIZER_CDECL __msan_get_track_origins(void);3536/* Returns the origin id of the latest UMR in the calling thread. */37uint32_t SANITIZER_CDECL __msan_get_umr_origin(void);3839/* Make memory region fully initialized (without changing its contents). */40void SANITIZER_CDECL __msan_unpoison(const volatile void *a, size_t size);4142/* Make a null-terminated string fully initialized (without changing its43contents). */44void SANITIZER_CDECL __msan_unpoison_string(const volatile char *a);4546/* Make first n parameters of the next function call fully initialized. */47void SANITIZER_CDECL __msan_unpoison_param(size_t n);4849/* Make memory region fully uninitialized (without changing its contents).50This is a legacy interface that does not update origin information. Use51__msan_allocated_memory() instead. */52void SANITIZER_CDECL __msan_poison(const volatile void *a, size_t size);5354/* Make memory region partially uninitialized (without changing its contents).55*/56void SANITIZER_CDECL __msan_partial_poison(const volatile void *data,57void *shadow, size_t size);5859/* Returns the offset of the first (at least partially) poisoned byte in the60memory range, or -1 if the whole range is good. */61intptr_t SANITIZER_CDECL __msan_test_shadow(const volatile void *x,62size_t size);6364/* Checks that memory range is fully initialized, and reports an error if it65* is not. */66void SANITIZER_CDECL __msan_check_mem_is_initialized(const volatile void *x,67size_t size);6869/* For testing:70__msan_set_expect_umr(1);71... some buggy code ...72__msan_set_expect_umr(0);73The last line will verify that a UMR happened. */74void SANITIZER_CDECL __msan_set_expect_umr(int expect_umr);7576/* Change the value of keep_going flag. Non-zero value means don't terminate77program execution when an error is detected. This will not affect error in78modules that were compiled without the corresponding compiler flag. */79void SANITIZER_CDECL __msan_set_keep_going(int keep_going);8081/* Print shadow and origin for the memory range to stderr in a human-readable82format. */83void SANITIZER_CDECL __msan_print_shadow(const volatile void *x, size_t size);8485/* Print shadow for the memory range to stderr in a minimalistic86human-readable format. */87void SANITIZER_CDECL __msan_dump_shadow(const volatile void *x, size_t size);8889/* Returns true if running under a dynamic tool (DynamoRio-based). */90int SANITIZER_CDECL __msan_has_dynamic_component(void);9192/* Tell MSan about newly allocated memory (ex.: custom allocator).93Memory will be marked uninitialized, with origin at the call site. */94void SANITIZER_CDECL __msan_allocated_memory(const volatile void *data,95size_t size);9697/* Tell MSan about newly destroyed memory. Mark memory as uninitialized. */98void SANITIZER_CDECL __sanitizer_dtor_callback(const volatile void *data,99size_t size);100void SANITIZER_CDECL __sanitizer_dtor_callback_fields(const volatile void *data,101size_t size);102void SANITIZER_CDECL __sanitizer_dtor_callback_vptr(const volatile void *data);103104/* This function may be optionally provided by user and should return105a string containing Msan runtime options. See msan_flags.h for details. */106const char *SANITIZER_CDECL __msan_default_options(void);107108/* Deprecated. Call __sanitizer_set_death_callback instead. */109void SANITIZER_CDECL110__msan_set_death_callback(void(SANITIZER_CDECL *callback)(void));111112/* Update shadow for the application copy of size bytes from src to dst.113Src and dst are application addresses. This function does not copy the114actual application memory, it only updates shadow and origin for such115copy. Source and destination regions can overlap. */116void SANITIZER_CDECL __msan_copy_shadow(const volatile void *dst,117const volatile void *src, size_t size);118119/* Disables uninitialized memory checks in interceptors. */120void SANITIZER_CDECL __msan_scoped_disable_interceptor_checks(void);121122/* Re-enables uninitialized memory checks in interceptors after a previous123call to __msan_scoped_disable_interceptor_checks. */124void SANITIZER_CDECL __msan_scoped_enable_interceptor_checks(void);125126void SANITIZER_CDECL __msan_start_switch_fiber(const void *bottom, size_t size);127void SANITIZER_CDECL __msan_finish_switch_fiber(const void **bottom_old,128size_t *size_old);129130#ifdef __cplusplus131} // extern "C"132#endif133134#endif135136137