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

file mmap() support #261

Closed
lunixbochs opened this issue Nov 12, 2015 · 6 comments
Closed

file mmap() support #261

lunixbochs opened this issue Nov 12, 2015 · 6 comments

Comments

@lunixbochs
Copy link
Contributor

I'd like to be able to directly mmap() files into target memory. I think this is facilitated in qemu-user by doing a "guest-to-host" address translation and just calling mmap() directly. Do host memory addresses backing guest memory ever change position? Something to guarantee a guest address range is backed by a fixed contiguous host memory region would be sufficient for this.

Maybe an API like guest_fixed_map(host_addr, guest_addr, size) would work, which points a region of guest memory at an existing region of host memory. This way it's not tied to anything overly platform specific like mmap() APIs.

@JonathonReinhart
Copy link
Member

I think this is huge. The vast majority of data copied into guest memory is probably coming from a file anyway.

@aquynh
Copy link
Member

aquynh commented Nov 13, 2015

yes this will be nice to have. Qemu has something called memory-backend-file, so you might want to look at that to see if we can use it for this API.

@lunixbochs
Copy link
Contributor Author

qemu-user seems to think calling mmap directly is fine (target_mmap() here is called from the mmap() syscall handler): https://github.com/hackndev/qemu/blob/master/darwin-user/mmap.c#L225

I just think a portable version of file mapping doesn't really need to be Unicorn's job. All I really want is the ability to make a fixed mapping from guest to existing host memory so I can do whatever I want with it, like invoke any syscall that needs to know the real backing page used by the guest (or manually map the same host region into two Unicorn instances, mostly satisfying my requirements in #142)

@aquynh
Copy link
Member

aquynh commented Nov 14, 2015

yes, feel free to propose new API and implement it.

lunixbochs added a commit to lunixbochs/unicorn that referenced this issue Nov 28, 2015
@lunixbochs
Copy link
Contributor Author

Proposed API usage (as implemented in the pull request):

uc_mem_map_ptr(handle, addr, size, void *ptr);

Permissions are not specified because Unicorn does not control them in this case.

Python and Go binding updates have been added to the PR as well. I think this API will be mostly useful in C, Go, and .NET clients, as Java and Python aren't imo as well suited to dumping raw pointers into OS syscalls.

lunixbochs added a commit to lunixbochs/unicorn that referenced this issue Nov 28, 2015
lunixbochs added a commit to lunixbochs/unicorn that referenced this issue Nov 28, 2015
lunixbochs added a commit to lunixbochs/unicorn that referenced this issue Nov 28, 2015
@aquynh
Copy link
Member

aquynh commented Jan 1, 2016

this is already solved with the new API uc_mem_map_ptr(), so closed. thanks

@aquynh aquynh closed this as completed Jan 1, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants