how can I detect whether a specific page is mapped in memory?

Deadly 提交于 2019-11-29 05:56:23

msync(addr, len, 0) and checking for ENOMEM seems to work (with a fairly superficial test).

This doesn't "remap" the memory, but creates another mapping at different address (since the one you give it is already taken, and it's treated as a hint anyway). The old one is still valid, you just lose the reference to it since you overwrite the ptr variable.

If you want to create multiple mappings to the same memory like that look into shm_open(2).

If you just want to check if address is mapped then the MAP_FIXED trick pointed out by @MerickOWA should work.

Edit 0:

You are right about MAP_FIXED, it doesn't help in this case. What you might try is mincore(2). One of the errors it returns is:

ENOMEMaddr to addr + length contained unmapped memory.

On QNX, you can use mem_offset() and posix_mem_offset() and check the contents of contig_len on output, comparing it with the length input parameter.

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