L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
dataspace_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/re/dataspace>
24#include <l4/sys/cxx/ipc_client>
25#include <l4/sys/cxx/consts>
26
32
33namespace L4Re {
34
35
36long
37Dataspace::__map(Dataspace::Offset offset, unsigned char *size,
38 Dataspace::Flags flags,
39 Dataspace::Map_addr local_addr,
40 L4::Cap<L4::Task> dst) const noexcept
41{
42 Map_addr spot = local_addr & ~(~0ULL << l4_umword_t(*size));
43 Map_addr base = local_addr & (~0ULL << l4_umword_t(*size));
44 L4::Ipc::Rcv_fpage r = L4::Ipc::Rcv_fpage::mem(base, *size, 0, dst);
45
47 long err = map_t::call(c(), offset, spot, flags, r, fp, l4_utcb());
48 if (L4_UNLIKELY(err < 0))
49 return err;
50
51 *size = fp.rcv_order();
52 return err;
53}
54
55long
56Dataspace::map_region(Dataspace::Offset offset, Dataspace::Flags flags,
57 Dataspace::Map_addr min_addr,
58 Dataspace::Map_addr max_addr,
59 L4::Cap<L4::Task> dst) const noexcept
60{
61 min_addr = L4::trunc_page(min_addr);
62 max_addr = L4::round_page(max_addr);
63 unsigned char order = L4_LOG2_PAGESIZE;
64
65 long err = 0;
66
67 while (min_addr < max_addr)
68 {
69 unsigned char order_mapped;
70 order_mapped = order
71 = L4::max_order(order, min_addr, min_addr, max_addr, min_addr);
72
73 err = __map(offset, &order_mapped, flags, min_addr, dst);
74 if (L4_UNLIKELY(err < 0))
75 return err;
76
77 if (order > order_mapped)
78 order = order_mapped;
79
80 min_addr += Map_addr(1) << order;
81 offset += Map_addr(1) << order;
82
83 if (min_addr >= max_addr)
84 return 0;
85
86 while (min_addr != L4::trunc_order(min_addr, order)
87 || max_addr < L4::round_order(min_addr + 1, order))
88 --order;
89 }
90
91 return 0;
92}
93
94
95long
96Dataspace::map(Dataspace::Offset offset, Dataspace::Flags flags,
97 Dataspace::Map_addr local_addr,
98 Dataspace::Map_addr min_addr,
99 Dataspace::Map_addr max_addr,
100 L4::Cap<L4::Task> dst) const noexcept
101{
102 min_addr = L4::trunc_page(min_addr);
103 max_addr = L4::round_page(max_addr);
104 local_addr = L4::trunc_page(local_addr);
105 unsigned char order
106 = L4::max_order(L4_LOG2_PAGESIZE, local_addr, min_addr, max_addr, local_addr);
107
108 return __map(offset, &order, flags, local_addr, dst);
109}
110
111Dataspace::Size
112Dataspace::size() const noexcept
113{
114 Stats stats = Stats();
115 int err = info(&stats);
116 if (err < 0)
117 return 0;
118 return stats.size;
119}
120
121Dataspace::Flags
122Dataspace::flags() const noexcept
123{
124 Stats stats = Stats();
125 int err = info(&stats);
126 if (err < 0)
127 return Flags(0);
128 return stats.flags;
129}
130
131};
long copy_in(Offset dst_offs, L4::Ipc::Cap< Dataspace > src, Offset src_offs, Size size)
Copy contents from another dataspace.
Size size() const noexcept
Get size of a dataspace.
Flags flags() const noexcept
Get flags of the dataspace.
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.
long map_info(l4_addr_t *, l4_addr_t *)
Get mapping range of dataspace.
Definition dataspace:315
long info(Stats *stats)
Get information on the dataspace.
long clear(Offset offset, Size size)
Clear parts of a dataspace.
long allocate(Offset offset, Size size)
Allocate a range in the dataspace.
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 flex-page mapping from the dataspace.
C++ interface for capabilities.
Definition capability.h:219
Rcv flex-page.
Definition ipc_types:460
Send flex-page.
Definition ipc_types:408
Dataspace interface.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition consts.h:398
l4_utcb_t * l4_utcb(void) L4_NOTHROW L4_PURE
Get the UTCB address.
Definition utcb.h:340
#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
constexpr T round_order(T val, unsigned char order)
Round a value up so the given number of lsb is zero.
Definition consts:32
constexpr T trunc_order(T val, unsigned char order)
Round a value down so the given number of lsb is zero.
Definition consts:18
Information about the dataspace.
Definition dataspace:137