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 
29 #include <l4/re/consts.h>
30 
46 typedef struct l4re_env_cap_entry_t
47 {
52 
58 
62  char name[16];
63 #ifdef __cplusplus
64 
68  l4re_env_cap_entry_t() : cap(L4_INVALID_CAP), flags(~0) {}
69 
78  : cap(c), flags(f)
79  {
80  for (unsigned i = 0; n && i < sizeof(name); ++i, ++n)
81  {
82  name[i] = *n;
83  if (!*n)
84  break;
85  }
86  }
87 
88  static bool is_valid_name(char const *n)
89  {
90  for (unsigned i = 0; *n; ++i, ++n)
91  if (i > sizeof(name))
92  return false;
93 
94  return true;
95  }
96 #endif
98 
99 
105 typedef struct l4re_env_t
106 {
117  l4re_env_cap_entry_t *caps;
118 } l4re_env_t;
119 
125 extern l4re_env_t *l4re_global_env;
126 
127 
133 L4_INLINE l4re_env_t *l4re_env(void) L4_NOTHROW;
134 
135 /*
136  * FIXME: this seems to be at the wrong place here
137  */
143 L4_INLINE l4_kernel_info_t *l4re_kip(void) L4_NOTHROW;
144 
145 
153 L4_INLINE l4_cap_idx_t
154 l4re_env_get_cap(char const *name) L4_NOTHROW;
155 
164 L4_INLINE l4_cap_idx_t
165 l4re_env_get_cap_e(char const *name, l4re_env_t const *e) L4_NOTHROW;
166 
177 L4_INLINE l4re_env_cap_entry_t const *
178 l4re_env_get_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW;
179 
180 L4_INLINE
182 { return l4re_global_env; }
183 
184 L4_INLINE
186 {
187  extern char __L4_KIP_ADDR__[];
188  return (l4_kernel_info_t *)__L4_KIP_ADDR__;
189 }
190 
191 L4_INLINE l4re_env_cap_entry_t const *
192 l4re_env_get_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW
193 {
194  l4re_env_cap_entry_t const *c = e->caps;
195  for (; c && c->flags != ~0UL; ++c)
196  {
197  unsigned i;
198  for (i = 0;
199  i < sizeof(c->name) && i < l && c->name[i] && name[i] && name[i] == c->name[i];
200  ++i)
201  ;
202 
203  if (i == l && (i == sizeof(c->name) || !c->name[i]))
204  return c;
205  }
206  return NULL;
207 }
208 
209 L4_INLINE l4_cap_idx_t
211 {
212  unsigned l;
213  l4re_env_cap_entry_t const *r;
214  for (l = 0; name[l]; ++l) ;
215  r = l4re_env_get_cap_l(name, l, e);
216  if (r)
217  return r->cap;
218 
219  return L4_INVALID_CAP;
220 }
221 
222 L4_INLINE l4_cap_idx_t
224 { return l4re_env_get_cap_e(name, l4re_env()); }
225 
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:210
l4_fpage_t utcb_area
UTCB area of the task.
Definition: env.h:115
Invalid capability selector.
Definition: consts.h:141
l4_umword_t flags
Some flags for the object.
Definition: env.h:57
l4_cap_idx_t parent
Parent object-capability.
Definition: env.h:107
struct l4re_env_t l4re_env_t
Initial environment data structure.
Initial environment data structure.
Definition: env.h:105
Common L4 ABI Data Types.
l4_cap_idx_t first_free_cap
First capability index available to the application.
Definition: env.h:114
l4_kernel_info_t * l4re_kip(void) L4_NOTHROW
Get Kernel Info Page.
Definition: env.h:185
unsigned long l4_cap_idx_t
L4 Capability selector Type.
Definition: types.h:341
Constants.
l4_cap_idx_t cap
The capability selector for the object.
Definition: env.h:51
L4 Kernel Interface Page.
Definition: __kip-32bit.h:38
l4_cap_idx_t rm
Region map object-capability.
Definition: env.h:108
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4re_env_cap_entry_t()
Create an invalid entry.
Definition: env.h:68
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:192
l4_addr_t first_free_utcb
First UTCB within the UTCB area available to the application.
Definition: env.h:116
l4re_env_cap_entry_t(char const *n, l4_cap_idx_t c, l4_umword_t f=0)
Create an entry with the name n, capability c, and flags f.
Definition: env.h:77
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_idx_t l4re_env_get_cap(char const *name) L4_NOTHROW
Get the capability selector for the object named name.
Definition: env.h:223
l4re_env_t * l4re_env(void) L4_NOTHROW
Get L4Re initial environment.
Definition: env.h:181
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_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
char name[16]
The name of the object.
Definition: env.h:62
#define L4_NOTHROW
Mark a function declaration and definition as never throwing an exception.
Definition: compiler.h:185
l4_cap_idx_t log
Logging object-capability.
Definition: env.h:110