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
27cdf0e10cSrcweir #include <exception>
28cdf0e10cSrcweir #include <typeinfo>
29cdf0e10cSrcweir #include <stdio.h>
30cdf0e10cSrcweir #include <stdlib.h>
31cdf0e10cSrcweir #include <string.h>
32cdf0e10cSrcweir
33cdf0e10cSrcweir #include "rtl/alloc.h"
34cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
37cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
38cdf0e10cSrcweir #include <uno/data.h>
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include <bridges/cpp_uno/shared/bridge.hxx>
41cdf0e10cSrcweir #include <bridges/cpp_uno/shared/types.hxx>
42cdf0e10cSrcweir #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
43cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtables.hxx"
44cdf0e10cSrcweir
45cdf0e10cSrcweir #include "abi.hxx"
46cdf0e10cSrcweir #include "share.hxx"
47cdf0e10cSrcweir
48cdf0e10cSrcweir using namespace ::rtl;
49cdf0e10cSrcweir using namespace ::com::sun::star::uno;
50cdf0e10cSrcweir
51cdf0e10cSrcweir //==================================================================================================
52cdf0e10cSrcweir static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
53cdf0e10cSrcweir void * pRegisterReturn, typelib_TypeDescriptionReference * pReturnTypeRef, bool bSimpleReturn,
54cdf0e10cSrcweir sal_uInt64 *pStack, sal_uInt32 nStack,
55cdf0e10cSrcweir sal_uInt64 *pGPR, sal_uInt32 nGPR,
56cdf0e10cSrcweir double *pFPR, sal_uInt32 nFPR) __attribute__((noinline));
57cdf0e10cSrcweir
callVirtualMethod(void * pThis,sal_uInt32 nVtableIndex,void * pRegisterReturn,typelib_TypeDescriptionReference * pReturnTypeRef,bool bSimpleReturn,sal_uInt64 * pStack,sal_uInt32 nStack,sal_uInt64 * pGPR,sal_uInt32 nGPR,double * pFPR,sal_uInt32 nFPR)58cdf0e10cSrcweir static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
59cdf0e10cSrcweir void * pRegisterReturn, typelib_TypeDescriptionReference * pReturnTypeRef, bool bSimpleReturn,
60cdf0e10cSrcweir sal_uInt64 *pStack, sal_uInt32 nStack,
61cdf0e10cSrcweir sal_uInt64 *pGPR, sal_uInt32 nGPR,
62cdf0e10cSrcweir double *pFPR, sal_uInt32 nFPR)
63cdf0e10cSrcweir {
64cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
65cdf0e10cSrcweir // Let's figure out what is really going on here
66cdf0e10cSrcweir {
67cdf0e10cSrcweir fprintf( stderr, "= callVirtualMethod() =\nGPR's (%d): ", nGPR );
68cdf0e10cSrcweir for ( unsigned int i = 0; i < nGPR; ++i )
69cdf0e10cSrcweir fprintf( stderr, "0x%lx, ", pGPR[i] );
70cdf0e10cSrcweir fprintf( stderr, "\nFPR's (%d): ", nFPR );
71cdf0e10cSrcweir for ( unsigned int i = 0; i < nFPR; ++i )
72cdf0e10cSrcweir fprintf( stderr, "%f, ", pFPR[i] );
73cdf0e10cSrcweir fprintf( stderr, "\nStack (%d): ", nStack );
74cdf0e10cSrcweir for ( unsigned int i = 0; i < nStack; ++i )
75cdf0e10cSrcweir fprintf( stderr, "0x%lx, ", pStack[i] );
76cdf0e10cSrcweir fprintf( stderr, "\n" );
77cdf0e10cSrcweir }
78cdf0e10cSrcweir #endif
79cdf0e10cSrcweir
80cdf0e10cSrcweir // The call instruction within the asm section of callVirtualMethod may throw
81cdf0e10cSrcweir // exceptions. So that the compiler handles this correctly, it is important
82cdf0e10cSrcweir // that (a) callVirtualMethod might call dummy_can_throw_anything (although this
83cdf0e10cSrcweir // never happens at runtime), which in turn can throw exceptions, and (b)
84cdf0e10cSrcweir // callVirtualMethod is not inlined at its call site (so that any exceptions are
85cdf0e10cSrcweir // caught which are thrown from the instruction calling callVirtualMethod):
86cdf0e10cSrcweir if ( !pThis )
87cdf0e10cSrcweir CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything( "xxx" ); // address something
88cdf0e10cSrcweir
89cdf0e10cSrcweir // Should not happen, but...
90cdf0e10cSrcweir if ( nFPR > x86_64::MAX_SSE_REGS )
91cdf0e10cSrcweir nFPR = x86_64::MAX_SSE_REGS;
92cdf0e10cSrcweir if ( nGPR > x86_64::MAX_GPR_REGS )
93cdf0e10cSrcweir nGPR = x86_64::MAX_GPR_REGS;
94cdf0e10cSrcweir
95cdf0e10cSrcweir // Get pointer to method
96cdf0e10cSrcweir sal_uInt64 pMethod = *((sal_uInt64 *)pThis);
97cdf0e10cSrcweir pMethod += 8 * nVtableIndex;
98cdf0e10cSrcweir pMethod = *((sal_uInt64 *)pMethod);
99cdf0e10cSrcweir
100cdf0e10cSrcweir // Load parameters to stack, if necessary
101*fea2173fSHerbert Dürr sal_uInt64* pCallStack = NULL;
102cdf0e10cSrcweir if ( nStack )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir // 16-bytes aligned
105cdf0e10cSrcweir sal_uInt32 nStackBytes = ( ( nStack + 1 ) >> 1 ) * 16;
106*fea2173fSHerbert Dürr pCallStack = (sal_uInt64*) __builtin_alloca( nStackBytes );
107cdf0e10cSrcweir memcpy( pCallStack, pStack, nStackBytes );
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir // Return values
111cdf0e10cSrcweir sal_uInt64 rax;
112cdf0e10cSrcweir sal_uInt64 rdx;
113cdf0e10cSrcweir double xmm0;
114cdf0e10cSrcweir double xmm1;
115cdf0e10cSrcweir
116cdf0e10cSrcweir asm volatile (
117cdf0e10cSrcweir // Fill the xmm registers
118cdf0e10cSrcweir "movq %2, %%rax\n\t"
119cdf0e10cSrcweir
120cdf0e10cSrcweir "movsd (%%rax), %%xmm0\n\t"
121cdf0e10cSrcweir "movsd 8(%%rax), %%xmm1\n\t"
122cdf0e10cSrcweir "movsd 16(%%rax), %%xmm2\n\t"
123cdf0e10cSrcweir "movsd 24(%%rax), %%xmm3\n\t"
124cdf0e10cSrcweir "movsd 32(%%rax), %%xmm4\n\t"
125cdf0e10cSrcweir "movsd 40(%%rax), %%xmm5\n\t"
126cdf0e10cSrcweir "movsd 48(%%rax), %%xmm6\n\t"
127cdf0e10cSrcweir "movsd 56(%%rax), %%xmm7\n\t"
128cdf0e10cSrcweir
129cdf0e10cSrcweir // Fill the general purpose registers
130cdf0e10cSrcweir "movq %1, %%rax\n\t"
131cdf0e10cSrcweir
132cdf0e10cSrcweir "movq (%%rax), %%rdi\n\t"
133cdf0e10cSrcweir "movq 8(%%rax), %%rsi\n\t"
134cdf0e10cSrcweir "movq 16(%%rax), %%rdx\n\t"
135cdf0e10cSrcweir "movq 24(%%rax), %%rcx\n\t"
136cdf0e10cSrcweir "movq 32(%%rax), %%r8\n\t"
137cdf0e10cSrcweir "movq 40(%%rax), %%r9\n\t"
138cdf0e10cSrcweir
139cdf0e10cSrcweir // Perform the call
140cdf0e10cSrcweir "movq %0, %%r11\n\t"
141cdf0e10cSrcweir "movq %3, %%rax\n\t"
142cdf0e10cSrcweir "call *%%r11\n\t"
143cdf0e10cSrcweir
144cdf0e10cSrcweir // Fill the return values
145cdf0e10cSrcweir "movq %%rax, %4\n\t"
146cdf0e10cSrcweir "movq %%rdx, %5\n\t"
147cdf0e10cSrcweir "movsd %%xmm0, %6\n\t"
148cdf0e10cSrcweir "movsd %%xmm1, %7\n\t"
149cdf0e10cSrcweir :
150cdf0e10cSrcweir : "m" ( pMethod ), "m" ( pGPR ), "m" ( pFPR ), "m" ( nFPR ),
151*fea2173fSHerbert Dürr "m" ( rax ), "m" ( rdx ), "m" ( xmm0 ), "m" ( xmm1 ),
152*fea2173fSHerbert Dürr "m" (pCallStack) // dummy input to prevent the compiler from optimizing the alloca out
1538e13a5e1SHerbert Dürr : "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11",
1548e13a5e1SHerbert Dürr "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
155cdf0e10cSrcweir );
156cdf0e10cSrcweir
157cdf0e10cSrcweir switch (pReturnTypeRef->eTypeClass)
158cdf0e10cSrcweir {
159cdf0e10cSrcweir case typelib_TypeClass_HYPER:
160cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
161cdf0e10cSrcweir *reinterpret_cast<sal_uInt64 *>( pRegisterReturn ) = rax;
162cdf0e10cSrcweir break;
163cdf0e10cSrcweir case typelib_TypeClass_LONG:
164cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
165cdf0e10cSrcweir case typelib_TypeClass_ENUM:
166cdf0e10cSrcweir *reinterpret_cast<sal_uInt32 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt32*>( &rax );
167cdf0e10cSrcweir break;
168cdf0e10cSrcweir case typelib_TypeClass_CHAR:
169cdf0e10cSrcweir case typelib_TypeClass_SHORT:
170cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
171cdf0e10cSrcweir *reinterpret_cast<sal_uInt16 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt16*>( &rax );
172cdf0e10cSrcweir break;
173cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
174cdf0e10cSrcweir case typelib_TypeClass_BYTE:
175cdf0e10cSrcweir *reinterpret_cast<sal_uInt8 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt8*>( &rax );
176cdf0e10cSrcweir break;
177cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
178cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
179cdf0e10cSrcweir *reinterpret_cast<double *>( pRegisterReturn ) = xmm0;
180cdf0e10cSrcweir break;
181cdf0e10cSrcweir default:
182cdf0e10cSrcweir {
183cdf0e10cSrcweir sal_Int32 const nRetSize = pReturnTypeRef->pType->nSize;
184cdf0e10cSrcweir if (bSimpleReturn && nRetSize <= 16 && nRetSize > 0)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir sal_uInt64 longs[2];
187cdf0e10cSrcweir longs[0] = rax;
188cdf0e10cSrcweir longs[1] = rdx;
189cdf0e10cSrcweir
190cdf0e10cSrcweir double doubles[2];
191cdf0e10cSrcweir doubles[0] = xmm0;
192cdf0e10cSrcweir doubles[1] = xmm1;
193cdf0e10cSrcweir x86_64::fill_struct( pReturnTypeRef, &longs[0], &doubles[0], pRegisterReturn);
194cdf0e10cSrcweir }
195cdf0e10cSrcweir break;
196cdf0e10cSrcweir }
197cdf0e10cSrcweir }
198cdf0e10cSrcweir }
199cdf0e10cSrcweir
200cdf0e10cSrcweir //==================================================================================================
201cdf0e10cSrcweir
202cdf0e10cSrcweir // Macros for easier insertion of values to registers or stack
203cdf0e10cSrcweir // pSV - pointer to the source
204cdf0e10cSrcweir // nr - order of the value [will be increased if stored to register]
205cdf0e10cSrcweir // pFPR, pGPR - pointer to the registers
206cdf0e10cSrcweir // pDS - pointer to the stack [will be increased if stored here]
207cdf0e10cSrcweir
208cdf0e10cSrcweir // The value in %xmm register is already prepared to be retrieved as a float,
209cdf0e10cSrcweir // thus we treat float and double the same
210cdf0e10cSrcweir #define INSERT_FLOAT_DOUBLE( pSV, nr, pFPR, pDS ) \
211cdf0e10cSrcweir if ( nr < x86_64::MAX_SSE_REGS ) \
212cdf0e10cSrcweir pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \
213cdf0e10cSrcweir else \
214cdf0e10cSrcweir *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
215cdf0e10cSrcweir
216cdf0e10cSrcweir #define INSERT_INT64( pSV, nr, pGPR, pDS ) \
217cdf0e10cSrcweir if ( nr < x86_64::MAX_GPR_REGS ) \
218cdf0e10cSrcweir pGPR[nr++] = *reinterpret_cast<sal_uInt64 *>( pSV ); \
219cdf0e10cSrcweir else \
220cdf0e10cSrcweir *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV );
221cdf0e10cSrcweir
222cdf0e10cSrcweir #define INSERT_INT32( pSV, nr, pGPR, pDS ) \
223cdf0e10cSrcweir if ( nr < x86_64::MAX_GPR_REGS ) \
224cdf0e10cSrcweir pGPR[nr++] = *reinterpret_cast<sal_uInt32 *>( pSV ); \
225cdf0e10cSrcweir else \
226cdf0e10cSrcweir *pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV );
227cdf0e10cSrcweir
228cdf0e10cSrcweir #define INSERT_INT16( pSV, nr, pGPR, pDS ) \
229cdf0e10cSrcweir if ( nr < x86_64::MAX_GPR_REGS ) \
230cdf0e10cSrcweir pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \
231cdf0e10cSrcweir else \
232cdf0e10cSrcweir *pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
233cdf0e10cSrcweir
234cdf0e10cSrcweir #define INSERT_INT8( pSV, nr, pGPR, pDS ) \
235cdf0e10cSrcweir if ( nr < x86_64::MAX_GPR_REGS ) \
236cdf0e10cSrcweir pGPR[nr++] = *reinterpret_cast<sal_uInt8 *>( pSV ); \
237cdf0e10cSrcweir else \
238cdf0e10cSrcweir *pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV );
239cdf0e10cSrcweir
240cdf0e10cSrcweir //==================================================================================================
241cdf0e10cSrcweir
242cdf0e10cSrcweir namespace {
243cdf0e10cSrcweir
appendCString(OUStringBuffer & buffer,char const * text)244cdf0e10cSrcweir void appendCString(OUStringBuffer & buffer, char const * text) {
245cdf0e10cSrcweir if (text != 0) {
246cdf0e10cSrcweir buffer.append(
247cdf0e10cSrcweir OStringToOUString(OString(text), RTL_TEXTENCODING_ISO_8859_1));
248cdf0e10cSrcweir // use 8859-1 to avoid conversion failure
249cdf0e10cSrcweir }
250cdf0e10cSrcweir }
251cdf0e10cSrcweir
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
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)254cdf0e10cSrcweir static void cpp_call(
255cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
256cdf0e10cSrcweir bridges::cpp_uno::shared::VtableSlot aVtableSlot,
257cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef,
258cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams,
259cdf0e10cSrcweir void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
260cdf0e10cSrcweir {
261cdf0e10cSrcweir // Maxium space for [complex ret ptr], values | ptr ...
262cdf0e10cSrcweir // (but will be used less - some of the values will be in pGPR and pFPR)
263cdf0e10cSrcweir sal_uInt64 *pStack = (sal_uInt64 *)__builtin_alloca( (nParams + 3) * sizeof(sal_uInt64) );
264cdf0e10cSrcweir sal_uInt64 *pStackStart = pStack;
265cdf0e10cSrcweir
266cdf0e10cSrcweir sal_uInt64 pGPR[x86_64::MAX_GPR_REGS];
267cdf0e10cSrcweir sal_uInt32 nGPR = 0;
268cdf0e10cSrcweir
269cdf0e10cSrcweir double pFPR[x86_64::MAX_SSE_REGS];
270cdf0e10cSrcweir sal_uInt32 nFPR = 0;
271cdf0e10cSrcweir
272cdf0e10cSrcweir // Return
273cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
274cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
275cdf0e10cSrcweir OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
276cdf0e10cSrcweir
277cdf0e10cSrcweir void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion (see below)
278cdf0e10cSrcweir
279cdf0e10cSrcweir bool bSimpleReturn = true;
280cdf0e10cSrcweir if ( pReturnTypeDescr )
281cdf0e10cSrcweir {
282cdf0e10cSrcweir if ( x86_64::return_in_hidden_param( pReturnTypeRef ) )
283cdf0e10cSrcweir bSimpleReturn = false;
284cdf0e10cSrcweir
285cdf0e10cSrcweir if ( bSimpleReturn )
286cdf0e10cSrcweir pCppReturn = pUnoReturn; // direct way for simple types
287cdf0e10cSrcweir else
288cdf0e10cSrcweir {
289cdf0e10cSrcweir // complex return via ptr
290cdf0e10cSrcweir pCppReturn = bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )?
291cdf0e10cSrcweir __builtin_alloca( pReturnTypeDescr->nSize ) : pUnoReturn;
292cdf0e10cSrcweir INSERT_INT64( &pCppReturn, nGPR, pGPR, pStack );
293cdf0e10cSrcweir }
294cdf0e10cSrcweir }
295cdf0e10cSrcweir
296cdf0e10cSrcweir // Push "this" pointer
297cdf0e10cSrcweir void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset;
298cdf0e10cSrcweir INSERT_INT64( &pAdjustedThisPtr, nGPR, pGPR, pStack );
299cdf0e10cSrcweir
300cdf0e10cSrcweir // Args
301cdf0e10cSrcweir void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
302cdf0e10cSrcweir // Indizes of values this have to be converted (interface conversion cpp<=>uno)
303cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
304cdf0e10cSrcweir // Type descriptions for reconversions
305cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
306cdf0e10cSrcweir
307cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
308cdf0e10cSrcweir
309cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
310cdf0e10cSrcweir {
311cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
312cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
313cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
314cdf0e10cSrcweir
315cdf0e10cSrcweir if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
316cdf0e10cSrcweir {
317cdf0e10cSrcweir uno_copyAndConvertData( pCppArgs[nPos] = alloca( 8 ), pUnoArgs[nPos], pParamTypeDescr,
318cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
319cdf0e10cSrcweir
320cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
321cdf0e10cSrcweir {
322cdf0e10cSrcweir case typelib_TypeClass_HYPER:
323cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
324cdf0e10cSrcweir INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack );
325cdf0e10cSrcweir break;
326cdf0e10cSrcweir case typelib_TypeClass_LONG:
327cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
328cdf0e10cSrcweir case typelib_TypeClass_ENUM:
329cdf0e10cSrcweir INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack );
330cdf0e10cSrcweir break;
331cdf0e10cSrcweir case typelib_TypeClass_SHORT:
332cdf0e10cSrcweir case typelib_TypeClass_CHAR:
333cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
334cdf0e10cSrcweir INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack );
335cdf0e10cSrcweir break;
336cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
337cdf0e10cSrcweir case typelib_TypeClass_BYTE:
338cdf0e10cSrcweir INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack );
339cdf0e10cSrcweir break;
340cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
341cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
342cdf0e10cSrcweir INSERT_FLOAT_DOUBLE( pCppArgs[nPos], nFPR, pFPR, pStack );
343cdf0e10cSrcweir break;
344cdf0e10cSrcweir default:
345cdf0e10cSrcweir break;
346cdf0e10cSrcweir }
347cdf0e10cSrcweir
348cdf0e10cSrcweir // no longer needed
349cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
350cdf0e10cSrcweir }
351cdf0e10cSrcweir else // ptr to complex value | ref
352cdf0e10cSrcweir {
353cdf0e10cSrcweir if (! rParam.bIn) // is pure out
354cdf0e10cSrcweir {
355cdf0e10cSrcweir // cpp out is constructed mem, uno out is not!
356cdf0e10cSrcweir uno_constructData(
357cdf0e10cSrcweir pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
358cdf0e10cSrcweir pParamTypeDescr );
359cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
360cdf0e10cSrcweir // will be released at reconversion
361cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
362cdf0e10cSrcweir }
363cdf0e10cSrcweir // is in/inout
364cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
365cdf0e10cSrcweir {
366cdf0e10cSrcweir uno_copyAndConvertData(
367cdf0e10cSrcweir pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
368cdf0e10cSrcweir pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
369cdf0e10cSrcweir
370cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
371cdf0e10cSrcweir // will be released at reconversion
372cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir else // direct way
375cdf0e10cSrcweir {
376cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos];
377cdf0e10cSrcweir // no longer needed
378cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
379cdf0e10cSrcweir }
380cdf0e10cSrcweir INSERT_INT64( &(pCppArgs[nPos]), nGPR, pGPR, pStack );
381cdf0e10cSrcweir }
382cdf0e10cSrcweir }
383cdf0e10cSrcweir
384cdf0e10cSrcweir try
385cdf0e10cSrcweir {
386cdf0e10cSrcweir try {
387cdf0e10cSrcweir callVirtualMethod(
388cdf0e10cSrcweir pAdjustedThisPtr, aVtableSlot.index,
389cdf0e10cSrcweir pCppReturn, pReturnTypeRef, bSimpleReturn,
390cdf0e10cSrcweir pStackStart, ( pStack - pStackStart ),
391cdf0e10cSrcweir pGPR, nGPR,
392cdf0e10cSrcweir pFPR, nFPR );
393cdf0e10cSrcweir } catch (Exception &) {
394cdf0e10cSrcweir throw;
395cdf0e10cSrcweir } catch (std::exception & e) {
396cdf0e10cSrcweir OUStringBuffer buf;
397cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("C++ code threw "));
398cdf0e10cSrcweir appendCString(buf, typeid(e).name());
399cdf0e10cSrcweir buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(": "));
400cdf0e10cSrcweir appendCString(buf, e.what());
401cdf0e10cSrcweir throw RuntimeException(
402cdf0e10cSrcweir buf.makeStringAndClear(), Reference< XInterface >());
403cdf0e10cSrcweir } catch (...) {
404cdf0e10cSrcweir throw RuntimeException(
405cdf0e10cSrcweir OUString(
406cdf0e10cSrcweir RTL_CONSTASCII_USTRINGPARAM(
407cdf0e10cSrcweir "C++ code threw unknown exception")),
408cdf0e10cSrcweir Reference< XInterface >());
409cdf0e10cSrcweir }
410cdf0e10cSrcweir
411cdf0e10cSrcweir // NO exception occured...
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 // fill uno exception
450cdf0e10cSrcweir fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
451cdf0e10cSrcweir
452cdf0e10cSrcweir // temporary params
453cdf0e10cSrcweir for ( ; nTempIndizes--; )
454cdf0e10cSrcweir {
455cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
456cdf0e10cSrcweir // destroy temp cpp param => cpp: every param was constructed
457cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
458cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
459cdf0e10cSrcweir }
460cdf0e10cSrcweir // return type
461cdf0e10cSrcweir if (pReturnTypeDescr)
462cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
463cdf0e10cSrcweir }
464cdf0e10cSrcweir }
465cdf0e10cSrcweir
466cdf0e10cSrcweir //==================================================================================================
467cdf0e10cSrcweir
468cdf0e10cSrcweir namespace bridges { namespace cpp_uno { namespace shared {
469cdf0e10cSrcweir
unoInterfaceProxyDispatch(uno_Interface * pUnoI,const typelib_TypeDescription * pMemberDescr,void * pReturn,void * pArgs[],uno_Any ** ppException)470cdf0e10cSrcweir void unoInterfaceProxyDispatch(
471cdf0e10cSrcweir uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
472cdf0e10cSrcweir void * pReturn, void * pArgs[], uno_Any ** ppException )
473cdf0e10cSrcweir {
474cdf0e10cSrcweir // is my surrogate
475cdf0e10cSrcweir bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
476cdf0e10cSrcweir = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
477cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
478cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
479cdf0e10cSrcweir #endif
480cdf0e10cSrcweir
481cdf0e10cSrcweir switch (pMemberDescr->eTypeClass)
482cdf0e10cSrcweir {
483cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
484cdf0e10cSrcweir {
485cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
486cdf0e10cSrcweir // determine vtable call index
487cdf0e10cSrcweir sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
488cdf0e10cSrcweir OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
489cdf0e10cSrcweir #endif
490cdf0e10cSrcweir VtableSlot aVtableSlot(
491cdf0e10cSrcweir getVtableSlot(
492cdf0e10cSrcweir reinterpret_cast<
493cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription const * >(
494cdf0e10cSrcweir pMemberDescr)));
495cdf0e10cSrcweir
496cdf0e10cSrcweir if (pReturn)
497cdf0e10cSrcweir {
498cdf0e10cSrcweir // dependent dispatch
499cdf0e10cSrcweir cpp_call(
500cdf0e10cSrcweir pThis, aVtableSlot,
501cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
502cdf0e10cSrcweir 0, 0, // no params
503cdf0e10cSrcweir pReturn, pArgs, ppException );
504cdf0e10cSrcweir }
505cdf0e10cSrcweir else
506cdf0e10cSrcweir {
507cdf0e10cSrcweir // is SET
508cdf0e10cSrcweir typelib_MethodParameter aParam;
509cdf0e10cSrcweir aParam.pTypeRef =
510cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
511cdf0e10cSrcweir aParam.bIn = sal_True;
512cdf0e10cSrcweir aParam.bOut = sal_False;
513cdf0e10cSrcweir
514cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef = 0;
515cdf0e10cSrcweir OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
516cdf0e10cSrcweir typelib_typedescriptionreference_new(
517cdf0e10cSrcweir &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
518cdf0e10cSrcweir
519cdf0e10cSrcweir // dependent dispatch
520cdf0e10cSrcweir aVtableSlot.index += 1; // get, then set method
521cdf0e10cSrcweir cpp_call(
522cdf0e10cSrcweir pThis, aVtableSlot, // get, then set method
523cdf0e10cSrcweir pReturnTypeRef,
524cdf0e10cSrcweir 1, &aParam,
525cdf0e10cSrcweir pReturn, pArgs, ppException );
526cdf0e10cSrcweir
527cdf0e10cSrcweir typelib_typedescriptionreference_release( pReturnTypeRef );
528cdf0e10cSrcweir }
529cdf0e10cSrcweir
530cdf0e10cSrcweir break;
531cdf0e10cSrcweir }
532cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
533cdf0e10cSrcweir {
534cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
535cdf0e10cSrcweir // determine vtable call index
536cdf0e10cSrcweir sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
537cdf0e10cSrcweir OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
538cdf0e10cSrcweir #endif
539cdf0e10cSrcweir VtableSlot aVtableSlot(
540cdf0e10cSrcweir getVtableSlot(
541cdf0e10cSrcweir reinterpret_cast<
542cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription const * >(
543cdf0e10cSrcweir pMemberDescr)));
544cdf0e10cSrcweir
545cdf0e10cSrcweir switch (aVtableSlot.index)
546cdf0e10cSrcweir {
547cdf0e10cSrcweir // standard calls
548cdf0e10cSrcweir case 1: // acquire uno interface
549cdf0e10cSrcweir (*pUnoI->acquire)( pUnoI );
550cdf0e10cSrcweir *ppException = 0;
551cdf0e10cSrcweir break;
552cdf0e10cSrcweir case 2: // release uno interface
553cdf0e10cSrcweir (*pUnoI->release)( pUnoI );
554cdf0e10cSrcweir *ppException = 0;
555cdf0e10cSrcweir break;
556cdf0e10cSrcweir case 0: // queryInterface() opt
557cdf0e10cSrcweir {
558cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
559cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
560cdf0e10cSrcweir if (pTD)
561cdf0e10cSrcweir {
562cdf0e10cSrcweir uno_Interface * pInterface = 0;
563cdf0e10cSrcweir (*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
564cdf0e10cSrcweir pThis->getBridge()->getUnoEnv(),
565cdf0e10cSrcweir (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
566cdf0e10cSrcweir
567cdf0e10cSrcweir if (pInterface)
568cdf0e10cSrcweir {
569cdf0e10cSrcweir ::uno_any_construct(
570cdf0e10cSrcweir reinterpret_cast< uno_Any * >( pReturn ),
571cdf0e10cSrcweir &pInterface, pTD, 0 );
572cdf0e10cSrcweir (*pInterface->release)( pInterface );
573cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
574cdf0e10cSrcweir *ppException = 0;
575cdf0e10cSrcweir break;
576cdf0e10cSrcweir }
577cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
578cdf0e10cSrcweir }
579cdf0e10cSrcweir } // else perform queryInterface()
580cdf0e10cSrcweir default:
581cdf0e10cSrcweir // dependent dispatch
582cdf0e10cSrcweir cpp_call(
583cdf0e10cSrcweir pThis, aVtableSlot,
584cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
585cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
586cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
587cdf0e10cSrcweir pReturn, pArgs, ppException );
588cdf0e10cSrcweir }
589cdf0e10cSrcweir break;
590cdf0e10cSrcweir }
591cdf0e10cSrcweir default:
592cdf0e10cSrcweir {
593cdf0e10cSrcweir ::com::sun::star::uno::RuntimeException aExc(
594cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
595cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
596cdf0e10cSrcweir
597cdf0e10cSrcweir Type const & rExcType = ::getCppuType( &aExc );
598cdf0e10cSrcweir // binary identical null reference
599cdf0e10cSrcweir ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
600cdf0e10cSrcweir }
601cdf0e10cSrcweir }
602cdf0e10cSrcweir }
603cdf0e10cSrcweir
604cdf0e10cSrcweir } } }
605