24#include <com/sun/star/uno/genfunc.hxx>
27#include <typelib/typedescription.hxx>
45 typelib_TypeDescriptionReference * pReturnTypeRef,
46 sal_Int32 nParams, typelib_MethodParameter * pParams,
47 void ** gpreg,
void ** fpreg,
void ** ovrflw,
48 sal_Int64 * pRegisterReturn )
63 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
65 void * pUnoReturn = 0;
66 void * pCppReturn = 0;
72 pUnoReturn = pRegisterReturn;
76 pCppReturn = *(
void **)gpreg;
81 ? alloca( pReturnTypeDescr->nSize )
90 static_assert(
sizeof(
void *) ==
sizeof(sal_Int32),
"### unexpected size!");
92 void ** pUnoArgs = (
void **)alloca( 4 *
sizeof(
void *) * nParams );
93 void ** pCppArgs = pUnoArgs + nParams;
95 sal_Int32 * pTempIndices = (sal_Int32 *)(pUnoArgs + (2 * nParams));
99 sal_Int32 nTempIndices = 0;
101 for ( sal_Int32 nPos = 0;
nPos < nParams; ++
nPos )
103 const typelib_MethodParameter & rParam = pParams[
nPos];
105 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
111 switch (pParamTypeDescr->eTypeClass)
114 case typelib_TypeClass_DOUBLE:
117 pCppArgs[
nPos] = fpreg;
118 pUnoArgs[
nPos] = fpreg;
127 pCppArgs[
nPos] = gpreg;
128 pUnoArgs[
nPos] = gpreg;
133 if (((
long)ovrflw) & 4) ovrflw++;
134 pCppArgs[
nPos] = ovrflw;
135 pUnoArgs[
nPos] = ovrflw;
140 case typelib_TypeClass_FLOAT:
145 float tmp = (float) (*((
double *)fpreg));
146 (*((
float *) fpreg)) = tmp;
147 pCppArgs[
nPos] = fpreg;
148 pUnoArgs[
nPos] = fpreg;
153 pCppArgs[
nPos] = gpreg;
154 pUnoArgs[
nPos] = gpreg;
160 if (((
long)ovrflw) & 4) ovrflw++;
161 float tmp = (float) (*((
double *)ovrflw));
162 (*((
float *) ovrflw)) = tmp;
163 pCppArgs[
nPos] = ovrflw;
164 pUnoArgs[
nPos] = ovrflw;
167 pCppArgs[
nPos] = ovrflw;
168 pUnoArgs[
nPos] = ovrflw;
174 case typelib_TypeClass_HYPER:
175 case typelib_TypeClass_UNSIGNED_HYPER:
181 pCppArgs[
nPos] = gpreg;
182 pUnoArgs[
nPos] = gpreg;
186 if (((
long)ovrflw) & 4) ovrflw++;
187 pCppArgs[
nPos] = ovrflw;
188 pUnoArgs[
nPos] = ovrflw;
193 case typelib_TypeClass_BYTE:
194 case typelib_TypeClass_BOOLEAN:
196 pCppArgs[
nPos] = (((
char *)gpreg) + 3);
197 pUnoArgs[
nPos] = (((
char *)gpreg) + 3);
201 pCppArgs[
nPos] = (((
char *)ovrflw) + 3);
202 pUnoArgs[
nPos] = (((
char *)ovrflw) + 3);
208 case typelib_TypeClass_CHAR:
209 case typelib_TypeClass_SHORT:
210 case typelib_TypeClass_UNSIGNED_SHORT:
212 pCppArgs[
nPos] = (((
char *)gpreg)+ 2);
213 pUnoArgs[
nPos] = (((
char *)gpreg)+ 2);
217 pCppArgs[
nPos] = (((
char *)ovrflw) + 2);
218 pUnoArgs[
nPos] = (((
char *)ovrflw) + 2);
226 pCppArgs[
nPos] = gpreg;
227 pUnoArgs[
nPos] = gpreg;
231 pCppArgs[
nPos] = ovrflw;
232 pUnoArgs[
nPos] = ovrflw;
239 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
245 pCppArgs[
nPos] = *(
void **)gpreg;
250 pCppArgs[
nPos] = *(
void **)ovrflw;
258 pUnoArgs[
nPos] = alloca( pParamTypeDescr->nSize );
259 pTempIndices[nTempIndices] =
nPos;
261 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
267 *(
void **)pCppStack, pParamTypeDescr,
269 pTempIndices[nTempIndices] =
nPos;
271 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
275 pUnoArgs[
nPos] = *(
void **)pCppStack;
277 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
287 (*pThis->
getUnoI()->pDispatcher)( pThis->
getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
293 for ( ; nTempIndices--; )
295 sal_Int32
nIndex = pTempIndices[nTempIndices];
297 if (pParams[nIndex].bIn)
298 uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndices], 0 );
299 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
301 if (pReturnTypeDescr)
302 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
307 return typelib_TypeClass_VOID;
312 for ( ; nTempIndices--; )
314 sal_Int32
nIndex = pTempIndices[nTempIndices];
317 if (pParams[nIndex].bOut)
327 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
332 if (pUnoReturn != pCppReturn)
340 *(
void **)pRegisterReturn = pCppReturn;
342 if (pReturnTypeDescr)
344 typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
345 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
349 return typelib_TypeClass_VOID;
355 sal_Int32 nFunctionIndex,
356 sal_Int32 nVtableOffset,
357 void ** gpreg,
void ** fpreg,
void ** ovrflw,
358 sal_Int64 * pRegisterReturn )
360 static_assert(
sizeof(sal_Int32)==
sizeof(
void *),
"### unexpected!");
367 if (nFunctionIndex & 0x80000000 )
369 nFunctionIndex &= 0x7fffffff;
377 pThis =
static_cast< char *
>(pThis) - nVtableOffset;
382 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->
getTypeDescr();
384 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
388 "illegal " << OUString::unacquired(&pTypeDescr->aBase.pTypeName)
389 <<
" vtable index " << nFunctionIndex <<
"/"
390 << pTypeDescr->nMapFunctionIndexToMemberIndex);
392 (
"illegal " + OUString::unacquired(&pTypeDescr->aBase.pTypeName)
393 +
" vtable index " + OUString::number(nFunctionIndex) +
"/"
394 + OUString::number(pTypeDescr->nMapFunctionIndexToMemberIndex)),
399 sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
400 assert(nMemberPos < pTypeDescr->nAllMembers);
402 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
404 typelib_TypeClass eRet;
405 switch (aMemberDescr.get()->eTypeClass)
407 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
409 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
413 pCppI, aMemberDescr.get(),
414 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
416 gpreg, fpreg, ovrflw, pRegisterReturn );
421 typelib_MethodParameter aParam;
423 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
428 pCppI, aMemberDescr.get(),
431 gpreg, fpreg, ovrflw, pRegisterReturn );
435 case typelib_TypeClass_INTERFACE_METHOD:
438 switch (nFunctionIndex)
442 eRet = typelib_TypeClass_VOID;
446 eRet = typelib_TypeClass_VOID;
451 TYPELIB_DANGER_GET( &pTD,
reinterpret_cast< Type *
>( gpreg[2] )->getTypeLibType() );
457 (
void **)&pInterface, pCppI->
getOid().pData,
458 (typelib_InterfaceTypeDescription *)pTD );
463 reinterpret_cast< uno_Any *
>( gpreg[0] ),
464 &pInterface, pTD, cpp_acquire );
465 pInterface->release();
466 TYPELIB_DANGER_RELEASE( pTD );
467 *(
void **)pRegisterReturn = gpreg[0];
468 eRet = typelib_TypeClass_ANY;
471 TYPELIB_DANGER_RELEASE( pTD );
476 pCppI, aMemberDescr.get(),
477 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
478 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
479 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
480 gpreg, fpreg, ovrflw, pRegisterReturn );
497static void cpp_vtable_call(
int nFunctionIndex,
int nVtableOffset,
void** gpregptr,
void** fpregptr,
void** ovrflw)
500 memcpy( gpreg, gpregptr, 32);
504 memcpy( fpreg, fpregptr, 64);
507 volatile long nRegReturn[2];
513 typelib_TypeClass aType =
514 cpp_mediate( nFunctionIndex, nVtableOffset, (
void**)gpreg,
520 ovrflw, (sal_Int64*)nRegReturn );
528 case typelib_TypeClass_BOOLEAN:
529 case typelib_TypeClass_BYTE:
531 "m"(nRegReturn[0]) );
534 case typelib_TypeClass_CHAR:
535 case typelib_TypeClass_SHORT:
536 case typelib_TypeClass_UNSIGNED_SHORT:
538 "m"(nRegReturn[0]) );
541 case typelib_TypeClass_FLOAT:
544 "m" (*((
float*)nRegReturn)) );
547 "m"(nRegReturn[0]) );
551 case typelib_TypeClass_DOUBLE:
554 "m" (*((
double*)nRegReturn)) );
557 "m"(nRegReturn[0]) );
559 "m"(nRegReturn[1]) );
563 case typelib_TypeClass_HYPER:
564 case typelib_TypeClass_UNSIGNED_HYPER:
566 "m"(nRegReturn[1]) );
570 "m"(nRegReturn[0]) );
578unsigned char *
codeSnippet(
unsigned char * code, sal_Int32 functionIndex, sal_Int32 vtableOffset,
586 if (! simpleRetType )
587 functionIndex |= 0x80000000;
589 unsigned long *
p = (
unsigned long *) code;
592 assert((((
unsigned long)code) & 0x3) == 0 );
674 *
p++ = 0x3c600000 | (((
unsigned long)functionIndex) >> 16);
675 *
p++ = 0x60630000 | (((
unsigned long)functionIndex) & 0x0000FFFF);
676 *
p++ = 0x3c800000 | (((
unsigned long)vtableOffset) >> 16);
677 *
p++ = 0x60840000 | (((
unsigned long)vtableOffset) & 0x0000FFFF);
695 int const lineSize = 32;
696 for (
unsigned char const *
p = bptr;
p < eptr + lineSize;
p += lineSize) {
697 __asm__ volatile (
"dcbst 0, %0" : :
"r"(
p) :
"memory");
699 __asm__ volatile (
"sync" : : :
"memory");
700 for (
unsigned char const *
p = bptr;
p < eptr + lineSize;
p += lineSize) {
701 __asm__ volatile (
"icbi 0, %0" : :
"r"(
p) :
"memory");
703 __asm__ volatile (
"isync" : : :
"memory");
711 return static_cast< Slot *
>(block) + 2;
728 void * block, sal_Int32 slotCount, sal_Int32,
729 typelib_InterfaceTypeDescription *)
731 Slot * slots = mapBlockToVtable(block);
733 slots[-1].fn = &
typeid(ProxyRtti);
734 return slots + slotCount;
738 Slot ** slots,
unsigned char * code, sal_PtrDiff writetoexecdiff,
739 typelib_InterfaceTypeDescription
const * type, sal_Int32 functionOffset,
740 sal_Int32 functionCount, sal_Int32 vtableOffset)
742 (*slots) -= functionCount;
748 for (sal_Int32 i = 0;
i <
type->nMembers; ++
i) {
750 TYPELIB_DANGER_GET(&member,
type->ppMembers[i]);
752 switch (member->eTypeClass) {
753 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
755 (s++)->fn = code + writetoexecdiff;
757 code, functionOffset++, vtableOffset,
760 typelib_InterfaceAttributeTypeDescription *
>(
761 member)->pAttributeTypeRef));
764 if (!
reinterpret_cast<
765 typelib_InterfaceAttributeTypeDescription *
>(
768 (s++)->fn = code + writetoexecdiff;
773 case typelib_TypeClass_INTERFACE_METHOD:
774 (s++)->fn = code + writetoexecdiff;
776 code, functionOffset++, vtableOffset,
779 typelib_InterfaceMethodTypeDescription *
>(
780 member)->pReturnTypeRef));
787 TYPELIB_DANGER_RELEASE(member);
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)
register sal_uInt32 r28 __asm__("%r28")
const int codeSnippetSize
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
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 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,...