aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/memory/poison-inl.h
blob: 1625de0484702b0b3aaa3bc9f1ec66c45831efb6 (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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#pragma once
#ifndef POISON_INL_H_
#error "Direct inclusion of this file is not allowed, include poison.h"
// For the sake of sane code completion.
#include "poison.h"
#endif

#include <util/system/compiler.h>

namespace NYT {

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

#if defined(_asan_enabled_)

extern "C" {
void __asan_poison_memory_region(void const volatile *addr, size_t size);
void __asan_unpoison_memory_region(void const volatile *addr, size_t size);
} // extern "C"

Y_FORCE_INLINE void PoisonUninitializedMemory(TMutableRef /*ref*/)
{ }

Y_FORCE_INLINE void PoisonFreedMemory(TMutableRef ref)
{
    __asan_poison_memory_region(ref.data(), ref.size());
}

Y_FORCE_INLINE void RecycleFreedMemory(TMutableRef ref)
{
    __asan_unpoison_memory_region(ref.data(), ref.size());
}

#elif defined(_msan_enabled_)

extern "C" {
void __msan_poison(const volatile void* a, size_t size);
} // extern "C"

Y_FORCE_INLINE void PoisonUninitializedMemory(TMutableRef ref)
{
    __msan_poison(ref.data(), ref.size());
}

Y_FORCE_INLINE void PoisonFreedMemory(TMutableRef ref)
{
    __msan_poison(ref.data(), ref.size());
}

Y_FORCE_INLINE void RecycleFreedMemory(TMutableRef /*ref*/)
{ }

#elif defined(NDEBUG)

Y_FORCE_INLINE void PoisonUninitializedMemory(TMutableRef /*ref*/)
{ }

Y_FORCE_INLINE void PoisonFreedMemory(TMutableRef /*ref*/)
{ }

Y_FORCE_INLINE void RecycleFreedMemory(TMutableRef /*ref*/)
{ }

#endif

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

} // namespace NYT