L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
rm_impl.h
Go to the documentation of this file.
1
5/*
6 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7 * Alexander Warg <warg@os.inf.tu-dresden.de>
8 * economic rights: Technische Universität Dresden (Germany)
9 *
10 * License: see LICENSE.spdx (in this directory or the directories above)
11 */
12#include <l4/bid_config.h>
13#include <l4/re/rm>
14#include <l4/re/dataspace>
15
16#include <l4/sys/cxx/ipc_client>
17
18#include <l4/sys/task>
19#include <l4/sys/err.h>
20
28
29namespace L4Re
30{
31
32long
33Rm::attach(l4_addr_t *start, unsigned long size, Rm::Flags flags,
34 L4::Ipc::Cap<Dataspace> mem, Rm::Offset offs,
35 unsigned char align, L4::Cap<L4::Task> const task) const noexcept
36{
37 if (((flags & F::Rights_mask) == Flags(0)) || (flags & F::Reserved))
39
40 long e = attach_t::call(c(), start, size, flags, mem, offs, align, mem.cap().cap());
41 if (e < 0)
42 return e;
43
44#ifdef CONFIG_MMU
45 if ((flags & (F::Eager_map | F::No_eager_map)) == F::Eager_map)
46#else
47 if (!(flags & F::No_eager_map) && mem.is_valid())
48#endif
49 e = mem.cap()->map_region(offs, map_flags(flags), *start, *start + size,
50 task);
51
52 return e;
53}
54
55int
56Rm::detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
57 L4::Cap<L4::Task> task, unsigned flags) const noexcept
58{
59 l4_addr_t rstart = 0, rsize = 0;
61 long e = detach_t::call(c(), start, size, flags, rstart, rsize, mem_cap);
62 if (L4_UNLIKELY(e < 0))
63 return e;
64
65 if (mem)
66 *mem = L4::Cap<L4Re::Dataspace>(mem_cap);
67
68 if (!task.is_valid())
69 return e;
70
71 rsize = l4_round_page(rsize);
72 unsigned order = L4_LOG2_PAGESIZE;
73 unsigned long sz = (1UL << order);
74 for (unsigned long p = rstart; rsize; p += sz, rsize -= sz)
75 {
76 while (sz > rsize)
77 {
78 --order;
79 sz >>= 1;
80 }
81
82 for (;;)
83 {
84 unsigned long m = sz << 1;
85 if (m > rsize)
86 break;
87
88 if (p & (m - 1))
89 break;
90
91 ++order;
92 sz <<= 1;
93 }
94
95 task->unmap(l4_fpage(p, order, L4_FPAGE_RWX),
97 }
98
99 return e;
100}
101}
long get_areas(l4_addr_t start, L4::Ipc::Ret_array< Range > areas)
Return the list of areas whose starting addresses are higher or equal to start in the address space m...
long free_area(l4_addr_t addr)
Free an area from the region map.
long get_regions(l4_addr_t start, L4::Ipc::Ret_array< Range > regions)
Return the list of regions whose starting addresses are higher or equal to start in the address space...
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:277
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:657
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) const noexcept
Attach a data space to a region.
Definition rm_impl.h:33
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:735
C++ interface for capabilities.
Definition capability.h:219
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:699
Dataspace interface.
Error codes.
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:157
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:684
@ L4_FPAGE_RWX
Read-write-execute flexpage.
Definition __l4_fpage.h:125
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.
Definition consts.h:477
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition consts.h:413
@ L4_FP_ALL_SPACES
Flag to tell the unmap operation to revoke permissions from all child mappings including the mapping ...
Definition consts.h:187
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:275
#define L4_RPC_DEF(name)
Generate the definition of an RPC stub.
Definition ipc_client:32
L4Re C++ Interfaces.
Definition cmd_control:14
Region mapper interface.
Common task related definitions.