L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 * License: see LICENSE.spdx (in this directory or the directories above)
15 */
16#pragma once
17
18#include <l4/sys/types.h>
19#include <l4/sys/l4int.h>
20#include <l4/sys/capability>
21#include <l4/re/protocols.h>
22#include <l4/sys/pager>
23#include <l4/sys/cxx/ipc_iface>
24#include <l4/sys/cxx/ipc_ret_array>
25#include <l4/sys/cxx/types>
26#include <l4/re/consts>
27#include <l4/re/dataspace>
28
29namespace L4Re {
30
82 public L4::Kobject_t<Rm, L4::Pager, L4RE_PROTO_RM,
83 L4::Type_info::Demand_t<1> >
84{
85public:
86 typedef L4Re::Dataspace::Offset Offset;
87
90 {
91 Detached_ds = 0,
92 Kept_ds = 1,
93 Split_ds = 2,
94 Detach_result_mask = 3,
95
96 Detach_again = 4,
97 };
98
99
102 {
104 Caching_shift = Dataspace::F::Caching_shift,
105 };
106
108 struct F
109 {
112 {
114 Search_addr = 0x20000,
116 In_area = 0x40000,
118 Eager_map = 0x80000,
120 No_eager_map = 0x100000,
122 Attach_mask = 0x1f0000,
123 };
124
126
129 {
131 Rights_mask = 0x0f,
133 R = Dataspace::F::R,
135 W = Dataspace::F::W,
137 X = Dataspace::F::X,
139 RW = Dataspace::F::RW,
141 RX = Dataspace::F::RX,
143 RWX = Dataspace::F::RWX,
144
146 Detach_free = 0x200,
148 Pager = 0x400,
150 Reserved = 0x800,
151
152
154 Caching_mask = Dataspace::F::Caching_mask,
156 Cache_normal = Dataspace::F::Normal,
158 Cache_buffered = Dataspace::F::Bufferable,
160 Cache_uncached = Dataspace::F::Uncacheable,
161
163 Ds_map_mask = 0xff,
164
166 Region_flags_mask = 0xffff,
167 };
168
170
171 friend constexpr Dataspace::Flags map_flags(Region_flags rf)
172 {
173 return Dataspace::Flags(static_cast<l4_uint16_t>(rf) & Ds_map_mask);
174 }
175
176 struct Flags : L4::Types::Flags_ops_t<Flags>
177 {
178 l4_uint32_t raw;
179 Flags() = default;
180 explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
181 constexpr Flags(Attach_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
182 constexpr Flags(Region_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
183
184 friend constexpr Dataspace::Flags map_flags(Flags f)
185 {
186 return Dataspace::Flags(f.raw & Ds_map_mask);
187 }
188
189 constexpr Region_flags region_flags() const
190 {
191 return Region_flags(raw & Region_flags_mask);
192 }
193
194 constexpr Attach_flags attach_flags() const
195 {
196 return Attach_flags(raw & Attach_mask);
197 }
198
199 constexpr bool r() const { return raw & L4_FPAGE_RO; }
200 constexpr bool w() const { return raw & L4_FPAGE_W; }
201 constexpr bool x() const { return raw & L4_FPAGE_X; }
202 constexpr unsigned cap_rights() const
203 { return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
204 };
205
206 friend constexpr Flags operator | (Region_flags l, Attach_flags r)
207 { return Flags(l) | Flags(r); }
208
209 friend constexpr Flags operator | (Attach_flags l, Region_flags r)
210 { return Flags(l) | Flags(r); }
211 };
212
213 using Attach_flags = F::Attach_flags;
214 using Region_flags = F::Region_flags;
215 using Flags = F::Flags;
216
219 {
229 Detach_exact = 1,
239 Detach_overlap = 2,
240
248 Detach_keep = 4,
249 };
250
277 long reserve_area(l4_addr_t *start, unsigned long size,
278 Flags flags = Flags(0),
279 unsigned char align = L4_PAGESHIFT) const noexcept
280 { return reserve_area_t::call(c(), start, size, flags, align); }
281
282 L4_RPC_NF(long, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
283 unsigned long size,
284 Flags flags,
285 unsigned char align));
286
302 template< typename T >
303 long reserve_area(T **start, unsigned long size,
304 Flags flags = Flags(0),
305 unsigned char align = L4_PAGESHIFT) const noexcept
306 {
307 return reserve_area_t::call(c(), reinterpret_cast<l4_addr_t*>(start), size,
308 flags, align);
309 }
310
323 L4_RPC(long, free_area, (l4_addr_t addr));
324
325 L4_RPC_NF(long, attach, (L4::Ipc::In_out<l4_addr_t *> start,
326 unsigned long size, Flags flags,
328 Offset offs, unsigned char align,
329 L4::Ipc::Opt<l4_cap_idx_t> client_cap));
330
331 L4_RPC_NF(long, detach, (l4_addr_t addr, unsigned long size, unsigned flags,
332 l4_addr_t &start, l4_addr_t &rsize,
333 l4_cap_idx_t &mem_cap));
334
390 long attach(l4_addr_t *start, unsigned long size, Flags flags,
391 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
392 unsigned char align = L4_PAGESHIFT,
393 L4::Cap<L4::Task> const task
394 = L4::Cap<L4::Task>::Invalid) const noexcept;
395
399 template< typename T >
400 long attach(T **start, unsigned long size, Flags flags,
401 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
402 unsigned char align = L4_PAGESHIFT,
403 L4::Cap<L4::Task> const task
404 = L4::Cap<L4::Task>::Invalid) const noexcept
405 {
406 union X { l4_addr_t a; T* t; };
407 X *x = reinterpret_cast<X*>(start);
408 return attach(&x->a, size, flags, mem, offs, align, task);
409 }
410
411#if __cplusplus >= 201103L
422 template< typename T >
424 {
425 private:
426 T _addr;
427 L4::Cap<Rm> _rm;
428
429 public:
430 Unique_region(Unique_region const &) = delete;
431 Unique_region &operator = (Unique_region const &) = delete;
432
436 Unique_region() noexcept
437 : _addr(0), _rm(L4::Cap<Rm>::Invalid) {}
438
444 explicit Unique_region(T addr) noexcept
445 : _addr(addr), _rm(L4::Cap<Rm>::Invalid) {}
446
453 Unique_region(T addr, L4::Cap<Rm> const &rm) noexcept
454 : _addr(addr), _rm(rm) {}
455
461 Unique_region(Unique_region &&o) noexcept : _addr(o.get()), _rm(o._rm)
462 { o.release(); }
463
469 Unique_region &operator = (Unique_region &&o) noexcept
470 {
471 if (&o != this)
472 {
473 if (_rm.is_valid())
474 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
475 _rm = o._rm;
476 _addr = o.release();
477 }
478 return *this;
479 }
480
486 ~Unique_region() noexcept
487 {
488 if (_rm.is_valid())
489 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
490 }
491
497 T get() const noexcept
498 { return _addr; }
499
505 T release() noexcept
506 {
508 return _addr;
509 }
510
517 void reset(T addr, L4::Cap<Rm> const &rm) noexcept
518 {
519 if (_rm.is_valid())
520 _rm->detach(l4_addr_t(_addr), 0);
521
522 _rm = rm;
523 _addr = addr;
524 }
525
529 void reset() noexcept
530 { reset(0, L4::Cap<Rm>::Invalid); }
531
537 bool is_valid() const noexcept
538 { return _rm.is_valid(); }
539
541 T operator * () const noexcept { return _addr; }
542
544 T operator -> () const noexcept { return _addr; }
545 };
546
547 template< typename T >
548 long attach(Unique_region<T> *start, unsigned long size, Flags flags,
549 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
550 unsigned char align = L4_PAGESHIFT,
551 L4::Cap<L4::Task> const task
552 = L4::Cap<L4::Task>::Invalid) const noexcept
553 {
554 l4_addr_t addr = reinterpret_cast<l4_addr_t>(start->get());
555
556 long res = attach(&addr, size, flags, mem, offs, align, task);
557 if (res < 0)
558 return res;
559
560 start->reset(reinterpret_cast<T>(addr), L4::Cap<Rm>(cap()));
561 return res;
562 }
563#endif
564
582 int detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
583 L4::Cap<L4::Task> const &task = This_task) const noexcept;
584
588 int detach(void *addr, L4::Cap<Dataspace> *mem,
589 L4::Cap<L4::Task> const &task = This_task) const noexcept;
590
610 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
611 L4::Cap<L4::Task> const &task) const noexcept;
612
657 long find(l4_addr_t *addr, unsigned long *size, Offset *offset,
658 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
659 { return find_t::call(c(), addr, size, flags, offset, m); }
660
661 L4_RPC_NF(long, find, (L4::Ipc::In_out<l4_addr_t *> addr,
663 L4Re::Rm::Flags *flags, Offset *offset,
665
676
682 using Region = Range;
683
690 using Area = Range;
691
706 L4_RPC(long, get_regions, (l4_addr_t start, L4::Ipc::Ret_array<Range> regions));
707
723 L4_RPC(long, get_areas, (l4_addr_t start, L4::Ipc::Ret_array<Range> areas));
724
725 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
726 L4::Cap<L4::Task> task, unsigned flags) const noexcept;
727
728 typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
729 reserve_area_t, free_area_t,
730 get_regions_t, get_areas_t> Rpcs;
731};
732
733
734inline int
736 L4::Cap<L4::Task> const &task) const noexcept
737{ return detach(addr, 1, mem, task, Detach_overlap); }
738
739inline int
741 L4::Cap<L4::Task> const &task) const noexcept
742{
743 return detach(reinterpret_cast<l4_addr_t>(addr), 1, mem, task,
744 Detach_overlap);
745}
746
747inline int
748Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
749 L4::Cap<L4::Task> const &task) const noexcept
750{ return detach(addr, size, mem, task, Detach_exact); }
751
752};
L4::Cap related definitions.
Unique region.
Definition rm:424
Unique_region(T addr) noexcept
Construct a Unique_region from an address.
Definition rm:444
Unique_region(Unique_region &&o) noexcept
Move-Construct a Unique_region
Definition rm:461
T get() const noexcept
Return the address.
Definition rm:497
void reset() noexcept
Make the Unique_region invalid.
Definition rm:529
bool is_valid() const noexcept
Check if the Unique_region is valid.
Definition rm:537
void reset(T addr, L4::Cap< Rm > const &rm) noexcept
Set new address and region manager.
Definition rm:517
Unique_region() noexcept
Construct an invalid Unique_region
Definition rm:436
~Unique_region() noexcept
Destructor.
Definition rm:486
Unique_region(T addr, L4::Cap< Rm > const &rm) noexcept
Construct a valid Unique_region from an address and a region manager.
Definition rm:453
T release() noexcept
Return the address and invalidate the Unique_region
Definition rm:505
Region map.
Definition rm:84
Detach_result
Result values for detach operation.
Definition rm:90
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:303
Region_flag_shifts
Region flag shifts.
Definition rm:102
long attach(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:400
Detach_flags
Flags for detach operation.
Definition rm:219
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
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
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:57
C++ interface for capabilities.
Definition capability.h:219
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:699
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
Dataspace interface.
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:27
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:335
@ L4_FPAGE_X
Executable flexpage.
Definition __l4_fpage.h:120
@ L4_FPAGE_RO
Read-only flexpage
Definition __l4_fpage.h:122
@ L4_FPAGE_W
Writable flexpage.
Definition __l4_fpage.h:121
@ L4_CAP_FPAGE_RO
Read right for capability flexpages.
Definition __l4_fpage.h:176
@ L4_CAP_FPAGE_RW
Read and interface specific 'W' right for capability flexpages.
Definition __l4_fpage.h:192
#define L4_PAGESHIFT
Size of a page, log2-based.
Definition consts.h:26
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:210
Interface Definition Language.
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:535
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:504
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition cmd_control:14
L4 low-level kernel interface.
Pager and Io_pager C++ interface.
L4Re Protocol Constants (C version)
Constants.
Rm flags definitions.
Definition rm:109
Region_flags
Region flags (permissions, cacheability, special).
Definition rm:129
Attach_flags
Flags for attach operation.
Definition rm:112
A range of virtual addresses.
Definition rm:670
l4_addr_t start
First address of the range.
Definition rm:672
l4_addr_t end
Last address of the range.
Definition rm:674
Pass the argument as plain data value.
Definition ipc_types:117
Mark an argument as in-out argument.
Definition ipc_types:42
Attribute for defining an optional RPC argument.
Definition ipc_types:137
Dynamically sized output array of type T.
Definition ipc_ret_array:24
Standard list of RPCs of an interface.
Definition __typeinfo.h:428
Mixin class to define a set of friend bitwise operators on DT.
Definition types:221
#define L4_TYPES_FLAGS_OPS_DEF(T)
Helper macro to define a set of bitwise operators on an enum type.
Definition types:195