在 OS X 上,如何找出当前的内存保护级别?
在 OS X 上,我可以使用 mprotect()
来请求将特定的内存页面设为可读、可写或可执行。
我想知道如何找出当前的保护级别是多少。举个例子,在 Linux 上我可以 cat /proc/$$/maps
来查找相同的信息:
$ cat /proc/$$/maps
00400000-004db000 r-xp 00000000 fb:00 131145 /bin/bash
006da000-006db000 r--p 000da000 fb:00 131145 /bin/bash
006db000-006e4000 rw-p 000db000 fb:00 131145 /bin/bash
006e4000-006ea000 rw-p 00000000 00:00 0
00df4000-00e55000 rw-p 00000000 00:00 0 [heap]
...
在这里我可以看到为主可执行文件映射了 5 个内存范围(bash
),一种是读/执行,一种是只读,其余的是读/写。
我已经浏览了所有我能找到的手册页和官方 API,以获取有关 OS X 的相同信息,但迄今为止一无所获。我发现唯一接近的是使用 mincore()
来确定页面是否在核心中。但这还不够;我还想要当前的权限集。
有没有任何未记录的方法可以做到这一点?
Possible Duplicate:
Retrieving the memory map of its own process in OS X 10.5/10.6
On OS X, I can use mprotect()
to request that a specific page of memory be made some combination of readable, writable or executable.
I want to know how to find out what the current protection level is. As an example, on Linux I can cat /proc/$$/maps
to find out the same information:
$ cat /proc/$/maps
00400000-004db000 r-xp 00000000 fb:00 131145 /bin/bash
006da000-006db000 r--p 000da000 fb:00 131145 /bin/bash
006db000-006e4000 rw-p 000db000 fb:00 131145 /bin/bash
006e4000-006ea000 rw-p 00000000 00:00 0
00df4000-00e55000 rw-p 00000000 00:00 0 [heap]
...
Here I can see that there are 5 ranges of memory mapped for the main executable (bash
), one is read/execute, one is read-only, and the rest are read/write.
I've looked through all the man pages and official APIs I can find to get the same information on OS X, and have come up empty so far. The only thing I've found that's close is to use mincore()
to figure out if a page is in-core or not. But that's not enough; I also want the current set of permissions.
Is there any undocumented way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
大多数与 VM 相关的系统调用都可以在 OSX 的 mach 库中找到。
http://web.mit.edu/darwin/src /modules/xnu/osfmk/man/vm_region.html
实际上,OSX 中的大多数 POSIX 调用只是适当的 Mach VM 系统调用的包装器。
Most VM related system calls can be found in the mach library for OSX.
http://web.mit.edu/darwin/src/modules/xnu/osfmk/man/vm_region.html
Actually most POSIX calls in OSX are just wrappers around the appropriate Mach VM syscalls.