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 
49 typedef struct l4re_env_cap_entry_t
50 {
55 
61 
65  char name[16];
66 #ifdef __cplusplus
67 
71  l4re_env_cap_entry_t() : cap(L4_INVALID_CAP), flags(~0) {}
72 
81  : cap(c), flags(f)
82  {
83  for (unsigned i = 0; n && i < sizeof(name); ++i, ++n)
84  {
85  name[i] = *n;
86  if (!*n)
87  break;
88  }
89  }
90 
91  static bool is_valid_name(char const *n)
92  {
93  for (unsigned i = 0; *n; ++i, ++n)
94  if (i > sizeof(name))
95  return false;
96 
97  return true;
98  }
99 #endif
101 
102 
108 typedef struct l4re_env_t
109 {
120  l4re_env_cap_entry_t *caps;
121 } l4re_env_t;
122 
128 extern l4re_env_t *l4re_global_env;
129 
130 
136 L4_INLINE l4re_env_t *l4re_env(void) L4_NOTHROW;
137 
138 /*
139  * FIXME: this seems to be at the wrong place here
140  */
146 L4_INLINE l4_kernel_info_t *l4re_kip(void) L4_NOTHROW;
147 
148 
156 L4_INLINE l4_cap_idx_t
157 l4re_env_get_cap(char const *name) L4_NOTHROW;
158 
167 L4_INLINE l4_cap_idx_t
168 l4re_env_get_cap_e(char const *name, l4re_env_t const *e) L4_NOTHROW;
169 
180 L4_INLINE l4re_env_cap_entry_t const *
181 l4re_env_get_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW;
182 
183 L4_INLINE
185 { return l4re_global_env; }
186 
187 L4_INLINE
189 {
190  extern char __L4_KIP_ADDR__[];
191  return (l4_kernel_info_t *)__L4_KIP_ADDR__;
192 }
193 
194 L4_INLINE l4re_env_cap_entry_t const *
195 l4re_env_get_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW
196 {
197  l4re_env_cap_entry_t const *c = e->caps;
198  for (; c && c->flags != ~0UL; ++c)
199  {
200  unsigned i;
201  for (i = 0;
202  i < sizeof(c->name) && i < l && c->name[i] && name[i] && name[i] == c->name[i];
203  ++i)
204  ;
205 
206  if (i == l && (i == sizeof(c->name) || !c->name[i]))
207  return c;
208  }
209  return NULL;
210 }
211 
212 L4_INLINE l4_cap_idx_t
214 {
215  unsigned l;
216  l4re_env_cap_entry_t const *r;
217  for (l = 0; name[l]; ++l) ;
218  r = l4re_env_get_cap_l(name, l, e);
219  if (r)
220  return r->cap;
221 
222  return L4_INVALID_CAP;
223 }
224 
225 L4_INLINE l4_cap_idx_t
227 { return l4re_env_get_cap_e(name, l4re_env()); }
228 
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:213
l4_fpage_t utcb_area
UTCB area of the task.
Definition: env.h:118
Invalid capability selector.
Definition: consts.h:141
l4_umword_t flags
Some flags for the object.
Definition: env.h:60
l4_cap_idx_t parent
Parent object-capability.
Definition: env.h:110
struct l4re_env_t l4re_env_t
Initial environment data structure.
Initial environment data structure.
Definition: env.h:108
Common L4 ABI Data Types.
l4_cap_idx_t first_free_cap
First capability index available to the application.
Definition: env.h:117
l4_kernel_info_t * l4re_kip(void) L4_NOTHROW
Get Kernel Info Page.
Definition: env.h:188
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:54
L4 Kernel Interface Page.
Definition: __kip-32bit.h:38
l4_cap_idx_t rm
Region map object-capability.
Definition: env.h:111
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
l4re_env_cap_entry_t()
Create an invalid entry.
Definition: env.h:71
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:195
l4_addr_t first_free_utcb
First UTCB within the UTCB area available to the application.
Definition: env.h:119
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:80
L4 flexpage type.
Definition: __l4_fpage.h:81
l4_cap_idx_t main_thread
Object-capability of the first user thread.
Definition: env.h:114
l4_cap_idx_t factory
Object-capability of the factory available to the task.
Definition: env.h:115
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:226
l4re_env_t * l4re_env(void) L4_NOTHROW
Get L4Re initial environment.
Definition: env.h:184
l4_cap_idx_t scheduler
Object capability for the scheduler set to use.
Definition: env.h:116
unsigned long l4_addr_t
Address type.
Definition: l4int.h:45
l4_cap_idx_t mem_alloc
Memory allocator object-capability.
Definition: env.h:112
Entry in the L4Re environment array for the named inital objects.
Definition: env.h:49
char name[16]
The name of the object.
Definition: env.h:65
#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:113