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