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)
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.
12 #include <l4/sys/task.h>
13 #include <l4/sys/factory.h>
14 #include <l4/sys/types.h>
15 #include <l4/sys/thread>
17 #include <l4/re/util/bitmap_cap_alloc>
18 #include <l4/re/error_helper>
21 #include <l4/cxx/exceptions>
22 #include <l4/cxx/hlist>
24 #include "server_obj.h"
30 #define DEBUG_CAP_ALLOC 0
40 : public L4::Basic_registry,
41 private L4::Irqep_t<Object_pool>
43 friend struct L4::Irqep_t<Object_pool>;
46 explicit Object_pool(Cap_alloc *ca);
47 Cap_alloc *cap_alloc() const { return _cap_alloc; }
48 cxx::H_list_t<Moe::Server_object> life;
51 Cap_alloc *_cap_alloc;
55 l4_utcb_t *utcb = l4_utcb();
56 for (auto i = life.begin(); i != life.end();)
58 if (i->obj_cap() && !i->obj_cap().validate(utcb).label())
72 Non_gc_cap_0 = Rcv_cap + 1,
76 // caps mainly used for things from outside (registered in name spaces)
77 // this are usually not a lot
78 L4Re::Util::Cap_alloc<Non_gc_caps> _non_gc;
81 Cap_alloc() : _non_gc(Non_gc_cap_0)
84 L4::Cap<L4::Kobject> alloc()
86 L4::Cap<L4::Kobject> cap = _non_gc.alloc<L4::Kobject>();
88 L4::cerr << "AC->" << L4::n_hex(cap.cap()) << "\n";
93 template< typename T >
94 L4::Cap<T> alloc() { return L4::cap_cast<T>(alloc()); }
96 L4::Cap<L4::Kobject> alloc(Moe::Server_object *_o)
98 // make sure we register an Epiface ptr
100 L4::Cap<L4::Kobject> cap = _non_gc.alloc<L4::Kobject>();
102 L4::cerr << "ACO->" << L4::n_hex(cap.cap()) << "\n";
105 throw(L4::Out_of_memory());
107 l4_umword_t id = l4_umword_t(o);
108 l4_factory_create_gate(L4_BASE_FACTORY_CAP, cap.cap(),
109 L4_BASE_THREAD_CAP, id);
111 _o->set_obj_cap(cap);
115 bool free(L4::Cap<void> const &cap, l4_umword_t unmap_flags = L4_FP_ALL_SPACES)
120 if ((cap.cap() >> L4_CAP_SHIFT) >= Non_gc_cap_0)
121 _non_gc.free(cap, L4_BASE_TASK_CAP, unmap_flags);
130 inline Object_pool::Object_pool(Cap_alloc *ca) : _cap_alloc(ca)
132 // make sure we register an Epiface PTR
133 L4::Epiface *self = this;
134 auto c = L4Re::chkcap(cap_alloc()->alloc<L4::Irq>());
135 L4Re::chksys(L4Re::Env::env()->factory()->create(c));
136 L4Re::chksys(c->attach(l4_umword_t(self),
137 L4::Cap<L4::Thread>(L4_BASE_THREAD_CAP)));
139 L4Re::chksys(L4::Cap<L4::Thread>(L4_BASE_THREAD_CAP)->register_del_irq(c));