Loading...
Searching...
No Matches
rm_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/bid_config.h>
#include <l4/re/rm>
#include <l4/re/dataspace>
#include <l4/sys/cxx/ipc_client>
#include <l4/sys/task>
#include <l4/sys/err.h>
L4_RPC_DEF(L4Re::Rm::reserve_area);
L4_RPC_DEF(L4Re::Rm::free_area);
L4_RPC_DEF(L4Re::Rm::attach);
L4_RPC_DEF(L4Re::Rm::detach);
L4_RPC_DEF(L4Re::Rm::get_regions);
L4_RPC_DEF(L4Re::Rm::get_areas);
L4_RPC_DEF(L4Re::Rm::find);
L4_RPC_DEF(L4Re::Rm::get_info);
namespace L4Re
{
long
Rm::attach(l4_addr_t *start, unsigned long size, Rm::Flags flags,
L4::Ipc::Cap<Dataspace> mem, Rm::Offset offs,
unsigned char align, L4::Cap<L4::Task> const task,
char const *name, Rm::Offset backing_offset) const noexcept
{
if ((flags & F::Rights_mask) == Flags(0)
|| (flags & (F::Reserved | F::Kernel)))
mem = L4::Ipc::Cap<L4Re::Dataspace>();
char const n = '\0';
long e = attach_t::call(c(), start, size, flags, mem, offs, align,
mem.cap().cap(), name ? name : &n, backing_offset);
if (e < 0)
return e;
#ifdef CONFIG_MMU
if ((flags & (F::Eager_map | F::No_eager_map)) == F::Eager_map)
#else
if (!(flags & F::No_eager_map) && mem.is_valid())
#endif
e = mem.cap()->map_region(offs, map_flags(flags), *start, *start + size,
task);
return e;
}
int
Rm::detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> task, unsigned flags) const noexcept
{
l4_addr_t rstart = 0, rsize = 0;
l4_cap_idx_t mem_cap = L4_INVALID_CAP;
long e = detach_t::call(c(), start, size, flags, rstart, rsize, mem_cap);
if (L4_UNLIKELY(e < 0))
return e;
if (mem)
*mem = L4::Cap<L4Re::Dataspace>(mem_cap);
if (!task.is_valid())
return e;
rsize = l4_round_page(rsize);
unsigned order = L4_LOG2_PAGESIZE;
unsigned long sz = (1UL << order);
for (unsigned long p = rstart; rsize; p += sz, rsize -= sz)
{
while (sz > rsize)
{
--order;
sz >>= 1;
}
for (;;)
{
unsigned long m = sz << 1;
if (m > rsize)
break;
if (p & (m - 1))
break;
++order;
sz <<= 1;
}
task->unmap(l4_fpage(p, order, L4_FPAGE_RWX),
L4_FP_ALL_SPACES);
}
return e;
}
}
L4Re::Rm::free_area
long free_area(l4_addr_t addr)
Free an area from the region map.
L4Re::Rm::reserve_area
long reserve_area(l4_addr_t *start, unsigned long size, Flags flags=Flags(0), unsigned char align=L4_PAGESHIFT) const noexcept
Reserve the given area in the region map.
Definition rm:280
L4Re::Rm::get_regions
long get_regions(l4_addr_t start, L4::Ipc::Ret_array< Region > regions)
Return the list of regions whose starting addresses are higher or equal to start in the address space...
L4Re::Rm::find
long find(l4_addr_t *addr, unsigned long *size, Offset *offset, L4Re::Rm::Flags *flags, L4::Cap< Dataspace > *m) noexcept
Find a region given an address and size.
Definition rm:672
L4Re::Rm::get_areas
long get_areas(l4_addr_t start, L4::Ipc::Ret_array< Area > areas)
Return the list of areas whose starting addresses are higher or equal to start in the address space m...
L4Re::Rm::attach
long attach(l4_addr_t *start, unsigned long size, Flags flags, L4::Ipc::Cap< Dataspace > mem, Offset offs=0, unsigned char align=L4_PAGESHIFT, L4::Cap< L4::Task > const task=L4::Cap< L4::Task >::Invalid, char const *name=nullptr, Offset backing_offset=0) const noexcept
Attach a data space to a region.
Definition rm_impl.h:34
L4Re::Rm::get_info
long get_info(l4_addr_t addr, L4::Ipc::String< char > &name, Offset &backing_offset)
Return auxiliary information of a region.
L4Re::Rm::detach
int detach(l4_addr_t addr, L4::Cap< Dataspace > *mem, L4::Cap< L4::Task > const &task=This_task) const noexcept
Detach and unmap a region from the address space.
Definition rm:765
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
L4::Ipc::Cap
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:699
L4::Kobject_t< Rm, L4::Pager, L4RE_PROTO_RM, L4::Type_info::Demand_t< 1 > >::c
L4::Cap< Class > c() const noexcept
Definition __typeinfo.h:769
dataspace
Dataspace interface.
err.h
Error codes.
l4_addr_t
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
L4_INVALID_CAP
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:153
l4_fpage
l4_fpage_t l4_fpage(l4_addr_t address, unsigned int order, unsigned char rights) L4_NOTHROW
Create a memory flexpage.
Definition __l4_fpage.h:703
L4_FPAGE_RWX
@ L4_FPAGE_RWX
Read-write-execute flexpage.
Definition __l4_fpage.h:125
l4_round_page
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.
Definition consts.h:473
L4_LOG2_PAGESIZE
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition consts.h:409
L4_FP_ALL_SPACES
@ L4_FP_ALL_SPACES
Flag to tell the unmap operation to revoke permissions from all child mappings including the mapping ...
Definition consts.h:183
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
rm
Region mapper interface.
L4Re::Rm::F::Rights_mask
@ Rights_mask
Region rights.
Definition rm:131
L4Re::Rm::F::Reserved
@ Reserved
Region is reserved (blocked).
Definition rm:152
L4Re::Rm::F::Kernel
@ Kernel
Kernel-provided memory (KUMEM).
Definition rm:146
L4Re::Rm::F::No_eager_map
@ No_eager_map
Prevent eager mapping of the attached data space.
Definition rm:120
L4Re::Rm::F::Eager_map
@ Eager_map
Eagerly map the attached data space in.
Definition rm:118
task
Common task related definitions.