gpt4 book ai didi

c++ - 页面映射写入只允许读取

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:58:46 24 4
gpt4 key购买 nike

如果我将页面映射为只写:

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;

为什么它不会在读取时出现段错误?

最佳答案

参见 man page :

On some hardware architectures (e.g., i386), PROT_WRITE implies PROT_READ.

你不应该依赖于这种行为。

关于c++ - 页面映射写入只允许读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22840898/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com