24#include <com/sun/star/uno/RuntimeException.hpp>
27#include <typelib/typedescription.hxx>
49 typelib_TypeDescriptionReference * pReturnTypeRef,
51 typelib_MethodParameter * pParams,
53 sal_Int64 * pRegisterReturn )
56 char *pTopStack = (
char *)pCallStack;
57 char *pFloatRegs = pTopStack + 2;
58 char *pGPRegs = pTopStack + (2+8)*8;
59 char *pStackedArgs = pTopStack + (2+8+8)*8;
67 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
69 void * pUnoReturn = 0;
71 void * pCppReturn = 0;
76 pUnoReturn = pRegisterReturn;
79 pCppReturn = pCallStack[0];
83 ? alloca( pReturnTypeDescr->nSize )
93 void ** pUnoArgs = (
void **)alloca(
sizeof(
void *) * nParams );
94 void ** pCppArgs = (
void **)alloca(
sizeof(
void *) * nParams );
98 int * pTempIndices = (sal_Int32 *)alloca(
sizeof(
int) * nParams);
103 int nTempIndices = 0;
107 const typelib_MethodParameter & rParam = pParams[
nPos];
109 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
114 if (nFPR < 8 && (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT ||
115 pParamTypeDescr->eTypeClass == typelib_TypeClass_DOUBLE))
117 pCppArgs[
nPos] = pUnoArgs[
nPos] = pFloatRegs;
121 else if (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT)
123 if ((pStackedArgs - pTopStack) % 4)
124 pStackedArgs += 4 - ((pStackedArgs - pTopStack) % 4);
125 pCppArgs[
nPos] = pUnoArgs[
nPos] = pStackedArgs;
128 else if (pParamTypeDescr->eTypeClass == typelib_TypeClass_DOUBLE)
130 if ((pStackedArgs - pTopStack) % 8)
131 pStackedArgs += 8 - ((pStackedArgs - pTopStack) % 8);
132 pCppArgs[
nPos] = pUnoArgs[
nPos] = pStackedArgs;
137 pCppArgs[
nPos] = pUnoArgs[
nPos] = pGPRegs;
142 switch (pParamTypeDescr->eTypeClass)
144 case typelib_TypeClass_HYPER:
145 case typelib_TypeClass_UNSIGNED_HYPER:
146 if ((pStackedArgs - pTopStack) % 8)
147 pStackedArgs += 8 - ((pStackedArgs - pTopStack) % 8);
148 pCppArgs[
nPos] = pUnoArgs[
nPos] = pStackedArgs;
151 case typelib_TypeClass_ENUM:
152 case typelib_TypeClass_LONG:
153 case typelib_TypeClass_UNSIGNED_LONG:
154 if ((pStackedArgs - pTopStack) % 4)
155 pStackedArgs += 4 - ((pStackedArgs - pTopStack) % 4);
156 pCppArgs[
nPos] = pUnoArgs[
nPos] = pStackedArgs;
159 case typelib_TypeClass_CHAR:
160 case typelib_TypeClass_SHORT:
161 case typelib_TypeClass_UNSIGNED_SHORT:
162 if ((pStackedArgs - pTopStack) % 2)
164 pCppArgs[
nPos] = pUnoArgs[
nPos] = pStackedArgs;
167 case typelib_TypeClass_BOOLEAN:
168 case typelib_TypeClass_BYTE:
169 pCppArgs[
nPos] = pUnoArgs[
nPos] = pStackedArgs;
173 assert(!
"should not happen");
177 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
183 pCppArgs[
nPos] = *(
void **)pGPRegs;
188 if ((pStackedArgs - pTopStack) % 8)
189 pStackedArgs += 8 - ((pStackedArgs - pTopStack) % 8);
190 pCppArgs[
nPos] = pStackedArgs;
197 pUnoArgs[
nPos] = alloca( pParamTypeDescr->nSize );
198 pTempIndices[nTempIndices] =
nPos;
200 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
206 alloca( pParamTypeDescr->nSize ),
207 pCppArgs[
nPos], pParamTypeDescr,
209 pTempIndices[nTempIndices] =
nPos;
211 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
217 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
227 (*pThis->
getUnoI()->pDispatcher)(
228 pThis->
getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
234 for ( ; nTempIndices--; )
236 int nIndex = pTempIndices[nTempIndices];
240 ppTempParamTypeDescr[nTempIndices], 0 );
241 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
243 if (pReturnTypeDescr)
244 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
249 return typelib_TypeClass_VOID;
254 for ( ; nTempIndices--; )
256 int nIndex = pTempIndices[nTempIndices];
258 ppTempParamTypeDescr[nTempIndices];
271 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
276 if (pUnoReturn != pCppReturn)
283 *(
void **)pRegisterReturn = pCppReturn;
285 if (pReturnTypeDescr)
287 typelib_TypeClass eRet =
288 (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
289 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
293 return typelib_TypeClass_VOID;
299 sal_Int32 nVtableOffset,
302 sal_Int64 nRegReturn;
303 sal_Int64 *pRegisterReturn = &nRegReturn;
307 void *pThis = pCallStack[2 + 8];
309 pThis =
static_cast< char *
>(pThis) - nVtableOffset;
314 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->
getTypeDescr();
317 assert( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex );
319 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
324 sal_Int32 nMemberPos =
325 pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
326 assert( nMemberPos < pTypeDescr->nAllMembers );
328 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
330 typelib_TypeClass eRet;
331 switch (aMemberDescr.get()->eTypeClass)
333 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
335 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] ==
340 pCppI, aMemberDescr.get(),
341 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
343 pCallStack, pRegisterReturn );
348 typelib_MethodParameter aParam;
350 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
355 pCppI, aMemberDescr.get(),
358 pCallStack, pRegisterReturn );
362 case typelib_TypeClass_INTERFACE_METHOD:
365 switch (nFunctionIndex)
369 eRet = typelib_TypeClass_VOID;
373 eRet = typelib_TypeClass_VOID;
378 TYPELIB_DANGER_GET(&pTD,
379 reinterpret_cast<Type *
>(pCallStack[2])->getTypeLibType());
385 (
void **)&pInterface, pCppI->
getOid().pData,
386 (typelib_InterfaceTypeDescription *)pTD );
391 reinterpret_cast< uno_Any *
>( pCallStack[0] ),
392 &pInterface, pTD, cpp_acquire );
393 pInterface->release();
394 TYPELIB_DANGER_RELEASE( pTD );
395 *(
void **)pRegisterReturn = pCallStack[0];
396 eRet = typelib_TypeClass_ANY;
399 TYPELIB_DANGER_RELEASE( pTD );
405 pCppI, aMemberDescr.get(),
406 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
407 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
408 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
409 pCallStack, pRegisterReturn );
437 unsigned char *
codeSnippet(
const typelib_InterfaceTypeDescription *type,
439 sal_Int32 functionIndex,
440 sal_Int32 vtableOffset)
459 SAL_INFO(
"bridges",
"codeSnippet(" << OUString(
type->aBase.pTypeName) <<
"::" << OUString(member->pTypeName) <<
"): [" << functionIndex <<
"," << vtableOffset <<
"]=" << (
void *) result <<
" (" << std::hex << ((
int*)result)[0] <<
"," << ((
int*)result)[1] <<
"," << ((
int*)result)[2] <<
"," << ((
int*)result)[3] <<
")");
470 return static_cast< Slot *
>(block) + 2;
476 return (slotCount + 2) *
sizeof (
Slot);
487 void * block, sal_Int32 slotCount, sal_Int32,
488 typelib_InterfaceTypeDescription *)
490 Slot * slots = mapBlockToVtable(block);
492 slots[-1].
fn = &
typeid(ProxyRtti);
493 return slots + slotCount;
498 unsigned char * code,
499 typelib_InterfaceTypeDescription
const * type,
500 sal_Int32 functionOffset,
501 sal_Int32 functionCount,
502 sal_Int32 vtableOffset)
504 (*slots) -= functionCount;
506 for (sal_Int32
i = 0;
i <
type->nMembers; ++
i)
509 TYPELIB_DANGER_GET(&member,
type->ppMembers[
i]);
511 switch (member->eTypeClass)
513 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
515 typelib_InterfaceAttributeTypeDescription *pAttrTD =
516 reinterpret_cast<typelib_InterfaceAttributeTypeDescription *
>( member );
519 (s++)->fn =
codeSnippet(
type, member, functionOffset++, vtableOffset );
522 if (!pAttrTD->bReadOnly)
524 (s++)->fn =
codeSnippet(
type, member, functionOffset++, vtableOffset );
528 case typelib_TypeClass_INTERFACE_METHOD:
530 (s++)->fn =
codeSnippet(
type, member, functionOffset++, vtableOffset );
537 TYPELIB_DANGER_RELEASE(member);
545 unsigned char const *,
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 cpp_vtable_call(sal_Int32 func, sal_Int32 offset, void **pStack)
is called on incoming vtable calls (called by asm snippets)
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_INFO(area, stream)
struct _typelib_TypeDescription typelib_TypeDescription
typelib_TypeClass __cdecl cpp_mediate(void **pCallStack, const sal_Int32 nFunctionIndex, const sal_Int32 nVtableOffset, sal_Int64 *const pRegisterReturn)
void raiseException(uno_Any *pUnoExc, uno_Mapping *pUno2Cpp)
bool return_in_x8(typelib_TypeDescriptionReference *pTypeRef)
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,...