L4Re Operating System Framework
Interface and Usage Documentation
Loading...
Searching...
No Matches
ipc_string
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#include "ipc_array"
12
13namespace L4 { namespace Ipc {
14
15template<typename CHAR = char const, typename LEN = unsigned long>
16struct String : Array<CHAR, LEN>
17{
18 static LEN strlength(CHAR *d) { LEN l = 0; while (d[l]) ++l; return l; }
19 String() {}
20 String(CHAR *d) : Array<CHAR, LEN>(strlength(d) + 1, d) {}
21 String(LEN len, CHAR *d) : Array<CHAR, LEN>(len, d) {}
22 void copy_in(CHAR const *s)
23 {
24 if (this->length < 1)
25 return;
26
27 LEN i;
28 for (i = 0; i < this->length - 1 && s[i]; ++i)
29 this->data[i] = s[i];
30 this->length = i + 1;
31 this->data[i] = CHAR();
32 }
33};
34
35template< typename CHAR = char, typename LEN_TYPE = unsigned long,
36 LEN_TYPE MAX = (L4_UTCB_GENERIC_DATA_SIZE *
37 sizeof(l4_umword_t)) / sizeof(CHAR) >
38using String_in_buf = Array_in_buf<CHAR, LEN_TYPE, MAX>;
39
40namespace Msg {
41
42template<typename A, typename LEN>
43struct Svr_val_ops< String<A, LEN> > : Svr_val_ops< Array_ref<A, LEN> >
44{
45 using Base = Svr_val_ops< Array_ref<A, LEN> >;
46 using svr_type = typename Base::svr_type;
47
48 static int to_svr_data(char *msg, unsigned offset, unsigned limit,
49 svr_type &a)
50 {
51 int r = Base::to_svr_data(msg, offset, limit, a);
52 if (r < 0)
53 return r;
54
55 // correct clients send at least the zero terminator
56 if (a.length < 1)
57 return -L4_EMSGTOOSHORT;
58
59 using elem_type = L4::Types::Remove_const_t<A>;
60 const_cast<elem_type*>(a.data)[a.length - 1] = A();
61 return r;
62 }
63};
64
65template<typename A, typename LEN>
66struct Clnt_val_ops<String<A, LEN>> : Clnt_val_ops<Array<A, LEN>>
67{
68 using Base = Clnt_val_ops<Array<A, LEN>>;
69 using type = typename Base::type;
70
71 static int from_msg_data(char *msg, unsigned offset, unsigned limit, type &a)
72 {
73 int r = Base::from_msg_data(msg, offset, limit, a);
74 if (r < 0)
75 return r;
76
77 // check for a bad server
78 if (a.length < 1)
79 return -L4_EMSGTOOSHORT;
80
81 a.data[a.length - 1] = A();
82 return r;
83 };
84};
85
86template<typename A, typename LEN>
87struct Is_valid_rpc_type<String<A, LEN> const *> : L4::Types::False {};
88template<typename A, typename LEN>
89struct Is_valid_rpc_type<String<A, LEN> const &> : L4::Types::False {};
90
91} // namespace Msg
92
93}}
unsigned long l4_umword_t
Unsigned machine word.
Definition l4int.h:40
@ L4_EMSGTOOSHORT
Message too short.
Definition err.h:58
IPC Message related functionality.
Definition ipc_array:154
IPC related functionality.
Definition ipc_array:13
L4 low-level kernel interface.
Server-side copy in buffer for Array.
Definition ipc_array:127
Array data type for dynamically sized arrays in RPCs.
Definition ipc_array:82
Defines client-side handling of 'MTYPE' as RPC argument.
Definition ipc_basics:409
static int from_msg_data(char *msg, unsigned offset, unsigned limit, MTYPE &arg) noexcept
Copy data from the message to a T client reference (arg must be MTYPE &).
Definition ipc_basics:419
Type trait defining a valid RPC parameter type.
Definition ipc_basics:521
Defines server-side handling of 'MTYPE' as RPC argument.
Definition ipc_basics:439
static int to_svr_data(char *msg, unsigned offset, unsigned limit, MTYPE &arg) noexcept
Copy data from the message to a T server reference (arg must be MTYPE &).
Definition ipc_basics:444
#define L4_UTCB_GENERIC_DATA_SIZE
Total number of message register (MRs) available.
Definition utcb.h:59