27#include <com/sun/star/uno/Exception.hpp>
28#include <com/sun/star/uno/RuntimeException.hpp>
29#include <com/sun/star/uno/genfunc.hxx>
45#define INSERT_FLOAT_DOUBLE( pSV, nr, pFPR, pDS ) \
46 if ( nr < MAX_FP_REGS ) \
47 pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \
49 *pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV );
51#define INSERT_INT64( pSV, nr, pGPR, pDS ) \
52 if ( nr < MAX_GP_REGS ) \
53 pGPR[nr++] = *reinterpret_cast<sal_Int64 *>( pSV ); \
55 *pDS++ = *reinterpret_cast<sal_Int64 *>( pSV );
57#define INSERT_INT32( pSV, nr, pGPR, pDS ) \
58 if ( nr < MAX_GP_REGS ) \
59 pGPR[nr++] = *reinterpret_cast<sal_Int32 *>( pSV ); \
61 *pDS++ = *reinterpret_cast<sal_Int32 *>( pSV );
63#define INSERT_INT16( pSV, nr, pGPR, pDS ) \
64 if ( nr < MAX_GP_REGS ) \
65 pGPR[nr++] = *reinterpret_cast<sal_Int16 *>( pSV ); \
67 *pDS++ = *reinterpret_cast<sal_Int16 *>( pSV );
69#define INSERT_UINT16( pSV, nr, pGPR, pDS ) \
70 if ( nr < MAX_GP_REGS ) \
71 pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \
73 *pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
75#define INSERT_INT8( pSV, nr, pGPR, pDS ) \
76 if ( nr < MAX_GP_REGS ) \
77 pGPR[nr++] = *reinterpret_cast<sal_Int8 *>( pSV ); \
79 *pDS++ = *reinterpret_cast<sal_Int8 *>( pSV );
88 const typelib_CompoundTypeDescription *
p =
89 reinterpret_cast<const typelib_CompoundTypeDescription*
>( pTypeDescr );
91 for (sal_Int32
i = 0;
i <
p->nMembers; ++
i)
93 typelib_TypeDescriptionReference *pTypeInStruct =
p->ppTypeRefs[
i ];
95 switch (pTypeInStruct->eTypeClass)
97 case typelib_TypeClass_STRUCT:
98 case typelib_TypeClass_EXCEPTION:
101 TYPELIB_DANGER_GET(&
t, pTypeInStruct);
102 bool isFPR = isReturnInFPR(
t, nSize);
103 TYPELIB_DANGER_RELEASE(
t);
108 case typelib_TypeClass_FLOAT:
109 case typelib_TypeClass_DOUBLE:
122 sal_Int64 * gret,
double * fret,
void * pRegisterReturn)
124 sal_uInt32 nSize = 0;
125 if (isReturnInFPR(pTypeDescr, nSize))
127 reinterpret_cast<double *
>( pRegisterReturn )[0] = fret[0];
128 reinterpret_cast<double *
>( pRegisterReturn )[1] = fret[1];
132 reinterpret_cast<sal_Int64 *
>( pRegisterReturn )[0] = gret[0];
133 reinterpret_cast<sal_Int64 *
>( pRegisterReturn )[1] = gret[1];
138 void * pAdjustedThisPtr,
139 sal_Int32 nVtableIndex,
140 void * pRegisterReturn,
141 typelib_TypeDescriptionReference * pReturnTypeRef,
155 sal_uInt64 pMethod = *((sal_uInt64 *)pAdjustedThisPtr);
156 pMethod += 8 * nVtableIndex;
157 void *mfunc = (
void *) *((sal_uInt64 *)pMethod);
159 fprintf(stderr,
"calling function %p\n", mfunc);
163 sal_uInt64* pCallStack =
NULL;
167 sal_uInt32 nStackBytes = ( ( nStack + 1 ) >> 1 ) * 16;
168 pCallStack = (sal_uInt64 *) __builtin_alloca( nStackBytes );
169 std::memcpy( pCallStack, pStack, nStackBytes );
178 "ld $4, 0(%[gpr]) \n\t"
179 "ld $5, 8(%[gpr]) \n\t"
180 "ld $6, 16(%[gpr]) \n\t"
181 "ld $7, 24(%[gpr]) \n\t"
182 "ld $8, 32(%[gpr]) \n\t"
183 "ld $9, 40(%[gpr]) \n\t"
184 "ld $10, 48(%[gpr]) \n\t"
185 "ld $11, 56(%[gpr]) \n\t"
187 "ldc1 $f12, 0(%[fpr]) \n\t"
188 "ldc1 $f13, 8(%[fpr]) \n\t"
189 "ldc1 $f14, 16(%[fpr]) \n\t"
190 "ldc1 $f15, 24(%[fpr]) \n\t"
191 "ldc1 $f16, 32(%[fpr]) \n\t"
192 "ldc1 $f17, 40(%[fpr]) \n\t"
193 "ldc1 $f18, 48(%[fpr]) \n\t"
194 "ldc1 $f19, 56(%[fpr]) \n\t"
198 "move %[gret1], $2 \n\t"
199 "move %[gret2], $3 \n\t"
200 "mov.d %[fret1], $f0 \n\t"
201 "mov.d %[fret2], $f2 \n\t"
203 :[gret1]
"=r"(gret[0]), [gret2]
"=r"(gret[1]),
204 [fret1]
"=f"(fret[0]), [fret2]
"=f"(fret[1])
205 :[gpr]
"r"(pGPR), [fpr]
"r"(pFPR), [mfunc]
"c"(mfunc),
206 [stack]
"m"(pCallStack)
207 :
"$2",
"$3",
"$4",
"$5",
"$6",
"$7",
"$8",
208 "$9",
"$10",
"$11",
"$31",
209 "$f0",
"$f2",
"$f12",
"$f13",
"$f14",
"$f15",
210 "$f16",
"$f17",
"$f18",
"$f19",
"memory"
213 switch (pReturnTypeRef->eTypeClass)
215 case typelib_TypeClass_HYPER:
216 case typelib_TypeClass_UNSIGNED_HYPER:
217 case typelib_TypeClass_LONG:
218 case typelib_TypeClass_UNSIGNED_LONG:
219 case typelib_TypeClass_ENUM:
220 case typelib_TypeClass_CHAR:
221 case typelib_TypeClass_SHORT:
222 case typelib_TypeClass_UNSIGNED_SHORT:
223 case typelib_TypeClass_BOOLEAN:
224 case typelib_TypeClass_BYTE:
225 *
reinterpret_cast<sal_Int64 *
>( pRegisterReturn ) = gret[0];
227 case typelib_TypeClass_FLOAT:
228 case typelib_TypeClass_DOUBLE:
229 *
reinterpret_cast<double *
>( pRegisterReturn ) = fret[0];
231 case typelib_TypeClass_STRUCT:
232 case typelib_TypeClass_EXCEPTION:
234 sal_Int32
const nRetSize = pReturnTypeRef->pType->nSize;
235 if (bSimpleReturn && nRetSize <= 16 && nRetSize > 0)
238 TYPELIB_DANGER_GET( &pTypeDescr, pReturnTypeRef );
239 fillReturn(pTypeDescr, gret, fret, pRegisterReturn);
240 TYPELIB_DANGER_RELEASE( pTypeDescr );
246 fprintf(stderr,
"unhandled return type %u\n", pReturnTypeRef->eTypeClass);
256 typelib_TypeDescriptionReference * pReturnTypeRef,
257 sal_Int32 nParams, typelib_MethodParameter * pParams,
258 void * pUnoReturn,
void * pUnoArgs[],
uno_Any ** ppUnoExc )
261 sal_uInt64 *pStack = (sal_uInt64 *)__builtin_alloca( ((nParams+3) *
sizeof(sal_Int64)) );
262 sal_uInt64 *pStackStart = pStack;
269 fprintf(stderr,
"in cpp_call\n");
274 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
275 assert(pReturnTypeDescr);
277 void * pCppReturn = 0;
279 bool bSimpleReturn =
true;
280 if (pReturnTypeDescr)
284 bSimpleReturn =
false;
287 __builtin_alloca( pReturnTypeDescr->nSize ) : pUnoReturn;
292 pCppReturn = pUnoReturn;
297 void* pAdjustedThisPtr =
reinterpret_cast< void **
>( pThis->
getCppI() ) + aVtableSlot.
offset;
301 void ** pCppArgs = (
void **)alloca( 3 *
sizeof(
void *) * nParams );
303 sal_Int32 * pTempIndices = (sal_Int32 *)(pCppArgs + nParams);
307 sal_Int32 nTempIndices = 0;
311 const typelib_MethodParameter & rParam = pParams[
nPos];
313 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
320 switch (pParamTypeDescr->eTypeClass)
322 case typelib_TypeClass_LONG:
323 case typelib_TypeClass_UNSIGNED_LONG:
324 case typelib_TypeClass_ENUM:
327 case typelib_TypeClass_CHAR:
328 case typelib_TypeClass_SHORT:
331 case typelib_TypeClass_UNSIGNED_SHORT:
334 case typelib_TypeClass_BOOLEAN:
335 case typelib_TypeClass_BYTE:
338 case typelib_TypeClass_FLOAT:
339 case typelib_TypeClass_DOUBLE:
342 case typelib_TypeClass_HYPER:
343 case typelib_TypeClass_UNSIGNED_HYPER:
351 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
359 pCppArgs[
nPos] = alloca( pParamTypeDescr->nSize ),
361 pTempIndices[nTempIndices] =
nPos;
363 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
369 pCppArgs[
nPos] = alloca( pParamTypeDescr->nSize ),
372 pTempIndices[nTempIndices] =
nPos;
374 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
380 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
390 pAdjustedThisPtr, aVtableSlot.
index,
391 pCppReturn, pReturnTypeRef, bSimpleReturn,
392 pStackStart, ( pStack - pStackStart ),
394 }
catch (css::uno::Exception &) {
396 }
catch (std::exception & e) {
397 throw css::uno::RuntimeException(
401 throw css::uno::RuntimeException(
"C++ code threw unknown exception");
407 for ( ; nTempIndices--; )
409 sal_Int32
nIndex = pTempIndices[nTempIndices];
429 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
432 if (pCppReturn && pUnoReturn != pCppReturn)
445 for ( ; nTempIndices--; )
447 sal_Int32
nIndex = pTempIndices[nTempIndices];
450 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
453 if (pReturnTypeDescr)
454 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
465 void * pReturn,
void * pArgs[],
uno_Any ** ppException )
473 fprintf(stderr,
"in dispatch\n");
476 switch (pMemberDescr->eTypeClass)
478 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
481 VtableSlot aVtableSlot(
484 typelib_InterfaceAttributeTypeDescription
const *
>(
492 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
494 pReturn, pArgs, ppException );
499 typelib_MethodParameter aParam;
501 ((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
505 typelib_TypeDescriptionReference * pReturnTypeRef = 0;
506 OUString aVoidName(
"void");
508 &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
511 aVtableSlot.index += 1;
516 pReturn, pArgs, ppException );
523 case typelib_TypeClass_INTERFACE_METHOD:
526 VtableSlot aVtableSlot(
529 typelib_InterfaceMethodTypeDescription
const *
>(
531 switch (aVtableSlot.index)
535 (*pUnoI->acquire)( pUnoI );
539 (*pUnoI->release)( pUnoI );
545 TYPELIB_DANGER_GET( &pTD,
reinterpret_cast< Type *
>( pArgs[0] )->getTypeLibType() );
548 uno_Interface * pInterface = 0;
550 (
void **)&pInterface, pThis->
oid.pData,
551 (typelib_InterfaceTypeDescription *)pTD );
556 reinterpret_cast< uno_Any *
>( pReturn ),
557 &pInterface, pTD, 0 );
558 (*pInterface->release)( pInterface );
559 TYPELIB_DANGER_RELEASE( pTD );
563 TYPELIB_DANGER_RELEASE( pTD );
570 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
571 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
572 ((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
573 pReturn, pArgs, ppException );
579 ::com::sun::star::uno::RuntimeException aExc(
580 "illegal member type description!",
585 ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
uno_Mapping * getUno2Cpp()
uno_ExtEnvironment * getUnoEnv()
uno_Mapping * getCpp2Uno()
A uno proxy wrapping a cpp interface.
com::sun::star::uno::XInterface * getCppI()
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_constructData(void *pMem, typelib_TypeDescription *pTypeDescr) SAL_THROW_EXTERN_C()
void SAL_CALL uno_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void callVirtualMethod(void *pThis, sal_uInt32 nVtableIndex, void *pRegisterReturn, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn, sal_uInt32 *pStack, sal_uInt32 nStack, sal_uInt32 *pGPR, double *pFPR) __attribute__((noinline))
#define INSERT_INT32(pSV, nr, pGPR, pDS)
#define INSERT_FLOAT_DOUBLE(pSV, nr, pFPR, pDS)
#define INSERT_INT8(pSV, nr, pGPR, pDS)
#define INSERT_INT16(pSV, nr, pGPR, pDS)
#define INSERT_INT64(pSV, nr, pGPR, pDS)
#define INSERT_UINT16(pSV, nr, pGPR, pDS)
static void 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)
struct _typelib_TypeDescription typelib_TypeDescription
bool return_in_hidden_param(typelib_TypeDescriptionReference *pTypeRef)
void fillUnoException(uno_Any *pUnoExc, uno_Mapping *pCpp2Uno)
void unoInterfaceProxyDispatch(uno_Interface *pUnoI, typelib_TypeDescription const *pMemberDescr, void *pReturn, void **pArgs, uno_Any **ppException)
VtableSlot getVtableSlot(typelib_InterfaceAttributeTypeDescription const *ifcMember)
Calculates the vtable slot associated with an interface attribute member.
bool isSimpleType(typelib_TypeClass typeClass)
Determines whether a type is a "simple" type (VOID, BOOLEAN, BYTE, SHORT, UNSIGNED SHORT,...
bool relatesToInterfaceType(typelib_TypeDescription const *type)
Determines whether a type relates to an interface type (is itself an interface type,...
void fillReturn(typelib_TypeDescriptionReference *pTypeRef, sal_Int64 *gret, double *fret, void *pRegisterReturn)
OUString runtimeToOUString(char const *runtimeString)
Represents a vtable slot of a C++ class.
sal_Int32 index
The index within the vtable.
sal_Int32 offset
The offset of the vtable.
void SAL_CALL typelib_typedescriptionreference_new(typelib_TypeDescriptionReference **ppTDR, typelib_TypeClass eTypeClass, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescriptionreference_release(typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()