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
172
173 friend void enum_bitops_enable(Region_flags);
174
175 friend constexpr Dataspace::Flags map_flags(Region_flags rf)
176 { return Dataspace::Flags(static_cast<l4_uint16_t>(rf) & Ds_map_mask); }
177
178 struct Flags : L4::Types::Flags_ops_t<Flags>
179 {
180 l4_uint32_t raw;
181
182 Flags() = default;
183 explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
184 constexpr Flags(Attach_flags af) : raw(static_cast<l4_uint32_t>(af)) {}
185 constexpr Flags(Region_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
186
187 constexpr Dataspace::Flags map_flags() const
188 { return Dataspace::Flags(raw & Ds_map_mask); }
189
190 constexpr Region_flags region_flags() const
191 { return Region_flags(raw & Region_flags_mask); }
192
193 constexpr Attach_flags attach_flags() const
194 { return Attach_flags(raw & Attach_mask); }
195
196 constexpr bool r() const { return raw & L4_FPAGE_RO; }
197 constexpr bool w() const { return raw & L4_FPAGE_W; }
198 constexpr bool x() const { return raw & L4_FPAGE_X; }
199
200 constexpr unsigned cap_rights() const
201 { return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
202 };
203
204 friend constexpr Flags operator | (Region_flags l, Attach_flags r)
205 { return Flags(l) | Flags(r); }
206
207 friend constexpr Flags operator | (Attach_flags l, Region_flags r)
208 { return Flags(l) | Flags(r); }
209 };
210
211 using Attach_flags = F::Attach_flags;
212 using Region_flags = F::Region_flags;
213 using Flags = F::Flags;
214
217 {
228
239
248 };
249
277 l4_ret_t 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(l4_ret_t, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
283 unsigned long size,
284 Flags flags,
285 unsigned char align));
286
304 template<typename T>
305 l4_ret_t reserve_area(T **start, unsigned long size,
306 Flags flags = Flags(0),
307 unsigned char align = L4_PAGESHIFT) const noexcept
308 {
309 return reserve_area_t::call(c(), reinterpret_cast<l4_addr_t*>(start), size,
310 flags, align);
311 }
312
327
329 unsigned long size, Flags flags,
331 Offset offs, unsigned char align,
333 L4::Ipc::String<> name, Offset backing_offset));
334
335 L4_RPC_NF(l4_ret_t, detach, (l4_addr_t addr, unsigned long size, unsigned flags,
336 l4_addr_t &start, l4_addr_t &rsize,
337 l4_cap_idx_t &mem_cap));
338
397 l4_ret_t attach(l4_addr_t *start, unsigned long size, Flags flags,
398 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
399 unsigned char align = L4_PAGESHIFT,
400 L4::Cap<L4::Task> const task
402 char const *name = nullptr,
403 Offset backing_offset = 0) const noexcept;
404
408 template<typename T>
409 l4_ret_t attach(T **start, unsigned long size, Flags flags,
410 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
411 unsigned char align = L4_PAGESHIFT,
412 L4::Cap<L4::Task> const task
413 = L4::Cap<L4::Task>::Invalid,
414 char const *name = nullptr,
415 Offset backing_offset = 0) const noexcept
416 {
417 union X { l4_addr_t a; T* t; };
418 X *x = reinterpret_cast<X*>(start);
419 return attach(&x->a, size, flags, mem, offs, align, task,
420 name, backing_offset);
421 }
422
423#if __cplusplus >= 201103L
434 template<typename T>
435 class Unique_region
436 {
437 private:
438 T _addr;
439 L4::Cap<Rm> _rm;
440
441 public:
442 Unique_region(Unique_region const &) = delete;
443 Unique_region &operator = (Unique_region const &) = delete;
444
448 Unique_region() noexcept
449 : _addr(0), _rm(L4::Cap<Rm>::Invalid) {}
450
456 explicit Unique_region(T addr) noexcept
457 : _addr(addr), _rm(L4::Cap<Rm>::Invalid) {}
458
465 Unique_region(T addr, L4::Cap<Rm> const &rm) noexcept
466 : _addr(addr), _rm(rm) {}
467
473 Unique_region(Unique_region &&o) noexcept : _addr(o.get()), _rm(o._rm)
474 { o.release(); }
475
481 Unique_region &operator = (Unique_region &&o) noexcept
482 {
483 if (&o != this)
484 {
485 if (_rm.is_valid())
486 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
487 _rm = o._rm;
488 _addr = o.release();
489 }
490 return *this;
491 }
492
498 ~Unique_region() noexcept
499 {
500 if (_rm.is_valid())
501 _rm->detach(reinterpret_cast<l4_addr_t>(_addr), 0);
502 }
503
509 T get() const noexcept
510 { return _addr; }
511
517 T release() noexcept
518 {
520 return _addr;
521 }
522
529 void reset(T addr, L4::Cap<Rm> const &rm) noexcept
530 {
531 if (_rm.is_valid())
532 _rm->detach(l4_addr_t(_addr), 0);
533
534 _rm = rm;
535 _addr = addr;
536 }
537
541 void reset() noexcept
543
549 bool is_valid() const noexcept
550 { return _rm.is_valid(); }
551
553 T operator * () const noexcept { return _addr; }
554
556 T operator -> () const noexcept { return _addr; }
557
558 explicit operator bool() const noexcept
559 { return is_valid(); }
560 };
561
562 template<typename T>
563 l4_ret_t attach(Unique_region<T> *start, unsigned long size, Flags flags,
564 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
565 unsigned char align = L4_PAGESHIFT,
566 L4::Cap<L4::Task> const task
568 char const *name = nullptr,
569 Offset backing_offset = 0) const noexcept
570 {
571 l4_addr_t addr = reinterpret_cast<l4_addr_t>(start->get());
572
573 long res = attach(&addr, size, flags, mem, offs, align, task,
574 name, backing_offset);
575 if (res < 0)
576 return res;
577
578 start->reset(reinterpret_cast<T>(addr), L4::Cap<Rm>(cap()));
579 return res;
580 }
581#endif
582
600 l4_ret_t detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
601 L4::Cap<L4::Task> const &task = This_task) const noexcept;
602
606 l4_ret_t detach(void *addr, L4::Cap<Dataspace> *mem,
607 L4::Cap<L4::Task> const &task = This_task) const noexcept;
608
628 l4_ret_t detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
629 L4::Cap<L4::Task> const &task) const noexcept;
630
675 l4_ret_t find(l4_addr_t *addr, unsigned long *size, Offset *offset,
676 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
677 { return find_t::call(c(), addr, size, flags, offset, m); }
678
681 L4Re::Rm::Flags *flags, Offset *offset,
683
689 struct Region
690 {
691 l4_addr_t start;
692 l4_addr_t end;
693 F::Region_flags flags;
694 };
695
702 struct Area
703 {
704 l4_addr_t start;
705 l4_addr_t end;
706 };
707
723
739
753 L4_RPC(l4_ret_t, get_info, (l4_addr_t addr, L4::Ipc::String<char> &name,
754 Offset &backing_offset));
755
756 l4_ret_t detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
757 L4::Cap<L4::Task> task, unsigned flags) const noexcept;
758
759 typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
760 reserve_area_t, free_area_t,
761 get_regions_t, get_areas_t,
762 get_info_t> Rpcs;
763};
764
765inline l4_ret_t
767 L4::Cap<L4::Task> const &task) const noexcept
768{ return detach(addr, 1, mem, task, Detach_overlap); }
769
770inline l4_ret_t
772 L4::Cap<L4::Task> const &task) const noexcept
773{
774 return detach(reinterpret_cast<l4_addr_t>(addr), 1, mem, task,
776}
777
778inline l4_ret_t
779Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
780 L4::Cap<L4::Task> const &task) const noexcept
781{ return detach(addr, size, mem, task, Detach_exact); }
782
783};
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:456
Unique_region(Unique_region &&o) noexcept
Move-Construct a Unique_region.
Definition rm:473
T get() const noexcept
Return the address.
Definition rm:509
void reset() noexcept
Make the Unique_region invalid.
Definition rm:541
bool is_valid() const noexcept
Check if the Unique_region is valid.
Definition rm:549
void reset(T addr, L4::Cap< Rm > const &rm) noexcept
Set new address and region manager.
Definition rm:529
Unique_region() noexcept
Construct an invalid Unique_region.
Definition rm:448
~Unique_region() noexcept
Destructor.
Definition rm:498
Unique_region(T addr, L4::Cap< Rm > const &rm) noexcept
Construct a valid Unique_region from an address and a region manager.
Definition rm:465
T release() noexcept
Return the address and invalidate the Unique_region.
Definition rm:517
Region map.
Definition rm:84
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:305
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
@ 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
Region_flag_shifts
Region flag shifts.
Definition rm:101
@ Caching_shift
Start of Rm cache bits.
Definition rm:103
l4_ret_t 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...
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:277
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:675
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:766
Detach_flags
Flags for detach operation.
Definition rm:217
@ Detach_overlap
Do an unmap of all overlapping regions.
Definition rm:238
@ Detach_exact
Do an unmap of the exact region given.
Definition rm:227
@ Detach_keep
Do not free the detached data space, ignore the F::Detach_free.
Definition rm:247
l4_ret_t get_info(l4_addr_t addr, L4::Ipc::String< char > &name, Offset &backing_offset)
Return auxiliary information of a region.
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...
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:35
@ 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:357
@ 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:28
constexpr T operator|(T l, T r) noexcept
Union enum values.
Definition types:528
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:703
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:164
@ Rights_mask
Region rights.
Definition rm:131
@ Region_flags_mask
Mask of all region flags.
Definition rm:170
@ Ds_map_mask
Mask for all bits for cache options and rights.
Definition rm:167
@ Reserved
Region is reserved (blocked).
Definition rm:153
@ Pager
Region has a pager.
Definition rm:151
@ 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:162
@ W
Writable region.
Definition rm:135
@ Cache_normal
Cache bits for normal cacheable memory.
Definition rm:160
@ Caching_mask
Mask of all Rm cache bits.
Definition rm:157
@ 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:690
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:204