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 * 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_array>
25#include <l4/sys/cxx/types>
26#include <l4/re/consts>
27#include <l4/re/dataspace>
28
29namespace L4Re {
30
73
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 {
92 Kept_ds = 1,
94 Detach_result_mask = 3,
95
97
99 };
100
107
109 struct F
110 {
113 {
115 Search_addr = 0x20000,
117 In_area = 0x40000,
119 Eager_map = 0x80000,
121 No_eager_map = 0x100000,
122
124 Attach_mask = 0x1f0000,
125 };
126
127 friend void enum_bitops_enable(Attach_flags);
128
179
180 friend void enum_bitops_enable(Region_flags);
181
182 friend constexpr Dataspace::Flags map_flags(Region_flags rf)
183 { return Dataspace::Flags(static_cast<l4_uint16_t>(rf) & Ds_map_mask); }
184
185 struct Flags : L4::Types::Flags_ops_t<Flags>
186 {
187 l4_uint32_t raw;
188
189 Flags() = default;
190 explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
191 constexpr Flags(Attach_flags af) : raw(static_cast<l4_uint32_t>(af)) {}
192 constexpr Flags(Region_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
193
194 constexpr Dataspace::Flags map_flags() const
195 { return Dataspace::Flags(raw & Ds_map_mask); }
196
197 constexpr Region_flags region_flags() const
198 { return Region_flags(raw & Region_flags_mask); }
199
200 constexpr Attach_flags attach_flags() const
201 { return Attach_flags(raw & Attach_mask); }
202
203 constexpr bool r() const { return raw & L4_FPAGE_RO; }
204 constexpr bool w() const { return raw & L4_FPAGE_W; }
205 constexpr bool x() const { return raw & L4_FPAGE_X; }
206
207 constexpr unsigned cap_rights() const
208 { return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
209 };
210
211 friend constexpr Flags operator | (Region_flags l, Attach_flags r)
212 { return Flags(l) | Flags(r); }
213
214 friend constexpr Flags operator | (Attach_flags l, Region_flags r)
215 { return Flags(l) | Flags(r); }
216 };
217
218 using Attach_flags = F::Attach_flags;
219 using Region_flags = F::Region_flags;
220 using Flags = F::Flags;
221
224 {
235
246 };
247
275 l4_ret_t reserve_area(l4_addr_t *start, unsigned long size,
276 Flags flags = Flags(0),
277 unsigned char align = L4_PAGESHIFT) const noexcept
278 { return reserve_area_t::call(c(), start, size, flags, align); }
279
280 L4_RPC_NF(l4_ret_t, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
281 unsigned long size,
282 Flags flags,
283 unsigned char align));
284
303 template<typename T>
304 l4_ret_t 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
326
328 unsigned long size, Flags flags,
330 Offset offs, unsigned char align,
332 L4::Ipc::String<> name, Offset backing_offset));
333
334 L4_RPC_NF(l4_ret_t, detach, (l4_addr_t addr, unsigned long size, unsigned flags,
335 l4_addr_t &start, l4_addr_t &rsize,
336 l4_cap_idx_t &mem_cap));
337
393 l4_ret_t attach(l4_addr_t *start, unsigned long size, Flags flags,
394 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
395 unsigned char align = L4_PAGESHIFT,
396 L4::Cap<L4::Task> const task
398 char const *name = nullptr,
399 Offset backing_offset = 0) const noexcept;
400
404 template<typename T>
405 l4_ret_t attach(T **start, unsigned long size, Flags flags,
406 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
407 unsigned char align = L4_PAGESHIFT,
408 L4::Cap<L4::Task> const task
409 = L4::Cap<L4::Task>::Invalid,
410 char const *name = nullptr,
411 Offset backing_offset = 0) const noexcept
412 {
413 union X { l4_addr_t a; T* t; };
414 X *x = reinterpret_cast<X*>(start);
415 return attach(&x->a, size, flags, mem, offs, align, task,
416 name, backing_offset);
417 }
418
419#if __cplusplus >= 201103L
430 template<typename T>
431 class Unique_region
432 {
433 private:
434 T _addr;
435 L4::Cap<Rm> _rm;
436
437 public:
438 Unique_region(Unique_region const &) = delete;
439 Unique_region &operator = (Unique_region const &) = delete;
440
444 Unique_region() noexcept
445 : _addr(0), _rm(L4::Cap<Rm>::Invalid) {}
446
452 explicit Unique_region(T addr) noexcept
453 : _addr(addr), _rm(L4::Cap<Rm>::Invalid) {}
454
461 Unique_region(T addr, L4::Cap<Rm> const &rm) noexcept
462 : _addr(addr), _rm(rm) {}
463
469 Unique_region(Unique_region &&o) noexcept : _addr(o.get()), _rm(o._rm)
470 { o.release(); }
471
477 Unique_region &operator = (Unique_region &&o) noexcept
478 {
479 if (&o != this)
480 {
481 if (_rm.is_valid())
482 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
483 _rm = o._rm;
484 _addr = o.release();
485 }
486 return *this;
487 }
488
494 ~Unique_region() noexcept
495 {
496 if (_rm.is_valid())
497 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
498 }
499
505 T get() const noexcept
506 { return _addr; }
507
513 T release() noexcept
514 {
516 return _addr;
517 }
518
525 void reset(T addr, L4::Cap<Rm> const &rm) noexcept
526 {
527 if (_rm.is_valid())
528 _rm->detach(l4_addr_t(_addr), 0);
529
530 _rm = rm;
531 _addr = addr;
532 }
533
537 void reset() noexcept
539
545 bool is_valid() const noexcept
546 { return _rm.is_valid(); }
547
549 T operator * () const noexcept { return _addr; }
550
552 T operator -> () const noexcept { return _addr; }
553
554 explicit operator bool() const noexcept
555 { return is_valid(); }
556 };
557
558 template<typename T>
559 l4_ret_t attach(Unique_region<T> *start, unsigned long size, Flags flags,
560 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
561 unsigned char align = L4_PAGESHIFT,
562 L4::Cap<L4::Task> const task
564 char const *name = nullptr,
565 Offset backing_offset = 0) const noexcept
566 {
567 l4_addr_t addr = reinterpret_cast<l4_addr_t>(start->get());
568
569 long res = attach(&addr, size, flags, mem, offs, align, task,
570 name, backing_offset);
571 if (res < 0)
572 return res;
573
574 start->reset(reinterpret_cast<T>(addr), L4::Cap<Rm>(cap()));
575 return res;
576 }
577#endif
578
596 l4_ret_t detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
597 L4::Cap<L4::Task> const &task = This_task) const noexcept;
598
602 l4_ret_t detach(void *addr, L4::Cap<Dataspace> *mem,
603 L4::Cap<L4::Task> const &task = This_task) const noexcept;
604
624 l4_ret_t detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
625 L4::Cap<L4::Task> const &task = This_task) const noexcept;
626
671 l4_ret_t find(l4_addr_t *addr, unsigned long *size, Offset *offset,
672 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
673 {
674 l4_cap_idx_t ds_idx;
675 l4_ret_t ret = find_t::call(c(), addr, size, flags, offset, &ds_idx);
676 if (ret >= 0)
677 *m = L4::Cap<Dataspace>(ds_idx);
678 return ret;
679 }
680
683 L4Re::Rm::Flags *flags, Offset *offset,
684 l4_cap_idx_t *m));
685
691 struct Region
692 {
693 l4_addr_t start;
694 l4_addr_t end;
695 F::Region_flags flags;
696 };
697
704 struct Area
705 {
706 l4_addr_t start;
707 l4_addr_t end;
708 F::Region_flags flags;
709 };
710
726
742
756 L4_RPC(l4_ret_t, get_info, (l4_addr_t addr, L4::Ipc::String<char> &name,
757 Offset &backing_offset));
758
781 l4_addr_t rescue_pc));
782
795
796 l4_ret_t detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
797 L4::Cap<L4::Task> task, unsigned flags) const noexcept;
798
799
828 l4_ret_t page_in(l4_addr_t start, unsigned long size, Region_flags rights,
829 L4::Cap<L4::Task> dst = L4::Cap<L4::Task>::Invalid) const noexcept;
830
847 typedef l4_ret_t (*page_in_fn)(l4_addr_t min_addr, l4_addr_t max_addr,
848 Region_flags rights);
849
873 L4_RPC_NF(l4_ret_t, page_in, (l4_addr_t min_addr, l4_addr_t max_addr,
874 Region_flags rights, L4::Ipc::Rcv_fpage rwin,
875 L4::Ipc::Snd_fpage &fp, page_in_fn *helper));
876
877
878 typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
879 reserve_area_t, free_area_t,
880 get_regions_t, get_areas_t,
881 get_info_t, add_rescue_jump_t,
882 remove_rescue_jump_t, page_in_t> Rpcs;
883};
884
885inline l4_ret_t
887 L4::Cap<L4::Task> const &task) const noexcept
888{ return detach(addr, 1, mem, task, Detach_overlap); }
889
890inline l4_ret_t
892 L4::Cap<L4::Task> const &task) const noexcept
893{
894 return detach(reinterpret_cast<l4_addr_t>(addr), 1, mem, task,
896}
897
898inline l4_ret_t
899Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
900 L4::Cap<L4::Task> const &task) const noexcept
901{ return detach(addr, size, mem, task, Detach_exact); }
902
903};
L4::Cap related definitions.
Interface for memory-like objects.
Definition dataspace:53
Unique_region(T addr) noexcept
Construct a Unique_region from an address.
Definition rm:452
Unique_region(Unique_region &&o) noexcept
Move-Construct a Unique_region.
Definition rm:469
T get() const noexcept
Return the address.
Definition rm:505
void reset() noexcept
Make the Unique_region invalid.
Definition rm:537
bool is_valid() const noexcept
Check if the Unique_region is valid.
Definition rm:545
void reset(T addr, L4::Cap< Rm > const &rm) noexcept
Set new address and region manager.
Definition rm:525
Unique_region() noexcept
Construct an invalid Unique_region.
Definition rm:444
~Unique_region() noexcept
Destructor.
Definition rm:494
Unique_region(T addr, L4::Cap< Rm > const &rm) noexcept
Construct a valid Unique_region from an address and a region manager.
Definition rm:461
T release() noexcept
Return the address and invalidate the Unique_region.
Definition rm:513
Region map.
Definition rm:84
l4_ret_t get_regions(l4_addr_t start, L4::Ipc::Array_ref< Region > &regions)
Return the list of regions whose starting addresses are higher or equal to start in the address space...
l4_ret_t add_rescue_jump(l4_addr_t pc_begin, l4_addr_t pc_end, l4_addr_t rescue_pc)
Register a rescue jump for a range of program counters.
l4_ret_t 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
l4_ret_t free_area(l4_addr_t addr)
Free an area from the region map.
Detach_result
Result values for detach operation.
Definition rm:90
@ Detached_ds
Detached data space.
Definition rm:91
@ Unmapped_range
The region mananager has already unmapped the pages.
Definition rm:98
@ Detach_again
Detached data space, more to do.
Definition rm:96
@ Split_ds
Split data space, and done.
Definition rm:93
@ Kept_ds
Kept data space.
Definition rm:92
l4_ret_t page_in(l4_addr_t start, unsigned long size, Region_flags rights, L4::Cap< L4::Task > dst=L4::Cap< L4::Task >::Invalid) const noexcept
Allocate and map pages for the given region.
Definition rm_impl.h:116
Region_flag_shifts
Region flag shifts.
Definition rm:103
@ Caching_shift
Start of Rm cache bits.
Definition rm:105
l4_ret_t 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:275
long get_areas(l4_addr_t start, L4::Ipc::Array_ref< Area > &areas)
Return the list of areas whose starting addresses are higher or equal to start in the address space m...
l4_ret_t(* page_in_fn)(l4_addr_t min_addr, l4_addr_t max_addr, Region_flags rights)
In-thread eager paging function.
Definition rm:847
l4_ret_t 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:671
l4_ret_t 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:886
Detach_flags
Flags for detach operation.
Definition rm:224
@ Detach_overlap
Do an unmap of all overlapping regions.
Definition rm:245
@ Detach_exact
Do an unmap of the exact region given.
Definition rm:234
L4::Typeid::Rpcs< attach_t, detach_t, find_t, reserve_area_t, free_area_t, get_regions_t, get_areas_t, get_info_t, add_rescue_jump_t, remove_rescue_jump_t, page_in_t > Rpcs
Eager paging RPC call.
Definition rm:882
l4_ret_t get_info(l4_addr_t addr, L4::Ipc::String< char > &name, Offset &backing_offset)
Return auxiliary information of a region.
l4_ret_t remove_rescue_jump(l4_addr_t pc)
Remove a previously registered rescue jump.
l4_ret_t attach(l4_addr_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, char const *name=nullptr, Offset backing_offset=0) const noexcept
Attach a data space to a region.
Definition rm_impl.h:38
@ Invalid
Invalid capability selector.
Definition capability.h:42
C++ interface for capabilities.
Definition capability.h:249
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:725
Non-small receive item.
Definition ipc_types:532
Send item or return item.
Definition ipc_types:300
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:372
@ 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:220
Interface Definition Language.
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:542
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:511
Fixed sized integer types, generic version.
Common L4 ABI Data Types.
l4_int16_t l4_ret_t
Return value of an IPC call as well as an RPC call.
Definition types.h:29
constexpr T operator|(T l, T r) noexcept
Union enum values.
Definition types:546
L4Re C++ Interfaces.
Definition cmd_control:14
L4 low-level kernel interface.
Pager and Io_pager C++ interface.
L4Re Protocol Constants (C version).
Constants.
@ Caching_shift
shift value for caching flags
Definition dataspace:61
@ Uncacheable
Request uncacheable memory mappings.
Definition dataspace:97
@ RW
Request read-write mapping.
Definition dataspace:77
@ Normal
Request normal (cached) memory mapping.
Definition dataspace:91
@ Caching_mask
Mask for caching flags.
Definition dataspace:99
@ X
Request execute-only mapping.
Definition dataspace:81
@ R
Request read-only mapping.
Definition dataspace:73
@ RWX
Request read-write-execute mapping.
Definition dataspace:85
@ W
Request write-only mapping.
Definition dataspace:79
@ Bufferable
Request bufferable (write buffered) mappings.
Definition dataspace:95
@ RX
Request read-execute mapping.
Definition dataspace:83
An area is a range of virtual addresses which is reserved, see L4Re::Rm::reserve_area().
Definition rm:705
Rm flags definitions.
Definition rm:110
Region_flags
Region flags (permissions, cacheability, special).
Definition rm:131
@ Cache_uncached
Cache bits for uncached memory.
Definition rm:171
@ Private
Attach the dataspace privately with copy-on-write semantics.
Definition rm:156
@ Rights_mask
Region rights.
Definition rm:133
@ Region_flags_mask
Mask of all region flags.
Definition rm:177
@ Ds_map_mask
Mask for all bits for cache options and rights.
Definition rm:174
@ Reserved
Region is reserved (blocked).
Definition rm:153
@ Pager
Region has a pager.
Definition rm:151
@ RWX
Readable, writable and executable region.
Definition rm:145
@ RW
Readable and writable region.
Definition rm:141
@ RX
Readable and executable region.
Definition rm:143
@ X
Executable region.
Definition rm:139
@ R
Readable region.
Definition rm:135
@ Cache_buffered
Cache bits for buffered (write combining) memory.
Definition rm:169
@ W
Writable region.
Definition rm:137
@ Cache_normal
Cache bits for normal cacheable memory.
Definition rm:167
@ Anonymous
Attach anonymous memory in the region.
Definition rm:160
@ Caching_mask
Mask of all Rm cache bits.
Definition rm:164
@ Kernel
Kernel-provided memory (KUMEM).
Definition rm:148
Attach_flags
Flags for attach operation.
Definition rm:113
@ Search_addr
Search for a suitable address range.
Definition rm:115
@ Attach_mask
Mask of all attach flags.
Definition rm:124
@ No_eager_map
Prevent eager mapping of the attached data space.
Definition rm:121
@ Eager_map
Eagerly map the attached data space in.
Definition rm:119
@ In_area
Search only in area, or map into area.
Definition rm:117
A region is a range of virtual addresses which is backed by content.
Definition rm:692
Array reference data type for arrays located in the message.
Definition ipc_array:29
Mark an argument as in-out argument.
Definition ipc_types:42
Attribute for defining an optional RPC argument.
Definition ipc_types:81
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:204