L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
dataspace_svr
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>,
5 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
6 * economic rights: Technische Universität Dresden (Germany)
7 *
8 * This file is part of TUD:OS and distributed under the terms of the
9 * GNU General Public License 2.
10 * Please see the COPYING-GPL-2 file for details.
11 *
12 * As a special exception, you may use this file as part of a free software
13 * library without restriction. Specifically, if other files instantiate
14 * templates or use macros or inline functions from this file, or you compile
15 * this file and link it with other files to produce an executable, this
16 * file does not by itself cause the resulting executable to be covered by
17 * the GNU General Public License. This exception does not however
18 * invalidate any other reasons why the executable file might be covered by
19 * the GNU General Public License.
20 */
21#pragma once
22
23#include <cstring>
24#include <cstddef>
25#include <l4/sys/types.h>
26#include <l4/cxx/list>
27#include <l4/cxx/minmax>
28#include <l4/re/dataspace>
29#include <l4/re/dataspace-sys.h>
30#include <l4/sys/cxx/ipc_legacy>
31
32namespace L4Re { namespace Util {
33
41{
42private:
44public:
45 L4_RPC_LEGACY_DISPATCH(L4Re::Dataspace);
46
49
50 Dataspace_svr() noexcept
51 : _ds_start(0), _ds_size(0), _map_flags(Snd_fpage::Map),
52 _cache_flags(Snd_fpage::Cached)
53 {}
54
55 virtual ~Dataspace_svr() noexcept {}
56
70 int map(Dataspace::Offset offset,
71 Dataspace::Map_addr local_addr,
72 Dataspace::Flags flags,
73 Dataspace::Map_addr min_addr,
74 Dataspace::Map_addr max_addr,
75 L4::Ipc::Snd_fpage &memory);
76
89 virtual int map_hook(Dataspace::Offset offs,
90 Dataspace::Flags flags,
91 Dataspace::Map_addr min,
92 Dataspace::Map_addr max)
93 {
94 (void)offs; (void)flags; (void)min; (void)max;
95 return 0;
96 }
97
103 virtual void take() noexcept
104 {}
105
113 virtual unsigned long release() noexcept
114 { return 0; }
115
128 virtual long copy(l4_addr_t dst_offs, l4_umword_t src_id,
129 l4_addr_t src_offs, unsigned long size) noexcept
130 {
131 (void)dst_offs; (void)src_id; (void)src_offs; (void)size;
132 return -L4_ENODEV;
133 }
134
144 virtual long clear(unsigned long offs, unsigned long size) const noexcept;
145
157 virtual long allocate(l4_addr_t offset, l4_size_t size, unsigned access) noexcept
158 { (void)offset; (void)size; (void)access; return -L4_ENODEV; }
159
165 virtual unsigned long page_shift() const noexcept
166 { return L4_LOG2_PAGESIZE; }
167
173 virtual bool is_static() const noexcept
174 { return true; }
175
176
177 long op_map(L4Re::Dataspace::Rights rights,
178 L4Re::Dataspace::Offset offset,
179 L4Re::Dataspace::Map_addr spot,
180 L4Re::Dataspace::Flags flags,
182 {
183 auto rf = map_flags(rights);
184
185 if (!rf.w() && flags.w())
186 return -L4_EPERM;
187
188 return map(offset, spot, flags & rf, 0, ~0, fp);
189 }
190
191 long op_allocate(L4Re::Dataspace::Rights rights,
192 L4Re::Dataspace::Offset offset,
193 L4Re::Dataspace::Size size)
194 { return allocate(offset, size, rights & 3); }
195
196 long op_copy_in(L4Re::Dataspace::Rights rights,
197 L4Re::Dataspace::Offset dst_offs,
198 L4::Ipc::Snd_fpage const &src_cap,
199 L4Re::Dataspace::Offset src_offs,
200 L4Re::Dataspace::Size sz)
201 {
202 if (!src_cap.id_received())
203 return -L4_EINVAL;
204
205 if (!(rights & L4_CAP_FPAGE_W))
206 return -L4_EACCESS;
207
208 if (sz == 0)
209 return L4_EOK;
210
211 return copy(dst_offs, src_cap.data(), src_offs, sz);
212 }
213
214 long op_info(L4Re::Dataspace::Rights rights, L4Re::Dataspace::Stats &s)
215 {
216 s.size = size();
217 // only return writable if really writable
218 s.flags = Dataspace::Flags(0);
219 if (map_flags(rights).w())
221 return L4_EOK;
222 }
223
224 long op_clear(L4Re::Dataspace::Rights rights,
225 L4Re::Dataspace::Offset offset,
226 L4Re::Dataspace::Size size)
227 {
228 if (!map_flags(rights).w())
229 return -L4_EACCESS;
230
231 return clear(offset, size);
232 }
233
234
235protected:
236 unsigned long size() const noexcept
237 { return _ds_size; }
238 unsigned long map_flags() const noexcept
239 { return _map_flags; }
240 unsigned long page_size() const noexcept
241 { return 1UL << page_shift(); }
242 unsigned long round_size() const noexcept
243 { return l4_round_size(size(), page_shift()); }
244 bool check_limit(l4_addr_t offset) const noexcept
245 { return offset < round_size(); }
246
247 L4Re::Dataspace::Flags
248 map_flags(L4Re::Dataspace::Rights rights = L4_CAP_FPAGE_W) const noexcept
249 {
250 auto f = (_rw_flags & L4Re::Dataspace::Flags(0x0f)) | L4Re::Dataspace::F::Caching_mask;
251 if (!(rights & L4_CAP_FPAGE_W))
253
254 return f;
255 }
256
257protected:
258 void size(unsigned long size) noexcept { _ds_size = size; }
259
260 l4_addr_t _ds_start;
261 l4_size_t _ds_size;
262 Map_type _map_flags;
263 Cache_type _cache_flags;
264 L4Re::Dataspace::Flags _rw_flags;
265};
266
267}}
Interface for memory-like objects.
Definition dataspace:63
Dataspace server class.
Definition dataspace_svr:41
virtual unsigned long page_shift() const noexcept
Define the size of the flexpage to map.
virtual void take() noexcept
Take a reference to this dataspace.
int map(Dataspace::Offset offset, Dataspace::Map_addr local_addr, Dataspace::Flags flags, Dataspace::Map_addr min_addr, Dataspace::Map_addr max_addr, L4::Ipc::Snd_fpage &memory)
Map a region of the dataspace.
virtual long allocate(l4_addr_t offset, l4_size_t size, unsigned access) noexcept
Allocate a region within a dataspace.
virtual long clear(unsigned long offs, unsigned long size) const noexcept
Clear a region in the dataspace.
virtual int map_hook(Dataspace::Offset offs, Dataspace::Flags flags, Dataspace::Map_addr min, Dataspace::Map_addr max)
A hook that is called as the first operation in each map request.
Definition dataspace_svr:89
virtual unsigned long release() noexcept
Release a reference to this dataspace.
virtual long copy(l4_addr_t dst_offs, l4_umword_t src_id, l4_addr_t src_offs, unsigned long size) noexcept
Copy from src dataspace to this destination dataspace.
virtual bool is_static() const noexcept
Return whether the dataspace is static.
Generic RPC wrapper for L4 flex-pages.
Definition ipc_types:322
Cacheopt
Caching options, see l4_fpage_cacheability_opt_t.
Definition ipc_types:342
bool id_received() const noexcept
Check if a label was received instead of a mapping.
Definition ipc_types:454
Map_type
Kind of mapping.
Definition ipc_types:335
l4_umword_t data() const noexcept
Return the raw flex page descriptor.
Definition ipc_types:474
Dataspace protocol defintion.
Dataspace interface.
unsigned int l4_size_t
Unsigned size type.
Definition l4int.h:35
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
@ L4_EACCESS
Permission denied.
Definition err.h:51
@ L4_EINVAL
Invalid argument.
Definition err.h:56
@ L4_ENODEV
No such thing.
Definition err.h:55
@ L4_EOK
Ok.
Definition err.h:43
@ L4_EPERM
No permission.
Definition err.h:44
@ L4_CAP_FPAGE_W
Interface specific 'W' right for capability flex-pages.
Definition __l4_fpage.h:160
#define L4_LOG2_PAGESIZE
Number of bits used for page offset.
Definition consts.h:398
l4_addr_t l4_round_size(l4_addr_t value, unsigned char bits) L4_NOTHROW
Round value up to the next alignment with bits size.
Definition consts.h:473
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition cmd_control:15
@ Caching_mask
Mask for caching flags.
Definition dataspace:108
@ W
Request write-only mapping.
Definition dataspace:89
Information about the dataspace.
Definition dataspace:136