forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.cc
More file actions
93 lines (64 loc) Β· 2.47 KB
/
memory.cc
File metadata and controls
93 lines (64 loc) Β· 2.47 KB
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
// Copyright 2021 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/heap/cppgc/memory.h"
#include <cstddef>
#include "src/heap/cppgc/globals.h"
namespace cppgc {
namespace internal {
void NoSanitizeMemset(void* address, char c, size_t bytes) {
volatile uint8_t* const base = static_cast<uint8_t*>(address);
for (size_t i = 0; i < bytes; ++i) {
base[i] = c;
}
}
#if defined(V8_USE_MEMORY_SANITIZER) || defined(V8_USE_ADDRESS_SANITIZER) || \
DEBUG
void SetMemoryAccessible(void* address, size_t size) {
#if defined(V8_USE_MEMORY_SANITIZER)
MSAN_MEMORY_IS_INITIALIZED(address, size);
#elif defined(V8_USE_ADDRESS_SANITIZER)
ASAN_UNPOISON_MEMORY_REGION(address, size);
#else // Debug builds.
memset(address, 0, size);
#endif // Debug builds.
}
void SetMemoryInaccessible(void* address, size_t size) {
#if defined(V8_USE_MEMORY_SANITIZER)
memset(address, 0, size);
MSAN_ALLOCATED_UNINITIALIZED_MEMORY(address, size);
#elif defined(V8_USE_ADDRESS_SANITIZER)
NoSanitizeMemset(address, 0, size);
ASAN_POISON_MEMORY_REGION(address, size);
#else
::cppgc::internal::ZapMemory(address, size);
#endif // Debug builds.
}
void CheckMemoryIsInaccessible(const void* address, size_t size) {
#if defined(V8_USE_MEMORY_SANITIZER)
static_assert(CheckMemoryIsInaccessibleIsNoop(),
"CheckMemoryIsInaccessibleIsNoop() needs to reflect "
"CheckMemoryIsInaccessible().");
// Unable to check that memory is marked as uninitialized by MSAN.
#elif defined(V8_USE_ADDRESS_SANITIZER)
static_assert(!CheckMemoryIsInaccessibleIsNoop(),
"CheckMemoryIsInaccessibleIsNoop() needs to reflect "
"CheckMemoryIsInaccessible().");
// Only check if memory is poisoned on 64 bit, since there we make sure that
// object sizes and alignments are multiple of shadow memory granularity.
#if defined(V8_HOST_ARCH_64_BIT)
ASAN_CHECK_WHOLE_MEMORY_REGION_IS_POISONED(address, size);
#endif
ASAN_UNPOISON_MEMORY_REGION(address, size);
CheckMemoryIsZero(address, size);
ASAN_POISON_MEMORY_REGION(address, size);
#else // Debug builds.
static_assert(!CheckMemoryIsInaccessibleIsNoop(),
"CheckMemoryIsInaccessibleIsNoop() needs to reflect "
"CheckMemoryIsInaccessible().");
CheckMemoryIsZapped(address, size);
#endif // Debug builds.
}
#endif
} // namespace internal
} // namespace cppgc