cmacoskernelmach

OS X kernel lock virtual address space into physical memory


To allocate memory I do like that:

uint64_t _addr = 0x00;

kern_return_t err = mach_vm_allocate(mach_task_self(), &_addr, size, VM_FLAGS_ANYWHERE);
    if (err != KERN_SUCCESS) {
        printf("failed to allocate %s\n", mach_error_string(err));

    }

But can someone please show me how to prevent that memory from being paged to the swap area? In Windows there is VirtualLock.


Solution

  • It should work to use mach_vm_wire() for this. It's not clear if you were asking about doing this from kernel code (e.g. a kext) or from user code. If from user space, you may need root privileges to do this.