L4Re - L4 Runtime Environment
 All Data Structures Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
namespace_impl.h
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 #include <l4/re/namespace-sys.h>
25 #include <l4/re/protocols>
26 
27 #include <l4/util/util.h>
28 
29 #include <l4/cxx/exceptions>
30 #include <l4/cxx/ipc_helper>
31 #include <l4/cxx/ipc_stream>
32 
33 #include <l4/sys/err.h>
34 
35 #include <cstring>
36 
37 namespace L4Re {
38 
39 long
40 Namespace::_query(char const *name, unsigned len,
41  L4::Cap<void> const &target,
42  l4_umword_t *local_id, bool iterate) const throw()
43 {
44  unsigned long res = len;
45  char const *n = name;
46  L4::Cap<Namespace> ns(cap());
47  while (res > 0)
48  {
50  io << L4::Opcode(L4Re::Namespace_::Query)
52  io << L4::Ipc::Small_buf(target.cap(), local_id ? L4_RCV_ITEM_LOCAL_ID : 0);
53  l4_msgtag_t r = io.call(ns.cap(), L4Re::Protocol::Namespace);
54  long err = l4_error(r);
55 
56  if (err < 0)
57  return err;
58 
59  bool const partly = err & Partly_resolved;
60  if (partly)
61  {
62  l4_umword_t dummy;
63  io >> dummy >> L4::Ipc::Buf_in<char const>(n, res);
64  }
65 
66  L4::Ipc::Snd_fpage cap;
67  io >> cap;
68  if (cap.id_received())
69  {
70  *local_id = cap.data();
71  return res;
72  }
73 
74  if (partly && iterate)
75  ns = L4::cap_cast<Namespace>(target);
76  else
77  return err;
78  }
79 
80  return res;
81 }
82 
83 long
84 Namespace::query(char const *name, unsigned len, L4::Cap<void> const &target,
85  int timeout, l4_umword_t *local_id, bool iterate) const throw()
86 {
87  long ret;
88  long rem = timeout;
89  long to = 0;
90 
91  if (rem)
92  to = 10;
93  do
94  {
95  ret = _query(name, len, target, local_id, iterate);
96 
97  if (ret >= 0)
98  return ret;
99 
100  if (EXPECT_FALSE(ret < 0 && (ret != -L4_EAGAIN)))
101  return ret;
102 
103  if (rem == to)
104  return ret;
105 
106  l4_sleep(to);
107 
108  rem -= to;
109  if (to < 100)
110  to += to;
111  if (to > rem)
112  to = rem;
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 long
124 Namespace::register_obj(char const *name, L4::Cap<void> const &o,
125  unsigned flags) const throw()
126 {
128  io << L4::Opcode(L4Re::Namespace_::Register)
129  << flags << L4::Ipc::Buf_cp_out<char const>(name, strlen(name));
130  if (o.is_valid())
131  io << L4::Ipc::Snd_fpage(o.fpage(L4_FPAGE_RWX & flags));
132  l4_msgtag_t res = io.call(cap(), L4Re::Protocol::Namespace);
133  return l4_error(res);
134 }
135 
136 long
137 Namespace::unlink(char const *name) throw()
138 {
140  io << L4::Opcode(L4Re::Namespace_::Unlink)
141  << L4::Ipc::Buf_cp_out<char const>(name, strlen(name));
142  l4_msgtag_t res = io.call(cap(), L4Re::Protocol::Namespace);
143  return l4_error(res);
144 }
145 
146 long
147 Namespace::link(char const *name, unsigned len,
148  L4::Cap<L4Re::Namespace> src_dir,
149  char const *src_name, unsigned src_len,
150  unsigned flags) throw()
151 {
153  io << L4::Opcode(L4Re::Namespace_::Link)
154  << flags << L4::Ipc::Buf_cp_out<char const>(name, len)
155  << L4::Ipc::Buf_cp_out<char const>(src_name, src_len)
156  << L4::Ipc::Snd_fpage(src_dir.fpage());
157  l4_msgtag_t res = io.call(cap(), L4Re::Protocol::Namespace);
158  return l4_error(res);
159 }
160 
161 };
L4Re - L4 Runtime Environment