8#pragma GCC system_header
10#include "capability.h"
17#include <l4/cxx/result>
18#include <l4/cxx/type_traits>
41 Server_iface
const &operator = (Server_iface
const &);
50 class Mem_window final
56 virtual ~Allocator() =
default;
58 virtual void dispose(
l4_fpage_t fp)
noexcept = 0;
61 Mem_window()
noexcept =
default;
62 Mem_window(
l4_fpage_t fp, Allocator *allocator) noexcept
63 : _fp(fp), _allocator(allocator)
69 Mem_window(Mem_window
const &) =
delete;
70 Mem_window &operator=(Mem_window
const &) =
delete;
72 Mem_window(Mem_window &&other) noexcept
73 : _fp(other._fp), _allocator(other._allocator)
76 other._allocator =
nullptr;
79 Mem_window &operator=(Mem_window &&other)
noexcept
86 _allocator = other._allocator;
89 other._allocator =
nullptr;
98 _allocator->dispose(_fp);
100 _allocator =
nullptr;
108 _allocator =
nullptr;
112 explicit operator bool()
const noexcept
118 void *get()
const noexcept
121 unsigned order()
const noexcept
129 Allocator *_allocator =
nullptr;
136 Server_iface &operator = (Server_iface &&) =
delete;
242inline Server_iface::~Server_iface() {}
259 Epiface(Epiface
const &) =
delete;
260 Epiface &operator = (Epiface
const &) =
delete;
267 class Stored_cap :
public Cap<void>
270 enum { Managed = 0x10 };
273 Stored_cap() =
default;
274 Stored_cap(
Cap<void> const &c,
bool managed =
false)
277 static_assert (!(
L4_CAP_MASK & Managed),
"conflicting bits used...");
280 bool managed()
const {
return cap() & Managed; }
338 if ((srv && cap) || (!srv && !cap))
341 _cap = Stored_cap(cap, managed);
367template<
typename RPC_IFACE,
typename BASE = Epiface>
392template<
typename Derived,
typename BASE = Epiface,
393 bool = cxx::is_polymorphic<BASE>::value>
398 static_cast<Derived*
>(
this)->handle_irq();
410template<
typename Derived,
typename BASE>
411struct Irqep_t<Derived, BASE, false> : Epiface_t0<void, BASE>
415 static_cast<Derived*
>(
this)->handle_irq();
517inline Registry_iface::~Registry_iface() {}
524template<
typename IFACE>
527 l4_ret_t op_num_interfaces(L4::Meta::Rights)
535 _iter_interfaces(iter);
540 L4::Ipc::String<char> &name)
543 [idx, &proto, &name, num = 0U](L4::Type_info
const *t)
mutable
548 if (
auto *n = t->name())
560 return _iter_interfaces(iter) ? 0 : -
L4_ERANGE;
568 static bool _iter_interfaces(F &f)
572 static bool _iter_interfaces(L4::Type_info
const *t, F &f)
580 for (
unsigned i = 0; i < t->num_bases(); ++i)
581 if (_iter_interfaces(t->base(i), f))
588template<
typename IFACE,
typename LIST>
592template<
typename IFACE>
593struct _Dispatch<IFACE, Iface_list_end>
595 template<
typename THIS,
typename A1,
typename A2 >
596 static l4_msgtag_t f(THIS *, l4_msgtag_t, A1, A2 &)
601template<
typename IFACE,
typename I,
typename LIST >
602struct _Dispatch<IFACE, Iface_list<I, LIST> >
605 template<
typename THIS >
606 static l4_msgtag_t _f(THIS *, l4_msgtag_t tag,
unsigned r,
609 using L4::Ipc::Msg::dispatch_call;
610 using Meta = L4::Meta::Rpcs;
611 using Msvr = Meta_svr<IFACE>;
612 return dispatch_call<Meta>(
static_cast<Msvr *
>(
nullptr), utcb, tag, r);
616 template<
typename THIS >
617 static l4_msgtag_t _f(THIS *self, l4_msgtag_t t,
unsigned r,
620 using L4::Ipc::Msg::dispatch_call;
621 return dispatch_call<typename I::iface_type::Rpcs>(self, utcb, t, r);
625 template<
typename THIS >
626 static l4_msgtag_t f(THIS *self, l4_msgtag_t tag,
unsigned r,
629 if (I::Proto == tag.
label())
630 return _f(self, tag, r, utcb,
633 return _Dispatch<IFACE, typename LIST::type>::f(self, tag, r, utcb);
637template<
typename IFACE>
639 _Dispatch<IFACE, typename L4::Kobject_typeid<IFACE>::Iface_list::type>
644template<
typename EPIFACE>
645struct Dispatch : Detail::Dispatch<typename EPIFACE::Interface>
656template<
typename Derived,
typename IFACE,
typename BASE = L4::Epiface,
657 bool = cxx::is_polymorphic<BASE>::value>
663 using Dispatch = Ipc::Dispatch<Derived>;
664 return Dispatch::f(
static_cast<Derived*
>(
this), tag, rights, utcb);
668template<
typename Derived,
typename IFACE,
typename BASE>
674 using Dispatch = Ipc::Dispatch<Derived>;
675 return Dispatch::f(
static_cast<Derived*
>(
this), tag, rights, utcb);
694 {
return reinterpret_cast<Value*
>(label & ~3UL); }
Type information handling.
This registry returns the corresponding server object based on the label of an Ipc_gate.
static l4_msgtag_t dispatch(l4_msgtag_t tag, l4_umword_t label, l4_utcb_t *utcb)
The dispatch function called by the server loop.
static Value * find(l4_umword_t label)
Get the server object for an Ipc_gate label.
l4_cap_idx_t cap() const noexcept
Return capability selector.
C++ interface for capabilities.
Interface for server-loop related functions.
virtual cxx::Result< Mem_window > get_rcv_mem() noexcept
Take the current memory receive window.
virtual int realloc_rcv_cap(int index)=0
Allocate a new capability for the given receive buffer.
virtual cxx::Result< L4::Reply_cap > take_reply_cap() noexcept
Take the currently used reply capability.
virtual int add_timeout(Timeout *timeout, l4_kernel_clock_t time)=0
Add a timeout to the server internal timeout queue.
virtual int remove_timeout(Timeout *timeout)=0
Remove the given timeout from the timer queue.
Server_iface()
Make a server interface.
L4::Type_info::Demand Demand
Data type expressing server-side demand for receive buffers.
virtual L4::Cap< void > get_rcv_cap(int index) const =0
Get capability slot allocated to the given receive buffer.
L4::Cap< void > rcv_cap(int index) const
Get receive cap with the given index as generic (void) type.
L4::Cap< T > rcv_cap(int index) const
Get given receive buffer as typed capability.
virtual int alloc_buffer_demand(Demand const &demand)=0
Tells the server to allocate buffers for the given demand.
Callback interface for Timeout_queue.
C++ Irq interface, see IRQs for the C interface.
Interface for kernel objects that allow to receive IPC from them.
Abstract interface for object registries.
virtual void unregister_obj(L4::Epiface *o, bool unmap=true)=0
Unregister the given object o from the server.
virtual L4::Cap< L4::Irq > register_irq_obj(L4::Epiface *o)=0
Register o as server-side object for asynchronous IRQs.
virtual L4::Cap< void > register_obj(L4::Epiface *o, char const *service)=0
Register an L4::Epiface for an IPC gate available in the applications environment under the name serv...
virtual L4::Cap< L4::Rcv_endpoint > register_obj(L4::Epiface *o, L4::Cap< L4::Rcv_endpoint > ep)=0
Register o as server-side object for a pre-allocated capability.
virtual L4::Cap< void > register_obj(L4::Epiface *o)=0
Register o as server-side object for synchronous RPC.
Data type for expressing the needed receive buffers at the server-side of an interface.
A result of a function call.
unsigned long l4_umword_t
Unsigned machine word.
signed long l4_mword_t
Signed machine word.
l4_uint64_t l4_kernel_clock_t
Kernel clock type.
#define L4_CAP_MASK
Mask to get only the relevant bits of an l4_cap_idx_t.
@ L4_EINVAL
Invalid argument.
@ L4_EBADPROTO
Unsupported protocol.
L4_CONSTEXPR int l4_is_fpage_valid(l4_fpage_t fp) L4_NOTHROW
Test if the flexpage is valid.
L4_CONSTEXPR l4_addr_t l4_fpage_memaddr(l4_fpage_t f) L4_NOTHROW
Return the memory address from the memory flexpage.
L4_CONSTEXPR unsigned l4_fpage_size(l4_fpage_t f) L4_NOTHROW
Return size (log2) from a flexpage.
L4_CONSTEXPR l4_fpage_t l4_fpage_invalid(void) L4_NOTHROW
Get an invalid flexpage.
Type_info const * kobject_typeid() noexcept
Get the L4::Type_info for the L4Re interface given in T.
l4_msgtag_t l4_msgtag(long label, unsigned words, unsigned items, unsigned flags) L4_NOTHROW
Create a message tag from the specified values.
@ L4_PROTO_META
Meta information protocol.
struct l4_utcb_t l4_utcb_t
Opaque type for the UTCB.
Common L4 ABI Data Types.
l4_int16_t l4_ret_t
Return value of an IPC call as well as an RPC call.
Helper classes for L4::Server instantiation.
Definition of interface data-type helpers.
L4 low-level kernel interface.
@ PROTO_EMPTY
Empty protocol for empty APIs.
Cap< T > cap_cast(Cap< F > const &c) noexcept
static_cast for capabilities.
Epiface mixin for generic Kobject-based interfaces.
Type_info::Demand get_buffer_demand() const
Get the server-side buffer demand based in IFACE.
Cap< RPC_IFACE > obj_cap() const
Get the (typed) capability to this object.
RPC_IFACE Interface
Data type of the IPC interface definition.
Epiface implementation for Kobject-based interface implementations.
l4_msgtag_t dispatch(l4_msgtag_t tag, unsigned rights, l4_utcb_t *utcb) final
The abstract handler for client requests to the object.
Base class for interface implementations.
Stored_cap obj_cap() const
Get the capability to the kernel object belonging to this object.
Ipc_svr::Server_iface::Demand Demand
Type for server-side receive buffer demand.
Ipc_svr::Server_iface Server_iface
Type for abstract server interface.
virtual ~Epiface()=0
Destroy the object.
Server_iface * server_iface() const
Get pointer to server interface at which the object is currently registered.
virtual l4_msgtag_t dispatch(l4_msgtag_t tag, unsigned rights, l4_utcb_t *utcb)=0
The abstract handler for client requests to the object.
void set_obj_cap(Cap< void > const &cap)
Deprecated server registration function.
virtual Demand get_buffer_demand() const =0
Get the server-side receive buffer demand for this object.
int set_server(Server_iface *srv, Cap< void > cap, bool managed=false)
Set server registration info for the object.
Epiface()
Make a server object.
Epiface implementation for interrupt handlers.
Cap< L4::Irq > obj_cap() const
Get the (typed) capability to this object.
l4_msgtag_t dispatch(l4_msgtag_t, unsigned, l4_utcb_t *) final
The abstract handler for client requests to the object.
T::__Kobject_typeid::Demand Demand
Data type expressing the static demand of receive buffers in a server.
Dynamic Type Information for L4Re Interfaces.
Message tag data structure.
long label() const L4_NOTHROW
Get the protocol value.