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 // Skip possible first slash
31 if (len && name[0] == '/')
32 {
33 ++name;
34 --len;
35 }
36
37 char const *n = name;
38 for (; len && *n != '/'; ++n, --len) // Count first path element
39 ;
40
41 Cap_entry const *e = _env->get(name, n - name);
42 if (!e)
43 return L4::Cap<void>(-L4_ENOENT);
44
45 if (len > 0 && *n == '/')
46 {
47 L4::Cap<L4Re::Namespace> ns(e->cap);
48 L4::Cap<void> cap = _ca->alloc<void>();
49
50 if (!cap.is_valid())
51 return L4::Cap<void>(-L4_ENOMEM);
52
53 long r = ns->query(n + 1, len - 1, cap, timeout, local_id, iterate);
54 if (r >= 0)
55 return cap;
56
57 _ca->free(cap);
58
59 return L4::Cap<void>(r);
60 }
61
62 return L4::Cap<void>(e->cap);
63 }
64
66 query(char const *name, int timeout = Namespace::To_default,
67 l4_umword_t *local_id = 0, bool iterate = true) const noexcept
68 { return query(name, __builtin_strlen(name), timeout, local_id, iterate); }
69
70 template<typename T >
72 query(char const *name, int timeout = Namespace::To_default,
73 l4_umword_t *local_id = 0, bool iterate = true) const noexcept
74 {
75 return L4::cap_cast<T>(query(name, __builtin_strlen(name),
76 timeout, local_id, iterate));
77 }
78};
79
80}}
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:57
C++ interface for capabilities.
Definition capability.h:219
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 l4re.dox:17
Namespace interface.
Capability allocator.