27#include <com/sun/star/uno/Exception.hpp>
28#include <com/sun/star/uno/RuntimeException.hpp>
29#include <com/sun/star/uno/genfunc.hxx>
47#define INSERT_FLOAT_DOUBLE(pSV, nfr, pFPR, ngr, pGPR, pDS) \
48 if (nfr < MAX_FP_REGS) \
49 pFPR[nfr++] = *reinterpret_cast<double*>(pSV); \
50 else if (ngr < MAX_FP_REGS) \
51 pGPR[ngr++] = *reinterpret_cast<sal_Int64*>(pSV); \
53 *pDS++ = *reinterpret_cast<sal_uInt64*>(pSV);
55#define INSERT_INT64(pSV, nr, pGPR, pDS) \
56 if (nr < MAX_GP_REGS) \
57 pGPR[nr++] = *reinterpret_cast<sal_Int64*>(pSV); \
59 *pDS++ = *reinterpret_cast<sal_Int64*>(pSV);
61#define INSERT_INT32(pSV, nr, pGPR, pDS) \
62 if (nr < MAX_GP_REGS) \
63 pGPR[nr++] = *reinterpret_cast<sal_Int32*>(pSV); \
65 *pDS++ = *reinterpret_cast<sal_Int32*>(pSV);
67#define INSERT_INT16(pSV, nr, pGPR, pDS) \
68 if (nr < MAX_GP_REGS) \
69 pGPR[nr++] = *reinterpret_cast<sal_Int16*>(pSV); \
71 *pDS++ = *reinterpret_cast<sal_Int16*>(pSV);
73#define INSERT_UINT16(pSV, nr, pGPR, pDS) \
74 if (nr < MAX_GP_REGS) \
75 pGPR[nr++] = *reinterpret_cast<sal_uInt16*>(pSV); \
77 *pDS++ = *reinterpret_cast<sal_uInt16*>(pSV);
79#define INSERT_INT8(pSV, nr, pGPR, pDS) \
80 if (nr < MAX_GP_REGS) \
81 pGPR[nr++] = *reinterpret_cast<sal_Int8*>(pSV); \
83 *pDS++ = *reinterpret_cast<sal_Int8*>(pSV);
92 printf(
"In isReturnInFPR, pTypeDescr = %p, nSize = %d\n", pTypeDescr, nSize);
94 const typelib_CompoundTypeDescription*
p
95 =
reinterpret_cast<const typelib_CompoundTypeDescription*
>(pTypeDescr);
97 for (sal_Int32
i = 0;
i <
p->nMembers; ++
i)
99 typelib_TypeDescriptionReference* pTypeInStruct =
p->ppTypeRefs[
i];
101 switch (pTypeInStruct->eTypeClass)
103 case typelib_TypeClass_STRUCT:
104 case typelib_TypeClass_EXCEPTION:
107 TYPELIB_DANGER_GET(&
t, pTypeInStruct);
108 bool isFPR = isReturnInFPR(
t, nSize);
109 TYPELIB_DANGER_RELEASE(
t);
114 case typelib_TypeClass_FLOAT:
115 case typelib_TypeClass_DOUBLE:
128 void* pRegisterReturn)
131 printf(
"In fillReturn, pTypeDescr = %p, gret = %p, fret = %p, pRegisterReturn = %p\n",
132 pTypeDescr, gret, fret, pRegisterReturn);
134 sal_uInt32 nSize = 0;
135 if (isReturnInFPR(pTypeDescr, nSize))
137 reinterpret_cast<double*
>(pRegisterReturn)[0] = fret[0];
138 reinterpret_cast<double*
>(pRegisterReturn)[1] = fret[1];
142 reinterpret_cast<sal_Int64*
>(pRegisterReturn)[0] = gret[0];
143 reinterpret_cast<sal_Int64*
>(pRegisterReturn)[1] = gret[1];
147static void callVirtualMethod(
void* pAdjustedThisPtr, sal_Int32 nVtableIndex,
void* pRegisterReturn,
148 typelib_TypeDescriptionReference* pReturnTypeRef,
bool bSimpleReturn,
149 sal_uInt64* pStack, sal_uInt32 nStack, sal_uInt64* pGPR,
double* pFPR,
153 printf(
"In callVirtualMethod:\n");
154 printf(
"pAdjustedThisPtr = %p, nVtableIndex = %d, pRegisterReturn = %p, pReturnTypeRef = %p\n",
155 pAdjustedThisPtr, nVtableIndex, pRegisterReturn, pReturnTypeRef);
156 printf(
"bSimpleReturn = %d, pStack = %p, nStack = %d, pGPR = %p, pFPR = %p, pReturnTypeDescr = "
158 bSimpleReturn, pStack, nStack, pGPR, pFPR, pReturnTypeDescr);
161 sal_uInt64 pMethod = *((sal_uInt64*)pAdjustedThisPtr);
162 pMethod += 8 * nVtableIndex;
163 void* mfunc = (
void*)*((sal_uInt64*)pMethod);
165 fprintf(stdout,
"calling function %p\n", mfunc);
169 sal_uInt64* pCallStack =
NULL;
173 sal_uInt32 nStackBytes = ((nStack + 1) >> 1) * 16;
174 pCallStack = (sal_uInt64*)__builtin_alloca(nStackBytes);
175 std::memcpy(pCallStack, pStack, nStackBytes);
178 sal_Int64* gret = (sal_Int64*)malloc(2 *
sizeof(sal_Int64));
179 sal_Int64* gret1 = gret;
180 sal_Int64* gret2 = gret + 1;
181 double* fret = (
double*)malloc(2 *
sizeof(
double));
182 double* fret1 = fret;
183 double* fret2 = fret + 1;
188 "ld a0, 0(%[gpr]) \n\t"
189 "ld a1, 8(%[gpr]) \n\t"
190 "ld a2, 16(%[gpr]) \n\t"
191 "ld a3, 24(%[gpr]) \n\t"
192 "ld a4, 32(%[gpr]) \n\t"
193 "ld a5, 40(%[gpr]) \n\t"
194 "ld a6, 48(%[gpr]) \n\t"
195 "ld a7, 56(%[gpr]) \n\t"
197 "fld fa0, 0(%[fpr]) \n\t"
198 "fld fa1, 8(%[fpr]) \n\t"
199 "fld fa2, 16(%[fpr]) \n\t"
200 "fld fa3, 24(%[fpr]) \n\t"
201 "fld fa4, 32(%[fpr]) \n\t"
202 "fld fa5, 40(%[fpr]) \n\t"
203 "fld fa6, 48(%[fpr]) \n\t"
204 "fld fa7, 56(%[fpr]) \n\t"
206 "jalr ra,%[mfunc],0 \n\t"
208 "add %[gret1], a0,zero \n\t"
209 "add %[gret2], a1,zero \n\t"
210 "fmv.d %[fret1], fa0 \n\t"
211 "fmv.d %[fret2], fa1 \n\t"
213 : [gret1]
"=&r"(*gret1), [gret2]
"=&r"(*gret2), [fret1]
"=&f"(*fret1), [fret2]
"=&f"(*fret2)
214 : [gpr]
"r"(pGPR), [fpr]
"r"(pFPR), [mfunc]
"r"(mfunc),
217 :
"a0",
"a1",
"a2",
"a3",
"a4",
"a5",
"a6",
"a7",
"ra",
"fa0",
"fa1",
"fa2",
"fa3",
"fa4",
218 "fa5",
"fa6",
"fa7",
"memory");
220 printf(
"In callVirtualMethod, fret = %p, gret = %p\n", fret, gret);
223 switch (pReturnTypeRef->eTypeClass)
225 case typelib_TypeClass_HYPER:
226 case typelib_TypeClass_UNSIGNED_HYPER:
227 case typelib_TypeClass_LONG:
228 case typelib_TypeClass_UNSIGNED_LONG:
229 case typelib_TypeClass_ENUM:
230 case typelib_TypeClass_CHAR:
231 case typelib_TypeClass_SHORT:
232 case typelib_TypeClass_UNSIGNED_SHORT:
233 case typelib_TypeClass_BOOLEAN:
234 case typelib_TypeClass_BYTE:
235 *
reinterpret_cast<sal_Int64*
>(pRegisterReturn) = gret[0];
237 case typelib_TypeClass_FLOAT:
238 case typelib_TypeClass_DOUBLE:
239 *
reinterpret_cast<double*
>(pRegisterReturn) = fret[0];
241 case typelib_TypeClass_STRUCT:
242 case typelib_TypeClass_EXCEPTION:
244 sal_Int32
const nRetSize = pReturnTypeRef->pType->nSize;
246 printf(
"nRetSize = %d\n", nRetSize);
248 if (bSimpleReturn && nRetSize <= 16 && nRetSize > 0)
251 TYPELIB_DANGER_GET(&pTypeDescr, pReturnTypeRef);
253 TYPELIB_DANGER_RELEASE(pTypeDescr);
259 fprintf(stdout,
"unhandled return type %u\n", pReturnTypeRef->eTypeClass);
267 typelib_TypeDescriptionReference* pReturnTypeRef, sal_Int32 nParams,
268 typelib_MethodParameter* pParams,
void* pUnoReturn,
void* pUnoArgs[],
272 printf(
"In cpp_call\n");
273 printf(
"pThis = %p, aVtableSlot = %p, pReturnTypeRef = %p, nParams = %d\n", pThis, aVtableSlot,
274 pReturnTypeRef, nParams);
275 printf(
"pParams = %p , pUnoReturn = %p, pUnoArgs = %p\n", pParams, pUnoReturn, pUnoArgs);
278 sal_uInt64* pStack = (sal_uInt64*)__builtin_alloca(((nParams + 3) *
sizeof(sal_Int64)));
279 sal_uInt64* pStackStart = pStack;
287 printf(
"pGPR = %p, pFPR = %p\n", pGPR, pFPR);
292 TYPELIB_DANGER_GET(&pReturnTypeDescr, pReturnTypeRef);
293 assert(pReturnTypeDescr);
295 void* pCppReturn = 0;
297 bool bSimpleReturn =
true;
298 if (pReturnTypeDescr)
302 bSimpleReturn =
false;
305 ? __builtin_alloca(pReturnTypeDescr->nSize)
311 pCppReturn = pUnoReturn;
316 void* pAdjustedThisPtr =
reinterpret_cast<void**
>(pThis->
getCppI()) + aVtableSlot.
offset;
320 void** pCppArgs = (
void**)alloca(3 *
sizeof(
void*) * nParams);
322 sal_Int32* pTempIndices = (sal_Int32*)(pCppArgs + nParams);
327 sal_Int32 nTempIndices = 0;
329 printf(
"In cpp_call, nParams = %d\n", nParams);
330 printf(
"pCppArgs = %p, pStack = %p\n", pCppArgs, pStack);
335 printf(
"In cpp_call, nPos = %d\n",
nPos);
337 const typelib_MethodParameter& rParam = pParams[
nPos];
339 TYPELIB_DANGER_GET(&pParamTypeDescr, rParam.pTypeRef);
344 printf(
"Before uno_copyAndConvertData and tons of switch.\n");
349 printf(
"Type = %d, Param = 0x%lx\n", pParamTypeDescr->eTypeClass,
350 *
reinterpret_cast<sal_uInt64*
>(pCppArgs[
nPos]));
352 switch (pParamTypeDescr->eTypeClass)
354 case typelib_TypeClass_LONG:
355 case typelib_TypeClass_UNSIGNED_LONG:
356 case typelib_TypeClass_ENUM:
359 case typelib_TypeClass_CHAR:
360 case typelib_TypeClass_SHORT:
363 case typelib_TypeClass_UNSIGNED_SHORT:
366 case typelib_TypeClass_BOOLEAN:
367 case typelib_TypeClass_BYTE:
370 case typelib_TypeClass_FLOAT:
371 case typelib_TypeClass_DOUBLE:
374 case typelib_TypeClass_HYPER:
375 case typelib_TypeClass_UNSIGNED_HYPER:
383 TYPELIB_DANGER_RELEASE(pParamTypeDescr);
391 pTempIndices[nTempIndices] =
nPos;
393 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
399 pUnoArgs[
nPos], pParamTypeDescr,
402 pTempIndices[nTempIndices] =
nPos;
404 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
410 TYPELIB_DANGER_RELEASE(pParamTypeDescr);
421 bSimpleReturn, pStackStart, (pStack - pStackStart), pGPR, pFPR,
424 catch (css::uno::Exception&)
428 catch (std::exception& e)
430 throw css::uno::RuntimeException(
"C++ code threw "
436 throw css::uno::RuntimeException(
"C++ code threw unknown exception");
442 for (; nTempIndices--;)
444 sal_Int32
nIndex = pTempIndices[nTempIndices];
464 TYPELIB_DANGER_RELEASE(pParamTypeDescr);
467 if (pCppReturn && pUnoReturn != pCppReturn)
480 for (; nTempIndices--;)
482 sal_Int32
nIndex = pTempIndices[nTempIndices];
485 TYPELIB_DANGER_RELEASE(ppTempParamTypeDescr[nTempIndices]);
488 if (pReturnTypeDescr)
489 TYPELIB_DANGER_RELEASE(pReturnTypeDescr);
497 void* pReturn,
void* pArgs[],
uno_Any** ppException)
500 printf(
"In unoInterfaceProxyDispatch:\n");
501 printf(
"pMemberDescr = %p, pReturn = %p, pArgs = %p, ppExeption = %p\n", pMemberDescr, pReturn,
510 fprintf(stdout,
"in dispatch\n");
513 switch (pMemberDescr->eTypeClass)
515 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
518 reinterpret_cast<typelib_InterfaceAttributeTypeDescription const*
>(pMemberDescr)));
525 ((typelib_InterfaceAttributeTypeDescription*)pMemberDescr)->pAttributeTypeRef,
527 pReturn, pArgs, ppException);
532 typelib_MethodParameter aParam;
534 = ((typelib_InterfaceAttributeTypeDescription*)pMemberDescr)->pAttributeTypeRef;
538 typelib_TypeDescriptionReference* pReturnTypeRef = 0;
539 OUString aVoidName(
"void");
544 aVtableSlot.index += 1;
545 cpp_call(pThis, aVtableSlot, pReturnTypeRef, 1, &aParam, pReturn, pArgs,
553 case typelib_TypeClass_INTERFACE_METHOD:
556 reinterpret_cast<typelib_InterfaceMethodTypeDescription const*
>(pMemberDescr)));
557 switch (aVtableSlot.index)
561 (*pUnoI->acquire)(pUnoI);
565 (*pUnoI->release)(pUnoI);
571 TYPELIB_DANGER_GET(&pTD,
reinterpret_cast<Type*
>(pArgs[0])->getTypeLibType());
574 uno_Interface* pInterface = 0;
577 (typelib_InterfaceTypeDescription*)pTD);
581 ::uno_any_construct(
reinterpret_cast<uno_Any*
>(pReturn), &pInterface,
583 (*pInterface->release)(pInterface);
584 TYPELIB_DANGER_RELEASE(pTD);
588 TYPELIB_DANGER_RELEASE(pTD);
595 ((typelib_InterfaceMethodTypeDescription*)pMemberDescr)->pReturnTypeRef,
596 ((typelib_InterfaceMethodTypeDescription*)pMemberDescr)->nParams,
597 ((typelib_InterfaceMethodTypeDescription*)pMemberDescr)->pParams, pReturn,
604 ::com::sun::star::uno::RuntimeException aExc(
605 "illegal member type description!",
610 ::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_INT8(pSV, nr, pGPR, pDS)
#define INSERT_FLOAT_DOUBLE(pSV, nfr, pFPR, ngr, 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 fillStruct(const typelib_TypeDescription *pTypeDescr, sal_Int64 *gret, double *fret, void *pRegisterReturn)
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()