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