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 c9f7fe5
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 @@ -127,6 +128,8 @@ _resize_virtual_memory :: proc "contextless" (ptr: rawptr, old_size: int, new_si
if result_remap != 0 {
return nil
}
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)
mach_vm_deallocate(mach_task_self_, u64(uintptr(ptr)), u64(old_size))
return rawptr(uintptr(new_address))
} else {
Expand Down

0 comments on commit c9f7fe5

Please sign in to comment.