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