L4Re - L4 Runtime Environment
env.h
Go to the documentation of this file.
1 
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  * Alexander Warg <warg@os.inf.tu-dresden.de>
8  * economic rights: Technische Universit├Ąt Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction. Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License. This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #pragma once
24 
25 #include <l4/sys/consts.h>
26 #include <l4/sys/types.h>
27 #include <l4/sys/kip.h>
28 #include <l4/sys/compiler.h>
29 
30 #include <l4/re/consts.h>
31 
50 typedef struct l4re_env_cap_entry_t
51 {
56 
62 
66  char name[16];
67 #ifdef __cplusplus
68 
73 
82  : cap(c), flags(f)
83  {
84  for (unsigned i = 0; n && i < sizeof(name); ++i, ++n)
85  {
86  name[i] = *n;
87  if (!*n)
88  break;
89  }
90  }
91 
92  static bool is_valid_name(char const *n) L4_NOTHROW
93  {
94  for (unsigned i = 0; *n; ++i, ++n)
95  if (i > sizeof(name))
96  return false;
97 
98  return true;
99  }
100 #endif
102 
103 
109 typedef struct l4re_env_t
110 {
121  l4re_env_cap_entry_t *caps;
122 } l4re_env_t;
123 
129 extern l4re_env_t *l4re_global_env;
130 
131 
137 L4_INLINE l4re_env_t *l4re_env(void) L4_NOTHROW;
138 
139 /*
140  * FIXME: this seems to be at the wrong place here
141  */
147 L4_INLINE l4_kernel_info_t *l4re_kip(void) L4_NOTHROW;
148 
149 
157 L4_INLINE l4_cap_idx_t
158 l4re_env_get_cap(char const *name) L4_NOTHROW;
159 
168 L4_INLINE l4_cap_idx_t
169 l4re_env_get_cap_e(char const *name, l4re_env_t const *e) L4_NOTHROW;
170 
181 L4_INLINE l4re_env_cap_entry_t const *
182 l4re_env_get_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW;
183 
184 L4_INLINE
186 { return l4re_global_env; }
187 
188 L4_INLINE
190 {
191  extern char __L4_KIP_ADDR__[];
192  return (l4_kernel_info_t *)__L4_KIP_ADDR__;
193 }
194 
195 L4_INLINE l4re_env_cap_entry_t const *
196 l4re_env_get_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW
197 {
198  l4re_env_cap_entry_t const *c = e->caps;
199  for (; c && c->flags != ~0UL; ++c)
200  {
201  unsigned i;
202  for (i = 0;
203  i < sizeof(c->name) && i < l && c->name[i] && name[i] && name[i] == c->name[i];
204  ++i)
205  ;
206 
207  if (i == l && (i == sizeof(c->name) || !c->name[i]))
208  return c;
209  }
210  return NULL;
211 }
212 
213 L4_INLINE l4_cap_idx_t
215 {
216  unsigned l;
217  l4re_env_cap_entry_t const *r;
218  for (l = 0; name[l]; ++l) ;
219  r = l4re_env_get_cap_l(name, l, e);
220  if (r)
221  return r->cap;
222 
223  return L4_INVALID_CAP;
224 }
225 
226 L4_INLINE l4_cap_idx_t
228 { return l4re_env_get_cap_e(name, l4re_env()); }
229 
l4_cap_idx_t l4re_env_get_cap_e(char const *name, l4re_env_t const *e) L4_NOTHROW
Get the capability selector for the object named name.
Definition: env.h:214
l4_fpage_t utcb_area
UTCB area of the task.
Definition: env.h:119
Invalid capability selector.
Definition: consts.h:141
l4re_env_cap_entry_t() L4_NOTHROW
Create an invalid entry.
Definition: env.h:72
l4re_env_cap_entry_t(char const *n, l4_cap_idx_t c, l4_umword_t f=0) L4_NOTHROW
Create an entry with the name n, capability c, and flags f.
Definition: env.h:81
l4_umword_t flags
Some flags for the object.
Definition: env.h:61
l4_cap_idx_t parent
Parent object-capability.
Definition: env.h:111
struct l4re_env_t l4re_env_t
Initial environment data structure.
Initial environment data structure.
Definition: env.h:109
Common L4 ABI Data Types.
l4_cap_idx_t first_free_cap
First capability index available to the application.
Definition: env.h:118
l4_kernel_info_t * l4re_kip(void) L4_NOTHROW
Get Kernel Info Page.
Definition: env.h:189
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:342
Constants.
l4_cap_idx_t cap
The capability selector for the object.
Definition: env.h:55
L4 compiler related defines.
L4 Kernel Interface Page.
Definition: __kip-32bit.h:38
l4_cap_idx_t rm
Region map object-capability.
Definition: env.h:112
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
Kernel Info Page access functions.
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
l4_addr_t first_free_utcb
First UTCB within the UTCB area available to the application.
Definition: env.h:120
L4 flexpage type.
Definition: __l4_fpage.h:83
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
l4_cap_idx_t l4re_env_get_cap(char const *name) L4_NOTHROW
Get the capability selector for the object named name.
Definition: env.h:227
l4re_env_t * l4re_env(void) L4_NOTHROW
Get L4Re initial environment.
Definition: env.h:185
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_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
char name[16]
The name of the object.
Definition: env.h:66
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:186
l4_cap_idx_t log
Logging object-capability.
Definition: env.h:114