2 * (c) 2008-2009 Alexander Warg <warg@os.inf.tu-dresden.de>
3 * economic rights: Technische Universität Dresden (Germany)
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.
9 #include <l4/cxx/iostream>
10 #include "name_space.h"
14 #include "server_obj.h"
16 #include <l4/cxx/l4iostream>
17 #include <l4/cxx/minmax>
23 Moe::Name_space *root_name_space()
25 static Moe::Name_space _root;
31 static Dbg dbg(Dbg::Name_space, "ns");
33 Name_space::Name_space()
34 : L4Re::Util::Names::Name_space(dbg, Err())
36 object_pool.cap_alloc()->alloc(this);
39 Name_space::~Name_space()
41 object_pool.cap_alloc()->free(this);
45 static Slab_alloc<Name_space> *alloc()
47 static Slab_alloc<Name_space> a;
52 Name_space::operator new (size_t) throw()
54 return alloc()->alloc();
58 Name_space::operator delete (void *p, size_t) throw()
59 { alloc()->free((Name_space*)p); }
62 Name_space::alloc_dynamic_entry(Names::Name const &name, unsigned flags)
64 char *na = (char*)GC_MALLOC_ATOMIC(name.len());
68 memcpy(na, name.start(), name.len());
69 Names::Name new_name(na, name.len());
70 Entry *e = new Moe::Entry(new_name, Names::Obj(flags), true);
80 Name_space::free_dynamic_entry(Names::Entry *n)
82 free(const_cast<char*>(n->name().start()));
83 assert (!n->next_link());
84 delete static_cast<Moe::Entry*>(n);
88 Name_space::get_capability(L4::Ipc::Snd_fpage const &cap_fp, L4::Cap<void> *cap,
89 L4::Server_object **lo)
91 L4::Cap<void> rcv_cap(Rcv_cap << L4_CAP_SHIFT);
93 if (cap_fp.id_received())
95 L4::Server_object *o = object_pool.find(cap_fp.data());
106 if (cap_fp.cap_received())
116 Name_space::save_capability(L4::Cap<void> *cap)
118 L4::Cap<void> rcv_cap(Rcv_cap << L4_CAP_SHIFT);
122 L4::Cap<void> nc = object_pool.cap_alloc()->alloc<void>();
132 Name_space::free_capability(L4::Cap<void> cap)
134 object_pool.cap_alloc()->free(cap);
139 namespace L4Re { namespace Util { namespace Names {
142 Name_space::dump(bool rec, int indent) const
145 //L4::cout << "MOE: Name space dump (" << obj_cap() << ")\n";
146 for (Const_iterator i = begin(); i != end(); ++i)
148 for (int x = 0; x < indent; ++x)
151 L4::cout << " " << i->name() << " -> " << i->obj()->cap()
152 << " o=" << (void*)i->obj()->obj() << " f="
153 << i->obj()->flags() << '\n';
154 if (rec && i->obj()->is_valid()
155 && (n = dynamic_cast<Name_space const *>(i->obj()->obj())))
156 n->dump(rec, indent + 1);