1*61dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*61dff127SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*61dff127SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*61dff127SAndrew Rist * distributed with this work for additional information
6*61dff127SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*61dff127SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*61dff127SAndrew Rist * "License"); you may not use this file except in compliance
9*61dff127SAndrew Rist * with the License. You may obtain a copy of the License at
10*61dff127SAndrew Rist *
11*61dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*61dff127SAndrew Rist *
13*61dff127SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*61dff127SAndrew Rist * software distributed under the License is distributed on an
15*61dff127SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*61dff127SAndrew Rist * KIND, either express or implied. See the License for the
17*61dff127SAndrew Rist * specific language governing permissions and limitations
18*61dff127SAndrew Rist * under the License.
19*61dff127SAndrew Rist *
20*61dff127SAndrew Rist *************************************************************/
21*61dff127SAndrew Rist
22*61dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir #include <malloc.h>
27cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
28cdf0e10cSrcweir #include <uno/data.h>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
31cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
32cdf0e10cSrcweir #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
33cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtables.hxx"
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include "share.hxx"
36cdf0e10cSrcweir
37cdf0e10cSrcweir #include <sal/alloca.h>
38cdf0e10cSrcweir
39cdf0e10cSrcweir using namespace rtl;
40cdf0e10cSrcweir using namespace com::sun::star::uno;
41cdf0e10cSrcweir
42cdf0e10cSrcweir namespace
43cdf0e10cSrcweir {
44cdf0e10cSrcweir //==================================================================================================
45cdf0e10cSrcweir // The call instruction within the asm section of callVirtualMethod may throw
46cdf0e10cSrcweir // exceptions. So that the compiler handles this correctly, it is important
47cdf0e10cSrcweir // that (a) callVirtualMethod might call dummy_can_throw_anything (although this
48cdf0e10cSrcweir // never happens at runtime), which in turn can throw exceptions, and (b)
49cdf0e10cSrcweir // callVirtualMethod is not inlined at its call site (so that any exceptions are
50cdf0e10cSrcweir // caught which are thrown from the instruction calling callVirtualMethod):
51cdf0e10cSrcweir
52cdf0e10cSrcweir void callVirtualMethod( void * pAdjustedThisPtr,
53cdf0e10cSrcweir sal_Int32 nVtableIndex,
54cdf0e10cSrcweir void * pRegisterReturn,
55cdf0e10cSrcweir typelib_TypeClass eReturnType,
56cdf0e10cSrcweir sal_Int32 * pStackLongs,
57cdf0e10cSrcweir sal_Int32 nStackLongs ) __attribute__((noinline));
58cdf0e10cSrcweir
callVirtualMethod(void * pAdjustedThisPtr,sal_Int32 nVtableIndex,void * pRegisterReturn,typelib_TypeClass eReturnType,sal_Int32 * pStackLongs,sal_Int32 nStackLongs)59cdf0e10cSrcweir void callVirtualMethod( void * pAdjustedThisPtr,
60cdf0e10cSrcweir sal_Int32 nVtableIndex,
61cdf0e10cSrcweir void * pRegisterReturn,
62cdf0e10cSrcweir typelib_TypeClass eReturnType,
63cdf0e10cSrcweir sal_Int32 * pStackLongs,
64cdf0e10cSrcweir sal_Int32 nStackLongs )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir // parameter list is mixed list of * and values
67cdf0e10cSrcweir // reference parameters are pointers
68cdf0e10cSrcweir
69cdf0e10cSrcweir OSL_ENSURE( pStackLongs && pAdjustedThisPtr, "### null ptr!" );
70cdf0e10cSrcweir OSL_ENSURE( (sizeof(void *) == 4) &&
71cdf0e10cSrcweir (sizeof(sal_Int32) == 4), "### unexpected size of int!" );
72cdf0e10cSrcweir OSL_ENSURE( nStackLongs && pStackLongs, "### no stack in callVirtualMethod !" );
73cdf0e10cSrcweir
74cdf0e10cSrcweir // never called
75cdf0e10cSrcweir if (! pAdjustedThisPtr) CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
76cdf0e10cSrcweir
77cdf0e10cSrcweir volatile long o0 = 0, o1 = 0; // for register returns
78cdf0e10cSrcweir volatile double f0d = 0;
79cdf0e10cSrcweir volatile float f0f = 0;
80cdf0e10cSrcweir volatile long long saveReg[7];
81cdf0e10cSrcweir
82cdf0e10cSrcweir __asm__ (
83cdf0e10cSrcweir // save registers
84cdf0e10cSrcweir "std %%l0, [%4]\n\t"
85cdf0e10cSrcweir "mov %4, %%l0\n\t"
86cdf0e10cSrcweir "mov %%l0, %%l1\n\t"
87cdf0e10cSrcweir "add %%l0, 8, %%l0\n\t"
88cdf0e10cSrcweir "std %%l2, [%%l0]\n\t"
89cdf0e10cSrcweir "add %%l0, 8, %%l0\n\t"
90cdf0e10cSrcweir "std %%l4, [%%l0]\n\t"
91cdf0e10cSrcweir "add %%l0, 8, %%l0\n\t"
92cdf0e10cSrcweir "std %%o0, [%%l0]\n\t"
93cdf0e10cSrcweir "add %%l0, 8, %%l0\n\t"
94cdf0e10cSrcweir "std %%o2, [%%l0]\n\t"
95cdf0e10cSrcweir "add %%l0, 8, %%l0\n\t"
96cdf0e10cSrcweir "std %%o4, [%%l0]\n\t"
97cdf0e10cSrcweir "add %%l0, 8, %%l0\n\t"
98cdf0e10cSrcweir "std %%l6, [%%l0]\n\t"
99cdf0e10cSrcweir "mov %%l1, %%l7\n\t"
100cdf0e10cSrcweir
101cdf0e10cSrcweir // increase our own stackframe if necessary
102cdf0e10cSrcweir "mov %%sp, %%l3\n\t" // save stack ptr for readjustment
103cdf0e10cSrcweir
104cdf0e10cSrcweir "subcc %%i5, 7, %%l0\n\t"
105cdf0e10cSrcweir "ble .LmoveOn\n\t"
106cdf0e10cSrcweir "nop\n\t"
107cdf0e10cSrcweir
108cdf0e10cSrcweir "sll %%l0, 2, %%l0\n\t"
109cdf0e10cSrcweir "add %%l0, 96, %%l0\n\t"
110cdf0e10cSrcweir "mov %%sp, %%l1\n\t" // old stack ptr
111cdf0e10cSrcweir "sub %%sp, %%l0, %%l0\n\t" // future stack ptr
112cdf0e10cSrcweir "andcc %%l0, 7, %%g0\n\t" // align stack to 8
113cdf0e10cSrcweir "be .LisAligned\n\t"
114cdf0e10cSrcweir "nop\n\t"
115cdf0e10cSrcweir "sub %%l0, 4, %%l0\n"
116cdf0e10cSrcweir ".LisAligned:\n\t"
117cdf0e10cSrcweir "mov %%l0, %%o5\n\t" // save newly computed stack ptr
118cdf0e10cSrcweir "add %%g0, 16, %%o4\n"
119cdf0e10cSrcweir
120cdf0e10cSrcweir // now copy longs down to save register window
121cdf0e10cSrcweir // and local variables
122cdf0e10cSrcweir ".LcopyDown:\n\t"
123cdf0e10cSrcweir "ld [%%l1], %%l2\n\t"
124cdf0e10cSrcweir "st %%l2,[%%l0]\n\t"
125cdf0e10cSrcweir "add %%l0, 4, %%l0\n\t"
126cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
127cdf0e10cSrcweir "subcc %%o4, 1, %%o4\n\t"
128cdf0e10cSrcweir "bne .LcopyDown\n\t"
129cdf0e10cSrcweir
130cdf0e10cSrcweir "mov %%o5, %%sp\n\t" // move new stack ptr (hopefully) atomically
131cdf0e10cSrcweir // while register window is valid in both spaces
132cdf0e10cSrcweir // (scheduling might hit in copyDown loop)
133cdf0e10cSrcweir
134cdf0e10cSrcweir "sub %%i5, 7, %%l0\n\t" // copy parameters past the sixth to stack
135cdf0e10cSrcweir "add %%i4, 28, %%l1\n\t"
136cdf0e10cSrcweir "add %%sp, 92, %%l2\n"
137cdf0e10cSrcweir ".LcopyLong:\n\t"
138cdf0e10cSrcweir "ld [%%l1], %%o0\n\t"
139cdf0e10cSrcweir "st %%o0, [%%l2]\n\t"
140cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
141cdf0e10cSrcweir "add %%l2, 4, %%l2\n\t"
142cdf0e10cSrcweir "subcc %%l0, 1, %%l0\n\t"
143cdf0e10cSrcweir "bne .LcopyLong\n\t"
144cdf0e10cSrcweir "nop\n"
145cdf0e10cSrcweir
146cdf0e10cSrcweir ".LmoveOn:\n\t"
147cdf0e10cSrcweir "mov %%i5, %%l0\n\t" // prepare out registers
148cdf0e10cSrcweir "mov %%i4, %%l1\n\t"
149cdf0e10cSrcweir
150cdf0e10cSrcweir "ld [%%l1], %%o0\n\t" // prepare complex return ptr
151cdf0e10cSrcweir "st %%o0, [%%sp+64]\n\t"
152cdf0e10cSrcweir "sub %%l0, 1, %%l0\n\t"
153cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
154cdf0e10cSrcweir
155cdf0e10cSrcweir "ld [%%l1], %%o0\n\t"
156cdf0e10cSrcweir "subcc %%l0, 1, %%l0\n\t"
157cdf0e10cSrcweir "be .LdoCall\n\t"
158cdf0e10cSrcweir "nop\n\t"
159cdf0e10cSrcweir
160cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
161cdf0e10cSrcweir "ld [%%l1], %%o1\n\t"
162cdf0e10cSrcweir "subcc %%l0, 1, %%l0\n\t"
163cdf0e10cSrcweir "be .LdoCall\n\t"
164cdf0e10cSrcweir "nop\n\t"
165cdf0e10cSrcweir
166cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
167cdf0e10cSrcweir "ld [%%l1], %%o2\n\t"
168cdf0e10cSrcweir "subcc %%l0, 1, %%l0\n\t"
169cdf0e10cSrcweir "be .LdoCall\n\t"
170cdf0e10cSrcweir "nop\n\t"
171cdf0e10cSrcweir
172cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
173cdf0e10cSrcweir "ld [%%l1], %%o3\n\t"
174cdf0e10cSrcweir "subcc %%l0, 1, %%l0\n\t"
175cdf0e10cSrcweir "be .LdoCall\n\t"
176cdf0e10cSrcweir "nop\n\t"
177cdf0e10cSrcweir
178cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
179cdf0e10cSrcweir "ld [%%l1], %%o4\n\t"
180cdf0e10cSrcweir "subcc %%l0, 1, %%l0\n\t"
181cdf0e10cSrcweir "be .LdoCall\n\t"
182cdf0e10cSrcweir "nop\n\t"
183cdf0e10cSrcweir
184cdf0e10cSrcweir "add %%l1, 4, %%l1\n\t"
185cdf0e10cSrcweir "ld [%%l1], %%o5\n"
186cdf0e10cSrcweir
187cdf0e10cSrcweir ".LdoCall:\n\t"
188cdf0e10cSrcweir "ld [%%i0], %%l0\n\t" // get vtable ptr
189cdf0e10cSrcweir
190cdf0e10cSrcweir "sll %%i1, 2, %%l6\n\t"
191cdf0e10cSrcweir // "add %%l6, 8, %%l6\n\t"
192cdf0e10cSrcweir "add %%l6, %%l0, %%l0\n\t"
193cdf0e10cSrcweir // // vtable has 8byte wide entries,
194cdf0e10cSrcweir // // upper half contains 2 half words, of which the first
195cdf0e10cSrcweir // // is the this ptr patch !
196cdf0e10cSrcweir // // first entry is (or __tf)
197cdf0e10cSrcweir
198cdf0e10cSrcweir // "ldsh [%%l0], %%l6\n\t" // load this ptr patch
199cdf0e10cSrcweir // "add %%l6, %%o0, %%o0\n\t" // patch this ptr
200cdf0e10cSrcweir
201cdf0e10cSrcweir // "add %%l0, 4, %%l0\n\t" // get virtual function ptr
202cdf0e10cSrcweir "ld [%%l0], %%l0\n\t"
203cdf0e10cSrcweir
204cdf0e10cSrcweir "ld [%%i4], %%l2\n\t"
205cdf0e10cSrcweir "subcc %%l2, %%g0, %%l2\n\t"
206cdf0e10cSrcweir "bne .LcomplexCall\n\t"
207cdf0e10cSrcweir "nop\n\t"
208cdf0e10cSrcweir "call %%l0\n\t"
209cdf0e10cSrcweir "nop\n\t"
210cdf0e10cSrcweir "ba .LcallReturned\n\t"
211cdf0e10cSrcweir "nop\n"
212cdf0e10cSrcweir ".LcomplexCall:\n\t"
213cdf0e10cSrcweir "call %%l0\n\t"
214cdf0e10cSrcweir "nop\n\t"
215cdf0e10cSrcweir "unimp\n"
216cdf0e10cSrcweir
217cdf0e10cSrcweir ".LcallReturned:\n\t"
218cdf0e10cSrcweir "mov %%l3, %%sp\n\t" // readjust stack so that our locals are where they belong
219cdf0e10cSrcweir "st %%o0, %0\n\t" // save possible return registers into our locals
220cdf0e10cSrcweir "st %%o1, %1\n\t"
221cdf0e10cSrcweir "std %%f0, %2\n\t"
222cdf0e10cSrcweir "st %%f0, %3\n\t"
223cdf0e10cSrcweir
224cdf0e10cSrcweir // restore registers
225cdf0e10cSrcweir "ldd [%%l7], %%l0\n\t"
226cdf0e10cSrcweir "add %%l7, 8, %%l7\n\t"
227cdf0e10cSrcweir "ldd [%%l7], %%l2\n\t"
228cdf0e10cSrcweir "add %%l7, 8, %%l7\n\t"
229cdf0e10cSrcweir "ldd [%%l7], %%l4\n\t"
230cdf0e10cSrcweir "add %%l7, 8, %%l7\n\t"
231cdf0e10cSrcweir "ldd [%%l7], %%o0\n\t"
232cdf0e10cSrcweir "add %%l7, 8, %%l7\n\t"
233cdf0e10cSrcweir "ldd [%%l7], %%o2\n\t"
234cdf0e10cSrcweir "add %%l7, 8, %%l7\n\t"
235cdf0e10cSrcweir "ldd [%%l7], %%o4\n\t"
236cdf0e10cSrcweir "add %%l7, 8, %%l7\n\t"
237cdf0e10cSrcweir "ldd [%%l7], %%l6\n\t"
238cdf0e10cSrcweir : :
239cdf0e10cSrcweir "m"(o0),
240cdf0e10cSrcweir "m"(o1),
241cdf0e10cSrcweir "m"(f0d),
242cdf0e10cSrcweir "m"(f0f),
243cdf0e10cSrcweir "r"(&saveReg[0])
244cdf0e10cSrcweir );
245cdf0e10cSrcweir switch( eReturnType )
246cdf0e10cSrcweir {
247cdf0e10cSrcweir case typelib_TypeClass_HYPER:
248cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
249cdf0e10cSrcweir ((long*)pRegisterReturn)[1] = o1;
250cdf0e10cSrcweir case typelib_TypeClass_LONG:
251cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
252cdf0e10cSrcweir case typelib_TypeClass_ENUM:
253cdf0e10cSrcweir ((long*)pRegisterReturn)[0] = o0;
254cdf0e10cSrcweir break;
255cdf0e10cSrcweir case typelib_TypeClass_CHAR:
256cdf0e10cSrcweir case typelib_TypeClass_SHORT:
257cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
258cdf0e10cSrcweir *(unsigned short*)pRegisterReturn = (unsigned short)o0;
259cdf0e10cSrcweir break;
260cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
261cdf0e10cSrcweir case typelib_TypeClass_BYTE:
262cdf0e10cSrcweir *(unsigned char*)pRegisterReturn = (unsigned char)o0;
263cdf0e10cSrcweir break;
264cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
265cdf0e10cSrcweir *(float*)pRegisterReturn = f0f;
266cdf0e10cSrcweir break;
267cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
268cdf0e10cSrcweir *(double*)pRegisterReturn = f0d;
269cdf0e10cSrcweir break;
270cdf0e10cSrcweir }
271cdf0e10cSrcweir }
272cdf0e10cSrcweir
273cdf0e10cSrcweir //=================================================================================================
cpp_call(bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,bridges::cpp_uno::shared::VtableSlot aVtableSlot,typelib_TypeDescriptionReference * pReturnTypeRef,sal_Int32 nParams,typelib_MethodParameter * pParams,void * pUnoReturn,void * pUnoArgs[],uno_Any ** ppUnoExc)274cdf0e10cSrcweir static void cpp_call(
275cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
276cdf0e10cSrcweir bridges::cpp_uno::shared::VtableSlot aVtableSlot,
277cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef,
278cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams,
279cdf0e10cSrcweir void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
280cdf0e10cSrcweir {
281cdf0e10cSrcweir // max space for: complex ret ptr, this, values|ptr ...
282cdf0e10cSrcweir char * pCppStack =
283cdf0e10cSrcweir (char *)alloca( (nParams+2) * sizeof(sal_Int64) );
284cdf0e10cSrcweir char * pCppStackStart = pCppStack;
285cdf0e10cSrcweir
286cdf0e10cSrcweir // return
287cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
288cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
289cdf0e10cSrcweir OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
290cdf0e10cSrcweir
291cdf0e10cSrcweir void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion
292cdf0e10cSrcweir
293cdf0e10cSrcweir if (pReturnTypeDescr)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
296cdf0e10cSrcweir {
297cdf0e10cSrcweir pCppReturn = pUnoReturn; // direct way for simple types
298cdf0e10cSrcweir *(void**)pCppStack = NULL;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir else
301cdf0e10cSrcweir {
302cdf0e10cSrcweir // complex return via ptr
303cdf0e10cSrcweir pCppReturn = *(void **)pCppStack = (bridges::cpp_uno::shared::relatesToInterfaceType(pReturnTypeDescr )
304cdf0e10cSrcweir ? alloca( pReturnTypeDescr->nSize )
305cdf0e10cSrcweir : pUnoReturn); // direct way
306cdf0e10cSrcweir }
307cdf0e10cSrcweir pCppStack += sizeof(void*);
308cdf0e10cSrcweir }
309cdf0e10cSrcweir // push this
310cdf0e10cSrcweir void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
311cdf0e10cSrcweir + aVtableSlot.offset;
312cdf0e10cSrcweir *(void**)pCppStack = pAdjustedThisPtr;
313cdf0e10cSrcweir pCppStack += sizeof( void* );
314cdf0e10cSrcweir
315cdf0e10cSrcweir // stack space
316cdf0e10cSrcweir OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
317cdf0e10cSrcweir // args
318cdf0e10cSrcweir void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
319cdf0e10cSrcweir // indizes of values this have to be converted (interface conversion cpp<=>uno)
320cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
321cdf0e10cSrcweir // type descriptions for reconversions
322cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
323cdf0e10cSrcweir
324cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
325cdf0e10cSrcweir
326cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
327cdf0e10cSrcweir {
328cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
329cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
330cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
331cdf0e10cSrcweir if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
332cdf0e10cSrcweir {
333cdf0e10cSrcweir pCppArgs[ nPos ] = CPPU_CURRENT_NAMESPACE::adjustPointer(pCppStack, pParamTypeDescr );
334cdf0e10cSrcweir
335cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
336cdf0e10cSrcweir {
337cdf0e10cSrcweir case typelib_TypeClass_HYPER:
338cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
339cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
340cdf0e10cSrcweir OSL_ASSERT( sizeof (double) == sizeof (sal_Int64) );
341cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(pCppStack) =
342cdf0e10cSrcweir *reinterpret_cast< sal_Int32 const * >(pUnoArgs[ nPos ]);
343cdf0e10cSrcweir pCppStack += sizeof (sal_Int32);
344cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(pCppStack) =
345cdf0e10cSrcweir *(reinterpret_cast< sal_Int32 const * >(pUnoArgs[ nPos ] ) + 1);
346cdf0e10cSrcweir break;
347cdf0e10cSrcweir default:
348cdf0e10cSrcweir uno_copyAndConvertData(
349cdf0e10cSrcweir pCppArgs[nPos], pUnoArgs[nPos], pParamTypeDescr,
350cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
351cdf0e10cSrcweir break;
352cdf0e10cSrcweir }
353cdf0e10cSrcweir // no longer needed
354cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
355cdf0e10cSrcweir }
356cdf0e10cSrcweir else // ptr to complex value | ref
357cdf0e10cSrcweir {
358cdf0e10cSrcweir if (! rParam.bIn) // is pure out
359cdf0e10cSrcweir {
360cdf0e10cSrcweir // cpp out is constructed mem, uno out is not!
361cdf0e10cSrcweir uno_constructData(
362cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
363cdf0e10cSrcweir pParamTypeDescr );
364cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
365cdf0e10cSrcweir // will be released at reconversion
366cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
367cdf0e10cSrcweir }
368cdf0e10cSrcweir // is in/inout
369cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType(
370cdf0e10cSrcweir pParamTypeDescr ))
371cdf0e10cSrcweir {
372cdf0e10cSrcweir uno_copyAndConvertData(
373cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
374cdf0e10cSrcweir pUnoArgs[nPos], pParamTypeDescr,
375cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
376cdf0e10cSrcweir
377cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
378cdf0e10cSrcweir // will be released at reconversion
379cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
380cdf0e10cSrcweir }
381cdf0e10cSrcweir else // direct way
382cdf0e10cSrcweir {
383cdf0e10cSrcweir *(void **)pCppStack = pCppArgs[nPos] = pUnoArgs[nPos];
384cdf0e10cSrcweir // no longer needed
385cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
386cdf0e10cSrcweir }
387cdf0e10cSrcweir }
388cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // standard parameter length
389cdf0e10cSrcweir }
390cdf0e10cSrcweir
391cdf0e10cSrcweir try
392cdf0e10cSrcweir {
393cdf0e10cSrcweir int nStackLongs = (pCppStack - pCppStackStart)/sizeof(sal_Int32);
394cdf0e10cSrcweir OSL_ENSURE( !( (pCppStack - pCppStackStart ) & 3), "UNALIGNED STACK !!! (Please DO panic" );
395cdf0e10cSrcweir
396cdf0e10cSrcweir if( nStackLongs & 1 )
397cdf0e10cSrcweir // stack has to be 8 byte aligned
398cdf0e10cSrcweir nStackLongs++;
399cdf0e10cSrcweir callVirtualMethod(
400cdf0e10cSrcweir pAdjustedThisPtr,
401cdf0e10cSrcweir aVtableSlot.index,
402cdf0e10cSrcweir pCppReturn,
403cdf0e10cSrcweir pReturnTypeDescr->eTypeClass,
404cdf0e10cSrcweir (sal_Int32 *)pCppStackStart,
405cdf0e10cSrcweir nStackLongs);
406cdf0e10cSrcweir // NO exception occured...
407cdf0e10cSrcweir *ppUnoExc = 0;
408cdf0e10cSrcweir
409cdf0e10cSrcweir // reconvert temporary params
410cdf0e10cSrcweir for ( ; nTempIndizes--; )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
413cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
414cdf0e10cSrcweir
415cdf0e10cSrcweir if (pParams[nIndex].bIn)
416cdf0e10cSrcweir {
417cdf0e10cSrcweir if (pParams[nIndex].bOut) // inout
418cdf0e10cSrcweir {
419cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
420cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
421cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
422cdf0e10cSrcweir }
423cdf0e10cSrcweir }
424cdf0e10cSrcweir else // pure out
425cdf0e10cSrcweir {
426cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
427cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
428cdf0e10cSrcweir }
429cdf0e10cSrcweir // destroy temp cpp param => cpp: every param was constructed
430cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
431cdf0e10cSrcweir
432cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
433cdf0e10cSrcweir }
434cdf0e10cSrcweir // return value
435cdf0e10cSrcweir if (pCppReturn && pUnoReturn != pCppReturn)
436cdf0e10cSrcweir {
437cdf0e10cSrcweir uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
438cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
439cdf0e10cSrcweir uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
440cdf0e10cSrcweir }
441cdf0e10cSrcweir }
442cdf0e10cSrcweir catch( ... )
443cdf0e10cSrcweir {
444cdf0e10cSrcweir // get exception
445cdf0e10cSrcweir fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions,
446cdf0e10cSrcweir *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
447cdf0e10cSrcweir
448cdf0e10cSrcweir // temporary params
449cdf0e10cSrcweir for ( ; nTempIndizes--; )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
452cdf0e10cSrcweir // destroy temp cpp param => cpp: every param was constructed
453cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
454cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
455cdf0e10cSrcweir }
456cdf0e10cSrcweir // return type
457cdf0e10cSrcweir if (pReturnTypeDescr)
458cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
459cdf0e10cSrcweir }
460cdf0e10cSrcweir }
461cdf0e10cSrcweir
462cdf0e10cSrcweir }
463cdf0e10cSrcweir
464cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
465cdf0e10cSrcweir
unoInterfaceProxyDispatch(uno_Interface * pUnoI,const typelib_TypeDescription * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)466cdf0e10cSrcweir void unoInterfaceProxyDispatch(
467cdf0e10cSrcweir uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
468cdf0e10cSrcweir void * pReturn, void * pArgs[], uno_Any ** ppException )
469cdf0e10cSrcweir {
470cdf0e10cSrcweir #if defined BRIDGES_DEBUG
471cdf0e10cSrcweir OString cstr( OUStringToOString( pMemberDescr->pTypeName, RTL_TEXTENCODING_ASCII_US ) );
472cdf0e10cSrcweir fprintf( stderr, "received dispatch( %s )\n", cstr.getStr() );
473cdf0e10cSrcweir #endif
474cdf0e10cSrcweir
475cdf0e10cSrcweir // is my surrogate
476cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
477cdf0e10cSrcweir = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
478cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
479cdf0e10cSrcweir
480cdf0e10cSrcweir switch (pMemberDescr->eTypeClass)
481cdf0e10cSrcweir {
482cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
483cdf0e10cSrcweir {
484cdf0e10cSrcweir VtableSlot aVtableSlot(
485cdf0e10cSrcweir getVtableSlot(
486cdf0e10cSrcweir reinterpret_cast<
487cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription const * >(
488cdf0e10cSrcweir pMemberDescr)));
489cdf0e10cSrcweir if (pReturn)
490cdf0e10cSrcweir {
491cdf0e10cSrcweir // dependent dispatch
492cdf0e10cSrcweir cpp_call(
493cdf0e10cSrcweir pThis, aVtableSlot,
494cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
495cdf0e10cSrcweir 0, 0, // no params
496cdf0e10cSrcweir pReturn, pArgs, ppException );
497cdf0e10cSrcweir }
498cdf0e10cSrcweir else
499cdf0e10cSrcweir {
500cdf0e10cSrcweir // is SET
501cdf0e10cSrcweir typelib_MethodParameter aParam;
502cdf0e10cSrcweir aParam.pTypeRef =
503cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
504cdf0e10cSrcweir aParam.bIn = sal_True;
505cdf0e10cSrcweir aParam.bOut = sal_False;
506cdf0e10cSrcweir
507cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef = 0;
508cdf0e10cSrcweir OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
509cdf0e10cSrcweir typelib_typedescriptionreference_new(
510cdf0e10cSrcweir &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
511cdf0e10cSrcweir
512cdf0e10cSrcweir // dependent dispatch
513cdf0e10cSrcweir aVtableSlot.index += 1; // get, then set method
514cdf0e10cSrcweir cpp_call(
515cdf0e10cSrcweir pThis, aVtableSlot,
516cdf0e10cSrcweir pReturnTypeRef,
517cdf0e10cSrcweir 1, &aParam,
518cdf0e10cSrcweir pReturn, pArgs, ppException );
519cdf0e10cSrcweir
520cdf0e10cSrcweir typelib_typedescriptionreference_release( pReturnTypeRef );
521cdf0e10cSrcweir }
522cdf0e10cSrcweir
523cdf0e10cSrcweir break;
524cdf0e10cSrcweir }
525cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
526cdf0e10cSrcweir {
527cdf0e10cSrcweir VtableSlot aVtableSlot(
528cdf0e10cSrcweir getVtableSlot(
529cdf0e10cSrcweir reinterpret_cast<
530cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription const * >(
531cdf0e10cSrcweir pMemberDescr)));
532cdf0e10cSrcweir switch (aVtableSlot.index)
533cdf0e10cSrcweir {
534cdf0e10cSrcweir // standard calls
535cdf0e10cSrcweir case 1: // acquire uno interface
536cdf0e10cSrcweir (*pUnoI->acquire)( pUnoI );
537cdf0e10cSrcweir *ppException = 0;
538cdf0e10cSrcweir break;
539cdf0e10cSrcweir case 2: // release uno interface
540cdf0e10cSrcweir (*pUnoI->release)( pUnoI );
541cdf0e10cSrcweir *ppException = 0;
542cdf0e10cSrcweir break;
543cdf0e10cSrcweir case 0: // queryInterface() opt
544cdf0e10cSrcweir {
545cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
546cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
547cdf0e10cSrcweir if (pTD)
548cdf0e10cSrcweir {
549cdf0e10cSrcweir uno_Interface * pInterface = 0;
550cdf0e10cSrcweir (*pThis->pBridge->getUnoEnv()->getRegisteredInterface)(
551cdf0e10cSrcweir pThis->pBridge->getUnoEnv(),
552cdf0e10cSrcweir (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
553cdf0e10cSrcweir
554cdf0e10cSrcweir if (pInterface)
555cdf0e10cSrcweir {
556cdf0e10cSrcweir ::uno_any_construct(
557cdf0e10cSrcweir reinterpret_cast< uno_Any * >( pReturn ),
558cdf0e10cSrcweir &pInterface, pTD, 0 );
559cdf0e10cSrcweir (*pInterface->release)( pInterface );
560cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
561cdf0e10cSrcweir *ppException = 0;
562cdf0e10cSrcweir break;
563cdf0e10cSrcweir }
564cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
565cdf0e10cSrcweir }
566cdf0e10cSrcweir } // else perform queryInterface()
567cdf0e10cSrcweir default:
568cdf0e10cSrcweir // dependent dispatch
569cdf0e10cSrcweir cpp_call(
570cdf0e10cSrcweir pThis, aVtableSlot,
571cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
572cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
573cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
574cdf0e10cSrcweir pReturn, pArgs, ppException );
575cdf0e10cSrcweir }
576cdf0e10cSrcweir break;
577cdf0e10cSrcweir }
578cdf0e10cSrcweir default:
579cdf0e10cSrcweir {
580cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException aExc(
581cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
582cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
583cdf0e10cSrcweir
584cdf0e10cSrcweir Type const & rExcType = ::getCppuType( &aExc );
585cdf0e10cSrcweir // binary identical null reference
586cdf0e10cSrcweir ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
587cdf0e10cSrcweir }
588cdf0e10cSrcweir }
589cdf0e10cSrcweir }
590cdf0e10cSrcweir
591cdf0e10cSrcweir } } }
592