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);
78 Name_space::free_dynamic_entry(Names::Entry *n)
80 assert (!n->next_link());
81 delete static_cast<Moe::Entry*>(n);
85 Name_space::get_capability(L4::Ipc::Snd_fpage const &cap_fp, L4::Cap<void> *cap,
86 L4::Server_object **lo)
88 L4::Cap<void> rcv_cap(Rcv_cap << L4_CAP_SHIFT);
90 if (cap_fp.id_received())
92 L4::Server_object *o = object_pool.find(cap_fp.data());
103 if (cap_fp.cap_received())
113 Name_space::save_capability(L4::Cap<void> *cap)
115 L4::Cap<void> rcv_cap(Rcv_cap << L4_CAP_SHIFT);
119 L4::Cap<void> nc = object_pool.cap_alloc()->alloc<void>();
129 Name_space::free_capability(L4::Cap<void> cap)
131 object_pool.cap_alloc()->free(cap);
136 namespace L4Re { namespace Util { namespace Names {
139 Name_space::dump(bool rec, int indent) const
142 //L4::cout << "MOE: Name space dump (" << obj_cap() << ")\n";
143 for (Const_iterator i = begin(); i != end(); ++i)
145 for (int x = 0; x < indent; ++x)
148 L4::cout << " " << i->name() << " -> " << i->obj()->cap()
149 << " o=" << (void*)i->obj()->obj() << " f="
150 << i->obj()->flags() << '\n';
151 if (rec && i->obj()->is_valid()
152 && (n = dynamic_cast<Name_space const *>(i->obj()->obj())))
153 n->dump(rec, indent + 1);