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,
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(static_cast<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(static_cast<l4_uint32_t>(rf)) {}
183 constexpr Flags(Region_flags rf) : raw(static_cast<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 {
308 return reserve_area_t::call(c(), reinterpret_cast<l4_addr_t*>(start), size,
309 flags, align);
310 }
311
324 L4_RPC(long, free_area, (l4_addr_t addr));
325
326 L4_RPC_NF(long, attach, (L4::Ipc::In_out<l4_addr_t *> start,
327 unsigned long size, Flags flags,
329 Offset offs, unsigned char align,
331 L4::Ipc::String<> name, Offset backing_offset));
332
333 L4_RPC_NF(long, detach, (l4_addr_t addr, unsigned long size, unsigned flags,
334 l4_addr_t &start, l4_addr_t &rsize,
335 l4_cap_idx_t &mem_cap));
336
395 long attach(l4_addr_t *start, unsigned long size, Flags flags,
396 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
397 unsigned char align = L4_PAGESHIFT,
398 L4::Cap<L4::Task> const task
400 char const *name = nullptr,
401 Offset backing_offset = 0) const noexcept;
402
406 template< typename T >
407 long attach(T **start, unsigned long size, Flags flags,
408 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
409 unsigned char align = L4_PAGESHIFT,
410 L4::Cap<L4::Task> const task
411 = L4::Cap<L4::Task>::Invalid,
412 char const *name = nullptr,
413 Offset backing_offset = 0) const noexcept
414 {
415 union X { l4_addr_t a; T* t; };
416 X *x = reinterpret_cast<X*>(start);
417 return attach(&x->a, size, flags, mem, offs, align, task,
418 name, backing_offset);
419 }
420
421#if __cplusplus >= 201103L
432 template< typename T >
434 {
435 private:
436 T _addr;
437 L4::Cap<Rm> _rm;
438
439 public:
440 Unique_region(Unique_region const &) = delete;
441 Unique_region &operator = (Unique_region const &) = delete;
442
446 Unique_region() noexcept
447 : _addr(0), _rm(L4::Cap<Rm>::Invalid) {}
448
454 explicit Unique_region(T addr) noexcept
455 : _addr(addr), _rm(L4::Cap<Rm>::Invalid) {}
456
463 Unique_region(T addr, L4::Cap<Rm> const &rm) noexcept
464 : _addr(addr), _rm(rm) {}
465
471 Unique_region(Unique_region &&o) noexcept : _addr(o.get()), _rm(o._rm)
472 { o.release(); }
473
479 Unique_region &operator = (Unique_region &&o) noexcept
480 {
481 if (&o != this)
482 {
483 if (_rm.is_valid())
484 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
485 _rm = o._rm;
486 _addr = o.release();
487 }
488 return *this;
489 }
490
496 ~Unique_region() noexcept
497 {
498 if (_rm.is_valid())
499 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
500 }
501
507 T get() const noexcept
508 { return _addr; }
509
515 T release() noexcept
516 {
518 return _addr;
519 }
520
527 void reset(T addr, L4::Cap<Rm> const &rm) noexcept
528 {
529 if (_rm.is_valid())
530 _rm->detach(l4_addr_t(_addr), 0);
531
532 _rm = rm;
533 _addr = addr;
534 }
535
539 void reset() noexcept
540 { reset(0, L4::Cap<Rm>::Invalid); }
541
547 bool is_valid() const noexcept
548 { return _rm.is_valid(); }
549
551 T operator * () const noexcept { return _addr; }
552
554 T operator -> () const noexcept { return _addr; }
555 };
556
557 template< typename T >
558 long attach(Unique_region<T> *start, unsigned long size, Flags flags,
559 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
560 unsigned char align = L4_PAGESHIFT,
561 L4::Cap<L4::Task> const task
563 char const *name = nullptr,
564 Offset backing_offset = 0) const noexcept
565 {
566 l4_addr_t addr = reinterpret_cast<l4_addr_t>(start->get());
567
568 long res = attach(&addr, size, flags, mem, offs, align, task,
569 name, backing_offset);
570 if (res < 0)
571 return res;
572
573 start->reset(reinterpret_cast<T>(addr), L4::Cap<Rm>(cap()));
574 return res;
575 }
576#endif
577
595 int detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
596 L4::Cap<L4::Task> const &task = This_task) const noexcept;
597
601 int detach(void *addr, L4::Cap<Dataspace> *mem,
602 L4::Cap<L4::Task> const &task = This_task) const noexcept;
603
623 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
624 L4::Cap<L4::Task> const &task) const noexcept;
625
670 long find(l4_addr_t *addr, unsigned long *size, Offset *offset,
671 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
672 { return find_t::call(c(), addr, size, flags, offset, m); }
673
674 L4_RPC_NF(long, find, (L4::Ipc::In_out<l4_addr_t *> addr,
676 L4Re::Rm::Flags *flags, Offset *offset,
678
689
695 using Region = Range;
696
703 using Area = Range;
704
719 L4_RPC(long, get_regions, (l4_addr_t start, L4::Ipc::Ret_array<Range> regions));
720
736 L4_RPC(long, get_areas, (l4_addr_t start, L4::Ipc::Ret_array<Range> areas));
737
751 L4_RPC(long, get_info, (l4_addr_t addr, L4::Ipc::String<char> &name,
752 Offset &backing_offset));
753
754 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
755 L4::Cap<L4::Task> task, unsigned flags) const noexcept;
756
757 typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
758 reserve_area_t, free_area_t,
759 get_regions_t, get_areas_t,
760 get_info_t> Rpcs;
761};
762
763
764inline int
766 L4::Cap<L4::Task> const &task) const noexcept
767{ return detach(addr, 1, mem, task, Detach_overlap); }
768
769inline int
771 L4::Cap<L4::Task> const &task) const noexcept
772{
773 return detach(reinterpret_cast<l4_addr_t>(addr), 1, mem, task,
774 Detach_overlap);
775}
776
777inline int
778Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
779 L4::Cap<L4::Task> const &task) const noexcept
780{ return detach(addr, size, mem, task, Detach_exact); }
781
782};
L4::Cap related definitions.
Interface for memory-like objects.
Definition dataspace:53
Unique region.
Definition rm:434
Unique_region(T addr) noexcept
Construct a Unique_region from an address.
Definition rm:454
Unique_region(Unique_region &&o) noexcept
Move-Construct a Unique_region
Definition rm:471
T get() const noexcept
Return the address.
Definition rm:507
void reset() noexcept
Make the Unique_region invalid.
Definition rm:539
bool is_valid() const noexcept
Check if the Unique_region is valid.
Definition rm:547
void reset(T addr, L4::Cap< Rm > const &rm) noexcept
Set new address and region manager.
Definition rm:527
Unique_region() noexcept
Construct an invalid Unique_region
Definition rm:446
~Unique_region() noexcept
Destructor.
Definition rm:496
Unique_region(T addr, L4::Cap< Rm > const &rm) noexcept
Construct a valid Unique_region from an address and a region manager.
Definition rm:463
T release() noexcept
Return the address and invalidate the Unique_region
Definition rm:515
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:304
Region_flag_shifts
Region flag shifts.
Definition rm:102
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:670
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:765
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:224
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:541
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:510
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:683
l4_addr_t start
First address of the range.
Definition rm:685
l4_addr_t end
Last address of the range.
Definition rm:687
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