是否可以更新现有内存映射的标志?
我正在编写X64组件中的一个小程序,该程序将产生孩子,所有这些都共享他们的内存映射,以便他们可以修改彼此的代码。为此,由于sys_clone
的参数clone_vm
似乎将程序置于未定义的行为中,因此我计划使用mmap
's map_shared
参数。
但是,我还需要孩子们修改父亲的守则。一种选择是还分配map_shared
映射并将其交给父亲,但是如果可能的话,我想避免这种情况(仅出于优雅的原因)。
由于该程序的基本映射(0x400000
一个在64位linux上)将不具有map_shared
flag默认情况下,是否可以使用SYSCALL将其更新为设置此标志? munmap
然后mmap
将不做并引起sigsegv,而mprotect
只能更改RWX权限。
I am writing a small program in x64 assembly that will spawn children, all sharing their memory mappings so they can modify each other's code. For this, since the argument CLONE_VM
of sys_clone
seems to place the program into undefined behaviour, I plan to use mmap
's MAP_SHARED
argument.
However, I would also need the children to modify the code of the father. One option is to also allocate a MAP_SHARED
mapping and give it to the father, but I'd like to avoid this if possible (only for elegance reasons).
Since the base mapping (the 0x400000
one on 64-bits Linux) of the program will not have the MAP_SHARED
flag by default, is it possible to update it using a syscall to set this flag? munmap
then mmap
will not do and cause a SIGSEGV, and mprotect
can only change the RWX permissions.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您无法更改现有的映射是私有的还是共享的,但是您可以在现有的私有映射上映射新的共享映射。您甚至可以在C中这样做:
作为奖励,此程序支持ASLR,并且不需要文本部分以
0x400000
开始。You can't change whether an existing mapping is private or shared, but you can map a new shared mapping over an existing private mapping. You can even do so in C, like this:
As a bonus, this program supports ASLR and doesn't require that the text section start at
0x400000
.