v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
memory.cc
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
6
7#include <cstddef>
8
10
11namespace cppgc {
12namespace internal {
13
14void NoSanitizeMemset(void* address, char c, size_t bytes) {
15 volatile uint8_t* const base = static_cast<uint8_t*>(address);
16 for (size_t i = 0; i < bytes; ++i) {
17 base[i] = c;
18 }
19}
20
21#if defined(V8_USE_MEMORY_SANITIZER) || defined(V8_USE_ADDRESS_SANITIZER) || \
22 DEBUG
23
24void SetMemoryAccessible(void* address, size_t size) {
25#if defined(V8_USE_MEMORY_SANITIZER)
26
27 MSAN_MEMORY_IS_INITIALIZED(address, size);
28
29#elif defined(V8_USE_ADDRESS_SANITIZER)
30
31 ASAN_UNPOISON_MEMORY_REGION(address, size);
32
33#else // Debug builds.
34
35 memset(address, 0, size);
36
37#endif // Debug builds.
38}
39
40void SetMemoryInaccessible(void* address, size_t size) {
41#if defined(V8_USE_MEMORY_SANITIZER)
42
43 memset(address, 0, size);
45
46#elif defined(V8_USE_ADDRESS_SANITIZER)
47
48 NoSanitizeMemset(address, 0, size);
49 ASAN_POISON_MEMORY_REGION(address, size);
50
51#else
52
53 ::cppgc::internal::ZapMemory(address, size);
54
55#endif // Debug builds.
56}
57
58void CheckMemoryIsInaccessible(const void* address, size_t size) {
59#if defined(V8_USE_MEMORY_SANITIZER)
60
61 static_assert(CheckMemoryIsInaccessibleIsNoop(),
62 "CheckMemoryIsInaccessibleIsNoop() needs to reflect "
63 "CheckMemoryIsInaccessible().");
64 // Unable to check that memory is marked as uninitialized by MSAN.
65
66#elif defined(V8_USE_ADDRESS_SANITIZER)
67
68 static_assert(!CheckMemoryIsInaccessibleIsNoop(),
69 "CheckMemoryIsInaccessibleIsNoop() needs to reflect "
70 "CheckMemoryIsInaccessible().");
71 // Only check if memory is poisoned on 64 bit, since there we make sure that
72 // object sizes and alignments are multiple of shadow memory granularity.
73#if defined(V8_HOST_ARCH_64_BIT)
75#endif
76 ASAN_UNPOISON_MEMORY_REGION(address, size);
77 CheckMemoryIsZero(address, size);
78 ASAN_POISON_MEMORY_REGION(address, size);
79
80#else // Debug builds.
81
82 static_assert(!CheckMemoryIsInaccessibleIsNoop(),
83 "CheckMemoryIsInaccessibleIsNoop() needs to reflect "
84 "CheckMemoryIsInaccessible().");
85 CheckMemoryIsZapped(address, size);
86
87#endif // Debug builds.
88}
89
90#endif
91
92} // namespace internal
93} // namespace cppgc
#define ASAN_UNPOISON_MEMORY_REGION(start, size)
Definition asan.h:71
#define ASAN_POISON_MEMORY_REGION(start, size)
Definition asan.h:64
#define ASAN_CHECK_WHOLE_MEMORY_REGION_IS_POISONED(start, size)
Definition asan.h:74
#define MSAN_MEMORY_IS_INITIALIZED(start, size)
Definition msan.h:37
#define MSAN_ALLOCATED_UNINITIALIZED_MEMORY(start, size)
Definition msan.h:29
V8_INLINE void CheckMemoryIsZero(const void *address, size_t size)
Definition memory.h:37
void NoSanitizeMemset(void *address, char c, size_t bytes)
Definition memory.cc:14
V8_INLINE void CheckMemoryIsInaccessible(const void *address, size_t size)
Definition memory.h:73
V8_INLINE void CheckMemoryIsZapped(const void *address, size_t size)
Definition memory.h:31
V8_INLINE void SetMemoryInaccessible(void *address, size_t size)
Definition memory.h:76
V8_INLINE void ZapMemory(void *address, size_t size)
Definition memory.h:25
V8_INLINE void SetMemoryAccessible(void *address, size_t size)
Definition memory.h:72
constexpr bool CheckMemoryIsInaccessibleIsNoop()
Definition memory.h:74