Skip to content

Commit

Permalink
Ensure remapped memory has desired protection on Darwin
Browse files Browse the repository at this point in the history
  • Loading branch information
Feoramund committed Feb 10, 2025
1 parent 633d369 commit e4f413c
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/runtime/virtual_memory_darwin.odin
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit e4f413c

Please sign in to comment.