6
6
7
7
#include < iomanip>
8
8
9
+ #include " src/base/build_config.h"
9
10
#include " src/base/iterator.h"
10
11
#include " src/base/macros.h"
11
12
#include " src/base/platform/platform.h"
21
22
#include " src/snapshot/embedded/embedded-data.h"
22
23
#include " src/utils/ostreams.h"
23
24
#include " src/utils/vector.h"
25
+ #include " src/wasm/code-space-access.h"
24
26
#include " src/wasm/compilation-environment.h"
25
27
#include " src/wasm/function-compiler.h"
26
28
#include " src/wasm/jump-table-assembler.h"
@@ -47,6 +49,10 @@ namespace wasm {
47
49
48
50
using trap_handler::ProtectedInstructionData;
49
51
52
+ #if defined(V8_OS_MACOSX) && defined(V8_HOST_ARCH_ARM64)
53
+ thread_local int CodeSpaceWriteScope::code_space_write_nesting_level_ = 0 ;
54
+ #endif
55
+
50
56
base::AddressRegion DisjointAllocationPool::Merge (
51
57
base::AddressRegion new_region) {
52
58
// Find the possible insertion position by identifying the first region whose
@@ -731,6 +737,7 @@ void WasmCodeAllocator::FreeCode(Vector<WasmCode* const> codes) {
731
737
// Zap code area and collect freed code regions.
732
738
DisjointAllocationPool freed_regions;
733
739
size_t code_size = 0 ;
740
+ CODE_SPACE_WRITE_SCOPE
734
741
for (WasmCode* code : codes) {
735
742
ZapCode (code->instruction_start (), code->instructions ().size ());
736
743
FlushInstructionCache (code->instruction_start (),
@@ -842,6 +849,7 @@ CompilationEnv NativeModule::CreateCompilationEnv() const {
842
849
}
843
850
844
851
WasmCode* NativeModule::AddCodeForTesting (Handle <Code> code) {
852
+ CODE_SPACE_WRITE_SCOPE
845
853
// For off-heap builtins, we create a copy of the off-heap instruction stream
846
854
// instead of the on-heap code object containing the trampoline. Ensure that
847
855
// we do not apply the on-heap reloc info to the off-heap instructions.
@@ -937,6 +945,7 @@ void NativeModule::UseLazyStub(uint32_t func_index) {
937
945
if (!lazy_compile_table_) {
938
946
uint32_t num_slots = module_->num_declared_functions ;
939
947
WasmCodeRefScope code_ref_scope;
948
+ CODE_SPACE_WRITE_SCOPE
940
949
base::AddressRegion single_code_space_region;
941
950
{
942
951
base::MutexGuard guard (&allocation_mutex_);
@@ -998,6 +1007,7 @@ std::unique_ptr<WasmCode> NativeModule::AddCodeWithCodeSpace(
998
1007
const int code_comments_offset = desc.code_comments_offset ;
999
1008
const int instr_size = desc.instr_size ;
1000
1009
1010
+ CODE_SPACE_WRITE_SCOPE
1001
1011
memcpy (dst_code_bytes.begin (), desc.buffer ,
1002
1012
static_cast <size_t >(desc.instr_size ));
1003
1013
@@ -1122,6 +1132,7 @@ WasmCode* NativeModule::AddDeserializedCode(
1122
1132
Vector<const byte> protected_instructions_data,
1123
1133
Vector<const byte> reloc_info, Vector<const byte> source_position_table,
1124
1134
WasmCode::Kind kind, ExecutionTier tier) {
1135
+ // CodeSpaceWriteScope is provided by the caller.
1125
1136
Vector<uint8_t > dst_code_bytes =
1126
1137
code_allocator_.AllocateForCode (this , instructions.size ());
1127
1138
memcpy (dst_code_bytes.begin (), instructions.begin (), instructions.size ());
@@ -1180,6 +1191,7 @@ WasmCode* NativeModule::CreateEmptyJumpTableInRegion(
1180
1191
Vector<uint8_t > code_space = code_allocator_.AllocateForCodeInRegion (
1181
1192
this , jump_table_size, region, allocator_lock);
1182
1193
DCHECK (!code_space.empty ());
1194
+ CODE_SPACE_WRITE_SCOPE
1183
1195
ZapCode (reinterpret_cast <Address>(code_space.begin ()), code_space.size ());
1184
1196
std::unique_ptr<WasmCode> code{
1185
1197
new WasmCode{this , // native_module
@@ -1205,6 +1217,7 @@ void NativeModule::PatchJumpTablesLocked(uint32_t slot_index, Address target) {
1205
1217
// The caller must hold the {allocation_mutex_}, thus we fail to lock it here.
1206
1218
DCHECK (!allocation_mutex_.TryLock ());
1207
1219
1220
+ CODE_SPACE_WRITE_SCOPE
1208
1221
for (auto & code_space_data : code_space_data_) {
1209
1222
DCHECK_IMPLIES (code_space_data.jump_table , code_space_data.far_jump_table );
1210
1223
if (!code_space_data.jump_table ) continue ;
@@ -1267,6 +1280,7 @@ void NativeModule::AddCodeSpace(
1267
1280
#endif // V8_OS_WIN64
1268
1281
1269
1282
WasmCodeRefScope code_ref_scope;
1283
+ CODE_SPACE_WRITE_SCOPE
1270
1284
WasmCode* jump_table = nullptr ;
1271
1285
WasmCode* far_jump_table = nullptr ;
1272
1286
const uint32_t num_wasm_functions = module_->num_declared_functions ;
@@ -1820,6 +1834,7 @@ std::vector<std::unique_ptr<WasmCode>> NativeModule::AddCompiledCode(
1820
1834
generated_code.reserve (results.size ());
1821
1835
1822
1836
// Now copy the generated code into the code space and relocate it.
1837
+ CODE_SPACE_WRITE_SCOPE
1823
1838
for (auto & result : results) {
1824
1839
DCHECK_EQ (result.code_desc .buffer , result.instr_buffer .get ());
1825
1840
size_t code_size = RoundUp<kCodeAlignment >(result.code_desc .instr_size );
0 commit comments