v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
hardware-support.h
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
5#ifndef V8_SANDBOX_HARDWARE_SUPPORT_H_
6#define V8_SANDBOX_HARDWARE_SUPPORT_H_
7
10
11namespace v8 {
12namespace internal {
13
15 public:
16 // Allocates a pkey that will be used to optionally block sandbox access. This
17 // function should be called once before any threads are created so that new
18 // threads inherit access to the new pkey.
19 static void InitializeBeforeThreadCreation();
20
21 // Try to set up hardware permissions to the sandbox address space. If
22 // successful, future calls to MaybeBlockAccess will block the current thread
23 // from accessing the memory.
24 static bool TryEnable(Address addr, size_t size);
25
27 public:
28#if V8_ENABLE_SANDBOX_HARDWARE_SUPPORT
29 explicit BlockAccessScope(int pkey);
31
32 private:
33 int pkey_;
34#else
35 BlockAccessScope() = default;
36#endif
37 };
38
39 // If V8_ENABLE_SANDBOX_HARDWARE_SUPPORT is enabled, this function will
40 // prevent any access (read or write) to all sandbox memory on the current
41 // thread, as long as the returned Scope object is valid. The only exception
42 // are read-only pages, which will still be readable.
43 static BlockAccessScope MaybeBlockAccess();
44
45 // Removes the pkey from read only pages, so that MaybeBlockAccess will still
46 // allow read access.
47 static void NotifyReadOnlyPageCreated(
48 Address addr, size_t size, PageAllocator::Permission current_permissions);
49
50 // This function should only be called by
51 // `ThreadIsolatedAllocator::SetDefaultPermissionsForSignalHandler`.
52 static void SetDefaultPermissionsForSignalHandler();
53
54 private:
55#if V8_ENABLE_SANDBOX_HARDWARE_SUPPORT
56 static int pkey_;
57#endif
58};
59
60} // namespace internal
61} // namespace v8
62
63#endif // V8_SANDBOX_HARDWARE_SUPPORT_H_
#define V8_ALLOW_UNUSED
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_NODISCARD
Definition v8config.h:693