简体   繁体   中英

How can I ask Mac OS to allocate memory at a specific address?

On Linux, you can allocate memory at a specific address like so:

void *foo = (void *)0xDEADBEEF;
size_t MyLength = 1024;
void *bar = mmap(foo, MyLength, PROT_READ | PROT_WRITE | MAP_ANONYMOUS | MAP_FIXED, MAP_PRIVATE, -1, 0);

Is this same method also possible on Mac OS, or if not, how does one do this on Mac OS?

My goal is to write a kernel extension to map out (and thus disable) a region of defective memory on a MacBook Pro with a non-removable defective RAM chip.

This is std C . It compiles fine on Xcode . Make sure to add:

#include <sys/mman.h>

Before you invest too much time writing a kernel extension for macOS be aware of its deprecation .

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