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 {
82  class L4_EXPORT Env
83  {
84  private:
85  l4re_env_t _env;
86  public:
87 
92 
100  static Env const *env() throw()
101  { return reinterpret_cast<Env*>(l4re_global_env); }
102 
107  L4::Cap<Parent> parent() const throw()
108  { return L4::Cap<Parent>(_env.parent); }
114  { return L4::Cap<Mem_alloc>(_env.mem_alloc); }
119  { return L4::Cap<L4::Factory>(_env.mem_alloc); }
124  L4::Cap<Rm> rm() const throw()
125  { return L4::Cap<Rm>(_env.rm); }
130  L4::Cap<Log> log() const throw()
131  { return L4::Cap<Log>(_env.log); }
137  { return L4::Cap<L4::Thread>(_env.main_thread); }
142  L4::Cap<L4::Task> task() const throw()
143  { return L4::Cap<L4::Task>(L4RE_THIS_TASK_CAP); }
149  { return L4::Cap<L4::Factory>(_env.factory); }
156  l4_cap_idx_t first_free_cap() const throw()
157  { return _env.first_free_cap; }
162  l4_fpage_t utcb_area() const throw()
163  { return _env.utcb_area; }
171  l4_addr_t first_free_utcb() const throw()
172  { return _env.first_free_utcb; }
173 
178  Cap_entry const *initial_caps() const throw()
179  { return _env.caps; }
180 
189  Cap_entry const *get(char const *name, unsigned l) const throw()
190  { return l4re_env_get_cap_l(name, l, &_env); }
191 
200  template< typename T >
201  L4::Cap<T> get_cap(char const *name, unsigned l) const throw()
202  {
203  if (Cap_entry const *e = get(name, l))
204  return L4::Cap<T>(e->cap);
205 
206  return L4::Cap<T>(-L4_ENOENT);
207  }
208 
215  template< typename T >
216  L4::Cap<T> get_cap(char const *name) const throw()
217  { return get_cap<T>(name, __builtin_strlen(name)); }
218 
223  void parent(L4::Cap<Parent> const &c) throw()
224  { _env.parent = c.cap(); }
229  void mem_alloc(L4::Cap<Mem_alloc> const &c) throw()
230  { _env.mem_alloc = c.cap(); }
235  void rm(L4::Cap<Rm> const &c) throw()
236  { _env.rm = c.cap(); }
241  void log(L4::Cap<Log> const &c) throw()
242  { _env.log = c.cap(); }
247  void main_thread(L4::Cap<L4::Thread> const &c) throw()
248  { _env.main_thread = c.cap(); }
253  void factory(L4::Cap<L4::Factory> const &c) throw()
254  { _env.factory = c.cap(); }
259  void first_free_cap(l4_cap_idx_t c) throw()
260  { _env.first_free_cap = c; }
265  void utcb_area(l4_fpage_t utcbs) throw()
266  { _env.utcb_area = utcbs; }
271  void first_free_utcb(l4_addr_t u) throw()
272  { _env.first_free_utcb = u; }
273 
280  { return L4::Cap<L4::Scheduler>(_env.scheduler); }
281 
286  void scheduler(L4::Cap<L4::Scheduler> const &c) throw()
287  { _env.scheduler = c.cap(); }
288 
293  void initial_caps(Cap_entry *first) throw()
294  { _env.caps = first; }
295  };
296 };
L4::Cap< Log > log() const
Object-capability to the logging service.
Definition: env:130
No such entity.
Definition: err.h:45
l4_addr_t first_free_utcb() const
First free UTCB.
Definition: env:171
void initial_caps(Cap_entry *first)
Set the pointer to the first Cap_entry in the initial objects array.
Definition: env:293
void mem_alloc(L4::Cap< Mem_alloc > const &c)
Set memory allocator object-capability.
Definition: env:229
l4_fpage_t utcb_area
UTCB area of the task.
Definition: env.h:115
Parent interface.
l4re_env_cap_entry_t Cap_entry
C++ type for an entry in the initial objects array.
Definition: env:91
l4_cap_idx_t parent
Parent object-capability.
Definition: env.h:107
L4::Cap< L4::Factory > factory() const
Object-capability to the factory object available to the task.
Definition: env:148
Constants.
Initial environment data structure.
Definition: env.h:105
l4_cap_idx_t first_free_cap() const
First available capability selector.
Definition: env:156
Log interface.
Common L4 ABI Data Types.
void utcb_area(l4_fpage_t utcbs)
Set UTCB area of the task.
Definition: env:265
L4::Cap< L4::Thread > main_thread() const
Object-capability of the first user thread.
Definition: env:136
void first_free_utcb(l4_addr_t u)
Set first free UTCB.
Definition: env:271
L4 low-level kernel interface.
l4_cap_idx_t first_free_cap
First capability index available to the application.
Definition: env.h:114
C++ interface of the initial environment that is provided to an L4 task.
Definition: env:82
Memory allocator interface.
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:341
L4Re C++ Interfaces.
Definition: cmd_control:15
Environment interface.
L4::Cap< L4::Scheduler > scheduler() const
Get the scheduler capability for the task.
Definition: env:279
void rm(L4::Cap< Rm > const &c)
Set region map object-capability.
Definition: env:235
void factory(L4::Cap< L4::Factory > const &c)
Set factory object-capability.
Definition: env:253
Region mapper interface.
void first_free_cap(l4_cap_idx_t c)
Set first available capability selector.
Definition: env:259
static Env const * env()
Returns the initial environment for the current task.
Definition: env:100
l4_cap_idx_t rm
Region map object-capability.
Definition: env.h:108
L4::Cap< L4::Factory > user_factory() const
Object-capability to the user-level object factory.
Definition: env:118
void log(L4::Cap< Log > const &c)
Set log object-capability.
Definition: env:241
void parent(L4::Cap< Parent > const &c)
Set parent object-capability.
Definition: env:223
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:192
l4_addr_t first_free_utcb
First UTCB within the UTCB area available to the application.
Definition: env.h:116
void scheduler(L4::Cap< L4::Scheduler > const &c)
Set the scheduler capability.
Definition: env:286
void main_thread(L4::Cap< L4::Thread > const &c)
Set object-capability of first user thread.
Definition: env:247
L4::Cap< Mem_alloc > mem_alloc() const
Object-capability to the memory allocator.
Definition: env:113
L4::Cap< L4::Task > task() const
Object-capability of the user task.
Definition: env:142
L4 flexpage type.
Definition: __l4_fpage.h:81
l4_cap_idx_t main_thread
Object-capability of the first user thread.
Definition: env.h:111
l4_cap_idx_t factory
Object-capability of the factory available to the task.
Definition: env.h:112
L4::Cap< T > get_cap(char const *name) const
Get the capability selector for the object named name.
Definition: env:216
L4::Cap< T > get_cap(char const *name, unsigned l) const
Get the capability selector for the object named name.
Definition: env:201
C++ interface for capabilities.
Definition: capability.h:13
l4_cap_idx_t scheduler
Object capability for the scheduler set to use.
Definition: env.h:113
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
l4_fpage_t utcb_area() const
UTCB area of the task.
Definition: env:162
l4_cap_idx_t mem_alloc
Memory allocator object-capability.
Definition: env.h:109
Entry in the L4Re environment array for the named inital objects.
Definition: env.h:46
L4::Cap< Parent > parent() const
Object-capability to the parent.
Definition: env:107
L4::Cap< Rm > rm() const
Object-capability to the region map.
Definition: env:124
Cap_entry const * initial_caps() const
Get a pointer to the first entry in the initial objects array.
Definition: env:178
l4_cap_idx_t log
Logging object-capability.
Definition: env.h:110