[英]Two page entries reference to the same physical page
For linux and windows, in the same process, how to make two page entries reference to the same physical page? 对于linux和Windows,在同一过程中,如何使两个页面条目引用同一物理页面?
For windows, by reading at the MSDN, looks like I can call CreateFileMapping
by passing INVALID_HANDLE_VALUE
to create a file mapping without backed by a file. 对于Windows,通过在MSDN上阅读,看来我可以通过传递
INVALID_HANDLE_VALUE
来创建文件映射而无需文件支持的方式来调用CreateFileMapping
。 Then I can call MapViewOfFileEx
twice with different lpBaseAddress
, which essentially makes two different addresses reference to the same physical address. 然后,我可以使用不同的
lpBaseAddress
两次调用MapViewOfFileEx
,这实际上使两个不同的地址引用相同的物理地址。
My question is, how to do it under linux? 我的问题是,在Linux下如何做? I read manual for
mmap
, and didn't see a way to do it, unless the region is backed by a file (with flag MAP_SHARED
) but modifications to this region will be written to the file, which is not what I want. 我阅读了
mmap
手册,但没有找到解决方法,除非该区域由文件(带有标志MAP_SHARED
)支持,但是对该区域的修改将写入该文件,这不是我想要的。 Does anyone aware of someway to do this? 有人知道这样做吗? I am not against backing by a file, as long as the writing to the region doesn't actually goes to the disk.
我不反对使用文件作为后盾,只要对该区域的写入实际上并没有写入磁盘。 Using
tmpfs
is not an option because I can't guarantee user has a tmpfs
mounted. 不能使用
tmpfs
因为我不能保证用户安装了tmpfs
。
By the way, the code should be user mode code, not kernel mode. 顺便说一句,代码应该是用户模式代码,而不是内核模式。
Use shm_open()
to create a file for mmap()
. 使用
shm_open()
为mmap()
创建文件。
"I want to write some emulator" is the same purpose as mine when I used this trick. 使用此技巧时,“我想写一些模拟器”与我的目的相同。 I did use ipc/shm, but I forgot the detail.
我确实使用过ipc / shm,但是我忘记了细节。 It was very very very very probably:
shmget()+shmat()
非常非常非常可能:
shmget()+shmat()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.