1*418b791dSBob Badour /*
2*418b791dSBob Badour * Copyright (c) 2019, The Linux Foundation. All rights reserved.
3*418b791dSBob Badour *
4*418b791dSBob Badour * Redistribution and use in source and binary forms, with or without
5*418b791dSBob Badour * modification, are permitted provided that the following conditions are
6*418b791dSBob Badour * met:
7*418b791dSBob Badour * * Redistributions of source code must retain the above copyright
8*418b791dSBob Badour * notice, this list of conditions and the following disclaimer.
9*418b791dSBob Badour * * Redistributions in binary form must reproduce the above
10*418b791dSBob Badour * copyright notice, this list of conditions and the following
11*418b791dSBob Badour * disclaimer in the documentation and/or other materials provided
12*418b791dSBob Badour * with the distribution.
13*418b791dSBob Badour * * Neither the name of The Linux Foundation nor the names of its
14*418b791dSBob Badour * contributors may be used to endorse or promote products derived
15*418b791dSBob Badour * from this software without specific prior written permission.
16*418b791dSBob Badour *
17*418b791dSBob Badour * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18*418b791dSBob Badour * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19*418b791dSBob Badour * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20*418b791dSBob Badour * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21*418b791dSBob Badour * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22*418b791dSBob Badour * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23*418b791dSBob Badour * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24*418b791dSBob Badour * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25*418b791dSBob Badour * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26*418b791dSBob Badour * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27*418b791dSBob Badour * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28*418b791dSBob Badour */
29*418b791dSBob Badour #ifndef _APPS_REMOTECTL_SKEL_H
30*418b791dSBob Badour #define _APPS_REMOTECTL_SKEL_H
31*418b791dSBob Badour #include "apps_remotectl.h"
32*418b791dSBob Badour #include "remote.h"
33*418b791dSBob Badour #include <string.h>
34*418b791dSBob Badour #ifndef ALLOCATOR_H
35*418b791dSBob Badour #define ALLOCATOR_H
36*418b791dSBob Badour
37*418b791dSBob Badour #include <stdlib.h>
38*418b791dSBob Badour #include <stdint.h>
39*418b791dSBob Badour
40*418b791dSBob Badour typedef struct _heap _heap;
41*418b791dSBob Badour struct _heap {
42*418b791dSBob Badour _heap* pPrev;
43*418b791dSBob Badour const char* loc;
44*418b791dSBob Badour uint64_t buf;
45*418b791dSBob Badour };
46*418b791dSBob Badour
47*418b791dSBob Badour typedef struct allocator {
48*418b791dSBob Badour _heap* pheap;
49*418b791dSBob Badour uint8_t* stack;
50*418b791dSBob Badour uint8_t* stackEnd;
51*418b791dSBob Badour int nSize;
52*418b791dSBob Badour } allocator;
53*418b791dSBob Badour
_heap_alloc(_heap ** ppa,const char * loc,int size,void ** ppbuf)54*418b791dSBob Badour static __inline int _heap_alloc(_heap** ppa, const char* loc, int size, void** ppbuf) {
55*418b791dSBob Badour _heap* pn = 0;
56*418b791dSBob Badour pn = malloc(size + sizeof(_heap) - sizeof(uint64_t));
57*418b791dSBob Badour if(pn != 0) {
58*418b791dSBob Badour pn->pPrev = *ppa;
59*418b791dSBob Badour pn->loc = loc;
60*418b791dSBob Badour *ppa = pn;
61*418b791dSBob Badour *ppbuf = (void*)&(pn->buf);
62*418b791dSBob Badour return 0;
63*418b791dSBob Badour } else {
64*418b791dSBob Badour return -1;
65*418b791dSBob Badour }
66*418b791dSBob Badour }
67*418b791dSBob Badour #define _ALIGN_SIZE(x, y) (((x) + (y-1)) & ~(y-1))
68*418b791dSBob Badour
69*418b791dSBob Badour
allocator_alloc(allocator * me,const char * loc,int size,unsigned int al,void ** ppbuf)70*418b791dSBob Badour static __inline int allocator_alloc(allocator* me,
71*418b791dSBob Badour const char* loc,
72*418b791dSBob Badour int size,
73*418b791dSBob Badour unsigned int al,
74*418b791dSBob Badour void** ppbuf) {
75*418b791dSBob Badour if(size < 0) {
76*418b791dSBob Badour return -1;
77*418b791dSBob Badour } else if (size == 0) {
78*418b791dSBob Badour *ppbuf = 0;
79*418b791dSBob Badour return 0;
80*418b791dSBob Badour }
81*418b791dSBob Badour if((_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size) < (uintptr_t)me->stack + me->nSize) {
82*418b791dSBob Badour *ppbuf = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al);
83*418b791dSBob Badour me->stackEnd = (uint8_t*)_ALIGN_SIZE((uintptr_t)me->stackEnd, al) + size;
84*418b791dSBob Badour return 0;
85*418b791dSBob Badour } else {
86*418b791dSBob Badour return _heap_alloc(&me->pheap, loc, size, ppbuf);
87*418b791dSBob Badour }
88*418b791dSBob Badour }
89*418b791dSBob Badour
90*418b791dSBob Badour
allocator_deinit(allocator * me)91*418b791dSBob Badour static __inline void allocator_deinit(allocator* me) {
92*418b791dSBob Badour _heap* pa = me->pheap;
93*418b791dSBob Badour while(pa != 0) {
94*418b791dSBob Badour _heap* pn = pa;
95*418b791dSBob Badour const char* loc = pn->loc;
96*418b791dSBob Badour (void)loc;
97*418b791dSBob Badour pa = pn->pPrev;
98*418b791dSBob Badour free(pn);
99*418b791dSBob Badour }
100*418b791dSBob Badour }
101*418b791dSBob Badour
allocator_init(allocator * me,uint8_t * stack,int stackSize)102*418b791dSBob Badour static __inline void allocator_init(allocator* me, uint8_t* stack, int stackSize) {
103*418b791dSBob Badour me->stack = stack;
104*418b791dSBob Badour me->stackEnd = stack + stackSize;
105*418b791dSBob Badour me->nSize = stackSize;
106*418b791dSBob Badour me->pheap = 0;
107*418b791dSBob Badour }
108*418b791dSBob Badour
109*418b791dSBob Badour
110*418b791dSBob Badour #endif // ALLOCATOR_H
111*418b791dSBob Badour
112*418b791dSBob Badour #ifndef SLIM_H
113*418b791dSBob Badour #define SLIM_H
114*418b791dSBob Badour
115*418b791dSBob Badour #include <stdint.h>
116*418b791dSBob Badour
117*418b791dSBob Badour //a C data structure for the idl types that can be used to implement
118*418b791dSBob Badour //static and dynamic language bindings fairly efficiently.
119*418b791dSBob Badour //
120*418b791dSBob Badour //the goal is to have a minimal ROM and RAM footprint and without
121*418b791dSBob Badour //doing too many allocations. A good way to package these things seemed
122*418b791dSBob Badour //like the module boundary, so all the idls within one module can share
123*418b791dSBob Badour //all the type references.
124*418b791dSBob Badour
125*418b791dSBob Badour
126*418b791dSBob Badour #define PARAMETER_IN 0x0
127*418b791dSBob Badour #define PARAMETER_OUT 0x1
128*418b791dSBob Badour #define PARAMETER_INOUT 0x2
129*418b791dSBob Badour #define PARAMETER_ROUT 0x3
130*418b791dSBob Badour #define PARAMETER_INROUT 0x4
131*418b791dSBob Badour
132*418b791dSBob Badour //the types that we get from idl
133*418b791dSBob Badour #define TYPE_OBJECT 0x0
134*418b791dSBob Badour #define TYPE_INTERFACE 0x1
135*418b791dSBob Badour #define TYPE_PRIMITIVE 0x2
136*418b791dSBob Badour #define TYPE_ENUM 0x3
137*418b791dSBob Badour #define TYPE_STRING 0x4
138*418b791dSBob Badour #define TYPE_WSTRING 0x5
139*418b791dSBob Badour #define TYPE_STRUCTURE 0x6
140*418b791dSBob Badour #define TYPE_UNION 0x7
141*418b791dSBob Badour #define TYPE_ARRAY 0x8
142*418b791dSBob Badour #define TYPE_SEQUENCE 0x9
143*418b791dSBob Badour
144*418b791dSBob Badour //these require the pack/unpack to recurse
145*418b791dSBob Badour //so it's a hint to those languages that can optimize in cases where
146*418b791dSBob Badour //recursion isn't necessary.
147*418b791dSBob Badour #define TYPE_COMPLEX_STRUCTURE (0x10 | TYPE_STRUCTURE)
148*418b791dSBob Badour #define TYPE_COMPLEX_UNION (0x10 | TYPE_UNION)
149*418b791dSBob Badour #define TYPE_COMPLEX_ARRAY (0x10 | TYPE_ARRAY)
150*418b791dSBob Badour #define TYPE_COMPLEX_SEQUENCE (0x10 | TYPE_SEQUENCE)
151*418b791dSBob Badour
152*418b791dSBob Badour
153*418b791dSBob Badour typedef struct Type Type;
154*418b791dSBob Badour
155*418b791dSBob Badour #define INHERIT_TYPE\
156*418b791dSBob Badour int32_t nativeSize; /*in the simple case its the same as wire size and alignment*/\
157*418b791dSBob Badour union {\
158*418b791dSBob Badour struct {\
159*418b791dSBob Badour const uintptr_t p1;\
160*418b791dSBob Badour const uintptr_t p2;\
161*418b791dSBob Badour } _cast;\
162*418b791dSBob Badour struct {\
163*418b791dSBob Badour uint32_t iid;\
164*418b791dSBob Badour uint32_t bNotNil;\
165*418b791dSBob Badour } object;\
166*418b791dSBob Badour struct {\
167*418b791dSBob Badour const Type *arrayType;\
168*418b791dSBob Badour int32_t nItems;\
169*418b791dSBob Badour } array;\
170*418b791dSBob Badour struct {\
171*418b791dSBob Badour const Type *seqType;\
172*418b791dSBob Badour int32_t nMaxLen;\
173*418b791dSBob Badour } seqSimple; \
174*418b791dSBob Badour struct {\
175*418b791dSBob Badour uint32_t bFloating;\
176*418b791dSBob Badour uint32_t bSigned;\
177*418b791dSBob Badour } prim; \
178*418b791dSBob Badour const SequenceType* seqComplex;\
179*418b791dSBob Badour const UnionType *unionType;\
180*418b791dSBob Badour const StructType *structType;\
181*418b791dSBob Badour int32_t stringMaxLen;\
182*418b791dSBob Badour uint8_t bInterfaceNotNil;\
183*418b791dSBob Badour } param;\
184*418b791dSBob Badour uint8_t type;\
185*418b791dSBob Badour uint8_t nativeAlignment\
186*418b791dSBob Badour
187*418b791dSBob Badour typedef struct UnionType UnionType;
188*418b791dSBob Badour typedef struct StructType StructType;
189*418b791dSBob Badour typedef struct SequenceType SequenceType;
190*418b791dSBob Badour struct Type {
191*418b791dSBob Badour INHERIT_TYPE;
192*418b791dSBob Badour };
193*418b791dSBob Badour
194*418b791dSBob Badour struct SequenceType {
195*418b791dSBob Badour const Type * seqType;
196*418b791dSBob Badour uint32_t nMaxLen;
197*418b791dSBob Badour uint32_t inSize;
198*418b791dSBob Badour uint32_t routSizePrimIn;
199*418b791dSBob Badour uint32_t routSizePrimROut;
200*418b791dSBob Badour };
201*418b791dSBob Badour
202*418b791dSBob Badour //byte offset from the start of the case values for
203*418b791dSBob Badour //this unions case value array. it MUST be aligned
204*418b791dSBob Badour //at the alignment requrements for the descriptor
205*418b791dSBob Badour //
206*418b791dSBob Badour //if negative it means that the unions cases are
207*418b791dSBob Badour //simple enumerators, so the value read from the descriptor
208*418b791dSBob Badour //can be used directly to find the correct case
209*418b791dSBob Badour typedef union CaseValuePtr CaseValuePtr;
210*418b791dSBob Badour union CaseValuePtr {
211*418b791dSBob Badour const uint8_t* value8s;
212*418b791dSBob Badour const uint16_t* value16s;
213*418b791dSBob Badour const uint32_t* value32s;
214*418b791dSBob Badour const uint64_t* value64s;
215*418b791dSBob Badour };
216*418b791dSBob Badour
217*418b791dSBob Badour //these are only used in complex cases
218*418b791dSBob Badour //so I pulled them out of the type definition as references to make
219*418b791dSBob Badour //the type smaller
220*418b791dSBob Badour struct UnionType {
221*418b791dSBob Badour const Type *descriptor;
222*418b791dSBob Badour uint32_t nCases;
223*418b791dSBob Badour const CaseValuePtr caseValues;
224*418b791dSBob Badour const Type * const *cases;
225*418b791dSBob Badour int32_t inSize;
226*418b791dSBob Badour int32_t routSizePrimIn;
227*418b791dSBob Badour int32_t routSizePrimROut;
228*418b791dSBob Badour uint8_t inAlignment;
229*418b791dSBob Badour uint8_t routAlignmentPrimIn;
230*418b791dSBob Badour uint8_t routAlignmentPrimROut;
231*418b791dSBob Badour uint8_t inCaseAlignment;
232*418b791dSBob Badour uint8_t routCaseAlignmentPrimIn;
233*418b791dSBob Badour uint8_t routCaseAlignmentPrimROut;
234*418b791dSBob Badour uint8_t nativeCaseAlignment;
235*418b791dSBob Badour uint8_t bDefaultCase;
236*418b791dSBob Badour };
237*418b791dSBob Badour
238*418b791dSBob Badour struct StructType {
239*418b791dSBob Badour uint32_t nMembers;
240*418b791dSBob Badour const Type * const *members;
241*418b791dSBob Badour int32_t inSize;
242*418b791dSBob Badour int32_t routSizePrimIn;
243*418b791dSBob Badour int32_t routSizePrimROut;
244*418b791dSBob Badour uint8_t inAlignment;
245*418b791dSBob Badour uint8_t routAlignmentPrimIn;
246*418b791dSBob Badour uint8_t routAlignmentPrimROut;
247*418b791dSBob Badour };
248*418b791dSBob Badour
249*418b791dSBob Badour typedef struct Parameter Parameter;
250*418b791dSBob Badour struct Parameter {
251*418b791dSBob Badour INHERIT_TYPE;
252*418b791dSBob Badour uint8_t mode;
253*418b791dSBob Badour uint8_t bNotNil;
254*418b791dSBob Badour };
255*418b791dSBob Badour
256*418b791dSBob Badour #define SLIM_SCALARS_IS_DYNAMIC(u) (((u) & 0x00ffffff) == 0x00ffffff)
257*418b791dSBob Badour
258*418b791dSBob Badour typedef struct Method Method;
259*418b791dSBob Badour struct Method {
260*418b791dSBob Badour uint32_t uScalars; //no method index
261*418b791dSBob Badour int32_t primInSize;
262*418b791dSBob Badour int32_t primROutSize;
263*418b791dSBob Badour int maxArgs;
264*418b791dSBob Badour int numParams;
265*418b791dSBob Badour const Parameter * const *params;
266*418b791dSBob Badour uint8_t primInAlignment;
267*418b791dSBob Badour uint8_t primROutAlignment;
268*418b791dSBob Badour };
269*418b791dSBob Badour
270*418b791dSBob Badour typedef struct Interface Interface;
271*418b791dSBob Badour
272*418b791dSBob Badour struct Interface {
273*418b791dSBob Badour int nMethods;
274*418b791dSBob Badour const Method * const *methodArray;
275*418b791dSBob Badour int nIIds;
276*418b791dSBob Badour const uint32_t *iids;
277*418b791dSBob Badour const uint16_t* methodStringArray;
278*418b791dSBob Badour const uint16_t* methodStrings;
279*418b791dSBob Badour const char* strings;
280*418b791dSBob Badour };
281*418b791dSBob Badour
282*418b791dSBob Badour
283*418b791dSBob Badour #endif //SLIM_H
284*418b791dSBob Badour
285*418b791dSBob Badour
286*418b791dSBob Badour #ifndef _APPS_REMOTECTL_SLIM_H
287*418b791dSBob Badour #define _APPS_REMOTECTL_SLIM_H
288*418b791dSBob Badour #include "remote.h"
289*418b791dSBob Badour #include <stdint.h>
290*418b791dSBob Badour
291*418b791dSBob Badour #ifndef __QAIC_SLIM
292*418b791dSBob Badour #define __QAIC_SLIM(ff) ff
293*418b791dSBob Badour #endif
294*418b791dSBob Badour #ifndef __QAIC_SLIM_EXPORT
295*418b791dSBob Badour #define __QAIC_SLIM_EXPORT
296*418b791dSBob Badour #endif
297*418b791dSBob Badour
298*418b791dSBob Badour static const Type types[1];
299*418b791dSBob Badour static const Type types[1] = {{0x1,{{(const uintptr_t)0,(const uintptr_t)0}}, 2,0x1}};
300*418b791dSBob Badour static const Parameter parameters[4] = {{0x8,{{(const uintptr_t)0x0,0}}, 4,0x4,0,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,3,0},{0x8,{{(const uintptr_t)&(types[0]),(const uintptr_t)0x0}}, 9,0x4,3,0},{0x4,{{(const uintptr_t)0,(const uintptr_t)1}}, 2,0x4,0,0}};
301*418b791dSBob Badour static const Parameter* const parameterArrays[7] = {(&(parameters[0])),(&(parameters[1])),(&(parameters[2])),(&(parameters[1])),(&(parameters[3])),(&(parameters[2])),(&(parameters[1]))};
302*418b791dSBob Badour static const Method methods[2] = {{REMOTE_SCALARS_MAKEX(0,0,0x2,0x2,0x0,0x0),0x8,0x8,6,4,(&(parameterArrays[0])),0x4,0x4},{REMOTE_SCALARS_MAKEX(0,0,0x1,0x2,0x0,0x0),0x8,0x4,5,3,(&(parameterArrays[4])),0x4,0x4}};
303*418b791dSBob Badour static const Method* const methodArrays[2] = {&(methods[0]),&(methods[1])};
304*418b791dSBob Badour static const char strings[36] = "dlerror\0handle\0close\0nErr\0name\0open\0";
305*418b791dSBob Badour static const uint16_t methodStrings[9] = {31,26,8,0,21,15,8,0,21};
306*418b791dSBob Badour static const uint16_t methodStringsArrays[2] = {0,5};
307*418b791dSBob Badour __QAIC_SLIM_EXPORT const Interface __QAIC_SLIM(apps_remotectl_slim) = {2,&(methodArrays[0]),0,0,&(methodStringsArrays [0]),methodStrings,strings};
308*418b791dSBob Badour #endif //_APPS_REMOTECTL_SLIM_H
309*418b791dSBob Badour #ifdef __GNUC__
310*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wpragmas"
311*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wuninitialized"
312*418b791dSBob Badour #pragma GCC diagnostic ignored "-Wunused-parameter"
313*418b791dSBob Badour #endif
314*418b791dSBob Badour
315*418b791dSBob Badour #ifndef __QAIC_REMOTE
316*418b791dSBob Badour #define __QAIC_REMOTE(ff) ff
317*418b791dSBob Badour #endif //__QAIC_REMOTE
318*418b791dSBob Badour
319*418b791dSBob Badour #ifndef __QAIC_HEADER
320*418b791dSBob Badour #define __QAIC_HEADER(ff) ff
321*418b791dSBob Badour #endif //__QAIC_HEADER
322*418b791dSBob Badour
323*418b791dSBob Badour #ifndef __QAIC_HEADER_EXPORT
324*418b791dSBob Badour #define __QAIC_HEADER_EXPORT
325*418b791dSBob Badour #endif // __QAIC_HEADER_EXPORT
326*418b791dSBob Badour
327*418b791dSBob Badour #ifndef __QAIC_HEADER_ATTRIBUTE
328*418b791dSBob Badour #define __QAIC_HEADER_ATTRIBUTE
329*418b791dSBob Badour #endif // __QAIC_HEADER_ATTRIBUTE
330*418b791dSBob Badour
331*418b791dSBob Badour #ifndef __QAIC_IMPL
332*418b791dSBob Badour #define __QAIC_IMPL(ff) ff
333*418b791dSBob Badour #endif //__QAIC_IMPL
334*418b791dSBob Badour
335*418b791dSBob Badour #ifndef __QAIC_IMPL_EXPORT
336*418b791dSBob Badour #define __QAIC_IMPL_EXPORT
337*418b791dSBob Badour #endif // __QAIC_IMPL_EXPORT
338*418b791dSBob Badour
339*418b791dSBob Badour #ifndef __QAIC_IMPL_ATTRIBUTE
340*418b791dSBob Badour #define __QAIC_IMPL_ATTRIBUTE
341*418b791dSBob Badour #endif // __QAIC_IMPL_ATTRIBUTE
342*418b791dSBob Badour
343*418b791dSBob Badour #ifndef __QAIC_STUB
344*418b791dSBob Badour #define __QAIC_STUB(ff) ff
345*418b791dSBob Badour #endif //__QAIC_STUB
346*418b791dSBob Badour
347*418b791dSBob Badour #ifndef __QAIC_STUB_EXPORT
348*418b791dSBob Badour #define __QAIC_STUB_EXPORT
349*418b791dSBob Badour #endif // __QAIC_STUB_EXPORT
350*418b791dSBob Badour
351*418b791dSBob Badour #ifndef __QAIC_STUB_ATTRIBUTE
352*418b791dSBob Badour #define __QAIC_STUB_ATTRIBUTE
353*418b791dSBob Badour #endif // __QAIC_STUB_ATTRIBUTE
354*418b791dSBob Badour
355*418b791dSBob Badour #ifndef __QAIC_SKEL
356*418b791dSBob Badour #define __QAIC_SKEL(ff) ff
357*418b791dSBob Badour #endif //__QAIC_SKEL__
358*418b791dSBob Badour
359*418b791dSBob Badour #ifndef __QAIC_SKEL_EXPORT
360*418b791dSBob Badour #define __QAIC_SKEL_EXPORT
361*418b791dSBob Badour #endif // __QAIC_SKEL_EXPORT
362*418b791dSBob Badour
363*418b791dSBob Badour #ifndef __QAIC_SKEL_ATTRIBUTE
364*418b791dSBob Badour #define __QAIC_SKEL_ATTRIBUTE
365*418b791dSBob Badour #endif // __QAIC_SKEL_ATTRIBUTE
366*418b791dSBob Badour
367*418b791dSBob Badour #ifdef __QAIC_DEBUG__
368*418b791dSBob Badour #ifndef __QAIC_DBG_PRINTF__
369*418b791dSBob Badour #define __QAIC_DBG_PRINTF__( ee ) do { printf ee ; } while(0)
370*418b791dSBob Badour #endif
371*418b791dSBob Badour #else
372*418b791dSBob Badour #define __QAIC_DBG_PRINTF__( ee ) (void)0
373*418b791dSBob Badour #endif
374*418b791dSBob Badour
375*418b791dSBob Badour
376*418b791dSBob Badour #define _OFFSET(src, sof) ((void*)(((char*)(src)) + (sof)))
377*418b791dSBob Badour
378*418b791dSBob Badour #define _COPY(dst, dof, src, sof, sz) \
379*418b791dSBob Badour do {\
380*418b791dSBob Badour struct __copy { \
381*418b791dSBob Badour char ar[sz]; \
382*418b791dSBob Badour };\
383*418b791dSBob Badour *(struct __copy*)_OFFSET(dst, dof) = *(struct __copy*)_OFFSET(src, sof);\
384*418b791dSBob Badour } while (0)
385*418b791dSBob Badour
386*418b791dSBob Badour #define _ASSIGN(dst, src, sof) \
387*418b791dSBob Badour do {\
388*418b791dSBob Badour dst = OFFSET(src, sof); \
389*418b791dSBob Badour } while (0)
390*418b791dSBob Badour
391*418b791dSBob Badour #define _STD_STRLEN_IF(str) (str == 0 ? 0 : strlen(str))
392*418b791dSBob Badour
393*418b791dSBob Badour #include "AEEStdErr.h"
394*418b791dSBob Badour
395*418b791dSBob Badour #define _TRY(ee, func) \
396*418b791dSBob Badour do { \
397*418b791dSBob Badour if (AEE_SUCCESS != ((ee) = func)) {\
398*418b791dSBob Badour __QAIC_DBG_PRINTF__((__FILE_LINE__ ": error: %d\n", (int)(ee)));\
399*418b791dSBob Badour goto ee##bail;\
400*418b791dSBob Badour } \
401*418b791dSBob Badour } while (0)
402*418b791dSBob Badour
403*418b791dSBob Badour #define _CATCH(exception) exception##bail: if (exception != AEE_SUCCESS)
404*418b791dSBob Badour
405*418b791dSBob Badour #define _ASSERT(nErr, ff) _TRY(nErr, 0 == (ff) ? AEE_EBADPARM : AEE_SUCCESS)
406*418b791dSBob Badour
407*418b791dSBob Badour #ifdef __QAIC_DEBUG__
408*418b791dSBob Badour #define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, allocator_alloc(pal, __FILE_LINE__, size, alignment, (void**)&pv))
409*418b791dSBob Badour #else
410*418b791dSBob Badour #define _ALLOCATE(nErr, pal, size, alignment, pv) _TRY(nErr, allocator_alloc(pal, 0, size, alignment, (void**)&pv))
411*418b791dSBob Badour #endif
412*418b791dSBob Badour
413*418b791dSBob Badour
414*418b791dSBob Badour #ifdef __cplusplus
415*418b791dSBob Badour extern "C" {
416*418b791dSBob Badour #endif
_skel_method(int (* _pfn)(uint32_t,char *,uint32_t,uint32_t *),uint32_t _sc,remote_arg * _pra)417*418b791dSBob Badour static __inline int _skel_method(int (*_pfn)(uint32_t, char*, uint32_t, uint32_t*), uint32_t _sc, remote_arg* _pra) {
418*418b791dSBob Badour remote_arg* _praEnd;
419*418b791dSBob Badour uint32_t _in0[1];
420*418b791dSBob Badour char* _rout1[1];
421*418b791dSBob Badour uint32_t _rout1Len[1];
422*418b791dSBob Badour uint32_t _rout2[1];
423*418b791dSBob Badour uint32_t* _primIn;
424*418b791dSBob Badour int _numIn[1];
425*418b791dSBob Badour uint32_t* _primROut;
426*418b791dSBob Badour remote_arg* _praIn;
427*418b791dSBob Badour remote_arg* _praROut;
428*418b791dSBob Badour int _nErr = 0;
429*418b791dSBob Badour _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc));
430*418b791dSBob Badour _ASSERT(_nErr, (_pra + 3) <= _praEnd);
431*418b791dSBob Badour _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1);
432*418b791dSBob Badour _ASSERT(_nErr, _pra[0].buf.nLen >= 8);
433*418b791dSBob Badour _primIn = _pra[0].buf.pv;
434*418b791dSBob Badour _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 4);
435*418b791dSBob Badour _primROut = _pra[(_numIn[0] + 1)].buf.pv;
436*418b791dSBob Badour _COPY(_in0, 0, _primIn, 0, 4);
437*418b791dSBob Badour _COPY(_rout1Len, 0, _primIn, 4, 4);
438*418b791dSBob Badour _praIn = (_pra + 1);
439*418b791dSBob Badour _praROut = (_praIn + _numIn[0] + 1);
440*418b791dSBob Badour _ASSERT(_nErr, (int)((_praROut[0].buf.nLen / 1)) >= (int)(_rout1Len[0]));
441*418b791dSBob Badour _rout1[0] = _praROut[0].buf.pv;
442*418b791dSBob Badour _TRY(_nErr, _pfn(*_in0, *_rout1, *_rout1Len, _rout2));
443*418b791dSBob Badour _COPY(_primROut, 0, _rout2, 0, 4);
444*418b791dSBob Badour _CATCH(_nErr) {}
445*418b791dSBob Badour return _nErr;
446*418b791dSBob Badour }
_skel_method_1(int (* _pfn)(char *,uint32_t *,char *,uint32_t,uint32_t *),uint32_t _sc,remote_arg * _pra)447*418b791dSBob Badour static __inline int _skel_method_1(int (*_pfn)(char*, uint32_t*, char*, uint32_t, uint32_t*), uint32_t _sc, remote_arg* _pra) {
448*418b791dSBob Badour remote_arg* _praEnd;
449*418b791dSBob Badour char* _in0[1];
450*418b791dSBob Badour uint32_t _in0Len[1];
451*418b791dSBob Badour uint32_t _rout1[1];
452*418b791dSBob Badour char* _rout2[1];
453*418b791dSBob Badour uint32_t _rout2Len[1];
454*418b791dSBob Badour uint32_t _rout3[1];
455*418b791dSBob Badour uint32_t* _primIn;
456*418b791dSBob Badour int _numIn[1];
457*418b791dSBob Badour uint32_t* _primROut;
458*418b791dSBob Badour remote_arg* _praIn;
459*418b791dSBob Badour remote_arg* _praROut;
460*418b791dSBob Badour int _nErr = 0;
461*418b791dSBob Badour _praEnd = ((_pra + REMOTE_SCALARS_INBUFS(_sc)) + REMOTE_SCALARS_OUTBUFS(_sc));
462*418b791dSBob Badour _ASSERT(_nErr, (_pra + 4) <= _praEnd);
463*418b791dSBob Badour _numIn[0] = (REMOTE_SCALARS_INBUFS(_sc) - 1);
464*418b791dSBob Badour _ASSERT(_nErr, _pra[0].buf.nLen >= 8);
465*418b791dSBob Badour _primIn = _pra[0].buf.pv;
466*418b791dSBob Badour _ASSERT(_nErr, _pra[(_numIn[0] + 1)].buf.nLen >= 8);
467*418b791dSBob Badour _primROut = _pra[(_numIn[0] + 1)].buf.pv;
468*418b791dSBob Badour _COPY(_in0Len, 0, _primIn, 0, 4);
469*418b791dSBob Badour _praIn = (_pra + 1);
470*418b791dSBob Badour _ASSERT(_nErr, (int)((_praIn[0].buf.nLen / 1)) >= (int)(_in0Len[0]));
471*418b791dSBob Badour _in0[0] = _praIn[0].buf.pv;
472*418b791dSBob Badour if(_in0Len[0] > 0)
473*418b791dSBob Badour {
474*418b791dSBob Badour _in0[0][(_in0Len[0] - 1)] = 0;
475*418b791dSBob Badour }
476*418b791dSBob Badour _COPY(_rout2Len, 0, _primIn, 4, 4);
477*418b791dSBob Badour _praROut = (_praIn + _numIn[0] + 1);
478*418b791dSBob Badour _ASSERT(_nErr, (int)((_praROut[0].buf.nLen / 1)) >= (int)(_rout2Len[0]));
479*418b791dSBob Badour _rout2[0] = _praROut[0].buf.pv;
480*418b791dSBob Badour _TRY(_nErr, _pfn(*_in0, _rout1, *_rout2, *_rout2Len, _rout3));
481*418b791dSBob Badour _COPY(_primROut, 0, _rout1, 0, 4);
482*418b791dSBob Badour _COPY(_primROut, 4, _rout3, 0, 4);
483*418b791dSBob Badour _CATCH(_nErr) {}
484*418b791dSBob Badour return _nErr;
485*418b791dSBob Badour }
__QAIC_SKEL(apps_remotectl_skel_invoke)486*418b791dSBob Badour __QAIC_SKEL_EXPORT int __QAIC_SKEL(apps_remotectl_skel_invoke)(uint32_t _sc, remote_arg* _pra) __QAIC_SKEL_ATTRIBUTE {
487*418b791dSBob Badour switch(REMOTE_SCALARS_METHOD(_sc))
488*418b791dSBob Badour {
489*418b791dSBob Badour case 0:
490*418b791dSBob Badour return _skel_method_1((void*)__QAIC_IMPL(apps_remotectl_open), _sc, _pra);
491*418b791dSBob Badour case 1:
492*418b791dSBob Badour return _skel_method((void*)__QAIC_IMPL(apps_remotectl_close), _sc, _pra);
493*418b791dSBob Badour }
494*418b791dSBob Badour return AEE_EUNSUPPORTED;
495*418b791dSBob Badour }
496*418b791dSBob Badour #ifdef __cplusplus
497*418b791dSBob Badour }
498*418b791dSBob Badour #endif
499*418b791dSBob Badour #endif //_APPS_REMOTECTL_SKEL_H
500