Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow mapping MAP_PRIVATE memory to file #92

Open
acatangiu opened this issue May 21, 2020 · 3 comments
Open

Allow mapping MAP_PRIVATE memory to file #92

acatangiu opened this issue May 21, 2020 · 3 comments

Comments

@acatangiu
Copy link

The only provided interfaces right now force MAP_SHARED on all file mappings.

@sandreim
Copy link

sandreim commented May 21, 2020

Current solution is this:

 fn restore(file: &File, state: &GuestMemoryState) -> std::result::Result<Self, Error> {
        let mmap_regions = state
            .regions
            .iter()
            .map(|region| {
                let file_clone = file.try_clone().expect("Cannot clone memory file.");
                MmapRegion::build(
                    Some(FileOffset::new(file_clone, region.offset)),
                    region.size,
                    libc::PROT_READ | libc::PROT_WRITE,
                    libc::MAP_NORESERVE | libc::MAP_PRIVATE,
                )
                .map(|r| {
                    GuestRegionMmap::new(r, GuestAddress(region.base_address))
                        .expect("Cannot create guest mmap region.")
                })
                .expect("Cannot create mmap region.")
            })
            .collect();

      Ok(Self::from_regions(mmap_regions).map_err(Error::CreateMemory)?)
}

@mikkorantalainen
Copy link

Is there any plans to support this natively? I was surprised to find that memmap::MmapOptions always uses MAP_SHARED.

@andreeaflorescu
Copy link
Member

Ping @bonzini @jiangliu @alexandruag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants