1278497Sdim//===-- msan_poisoning.h ----------------------------------------*- C++ -*-===//
2278497Sdim//
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
6278497Sdim//
7278497Sdim//===----------------------------------------------------------------------===//
8278497Sdim//
9278497Sdim// This file is a part of MemorySanitizer.
10278497Sdim//
11278497Sdim//===----------------------------------------------------------------------===//
12278497Sdim
13278497Sdim#ifndef MSAN_POISONING_H
14278497Sdim#define MSAN_POISONING_H
15278497Sdim
16278497Sdim#include "msan.h"
17278497Sdim
18278497Sdimnamespace __msan {
19278497Sdim
20278497Sdim// Return origin for the first poisoned byte in the memory range, or 0.
21278497Sdimu32 GetOriginIfPoisoned(uptr addr, uptr size);
22278497Sdim
23278497Sdim// Walk [addr, addr+size) app memory region, copying origin tags from the
24278497Sdim// corresponding positions in [src_origin, src_origin+size) where the
25278497Sdim// corresponding shadow in [src_shadow, src_shadow+size) is non-zero.
26278497Sdimvoid SetOriginIfPoisoned(uptr addr, uptr src_shadow, uptr size, u32 src_origin);
27278497Sdim
28278497Sdim// Copy origin from src (app address) to dst (app address), creating chained
29278497Sdim// origin ids as necessary, without overriding origin for fully initialized
30278497Sdim// quads.
31278497Sdimvoid CopyOrigin(const void *dst, const void *src, uptr size, StackTrace *stack);
32278497Sdim
33278497Sdim// memmove() shadow and origin. Dst and src are application addresses.
34278497Sdim// See CopyOrigin() for the origin copying logic.
35278497Sdimvoid MoveShadowAndOrigin(const void *dst, const void *src, uptr size,
36278497Sdim                         StackTrace *stack);
37278497Sdim
38278497Sdim// memcpy() shadow and origin. Dst and src are application addresses.
39278497Sdim// See CopyOrigin() for the origin copying logic.
40278497Sdimvoid CopyShadowAndOrigin(const void *dst, const void *src, uptr size,
41278497Sdim                         StackTrace *stack);
42278497Sdim
43278497Sdim// memcpy() app memory, and do "the right thing" to the corresponding shadow and
44278497Sdim// origin regions.
45278497Sdimvoid CopyMemory(void *dst, const void *src, uptr size, StackTrace *stack);
46278497Sdim
47278497Sdim// Fill shadow will value. Ptr is an application address.
48278497Sdimvoid SetShadow(const void *ptr, uptr size, u8 value);
49278497Sdim
50278497Sdim// Set origin for the memory region.
51278497Sdimvoid SetOrigin(const void *dst, uptr size, u32 origin);
52278497Sdim
53278497Sdim// Mark memory region uninitialized, with origins.
54278497Sdimvoid PoisonMemory(const void *dst, uptr size, StackTrace *stack);
55278497Sdim
56278497Sdim}  // namespace __msan
57278497Sdim
58278497Sdim#endif  // MSAN_POISONING_H
59