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
99
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
125 L4_TYPES_FLAGS_OPS_DEF(Attach_flags);
126
171
172 L4_TYPES_FLAGS_OPS_DEF(Region_flags);
173
174 friend constexpr Dataspace::Flags map_flags(Region_flags rf)
175 {
176 return Dataspace::Flags(static_cast<l4_uint16_t>(rf) & Ds_map_mask);
177 }
178
179 struct Flags : L4::Types::Flags_ops_t<Flags>
180 {
181 l4_uint32_t raw;
182 Flags() = default;
183 explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
184 constexpr Flags(Attach_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
185 constexpr Flags(Region_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
186
187 friend constexpr Dataspace::Flags map_flags(Flags f)
188 {
189 return Dataspace::Flags(f.raw & Ds_map_mask);
190 }
191
192 constexpr Region_flags region_flags() const
193 {
194 return Region_flags(raw & Region_flags_mask);
195 }
196
197 constexpr Attach_flags attach_flags() const
198 {
199 return Attach_flags(raw & Attach_mask);
200 }
201
202 constexpr bool r() const { return raw & L4_FPAGE_RO; }
203 constexpr bool w() const { return raw & L4_FPAGE_W; }
204 constexpr bool x() const { return raw & L4_FPAGE_X; }
205 constexpr unsigned cap_rights() const
206 { return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
207 };
208
209 friend constexpr Flags operator | (Region_flags l, Attach_flags r)
210 { return Flags(l) | Flags(r); }
211
212 friend constexpr Flags operator | (Attach_flags l, Region_flags r)
213 { return Flags(l) | Flags(r); }
214 };
215
216 using Attach_flags = F::Attach_flags;
217 using Region_flags = F::Region_flags;
218 using Flags = F::Flags;
219
253
280 long reserve_area(l4_addr_t *start, unsigned long size,
281 Flags flags = Flags(0),
282 unsigned char align = L4_PAGESHIFT) const noexcept
283 { return reserve_area_t::call(c(), start, size, flags, align); }
284
285 L4_RPC_NF(long, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
286 unsigned long size,
287 Flags flags,
288 unsigned char align));
289
305 template< typename T >
306 long reserve_area(T **start, unsigned long size,
307 Flags flags = Flags(0),
308 unsigned char align = L4_PAGESHIFT) const noexcept
309 {
310 return reserve_area_t::call(c(), reinterpret_cast<l4_addr_t*>(start), size,
311 flags, align);
312 }
313
326 L4_RPC(long, free_area, (l4_addr_t addr));
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(long, 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 long 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 long 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
559 template< typename T >
560 long attach(Unique_region<T> *start, unsigned long size, Flags flags,
561 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
562 unsigned char align = L4_PAGESHIFT,
563 L4::Cap<L4::Task> const task
565 char const *name = nullptr,
566 Offset backing_offset = 0) const noexcept
567 {
568 l4_addr_t addr = reinterpret_cast<l4_addr_t>(start->get());
569
570 long res = attach(&addr, size, flags, mem, offs, align, task,
571 name, backing_offset);
572 if (res < 0)
573 return res;
574
575 start->reset(reinterpret_cast<T>(addr), L4::Cap<Rm>(cap()));
576 return res;
577 }
578#endif
579
597 int detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
598 L4::Cap<L4::Task> const &task = This_task) const noexcept;
599
603 int detach(void *addr, L4::Cap<Dataspace> *mem,
604 L4::Cap<L4::Task> const &task = This_task) const noexcept;
605
625 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
626 L4::Cap<L4::Task> const &task) const noexcept;
627
672 long find(l4_addr_t *addr, unsigned long *size, Offset *offset,
673 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
674 { return find_t::call(c(), addr, size, flags, offset, m); }
675
676 L4_RPC_NF(long, find, (L4::Ipc::In_out<l4_addr_t *> addr,
678 L4Re::Rm::Flags *flags, Offset *offset,
680
686 struct Region
687 {
688 l4_addr_t start;
689 l4_addr_t end;
690 F::Region_flags flags;
691 };
692
699 struct Area
700 {
701 l4_addr_t start;
702 l4_addr_t end;
703 };
704
720
735
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,
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(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
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:306
Region_flag_shifts
Region flag shifts.
Definition rm:102
@ Caching_shift
Start of Rm cache bits.
Definition rm:104
Detach_flags
Flags for detach operation.
Definition rm:222
@ Detach_overlap
Do an unmap of all overlapping regions.
Definition rm:242
@ Detach_exact
Do an unmap of the exact region given.
Definition rm:232
@ Detach_keep
Do not free the detached data space, ignore the F::Detach_free.
Definition rm:251
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:280
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:672
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:34
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:765
@ 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.
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:700
Rm flags definitions.
Definition rm:109
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:112
@ Search_addr
Search for a suitable address range.
Definition rm:114
@ Attach_mask
Mask of all attach flags.
Definition rm:122
@ No_eager_map
Prevent eager mapping of the attached data space.
Definition rm:120
@ Eager_map
Eagerly map the attached data space in.
Definition rm:118
@ In_area
Search only in area, or map into area.
Definition rm:116
A region is a range of virtual addresses which is backed by content.
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