forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmemory.h
More file actions
85 lines (60 loc) Β· 2.26 KB
/
memory.h
File metadata and controls
85 lines (60 loc) Β· 2.26 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
// 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.
#ifndef V8_HEAP_CPPGC_MEMORY_H_
#define V8_HEAP_CPPGC_MEMORY_H_
#include <cstddef>
#include <cstdint>
#include <cstring>
#include "src/base/macros.h"
#include "src/base/sanitizer/asan.h"
#include "src/base/sanitizer/msan.h"
#include "src/heap/cppgc/globals.h"
namespace cppgc {
namespace internal {
V8_NOINLINE DISABLE_ASAN void NoSanitizeMemset(void* address, char c,
size_t bytes);
static constexpr uint8_t kZappedValue = 0xdc;
V8_INLINE void ZapMemory(void* address, size_t size) {
// The lowest bit of the zapped value should be 0 so that zapped object are
// never viewed as fully constructed objects.
memset(address, kZappedValue, size);
}
V8_INLINE void CheckMemoryIsZapped(const void* address, size_t size) {
for (size_t i = 0; i < size; i++) {
CHECK_EQ(kZappedValue, reinterpret_cast<ConstAddress>(address)[i]);
}
}
V8_INLINE void CheckMemoryIsZero(const void* address, size_t size) {
for (size_t i = 0; i < size; i++) {
CHECK_EQ(0, reinterpret_cast<ConstAddress>(address)[i]);
}
}
// Together `SetMemoryAccessible()` and `SetMemoryInaccessible()` form the
// memory access model for allocation and free.
#if defined(V8_USE_MEMORY_SANITIZER) || defined(V8_USE_ADDRESS_SANITIZER) || \
DEBUG
void SetMemoryAccessible(void* address, size_t size);
void SetMemoryInaccessible(void* address, size_t size);
void CheckMemoryIsInaccessible(const void* address, size_t size);
constexpr bool CheckMemoryIsInaccessibleIsNoop() {
#if defined(V8_USE_MEMORY_SANITIZER)
return true;
#elif defined(V8_USE_ADDRESS_SANITIZER)
return false;
#else // Debug builds.
return false;
#endif // Debug builds.
}
#else
// Nothing to be done for release builds.
V8_INLINE void SetMemoryAccessible(void* address, size_t size) {}
V8_INLINE void CheckMemoryIsInaccessible(const void* address, size_t size) {}
constexpr bool CheckMemoryIsInaccessibleIsNoop() { return true; }
V8_INLINE void SetMemoryInaccessible(void* address, size_t size) {
memset(address, 0, size);
}
#endif
} // namespace internal
} // namespace cppgc
#endif // V8_HEAP_CPPGC_MEMORY_H_