L4Re Operating System Framework
Interface and Usage Documentation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ipc_ret_array
1// vi:set ft=cpp: -*- Mode: C++ -*-
2/*
3 * (c) 2014 Alexander Warg <alexander.warg@kernkonzept.com>
4 *
5 * License: see LICENSE.spdx (in this directory or the directories above)
6 */
7#pragma once
8
9#include "types"
10#include "ipc_basics"
11
12namespace L4 { namespace Ipc L4_EXPORT {
13
14// ---------------------------------------------------------------
23template<typename T> struct L4_EXPORT Ret_array
24{
25 typedef T const **ptr_type;
26
27 T *value = nullptr;
28 unsigned max = 0;
29 Ret_array() {}
30 Ret_array(T *v, unsigned max) : value(v), max(max) {}
31};
32
33namespace Msg {
34
35template<typename A> struct Elem< Ret_array<A> >
36{
37 enum { Is_optional = false };
38 typedef Ret_array<A> type;
39 typedef typename type::ptr_type arg_type;
40 typedef type svr_type;
41 typedef type svr_arg_type;
42};
43
44template<typename A>
45struct Is_valid_rpc_type<Ret_array<A> *> : L4::Types::False {};
46template<typename A>
47struct Is_valid_rpc_type<Ret_array<A> &> : L4::Types::False {};
48template<typename A>
49struct Is_valid_rpc_type<Ret_array<A> const &> : L4::Types::False {};
50template<typename A>
51struct Is_valid_rpc_type<Ret_array<A> const *> : L4::Types::False {};
52
53template<typename A> struct Class< Ret_array<A> > : Class<A>::type {};
54template<typename A> struct Direction< Ret_array<A> > : Dir_out {};
55
56template<typename A, typename CLASS>
57struct Clnt_val_ops<A const *, Dir_out, CLASS> : Clnt_noops<A const *>
58{
59 using Clnt_noops<A const *>::from_msg;
60 static int from_msg(char *msg, unsigned offset, unsigned limit, long ret,
61 A const *&arg, Dir_out, Cls_data)
62 {
63 offset = align_to<A>(offset);
64 arg = reinterpret_cast<A const *>(msg + offset);
65 if (L4_UNLIKELY(!check_size<A>(offset, limit, ret)))
66 return -1;
67
68 return offset + ret * sizeof(A);
69 }
70};
71
72template<typename A, typename CLASS>
73struct Svr_val_ops<Ret_array<A>, Dir_out, CLASS> :
74 Svr_noops<Ret_array<A> >
75{
76 typedef Ret_array<A> ret_array;
77 using Svr_noops<ret_array>::from_svr;
78 static int from_svr(char *, unsigned offset, unsigned limit, long ret,
79 ret_array const &, Dir_out, CLASS)
80 {
81 offset = align_to<A>(offset);
82 if (L4_UNLIKELY(!check_size<A>(offset, limit, ret)))
83 return -1;
84 offset += sizeof(A) * ret;
85 return offset;
86 }
87
88 using Svr_noops<ret_array>::to_svr;
89 static int to_svr(char *msg, unsigned offset, unsigned limit,
90 ret_array &arg, Dir_out, CLASS)
91 {
92 // there can be actually no limit check here, as this
93 // is variably sized output array
94 // FIXME: we could somehow makesure that this is the last
95 // output value...
96 offset = align_to<A>(offset);
97 arg = ret_array(reinterpret_cast<A*>(msg + offset),
98 (limit - offset) / sizeof(A));
99 // FIXME: we dont know the length of the array here so, cheat
100 return offset;
101 }
102};
103} // namespace Msg
104
105}}
#define L4_UNLIKELY(x)
Expression is unlikely to execute.
Definition compiler.h:275
#define L4_EXPORT
Attribute to mark functions, variables, and data types as being exported from a library.
Definition compiler.h:210
L4 low-level kernel interface.
Dynamically sized output array of type T.
Definition ipc_ret_array:24
False meta value.
Definition types:296