mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 00:13:50 +00:00
[VM] For app-jit snapshot on MacOS 10.15 and higher mmap ANONYMOUS pages and
read the app-jit snapshot into this memory instead of directly mapping the app-jit snapshot. use MAP_JIT option only for executable pages and do not use it on iOS. Change-Id: I8db6f29293677bbf36209473709077115b7b489e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/113219 Reviewed-by: Ryan Macnak <rmacnak@google.com> Commit-Queue: Siva Annamalai <asiva@google.com>
This commit is contained in:
parent
f236abc902
commit
2023f09b56
|
@ -80,17 +80,41 @@ MappedMemory* File::Map(MapType type, int64_t position, int64_t length) {
|
|||
ASSERT(handle_->fd() >= 0);
|
||||
ASSERT(length > 0);
|
||||
int prot = PROT_NONE;
|
||||
int map_flags = MAP_PRIVATE;
|
||||
switch (type) {
|
||||
case kReadOnly:
|
||||
prot = PROT_READ;
|
||||
break;
|
||||
case kReadExecute:
|
||||
prot = PROT_READ | PROT_EXEC;
|
||||
if (IsAtLeastOS10_14()) {
|
||||
map_flags |= (MAP_JIT | MAP_ANONYMOUS);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
void* addr = mmap(NULL, length, prot, MAP_PRIVATE, handle_->fd(), position);
|
||||
void* addr = NULL;
|
||||
if ((type == kReadExecute) && IsAtLeastOS10_14()) {
|
||||
addr = mmap(NULL, length, (PROT_READ | PROT_WRITE), map_flags, -1, 0);
|
||||
if (addr == MAP_FAILED) {
|
||||
Syslog::PrintErr("mmap failed %s\n", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
SetPosition(position);
|
||||
if (!ReadFully(addr, length)) {
|
||||
Syslog::PrintErr("ReadFully failed\n");
|
||||
munmap(addr, length);
|
||||
return NULL;
|
||||
}
|
||||
if (mprotect(addr, length, prot) != 0) {
|
||||
Syslog::PrintErr("mprotect failed %s\n", strerror(errno));
|
||||
munmap(addr, length);
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
addr = mmap(NULL, length, prot, map_flags, handle_->fd(), position);
|
||||
}
|
||||
if (addr == MAP_FAILED) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -214,8 +214,8 @@ VirtualMemory* VirtualMemory::AllocateAligned(intptr_t size,
|
|||
PROT_READ | PROT_WRITE |
|
||||
((is_executable && !FLAG_write_protect_code) ? PROT_EXEC : 0);
|
||||
int map_flags = MAP_PRIVATE | MAP_ANONYMOUS;
|
||||
#if defined(HOST_OS_MACOS)
|
||||
if (IsAtLeastOS10_14()) {
|
||||
#if (defined(HOST_OS_MACOS) && !defined(HOST_OS_IOS))
|
||||
if (is_executable && IsAtLeastOS10_14()) {
|
||||
map_flags |= MAP_JIT;
|
||||
}
|
||||
#endif // defined(HOST_OS_MACOS)
|
||||
|
|
Loading…
Reference in a new issue