mirror of
https://github.com/yuzu-emu/unicorn.git
synced 2025-02-25 19:36:50 +00:00
memory: Store physical root MR in FlatView
Address spaces get to keep a root MR (alias or not) but FlatView stores the actual MR as this is going to be used later on to decide whether to share a particular FlatView or not. Backports commit 89c177bbdd6cf8e50b3fd4831697d50e195d6432 from qemu
This commit is contained in:
parent
d9bc1bcc8c
commit
037d039a4d
|
@ -261,6 +261,7 @@ struct FlatView {
|
||||||
unsigned nr;
|
unsigned nr;
|
||||||
unsigned nr_allocated;
|
unsigned nr_allocated;
|
||||||
struct AddressSpaceDispatch *dispatch;
|
struct AddressSpaceDispatch *dispatch;
|
||||||
|
MemoryRegion *root;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct AddressSpaceOps AddressSpaceOps;
|
typedef struct AddressSpaceOps AddressSpaceOps;
|
||||||
|
@ -289,12 +290,14 @@ static bool flatrange_equal(FlatRange *a, FlatRange *b)
|
||||||
&& a->readonly == b->readonly;
|
&& a->readonly == b->readonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
static FlatView *flatview_new(void)
|
static FlatView *flatview_new(MemoryRegion *mr_root)
|
||||||
{
|
{
|
||||||
FlatView *view;
|
FlatView *view;
|
||||||
|
|
||||||
view = g_new0(FlatView, 1);
|
view = g_new0(FlatView, 1);
|
||||||
view->ref = 1;
|
view->ref = 1;
|
||||||
|
view->root = mr_root;
|
||||||
|
memory_region_ref(mr_root);
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -327,6 +330,7 @@ static void flatview_destroy(FlatView *view)
|
||||||
memory_region_unref(view->ranges[i].mr);
|
memory_region_unref(view->ranges[i].mr);
|
||||||
}
|
}
|
||||||
g_free(view->ranges);
|
g_free(view->ranges);
|
||||||
|
memory_region_unref(view->root);
|
||||||
g_free(view);
|
g_free(view);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -682,12 +686,25 @@ static void render_memory_region(FlatView *view,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static MemoryRegion *memory_region_get_flatview_root(MemoryRegion *mr)
|
||||||
|
{
|
||||||
|
while (mr->alias && !mr->alias_offset &&
|
||||||
|
int128_ge(mr->size, mr->alias->size)) {
|
||||||
|
/* The alias is included in its entirety. Use it as
|
||||||
|
* the "real" root, so that we can share more FlatViews.
|
||||||
|
*/
|
||||||
|
mr = mr->alias;
|
||||||
|
}
|
||||||
|
|
||||||
|
return mr;
|
||||||
|
}
|
||||||
|
|
||||||
/* Render a memory topology into a list of disjoint absolute ranges. */
|
/* Render a memory topology into a list of disjoint absolute ranges. */
|
||||||
static FlatView *generate_memory_topology(MemoryRegion *mr)
|
static FlatView *generate_memory_topology(MemoryRegion *mr)
|
||||||
{
|
{
|
||||||
FlatView *view;
|
FlatView *view;
|
||||||
|
|
||||||
view = flatview_new();
|
view = flatview_new(mr);
|
||||||
|
|
||||||
if (mr) {
|
if (mr) {
|
||||||
render_memory_region(view, mr, int128_zero(),
|
render_memory_region(view, mr, int128_zero(),
|
||||||
|
@ -778,7 +795,8 @@ static void address_space_update_topology_pass(AddressSpace *as,
|
||||||
static void address_space_update_topology(AddressSpace *as)
|
static void address_space_update_topology(AddressSpace *as)
|
||||||
{
|
{
|
||||||
FlatView *old_view = address_space_get_flatview(as);
|
FlatView *old_view = address_space_get_flatview(as);
|
||||||
FlatView *new_view = generate_memory_topology(as->root);
|
MemoryRegion *physmr = memory_region_get_flatview_root(old_view->root);
|
||||||
|
FlatView *new_view = generate_memory_topology(physmr);
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
new_view->dispatch = address_space_dispatch_new(as->uc, new_view);
|
new_view->dispatch = address_space_dispatch_new(as->uc, new_view);
|
||||||
|
@ -1813,7 +1831,7 @@ void address_space_init(struct uc_struct *uc, AddressSpace *as, MemoryRegion *ro
|
||||||
as->uc = uc;
|
as->uc = uc;
|
||||||
as->root = root;
|
as->root = root;
|
||||||
as->malloced = false;
|
as->malloced = false;
|
||||||
as->current_map = flatview_new();
|
as->current_map = flatview_new(root);
|
||||||
QTAILQ_INIT(&as->listeners);
|
QTAILQ_INIT(&as->listeners);
|
||||||
QTAILQ_INSERT_TAIL(&uc->address_spaces, as, address_spaces_link);
|
QTAILQ_INSERT_TAIL(&uc->address_spaces, as, address_spaces_link);
|
||||||
as->name = g_strdup(name ? name : "anonymous");
|
as->name = g_strdup(name ? name : "anonymous");
|
||||||
|
|
Loading…
Reference in a new issue