Loading...
Searching...
No Matches
dataspace_impl.h
Go to the documentation of this file.
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#include <l4/re/dataspace>
#include <l4/sys/cxx/ipc_client>
#include <l4/sys/cxx/consts>
L4_RPC_DEF(L4Re::Dataspace::clear);
L4_RPC_DEF(L4Re::Dataspace::allocate);
L4_RPC_DEF(L4Re::Dataspace::copy_in);
L4_RPC_DEF(L4Re::Dataspace::info);
L4_RPC_DEF(L4Re::Dataspace::map_info);
namespace L4Re {
long
Dataspace::__map(Dataspace::Offset offset, unsigned char *size,
Dataspace::Flags flags,
Dataspace::Map_addr local_addr,
L4::Cap<L4::Task> dst) const noexcept
{
Map_addr spot = local_addr & ~(~0ULL << l4_umword_t(*size));
Map_addr base = local_addr & (~0ULL << l4_umword_t(*size));
L4::Ipc::Rcv_fpage r = L4::Ipc::Rcv_fpage::mem(base, *size, 0, dst);
L4::Ipc::Snd_fpage fp;
long err = map_t::call(c(), offset, spot, flags, r, fp, l4_utcb());
if (L4_UNLIKELY(err < 0))
return err;
*size = fp.rcv_order();
return err;
}
long
Dataspace::map_region(Dataspace::Offset offset, Dataspace::Flags flags,
Dataspace::Map_addr min_addr,
Dataspace::Map_addr max_addr,
L4::Cap<L4::Task> dst) const noexcept
{
min_addr = L4::trunc_page(min_addr);
max_addr = L4::round_page(max_addr);
unsigned char order = L4_LOG2_PAGESIZE;
long err = 0;
while (min_addr < max_addr)
{
unsigned char order_mapped;
order_mapped = order
= L4::max_order(order, min_addr, min_addr, max_addr, min_addr);
err = __map(offset, &order_mapped, flags, min_addr, dst);
if (L4_UNLIKELY(err < 0))
return err;
if (order > order_mapped)
order = order_mapped;
min_addr += Map_addr(1) << order;
offset += Map_addr(1) << order;
if (min_addr >= max_addr)
return 0;
while (min_addr != L4::trunc_order(min_addr, order)
|| max_addr < L4::round_order(min_addr + 1, order))
--order;
}
return 0;
}
long
Dataspace::map(Dataspace::Offset offset, Dataspace::Flags flags,
Dataspace::Map_addr local_addr,
Dataspace::Map_addr min_addr,
Dataspace::Map_addr max_addr,
L4::Cap<L4::Task> dst) const noexcept
{
min_addr = L4::trunc_page(min_addr);
max_addr = L4::round_page(max_addr);
local_addr = L4::trunc_page(local_addr);
unsigned char order
= L4::max_order(L4_LOG2_PAGESIZE, local_addr, min_addr, max_addr, local_addr);
return __map(offset, &order, flags, local_addr, dst);
}
Dataspace::Size
Dataspace::size() const noexcept
{
Stats stats = Stats();
int err = info(&stats);
if (err < 0)
return 0;
return stats.size;
}
Dataspace::Flags
Dataspace::flags() const noexcept
{
Stats stats = Stats();
int err = info(&stats);
if (err < 0)
return Flags(0);
return stats.flags;
}
};
L4Re::Dataspace::map
long map(Offset offset, Flags flags, Map_addr local_addr, Map_addr min_addr, Map_addr max_addr, L4::Cap< L4::Task > dst=L4::Cap< L4::Task >::Invalid) const noexcept
Request a flexpage mapping from the dataspace.
Definition dataspace_impl.h:85
L4Re::Dataspace::copy_in
long copy_in(Offset dst_offs, L4::Ipc::Cap< Dataspace > src, Offset src_offs, Size size)
Copy contents from another dataspace.
L4Re::Dataspace::map_region
long map_region(Offset offset, Flags flags, Map_addr min_addr, Map_addr max_addr, L4::Cap< L4::Task > dst=L4::Cap< L4::Task >::Invalid) const noexcept
Map a part of a dataspace into a local memory area.
Definition dataspace_impl.h:45
L4Re::Dataspace::info
long info(Stats *stats)
Get information on the dataspace.
L4Re::Dataspace::map_info
long map_info(l4_addr_t *start_addr, l4_addr_t *end_addr)
Get mapping range of dataspace.
Definition dataspace:305
L4Re::Dataspace::size
Size size() const noexcept
Get size of a dataspace.
Definition dataspace_impl.h:101
L4Re::Dataspace::clear
long clear(Offset offset, Size size)
Clear parts of a dataspace.
L4Re::Dataspace::allocate
long allocate(Offset offset, Size size)
Allocate a range in the dataspace.
L4Re::Dataspace::flags
Flags flags() const noexcept
Get flags of the dataspace.
Definition dataspace_impl.h:111
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
L4::Ipc::Rcv_fpage::mem
static Rcv_fpage mem(l4_addr_t base, int order, l4_addr_t snd_base=0, L4::Cap< void > rcv_task=L4::Cap< void >::Invalid) noexcept
Construct a receive item for the memory space.
Definition ipc_types:594
L4::Ipc::Snd_fpage::rcv_order
unsigned rcv_order() const noexcept
(Defined for return items only.) Get log₂ size.
Definition ipc_types:465
dataspace
Dataspace interface.
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
L4_LOG2_PAGESIZE
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition consts.h:409
l4_utcb
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:346
L4_UNLIKELY
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:284
ipc_client
L4_RPC_DEF
#define L4_RPC_DEF(name)
Generate the definition of an RPC stub.
Definition ipc_client:32
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4::round_order
constexpr T round_order(T val, unsigned char order)
Round a value up so the given number of lsb is zero.
Definition consts:32
L4::trunc_order
constexpr T trunc_order(T val, unsigned char order)
Round a value down so the given number of lsb is zero.
Definition consts:18
L4Re::Dataspace::Stats
Information about the dataspace.
Definition dataspace:127
L4Re::Dataspace::Stats::size
Size size
size
Definition dataspace:128
L4Re::Dataspace::Stats::flags
Flags flags
flags
Definition dataspace:129