v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
code-space-access.h
Go to the documentation of this file.
1// Copyright 2020 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_WASM_CODE_SPACE_ACCESS_H_
6#define V8_WASM_CODE_SPACE_ACCESS_H_
7
8#if !V8_ENABLE_WEBASSEMBLY
9#error This header should only be included if WebAssembly is enabled.
10#endif // !V8_ENABLE_WEBASSEMBLY
11
13#include "src/base/macros.h"
15
16namespace v8::internal::wasm {
17
18class NativeModule;
19
20// Within the scope, the code space is writable (and for Apple M1 also not
21// executable). After the last (nested) scope is destructed, the code space is
22// not writable.
23// This uses three different implementations, depending on the platform, flags,
24// and runtime support:
25// - On MacOS on ARM64 ("Apple M1"/Apple Silicon), it uses APRR/MAP_JIT to
26// switch only the calling thread between writable and executable. This achieves
27// "real" W^X and is thread-local and fast.
28// - When Intel PKU (aka. memory protection keys) are available, it switches
29// the protection keys' permission between writable and not writable. The
30// executable permission cannot be retracted with PKU. That is, this "only"
31// achieves write-protection, but is similarly thread-local and fast.
32// - As a fallback, we switch with {mprotect()} between R-X and RWX (due to
33// concurrent compilation and execution). This is slow and process-wide. With
34// {mprotect()}, we currently switch permissions for the entire module's memory:
35// - for AOT, that's as efficient as it can be.
36// - for Lazy, we don't have a heuristic for functions that may need patching,
37// and even if we did, the resulting set of pages may be fragmented.
38// Currently, we try and keep the number of syscalls low.
39// - similar argument for debug time.
40// MAP_JIT on Apple M1 cannot switch permissions for smaller ranges of memory,
41// and for PKU we would need multiple keys, so both of them also switch
42// permissions for all code pages.
44 public:
46
47 // Disable copy constructor and copy-assignment operator, since this manages
48 // a resource and implicit copying of the scope can yield surprising errors.
51
52 private:
54};
55
56} // namespace v8::internal::wasm
57
58#endif // V8_WASM_CODE_SPACE_ACCESS_H_
CodeSpaceWriteScope & operator=(const CodeSpaceWriteScope &)=delete
CodeSpaceWriteScope(const CodeSpaceWriteScope &)=delete
#define V8_EXPORT_PRIVATE
Definition macros.h:460
#define V8_NODISCARD
Definition v8config.h:693