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 (),
@@ -847,6 +854,7 @@ CompilationEnv NativeModule::CreateCompilationEnv() const {
847
854
}
848
855
849
856
WasmCode* NativeModule::AddCodeForTesting (Handle <Code> code) {
857
+ CODE_SPACE_WRITE_SCOPE
850
858
// For off-heap builtins, we create a copy of the off-heap instruction stream
851
859
// instead of the on-heap code object containing the trampoline. Ensure that
852
860
// we do not apply the on-heap reloc info to the off-heap instructions.
@@ -942,6 +950,7 @@ void NativeModule::UseLazyStub(uint32_t func_index) {
942
950
if (!lazy_compile_table_) {
943
951
uint32_t num_slots = module_->num_declared_functions ;
944
952
WasmCodeRefScope code_ref_scope;
953
+ CODE_SPACE_WRITE_SCOPE
945
954
base::AddressRegion single_code_space_region;
946
955
{
947
956
base::MutexGuard guard (&allocation_mutex_);
@@ -1003,6 +1012,7 @@ std::unique_ptr<WasmCode> NativeModule::AddCodeWithCodeSpace(
1003
1012
const int code_comments_offset = desc.code_comments_offset ;
1004
1013
const int instr_size = desc.instr_size ;
1005
1014
1015
+ CODE_SPACE_WRITE_SCOPE
1006
1016
memcpy (dst_code_bytes.begin (), desc.buffer ,
1007
1017
static_cast <size_t >(desc.instr_size ));
1008
1018
@@ -1138,6 +1148,7 @@ WasmCode* NativeModule::AddDeserializedCode(
1138
1148
Vector<const byte> protected_instructions_data,
1139
1149
Vector<const byte> reloc_info, Vector<const byte> source_position_table,
1140
1150
WasmCode::Kind kind, ExecutionTier tier) {
1151
+ // CodeSpaceWriteScope is provided by the caller.
1141
1152
Vector<uint8_t > dst_code_bytes =
1142
1153
code_allocator_.AllocateForCode (this , instructions.size ());
1143
1154
memcpy (dst_code_bytes.begin (), instructions.begin (), instructions.size ());
@@ -1196,6 +1207,7 @@ WasmCode* NativeModule::CreateEmptyJumpTableInRegion(
1196
1207
Vector<uint8_t > code_space = code_allocator_.AllocateForCodeInRegion (
1197
1208
this , jump_table_size, region, allocator_lock);
1198
1209
DCHECK (!code_space.empty ());
1210
+ CODE_SPACE_WRITE_SCOPE
1199
1211
ZapCode (reinterpret_cast <Address>(code_space.begin ()), code_space.size ());
1200
1212
std::unique_ptr<WasmCode> code{
1201
1213
new WasmCode{this , // native_module
@@ -1221,6 +1233,7 @@ void NativeModule::PatchJumpTablesLocked(uint32_t slot_index, Address target) {
1221
1233
// The caller must hold the {allocation_mutex_}, thus we fail to lock it here.
1222
1234
DCHECK (!allocation_mutex_.TryLock ());
1223
1235
1236
+ CODE_SPACE_WRITE_SCOPE
1224
1237
for (auto & code_space_data : code_space_data_) {
1225
1238
DCHECK_IMPLIES (code_space_data.jump_table , code_space_data.far_jump_table );
1226
1239
if (!code_space_data.jump_table ) continue ;
@@ -1283,6 +1296,7 @@ void NativeModule::AddCodeSpace(
1283
1296
#endif // V8_OS_WIN64
1284
1297
1285
1298
WasmCodeRefScope code_ref_scope;
1299
+ CODE_SPACE_WRITE_SCOPE
1286
1300
WasmCode* jump_table = nullptr ;
1287
1301
WasmCode* far_jump_table = nullptr ;
1288
1302
const uint32_t num_wasm_functions = module_->num_declared_functions ;
@@ -1843,6 +1857,7 @@ std::vector<std::unique_ptr<WasmCode>> NativeModule::AddCompiledCode(
1843
1857
generated_code.reserve (results.size ());
1844
1858
1845
1859
// Now copy the generated code into the code space and relocate it.
1860
+ CODE_SPACE_WRITE_SCOPE
1846
1861
for (auto & result : results) {
1847
1862
DCHECK_EQ (result.code_desc .buffer , result.instr_buffer .get ());
1848
1863
size_t code_size = RoundUp<kCodeAlignment >(result.code_desc .instr_size );
0 commit comments