genode/repos/base-foc/src/lib/base/capability.cc
Norman Feske 88b358c5ef Unification of native_capability.h
This patch establishes the sole use of generic headers across all
kernels. The common 'native_capability.h' is based on the version of
base-sel4. All traditional L4 kernels and Linux use the same
implementation of the capability-lifetime management. On base-hw, NOVA,
Fiasco.OC, and seL4, custom implementations (based on their original
mechanisms) are used, with the potential to unify them further in the
future.

This change achieves binary compatibility of dynamically linked programs
across all kernels.

Furthermore, the patch introduces a Native_capability::print method,
which allows the easy output of the kernel-specific capability
representation using the base/log.h API.

Issue #1993
2016-07-11 13:07:37 +02:00

73 lines
1.2 KiB
C++

/*
* \brief Capability lifetime management
* \author Norman Feske
* \date 2015-05-06
*/
/*
* Copyright (C) 2015 Genode Labs GmbH
*
* This file is part of the Genode OS framework, which is distributed
* under the terms of the GNU General Public License version 2.
*/
/* Fiasco includes */
namespace Fiasco {
#include <l4/sys/types.h>
}
/* base-internal includes */
#include <base/internal/cap_map.h>
#include <base/internal/capability_data.h>
using namespace Genode;
Native_capability::Native_capability() { }
void Native_capability::_inc()
{
if (_data)
_data->inc();
}
void Native_capability::_dec()
{
if (_data && !_data->dec())
cap_map()->remove(_data);
}
long Native_capability::local_name() const
{
return _data ? _data->id() : 0;
}
bool Native_capability::valid() const
{
return (_data != 0) && _data->valid();
}
Native_capability::Raw Native_capability::raw() const
{
return { (unsigned long)local_name(), 0, 0, 0 };
}
void Native_capability::print(Genode::Output &out) const
{
using Genode::print;
print(out, "cap<");
if (_data) {
print(out, "kcap=", Hex(_data->kcap()), ",key=", (unsigned)_data->id());
} else {
print(out, "invalid");
}
print(out, ">");
}