Skip to content

Commit 9b5777d

Browse files
rmacnak-googleCommit Queue
authored andcommitted
[vm, gc] Allocate aligned memory directly on Mac.
Don't need to over-allocate and truncate to the aligned subregion unless we are using MAP_JIT. TEST=ci Change-Id: Id2931198246e527eff746aed7efbe72d8dc5efb1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/438242 Reviewed-by: Slava Egorov <[email protected]> Commit-Queue: Ryan Macnak <[email protected]>
1 parent d183c83 commit 9b5777d

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

runtime/vm/virtual_memory_posix.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,25 @@ static void* GenericMapAligned(void* hint,
113113
intptr_t alignment,
114114
intptr_t allocated_size,
115115
int map_flags) {
116+
#if defined(DART_HOST_OS_MACOS)
117+
// vm_map doesn't support MAP_JIT.
118+
if ((map_flags & MAP_JIT) == 0) {
119+
vm_address_t address = 0;
120+
vm_prot_t cur_prot = 0;
121+
if ((prot & PROT_READ) != 0) cur_prot |= VM_PROT_READ;
122+
if ((prot & PROT_WRITE) != 0) cur_prot |= VM_PROT_WRITE;
123+
if ((prot & PROT_EXEC) != 0) cur_prot |= VM_PROT_EXECUTE;
124+
vm_prot_t max_prot = VM_PROT_ALL;
125+
const kern_return_t result =
126+
vm_map(mach_task_self(), &address, size, /*mask=*/alignment - 1,
127+
VM_FLAGS_ANYWHERE, MEMORY_OBJECT_NULL, /*offset=*/0,
128+
/*copy=*/FALSE, cur_prot, max_prot, VM_INHERIT_DEFAULT);
129+
if (result != KERN_SUCCESS) {
130+
return nullptr;
131+
}
132+
return reinterpret_cast<void*>(address);
133+
}
134+
#endif
116135
void* address = Map(hint, allocated_size, prot, map_flags, -1, 0);
117136
if (address == MAP_FAILED) {
118137
return nullptr;

0 commit comments

Comments
 (0)