Skip to content

Commit e4f413c

Browse files
committed
Ensure remapped memory has desired protection on Darwin
1 parent 633d369 commit e4f413c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

base/runtime/virtual_memory_darwin.odin

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ foreign lib {
1111
mach_task_self_: u32
1212
mach_vm_allocate :: proc(target: u32, address: ^u64, size: u64, flags: i32) -> i32 ---
1313
mach_vm_deallocate :: proc(target: u32, address: u64, size: u64) -> i32 ---
14+
mach_vm_protect :: proc(target_task: u32, address: u64, size: u64, set_maximum: b32, new_protection: i32) -> i32 ---
1415
mach_vm_map :: proc(
1516
target_task: u32,
1617
address: ^u64,
@@ -122,6 +123,8 @@ _resize_virtual_memory :: proc "contextless" (ptr: rawptr, old_size: int, new_si
122123
alignment_mask = u64(alignment) - 1
123124
}
124125

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)
125128
cur_protection, max_protection: i32
126129
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)
127130
if result_remap != 0 {

0 commit comments

Comments
 (0)