Why does mmap() use MAP_FAILED instead of NULL?

江枫思渺然 提交于 2019-12-04 00:40:21

There are some rare situations where mmap() will actually create a mapping at address 0x0. These days, it typically requires root privileges (or for the mmap_min_addr sysctl to be set to zero on Linux systems) but it is possible. If such a mapping is created, it becomes possible to write to this address.

MAP_FAILED, on the other hand, is never a valid return value from mmap(), so it's usable as a sentinel.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!