xref: /freebsd/contrib/llvm-project/compiler-rt/lib/msan/msan_poisoning.h (revision 0b57cec536236d46e3dba9bd041533462f33dbb7)
1*0b57cec5SDimitry Andric //===-- msan_poisoning.h ----------------------------------------*- C++ -*-===//
2*0b57cec5SDimitry Andric //
3*0b57cec5SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*0b57cec5SDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
5*0b57cec5SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*0b57cec5SDimitry Andric //
7*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
8*0b57cec5SDimitry Andric //
9*0b57cec5SDimitry Andric // This file is a part of MemorySanitizer.
10*0b57cec5SDimitry Andric //
11*0b57cec5SDimitry Andric //===----------------------------------------------------------------------===//
12*0b57cec5SDimitry Andric 
13*0b57cec5SDimitry Andric #ifndef MSAN_POISONING_H
14*0b57cec5SDimitry Andric #define MSAN_POISONING_H
15*0b57cec5SDimitry Andric 
16*0b57cec5SDimitry Andric #include "msan.h"
17*0b57cec5SDimitry Andric 
18*0b57cec5SDimitry Andric namespace __msan {
19*0b57cec5SDimitry Andric 
20*0b57cec5SDimitry Andric // Return origin for the first poisoned byte in the memory range, or 0.
21*0b57cec5SDimitry Andric u32 GetOriginIfPoisoned(uptr addr, uptr size);
22*0b57cec5SDimitry Andric 
23*0b57cec5SDimitry Andric // Walk [addr, addr+size) app memory region, copying origin tags from the
24*0b57cec5SDimitry Andric // corresponding positions in [src_origin, src_origin+size) where the
25*0b57cec5SDimitry Andric // corresponding shadow in [src_shadow, src_shadow+size) is non-zero.
26*0b57cec5SDimitry Andric void SetOriginIfPoisoned(uptr addr, uptr src_shadow, uptr size, u32 src_origin);
27*0b57cec5SDimitry Andric 
28*0b57cec5SDimitry Andric // Copy origin from src (app address) to dst (app address), creating chained
29*0b57cec5SDimitry Andric // origin ids as necessary, without overriding origin for fully initialized
30*0b57cec5SDimitry Andric // quads.
31*0b57cec5SDimitry Andric void CopyOrigin(const void *dst, const void *src, uptr size, StackTrace *stack);
32*0b57cec5SDimitry Andric 
33*0b57cec5SDimitry Andric // memmove() shadow and origin. Dst and src are application addresses.
34*0b57cec5SDimitry Andric // See CopyOrigin() for the origin copying logic.
35*0b57cec5SDimitry Andric void MoveShadowAndOrigin(const void *dst, const void *src, uptr size,
36*0b57cec5SDimitry Andric                          StackTrace *stack);
37*0b57cec5SDimitry Andric 
38*0b57cec5SDimitry Andric // memcpy() shadow and origin. Dst and src are application addresses.
39*0b57cec5SDimitry Andric // See CopyOrigin() for the origin copying logic.
40*0b57cec5SDimitry Andric void CopyShadowAndOrigin(const void *dst, const void *src, uptr size,
41*0b57cec5SDimitry Andric                          StackTrace *stack);
42*0b57cec5SDimitry Andric 
43*0b57cec5SDimitry Andric // memcpy() app memory, and do "the right thing" to the corresponding shadow and
44*0b57cec5SDimitry Andric // origin regions.
45*0b57cec5SDimitry Andric void CopyMemory(void *dst, const void *src, uptr size, StackTrace *stack);
46*0b57cec5SDimitry Andric 
47*0b57cec5SDimitry Andric // Fill shadow will value. Ptr is an application address.
48*0b57cec5SDimitry Andric void SetShadow(const void *ptr, uptr size, u8 value);
49*0b57cec5SDimitry Andric 
50*0b57cec5SDimitry Andric // Set origin for the memory region.
51*0b57cec5SDimitry Andric void SetOrigin(const void *dst, uptr size, u32 origin);
52*0b57cec5SDimitry Andric 
53*0b57cec5SDimitry Andric // Mark memory region uninitialized, with origins.
54*0b57cec5SDimitry Andric void PoisonMemory(const void *dst, uptr size, StackTrace *stack);
55*0b57cec5SDimitry Andric 
56*0b57cec5SDimitry Andric }  // namespace __msan
57*0b57cec5SDimitry Andric 
58*0b57cec5SDimitry Andric #endif  // MSAN_POISONING_H
59