linux – mmap内存保护的目的是什么PROT_NONE

我正在阅读mmap的documentation,并落在这条线上:

PROT_NONE Pages may not be accessed.

有没有用来将文件映射到内存,但是不能访问它?

PROT_NONE可以用来实现guard pages,微软有同样的概念(MSDN).

引用第一个链接:

… allocation of additional inaccessible memory during memory allocation
operations is a technique for mitigating against exploitation of heap
buffer overflows. These guard pages are unmapped pages placed between
all memory allocations of one page or larger. The guard page causes a
segmentation fault upon any access.

因此在实现对诸如网络接口,虚拟机和解释器等领域的保护方面非常有用.示例用法:pthread_attr_setguardsize, pthread_attr_getguardsize.

翻译自:https://stackoverflow.com/questions/12916603/what-s-the-purpose-of-mmap-memory-protection-prot-none

转载注明原文:linux – mmap内存保护的目的是什么PROT_NONE