Skip to content

Commit 4029888

Browse files
oleavra60814billy
authored andcommitted
deps: v8: backport d37ddb4 to v14
Original commit message: 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 6a91400 commit 4029888

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.22',
39+
'v8_embedder_string': '-node.23',
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
@@ -118,6 +118,7 @@ const int kMmapFdOffset = 0;
118118
int GetProtectionFromMemoryPermission(OS::MemoryPermission access) {
119119
switch (access) {
120120
case OS::MemoryPermission::kNoAccess:
121+
case OS::MemoryPermission::kNoAccessWillJitLater:
121122
return PROT_NONE;
122123
case OS::MemoryPermission::kRead:
123124
return PROT_READ;
@@ -140,15 +141,12 @@ int GetFlagsForMemoryPermission(OS::MemoryPermission access) {
140141
#if V8_OS_QNX
141142
flags |= MAP_LAZY;
142143
#endif // V8_OS_QNX
143-
#if V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT) && \
144-
!defined(V8_OS_IOS)
145-
// TODO(jkummerow): using the V8_OS_IOS define is a crude approximation
146-
// of the fact that we don't want to set the MAP_JIT flag when
147-
// FLAG_jitless == true, as src/base/ doesn't know any flags.
148-
// TODO(crbug.com/1117591): This is only needed for code spaces.
144+
}
145+
#if V8_OS_MACOSX && V8_HOST_ARCH_ARM64 && defined(MAP_JIT)
146+
if (access == OS::MemoryPermission::kNoAccessWillJitLater) {
149147
flags |= MAP_JIT;
150-
#endif
151148
}
149+
#endif
152150
return flags;
153151
}
154152

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
@@ -212,15 +212,17 @@ bool OnCriticalMemoryPressure(size_t length) {
212212
VirtualMemory::VirtualMemory() = default;
213213

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

deps/v8/src/utils/allocation.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ V8_EXPORT_PRIVATE bool OnCriticalMemoryPressure(size_t length);
150150
// Represents and controls an area of reserved memory.
151151
class VirtualMemory final {
152152
public:
153+
enum JitPermission { kNoJit, kMapAsJittable };
154+
153155
// Empty VirtualMemory object, controlling no reserved memory.
154156
V8_EXPORT_PRIVATE VirtualMemory();
155157

@@ -158,8 +160,8 @@ class VirtualMemory final {
158160
// size. The |size| must be aligned with |page_allocator|'s commit page size.
159161
// This may not be at the position returned by address().
160162
V8_EXPORT_PRIVATE VirtualMemory(v8::PageAllocator* page_allocator,
161-
size_t size, void* hint,
162-
size_t alignment = 1);
163+
size_t size, void* hint, size_t alignment = 1,
164+
JitPermission jit = kNoJit);
163165

164166
// Construct a virtual memory by assigning it some already mapped address
165167
// and size.

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

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

1590-
VirtualMemory mem(page_allocator, size, hint, allocate_page_size);
1590+
// When we start exposing Wasm in jitless mode, then the jitless flag
1591+
// will have to determine whether we set kMapAsJittable or not.
1592+
DCHECK(!FLAG_jitless);
1593+
VirtualMemory mem(page_allocator, size, hint, allocate_page_size,
1594+
VirtualMemory::kMapAsJittable);
15911595
if (!mem.IsReserved()) {
15921596
BackingStore::ReleaseReservation(size);
15931597
return {};

deps/v8/test/cctest/cctest.status

+1
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,7 @@
478478
'test-jump-table-assembler/*': [SKIP],
479479
'test-gc/*': [SKIP],
480480
'test-grow-memory/*': [SKIP],
481+
'test-liftoff-inspection/*': [SKIP],
481482
'test-run-wasm-64/*': [SKIP],
482483
'test-run-wasm-asmjs/*': [SKIP],
483484
'test-run-wasm-atomics64/*': [SKIP],

0 commit comments

Comments
 (0)