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 * This file is part of TUD:OS and distributed under the terms of the
15 * GNU General Public License 2.
16 * Please see the COPYING-GPL-2 file for details.
17 *
18 * As a special exception, you may use this file as part of a free software
19 * library without restriction. Specifically, if other files instantiate
20 * templates or use macros or inline functions from this file, or you compile
21 * this file and link it with other files to produce an executable, this
22 * file does not by itself cause the resulting executable to be covered by
23 * the GNU General Public License. This exception does not however
24 * invalidate any other reasons why the executable file might be covered by
25 * the GNU General Public License.
26 */
27#pragma once
28
29#include <l4/sys/types.h>
30#include <l4/sys/l4int.h>
31#include <l4/sys/capability>
32#include <l4/re/protocols.h>
33#include <l4/sys/pager>
34#include <l4/sys/cxx/ipc_iface>
35#include <l4/sys/cxx/ipc_ret_array>
36#include <l4/sys/cxx/types>
37#include <l4/re/consts>
38#include <l4/re/dataspace>
39
40namespace L4Re {
41
93 public L4::Kobject_t<Rm, L4::Pager, L4RE_PROTO_RM,
94 L4::Type_info::Demand_t<1> >
95{
96public:
97 typedef L4Re::Dataspace::Offset Offset;
98
101 {
102 Detached_ds = 0,
103 Kept_ds = 1,
104 Split_ds = 2,
105 Detach_result_mask = 3,
106
107 Detach_again = 4,
108 };
109
110
113 {
115 Caching_shift = Dataspace::F::Caching_shift,
116 };
117
119 struct F
120 {
123 {
125 Search_addr = 0x20000,
127 In_area = 0x40000,
129 Eager_map = 0x80000,
131 No_eager_map = 0x100000,
133 Attach_mask = 0x1f0000,
134 };
135
137
140 {
142 Rights_mask = 0x0f,
144 R = Dataspace::F::R,
146 W = Dataspace::F::W,
148 X = Dataspace::F::X,
150 RW = Dataspace::F::RW,
152 RX = Dataspace::F::RX,
154 RWX = Dataspace::F::RWX,
155
157 Detach_free = 0x200,
159 Pager = 0x400,
161 Reserved = 0x800,
162
163
165 Caching_mask = Dataspace::F::Caching_mask,
167 Cache_normal = Dataspace::F::Normal,
169 Cache_buffered = Dataspace::F::Bufferable,
171 Cache_uncached = Dataspace::F::Uncacheable,
172
174 Ds_map_mask = 0xff,
175
177 Region_flags_mask = 0xffff,
178 };
179
181
182 friend constexpr Dataspace::Flags map_flags(Region_flags rf)
183 {
184 return Dataspace::Flags(static_cast<l4_uint16_t>(rf) & Ds_map_mask);
185 }
186
187 struct Flags : L4::Types::Flags_ops_t<Flags>
188 {
189 l4_uint32_t raw;
190 Flags() = default;
191 explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
192 constexpr Flags(Attach_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
193 constexpr Flags(Region_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
194
195 friend constexpr Dataspace::Flags map_flags(Flags f)
196 {
197 return Dataspace::Flags(f.raw & Ds_map_mask);
198 }
199
200 constexpr Region_flags region_flags() const
201 {
202 return Region_flags(raw & Region_flags_mask);
203 }
204
205 constexpr Attach_flags attach_flags() const
206 {
207 return Attach_flags(raw & Attach_mask);
208 }
209
210 constexpr bool r() const { return raw & L4_FPAGE_RO; }
211 constexpr bool w() const { return raw & L4_FPAGE_W; }
212 constexpr bool x() const { return raw & L4_FPAGE_X; }
213 constexpr unsigned cap_rights() const
214 { return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
215 };
216
217 friend constexpr Flags operator | (Region_flags l, Attach_flags r)
218 { return Flags(l) | Flags(r); }
219
220 friend constexpr Flags operator | (Attach_flags l, Region_flags r)
221 { return Flags(l) | Flags(r); }
222 };
223
224 using Attach_flags = F::Attach_flags;
225 using Region_flags = F::Region_flags;
226 using Flags = F::Flags;
227
230 {
240 Detach_exact = 1,
250 Detach_overlap = 2,
251
259 Detach_keep = 4,
260 };
261
288 long reserve_area(l4_addr_t *start, unsigned long size,
289 Flags flags = Flags(0),
290 unsigned char align = L4_PAGESHIFT) const noexcept
291 { return reserve_area_t::call(c(), start, size, flags, align); }
292
293 L4_RPC_NF(long, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
294 unsigned long size,
295 Flags flags,
296 unsigned char align));
297
313 template< typename T >
314 long reserve_area(T **start, unsigned long size,
315 Flags flags = Flags(0),
316 unsigned char align = L4_PAGESHIFT) const noexcept
317 {
318 return reserve_area_t::call(c(), reinterpret_cast<l4_addr_t*>(start), size,
319 flags, align);
320 }
321
334 L4_RPC(long, free_area, (l4_addr_t addr));
335
336 L4_RPC_NF(long, attach, (L4::Ipc::In_out<l4_addr_t *> start,
337 unsigned long size, Flags flags,
339 Offset offs, unsigned char align,
340 L4::Ipc::Opt<l4_cap_idx_t> client_cap));
341
342 L4_RPC_NF(long, detach, (l4_addr_t addr, unsigned long size, unsigned flags,
343 l4_addr_t &start, l4_addr_t &rsize,
344 l4_cap_idx_t &mem_cap));
345
401 long attach(l4_addr_t *start, unsigned long size, Flags flags,
402 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
403 unsigned char align = L4_PAGESHIFT,
404 L4::Cap<L4::Task> const task
405 = L4::Cap<L4::Task>::Invalid) const noexcept;
406
410 template< typename T >
411 long attach(T **start, unsigned long size, Flags flags,
412 L4::Ipc::Cap<Dataspace> mem, Offset offs = 0,
413 unsigned char align = L4_PAGESHIFT,
414 L4::Cap<L4::Task> const task
415 = L4::Cap<L4::Task>::Invalid) 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 }
421
422#if __cplusplus >= 201103L
433 template< typename T >
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
541 { reset(0, L4::Cap<Rm>::Invalid); }
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
563 = L4::Cap<L4::Task>::Invalid) const noexcept
564 {
565 l4_addr_t addr = reinterpret_cast<l4_addr_t>(start->get());
566
567 long res = attach(&addr, size, flags, mem, offs, align, task);
568 if (res < 0)
569 return res;
570
571 start->reset(reinterpret_cast<T>(addr), L4::Cap<Rm>(cap()));
572 return res;
573 }
574#endif
575
593 int detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
594 L4::Cap<L4::Task> const &task = This_task) const noexcept;
595
599 int detach(void *addr, L4::Cap<Dataspace> *mem,
600 L4::Cap<L4::Task> const &task = This_task) const noexcept;
601
621 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
622 L4::Cap<L4::Task> const &task) const noexcept;
623
668 long find(l4_addr_t *addr, unsigned long *size, Offset *offset,
669 L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
670 { return find_t::call(c(), addr, size, flags, offset, m); }
671
672 L4_RPC_NF(long, find, (L4::Ipc::In_out<l4_addr_t *> addr,
674 L4Re::Rm::Flags *flags, Offset *offset,
676
687
693 using Region = Range;
694
701 using Area = Range;
702
717 L4_RPC(long, get_regions, (l4_addr_t start, L4::Ipc::Ret_array<Range> regions));
718
734 L4_RPC(long, get_areas, (l4_addr_t start, L4::Ipc::Ret_array<Range> areas));
735
736 int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
737 L4::Cap<L4::Task> task, unsigned flags) const noexcept;
738
739 typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
740 reserve_area_t, free_area_t,
741 get_regions_t, get_areas_t> Rpcs;
742};
743
744
745inline int
747 L4::Cap<L4::Task> const &task) const noexcept
748{ return detach(addr, 1, mem, task, Detach_overlap); }
749
750inline int
752 L4::Cap<L4::Task> const &task) const noexcept
753{
754 return detach(reinterpret_cast<l4_addr_t>(addr), 1, mem, task,
755 Detach_overlap);
756}
757
758inline int
759Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
760 L4::Cap<L4::Task> const &task) const noexcept
761{ return detach(addr, size, mem, task, Detach_exact); }
762
763};
L4::Cap related definitions.
Unique region.
Definition rm:435
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:95
Detach_result
Result values for detach operation.
Definition rm:101
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:314
Region_flag_shifts
Region flag shifts.
Definition rm:113
long attach(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) const noexcept
Attach a data space to a region.
Definition rm:411
Detach_flags
Flags for detach operation.
Definition rm:230
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:288
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:668
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:746
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:219
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:563
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:761
Dataspace interface.
unsigned long l4_addr_t
Address type.
Definition l4int.h:45
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:40
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:38
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:359
@ L4_FPAGE_X
Executable flex page.
Definition __l4_fpage.h:126
@ L4_FPAGE_RO
Read-only flex page
Definition __l4_fpage.h:128
@ L4_FPAGE_W
Writable flex page.
Definition __l4_fpage.h:127
@ L4_CAP_FPAGE_RO
Read right for capability flex-pages.
Definition __l4_fpage.h:179
@ L4_CAP_FPAGE_RW
Read and interface specific 'W' right for capability flex-pages.
Definition __l4_fpage.h:195
#define L4_PAGESHIFT
Size of a page, log2-based.
Definition consts.h:37
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:231
Interface Definition Language.
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:528
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:497
Common L4 ABI Data Types.
L4Re C++ Interfaces.
Definition l4re.dox:17
L4 low-level kernel interface.
Definition io_regblock.h:19
Pager and Io_pager C++ interface.
L4Re Protocol Constants (C version)
Constants.
Rm flags definitions.
Definition rm:120
Region_flags
Region flags (permissions, cacheability, special).
Definition rm:140
Attach_flags
Flags for attach operation.
Definition rm:123
A range of virtual addresses.
Definition rm:681
l4_addr_t start
First address of the range.
Definition rm:683
l4_addr_t end
Last address of the range.
Definition rm:685
Pass the argument as plain data value.
Definition ipc_types:128
Mark an argument as in-out argument.
Definition ipc_types:53
Attribute for defining an optional RPC argument.
Definition ipc_types:148
Dynamically sized output array of type T.
Definition ipc_ret_array:35
Standard list of RPCs of an interface.
Definition __typeinfo.h:439
Mixin class to define a set of friend bitwise operators on DT.
Definition types:232
#define L4_TYPES_FLAGS_OPS_DEF(T)
Helper macro to define a set of bitwise operators on an enum type.
Definition types:206