Skip to content

Commit 7a243d6

Browse files
Bertrand PreslesBertrand Presles
authored andcommitted
Backported PR nodejs#35986
1 parent f5c706e commit 7a243d6

14 files changed

+137
-10
lines changed

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
# Reset this number to 0 on major V8 upgrades.
3636
# Increment by one for each non-official patch applied to deps/v8.
37-
'v8_embedder_string': '-node.45',
37+
'v8_embedder_string': '-node.49 ',
3838

3939
##### V8 defaults for Node.js #####
4040

deps/v8/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2907,6 +2907,7 @@ v8_source_set("v8_base_without_compiler") {
29072907
"src/wasm/baseline/liftoff-compiler.cc",
29082908
"src/wasm/baseline/liftoff-compiler.h",
29092909
"src/wasm/baseline/liftoff-register.h",
2910+
"src/wasm/code-space-access.h",
29102911
"src/wasm/compilation-environment.h",
29112912
"src/wasm/decoder.h",
29122913
"src/wasm/function-body-decoder-impl.h",

deps/v8/include/v8-platform.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,13 @@ class PageAllocator {
240240
kReadWrite,
241241
// TODO(hpayer): Remove this flag. Memory should never be rwx.
242242
kReadWriteExecute,
243-
kReadExecute
243+
kReadExecute,
244+
// Set this when reserving memory that will later require kReadWriteExecute
245+
// permissions. The resulting behavior is platform-specific, currently
246+
// this is used to set the MAP_JIT flag on Apple Silicon.
247+
// TODO(jkummerow): Remove this when Wasm has a platform-independent
248+
// w^x implementation.
249+
kNoAccessWillJitLater
244250
};
245251

246252
/**

deps/v8/src/base/page-allocator.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
#include "src/base/platform/platform.h"
88

9+
#if V8_OS_MACOSX
10+
#include <sys/mman.h> // For MAP_JIT.
11+
#endif
12+
913
namespace v8 {
1014
namespace base {
1115

@@ -21,6 +25,8 @@ STATIC_ASSERT_ENUM(PageAllocator::kReadWriteExecute,
2125
base::OS::MemoryPermission::kReadWriteExecute);
2226
STATIC_ASSERT_ENUM(PageAllocator::kReadExecute,
2327
base::OS::MemoryPermission::kReadExecute);
28+
STATIC_ASSERT_ENUM(PageAllocator::kNoAccessWillJitLater,
29+
base::OS::MemoryPermission::kNoAccessWillJitLater);
2430

2531
#undef STATIC_ASSERT_ENUM
2632

@@ -38,6 +44,14 @@ void* PageAllocator::GetRandomMmapAddr() {
3844

3945
void* PageAllocator::AllocatePages(void* hint, size_t size, size_t alignment,
4046
PageAllocator::Permission access) {
47+
#if !(V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT))
48+
// kNoAccessWillJitLater is only used on Apple Silicon. Map it to regular
49+
// kNoAccess on other platforms, so code doesn't have to handle both enum
50+
// values.
51+
if (access == PageAllocator::kNoAccessWillJitLater) {
52+
access = PageAllocator::kNoAccess;
53+
}
54+
#endif
4155
return base::OS::Allocate(hint, size, alignment,
4256
static_cast<base::OS::MemoryPermission>(access));
4357
}

deps/v8/src/base/platform/platform-cygwin.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ namespace {
3333
DWORD GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
3434
switch (access) {
3535
case OS::MemoryPermission::kNoAccess:
36+
case OS::MemoryPermission::kNoAccessWillJitLater:
3637
return PAGE_NOACCESS;
3738
case OS::MemoryPermission::kRead:
3839
return PAGE_READONLY;

deps/v8/src/base/platform/platform-fuchsia.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace {
1818
uint32_t GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
1919
switch (access) {
2020
case OS::MemoryPermission::kNoAccess:
21+
case OS::MemoryPermission::kNoAccessWillJitLater:
2122
return 0; // no permissions
2223
case OS::MemoryPermission::kRead:
2324
return ZX_VM_PERM_READ;

deps/v8/src/base/platform/platform-posix.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ const int kMmapFdOffset = 0;
111111
int GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
112112
switch (access) {
113113
case OS::MemoryPermission::kNoAccess:
114+
case OS::MemoryPermission::kNoAccessWillJitLater:
114115
return PROT_NONE;
115116
case OS::MemoryPermission::kRead:
116117
return PROT_READ;
@@ -134,6 +135,11 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access) {
134135
flags |= MAP_LAZY;
135136
#endif // V8_OS_QNX
136137
}
138+
#if V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT)
139+
if (access == OS::MemoryPermission::kNoAccessWillJitLater) {
140+
flags |= MAP_JIT;
141+
}
142+
#endif
137143
return flags;
138144
}
139145

deps/v8/src/base/platform/platform-win32.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -753,6 +753,7 @@ namespace {
753753
DWORD GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
754754
switch (access) {
755755
case OS::MemoryPermission::kNoAccess:
756+
case OS::MemoryPermission::kNoAccessWillJitLater:
756757
return PAGE_NOACCESS;
757758
case OS::MemoryPermission::kRead:
758759
return PAGE_READONLY;

deps/v8/src/base/platform/platform.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,10 @@ class V8_BASE_EXPORT OS {
163163
kReadWrite,
164164
// TODO(hpayer): Remove this flag. Memory should never be rwx.
165165
kReadWriteExecute,
166-
kReadExecute
166+
kReadExecute,
167+
// TODO(jkummerow): Remove this when Wasm has a platform-independent
168+
// w^x implementation.
169+
kNoAccessWillJitLater
167170
};
168171

169172
static bool HasLazyCommits();

deps/v8/src/utils/allocation.cc

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,15 +207,17 @@ bool OnCriticalMemoryPressure(size_t length) {
207207
}
208208

209209
VirtualMemory::VirtualMemory(v8::PageAllocator* page_allocator, size_t size,
210-
void* hint, size_t alignment)
210+
void* hint, size_t alignment, JitPermission jit)
211211
: page_allocator_(page_allocator) {
212212
DCHECK_NOT_NULL(page_allocator);
213213
DCHECK(IsAligned(size, page_allocator_->CommitPageSize()));
214214
size_t page_size = page_allocator_->AllocatePageSize();
215215
alignment = RoundUp(alignment, page_size);
216-
Address address = reinterpret_cast<Address>(
217-
AllocatePages(page_allocator_, hint, RoundUp(size, page_size), alignment,
218-
PageAllocator::kNoAccess));
216+
PageAllocator::Permission permissions =
217+
jit == kMapAsJittable ? PageAllocator::kNoAccessWillJitLater
218+
: PageAllocator::kNoAccess;
219+
Address address = reinterpret_cast<Address>(AllocatePages(
220+
page_allocator_, hint, RoundUp(size, page_size), alignment, permissions));
219221
if (address != kNullAddress) {
220222
DCHECK(IsAligned(address, alignment));
221223
region_ = base::AddressRegion(address, size);

0 commit comments

Comments
 (0)