Skip to content

Commit d37ddb4

Browse files
oleavrnodejs-github-bot
authored andcommitted
deps: V8: cherry-pick 4e077ff0444a
Original commit message: [mac] Set MAP_JIT only when necessary This is a "minimal" change to achieve the required goal: seeing that there is only one place where we need to indicate that memory should be reserved with MAP_JIT, we can add a value to the Permissions enum instead of adding a second, orthogonal parameter. That way we avoid changing public API functions, which makes this CL easier to undo once we have platform-independent w^x in Wasm. Bug: chromium:1117591 Change-Id: I6333d69ab29d5900c689f08dcc892a5f1c1159b8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2435365 Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Reviewed-by: Clemens Backes <clemensb@chromium.org> Cr-Commit-Position: refs/heads/master@{#70379} PR-URL: nodejs#35986 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Beth Griggs <bgriggs@redhat.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
1 parent 1337a34 commit d37ddb4

11 files changed

+39
-16
lines changed

common.gypi

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737
# Reset this number to 0 on major V8 upgrades.
3838
# Increment by one for each non-official patch applied to deps/v8.
39-
'v8_embedder_string': '-node.19',
39+
'v8_embedder_string': '-node.20',
4040

4141
##### V8 defaults for Node.js #####
4242

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

+10
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ STATIC_ASSERT_ENUM(PageAllocator::kReadWriteExecute,
2121
base::OS::MemoryPermission::kReadWriteExecute);
2222
STATIC_ASSERT_ENUM(PageAllocator::kReadExecute,
2323
base::OS::MemoryPermission::kReadExecute);
24+
STATIC_ASSERT_ENUM(PageAllocator::kNoAccessWillJitLater,
25+
base::OS::MemoryPermission::kNoAccessWillJitLater);
2426

2527
#undef STATIC_ASSERT_ENUM
2628

@@ -38,6 +40,14 @@ void* PageAllocator::GetRandomMmapAddr() {
3840

3941
void* PageAllocator::AllocatePages(void* hint, size_t size, size_t alignment,
4042
PageAllocator::Permission access) {
43+
#if !(V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT))
44+
// kNoAccessWillJitLater is only used on Apple Silicon. Map it to regular
45+
// kNoAccess on other platforms, so code doesn't have to handle both enum
46+
// values.
47+
if (access == PageAllocator::kNoAccessWillJitLater) {
48+
access = PageAllocator::kNoAccess;
49+
}
50+
#endif
4151
return base::OS::Allocate(hint, size, alignment,
4252
static_cast<base::OS::MemoryPermission>(access));
4353
}

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

+1
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

+1
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

+5-7
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ const int kMmapFdOffset = 0;
125125
int GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
126126
switch (access) {
127127
case OS::MemoryPermission::kNoAccess:
128+
case OS::MemoryPermission::kNoAccessWillJitLater:
128129
return PROT_NONE;
129130
case OS::MemoryPermission::kRead:
130131
return PROT_READ;
@@ -151,15 +152,12 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access,
151152
#if V8_OS_QNX
152153
flags |= MAP_LAZY;
153154
#endif // V8_OS_QNX
154-
#if V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT) && \
155-
!defined(V8_OS_IOS)
156-
// TODO(jkummerow): using the V8_OS_IOS define is a crude approximation
157-
// of the fact that we don't want to set the MAP_JIT flag when
158-
// FLAG_jitless == true, as src/base/ doesn't know any flags.
159-
// TODO(crbug.com/1117591): This is only needed for code spaces.
155+
}
156+
#if V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT)
157+
if (access == OS::MemoryPermission::kNoAccessWillJitLater) {
160158
flags |= MAP_JIT;
161-
#endif
162159
}
160+
#endif
163161
return flags;
164162
}
165163

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

+1
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

+4-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,10 @@ class V8_BASE_EXPORT OS {
167167
kReadWrite,
168168
// TODO(hpayer): Remove this flag. Memory should never be rwx.
169169
kReadWriteExecute,
170-
kReadExecute
170+
kReadExecute,
171+
// TODO(jkummerow): Remove this when Wasm has a platform-independent
172+
// w^x implementation.
173+
kNoAccessWillJitLater
171174
};
172175

173176
static bool HasLazyCommits();

deps/v8/src/utils/allocation.cc

+6-4
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,17 @@ bool OnCriticalMemoryPressure(size_t length) {
213213
VirtualMemory::VirtualMemory() = default;
214214

215215
VirtualMemory::VirtualMemory(v8::PageAllocator* page_allocator, size_t size,
216-
void* hint, size_t alignment)
216+
void* hint, size_t alignment, JitPermission jit)
217217
: page_allocator_(page_allocator) {
218218
DCHECK_NOT_NULL(page_allocator);
219219
DCHECK(IsAligned(size, page_allocator_->CommitPageSize()));
220220
size_t page_size = page_allocator_->AllocatePageSize();
221221
alignment = RoundUp(alignment, page_size);
222-
Address address = reinterpret_cast<Address>(
223-
AllocatePages(page_allocator_, hint, RoundUp(size, page_size), alignment,
224-
PageAllocator::kNoAccess));
222+
PageAllocator::Permission permissions =
223+
jit == kMapAsJittable ? PageAllocator::kNoAccessWillJitLater
224+
: PageAllocator::kNoAccess;
225+
Address address = reinterpret_cast<Address>(AllocatePages(
226+
page_allocator_, hint, RoundUp(size, page_size), alignment, permissions));
225227
if (address != kNullAddress) {
226228
DCHECK(IsAligned(address, alignment));
227229
region_ = base::AddressRegion(address, size);

deps/v8/src/utils/allocation.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ V8_EXPORT_PRIVATE bool OnCriticalMemoryPressure(size_t length);
156156
// Represents and controls an area of reserved memory.
157157
class VirtualMemory final {
158158
public:
159+
enum JitPermission { kNoJit, kMapAsJittable };
160+
159161
// Empty VirtualMemory object, controlling no reserved memory.
160162
V8_EXPORT_PRIVATE VirtualMemory();
161163

@@ -164,8 +166,8 @@ class VirtualMemory final {
164166
// size. The |size| must be aligned with |page_allocator|'s commit page size.
165167
// This may not be at the position returned by address().
166168
V8_EXPORT_PRIVATE VirtualMemory(v8::PageAllocator* page_allocator,
167-
size_t size, void* hint,
168-
size_t alignment = 1);
169+
size_t size, void* hint, size_t alignment = 1,
170+
JitPermission jit = kNoJit);
169171

170172
// Construct a virtual memory by assigning it some already mapped address
171173
// and size.

deps/v8/src/wasm/wasm-code-manager.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -1610,7 +1610,11 @@ VirtualMemory WasmCodeManager::TryAllocate(size_t size, void* hint) {
16101610
if (!BackingStore::ReserveAddressSpace(size)) return {};
16111611
if (hint == nullptr) hint = page_allocator->GetRandomMmapAddr();
16121612

1613-
VirtualMemory mem(page_allocator, size, hint, allocate_page_size);
1613+
// When we start exposing Wasm in jitless mode, then the jitless flag
1614+
// will have to determine whether we set kMapAsJittable or not.
1615+
DCHECK(!FLAG_jitless);
1616+
VirtualMemory mem(page_allocator, size, hint, allocate_page_size,
1617+
VirtualMemory::kMapAsJittable);
16141618
if (!mem.IsReserved()) {
16151619
BackingStore::ReleaseReservation(size);
16161620
return {};

deps/v8/test/cctest/cctest.status

+1
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,7 @@
496496
'test-jump-table-assembler/*': [SKIP],
497497
'test-gc/*': [SKIP],
498498
'test-grow-memory/*': [SKIP],
499+
'test-liftoff-inspection/*': [SKIP],
499500
'test-run-wasm-64/*': [SKIP],
500501
'test-run-wasm-asmjs/*': [SKIP],
501502
'test-run-wasm-atomics64/*': [SKIP],

0 commit comments

Comments
 (0)