]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/moe/server/src/app_task.cc
update
[l4.git] / l4 / pkg / moe / 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
16
17 using L4Re::Dataspace;
18
19
20 int
21 App_task::dispatch(l4_umword_t obj, L4::Ipc::Iostream &ios)
22 {
23   l4_msgtag_t tag;
24   ios >> tag;
25
26   if (tag.label() != L4Re::Protocol::Parent)
27     return -L4_EBADPROTO;
28
29   L4::Opcode op;
30   ios >> op;
31   switch (op)
32     {
33       case L4Re::Parent_::Signal:
34       {
35         unsigned long sig;
36         unsigned long val;
37         ios >> sig >> val;
38
39         switch (sig)
40           {
41           case 0: // exit
42             {
43               object_pool.cap_alloc()->free(this);
44               if (val != 0)
45                 L4::cout << "MOE: task " << obj << " exited with " << val
46                          << '\n';
47
48               GC_gcollect();
49               GC_gcollect_and_unmap();
50               return -L4_ENOREPLY;
51             }
52           default: break;
53           }
54         return L4_EOK;
55       }
56     default:
57       return -L4_ENOSYS;
58     }
59 }
60
61 App_task::App_task()
62   : _task(L4::Cap<L4::Task>::Invalid),
63     _thread(L4::Cap<L4::Thread>::Invalid),
64     _alloc(Allocator::root_allocator())
65 {
66   object_pool.cap_alloc()->alloc(&_rm);
67   object_pool.cap_alloc()->alloc(&log);
68 }
69
70 App_task::~App_task()
71 {
72   object_pool.cap_alloc()->free(&_rm);
73   object_pool.cap_alloc()->free(&log);
74   object_pool.cap_alloc()->free(_thread);
75   object_pool.cap_alloc()->free(_task);
76   object_pool.cap_alloc()->free(&_sched);
77 }