mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-01 14:53:54 -06:00
linux-user: Use init_guest_space when -R and -B are specified
Roll the code used to initialize the guest memory space when -R or -B is used into 'init_guest_space' and then call 'init_guest_space' from the driver. This way the reserved guest memory space can be probed for. Calling 'mmap' just once as is currently done is not guaranteed to succeed since the host address space validation might fail. Signed-off-by: Meador Inge <meadori@codesourcery.com> [PMM: Fixed minor whitespace errors.] Reviewed-by: Peter Maydell <peter.maydell@linaro.org> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
parent
dce104013d
commit
806d102141
3 changed files with 56 additions and 44 deletions
|
@ -3516,39 +3516,16 @@ int main(int argc, char **argv, char **envp)
|
|||
*/
|
||||
guest_base = HOST_PAGE_ALIGN(guest_base);
|
||||
|
||||
if (reserved_va) {
|
||||
void *p;
|
||||
int flags;
|
||||
|
||||
flags = MAP_ANONYMOUS | MAP_PRIVATE | MAP_NORESERVE;
|
||||
if (have_guest_base) {
|
||||
flags |= MAP_FIXED;
|
||||
}
|
||||
p = mmap((void *)guest_base, reserved_va, PROT_NONE, flags, -1, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
if (reserved_va || have_guest_base) {
|
||||
guest_base = init_guest_space(guest_base, reserved_va, 0,
|
||||
have_guest_base);
|
||||
if (guest_base == (unsigned long)-1) {
|
||||
fprintf(stderr, "Unable to reserve guest address space\n");
|
||||
exit(1);
|
||||
}
|
||||
guest_base = (unsigned long)p;
|
||||
/* Make sure the address is properly aligned. */
|
||||
if (guest_base & ~qemu_host_page_mask) {
|
||||
munmap(p, reserved_va);
|
||||
p = mmap((void *)guest_base, reserved_va + qemu_host_page_size,
|
||||
PROT_NONE, flags, -1, 0);
|
||||
if (p == MAP_FAILED) {
|
||||
fprintf(stderr, "Unable to reserve guest address space\n");
|
||||
exit(1);
|
||||
}
|
||||
guest_base = HOST_PAGE_ALIGN((unsigned long)p);
|
||||
}
|
||||
qemu_log("Reserved 0x%lx bytes of guest address space\n", reserved_va);
|
||||
mmap_next_start = reserved_va;
|
||||
}
|
||||
|
||||
if (reserved_va || have_guest_base) {
|
||||
if (!guest_validate_base(guest_base)) {
|
||||
fprintf(stderr, "Guest base/Reserved VA rejected by guest code\n");
|
||||
exit(1);
|
||||
if (reserved_va) {
|
||||
mmap_next_start = reserved_va;
|
||||
}
|
||||
}
|
||||
#endif /* CONFIG_USE_GUEST_BASE */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue