diff --git a/include/qemu.h b/include/qemu.h index cf4f0421..5428cf25 100644 --- a/include/qemu.h +++ b/include/qemu.h @@ -19,7 +19,6 @@ struct uc_struct; // This two struct is originally from qemu/include/exec/cpu-all.h // Temporarily moved here since there is circular inclusion. -typedef struct RAMBlock RAMBlock; struct RAMBlock { struct MemoryRegion *mr; uint8_t *host; diff --git a/qemu/aarch64.h b/qemu/aarch64.h index e51f654a..94868eaa 100644 --- a/qemu/aarch64.h +++ b/qemu/aarch64.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_aarch64 #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_aarch64 #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_aarch64 +#define qemu_ram_block_from_host qemu_ram_block_from_host_aarch64 #define qemu_ram_foreach_block qemu_ram_foreach_block_aarch64 #define qemu_ram_free qemu_ram_free_aarch64 #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_aarch64 +#define qemu_ram_get_idstr qemu_ram_get_idstr_aarch64 #define qemu_ram_ptr_length qemu_ram_ptr_length_aarch64 #define qemu_ram_remap qemu_ram_remap_aarch64 #define qemu_ram_resize qemu_ram_resize_aarch64 diff --git a/qemu/aarch64eb.h b/qemu/aarch64eb.h index c04abd4d..fb99f006 100644 --- a/qemu/aarch64eb.h +++ b/qemu/aarch64eb.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_aarch64eb #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_aarch64eb #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_aarch64eb +#define qemu_ram_block_from_host qemu_ram_block_from_host_aarch64eb #define qemu_ram_foreach_block qemu_ram_foreach_block_aarch64eb #define qemu_ram_free qemu_ram_free_aarch64eb #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_aarch64eb +#define qemu_ram_get_idstr qemu_ram_get_idstr_aarch64eb #define qemu_ram_ptr_length qemu_ram_ptr_length_aarch64eb #define qemu_ram_remap qemu_ram_remap_aarch64eb #define qemu_ram_resize qemu_ram_resize_aarch64eb diff --git a/qemu/arm.h b/qemu/arm.h index 52fe98f4..b8432a7b 100644 --- a/qemu/arm.h +++ b/qemu/arm.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_arm #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_arm #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_arm +#define qemu_ram_block_from_host qemu_ram_block_from_host_arm #define qemu_ram_foreach_block qemu_ram_foreach_block_arm #define qemu_ram_free qemu_ram_free_arm #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_arm +#define qemu_ram_get_idstr qemu_ram_get_idstr_arm #define qemu_ram_ptr_length qemu_ram_ptr_length_arm #define qemu_ram_remap qemu_ram_remap_arm #define qemu_ram_resize qemu_ram_resize_arm diff --git a/qemu/armeb.h b/qemu/armeb.h index ba4ff239..b16493fd 100644 --- a/qemu/armeb.h +++ b/qemu/armeb.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_armeb #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_armeb #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_armeb +#define qemu_ram_block_from_host qemu_ram_block_from_host_armeb #define qemu_ram_foreach_block qemu_ram_foreach_block_armeb #define qemu_ram_free qemu_ram_free_armeb #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_armeb +#define qemu_ram_get_idstr qemu_ram_get_idstr_armeb #define qemu_ram_ptr_length qemu_ram_ptr_length_armeb #define qemu_ram_remap qemu_ram_remap_armeb #define qemu_ram_resize qemu_ram_resize_armeb diff --git a/qemu/exec.c b/qemu/exec.c index 5df6a3a8..13233b2d 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -986,6 +986,11 @@ static RAMBlock *find_ram_block(struct uc_struct *uc, ram_addr_t addr) return NULL; } +const char *qemu_ram_get_idstr(RAMBlock *rb) +{ + return rb->idstr; +} + void qemu_ram_unset_idstr(struct uc_struct *uc, ram_addr_t addr) { RAMBlock *block = find_ram_block(uc, addr); @@ -1301,9 +1306,27 @@ static void *qemu_ram_ptr_length(struct uc_struct *uc, ram_addr_t addr, hwaddr * abort(); } -/* Some of the softmmu routines need to translate from a host pointer - (typically a TLB entry) back to a ram offset. */ -MemoryRegion *qemu_ram_addr_from_host(struct uc_struct *uc, void *ptr, ram_addr_t *ram_addr) +/* + * Translates a host ptr back to a RAMBlock, a ram_addr and an offset + * in that RAMBlock. + * + * ptr: Host pointer to look up + * round_offset: If true round the result offset down to a page boundary + * *ram_addr: set to result ram_addr + * *offset: set to result offset within the RAMBlock + * + * Returns: RAMBlock (or NULL if not found) + * + * + * By the time this function returns, the returned pointer is not protected + * by RCU anymore. If the caller is not within an RCU critical section and + * does not hold the iothread lock, it must have other means of protecting the + * pointer, such as a reference to the region that includes the incoming + * ram_addr_t. + */ +RAMBlock *qemu_ram_block_from_host(struct uc_struct* uc, void *ptr, bool round_offset, + ram_addr_t *ram_addr, + ram_addr_t *offset) { RAMBlock *block; uint8_t *host = ptr; @@ -1326,7 +1349,27 @@ MemoryRegion *qemu_ram_addr_from_host(struct uc_struct *uc, void *ptr, ram_addr_ return NULL; found: - *ram_addr = block->offset + (host - block->host); + *offset = (host - block->host); + if (round_offset) { + *offset &= TARGET_PAGE_MASK; + } + *ram_addr = block->offset + *offset; + return block; +} + +/* Some of the softmmu routines need to translate from a host pointer + (typically a TLB entry) back to a ram offset. */ +MemoryRegion *qemu_ram_addr_from_host(struct uc_struct* uc, void *ptr, ram_addr_t *ram_addr) +{ + RAMBlock *block; + ram_addr_t offset; /* Not used */ + + block = qemu_ram_block_from_host(uc, ptr, false, ram_addr, &offset); + + if (!block) { + return NULL; + } + return block->mr; } diff --git a/qemu/header_gen.py b/qemu/header_gen.py index f1179ebc..32fbd021 100644 --- a/qemu/header_gen.py +++ b/qemu/header_gen.py @@ -2442,9 +2442,11 @@ symbols = ( 'qemu_ram_alloc', 'qemu_ram_alloc_from_ptr', 'qemu_ram_alloc_resizeable', + 'qemu_ram_block_from_host', 'qemu_ram_foreach_block', 'qemu_ram_free', 'qemu_ram_free_from_ptr', + 'qemu_ram_get_idstr', 'qemu_ram_ptr_length', 'qemu_ram_remap', 'qemu_ram_resize', diff --git a/qemu/include/exec/cpu-common.h b/qemu/include/exec/cpu-common.h index f47ce42c..af0051a0 100644 --- a/qemu/include/exec/cpu-common.h +++ b/qemu/include/exec/cpu-common.h @@ -49,8 +49,11 @@ typedef uint32_t CPUReadMemoryFunc(void *opaque, hwaddr addr); void qemu_ram_remap(struct uc_struct *uc, ram_addr_t addr, ram_addr_t length); /* This should not be used by devices. */ MemoryRegion *qemu_ram_addr_from_host(struct uc_struct* uc, void *ptr, ram_addr_t *ram_addr); +RAMBlock *qemu_ram_block_from_host(struct uc_struct* uc, void *ptr, bool round_offset, + ram_addr_t *ram_addr, ram_addr_t *offset); void qemu_ram_set_idstr(struct uc_struct *uc, ram_addr_t addr, const char *name, DeviceState *dev); void qemu_ram_unset_idstr(struct uc_struct *uc, ram_addr_t addr); +const char *qemu_ram_get_idstr(RAMBlock *rb); bool cpu_physical_memory_rw(AddressSpace *as, hwaddr addr, uint8_t *buf, int len, int is_write); diff --git a/qemu/include/qemu/typedefs.h b/qemu/include/qemu/typedefs.h index 516a1ec5..04dee4db 100644 --- a/qemu/include/qemu/typedefs.h +++ b/qemu/include/qemu/typedefs.h @@ -77,6 +77,7 @@ typedef struct SHPCDevice SHPCDevice; typedef struct FWCfgState FWCfgState; typedef struct PcGuestInfo PcGuestInfo; typedef struct Range Range; +typedef struct RAMBlock RAMBlock; typedef struct AdapterInfo AdapterInfo; #endif /* QEMU_TYPEDEFS_H */ diff --git a/qemu/m68k.h b/qemu/m68k.h index 54f14515..9b2f334f 100644 --- a/qemu/m68k.h +++ b/qemu/m68k.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_m68k #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_m68k #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_m68k +#define qemu_ram_block_from_host qemu_ram_block_from_host_m68k #define qemu_ram_foreach_block qemu_ram_foreach_block_m68k #define qemu_ram_free qemu_ram_free_m68k #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_m68k +#define qemu_ram_get_idstr qemu_ram_get_idstr_m68k #define qemu_ram_ptr_length qemu_ram_ptr_length_m68k #define qemu_ram_remap qemu_ram_remap_m68k #define qemu_ram_resize qemu_ram_resize_m68k diff --git a/qemu/mips.h b/qemu/mips.h index aada73d9..7729efaa 100644 --- a/qemu/mips.h +++ b/qemu/mips.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_mips #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_mips #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_mips +#define qemu_ram_block_from_host qemu_ram_block_from_host_mips #define qemu_ram_foreach_block qemu_ram_foreach_block_mips #define qemu_ram_free qemu_ram_free_mips #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_mips +#define qemu_ram_get_idstr qemu_ram_get_idstr_mips #define qemu_ram_ptr_length qemu_ram_ptr_length_mips #define qemu_ram_remap qemu_ram_remap_mips #define qemu_ram_resize qemu_ram_resize_mips diff --git a/qemu/mips64.h b/qemu/mips64.h index cad2cd26..e5bac112 100644 --- a/qemu/mips64.h +++ b/qemu/mips64.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_mips64 #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_mips64 #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_mips64 +#define qemu_ram_block_from_host qemu_ram_block_from_host_mips64 #define qemu_ram_foreach_block qemu_ram_foreach_block_mips64 #define qemu_ram_free qemu_ram_free_mips64 #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_mips64 +#define qemu_ram_get_idstr qemu_ram_get_idstr_mips64 #define qemu_ram_ptr_length qemu_ram_ptr_length_mips64 #define qemu_ram_remap qemu_ram_remap_mips64 #define qemu_ram_resize qemu_ram_resize_mips64 diff --git a/qemu/mips64el.h b/qemu/mips64el.h index bda5fe07..554937c4 100644 --- a/qemu/mips64el.h +++ b/qemu/mips64el.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_mips64el #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_mips64el #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_mips64el +#define qemu_ram_block_from_host qemu_ram_block_from_host_mips64el #define qemu_ram_foreach_block qemu_ram_foreach_block_mips64el #define qemu_ram_free qemu_ram_free_mips64el #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_mips64el +#define qemu_ram_get_idstr qemu_ram_get_idstr_mips64el #define qemu_ram_ptr_length qemu_ram_ptr_length_mips64el #define qemu_ram_remap qemu_ram_remap_mips64el #define qemu_ram_resize qemu_ram_resize_mips64el diff --git a/qemu/mipsel.h b/qemu/mipsel.h index 9dc605c3..8eed6fa4 100644 --- a/qemu/mipsel.h +++ b/qemu/mipsel.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_mipsel #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_mipsel #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_mipsel +#define qemu_ram_block_from_host qemu_ram_block_from_host_mipsel #define qemu_ram_foreach_block qemu_ram_foreach_block_mipsel #define qemu_ram_free qemu_ram_free_mipsel #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_mipsel +#define qemu_ram_get_idstr qemu_ram_get_idstr_mipsel #define qemu_ram_ptr_length qemu_ram_ptr_length_mipsel #define qemu_ram_remap qemu_ram_remap_mipsel #define qemu_ram_resize qemu_ram_resize_mipsel diff --git a/qemu/powerpc.h b/qemu/powerpc.h index 33ad67b6..c3cea22c 100644 --- a/qemu/powerpc.h +++ b/qemu/powerpc.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_powerpc #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_powerpc #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_powerpc +#define qemu_ram_block_from_host qemu_ram_block_from_host_powerpc #define qemu_ram_foreach_block qemu_ram_foreach_block_powerpc #define qemu_ram_free qemu_ram_free_powerpc #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_powerpc +#define qemu_ram_get_idstr qemu_ram_get_idstr_powerpc #define qemu_ram_ptr_length qemu_ram_ptr_length_powerpc #define qemu_ram_remap qemu_ram_remap_powerpc #define qemu_ram_resize qemu_ram_resize_powerpc diff --git a/qemu/sparc.h b/qemu/sparc.h index 4f7437b2..1677b1a4 100644 --- a/qemu/sparc.h +++ b/qemu/sparc.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_sparc #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_sparc #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_sparc +#define qemu_ram_block_from_host qemu_ram_block_from_host_sparc #define qemu_ram_foreach_block qemu_ram_foreach_block_sparc #define qemu_ram_free qemu_ram_free_sparc #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_sparc +#define qemu_ram_get_idstr qemu_ram_get_idstr_sparc #define qemu_ram_ptr_length qemu_ram_ptr_length_sparc #define qemu_ram_remap qemu_ram_remap_sparc #define qemu_ram_resize qemu_ram_resize_sparc diff --git a/qemu/sparc64.h b/qemu/sparc64.h index 4347750e..d8af9602 100644 --- a/qemu/sparc64.h +++ b/qemu/sparc64.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_sparc64 #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_sparc64 #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_sparc64 +#define qemu_ram_block_from_host qemu_ram_block_from_host_sparc64 #define qemu_ram_foreach_block qemu_ram_foreach_block_sparc64 #define qemu_ram_free qemu_ram_free_sparc64 #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_sparc64 +#define qemu_ram_get_idstr qemu_ram_get_idstr_sparc64 #define qemu_ram_ptr_length qemu_ram_ptr_length_sparc64 #define qemu_ram_remap qemu_ram_remap_sparc64 #define qemu_ram_resize qemu_ram_resize_sparc64 diff --git a/qemu/x86_64.h b/qemu/x86_64.h index 6766b97f..be478157 100644 --- a/qemu/x86_64.h +++ b/qemu/x86_64.h @@ -2436,9 +2436,11 @@ #define qemu_ram_alloc qemu_ram_alloc_x86_64 #define qemu_ram_alloc_from_ptr qemu_ram_alloc_from_ptr_x86_64 #define qemu_ram_alloc_resizeable qemu_ram_alloc_resizeable_x86_64 +#define qemu_ram_block_from_host qemu_ram_block_from_host_x86_64 #define qemu_ram_foreach_block qemu_ram_foreach_block_x86_64 #define qemu_ram_free qemu_ram_free_x86_64 #define qemu_ram_free_from_ptr qemu_ram_free_from_ptr_x86_64 +#define qemu_ram_get_idstr qemu_ram_get_idstr_x86_64 #define qemu_ram_ptr_length qemu_ram_ptr_length_x86_64 #define qemu_ram_remap qemu_ram_remap_x86_64 #define qemu_ram_resize qemu_ram_resize_x86_64