L4Re - L4 Runtime Environment
namespace_impl.h
Go to the documentation of this file.
1 
5 /*
6  * (c) 2008-2009 Adam Lackorzynski <adam@os.inf.tu-dresden.de>,
7  * Alexander Warg <warg@os.inf.tu-dresden.de>
8  * economic rights: Technische Universit├Ąt Dresden (Germany)
9  *
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  *
14  * As a special exception, you may use this file as part of a free software
15  * library without restriction. Specifically, if other files instantiate
16  * templates or use macros or inline functions from this file, or you compile
17  * this file and link it with other files to produce an executable, this
18  * file does not by itself cause the resulting executable to be covered by
19  * the GNU General Public License. This exception does not however
20  * invalidate any other reasons why the executable file might be covered by
21  * the GNU General Public License.
22  */
23 #include <l4/re/namespace>
24 
25 #include <l4/util/util.h>
26 #include <l4/sys/cxx/ipc_client>
27 #include <l4/sys/assert.h>
28 
29 #include <cstring>
30 
34 
35 namespace L4Re {
36 
37 long
38 Namespace::_query(char const *name, unsigned len,
39  L4::Cap<void> const &target,
40  l4_umword_t *local_id, bool iterate) const throw()
41 {
42  l4_assert(target.is_valid());
43 
44  L4::Cap<Namespace> ns = c();
46 
47  while (_name.length > 0)
48  {
50  L4::Opcode dummy;
51  int err = query_t::call(ns, _name,
52  L4::Ipc::Small_buf(target.cap(),
53  local_id
55  : 0),
56  cap, dummy, _name);
57  if (err < 0)
58  return err;
59 
60  bool const partly = err & Partly_resolved;
61  if (cap.id_received())
62  {
63  *local_id = cap.data();
64  return _name.length;
65  }
66 
67  if (partly && iterate)
68  ns = L4::cap_cast<Namespace>(target);
69  else
70  return err;
71  }
72 
73  return _name.length;
74 }
75 
76 long
77 Namespace::query(char const *name, unsigned len, L4::Cap<void> const &target,
78  int timeout, l4_umword_t *local_id, bool iterate) const throw()
79 {
80  if (L4_UNLIKELY(len == 0))
81  return -L4_EINVAL;
82 
83  long ret;
84  long rem = timeout;
85  long to = 0;
86 
87  if (rem)
88  to = 10;
89  do
90  {
91  ret = _query(name, len, target, local_id, iterate);
92 
93  if (ret >= 0)
94  return ret;
95 
96  if (L4_UNLIKELY(ret < 0 && (ret != -L4_EAGAIN)))
97  return ret;
98 
99  if (rem == to)
100  return ret;
101 
102  l4_sleep(to);
103 
104  if (rem > 0)
105  {
106  rem -= to;
107  if (to > rem)
108  to = rem;
109  }
110 
111  if (to < 100)
112  to += to;
113  }
114  while (486);
115 }
116 
117 long
118 Namespace::query(char const *name, L4::Cap<void> const &target,
119  int timeout, l4_umword_t *local_id,
120  bool iterate) const throw()
121 { return query(name, strlen(name), target, timeout, local_id, iterate); }
122 
123 }
Low-level assert implementation.
Invalid argument.
Definition: err.h:56
long query(char const *name, L4::Cap< void > const &cap, int timeout=To_default, l4_umword_t *local_id=0, bool iterate=true) const
Query the name space for a named object.
A receive item for receiving a single capability.
Definition: ipc_types:268
L4Re C++ Interfaces.
Definition: cmd_control:15
long register_obj(char const *name, L4::Ipc::Cap< void > obj, unsigned flags=Rw) const
Register an object with a name.
Definition: namespace:176
The receiver requests to receive a local ID instead of a mapping whenever possible.
Definition: consts.h:212
int Opcode
Data type for RPC opcodes.
Definition: __typeinfo.h:47
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition: compiler.h:234
l4_umword_t data() const
Return the raw flex page descriptor.
Definition: ipc_types:470
unsigned long l4_umword_t
Unsigned machine word.
Definition: l4int.h:52
#define l4_assert(expr)
Low-level assert.
Definition: assert.h:43
Namespace interface.
void l4_sleep(int ms) L4_NOTHROW
Suspend thread for a period of ms milliseconds.
long unlink(char const *name)
Remove an entry from the name space.
Definition: namespace:202
#define L4_RPC_DEF(name)
Generate the definition of an RPC stub.
Definition: ipc_client:43
Cap< T > cap_cast(Cap< F > const &c)
static_cast for capabilities.
Definition: capability.h:376
Try again.
Definition: err.h:49
C++ interface for capabilities.
Definition: capability.h:13
Array data type for dynamically sized arrays in RPCs.
Definition: ipc_array:85
bool id_received() const
Check if a label was received instead of a mapping.
Definition: ipc_types:450
Generic RPC wrapper for L4 flex-pages.
Definition: ipc_types:321