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 * This file is part of TUD:OS and distributed under the terms of the
11 * GNU General Public License 2.
12 * Please see the COPYING-GPL-2 file for details.
13 *
14 * As a special exception, you may use this file as part of a free software
15 * library without restriction. Specifically, if other files instantiate
16 * templates or use macros or inline functions from this file, or you compile
17 * this file and link it with other files to produce an executable, this
18 * file does not by itself cause the resulting executable to be covered by
19 * the GNU General Public License. This exception does not however
20 * invalidate any other reasons why the executable file might be covered by
21 * the GNU General Public License.
22 */
23#include <l4/bid_config.h>
24#include <l4/re/rm>
25#include <l4/re/dataspace>
26
27#include <l4/sys/cxx/ipc_client>
28
29#include <l4/sys/task>
30#include <l4/sys/err.h>
31
39
40namespace L4Re
41{
42
43long
44Rm::attach(l4_addr_t *start, unsigned long size, Rm::Flags flags,
45 L4::Ipc::Cap<Dataspace> mem, Rm::Offset offs,
46 unsigned char align, L4::Cap<L4::Task> const task) const noexcept
47{
48 if (((flags & F::Rights_mask) == Flags(0)) || (flags & F::Reserved))
50
51 long e = attach_t::call(c(), start, size, flags, mem, offs, align, mem.cap().cap());
52 if (e < 0)
53 return e;
54
55#ifdef CONFIG_MMU
56 if ((flags & (F::Eager_map | F::No_eager_map)) == F::Eager_map)
57#else
58 if (!(flags & F::No_eager_map) && mem.is_valid())
59#endif
60 e = mem.cap()->map_region(offs, map_flags(flags), *start, *start + size,
61 task);
62
63 return e;
64}
65
66int
67Rm::detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
68 L4::Cap<L4::Task> task, unsigned flags) const noexcept
69{
70 l4_addr_t rstart = 0, rsize = 0;
72 long e = detach_t::call(c(), start, size, flags, rstart, rsize, mem_cap);
73 if (L4_UNLIKELY(e < 0))
74 return e;
75
76 if (mem)
77 *mem = L4::Cap<L4Re::Dataspace>(mem_cap);
78
79 if (!task.is_valid())
80 return e;
81
82 rsize = l4_round_page(rsize);
83 unsigned order = L4_LOG2_PAGESIZE;
84 unsigned long sz = (1UL << order);
85 for (unsigned long p = rstart; rsize; p += sz, rsize -= sz)
86 {
87 while (sz > rsize)
88 {
89 --order;
90 sz >>= 1;
91 }
92
93 for (;;)
94 {
95 unsigned long m = sz << 1;
96 if (m > rsize)
97 break;
98
99 if (p & (m - 1))
100 break;
101
102 ++order;
103 sz <<= 1;
104 }
105
106 task->unmap(l4_fpage(p, order, L4_FPAGE_RWX),
108 }
109
110 return e;
111}
112}
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:288
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:668
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:44
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:746
C++ interface for capabilities.
Definition capability.h:219
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:563
Dataspace interface.
Error codes.
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:359
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:168
l4_fpage_t l4_fpage(l4_addr_t address, unsigned int size, unsigned char rights) L4_NOTHROW
Create a memory flex page.
Definition __l4_fpage.h:668
@ L4_FPAGE_RWX
Read-write-execute flex page.
Definition __l4_fpage.h:131
l4_addr_t l4_round_page(l4_addr_t address) L4_NOTHROW
Round address up to the next page.
Definition consts.h:462
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition consts.h:398
@ L4_FP_ALL_SPACES
Flag to tell the unmap operation to revoke permissions from all child mappings including the mapping ...
Definition consts.h:198
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:296
#define L4_RPC_DEF(name)
Generate the definition of an RPC stub.
Definition ipc_client:43
L4Re C++ Interfaces.
Definition l4re.dox:17
Region mapper interface.
Common task related definitions.