L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
rm
Go to the documentation of this file.
1// -*- Mode: C++ -*-
2// vim:ft=cpp
7/*
8 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
9 * Alexander Warg <warg@os.inf.tu-dresden.de>,
10 * Björn Döbel <doebel@os.inf.tu-dresden.de>,
11 * Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
12 * economic rights: Technische Universität Dresden (Germany)
13 *
14 * This file is part of TUD:OS and distributed under the terms of the
15 * GNU General Public License 2.
16 * Please see the COPYING-GPL-2 file for details.
17 *
18 * As a special exception, you may use this file as part of a free software
19 * library without restriction. Specifically, if other files instantiate
20 * templates or use macros or inline functions from this file, or you compile
21 * this file and link it with other files to produce an executable, this
22 * file does not by itself cause the resulting executable to be covered by
23 * the GNU General Public License. This exception does not however
24 * invalidate any other reasons why the executable file might be covered by
25 * the GNU General Public License.
26 */
27#pragma once
28
29#include <l4/sys/types.h>
30#include <l4/sys/l4int.h>
31#include <l4/sys/capability>
32#include <l4/re/protocols.h>
33#include <l4/sys/pager>
34#include <l4/sys/cxx/ipc_iface>
35#include <l4/sys/cxx/ipc_ret_array>
36#include <l4/sys/cxx/types>
37#include <l4/re/consts>
38#include <l4/re/dataspace>
39
40namespace L4Re {
41
86 public L4::Kobject_t<Rm, L4::Pager, L4RE_PROTO_RM,
87 L4::Type_info::Demand_t<1> >
88{
89public:
90 typedef L4Re::Dataspace::Offset Offset;
91
94 {
95 Detached_ds = 0,
96 Kept_ds = 1,
97 Split_ds = 2,
98 Detach_result_mask = 3,
99
100 Detach_again = 4,
101 };
102
103
106 {
108 Caching_shift = Dataspace::F::Caching_shift,
109 };
110
112 struct F
113 {
116 {
118 Search_addr = 0x20000,
120 In_area = 0x40000,
122 Eager_map = 0x80000,
124 Attach_mask = 0xf0000,
125 };
126
128
130 {
132 Rights_mask = 0x0f,
134 R = Dataspace::F::R,
136 W = Dataspace::F::W,
138 X = Dataspace::F::X,
140 RW = Dataspace::F::RW,
142 RX = Dataspace::F::RX,
144 RWX = Dataspace::F::RWX,
145
147 Detach_free = 0x200,
149 Pager = 0x400,
151 Reserved = 0x800,
152
153
155 Caching_mask = Dataspace::F::Caching_mask,
157 Cache_normal = Dataspace::F::Normal,
159 Cache_buffered = Dataspace::F::Bufferable,
161 Cache_uncached = Dataspace::F::Uncacheable,
162
164 Ds_map_mask = 0xff,
165
167 Region_flags_mask = 0xffff,
168 };
169
171
172 friend constexpr Dataspace::Flags map_flags(Region_flags rf)
173 {
174 return Dataspace::Flags((l4_uint16_t)rf & Ds_map_mask);
175 }
176
177 struct Flags : L4::Types::Flags_ops_t<Flags>
178 {
179 l4_uint32_t raw;
180 Flags() = default;
181 explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
182 constexpr Flags(Attach_flags rf) : raw((l4_uint32_t)rf) {}
183 constexpr Flags(Region_flags rf) : raw((l4_uint32_t)rf) {}
184
185 friend constexpr Dataspace::Flags map_flags(Flags f)
186 {
187 return Dataspace::Flags(f.raw & Ds_map_mask);
188 }
189
190 constexpr Region_flags region_flags() const
191 {
192 return Region_flags(raw & Region_flags_mask);
193 }
194
195 constexpr Attach_flags attach_flags() const
196 {
197 return Attach_flags(raw & Attach_mask);
198 }
199
200 constexpr bool r() const { return raw & L4_FPAGE_RO; }
201 constexpr bool w() const { return raw & L4_FPAGE_W; }
202 constexpr bool x() const { return raw & L4_FPAGE_X; }
203 constexpr unsigned cap_rights() const
204 { return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
205 };
206
207 friend constexpr Flags operator | (Region_flags l, Attach_flags r)
208 { return Flags(l) | Flags(r); }
209
210 friend constexpr Flags operator | (Attach_flags l, Region_flags r)
211 { return Flags(l) | Flags(r); }
212 };
213
214 using Attach_flags = F::Attach_flags;
215 using Region_flags = F::Region_flags;
216 using Flags = F::Flags;
217
220 {
230 Detach_exact = 1,
240 Detach_overlap = 2,
241
249 Detach_keep = 4,
250 };
251
278 long reserve_area(l4_addr_t *start, unsigned long size,
279 Flags flags = Flags(0),
280 unsigned char align = L4_PAGESHIFT) const noexcept
281 { return reserve_area_t::call(c(), start, size, flags, align); }
282
283 L4_RPC_NF(long, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
284 unsigned long size,
285 Flags flags,
286 unsigned char align));
287
303 template< typename T >
304 long reserve_area(T **start, unsigned long size,
305 Flags flags = Flags(0),
306 unsigned char align = L4_PAGESHIFT) const noexcept
307 { return reserve_area_t::call(c(), (l4_addr_t*)start, size, flags, align); }
308
321 L4_RPC(long, free_area, (l4_addr_t addr));
322
323 L4_RPC_NF(long, attach, (L4::Ipc::In_out<l4_addr_t *> start,
324 unsigned long size, Flags flags,
326 Offset offs, unsigned char align,
327 L4::Ipc::Opt<l4_cap_idx_t> client_cap));
328
329 L4_RPC_NF(long, detach, (l4_addr_t addr, unsigned long size, unsigned flags,
330 l4_addr_t &start, l4_addr_t &rsize,
331 l4_cap_idx_t &mem_cap));
332
383 long attach(l4_addr_t *start, unsigned long size, Flags flags,
384 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
385 unsigned char align = L4_PAGESHIFT) const noexcept;
386
390 template< typename T >
391 long attach(T **start, unsigned long size, Flags flags,
392 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
393 unsigned char align = L4_PAGESHIFT) const noexcept
394 {
395 union X { l4_addr_t a; T* t; };
396 X *x = reinterpret_cast<X*>(start);
397 return attach(&x->a, size, flags, mem, offs, align);
398 }
399
400#if __cplusplus >= 201103L
411 template< typename T >
413 {
414 private:
415 T _addr;
416 L4::Cap<Rm> _rm;
417
418 public:
419 Unique_region(Unique_region const &) = delete;
420 Unique_region &operator = (Unique_region const &) = delete;
421
425 Unique_region() noexcept
426 : _addr(0), _rm(L4::Cap<Rm>::Invalid) {}
427
433 explicit Unique_region(T addr) noexcept
434 : _addr(addr), _rm(L4::Cap<Rm>::Invalid) {}
435
442 Unique_region(T addr, L4::Cap<Rm> const &rm) noexcept
443 : _addr(addr), _rm(rm) {}
444
450 Unique_region(Unique_region &&o) noexcept : _addr(o.get()), _rm(o._rm)
451 { o.release(); }
452
458 Unique_region &operator = (Unique_region &&o) noexcept
459 {
460 if (&o != this)
461 {
462 if (_rm.is_valid())
463 _rm->detach(l4_addr_t(_addr), 0);
464 _rm = o._rm;
465 _addr = o.release();
466 }
467 return *this;
468 }
469
475 ~Unique_region() noexcept
476 {
477 if (_rm.is_valid())
478 _rm->detach(l4_addr_t(_addr), 0);
479 }
480
486 T get() const noexcept
487 { return _addr; }
488
494 T release() noexcept
495 {
497 return _addr;
498 }
499
506 void reset(T addr, L4::Cap<Rm> const &rm) noexcept
507 {
508 if (_rm.is_valid())
509 _rm->detach(l4_addr_t(_addr), 0);
510
511 _rm = rm;
512 _addr = addr;
513 }
514
518 void reset() noexcept
519 { reset(0, L4::Cap<Rm>::Invalid); }
520
526 bool is_valid() const noexcept
527 { return _rm.is_valid(); }
528
530 T operator * () const noexcept { return _addr; }
531
533 T operator -> () const noexcept { return _addr; }
534 };
535
536 template< typename T >
537 long attach(Unique_region<T> *start, unsigned long size, Flags flags,
538 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
539 unsigned char align = L4_PAGESHIFT) const noexcept
540 {
541 l4_addr_t addr = (l4_addr_t)start->get();
542
543 long res = attach(&addr, size, flags, mem, offs, align);
544 if (res < 0)
545 return res;
546
547 start->reset((T)addr, L4::Cap<Rm>(cap()));
548 return res;
549 }
550#endif
551
569 int detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
570 L4::Cap<L4::Task> const &task = This_task) const noexcept;
571
575 int detach(void *addr, L4::Cap<Dataspace> *mem,
576 L4::Cap<L4::Task> const &task = This_task) const noexcept;
577
597 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
598 L4::Cap<L4::Task> const &task) const noexcept;
599
644 long find(l4_addr_t *addr, unsigned long *size, Offset *offset,
645 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
646 { return find_t::call(c(), addr, size, flags, offset, m); }
647
648 L4_RPC_NF(long, find, (L4::Ipc::In_out<l4_addr_t *> addr,
650 L4Re::Rm::Flags *flags, Offset *offset,
652
663
669 using Region = Range;
670
677 using Area = Range;
678
693 L4_RPC(long, get_regions, (l4_addr_t start, L4::Ipc::Ret_array<Range> regions));
694
710 L4_RPC(long, get_areas, (l4_addr_t start, L4::Ipc::Ret_array<Range> areas));
711
712 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
713 L4::Cap<L4::Task> task, unsigned flags) const noexcept;
714
715 typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
716 reserve_area_t, free_area_t,
717 get_regions_t, get_areas_t> Rpcs;
718};
719
720
721inline int
723 L4::Cap<L4::Task> const &task) const noexcept
724{ return detach(addr, 1, mem, task, Detach_overlap); }
725
726inline int
728 L4::Cap<L4::Task> const &task) const noexcept
729{ return detach((l4_addr_t)addr, 1, mem, task, Detach_overlap); }
730
731inline int
732Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
733 L4::Cap<L4::Task> const &task) const noexcept
734{ return detach(addr, size, mem, task, Detach_exact); }
735
736};
L4::Cap related definitions.
Unique region.
Definition rm:413
Unique_region(T addr) noexcept
Construct a Unique_region from an address.
Definition rm:433
Unique_region(Unique_region &&o) noexcept
Move-Construct a Unique_region
Definition rm:450
T get() const noexcept
Return the address.
Definition rm:486
void reset() noexcept
Make the Unique_region invalid.
Definition rm:518
bool is_valid() const noexcept
Check if the Unique_region is valid.
Definition rm:526
void reset(T addr, L4::Cap< Rm > const &rm) noexcept
Set new address and region manager.
Definition rm:506
Unique_region() noexcept
Construct an invalid Unique_region
Definition rm:425
~Unique_region() noexcept
Destructor.
Definition rm:475
Unique_region(T addr, L4::Cap< Rm > const &rm) noexcept
Construct a valid Unique_region from an address and a region manager.
Definition rm:442
T release() noexcept
Return the address and invalidate the Unique_region
Definition rm:494
Region map.
Definition rm:88
Detach_result
Result values for detach operation.
Definition rm:94
long reserve_area(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:304
Region_flag_shifts
Region flag shifts.
Definition rm:106
long attach(T **start, unsigned long size, Flags flags, L4::Ipc::Cap< Dataspace > mem, Offset offs=0, unsigned char align=L4_PAGESHIFT) const noexcept
Attach a data space to a region.
Definition rm:391
Detach_flags
Flags for detach operation.
Definition rm:220
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:278
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:644
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:722
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:60
C++ interface for capabilities.
Definition capability.h:222
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:546
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:760
Dataspace interface.
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:40
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:38
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:358
@ L4_FPAGE_X
Executable flex page.
Definition __l4_fpage.h:126
@ L4_FPAGE_RO
Read-only flex page
Definition __l4_fpage.h:128
@ L4_FPAGE_W
Writable flex page.
Definition __l4_fpage.h:127
@ L4_CAP_FPAGE_RO
Read right for capability flex-pages.
Definition __l4_fpage.h:179
@ L4_CAP_FPAGE_RW
Read and interface specific 'W' right for capability flex-pages.
Definition __l4_fpage.h:195
#define L4_PAGESHIFT
Size of a page, log2-based.
Definition consts.h:37
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:221
Interface Definition Language.
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:528
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:497
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition cmd_control:15
L4 low-level kernel interface.
Pager and Io_pager C++ interface.
L4Re Protocol Constants (C version)
Constants.
Rm flags definitions.
Definition rm:113
Region_flags
Definition rm:130
Attach_flags
Flags for attach operation.
Definition rm:116
A range of virtual addresses.
Definition rm:657
l4_addr_t start
First address of the range.
Definition rm:659
l4_addr_t end
Last address of the range.
Definition rm:661
Pass the argument as plain data value.
Definition ipc_types:128
Mark an argument as in-out argument.
Definition ipc_types:53
Attribute for defining an optional RPC argument.
Definition ipc_types:148
Dynamically sized output array of type T.
Definition ipc_ret_array:35
Standard list of RPCs of an interface.
Definition __typeinfo.h:438
Mixin class to define a set of friend bitwise operators on DT.
Definition types:233
#define L4_TYPES_FLAGS_OPS_DEF(T)
Helper macro to define a set of bitwise operators on an enum type.
Definition types:207