2015-05-19 14:18:40 +02:00
|
|
|
/*
|
|
|
|
* \brief Kernel object handling in core
|
|
|
|
* \author Stefan Kalkowski
|
|
|
|
* \date 2015-04-21
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2017-02-20 13:23:52 +01:00
|
|
|
* Copyright (C) 2015-2017 Genode Labs GmbH
|
2015-05-19 14:18:40 +02:00
|
|
|
*
|
|
|
|
* This file is part of the Genode OS framework, which is distributed
|
2017-02-20 13:23:52 +01:00
|
|
|
* under the terms of the GNU Affero General Public License version 3.
|
2015-05-19 14:18:40 +02:00
|
|
|
*/
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#ifndef _CORE__OBJECT_H_
|
|
|
|
#define _CORE__OBJECT_H_
|
2015-05-19 14:18:40 +02:00
|
|
|
|
2016-06-15 15:04:54 +02:00
|
|
|
/* Genode includes */
|
|
|
|
#include <util/construct_at.h>
|
|
|
|
|
|
|
|
/* base-internal includes */
|
|
|
|
#include <base/internal/capability_space.h>
|
|
|
|
|
|
|
|
/* base-hw includes */
|
2015-05-19 14:18:40 +02:00
|
|
|
#include <kernel/interface.h>
|
|
|
|
#include <kernel/object.h>
|
|
|
|
|
2016-06-15 15:04:54 +02:00
|
|
|
namespace Genode {
|
2015-05-19 14:18:40 +02:00
|
|
|
/**
|
|
|
|
* Represents a kernel object in core
|
|
|
|
*
|
|
|
|
* \param T type of the kernel object
|
|
|
|
*/
|
|
|
|
template <typename T> class Kernel_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
class Genode::Kernel_object
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
|
|
|
|
uint8_t _data[sizeof(Kernel::Core_object<T>)]
|
|
|
|
__attribute__((aligned(sizeof(addr_t))));
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
Untyped_capability _cap;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
Kernel_object() {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a kernel object either via a syscall or directly
|
|
|
|
*/
|
|
|
|
template <typename... ARGS>
|
|
|
|
Kernel_object(bool syscall, ARGS &&... args)
|
2016-06-15 15:04:54 +02:00
|
|
|
: _cap(Capability_space::import(syscall ? T::syscall_create(&_data, args...)
|
|
|
|
: Kernel::cap_id_invalid()))
|
|
|
|
{
|
|
|
|
if (!syscall) construct_at<T>(&_data, args...);
|
|
|
|
}
|
2015-05-19 14:18:40 +02:00
|
|
|
|
|
|
|
~Kernel_object() { T::syscall_destroy(kernel_object()); }
|
|
|
|
|
|
|
|
T * kernel_object() { return reinterpret_cast<T*>(_data); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the kernel object explicitely via this function
|
|
|
|
*/
|
|
|
|
template <typename... ARGS>
|
|
|
|
bool create(ARGS &&... args)
|
|
|
|
{
|
|
|
|
if (_cap.valid()) return false;
|
2016-06-15 15:04:54 +02:00
|
|
|
_cap = Capability_space::import(T::syscall_create(&_data, args...));
|
2015-05-19 14:18:40 +02:00
|
|
|
return _cap.valid();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-12 10:06:29 +02:00
|
|
|
#endif /* _CORE__OBJECT_H_ */
|