28#include <com/sun/star/uno/genfunc.hxx>
29#include <com/sun/star/uno/RuntimeException.hpp>
31#include <typelib/typedescription.hxx>
63 typelib_TypeDescriptionReference * pReturnTypeRef,
64 sal_Int32 nParams, typelib_MethodParameter * pParams,
65 void ** gpreg,
void ** fpreg,
void ** ovrflw,
66 sal_uInt64 * pRegisterReturn )
68 unsigned int nr_gpr = 0;
69 unsigned int nr_fpr = 0;
74 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
76 = (pReturnTypeRef ==
nullptr || pReturnTypeRef->eTypeClass == typelib_TypeClass_VOID)
79 void * pUnoReturn =
nullptr;
80 void * pCppReturn =
nullptr;
82 if ( pReturnTypeDescr )
86 pCppReturn = *gpreg++;
90 ? alloca( pReturnTypeDescr->nSize )
94 pUnoReturn = pRegisterReturn;
103 void ** pUnoArgs =
static_cast<void **
>(alloca( 4 *
sizeof(
void *) * nParams ));
104 void ** pCppArgs = pUnoArgs + nParams;
106 sal_Int32 * pTempIndices =
reinterpret_cast<sal_Int32 *
>(pUnoArgs + (2 * nParams));
110 sal_Int32 nTempIndices = 0;
114 const typelib_MethodParameter & rParam = pParams[
nPos];
121 bool bFitsRegisters =
126 assert(bFitsRegisters && ( ( nUsedSSE == 1 && nUsedGPR == 0 ) || ( nUsedSSE == 0 && nUsedGPR == 1 ) ));
132 pCppArgs[
nPos] = pUnoArgs[
nPos] = fpreg++;
136 pCppArgs[
nPos] = pUnoArgs[
nPos] = ovrflw++;
138 else if ( nUsedGPR == 1 )
142 pCppArgs[
nPos] = pUnoArgs[
nPos] = gpreg++;
146 pCppArgs[
nPos] = pUnoArgs[
nPos] = ovrflw++;
152 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
157 pCppArgs[
nPos] = pCppStack = *gpreg++;
161 pCppArgs[
nPos] = pCppStack = *ovrflw++;
166 pUnoArgs[
nPos] = alloca( pParamTypeDescr->nSize );
167 pTempIndices[nTempIndices] =
nPos;
169 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
174 pCppStack, pParamTypeDescr,
176 pTempIndices[nTempIndices] =
nPos;
178 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
182 pUnoArgs[
nPos] = pCppStack;
184 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
194 (*pThis->
getUnoI()->pDispatcher)( pThis->
getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
200 for ( ; nTempIndices--; )
202 sal_Int32
nIndex = pTempIndices[nTempIndices];
206 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
208 if (pReturnTypeDescr)
209 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
218 for ( ; nTempIndices--; )
220 sal_Int32
nIndex = pTempIndices[nTempIndices];
223 if ( pParams[
nIndex].bOut )
233 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
238 if ( pUnoReturn != pCppReturn )
246 *
reinterpret_cast<void **
>(pRegisterReturn) = pCppReturn;
248 if ( pReturnTypeDescr )
250 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
252 switch (returnKind) {
271 sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
272 void ** gpreg,
void ** fpreg,
void ** ovrflw,
273 sal_uInt64 * pRegisterReturn )
279 if ( nFunctionIndex & 0x80000000 )
281 nFunctionIndex &= 0x7fffffff;
288 pThis =
static_cast<char *
>( pThis ) - nVtableOffset;
293 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->
getTypeDescr();
295 if ( nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex )
299 "illegal " << OUString::unacquired(&pTypeDescr->aBase.pTypeName)
300 <<
" vtable index " << nFunctionIndex <<
"/"
301 << pTypeDescr->nMapFunctionIndexToMemberIndex);
303 (
"illegal " + OUString::unacquired(&pTypeDescr->aBase.pTypeName)
304 +
" vtable index " + OUString::number(nFunctionIndex) +
"/"
305 + OUString::number(pTypeDescr->nMapFunctionIndexToMemberIndex)),
310 sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
311 assert(nMemberPos < pTypeDescr->nAllMembers);
313 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
316 switch ( aMemberDescr.get()->eTypeClass )
318 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
320 typelib_TypeDescriptionReference *pAttrTypeRef =
321 reinterpret_cast<typelib_InterfaceAttributeTypeDescription *
>( aMemberDescr.get() )->pAttributeTypeRef;
323 if ( pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex )
326 eRet =
cpp2uno_call( pCppI, aMemberDescr.get(), pAttrTypeRef,
328 gpreg, fpreg, ovrflw, pRegisterReturn );
333 typelib_MethodParameter aParam;
334 aParam.pTypeRef = pAttrTypeRef;
341 gpreg, fpreg, ovrflw, pRegisterReturn );
345 case typelib_TypeClass_INTERFACE_METHOD:
348 switch ( nFunctionIndex )
361 TYPELIB_DANGER_GET( &pTD,
static_cast<Type *
>( gpreg[2] )->getTypeLibType() );
367 reinterpret_cast<void **
>(&pInterface),
369 reinterpret_cast<typelib_InterfaceTypeDescription *
>( pTD ) );
373 ::uno_any_construct(
static_cast<uno_Any *
>( gpreg[0] ),
374 &pInterface, pTD, cpp_acquire );
376 pInterface->release();
377 TYPELIB_DANGER_RELEASE( pTD );
379 reinterpret_cast<void **
>( pRegisterReturn )[0] = gpreg[0];
383 TYPELIB_DANGER_RELEASE( pTD );
389 typelib_InterfaceMethodTypeDescription *pMethodTD =
390 reinterpret_cast<typelib_InterfaceMethodTypeDescription *
>( aMemberDescr.get() );
393 pMethodTD->pReturnTypeRef,
396 gpreg, fpreg, ovrflw, pRegisterReturn );
424 sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
425 bool bHasHiddenParam )
427 sal_uInt64 nOffsetAndIndex = (
static_cast<sal_uInt64
>(nVtableOffset) << 32 ) |
static_cast<sal_uInt64
>(nFunctionIndex);
429 if ( bHasHiddenParam )
430 nOffsetAndIndex |= 0x80000000;
433 *
reinterpret_cast<sal_uInt16 *
>(
code ) = 0xba49;
434 *
reinterpret_cast<sal_uInt16 *
>(
code + 2 ) = nOffsetAndIndex & 0xFFFF;
435 *
reinterpret_cast<sal_uInt32 *
>(
code + 4 ) = nOffsetAndIndex >> 16;
436 *
reinterpret_cast<sal_uInt16 *
>(
code + 8 ) = nOffsetAndIndex >> 48;
439 *
reinterpret_cast<sal_uInt16 *
>(
code + 10 ) = 0xbb49;
440 *
reinterpret_cast<sal_uInt32 *
>(
code + 12 )
442 *
reinterpret_cast<sal_uInt32 *
>(
code + 16 )
446 *
reinterpret_cast<sal_uInt32 *
>(
code + 20 ) = 0x00e3ff49;
448#if OSL_DEBUG_LEVEL > 1
450 "==> codeSnippet, functionIndex=%d%s, vtableOffset=%d\n",
451 nFunctionIndex, (bHasHiddenParam ?
"|0x80000000":
""), nVtableOffset);
462 return static_cast< Slot *
>(block) + 2;
479 void * block, sal_Int32 slotCount, sal_Int32,
480 typelib_InterfaceTypeDescription *)
482 Slot * slots = mapBlockToVtable(block);
483 slots[-2].fn =
nullptr;
484 slots[-1].fn = &
typeid(ProxyRtti);
485 return slots + slotCount;
490 Slot ** slots,
unsigned char * code,
491 typelib_InterfaceTypeDescription
const * type, sal_Int32 nFunctionOffset,
492 sal_Int32 functionCount, sal_Int32 nVtableOffset )
494 const sal_PtrDiff writetoexecdiff = 0;
495 (*slots) -= functionCount;
497 for ( sal_Int32 nPos = 0;
nPos <
type->nMembers; ++
nPos )
501 TYPELIB_DANGER_GET( &pTD,
type->ppMembers[ nPos ] );
504 if ( typelib_TypeClass_INTERFACE_ATTRIBUTE == pTD->eTypeClass )
506 typelib_InterfaceAttributeTypeDescription *pAttrTD =
507 reinterpret_cast<typelib_InterfaceAttributeTypeDescription *
>( pTD );
510 (s++)->fn = code + writetoexecdiff;
514 if ( ! pAttrTD->bReadOnly )
517 (s++)->fn = code + writetoexecdiff;
521 else if ( typelib_TypeClass_INTERFACE_METHOD == pTD->eTypeClass )
523 typelib_InterfaceMethodTypeDescription *pMethodTD =
524 reinterpret_cast<typelib_InterfaceMethodTypeDescription *
>( pTD );
526 (s++)->fn = code + writetoexecdiff;
533 TYPELIB_DANGER_RELEASE( pTD );
539 SAL_UNUSED_PARAMETER
unsigned char const *,
540 SAL_UNUSED_PARAMETER
unsigned char const * )
uno_Mapping * getUno2Cpp()
uno_ExtEnvironment * getCppEnv()
uno_Mapping * getCpp2Uno()
A cpp proxy wrapping a uno interface.
uno_Interface * getUnoI()
static CppInterfaceProxy * castInterfaceToProxy(void *pInterface)
typelib_InterfaceTypeDescription * getTypeDescr()
const OUString & getOid() const
static Slot * mapBlockToVtable(void *block)
Given a pointer to a block, turn it into a vtable pointer.
static void flushCode(unsigned char const *begin, unsigned char const *end)
Flush all the generated code snippets of a vtable, on platforms that require it.
static unsigned char * addLocalFunctions(Slot **slots, unsigned char *code, sal_PtrDiff writetoexecdiff, typelib_InterfaceTypeDescription const *type, sal_Int32 functionOffset, sal_Int32 functionCount, sal_Int32 vtableOffset)
Fill the vtable slots corresponding to all local (i.e., not inherited) functions of a given interface...
static Slot * initializeBlock(void *block, sal_Int32 slotCount, sal_Int32 vtableNumber, typelib_InterfaceTypeDescription *type)
Initialize a raw vtable block.
static std::size_t getBlockSize(sal_Int32 slotCount)
Calculate the size of a raw vtable block.
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void(* privateSnippetExecutor)()
const int codeSnippetSize
int cpp_vtable_call(sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset, void **gpreg, void **fpreg, void **ovrflw, sal_uInt64 *pRegisterReturn)
static unsigned char * codeSnippet(unsigned char *code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset, bool bHasHiddenParam)
static int cpp2uno_call(bridges::cpp_uno::shared::CppInterfaceProxy *pThis, const typelib_TypeDescription *pMemberTypeDescr, typelib_TypeDescriptionReference *pReturnTypeRef, sal_Int32 nParams, typelib_MethodParameter *pParams, void **gpreg, void **fpreg, void **ovrflw, sal_uInt64 *pRegisterReturn)
#define SAL_WARN(area, stream)
struct _typelib_TypeDescription typelib_TypeDescription
void raiseException(uno_Any *pUnoExc, uno_Mapping *pUno2Cpp)
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,...
bool examine_argument(typelib_TypeDescriptionReference *pTypeRef, int &nUsedGPR, int &nUsedSSE) noexcept
bool return_in_hidden_param(typelib_TypeDescriptionReference *pTypeRef) noexcept
Does function that returns this type use a hidden parameter, or registers?
const sal_uInt32 MAX_SSE_REGS
ReturnKind getReturnKind(typelib_TypeDescriptionReference *type) noexcept
const sal_uInt32 MAX_GPR_REGS