From 4a31e1f6355f036e4c97641cf317a77f98af8cab Mon Sep 17 00:00:00 2001 From: Feoramund <161657516+Feoramund@users.noreply.github.com> Date: Mon, 10 Feb 2025 16:14:46 -0500 Subject: [PATCH] Ensure remapped memory has desired protection on Darwin --- base/runtime/virtual_memory_darwin.odin | 3 +++ 1 file changed, 3 insertions(+) diff --git a/base/runtime/virtual_memory_darwin.odin b/base/runtime/virtual_memory_darwin.odin index 4642edf84..548b5ff04 100644 --- a/base/runtime/virtual_memory_darwin.odin +++ b/base/runtime/virtual_memory_darwin.odin @@ -11,6 +11,7 @@ foreign lib { mach_task_self_: u32 mach_vm_allocate :: proc(target: u32, address: ^u64, size: u64, flags: i32) -> i32 --- mach_vm_deallocate :: proc(target: u32, address: u64, size: u64) -> i32 --- + mach_vm_protect :: proc(target_task: u32, address: u64, size: u64, set_maximum: b32, new_protection: i32) -> i32 --- mach_vm_map :: proc( target_task: u32, address: ^u64, @@ -122,6 +123,8 @@ _resize_virtual_memory :: proc "contextless" (ptr: rawptr, old_size: int, new_si alignment_mask = u64(alignment) - 1 } + mach_vm_protect(mach_task_self_, new_address, u64(new_size), true, VM_PROT_READ|VM_PROT_WRITE) + mach_vm_protect(mach_task_self_, new_address, u64(new_size), false, VM_PROT_READ|VM_PROT_WRITE) cur_protection, max_protection: i32 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) if result_remap != 0 {