3 * \brief Environment interface
6 * (c) 2008-2009 Technische Universität Dresden
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
11 * As a special exception, you may use this file as part of a free software
12 * library without restriction. Specifically, if other files instantiate
13 * templates or use macros or inline functions from this file, or you compile
14 * this file and link it with other files to produce an executable, this
15 * file does not by itself cause the resulting executable to be covered by
16 * the GNU General Public License. This exception does not however
17 * invalidate any other reasons why the executable file might be covered by
18 * the GNU General Public License.
22 #include <l4/sys/consts.h>
23 #include <l4/sys/types.h>
24 #include <l4/sys/kip.h>
26 #include <l4/re/consts.h>
29 * \brief Entry in the L4Re environment array for the named inital objects.
30 * \ingroup api_l4re_env
32 typedef struct l4re_env_cap_entry_t
35 * \brief The capability selector for the obeject.
40 * \brief Some flags for the object.
41 * \note Currently unused.
46 * \brief The name of the object.
52 * \brief Create an invalid entry.
54 l4re_env_cap_entry_t() : cap(L4_INVALID_CAP), flags(~0) {}
57 * \brief Create an entry with the name \a n, capability \a c, and
60 * \param n is the name of the initial object.
61 * \param c is the capability selector that refers the initial object.
62 * \param f are the additional flags for the object.
64 l4re_env_cap_entry_t(char const *n, l4_cap_idx_t c, l4_umword_t f = 0)
67 for (unsigned i = 0; n && i < sizeof(name); ++i, ++n)
75 } l4re_env_cap_entry_t;
79 * \brief Initial Environment structure (C version)
80 * \ingroup api_l4re_env
82 * \see \link api_l4re_env Initial environment \endlink
84 typedef struct l4re_env_t
86 l4_cap_idx_t parent; /**< Parent object-capability */
87 l4_cap_idx_t rm; /**< Region map object-capability */
88 l4_cap_idx_t mem_alloc; /**< Memory allocator object-capability */
89 l4_cap_idx_t log; /**< Logging object-capability */
90 l4_cap_idx_t main_thread; /**< Object-capability of the first user thread */
91 l4_cap_idx_t factory; /**< Object-capability of the factory available to the task */
92 l4_cap_idx_t scheduler; /**< Object capability for the scheduler set to use */
93 l4_cap_idx_t first_free_cap; /**< First capability index available to the application */
94 l4_fpage_t utcb_area; /**< UTCB area of the task */
95 l4_addr_t first_free_utcb; /**< First UTCB within the UTCB area available to the application */
96 l4re_env_cap_entry_t *caps;
101 * \brief Pointer to L4Re initial environment (C version).
102 * \ingroup api_l4re_env
104 extern l4re_env_t *l4re_global_env;
108 * \brief Get L4Re initial environment (C version).
109 * \ingroup api_l4re_env
110 * \return Pointer to L4Re initial environment (C version).
112 L4_INLINE l4re_env_t *l4re_env(void) L4_NOTHROW;
115 * FIXME: this seems to be at the wrong place here
118 * \brief Get Kernel Info Page.
119 * \ingroup api_l4re_env
120 * \return Pointer to Kernel Info Page (KIP) structure.
122 L4_INLINE l4_kernel_info_t *l4re_kip(void) L4_NOTHROW;
126 * \brief Get the capability selector for the object named \a name.
127 * \ingroup api_l4re_env
128 * \param name is the name of the object to lookup in the initial objects.
129 * \return A valid capability selector if the object exists or an invalid
130 * capability selector if not (l4_is_invalid_cap()).
132 L4_INLINE l4_cap_idx_t
133 l4re_get_env_cap(char const *name) L4_NOTHROW;
136 * \brief Get the capability selector for the object named \a name.
137 * \ingroup api_l4re_env
138 * \param name is the name of the object to lookup in the initial objects.
139 * \param e is the environment structure to use for the operation.
140 * \return A valid capability selector if the object exists or an invalid
141 * capability selector if not (l4_is_invalid_cap()).
143 L4_INLINE l4_cap_idx_t
144 l4re_get_env_cap_e(char const *name, l4re_env_t const *e) L4_NOTHROW;
147 * \brief Get the full l4re_env_cap_entry_t for the object named \a name.
148 * \ingroup api_l4re_env
149 * \param name is the name of the object to lookup in the initial objects.
150 * \param l is the length of the name string, thus \a name might not be zero
152 * \param e is the environment structure to use for the operation.
153 * \return A pointer to an l4re_env_cap_entry_t if the object exists or
156 L4_INLINE l4re_env_cap_entry_t const *
157 l4re_get_env_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW;
161 l4re_env_t *l4re_env() L4_NOTHROW
162 { return l4re_global_env; }
165 l4_kernel_info_t *l4re_kip() L4_NOTHROW
167 extern char __L4_KIP_ADDR__[1];
168 return (l4_kernel_info_t *)__L4_KIP_ADDR__;
171 L4_INLINE l4re_env_cap_entry_t const *
172 l4re_get_env_cap_l(char const *name, unsigned l, l4re_env_t const *e) L4_NOTHROW
174 l4re_env_cap_entry_t const *c = e->caps;
175 for (; c && c->flags != ~0UL; ++c)
178 char const *n = name;
179 for (i = 0; i < sizeof(c->name) && i < l && c->name[i] && *n && *n == c->name[i]; ++i, ++n)
182 if (i == l && (i == sizeof(c->name) || !c->name[i]))
188 L4_INLINE l4_cap_idx_t
189 l4re_get_env_cap_e(char const *name, l4re_env_t const *e) L4_NOTHROW
192 l4re_env_cap_entry_t const *r;
193 for (l = 0; name[l]; ++l) ;
194 r = l4re_get_env_cap_l(name, l, e);
198 return L4_INVALID_CAP;
201 L4_INLINE l4_cap_idx_t
202 l4re_get_env_cap(char const *name) L4_NOTHROW
203 { return l4re_get_env_cap_e(name, l4re_env()); }