Loading...
Searching...
No Matches
rm
Go to the documentation of this file.
// -*- Mode: C++ -*-
// vim:ft=cpp
/*
* (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
* Alexander Warg <warg@os.inf.tu-dresden.de>,
* Björn Döbel <doebel@os.inf.tu-dresden.de>,
* Torsten Frenzel <frenzel@os.inf.tu-dresden.de>
* economic rights: Technische Universität Dresden (Germany)
*
* License: see LICENSE.spdx (in this directory or the directories above)
*/
#pragma once
#include <l4/sys/types.h>
#include <l4/sys/l4int.h>
#include <l4/sys/capability>
#include <l4/re/protocols.h>
#include <l4/sys/pager>
#include <l4/sys/cxx/ipc_iface>
#include <l4/sys/cxx/ipc_ret_array>
#include <l4/sys/cxx/types>
#include <l4/re/consts>
#include <l4/re/dataspace>
namespace L4Re {
class L4_EXPORT Rm :
public L4::Kobject_t<Rm, L4::Pager, L4RE_PROTO_RM,
L4::Type_info::Demand_t<1> >
{
public:
typedef L4Re::Dataspace::Offset Offset;
enum Detach_result
{
Detached_ds = 0,
Kept_ds = 1,
Split_ds = 2,
Detach_result_mask = 3,
Detach_again = 4,
};
enum Region_flag_shifts
{
Caching_shift = Dataspace::F::Caching_shift,
};
struct F
{
enum Attach_flags : l4_uint32_t
{
Search_addr = 0x20000,
In_area = 0x40000,
Eager_map = 0x80000,
No_eager_map = 0x100000,
Attach_mask = 0x1f0000,
};
L4_TYPES_FLAGS_OPS_DEF(Attach_flags);
enum Region_flags : l4_uint16_t
{
Rights_mask = 0x0f,
R = Dataspace::F::R,
W = Dataspace::F::W,
X = Dataspace::F::X,
RW = Dataspace::F::RW,
RX = Dataspace::F::RX,
RWX = Dataspace::F::RWX,
Kernel = 0x100,
Detach_free = 0x200,
Pager = 0x400,
Reserved = 0x800,
Caching_mask = Dataspace::F::Caching_mask,
Cache_normal = Dataspace::F::Normal,
Cache_buffered = Dataspace::F::Bufferable,
Cache_uncached = Dataspace::F::Uncacheable,
Ds_map_mask = 0xff,
Region_flags_mask = 0xffff,
};
L4_TYPES_FLAGS_OPS_DEF(Region_flags);
friend constexpr Dataspace::Flags map_flags(Region_flags rf)
{
return Dataspace::Flags(static_cast< l4_uint16_t >(rf) & Ds_map_mask);
}
struct Flags : L4::Types::Flags_ops_t<Flags>
{
l4_uint32_t raw;
Flags() = default;
explicit constexpr Flags(l4_uint32_t f) : raw(f) {}
constexpr Flags(Attach_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
constexpr Flags(Region_flags rf) : raw(static_cast<l4_uint32_t>(rf)) {}
friend constexpr Dataspace::Flags map_flags(Flags f)
{
return Dataspace::Flags(f.raw & Ds_map_mask);
}
constexpr Region_flags region_flags() const
{
return Region_flags(raw & Region_flags_mask);
}
constexpr Attach_flags attach_flags() const
{
return Attach_flags(raw & Attach_mask);
}
constexpr bool r() const { return raw & L4_FPAGE_RO; }
constexpr bool w() const { return raw & L4_FPAGE_W; }
constexpr bool x() const { return raw & L4_FPAGE_X; }
constexpr unsigned cap_rights() const
{ return w() ? L4_CAP_FPAGE_RW : L4_CAP_FPAGE_RO; }
};
friend constexpr Flags operator | (Region_flags l, Attach_flags r)
{ return Flags(l) | Flags(r); }
friend constexpr Flags operator | (Attach_flags l, Region_flags r)
{ return Flags(l) | Flags(r); }
};
using Attach_flags = F::Attach_flags;
using Region_flags = F::Region_flags;
using Flags = F::Flags;
enum Detach_flags
{
Detach_exact = 1,
Detach_overlap = 2,
Detach_keep = 4,
};
long reserve_area(l4_addr_t *start, unsigned long size,
Flags flags = Flags(0),
unsigned char align = L4_PAGESHIFT) const noexcept
{ return reserve_area_t::call(c(), start, size, flags, align); }
L4_RPC_NF(long, reserve_area, (L4::Ipc::In_out<l4_addr_t *> start,
unsigned long size,
Flags flags,
unsigned char align));
template< typename T >
long reserve_area(T **start, unsigned long size,
Flags flags = Flags(0),
unsigned char align = L4_PAGESHIFT) const noexcept
{
return reserve_area_t::call(c(), reinterpret_cast< l4_addr_t*>(start), size,
flags, align);
}
L4_RPC(long, free_area, (l4_addr_t addr));
L4_RPC_NF(long, attach, (L4::Ipc::In_out<l4_addr_t *> start,
unsigned long size, Flags flags,
L4::Ipc::Opt<L4::Ipc::Cap<Dataspace> > mem,
Offset offs, unsigned char align,
L4::Ipc::Opt<l4_cap_idx_t> client_cap,
L4::Ipc::String<> name, Offset backing_offset));
L4_RPC_NF(long, detach, (l4_addr_t addr, unsigned long size, unsigned flags,
l4_addr_t &start, l4_addr_t &rsize,
l4_cap_idx_t &mem_cap));
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;
template< typename T >
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,
char const *name = nullptr,
Offset backing_offset = 0) const noexcept
{
union X { l4_addr_t a; T* t; };
X *x = reinterpret_cast<X*>(start);
return attach(&x->a, size, flags, mem, offs, align, task,
name, backing_offset);
}
#if __cplusplus >= 201103L
template< typename T >
class Unique_region
{
private:
T _addr;
L4::Cap<Rm> _rm;
public:
Unique_region(Unique_region const &) = delete;
Unique_region &operator = (Unique_region const &) = delete;
Unique_region() noexcept
: _addr(0), _rm(L4::Cap<Rm>::Invalid) {}
explicit Unique_region(T addr) noexcept
: _addr(addr), _rm(L4::Cap<Rm>::Invalid) {}
Unique_region(T addr, L4::Cap<Rm> const &rm) noexcept
: _addr(addr), _rm(rm) {}
Unique_region(Unique_region &&o) noexcept : _addr(o.get()), _rm(o._rm)
{ o.release(); }
Unique_region &operator = (Unique_region &&o) noexcept
{
if (&o != this)
{
if (_rm.is_valid())
_rm->detach(reinterpret_cast< l4_addr_t >(_addr), 0);
_rm = o._rm;
_addr = o.release();
}
return *this;
}
~Unique_region() noexcept
{
if (_rm.is_valid())
_rm->detach(reinterpret_cast< l4_addr_t >(_addr), 0);
}
T get() const noexcept
{ return _addr; }
T release() noexcept
{
_rm = L4::Cap<Rm>::Invalid;
return _addr;
}
void reset(T addr, L4::Cap<Rm> const &rm) noexcept
{
if (_rm.is_valid())
_rm->detach(l4_addr_t(_addr), 0);
_rm = rm;
_addr = addr;
}
void reset() noexcept
{ reset(0, L4::Cap<Rm>::Invalid); }
bool is_valid() const noexcept
{ return _rm.is_valid(); }
T operator * () const noexcept { return _addr; }
T operator -> () const noexcept { return _addr; }
};
template< typename T >
long attach(Unique_region<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
{
l4_addr_t addr = reinterpret_cast< l4_addr_t >(start->get());
long res = attach(&addr, size, flags, mem, offs, align, task,
name, backing_offset);
if (res < 0)
return res;
start->reset(reinterpret_cast<T>(addr), L4::Cap<Rm>(cap()));
return res;
}
#endif
int detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> const &task = This_task) const noexcept;
int detach(void *addr, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> const &task = This_task) const noexcept;
int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> const &task) const noexcept;
long find(l4_addr_t *addr, unsigned long *size, Offset *offset,
L4Re::Rm::Flags *flags, L4::Cap<Dataspace> *m) noexcept
{ return find_t::call(c(), addr, size, flags, offset, m); }
L4_RPC_NF(long, find, (L4::Ipc::In_out<l4_addr_t *> addr,
L4::Ipc::In_out<unsigned long *> size,
L4Re::Rm::Flags *flags, Offset *offset,
L4::Ipc::As_value<L4::Cap<Dataspace> > *m));
struct Region
{
l4_addr_t start;
l4_addr_t end;
F::Region_flags flags;
};
struct Area
{
l4_addr_t start;
l4_addr_t end;
};
L4_RPC(long, get_regions, (l4_addr_t start, L4::Ipc::Ret_array<Region> regions));
L4_RPC(long, get_areas, (l4_addr_t start, L4::Ipc::Ret_array<Area> areas));
L4_RPC(long, get_info, (l4_addr_t addr, L4::Ipc::String<char> &name,
Offset &backing_offset));
int detach(l4_addr_t start, unsigned long size, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> task, unsigned flags) const noexcept;
typedef L4::Typeid::Rpcs<attach_t, detach_t, find_t,
reserve_area_t, free_area_t,
get_regions_t, get_areas_t,
get_info_t> Rpcs;
};
inline int
Rm::detach(l4_addr_t addr, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> const &task) const noexcept
{ return detach(addr, 1, mem, task, Detach_overlap); }
inline int
Rm::detach(void *addr, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> const &task) const noexcept
{
return detach(reinterpret_cast< l4_addr_t >(addr), 1, mem, task,
Detach_overlap);
}
inline int
Rm::detach(l4_addr_t addr, unsigned long size, L4::Cap<Dataspace> *mem,
L4::Cap<L4::Task> const &task) const noexcept
{ return detach(addr, size, mem, task, Detach_exact); }
};
capability
L4::Cap related definitions.
L4Re::Dataspace
Interface for memory-like objects.
Definition dataspace:53
L4Re::Rm::Unique_region::Unique_region
Unique_region(T addr) noexcept
Construct a Unique_region from an address.
Definition rm:456
L4Re::Rm::Unique_region::Unique_region
Unique_region(Unique_region &&o) noexcept
Move-Construct a Unique_region.
Definition rm:473
L4Re::Rm::Unique_region::get
T get() const noexcept
Return the address.
Definition rm:509
L4Re::Rm::Unique_region::reset
void reset() noexcept
Make the Unique_region invalid.
Definition rm:541
L4Re::Rm::Unique_region::is_valid
bool is_valid() const noexcept
Check if the Unique_region is valid.
Definition rm:549
L4Re::Rm::Unique_region::reset
void reset(T addr, L4::Cap< Rm > const &rm) noexcept
Set new address and region manager.
Definition rm:529
L4Re::Rm::Unique_region::Unique_region
Unique_region() noexcept
Construct an invalid Unique_region.
Definition rm:448
L4Re::Rm::Unique_region::~Unique_region
~Unique_region() noexcept
Destructor.
Definition rm:498
L4Re::Rm::Unique_region::Unique_region
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
L4Re::Rm::Unique_region::release
T release() noexcept
Return the address and invalidate the Unique_region.
Definition rm:517
L4Re::Rm
Region map.
Definition rm:84
L4Re::Rm::free_area
long free_area(l4_addr_t addr)
Free an area from the region map.
L4Re::Rm::Detach_result
Detach_result
Result values for detach operation.
Definition rm:90
L4Re::Rm::Detached_ds
@ Detached_ds
Detached data sapce.
Definition rm:91
L4Re::Rm::Detach_again
@ Detach_again
Detached data space, more to do.
Definition rm:96
L4Re::Rm::Split_ds
@ Split_ds
Splitted data space, and done.
Definition rm:93
L4Re::Rm::Kept_ds
@ Kept_ds
Kept data space.
Definition rm:92
L4Re::Rm::reserve_area
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
L4Re::Rm::Region_flag_shifts
Region_flag_shifts
Region flag shifts.
Definition rm:102
L4Re::Rm::Caching_shift
@ Caching_shift
Start of Rm cache bits.
Definition rm:104
L4Re::Rm::Detach_flags
Detach_flags
Flags for detach operation.
Definition rm:222
L4Re::Rm::Detach_overlap
@ Detach_overlap
Do an unmap of all overlapping regions.
Definition rm:242
L4Re::Rm::Detach_exact
@ Detach_exact
Do an unmap of the exact region given.
Definition rm:232
L4Re::Rm::Detach_keep
@ Detach_keep
Do not free the detached data space, ignore the F::Detach_free.
Definition rm:251
L4Re::Rm::reserve_area
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
L4Re::Rm::get_regions
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...
L4Re::Rm::find
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
L4Re::Rm::get_areas
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...
L4Re::Rm::attach
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
L4Re::Rm::get_info
long get_info(l4_addr_t addr, L4::Ipc::String< char > &name, Offset &backing_offset)
Return auxiliary information of a region.
L4Re::Rm::detach
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
L4::Cap_base::Invalid
@ Invalid
Invalid capability selector.
Definition capability.h:42
L4::Cap
C++ interface for capabilities.
Definition capability.h:224
L4::Ipc::Cap
Capability type for RPC interfaces (see L4::Cap<T>).
Definition ipc_types:699
L4::Kobject_t
Helper class to create an L4Re interface class that is derived from a single base class.
Definition __typeinfo.h:750
L4::Kobject_t< Rm, L4::Pager, L4RE_PROTO_RM, L4::Type_info::Demand_t< 1 > >::c
L4::Cap< Class > c() const noexcept
Definition __typeinfo.h:769
dataspace
Dataspace interface.
l4_addr_t
unsigned long l4_addr_t
Address type.
Definition l4int.h:34
l4_uint32_t
unsigned int l4_uint32_t
Unsigned 32bit value.
Definition l4int.h:29
l4_uint16_t
unsigned short int l4_uint16_t
Unsigned 16bit value.
Definition l4int.h:27
l4_cap_idx_t
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:336
L4_FPAGE_X
@ L4_FPAGE_X
Executable flexpage.
Definition __l4_fpage.h:120
L4_FPAGE_RO
@ L4_FPAGE_RO
Read-only flexpage.
Definition __l4_fpage.h:122
L4_FPAGE_W
@ L4_FPAGE_W
Writable flexpage.
Definition __l4_fpage.h:121
L4_CAP_FPAGE_RO
@ L4_CAP_FPAGE_RO
Read right for capability flexpages.
Definition __l4_fpage.h:176
L4_CAP_FPAGE_RW
@ L4_CAP_FPAGE_RW
Read and interface specific 'W' right for capability flexpages.
Definition __l4_fpage.h:192
L4_PAGESHIFT
#define L4_PAGESHIFT
Size of a page, log2-based.
Definition consts.h:26
L4_EXPORT
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:214
ipc_iface
Interface Definition Language.
L4_RPC
#define L4_RPC(res, name, args, attr...)
Define an RPC call (type and callable).
Definition ipc_iface:541
L4_RPC_NF
#define L4_RPC_NF(res, name, args...)
Define an RPC call type (the type only, no callable).
Definition ipc_iface:510
l4int.h
Fixed sized integer types, generic version.
types.h
Common L4 ABI Data Types.
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4
L4 low-level kernel interface.
Definition l4sys-l4f-groups.dox:50
pager
Pager and Io_pager C++ interface.
protocols.h
L4Re Protocol Constants (C version).
consts
Constants.
L4Re::Dataspace::F::Caching_shift
@ Caching_shift
shift value for caching flags
Definition dataspace:61
L4Re::Dataspace::F::Uncacheable
@ Uncacheable
Request uncacheable memory mappings.
Definition dataspace:97
L4Re::Dataspace::F::RW
@ RW
Request read-write mapping.
Definition dataspace:77
L4Re::Dataspace::F::Normal
@ Normal
Request normal (cached) memory mapping.
Definition dataspace:91
L4Re::Dataspace::F::Caching_mask
@ Caching_mask
Mask for caching flags.
Definition dataspace:99
L4Re::Dataspace::F::X
@ X
Request execute-only mapping.
Definition dataspace:81
L4Re::Dataspace::F::R
@ R
Request read-only mapping.
Definition dataspace:73
L4Re::Dataspace::F::RWX
@ RWX
Request read-write-execute mapping.
Definition dataspace:85
L4Re::Dataspace::F::W
@ W
Request write-only mapping.
Definition dataspace:79
L4Re::Dataspace::F::Bufferable
@ Bufferable
Request bufferable (write buffered) mappings.
Definition dataspace:95
L4Re::Dataspace::F::RX
@ RX
Request read-execute mapping.
Definition dataspace:83
L4Re::Rm::Area
An area is a range of virtual addresses which is reserved, see L4Re::Rm::reserve_area().
Definition rm:700
L4Re::Rm::F
Rm flags definitions.
Definition rm:109
L4Re::Rm::F::Region_flags
Region_flags
Region flags (permissions, cacheability, special).
Definition rm:129
L4Re::Rm::F::Cache_uncached
@ Cache_uncached
Cache bits for uncached memory.
Definition rm:163
L4Re::Rm::F::Rights_mask
@ Rights_mask
Region rights.
Definition rm:131
L4Re::Rm::F::Region_flags_mask
@ Region_flags_mask
Mask of all region flags.
Definition rm:169
L4Re::Rm::F::Ds_map_mask
@ Ds_map_mask
Mask for all bits for cache options and rights.
Definition rm:166
L4Re::Rm::F::Reserved
@ Reserved
Region is reserved (blocked).
Definition rm:152
L4Re::Rm::F::Pager
@ Pager
Region has a pager.
Definition rm:150
L4Re::Rm::F::RWX
@ RWX
Readable, writable and executable region.
Definition rm:143
L4Re::Rm::F::RW
@ RW
Readable and writable region.
Definition rm:139
L4Re::Rm::F::RX
@ RX
Readable and executable region.
Definition rm:141
L4Re::Rm::F::X
@ X
Executable region.
Definition rm:137
L4Re::Rm::F::R
@ R
Readable region.
Definition rm:133
L4Re::Rm::F::Detach_free
@ Detach_free
Free the portion of the data space after detach.
Definition rm:148
L4Re::Rm::F::Cache_buffered
@ Cache_buffered
Cache bits for buffered (write combining) memory.
Definition rm:161
L4Re::Rm::F::W
@ W
Writable region.
Definition rm:135
L4Re::Rm::F::Cache_normal
@ Cache_normal
Cache bits for normal cacheable memory.
Definition rm:159
L4Re::Rm::F::Caching_mask
@ Caching_mask
Mask of all Rm cache bits.
Definition rm:156
L4Re::Rm::F::Kernel
@ Kernel
Kernel-provided memory (KUMEM).
Definition rm:146
L4Re::Rm::F::Attach_flags
Attach_flags
Flags for attach operation.
Definition rm:112
L4Re::Rm::F::Search_addr
@ Search_addr
Search for a suitable address range.
Definition rm:114
L4Re::Rm::F::Attach_mask
@ Attach_mask
Mask of all attach flags.
Definition rm:122
L4Re::Rm::F::No_eager_map
@ No_eager_map
Prevent eager mapping of the attached data space.
Definition rm:120
L4Re::Rm::F::Eager_map
@ Eager_map
Eagerly map the attached data space in.
Definition rm:118
L4Re::Rm::F::In_area
@ In_area
Search only in area, or map into area.
Definition rm:116
L4Re::Rm::Region
A region is a range of virtual addresses which is backed by content.
Definition rm:687
L4::Ipc::As_value
Pass the argument as plain data value.
Definition ipc_types:117
L4::Ipc::In_out
Mark an argument as in-out argument.
Definition ipc_types:42
L4::Ipc::Opt
Attribute for defining an optional RPC argument.
Definition ipc_types:137
L4::Ipc::Ret_array
Dynamically sized output array of type T.
Definition ipc_ret_array:24
L4::Typeid::Rpcs
Standard list of RPCs of an interface.
Definition __typeinfo.h:428
L4::Types::Flags_ops_t
Mixin class to define a set of friend bitwise operators on DT.
Definition types:221
types
L4_TYPES_FLAGS_OPS_DEF
#define L4_TYPES_FLAGS_OPS_DEF(T)
Helper macro to define a set of bitwise operators on an enum type.
Definition types:195