]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/loader/server/src/app_task.cc
22f04444cc66caf24bad3b18557598a3ddb045ad
[l4.git] / l4 / pkg / loader / server / src / app_task.cc
1 /*
2  * (c) 2008-2009 Technische Universität Dresden
3  * This file is part of TUD:OS and distributed under the terms of the
4  * GNU General Public License 2.
5  * Please see the COPYING-GPL-2 file for details.
6  */
7 #include "app_task.h"
8 //#include "slab_alloc.h"
9 //#include "globals.h"
10 #include <l4/re/parent-sys.h>
11 #include <l4/re/protocols>
12 #include <l4/re/error_helper>
13 #include <l4/re/util/cap_alloc>
14
15 #include <l4/cxx/iostream>
16
17 #include "obj_reg.h"
18
19
20 using L4Re::Util::cap_alloc;
21 using L4Re::Dataspace;
22
23 #if 0
24 static Slab_alloc<App_task> *alloc()
25 {
26   static Slab_alloc<App_task> a;
27   return &a;
28 }
29 #endif
30
31 #if 0
32 void *App_task::operator new (size_t) throw()
33 { return alloc()->alloc(); }
34
35 void App_task::operator delete (void *m) throw()
36 { alloc()->free((App_task*)m); }
37 #endif
38
39 int
40 App_task::dispatch(l4_umword_t obj, L4::Ipc_iostream &ios)
41 {
42   l4_msgtag_t tag;
43   ios >> tag;
44
45   if (tag.label() != L4Re::Protocol::Parent)
46     return -L4_EBADPROTO;
47
48   L4::Opcode op;
49   ios >> op;
50   switch (op)
51     {
52       case L4Re::Parent_::Signal:
53       {
54         unsigned long sig;
55         unsigned long val;
56         ios >> sig >> val;
57
58         switch (sig)
59           {
60           case 0: // exit
61             {
62               L4Re::Util::cap_alloc.free(obj_cap());
63               delete this;
64               if (val != 0)
65                 L4::cout << "LDR: task " << obj << " exited with " << val
66                          << '\n';
67               return -L4_ENOREPLY;
68             }
69           default: break;
70           }
71         return L4_EOK;
72       }
73     default:
74       return -L4_ENOSYS;
75     }
76 }
77
78 App_task::App_task()
79   : _task(L4::Cap<L4::Task>::Invalid),
80     _thread(L4::Cap<L4::Thread>::Invalid)
81 {
82   //object_pool.cap_alloc()->alloc(&_alloc);
83   Gate_alloc::registry.register_obj(&_rm);
84   _rm.init();
85   //object_pool.cap_alloc()->alloc(&log);
86 }
87
88 App_task::~App_task()
89 {
90   //object_pool.cap_alloc()->free(&_alloc);
91   Gate_alloc::registry.unregister_obj(&_rm);
92   //object_pool.cap_alloc()->free(&log);
93   if (_thread.is_valid())
94     cap_alloc.free(_thread);
95
96   if (_task.is_valid())
97     cap_alloc.free(_task);
98
99   if (_sched.obj_cap().is_valid())
100     cap_alloc.free(_sched.obj_cap());
101
102   Gate_alloc::registry.unregister_obj(this);
103 }