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_ret_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 };
98
105
107 struct F
108 {
111 {
113 Search_addr = 0x20000,
115 In_area = 0x40000,
117 Eager_map = 0x80000,
119 No_eager_map = 0x100000,
120
122 Attach_mask = 0x1f0000,
123 };
124
125 friend void enum_bitops_enable(Attach_flags);
126
171
172 friend void enum_bitops_enable(Region_flags);
173
174 friend constexpr Dataspace::Flags map_flags(Region_flags rf)
175 { return Dataspace::Flags(static_cast<l4_uint16_t>(rf) & Ds_map_mask); }
176
177 struct Flags : L4::Types::Flags_ops_t<Flags>
178 {
179 l4_uint32_t raw;
180
181 Flags() = default;
182 explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
183 constexpr Flags(Attach_flags af) : raw(static_cast<l4_uint32_t>(af)) {}
184 constexpr Flags(Region_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
185
186 constexpr Dataspace::Flags map_flags() const
187 { return Dataspace::Flags(raw & Ds_map_mask); }
188
189 constexpr Region_flags region_flags() const
190 { return Region_flags(raw & Region_flags_mask); }
191
192 constexpr Attach_flags attach_flags() const
193 { return Attach_flags(raw & Attach_mask); }
194
195 constexpr bool r() const { return raw & L4_FPAGE_RO; }
196 constexpr bool w() const { return raw & L4_FPAGE_W; }
197 constexpr bool x() const { return raw & L4_FPAGE_X; }
198
199 constexpr unsigned cap_rights() const
200 { return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
201 };
202
203 friend constexpr Flags operator | (Region_flags l, Attach_flags r)
204 { return Flags(l) | Flags(r); }
205
206 friend constexpr Flags operator | (Attach_flags l, Region_flags r)
207 { return Flags(l) | Flags(r); }
208 };
209
210 using Attach_flags = F::Attach_flags;
211 using Region_flags = F::Region_flags;
212 using Flags = F::Flags;
213
216 {
227
238
247 };
248
276 long reserve_area(l4_addr_t *start, unsigned long size,
277 Flags flags = Flags(0),
278 unsigned char align = L4_PAGESHIFT) const noexcept
279 { return reserve_area_t::call(c(), start, size, flags, align); }
280
281 L4_RPC_NF(long, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
282 unsigned long size,
283 Flags flags,
284 unsigned char align));
285
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
325 L4_RPC(long, free_area, (l4_addr_t addr));
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(long, 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
396 long attach(l4_addr_t *start, unsigned long size, Flags flags,
397 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
398 unsigned char align = L4_PAGESHIFT,
399 L4::Cap<L4::Task> const task
401 char const *name = nullptr,
402 Offset backing_offset = 0) const noexcept;
403
407 template<typename T>
408 long attach(T **start, unsigned long size, Flags flags,
409 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
410 unsigned char align = L4_PAGESHIFT,
411 L4::Cap<L4::Task> const task
412 = L4::Cap<L4::Task>::Invalid,
413 char const *name = nullptr,
414 Offset backing_offset = 0) const noexcept
415 {
416 union X { l4_addr_t a; T* t; };
417 X *x = reinterpret_cast<X*>(start);
418 return attach(&x->a, size, flags, mem, offs, align, task,
419 name, backing_offset);
420 }
421
422#if __cplusplus >= 201103L
433 template<typename T>
434 class Unique_region
435 {
436 private:
437 T _addr;
438 L4::Cap<Rm> _rm;
439
440 public:
441 Unique_region(Unique_region const &) = delete;
442 Unique_region &operator = (Unique_region const &) = delete;
443
447 Unique_region() noexcept
448 : _addr(0), _rm(L4::Cap<Rm>::Invalid) {}
449
455 explicit Unique_region(T addr) noexcept
456 : _addr(addr), _rm(L4::Cap<Rm>::Invalid) {}
457
464 Unique_region(T addr, L4::Cap<Rm> const &rm) noexcept
465 : _addr(addr), _rm(rm) {}
466
472 Unique_region(Unique_region &&o) noexcept : _addr(o.get()), _rm(o._rm)
473 { o.release(); }
474
480 Unique_region &operator = (Unique_region &&o) noexcept
481 {
482 if (&o != this)
483 {
484 if (_rm.is_valid())
485 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
486 _rm = o._rm;
487 _addr = o.release();
488 }
489 return *this;
490 }
491
497 ~Unique_region() noexcept
498 {
499 if (_rm.is_valid())
500 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
501 }
502
508 T get() const noexcept
509 { return _addr; }
510
516 T release() noexcept
517 {
519 return _addr;
520 }
521
528 void reset(T addr, L4::Cap<Rm> const &rm) noexcept
529 {
530 if (_rm.is_valid())
531 _rm->detach(l4_addr_t(_addr), 0);
532
533 _rm = rm;
534 _addr = addr;
535 }
536
540 void reset() noexcept
542
548 bool is_valid() const noexcept
549 { return _rm.is_valid(); }
550
552 T operator * () const noexcept { return _addr; }
553
555 T operator -> () const noexcept { return _addr; }
556 };
557
558 template<typename T>
559 long 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 int detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
597 L4::Cap<L4::Task> const &task = This_task) const noexcept;
598
602 int detach(void *addr, L4::Cap<Dataspace> *mem,
603 L4::Cap<L4::Task> const &task = This_task) const noexcept;
604
624 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
625 L4::Cap<L4::Task> const &task) const noexcept;
626
671 long find(l4_addr_t *addr, unsigned long *size, Offset *offset,
672 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
673 { return find_t::call(c(), addr, size, flags, offset, m); }
674
675 L4_RPC_NF(long, find, (L4::Ipc::In_out<l4_addr_t *> addr,
677 L4Re::Rm::Flags *flags, Offset *offset,
679
685 struct Region
686 {
687 l4_addr_t start;
688 l4_addr_t end;
689 F::Region_flags flags;
690 };
691
698 struct Area
699 {
700 l4_addr_t start;
701 l4_addr_t end;
702 };
703
719
735
749 L4_RPC(long, get_info, (l4_addr_t addr, L4::Ipc::String<char> &name,
750 Offset &backing_offset));
751
752 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
753 L4::Cap<L4::Task> task, unsigned flags) const noexcept;
754
755 typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
756 reserve_area_t, free_area_t,
757 get_regions_t, get_areas_t,
758 get_info_t> Rpcs;
759};
760
761inline int
763 L4::Cap<L4::Task> const &task) const noexcept
764{ return detach(addr, 1, mem, task, Detach_overlap); }
765
766inline int
768 L4::Cap<L4::Task> const &task) const noexcept
769{
770 return detach(reinterpret_cast<l4_addr_t>(addr), 1, mem, task,
772}
773
774inline int
775Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
776 L4::Cap<L4::Task> const &task) const noexcept
777{ return detach(addr, size, mem, task, Detach_exact); }
778
779};
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:455
Unique_region(Unique_region &&o) noexcept
Move-Construct a Unique_region.
Definition rm:472
T get() const noexcept
Return the address.
Definition rm:508
void reset() noexcept
Make the Unique_region invalid.
Definition rm:540
bool is_valid() const noexcept
Check if the Unique_region is valid.
Definition rm:548
void reset(T addr, L4::Cap< Rm > const &rm) noexcept
Set new address and region manager.
Definition rm:528
Unique_region() noexcept
Construct an invalid Unique_region.
Definition rm:447
~Unique_region() noexcept
Destructor.
Definition rm:497
Unique_region(T addr, L4::Cap< Rm > const &rm) noexcept
Construct a valid Unique_region from an address and a region manager.
Definition rm:464
T release() noexcept
Return the address and invalidate the Unique_region.
Definition rm:516
Region map.
Definition rm:84
long 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 sapce.
Definition rm:91
@ Detach_again
Detached data space, more to do.
Definition rm:96
@ Split_ds
Splitted data space, and done.
Definition rm:93
@ Kept_ds
Kept data space.
Definition rm:92
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:101
@ Caching_shift
Start of Rm cache bits.
Definition rm:103
Detach_flags
Flags for detach operation.
Definition rm:216
@ Detach_overlap
Do an unmap of all overlapping regions.
Definition rm:237
@ Detach_exact
Do an unmap of the exact region given.
Definition rm:226
@ Detach_keep
Do not free the detached data space, ignore the F::Detach_free.
Definition rm:246
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:276
long get_regions(l4_addr_t start, L4::Ipc::Ret_array< Region > regions)
Return the list of regions whose starting addresses are higher or equal to start in the address space...
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:671
long get_areas(l4_addr_t start, L4::Ipc::Ret_array< Area > areas)
Return the list of areas whose starting addresses are higher or equal to start in the address space m...
long 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:35
long get_info(l4_addr_t addr, L4::Ipc::String< char > &name, Offset &backing_offset)
Return auxiliary information of a region.
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:762
@ Invalid
Invalid capability selector.
Definition capability.h:42
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:336
@ 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:214
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
Fixed sized integer types, generic version.
Common L4 ABI Data Types.
constexpr T operator|(T l, T r) noexcept
Union enum values.
Definition types:476
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:699
Rm flags definitions.
Definition rm:108
Region_flags
Region flags (permissions, cacheability, special).
Definition rm:129
@ Cache_uncached
Cache bits for uncached memory.
Definition rm:163
@ Rights_mask
Region rights.
Definition rm:131
@ Region_flags_mask
Mask of all region flags.
Definition rm:169
@ Ds_map_mask
Mask for all bits for cache options and rights.
Definition rm:166
@ Reserved
Region is reserved (blocked).
Definition rm:152
@ Pager
Region has a pager.
Definition rm:150
@ RWX
Readable, writable and executable region.
Definition rm:143
@ RW
Readable and writable region.
Definition rm:139
@ RX
Readable and executable region.
Definition rm:141
@ X
Executable region.
Definition rm:137
@ R
Readable region.
Definition rm:133
@ Detach_free
Free the portion of the data space after detach.
Definition rm:148
@ Cache_buffered
Cache bits for buffered (write combining) memory.
Definition rm:161
@ W
Writable region.
Definition rm:135
@ Cache_normal
Cache bits for normal cacheable memory.
Definition rm:159
@ Caching_mask
Mask of all Rm cache bits.
Definition rm:156
@ Kernel
Kernel-provided memory (KUMEM).
Definition rm:146
Attach_flags
Flags for attach operation.
Definition rm:111
@ Search_addr
Search for a suitable address range.
Definition rm:113
@ Attach_mask
Mask of all attach flags.
Definition rm:122
@ No_eager_map
Prevent eager mapping of the attached data space.
Definition rm:119
@ Eager_map
Eagerly map the attached data space in.
Definition rm:117
@ In_area
Search only in area, or map into area.
Definition rm:115
A region is a range of virtual addresses which is backed by content.
Definition rm:686
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:196