页面映射写入仅允许读取

Page mapped write only allows reading

本文关键字:许读取 读取 映射      更新时间:2023-10-16

如果我将页面映射为仅写入:

int* mem_location = (int*)mmap(nullptr, getpagesize(), 
    PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
cout << "Read @" << mem_location << ". This should segfault: " 
     << *mem_location << endl;
cout << "doesn't though??" << endl;

为什么在读取时没有段错误?

请参阅手册页:

在某些硬件架构(例如 i386)上,PROT_WRITE意味着PROT_READ。

不应依赖此行为。