L4Re Operating System Framework – Interface and Usage Documentation
Loading...
Searching...
No Matches
env_ns
1// vi:set ft=cpp: -*- Mode: C++ -*-
2
3#pragma once
4
5#include <l4/re/cap_alloc>
7#include <l4/re/namespace>
8#include <l4/re/env>
9#include <cstring>
10
11namespace L4Re { namespace Util {
12
13class Env_ns
14{
15private:
16 L4Re::Cap_alloc *_ca;
17 Env const *_env;
18
19public:
20 explicit Env_ns(Env const *env = Env::env(),
22 : _ca(ca), _env(env) {}
23
25 query(char const *name, unsigned len, int timeout = Namespace::To_default,
26 l4_umword_t *local_id = 0, bool iterate = true) const noexcept
27 {
28 typedef Env::Cap_entry Cap_entry;
29
30 char const *n = name;
31 for (; len && *n != '/'; ++n, --len)
32 ;
33
34 Cap_entry const *e = _env->get(name, n - name);
35 if (!e)
36 return L4::Cap<void>(-L4_ENOENT);
37
38 if (len > 0 && *n == '/')
39 {
40 L4::Cap<L4Re::Namespace> ns(e->cap);
41 L4::Cap<void> cap = _ca->alloc<void>();
42
43 if (!cap.is_valid())
44 return L4::Cap<void>(-L4_ENOMEM);
45
46 long r = ns->query(n + 1, len - 1, cap, timeout, local_id, iterate);
47 if (r >= 0)
48 return cap;
49
50 _ca->free(cap);
51
52 return L4::Cap<void>(r);
53 }
54
55 return L4::Cap<void>(e->cap);
56 }
57
59 query(char const *name, int timeout = Namespace::To_default,
60 l4_umword_t *local_id = 0, bool iterate = true) const noexcept
61 { return query(name, __builtin_strlen(name), timeout, local_id, iterate); }
62
63 template<typename T >
65 query(char const *name, int timeout = Namespace::To_default,
66 l4_umword_t *local_id = 0, bool iterate = true) const noexcept
67 {
68 return L4::cap_cast<T>(query(name, __builtin_strlen(name),
69 timeout, local_id, iterate));
70 }
71};
72
73}}
Abstract capability-allocator interface.
Capability allocator interface.
Definition cap_alloc:42
virtual L4::Cap< void > alloc() noexcept=0
Allocate a capability.
static L4Re::Cap_alloc * get_cap_alloc(CAP_ALLOC &ca)
Construct an instance of a capability allocator.
Definition cap_alloc:90
virtual void free(L4::Cap< void > cap, l4_cap_idx_t task=L4_INVALID_CAP, unsigned unmap_flags=L4_FP_ALL_SPACES) noexcept=0
Free a capability.
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition env:103
l4re_env_cap_entry_t Cap_entry
C++ type for an entry in the initial objects array.
Definition env:94
@ To_default
Default timeout.
Definition namespace:96
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:60
C++ interface for capabilities.
Definition capability.h:222
Environment interface.
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:51
@ L4_ENOENT
No such entity.
Definition err.h:45
@ L4_ENOMEM
No memory.
Definition err.h:50
_Cap_alloc & cap_alloc
Capability allocator.
L4Re C++ Interfaces.
Definition cmd_control:15
Namespace interface.
Capability allocator.