29namespace L4Re {
namespace Util {
31template<
typename DERIVED,
typename Dbg>
35 DERIVED *rm() {
return static_cast<DERIVED*
>(
this); }
36 DERIVED
const *rm()
const {
return static_cast<DERIVED
const *
>(
this); }
43 long op_attach(L4Re::Rm::Rights,
l4_addr_t &_start,
44 unsigned long size, Rm::Flags flags,
48 typename DERIVED::Dataspace ds;
52 if (
long r = rm()->validate_ds
53 (
static_cast<DERIVED*
>(
this)->server_iface(), ds_cap,
54 flags.region_flags(), &ds))
64 Rm::Region_flags r_flags = flags.region_flags();
65 Rm::Attach_flags a_flags = flags.attach_flags();
67 typename DERIVED::Region_handler handler(ds, client_cap_idx, offs, r_flags);
68 start =
l4_addr_t(rm()->attach(
reinterpret_cast<void*
>(start), size,
69 handler, a_flags, align));
81 long op_free_area(L4Re::Rm::Rights,
l4_addr_t start)
83 if (!rm()->detach_area(start))
92 long op_find(L4Re::Rm::Rights,
l4_addr_t &addr,
unsigned long &size,
93 L4Re::Rm::Flags &flags, L4Re::Rm::Offset &offset,
96 if (!DERIVED::Have_find)
99 Rm::Flags flag_area { 0 };
101 typename DERIVED::Node r = rm()->find(Region(addr, addr + size -1));
104 r = rm()->area_find(Region(addr, addr + size - 1));
110 addr = r->first.start();
111 size = r->first.end() + 1 - addr;
113 flags = r->second.flags() | flag_area;
114 offset = r->second.offset();
122 long op_detach(L4Re::Rm::Rights,
l4_addr_t addr,
123 unsigned long size,
unsigned flags,
128 typename DERIVED::Region_handler h;
129 int err = rm()->detach(
reinterpret_cast<void*
>(addr), size, flags, &r, &h);
146 mem_cap = h.client_cap_idx();
153 long op_reserve_area(L4Re::Rm::Rights,
l4_addr_t &start,
unsigned long size,
154 L4Re::Rm::Flags flags,
unsigned char align)
156 start = rm()->attach_area(start, size, flags, align);
165 long op_get_regions(L4Re::Rm::Rights,
l4_addr_t addr,
168 typename DERIVED::Node r;
170 while ((r = rm()->lower_bound(Region(addr))))
173 x.start = r->first.start();
174 x.end = r->first.end();
176 if (++num >= regions.max)
179 if (x.end >= rm()->max_addr())
189 long op_get_areas(L4Re::Rm::Rights,
l4_addr_t addr,
192 typename DERIVED::Node r;
194 while ((r = rm()->lower_bound_area(Region(addr))))
197 x.start = r->first.start();
198 x.end = r->first.end();
200 if (++num >= areas.max)
203 if (x.end >= rm()->max_addr())
233 Dbg(Dbg::Server).printf(
"page fault: %lx pc=%lx\n", addr, pc);
235 bool need_w = addr & 2;
236 bool need_x = addr & 4;
238 typename DERIVED::Node n = rm()->find(addr);
240 if (!n || !n->second.memory())
242 Dbg(Dbg::Warn,
"rm").printf(
"unhandled %s page fault at 0x%lx pc=0x%lx\n",
244 need_x ?
"instruction" :
"read", addr, pc);
251 Dbg(Dbg::Warn,
"rm").printf(
"write page fault in readonly region at 0x%lx pc=0x%lx\n",
259 Dbg(Dbg::Warn,
"rm").printf(
"instruction page fault in non-exec region at 0x%lx pc=0x%lx\n",
265 typename DERIVED::Region_handler::Ops::Map_result map_res;
266 if (
int err = n->second.map(addr, n->first, need_w, &map_res))
268 Dbg(Dbg::Warn,
"rm").printf(
"mapping for page fault failed with error %d at 0x%lx pc=0x%lx\n",
274 pager_set_result(&fp, map_res);
Range Area
An area is a range of virtual addresses which is reserved, see L4Re::Rm::reserve_area().
Range Region
A region is a range of virtual addresses which is backed by a dataspace.
C++ interface for capabilities.
unsigned long l4_umword_t
Unsigned machine word.
unsigned long l4_addr_t
Address type.
unsigned long l4_cap_idx_t
Capability selector type.
@ L4_INVALID_CAP
Invalid capability selector.
@ L4_ENOENT
No such entity.
@ L4_EACCESS
Permission denied.
@ L4_EINVAL
Invalid argument.
@ L4_EADDRNOTAVAIL
Address not available.
l4_addr_t l4_trunc_page(l4_addr_t address) L4_NOTHROW
Round an address down to the next lower page boundary.
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.
#define L4_PAGESIZE
Minimal page size (in bytes).
@ L4_INVALID_ADDR
Invalid address.
Common L4 ABI Data Types.
@ Reserved
Region is reserved (blocked)
@ In_area
Search only in area, or map into area.
Attribute for defining an optional RPC argument.
Dynamically sized output array of type T.