1 /*
2  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
3  *               Alexander Warg <warg@os.inf.tu-dresden.de>
4  *     economic rights: Technische Universität Dresden (Germany)
5  *
6  * This file is part of TUD:OS and distributed under the terms of the
7  * GNU General Public License 2.
8  * Please see the COPYING-GPL-2 file for details.
9  */
10 #include "region.h"
11 #include "globals.h"
12 #include <stdlib.h>
13 
14 // internal uclibc symbol for ENV
15 extern char const **__environ;
16 
17 namespace Global
18 {
19   L4::Cap<L4Re::Mem_alloc> allocator(L4::Cap_base::No_init);
20   cxx::Static_container<Region_map> local_rm;
21   cxx::Static_container<Cap_alloc> cap_alloc;
22   char const *const *argv;
23   char const *const *envp;
24   int argc;
25   l4re_aux_t *l4re_aux;
26   bool Init_globals::_initialized;
27 
init()28   void Init_globals::init()
29   {
30     envp = __environ;
31     l4_umword_t const *auxp = reinterpret_cast<l4_umword_t const *>(envp);
32     while (*auxp)
33       ++auxp;
34 
35     ++auxp;
36 
37     while (*auxp)
38       {
39         if (*auxp == 0xf0)
40           l4re_aux = (l4re_aux_t*)auxp[1];
41         auxp += 2;
42       }
43 
44     L4Re::Env *env = const_cast<L4Re::Env*>(L4Re::Env::env());
45     cap_alloc.construct(env->first_free_cap());
46     env->first_free_cap(env->first_free_cap() + Global::Max_local_rm_caps);
47     L4::Cap<L4Re::Mem_alloc> obj = env->mem_alloc();
48 
49     if (!obj.is_valid())
50       {
51         Err(Err::Fatal).printf("could not find the base memory allocator\n");
52         exit(-1);
53       }
54 
55     allocator = obj;
56     local_rm.construct();
57     local_rm->init();
58   }
59 };
60