[RFC v2 11/26] memory: Rename address_space_lookup_region and expose it to Rust
Zhao Liu <[email protected]> Wed, 8 Jul 2026 16:10:37 +0800
| Newsgroups | org.nongnu.qemu-rust,org.nongnu.qemu-devel |
|---|---|
| Message-ID | <[email protected]> |
address_space_lookup_region() returns a pointer to a MemoryRegionSection instead of a MemoryRegion. Therefore, rename it to address_space_lookup_section(). Add its declaration to memory.h so that bindgen can generate bindings for it. This interface will be used to implement GuestMemory::find_region() in the vm_memory crate. In addition, add its documentation in memory.h. Signed-off-by: Zhao Liu <[email protected]> --- include/system/memory.h | 21 +++++++++++++++++++++ system/physmem.c | 8 ++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/system/memory.h b/include/system/memory.h index bf5bfa7164fb..c32e3d01f825 100644 --- a/include/system/memory.h +++ b/include/system/memory.h @@ -948,6 +948,27 @@ static inline FlatView *address_space_to_flatview(const AddressSpace *as) return qatomic_rcu_read(&as->current_map); } +/** + * address_space_lookup_section: Find the MemoryRegionSection within a + * given #AddressSpaceDispatch. + * + * @d: The AddressSpaceDispatch to search within. + * @addr: The address to look up. + * @resolve_subpage: If 'true', resolve to a subpage section if the + * region is a subpage container. + * + * This function translates an address (@addr) into its corresponding + * #MemoryRegionSection within a given address space dispatch (@d). + * Must be called within an RCU critical section. + * + * Returns: + * A pointer to the #MemoryRegionSection. If the address is not + * mapped, this will be a pointer to the 'unassigned' section. + */ +MemoryRegionSection *address_space_lookup_section(AddressSpaceDispatch *d, + hwaddr addr, + bool resolve_subpage); + /** * flatview_ref: Atomically increment the reference count of a #FlatView. * diff --git a/system/physmem.c b/system/physmem.c index c21ea929153e..f807e60aa348 100644 --- a/system/physmem.c +++ b/system/physmem.c @@ -342,9 +342,9 @@ static MemoryRegionSection *phys_page_find(AddressSpaceDispatch *d, hwaddr addr) } /* Called from RCU critical section */ -static MemoryRegionSection *address_space_lookup_region(AddressSpaceDispatch *d, - hwaddr addr, - bool resolve_subpage) +MemoryRegionSection *address_space_lookup_section(AddressSpaceDispatch *d, + hwaddr addr, + bool resolve_subpage) { MemoryRegionSection *section = qatomic_read(&d->mru_section); subpage_t *subpage; @@ -370,7 +370,7 @@ address_space_translate_internal(AddressSpaceDispatch *d, hwaddr addr, hwaddr *x MemoryRegion *mr; Int128 diff; - section = address_space_lookup_region(d, addr, resolve_subpage); + section = address_space_lookup_section(d, addr, resolve_subpage); /* Compute offset within MemoryRegionSection */ addr -= section->offset_within_address_space; -- 2.34.1