v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
hardware-support.cc
Go to the documentation of this file.
1// Copyright 2024 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#if V8_ENABLE_SANDBOX_HARDWARE_SUPPORT
9#endif
10
11namespace v8 {
12namespace internal {
13
14#if V8_ENABLE_SANDBOX_HARDWARE_SUPPORT
15
16int SandboxHardwareSupport::pkey_ =
17 base::MemoryProtectionKey::kNoMemoryProtectionKey;
18
19// static
20bool SandboxHardwareSupport::TryEnable(Address addr, size_t size) {
21 if (pkey_ != base::MemoryProtectionKey::kNoMemoryProtectionKey) {
22 return base::MemoryProtectionKey::SetPermissionsAndKey(
23 {addr, size}, v8::PageAllocator::Permission::kNoAccess, pkey_);
24 }
25 return false;
26}
27
28// static
30 DCHECK_EQ(pkey_, base::MemoryProtectionKey::kNoMemoryProtectionKey);
31 pkey_ = base::MemoryProtectionKey::AllocateKey();
32}
33
34// static
36 if (pkey_ != base::MemoryProtectionKey::kNoMemoryProtectionKey) {
37 base::MemoryProtectionKey::SetPermissionsForKey(
38 pkey_, base::MemoryProtectionKey::Permission::kNoRestrictions);
39 }
40}
41
42// static
44 Address addr, size_t size, PageAllocator::Permission perm) {
45 if (pkey_ != base::MemoryProtectionKey::kNoMemoryProtectionKey) {
46 // Reset the pkey of the read-only page to the default pkey, since some
47 // SBXCHECKs will safely read read-only data from the heap.
48 base::MemoryProtectionKey::SetPermissionsAndKey(
49 {addr, size}, perm, base::MemoryProtectionKey::kDefaultProtectionKey);
50 }
51}
52
53// static
54SandboxHardwareSupport::BlockAccessScope
56 return BlockAccessScope(pkey_);
57}
58
60 : pkey_(pkey) {
61 if (pkey_ != base::MemoryProtectionKey::kNoMemoryProtectionKey) {
62 base::MemoryProtectionKey::SetPermissionsForKey(
63 pkey_, base::MemoryProtectionKey::Permission::kDisableAccess);
64 }
65}
66
67SandboxHardwareSupport::BlockAccessScope::~BlockAccessScope() {
68 if (pkey_ != base::MemoryProtectionKey::kNoMemoryProtectionKey) {
69 base::MemoryProtectionKey::SetPermissionsForKey(
70 pkey_, base::MemoryProtectionKey::Permission::kNoRestrictions);
71 }
72}
73
74#else // V8_ENABLE_SANDBOX_HARDWARE_SUPPORT
75
76// static
77bool SandboxHardwareSupport::TryEnable(Address addr, size_t size) {
78 return false;
79}
80
81// static
82void SandboxHardwareSupport::InitializeBeforeThreadCreation() {}
83
84// static
85void SandboxHardwareSupport::SetDefaultPermissionsForSignalHandler() {}
86
87// static
88void SandboxHardwareSupport::NotifyReadOnlyPageCreated(
89 Address addr, size_t size, PageAllocator::Permission perm) {}
90
91// static
93SandboxHardwareSupport::MaybeBlockAccess() {
94 return BlockAccessScope();
95}
96
97#endif
98
99} // namespace internal
100} // namespace v8
static void NotifyReadOnlyPageCreated(Address addr, size_t size, PageAllocator::Permission current_permissions)
static bool TryEnable(Address addr, size_t size)
static BlockAccessScope MaybeBlockAccess()
#define DCHECK_EQ(v1, v2)
Definition logging.h:485