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
12
#include "
src/base/build_config.h
"
13
#include "
src/base/macros.h
"
14
#include "
src/common/code-memory-access.h
"
15
16
namespace
v8::internal::wasm
{
17
18
class
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.
43
class
V8_NODISCARD
CodeSpaceWriteScope
final {
44
public
:
45
explicit
V8_EXPORT_PRIVATE
CodeSpaceWriteScope
();
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.
49
CodeSpaceWriteScope
(
const
CodeSpaceWriteScope
&) =
delete
;
50
CodeSpaceWriteScope
&
operator=
(
const
CodeSpaceWriteScope
&) =
delete
;
51
52
private
:
53
RwxMemoryWriteScope
rwx_write_scope_
;
54
};
55
56
}
// namespace v8::internal::wasm
57
58
#endif
// V8_WASM_CODE_SPACE_ACCESS_H_
build_config.h
v8::internal::RwxMemoryWriteScope
Definition
code-memory-access.h:90
v8::internal::wasm::CodeSpaceWriteScope
Definition
code-space-access.h:43
v8::internal::wasm::CodeSpaceWriteScope::operator=
CodeSpaceWriteScope & operator=(const CodeSpaceWriteScope &)=delete
v8::internal::wasm::CodeSpaceWriteScope::rwx_write_scope_
RwxMemoryWriteScope rwx_write_scope_
Definition
code-space-access.h:53
v8::internal::wasm::CodeSpaceWriteScope::CodeSpaceWriteScope
CodeSpaceWriteScope(const CodeSpaceWriteScope &)=delete
code-memory-access.h
v8::internal::wasm
Definition
asm-parser.cc:24
macros.h
V8_EXPORT_PRIVATE
#define V8_EXPORT_PRIVATE
Definition
macros.h:460
V8_NODISCARD
#define V8_NODISCARD
Definition
v8config.h:693
src
wasm
code-space-access.h
Generated on Sun Apr 6 2025 21:08:58 for v8 by
1.12.0