Skip to contentSkip to conversation

memory: Forbid memory_region_set_address() on AS root

PATCH In review Philippe Mathieu-Daudé 1 participant 2 messages Apr 17, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 memory: Forbid memory_region_set_address() on AS root

To be sure an AddressSpace is zero-based, forbid changing base address of MemoryRegion used as AddressSpace container.

---
Based-on: <[email protected]>

---
 softmmu/memory.c | 1 +
 1 file changed, 1 insertion(+)
softmmu/memory.c +1 -0
index 409bcaec7f5..73c0e6f84f5 100644
@@ -2522,6 +2522,7 @@ static void memory_region_readd_subregion(MemoryRegion *mr)
 
 void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
 {
+    assert(!mr->is_root_mr);
     if (addr != mr->addr) {
         mr->addr = addr;
         memory_region_readd_subregion(mr);
Signature · 1 line
2.26.3
#1 lore raw
Quoted 15 lines · Philippe Mathieu-Daudé

To be sure an AddressSpace is zero-based, forbid changing base address of MemoryRegion used as AddressSpace container.

---
Based-on: <[email protected]>

---
 softmmu/memory.c | 1 +
 1 file changed, 1 insertion(+)
softmmu/memory.c +0 -0
index 409bcaec7f5..73c0e6f84f5 100644

softmmu/memory.c static void memory_region_readd_subregion(MemoryRegion *mr) · line 2525

Quoted 4 lines
softmmu/memory.c +1 -0
@@ -2522,6 +2522,7 @@ static void memory_region_readd_subregion(MemoryRegion *mr)
 
 void memory_region_set_address(MemoryRegion *mr, hwaddr addr)
 {
+    assert(!mr->is_root_mr);

Hmm to not discriminate the API usage, maybe safer as:

       assert(!(addr && mr->is_root_mr));
Quoted 4 lines
softmmu/memory.c +0 -0
     if (addr != mr->addr) {
         mr->addr = addr;
         memory_region_readd_subregion(mr);