简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM