aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/poison.h
blob: cdd7eb557a0e0464d46c008210e81f21b163e378 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#pragma once

#include "ref.h"

namespace NYT {

////////////////////////////////////////////////////////////////////////////////

//! Poisons an uninitialized slice of memory.
/*
 * In release builds, does nothing.
 * In checked builds, clobbers memory with a garbage pattern.
 * In ASAN builds, does nothing.
 * In MSAN builds, invokes sanitizer poisoning to catch uninit-read.
 */
void PoisonUninitializedMemory(TMutableRef ref);

//! Poisons a freed slice of memory.
/*
 * In release builds, does nothing.
 * In checked builds, clobbers memory with a garbage pattern.
 * In ASAN and MSAN builds, invokes sanitizer poisoning to catch use-after-free.
 */
void PoisonFreedMemory(TMutableRef ref);

//! Indicates that a slice of memory that was previously given to #PoisonFreedMemory
//! has been recycled and can be reused.
/*!
 * In release builds, does nothing.
 * In checked builds, clobbers memory with a garbage pattern.
 * In ASAN builds, invokes sanitizer unpoisoning.
 * In MSAN builds, does nothing (the memory remains poisoned to catch uninit-read).
 */
void RecycleFreedMemory(TMutableRef ref);

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT

#define POISON_INL_H_
#include "poison-inl.h"
#undef POISON_INL_H_