Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 219755c

Browse files
committedFeb 10, 2025
Revert to unoptimized behavior on Darwin
1 parent e4f413c commit 219755c

File tree

1 file changed

+7
-36
lines changed

1 file changed

+7
-36
lines changed
 

‎base/runtime/virtual_memory_darwin.odin

+7-36
Original file line numberDiff line numberDiff line change
@@ -100,42 +100,13 @@ _free_virtual_memory :: proc "contextless" (ptr: rawptr, size: int) {
100100
}
101101

102102
_resize_virtual_memory :: proc "contextless" (ptr: rawptr, old_size: int, new_size: int, alignment: int) -> rawptr {
103-
old_size_pages := old_size / PAGE_SIZE
104-
new_size_pages := new_size / PAGE_SIZE
105-
if old_size % PAGE_SIZE != 0 {
106-
old_size_pages += 1
107-
}
108-
if new_size % PAGE_SIZE != 0 {
109-
new_size_pages += 1
110-
}
111-
112-
if new_size_pages == old_size_pages {
113-
return ptr
114-
} else if new_size_pages > old_size_pages {
115-
new_address: u64
116-
result_alloc := mach_vm_allocate(mach_task_self_, &new_address, u64(new_size), VM_FLAGS_ANYWHERE)
117-
if result_alloc != 0 {
118-
return nil
119-
}
120-
121-
alignment_mask: u64
122-
if alignment != 0 {
123-
alignment_mask = u64(alignment) - 1
124-
}
125-
126-
mach_vm_protect(mach_task_self_, new_address, u64(new_size), true, VM_PROT_READ|VM_PROT_WRITE)
127-
mach_vm_protect(mach_task_self_, new_address, u64(new_size), false, VM_PROT_READ|VM_PROT_WRITE)
128-
cur_protection, max_protection: i32
129-
result_remap := mach_vm_remap(mach_task_self_, &new_address, u64(old_size), alignment_mask, VM_FLAGS_ANYWHERE, mach_task_self_, u64(uintptr(ptr)), true, &cur_protection, &max_protection, VM_INHERIT_COPY)
130-
if result_remap != 0 {
131-
return nil
132-
}
133-
mach_vm_deallocate(mach_task_self_, u64(uintptr(ptr)), u64(old_size))
134-
return rawptr(uintptr(new_address))
103+
result: rawptr = ---
104+
if alignment == 0 {
105+
result = _allocate_virtual_memory(new_size)
135106
} else {
136-
new_size_boundary := new_size_pages * PAGE_SIZE
137-
shrink_by := u64(old_size - new_size)
138-
mach_vm_deallocate(mach_task_self_, u64(uintptr(ptr) + uintptr(new_size_boundary)), shrink_by)
139-
return rawptr(uintptr(ptr))
107+
result = _allocate_virtual_memory_aligned(new_size, alignment)
140108
}
109+
intrinsics.mem_copy_non_overlapping(result, ptr, min(new_size, old_size))
110+
mach_vm_deallocate(mach_task_self_, u64(uintptr(ptr)), u64(old_size))
111+
return result
141112
}

0 commit comments

Comments
 (0)
Please sign in to comment.