Loading...
Searching...
No Matches
env_ns
// vi:set ft=cpp: -*- Mode: C++ -*-
#pragma once
#include <l4/re/cap_alloc>
#include <l4/re/util/cap_alloc>
#include <l4/re/namespace>
#include <l4/re/env>
#include <string.h>
namespace L4Re { namespace Util {
class Env_ns
{
private:
L4Re::Cap_alloc *_ca;
Env const *_env;
public:
explicit Env_ns(Env const *env = Env::env(),
L4Re::Cap_alloc *ca = &L4Re::Util::cap_alloc)
: _ca(ca), _env(env) {}
L4::Cap<void>
query(char const *name, unsigned len, int timeout = Namespace::To_default,
l4_umword_t *local_id = 0, bool iterate = true) const noexcept
{
typedef Env::Cap_entry Cap_entry;
// Skip possible first slash
if (len && name[0] == '/')
{
++name;
--len;
}
char const *n = name;
for (; len && *n != '/'; ++n, --len) // Count first path element
;
Cap_entry const *e = _env->get(name, n - name);
if (!e)
return L4::Cap<void>(-L4_ENOENT);
if (len > 0 && *n == '/')
{
L4::Cap<L4Re::Namespace> ns(e->cap);
L4::Cap<void> cap = _ca->alloc<void>();
if (!cap.is_valid())
return L4::Cap<void>(-L4_ENOMEM);
long r = ns->query(n + 1, len - 1, cap, timeout, local_id, iterate);
if (r >= 0)
return cap;
_ca->free(cap);
return L4::Cap<void>(r);
}
return L4::Cap<void>(e->cap);
}
L4::Cap<void>
query(char const *name, int timeout = Namespace::To_default,
l4_umword_t *local_id = 0, bool iterate = true) const noexcept
{ return query(name, __builtin_strlen(name), timeout, local_id, iterate); }
template<typename T >
L4::Cap<T>
query(char const *name, int timeout = Namespace::To_default,
l4_umword_t *local_id = 0, bool iterate = true) const noexcept
{
return L4::cap_cast<T>(query(name, __builtin_strlen(name),
timeout, local_id, iterate));
}
};
}}
cap_alloc
Abstract capability-allocator interface.
L4Re::Env::env
static Env const * env() noexcept
Returns the initial environment for the current task.
Definition env:96
L4Re::Env::Cap_entry
l4re_env_cap_entry_t Cap_entry
C++ type for an entry in the initial objects array.
Definition env:87
L4Re::Namespace::To_default
@ To_default
Default timeout.
Definition namespace:85
L4::Cap_base::is_valid
bool is_valid() const noexcept
Test whether the capability is a valid capability index (i.e., not L4_INVALID_CAP).
Definition capability.h:57
env
Environment interface.
l4_umword_t
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
L4_ENOENT
@ L4_ENOENT
No such entity.
Definition err.h:34
L4_ENOMEM
@ L4_ENOMEM
No memory.
Definition err.h:39
L4Re::Util::cap_alloc
_Cap_alloc & cap_alloc
Capability allocator.
L4Re::Util
Documentation of the L4 Runtime Environment utility functionality in C++.
Definition l4re.dox:21
L4Re
L4Re C++ Interfaces.
Definition cmd_control:14
L4::cap_cast
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.
Definition capability.h:416
namespace
Namespace interface.
string.h
String.
cap_alloc
Capability allocator.