mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-11 21:32:57 +00:00
core: change order of _export_ds and _clear_ds
On seL4, we need to convert untyped memory to page frames before being able to use it as normal memory. There already exists the hook function '_export_ds' that is principally suitable for such tasks. It is currently solely used on Linux where we have to create a file for each dataspace. To make the hook useful also for seL4, we need to call _export_ds prior _clear_ds. Otherwise, we would try to clear memory that is still untyped.
This commit is contained in:
parent
a312d440c8
commit
4736488d99
@ -73,62 +73,7 @@ static inline void * alloc_region(Dataspace_component *ds, const size_t size)
|
||||
|
||||
void Ram_session_component::_clear_ds(Dataspace_component *ds)
|
||||
{
|
||||
const size_t page_rounded_size = (ds->size() + get_page_size() - 1) & get_page_mask();
|
||||
size_t pages = page_rounded_size >> get_page_size_log2();
|
||||
size_t virt_size = page_rounded_size;
|
||||
|
||||
void * virt_ptr = alloc_region(ds, virt_size);
|
||||
|
||||
/* if it's not possible to get it in one piece, try to get a smaller one */
|
||||
while (pages && !virt_ptr) {
|
||||
pages >>= 1;
|
||||
virt_size = pages << get_page_size_log2();
|
||||
virt_ptr = alloc_region(ds, virt_size);
|
||||
}
|
||||
|
||||
/* no free virtual region available ? */
|
||||
if (!virt_ptr) return;
|
||||
|
||||
Nova::Utcb * const utcb = reinterpret_cast<Nova::Utcb *>(Thread_base::myself()->utcb());
|
||||
const Nova::Rights rights(true, true, true);
|
||||
|
||||
addr_t const virt_addr = reinterpret_cast<addr_t>(virt_ptr);
|
||||
addr_t phys = ds->phys_addr();
|
||||
|
||||
if (verbose_ram_ds)
|
||||
printf("-- map - ram ds to be cleared phys 0x%8lx+0x%8zx\n",
|
||||
ds->phys_addr(), page_rounded_size);
|
||||
|
||||
while (phys < ds->phys_addr() + page_rounded_size) {
|
||||
|
||||
if (verbose_ram_ds)
|
||||
printf("-- map - clear phys 0x%8lx+0x%8zx\n", phys, virt_size);
|
||||
|
||||
/* map the dataspace's physical pages to core local addresses */
|
||||
if (map_local(utcb, phys, virt_addr, virt_size >> get_page_size_log2(),
|
||||
rights, true))
|
||||
{
|
||||
PERR("map failed - ram ds size=0x%8zx phys 0x%8lx, core-local 0x%8p",
|
||||
virt_size, phys, virt_ptr);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
memset(virt_ptr, 0, virt_size);
|
||||
|
||||
unmap_local(utcb, virt_addr, virt_size >> get_page_size_log2());
|
||||
|
||||
phys += virt_size;
|
||||
|
||||
if (page_rounded_size - virt_size < phys - ds->phys_addr())
|
||||
virt_size = ds->phys_addr() + page_rounded_size - phys;
|
||||
}
|
||||
|
||||
/* free virtual region - don't use 'virt_size' - use 'pages' */
|
||||
platform()->region_alloc()->free(virt_ptr, pages << get_page_size_log2());
|
||||
|
||||
/* signal that we cleared the memory successfully */
|
||||
ds->assign_core_local_addr(0);
|
||||
memset((void *)ds->core_local_addr(), 0, ds->size());
|
||||
}
|
||||
|
||||
|
||||
@ -136,10 +81,6 @@ void Ram_session_component::_export_ram_ds(Dataspace_component *ds) {
|
||||
|
||||
const size_t page_rounded_size = (ds->size() + get_page_size() - 1) & get_page_mask();
|
||||
|
||||
/* if clearing the pages failed don't give the pages out */
|
||||
if (!ds || ds->core_local_addr())
|
||||
throw Out_of_metadata();
|
||||
|
||||
/* allocate the virtual region contiguous for the dataspace */
|
||||
void * virt_ptr = alloc_region(ds, page_rounded_size);
|
||||
if (!virt_ptr)
|
||||
|
@ -181,13 +181,6 @@ Ram_dataspace_capability Ram_session_component::alloc(size_t ds_size, Cache_attr
|
||||
throw Out_of_metadata();
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill new dataspaces with zeros. For non-cached RAM dataspaces, this
|
||||
* function must also make sure to flush all cache lines related to the
|
||||
* address range used by the dataspace.
|
||||
*/
|
||||
_clear_ds(ds);
|
||||
|
||||
/* create native shared memory representation of dataspace */
|
||||
try {
|
||||
_export_ram_ds(ds);
|
||||
@ -200,6 +193,13 @@ Ram_dataspace_capability Ram_session_component::alloc(size_t ds_size, Cache_attr
|
||||
throw Quota_exceeded();
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill new dataspaces with zeros. For non-cached RAM dataspaces, this
|
||||
* function must also make sure to flush all cache lines related to the
|
||||
* address range used by the dataspace.
|
||||
*/
|
||||
_clear_ds(ds);
|
||||
|
||||
if (verbose)
|
||||
PDBG("ds_size=%zu, used_quota=%zu quota_limit=%zu",
|
||||
ds_size, used_quota(), _quota_limit);
|
||||
|
Loading…
x
Reference in New Issue
Block a user