L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
name_space_svr
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
4 * Alexander Warg <warg@os.inf.tu-dresden.de>
5 * economic rights: Technische Universität Dresden (Germany)
6 *
7 * This file is part of TUD:OS and distributed under the terms of the
8 * GNU General Public License 2.
9 * Please see the COPYING-GPL-2 file for details.
10 *
11 * As a special exception, you may use this file as part of a free software
12 * library without restriction. Specifically, if other files instantiate
13 * templates or use macros or inline functions from this file, or you compile
14 * this file and link it with other files to produce an executable, this
15 * file does not by itself cause the resulting executable to be covered by
16 * the GNU General Public License. This exception does not however
17 * invalidate any other reasons why the executable file might be covered by
18 * the GNU General Public License.
19 */
20#pragma once
21
22#include <l4/cxx/avl_tree>
23#include <l4/cxx/std_ops>
24#include <l4/sys/cxx/ipc_epiface>
25#include <l4/cxx/string>
26
27#include <l4/sys/capability>
28#include <l4/re/namespace>
29
30#include <cstddef>
31
32namespace L4Re { namespace Util {
33
34class Dbg;
35class Err;
36
37namespace Names {
38
42class Name : public cxx::String
43{
44public:
45
46 Name(const char *name = "") : String(name, __builtin_strlen(name)) {}
47 Name(const char *name, unsigned long len) : String(name, len) {}
48 Name(cxx::String const &n) : String(n) {}
49 char const *name() const { return start(); }
50 bool operator < (Name const &r) const;
51};
52
53
57class Obj
58{
59protected:
60 unsigned _f;
61 union
62 {
63 l4_cap_idx_t _cap;
64 L4::Epiface *_obj;
65 };
66
67
68public:
69 enum Flags
70 {
72 F_strong = L4Re::Namespace::Strong,
73
74 F_trusted = L4Re::Namespace::Trusted,
75
76 F_rights_mask = F_rw | F_strong | F_trusted,
77
78 F_cap = 0x100,
79 F_local = 0x200,
80 F_replacable = 0x400,
81 F_base_mask = 0xf00,
82 };
83
84
85 unsigned flags() const { return _f; }
86 void restrict_flags(unsigned max_rights)
87 { _f &= (~F_rights_mask | (max_rights & F_rights_mask)); }
88
89 bool is_rw() const { return (_f & F_rw) == F_rw; }
90 bool is_strong() const { return _f & F_strong; }
91
92 bool is_valid() const { return _f & F_cap; }
93 bool is_complete() const { return is_valid(); }
94 bool is_local() const { return _f & F_local; }
95 bool is_replacable() const { return _f & F_replacable; }
96 bool is_trusted() const { return _f & F_trusted; }
97
98 L4::Epiface *obj() const { if (is_local()) return _obj; return 0; }
99 L4::Cap<void> cap() const
100 {
101 if (!is_local())
102 return L4::Cap<void>(_cap);
103 if (!_obj)
105 return _obj->obj_cap();
106 }
107
108
109 void set(Obj const &o, unsigned flags)
110 {
111 *this = o;
112 restrict_flags(flags);
113 }
114
115 explicit Obj(unsigned flags = 0)
116 : _f(flags), _cap(L4_INVALID_CAP)
117 {}
118
119 Obj(unsigned f, L4::Cap<void> const &cap)
120 : _f((f & ~F_base_mask) | F_cap), _cap(cap.cap())
121 {}
122
123 Obj(unsigned f, L4::Epiface *o)
124 : _f((f & ~F_base_mask) | F_cap | F_local), _obj(o)
125 {}
126
127 void reset(unsigned flags)
128 {
129 _f = (_f & F_replacable) | (flags & ~(F_cap | F_local));
130 _cap = L4_INVALID_CAP;
131 }
132
133
134};
135
136
140class Entry : public cxx::Avl_tree_node
141{
142private:
143 friend class Name_space;
144 Name _n;
145 Obj _o;
146
147 bool _dynamic;
148
149public:
150 Entry(Name const &n, Obj const &o, bool dynamic = false)
151 : _n(n), _o(o), _dynamic(dynamic) {}
152
153 Name const &name() const { return _n; }
154 Obj const *obj() const { return &_o; }
155 Obj *obj() { return &_o; }
156 void obj(Obj const &o) { _o = o; }
157
158 bool is_placeholder() const
159 { return !obj()->is_complete(); }
160
161 bool is_dynamic() const { return _dynamic; }
162
163 void set(Obj const &o);
164
165private:
166 void * operator new (size_t s);
167 void operator delete(void *b);
168
169};
170
171struct Names_get_key
172{
173 typedef Name Key_type;
174 static Key_type const &key_of(Entry const *e)
175 { return e->name(); }
176};
177
178
187{
188 friend class Entry;
189
190private:
192 Tree _tree;
193
194protected:
195 L4Re::Util::Dbg const &_dbg;
196 L4Re::Util::Err const &_err;
197
198public:
199
200 typedef Tree::Const_iterator Const_iterator;
201
202 Const_iterator begin() const { return _tree.begin(); }
203 Const_iterator end() const { return _tree.end(); }
204
205 Name_space(L4Re::Util::Dbg const &dbg, L4Re::Util::Err const &err)
206 : _dbg(dbg), _err(err)
207 {}
208
212 virtual ~Name_space() {}
213
214 Entry *find(Name const &name) const { return _tree.find_node(name); }
215 Entry *remove(Name const &name) { return _tree.remove(name); }
216 Entry *find_iter(Name const &name) const;
217 bool insert(Entry *e) { return _tree.insert(e).second; }
218
219 void dump(bool rec = false, int indent = 0) const;
220
221protected:
222 // server support --------------------------------------------
235 virtual Entry *alloc_dynamic_entry(Name const &n, unsigned flags) = 0;
236
242 virtual void free_dynamic_entry(Entry *e) = 0;
243
266 virtual int get_epiface(l4_umword_t data, bool is_local, L4::Epiface **lo) = 0;
267
280 virtual int copy_receive_cap(L4::Cap<void> *cap) = 0;
281
290 virtual void free_capability(L4::Cap<void> cap) = 0;
291
300 virtual void free_epiface(L4::Epiface *epiface) = 0;
301
302 int insert_entry(Name const &name, unsigned flags, Entry **e);
303
304public:
305 // server interface ------------------------------------------
306 int op_query(L4Re::Namespace::Rights,
310
311 int op_register_obj(L4Re::Namespace::Rights, unsigned flags,
313 L4::Ipc::Snd_fpage &cap);
314
315 int op_unlink(L4Re::Namespace::Rights r,
317};
318
319}}}
320
AVL tree.
L4::Cap related definitions.
@ Trusted
Obsolete, do not use.
Definition namespace:75
@ Strong
Strong.
Definition namespace:74
@ Rw
Read-write.
Definition namespace:71
Abstract server-side implementation of the L4::Namespace interface.
virtual void free_dynamic_entry(Entry *e)=0
Free an entry previously allocated with alloc_dynamic_entry().
virtual int get_epiface(l4_umword_t data, bool is_local, L4::Epiface **lo)=0
Return a pointer to the epiface assigned to a given label.
virtual Entry * alloc_dynamic_entry(Name const &n, unsigned flags)=0
Allocate a new entry for the given name.
virtual int copy_receive_cap(L4::Cap< void > *cap)=0
Return the receive capability for permanent use.
virtual ~Name_space()
The destructor of the derived class is responsible for freeing resources.
virtual void free_capability(L4::Cap< void > cap)=0
Free a capability previously acquired with copy_receive_cap().
virtual void free_epiface(L4::Epiface *epiface)=0
Free epiface previously acquired with get_epiface().
C++ interface for capabilities.
Definition capability.h:222
Generic RPC wrapper for L4 flex-pages.
Definition ipc_types:322
Node of an AVL tree.
Definition avl_tree:39
A generic AVL tree.
Definition avl_tree:108
Pair< Node *, bool > insert(Node *new_node)
Insert a new node into this AVL tree.
Definition avl_tree:227
Node * remove(Key_param_type key)
Remove the node with key from the tree.
Definition avl_tree:289
Bst::Const_iterator Const_iterator
Constant forward iterator for the tree.
Definition avl_tree:139
Node * find_node(Key_param_type key) const
find the node with the given key.
Definition bst.h:276
Const_iterator end() const
Get the end marker for the constant forward iterator.
Definition bst.h:184
Const_iterator begin() const
Get the constant forward iterator for the first element in the set.
Definition bst.h:179
Allocation free string class with explicit length field.
Definition string:42
Index start() const
Pointer to first character.
Definition string:65
int len() const
Length.
Definition string:69
String()
Zero-initialize. Create an invalid string.
Definition string:62
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
unsigned long l4_cap_idx_t
Capability selector type.
Definition types.h:358
@ L4_INVALID_CAP
Invalid capability selector.
Definition consts.h:168
L4Re C++ Interfaces.
Definition cmd_control:15
Namespace interface.
Base class for interface implementations.
Definition ipc_epiface:157
Server-side copy in buffer for Array.
Definition ipc_array:138
Array reference data type for arrays located in the message.
Definition ipc_array:40
Attribute for defining an optional RPC argument.
Definition ipc_types:148