L4Re - L4 Runtime Environment
env
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  * economic rights: Technische Universität Dresden (Germany)
12  *
13  * This file is part of TUD:OS and distributed under the terms of the
14  * GNU General Public License 2.
15  * Please see the COPYING-GPL-2 file for details.
16  *
17  * As a special exception, you may use this file as part of a free software
18  * library without restriction. Specifically, if other files instantiate
19  * templates or use macros or inline functions from this file, or you compile
20  * this file and link it with other files to produce an executable, this
21  * file does not by itself cause the resulting executable to be covered by
22  * the GNU General Public License. This exception does not however
23  * invalidate any other reasons why the executable file might be covered by
24  * the GNU General Public License.
25  */
26 #pragma once
27 
28 #include <l4/sys/types.h>
29 
30 #include <l4/re/rm>
31 #include <l4/re/parent>
32 #include <l4/re/mem_alloc>
33 #include <l4/re/log>
34 #include <l4/re/consts>
35 
36 #include <l4/re/env.h>
37 
38 namespace L4 {
39 class Scheduler;
40 }
41 
45 namespace L4Re
46 {
85  class L4_EXPORT Env
86  {
87  private:
88  l4re_env_t _env;
89  public:
90 
95 
103  static Env const *env() noexcept
104  { return reinterpret_cast<Env*>(l4re_global_env); }
105 
110  L4::Cap<Parent> parent() const noexcept
111  { return L4::Cap<Parent>(_env.parent); }
116  L4::Cap<Mem_alloc> mem_alloc() const noexcept
117  { return L4::Cap<Mem_alloc>(_env.mem_alloc); }
122  { return L4::Cap<L4::Factory>(_env.mem_alloc); }
127  L4::Cap<Rm> rm() const noexcept
128  { return L4::Cap<Rm>(_env.rm); }
133  L4::Cap<Log> log() const noexcept
134  { return L4::Cap<Log>(_env.log); }
140  { return L4::Cap<L4::Thread>(_env.main_thread); }
145  L4::Cap<L4::Task> task() const noexcept
146  { return L4::Cap<L4::Task>(L4RE_THIS_TASK_CAP); }
151  L4::Cap<L4::Factory> factory() const noexcept
152  { return L4::Cap<L4::Factory>(_env.factory); }
159  l4_cap_idx_t first_free_cap() const noexcept
160  { return _env.first_free_cap; }
165  l4_fpage_t utcb_area() const noexcept
166  { return _env.utcb_area; }
174  l4_addr_t first_free_utcb() const noexcept
175  { return _env.first_free_utcb; }
176 
181  Cap_entry const *initial_caps() const noexcept
182  { return _env.caps; }
183 
192  Cap_entry const *get(char const *name, unsigned l) const noexcept
193  { return l4re_env_get_cap_l(name, l, &_env); }
194 
203  template< typename T >
204  L4::Cap<T> get_cap(char const *name, unsigned l) const noexcept
205  {
206  if (Cap_entry const *e = get(name, l))
207  return L4::Cap<T>(e->cap);
208 
209  return L4::Cap<T>(-L4_ENOENT);
210  }
211 
218  template< typename T >
219  L4::Cap<T> get_cap(char const *name) const noexcept
220  { return get_cap<T>(name, __builtin_strlen(name)); }
221 
226  void parent(L4::Cap<Parent> const &c) noexcept
227  { _env.parent = c.cap(); }
232  void mem_alloc(L4::Cap<Mem_alloc> const &c) noexcept
233  { _env.mem_alloc = c.cap(); }
238  void rm(L4::Cap<Rm> const &c) noexcept
239  { _env.rm = c.cap(); }
244  void log(L4::Cap<Log> const &c) noexcept
245  { _env.log = c.cap(); }
250  void main_thread(L4::Cap<L4::Thread> const &c) noexcept
251  { _env.main_thread = c.cap(); }
256  void factory(L4::Cap<L4::Factory> const &c) noexcept
257  { _env.factory = c.cap(); }
262  void first_free_cap(l4_cap_idx_t c) noexcept
263  { _env.first_free_cap = c; }
268  void utcb_area(l4_fpage_t utcbs) noexcept
269  { _env.utcb_area = utcbs; }
274  void first_free_utcb(l4_addr_t u) noexcept
275  { _env.first_free_utcb = u; }
276 
283  { return L4::Cap<L4::Scheduler>(_env.scheduler); }
284 
289  void scheduler(L4::Cap<L4::Scheduler> const &c) noexcept
290  { _env.scheduler = c.cap(); }
291 
296  void initial_caps(Cap_entry *first) noexcept
297  { _env.caps = first; }
298  };
299 };
void first_free_cap(l4_cap_idx_t c) noexcept
Set first available capability selector.
Definition: env:262
No such entity.
Definition: err.h:45
void main_thread(L4::Cap< L4::Thread > const &c) noexcept
Set object-capability of first user thread.
Definition: env:250
void initial_caps(Cap_entry *first) noexcept
Set the pointer to the first Cap_entry in the initial objects array.
Definition: env:296
Constants.
l4_fpage_t utcb_area
UTCB area of the task.
Definition: env.h:119
Parent interface.
l4re_env_cap_entry_t Cap_entry
C++ type for an entry in the initial objects array.
Definition: env:94
l4_cap_idx_t parent
Parent object-capability.
Definition: env.h:111
Initial environment data structure.
Definition: env.h:109
l4_addr_t first_free_utcb() const noexcept
First free UTCB.
Definition: env:174
Log interface.
Common L4 ABI Data Types.
L4 low-level kernel interface.
l4_cap_idx_t first_free_cap
First capability index available to the application.
Definition: env.h:118
C++ interface of the initial environment that is provided to an L4 task.
Definition: env:85
l4_fpage_t utcb_area() const noexcept
UTCB area of the task.
Definition: env:165
void mem_alloc(L4::Cap< Mem_alloc > const &c) noexcept
Set memory allocator object-capability.
Definition: env:232
Memory allocator interface.
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
L4Re C++ Interfaces.
Definition: cmd_control:15
Environment interface.
Cap_entry const * initial_caps() const noexcept
Get a pointer to the first entry in the initial objects array.
Definition: env:181
L4::Cap< L4::Factory > user_factory() const noexcept
Object-capability to the user-level object factory.
Definition: env:121
void rm(L4::Cap< Rm > const &c) noexcept
Set region map object-capability.
Definition: env:238
L4::Cap< T > get_cap(char const *name, unsigned l) const noexcept
Get the capability selector for the object named name.
Definition: env:204
L4::Cap< Rm > rm() const noexcept
Object-capability to the region map.
Definition: env:127
L4::Cap< T > get_cap(char const *name) const noexcept
Get the capability selector for the object named name.
Definition: env:219
L4::Cap< L4::Thread > main_thread() const noexcept
Object-capability of the first user thread.
Definition: env:139
L4::Cap< Mem_alloc > mem_alloc() const noexcept
Object-capability to the memory allocator.
Definition: env:116
Region mapper interface.
l4_cap_idx_t rm
Region map object-capability.
Definition: env.h:112
void scheduler(L4::Cap< L4::Scheduler > const &c) noexcept
Set the scheduler capability.
Definition: env:289
L4::Cap< L4::Task > task() const noexcept
Object-capability of the user task.
Definition: env:145
l4re_env_cap_entry_t const * l4re_env_get_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW
Get the full l4re_env_cap_entry_t for the object named name.
Definition: env.h:196
void log(L4::Cap< Log > const &c) noexcept
Set log object-capability.
Definition: env:244
l4_addr_t first_free_utcb
First UTCB within the UTCB area available to the application.
Definition: env.h:120
void first_free_utcb(l4_addr_t u) noexcept
Set first free UTCB.
Definition: env:274
void utcb_area(l4_fpage_t utcbs) noexcept
Set UTCB area of the task.
Definition: env:268
L4::Cap< Parent > parent() const noexcept
Object-capability to the parent.
Definition: env:110
L4::Cap< L4::Factory > factory() const noexcept
Object-capability to the factory object available to the task.
Definition: env:151
L4 flexpage type.
Definition: __l4_fpage.h:83
void factory(L4::Cap< L4::Factory > const &c) noexcept
Set factory object-capability.
Definition: env:256
l4_cap_idx_t main_thread
Object-capability of the first user thread.
Definition: env.h:115
l4_cap_idx_t factory
Object-capability of the factory available to the task.
Definition: env.h:116
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition: env:103
C++ interface for capabilities.
Definition: capability.h:13
void parent(L4::Cap< Parent > const &c) noexcept
Set parent object-capability.
Definition: env:226
l4_cap_idx_t first_free_cap() const noexcept
First available capability selector.
Definition: env:159
l4_cap_idx_t scheduler
Object capability for the scheduler set to use.
Definition: env.h:117
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
L4::Cap< Log > log() const noexcept
Object-capability to the logging service.
Definition: env:133
l4_cap_idx_t mem_alloc
Memory allocator object-capability.
Definition: env.h:113
Entry in the L4Re environment array for the named inital objects.
Definition: env.h:50
L4::Cap< L4::Scheduler > scheduler() const noexcept
Get the scheduler capability for the task.
Definition: env:282
l4_cap_idx_t log
Logging object-capability.
Definition: env.h:114