开发者

how to get protection flags of a memory area, flags are PROT_READ /PROT_EXEC in mprotect

I use 开发者_运维知识库mprotect() to set protection flags to a memory area. Later on, I want to restore this memory area's protection flags.

My question is, how to get protection flags of a memory area? the flags inclue PROT_READ ...

My workaround is to parse /proc/self/maps manually. But this solution is to clumsy ...

I wonder if there's any system call that I can use.


In general that's the only way. POSIX does not provide a way to access the protections. In application-specific usages where you have control over the code that maps the page, you could have it save the flags somewhere at that time, but in general you have to read /proc/self/maps. In addition, you may want to fallback to some default permissions if you can't read /proc. PROT_READ|PROT_WRITE is probably a reasonable default for most things but in some cases you may also want PROT_EXEC.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜