int fd = open("demo.txt", O_RDWR|O_CREAT, 0);
void *address = mmap(nil, PAGE_SIZE, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, fd, 0);
if (address == MAP_FAILED)
return;
memcpy((void *)address, func, 32);
// restore page permission
mprotect((void *)address, PAGE_SIZE, PROT_READ | PROT_EXEC);
int (*funcPtr)() = address;
funcPtr();
上面的代码为什么在非越狱机器下,xcode release编译也能成功运行起来?我运行了mmap内存里的汇编,这在正常机器下不应该crash吗?