From 52b312099540ca397d7ff4a918e6efb22f9d954b Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Sat, 17 Feb 2018 19:44:38 -0500 Subject: [PATCH] exec: make qemu_ram_ptr_length more similar to qemu_get_ram_ptr Notably, use qemu_get_ram_block to enjoy the MRU optimization. Backports commit e81bcda529378f5ed8b9b0b59bb2b24b8ee1c814 from qemu --- qemu/exec.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/qemu/exec.c b/qemu/exec.c index 5ac84130..9397ed00 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -1277,20 +1277,29 @@ void *qemu_get_ram_ptr(struct uc_struct *uc, ram_addr_t addr) static void *qemu_ram_ptr_length(struct uc_struct *uc, ram_addr_t addr, hwaddr *size) { RAMBlock *block; + ram_addr_t offset_inside_block; if (*size == 0) { return NULL; } - QTAILQ_FOREACH(block, &uc->ram_list.blocks, next) { - if (addr - block->offset < block->max_length) { - if (addr - block->offset + *size > block->max_length) - *size = block->max_length - addr + block->offset; - return ramblock_ptr(block, addr - block->offset); - } - } + block = qemu_get_ram_block(uc, addr); + offset_inside_block = addr - block->offset; + *size = MIN(*size, block->max_length - offset_inside_block); - fprintf(stderr, "Bad ram offset %" PRIx64 "\n", (uint64_t)addr); - abort(); + // Unicorn: Commented out + //if (xen_enabled() && block->host == NULL) { + // /* We need to check if the requested address is in the RAM + // * because we don't want to map the entire memory in QEMU. + // * In that case just map the requested area. + // */ + // if (block->offset == 0) { + // return xen_map_cache(addr, *size, 1); + // } + // + // block->host = xen_map_cache(block->offset, block->max_length, 1); + //} + + return ramblock_ptr(block, offset_inside_block); } /*