1.1 --- a/pkg/devices/util/src/dataspace.cc Sat Jun 10 23:59:44 2023 +0200
1.2 +++ b/pkg/devices/util/src/dataspace.cc Sun Jun 11 15:42:11 2023 +0200
1.3 @@ -19,46 +19,28 @@
1.4 * Boston, MA 02110-1301, USA
1.5 */
1.6
1.7 -#include <l4/re/dataspace>
1.8 -#include <l4/re/env>
1.9 -#include <l4/re/rm>
1.10 -#include <l4/re/util/cap_alloc>
1.11 +#include <l4/re/c/mem_alloc.h>
1.12 +
1.13 +#include <ipc/mem_ipc.h>
1.14
1.15 #include "dataspace.h"
1.16
1.17 -/*
1.18 -Allocate and map a region containing data, using the given mem_size to indicate
1.19 -the required region size, along with a pointer to be set to the allocated
1.20 -region. Return a capability which may be invalid if allocation or mapping
1.21 -failed.
1.22 +
1.23 +
1.24 +/* Allocate and map a region containing data, using the given mem_size to
1.25 + indicate the required region size, along with a pointer to be set to the
1.26 + allocated region. Return a capability which may be invalid if allocation or
1.27 + mapping failed.
1.28 */
1.29
1.30 -L4::Cap<L4Re::Dataspace> allocate_data(l4_size_t mem_size, void **allocated)
1.31 +l4re_ds_t allocate_data(l4_size_t mem_size, void **allocated)
1.32 {
1.33 - /* Obtain a capability for the allocated memory. */
1.34 -
1.35 - L4::Cap<L4Re::Dataspace> mem = L4Re::Util::cap_alloc.alloc<L4Re::Dataspace>();
1.36 -
1.37 - if (!mem.is_valid())
1.38 - return L4::Cap<L4Re::Dataspace>::Invalid;
1.39 -
1.40 - /* Allocate memory for the data. */
1.41 + l4re_ds_t mem;
1.42
1.43 - if (L4Re::Env::env()->mem_alloc()->alloc(mem_size, mem, L4Re::Mem_alloc::Continuous))
1.44 - {
1.45 - L4Re::Util::cap_alloc.free(mem);
1.46 - return L4::Cap<L4Re::Dataspace>::Invalid;
1.47 - }
1.48 -
1.49 - /* Map the memory to a virtual address. */
1.50 + /* Allocate memory for the data and map it to a virtual address. */
1.51
1.52 - if (L4Re::Env::env()->rm()->attach(allocated, mem->size(),
1.53 - L4Re::Rm::F::Search_addr | L4Re::Rm::F::RW,
1.54 - L4::Ipc::make_cap_rw(mem)))
1.55 - {
1.56 - L4Re::Util::cap_alloc.free(mem);
1.57 - return L4::Cap<L4Re::Dataspace>::Invalid;
1.58 - }
1.59 + if (ipc_allocate_align(mem_size, L4RE_MA_CONTINUOUS, 0, allocated, &mem))
1.60 + return L4_INVALID_CAP;
1.61
1.62 return mem;
1.63 }