diff --git a/repos/base-nova/src/core/ram_session_support.cc b/repos/base-nova/src/core/ram_session_support.cc index 1fad96dbb..12118ac53 100644 --- a/repos/base-nova/src/core/ram_session_support.cc +++ b/repos/base-nova/src/core/ram_session_support.cc @@ -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(Thread_base::myself()->utcb()); - const Nova::Rights rights(true, true, true); - - addr_t const virt_addr = reinterpret_cast(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) diff --git a/repos/base/src/core/ram_session_component.cc b/repos/base/src/core/ram_session_component.cc index a4272cfc5..249c6dd19 100644 --- a/repos/base/src/core/ram_session_component.cc +++ b/repos/base/src/core/ram_session_component.cc @@ -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);