1 /*
2 * (c) 2008-2010 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
4 *
5 * This file is part of TUD:OS and distributed under the terms of the
6 * GNU General Public License 2.
7 * Please see the COPYING-GPL-2 file for details.
8 */
9 #include "app_task.h"
10
11 #include <l4/re/error_helper>
12 #include <l4/re/util/cap_alloc>
13
14 #include <l4/cxx/iostream>
15
16 using L4Re::Util::cap_alloc;
17 using L4Re::Dataspace;
18 using L4Re::chkcap;
19 using L4Re::chksys;
20
21
22 #if 0
23 static Slab_alloc<App_task> *alloc()
24 {
25 static Slab_alloc<App_task> a;
26 return &a;
27 }
28 #endif
29
30 #if 0
31 void *App_task::operator new (size_t) throw()
32 { return alloc()->alloc(); }
33
34 void App_task::operator delete (void *m) throw()
35 { alloc()->free((App_task*)m); }
36 #endif
37
38 int
op_signal(L4Re::Parent::Rights,unsigned long sig,unsigned long val)39 App_task::op_signal(L4Re::Parent::Rights, unsigned long sig, unsigned long val)
40 {
41 switch (sig)
42 {
43 case 0: // exit
44 {
45 // kick the capability reference
46 // long refs = remove_ref();
47 _state = Zombie;
48 _exit_code = val;
49
50 terminate();
51
52 if (remove_ref() == 0)
53 {
54 delete this;
55 return -L4_ENOREPLY;
56 }
57
58 if (l4_cap_idx_t o = observer())
59 {
60 observer(0);
61 l4_ipc_send(o, l4_utcb(), l4_msgtag(0,0,0,0), L4_IPC_NEVER);
62 }
63
64 return -L4_ENOREPLY;
65 }
66 default: break;
67 }
68 return L4_EOK;
69 }
70
App_task(Ned::Registry * r,L4Re::Util::Ref_cap<L4::Factory>::Cap const & alloc)71 App_task::App_task(Ned::Registry *r,
72 L4Re::Util::Ref_cap<L4::Factory>::Cap const &alloc)
73 : _ref_cnt(0), _r(r),
74 _task(chkcap(cap_alloc.alloc<L4::Task>(), "allocating task cap")),
75 _thread(chkcap(cap_alloc.alloc<L4::Thread>(), "allocating thread cap")),
76 _rm(chkcap(cap_alloc.alloc<L4Re::Rm>(), "allocating region-map cap")),
77 _state(Initializing), _observer(0)
78 {
79 chksys(alloc->create(_rm.get()), "allocating new region map");
80
81 chkcap(_r->register_obj(this), "register App_task endpoint");
82 }
83
84 void
terminate()85 App_task::terminate()
86 {
87 _task.reset();
88 _thread.reset();
89 _rm.reset();
90
91 _r->unregister_obj(this);
92 }
93
~App_task()94 App_task::~App_task()
95 {
96 _r->unregister_obj(this);
97 }
98