27#include <com/sun/star/uno/Exception.hpp>
28#include <com/sun/star/uno/RuntimeException.hpp>
29#include <com/sun/star/uno/genfunc.hxx>
45void pushArgs(
unsigned long value,
unsigned long*
const stack, sal_Int32*
const sp,
46 unsigned long*
const regs, sal_Int32*
const nregs)
48 (*nregs != 8 ? regs[(*nregs)++] : stack[(*sp)++]) = value;
51static void callVirtualMethod(
void* pAdjustedThisPtr, sal_Int32 nVtableIndex,
void* pRegisterReturn,
52 typelib_TypeDescriptionReference* pReturnTypeRef,
bool bSimpleReturn,
53 sal_uInt64* pStack, sal_uInt32 nStack, sal_uInt64* pGPR,
double* pFPR)
56 sal_uInt64 pMethod = *((sal_uInt64*)pAdjustedThisPtr);
57 pMethod += 8 * nVtableIndex;
58 void* mfunc = (
void*)*((sal_uInt64*)pMethod);
60 sal_uInt64* pCallStack =
NULL;
64 sal_uInt32 nStackBytes = ((nStack + 1) >> 1) * 16;
65 pCallStack = (sal_uInt64*)__builtin_alloca(nStackBytes);
66 std::memcpy(pCallStack, pStack, nStackBytes);
73 "ld.d $r4,%[gpr],0 \n\t"
74 "ld.d $r5,%[gpr],8 \n\t"
75 "ld.d $r6,%[gpr],16 \n\t"
76 "ld.d $r7,%[gpr],24 \n\t"
77 "ld.d $r8,%[gpr],32 \n\t"
78 "ld.d $r9,%[gpr],40 \n\t"
79 "ld.d $r10,%[gpr],48 \n\t"
80 "ld.d $r11,%[gpr],56 \n\t"
82 "fld.d $f0,%[fpr],0 \n\t"
83 "fld.d $f1,%[fpr],8 \n\t"
84 "fld.d $f2,%[fpr],16 \n\t"
85 "fld.d $f3,%[fpr],24 \n\t"
86 "fld.d $f4,%[fpr],32 \n\t"
87 "fld.d $f5,%[fpr],40 \n\t"
88 "fld.d $f6,%[fpr],48 \n\t"
89 "fld.d $f7,%[fpr],56 \n\t"
91 "jirl $ra,%[mfunc],0 \n\t"
93 "move %[gret1], $a0 \n\t"
94 "move %[gret2], $a1 \n\t"
95 "fmov.d %[fret1], $f0 \n\t"
96 "fmov.d %[fret2], $f1 \n\t"
97 : [gret1]
"=r"(gret[0]), [gret2]
"=r"(gret[1]), [fret1]
"=f"(fret[0]), [fret2]
"=f"(fret[1])
98 : [gpr]
"r"(pGPR), [fpr]
"r"(pFPR), [mfunc]
"r"(mfunc),
101 :
"$r4",
"$r5",
"$r6",
"$r7",
"$r8",
"$r9",
"$r10",
"$r11",
"$r1",
"$f0",
"$f1",
"$f2",
102 "$f3",
"$f4",
"$f5",
"$f6",
"$f7",
"memory");
104 switch (pReturnTypeRef->eTypeClass)
106 case typelib_TypeClass_HYPER:
107 case typelib_TypeClass_UNSIGNED_HYPER:
108 case typelib_TypeClass_LONG:
109 case typelib_TypeClass_UNSIGNED_LONG:
110 case typelib_TypeClass_ENUM:
111 case typelib_TypeClass_CHAR:
112 case typelib_TypeClass_SHORT:
113 case typelib_TypeClass_UNSIGNED_SHORT:
114 case typelib_TypeClass_BOOLEAN:
115 case typelib_TypeClass_BYTE:
116 *
reinterpret_cast<sal_Int64*
>(pRegisterReturn) = gret[0];
118 case typelib_TypeClass_FLOAT:
119 case typelib_TypeClass_DOUBLE:
120 *
reinterpret_cast<double*
>(pRegisterReturn) = fret[0];
122 case typelib_TypeClass_STRUCT:
123 case typelib_TypeClass_EXCEPTION:
125 sal_Int32
const nRetSize = pReturnTypeRef->pType->nSize;
126 if (bSimpleReturn && nRetSize <= 16 && nRetSize > 0)
139 typelib_TypeDescriptionReference* pReturnTypeRef, sal_Int32 nParams,
140 typelib_MethodParameter* pParams,
void* pUnoReturn,
void* pUnoArgs[],
144 sal_uInt64* pStack = (sal_uInt64*)__builtin_alloca(((nParams + 3) *
sizeof(sal_Int64)));
145 sal_uInt64* pStackStart = pStack;
149 sal_Int32 gCount = 0;
151 sal_Int32 fCount = 0;
155 TYPELIB_DANGER_GET(&pReturnTypeDescr, pReturnTypeRef);
156 assert(pReturnTypeDescr);
158 void* pCppReturn = 0;
160 bool bSimpleReturn =
true;
161 if (pReturnTypeDescr)
165 bSimpleReturn =
false;
168 ? __builtin_alloca(pReturnTypeDescr->nSize)
170 pGPR[gCount++] =
reinterpret_cast<unsigned long>(pCppReturn);
174 pCppReturn = pUnoReturn;
179 void* pAdjustedThisPtr =
reinterpret_cast<void**
>(pThis->
getCppI()) + aVtableSlot.
offset;
180 pGPR[gCount++] =
reinterpret_cast<unsigned long>(pAdjustedThisPtr);
183 void** pCppArgs = (
void**)alloca(3 *
sizeof(
void*) * nParams);
185 sal_Int32* pTempIndices = (sal_Int32*)(pCppArgs + nParams);
190 sal_Int32 nTempIndices = 0;
192 for (sal_Int32 nPos = 0;
nPos < nParams; ++
nPos)
194 const typelib_MethodParameter& rParam = pParams[
nPos];
196 TYPELIB_DANGER_GET(&pParamTypeDescr, rParam.pTypeRef);
203 switch (pParamTypeDescr->eTypeClass)
205 case typelib_TypeClass_LONG:
206 case typelib_TypeClass_ENUM:
207 pushArgs(*
static_cast<sal_Int32*
>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
209 case typelib_TypeClass_UNSIGNED_LONG:
210 pushArgs(*
static_cast<sal_uInt32*
>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
212 case typelib_TypeClass_CHAR:
213 pushArgs(*
static_cast<sal_Unicode*
>(pCppArgs[nPos]), pStack, &sp, pGPR,
216 case typelib_TypeClass_SHORT:
217 pushArgs(*
static_cast<sal_Int16*
>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
219 case typelib_TypeClass_UNSIGNED_SHORT:
220 pushArgs(*
static_cast<sal_uInt16*
>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
222 case typelib_TypeClass_BOOLEAN:
223 pushArgs(
static_cast<unsigned long>(*
static_cast<sal_Bool*
>(pCppArgs[nPos])),
224 pStack, &sp, pGPR, &gCount);
226 case typelib_TypeClass_BYTE:
227 pushArgs(*
static_cast<sal_Int8*
>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
229 case typelib_TypeClass_FLOAT:
230 case typelib_TypeClass_DOUBLE:
233 pFPR[fCount++] = *
static_cast<double*
>(pCppArgs[
nPos]);
237 pGPR[gCount++] = *
static_cast<unsigned long*
>(pCppArgs[
nPos]);
241 pStack[sp++] = *
static_cast<unsigned long*
>(pCppArgs[
nPos]);
244 case typelib_TypeClass_HYPER:
245 pushArgs(*
static_cast<sal_Int64*
>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
247 case typelib_TypeClass_UNSIGNED_HYPER:
248 pushArgs(*
static_cast<sal_uInt64*
>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
255 TYPELIB_DANGER_RELEASE(pParamTypeDescr);
262 uno_constructData(pCppArgs[nPos] = alloca(pParamTypeDescr->nSize), pParamTypeDescr);
263 pTempIndices[nTempIndices] =
nPos;
265 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
271 pUnoArgs[nPos], pParamTypeDescr,
274 pTempIndices[nTempIndices] =
nPos;
276 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
282 TYPELIB_DANGER_RELEASE(pParamTypeDescr);
284 pushArgs(
reinterpret_cast<unsigned long>(pCppArgs[nPos]), pStack, &sp, pGPR, &gCount);
293 bSimpleReturn, pStackStart, sp, pGPR, pFPR);
295 catch (css::uno::Exception&)
299 catch (std::exception& e)
301 throw css::uno::RuntimeException(
"C++ code threw "
307 throw css::uno::RuntimeException(
"C++ code threw unknown exception");
313 for (; nTempIndices--;)
315 sal_Int32
nIndex = pTempIndices[nTempIndices];
318 if (pParams[nIndex].bIn)
320 if (pParams[nIndex].bOut)
335 TYPELIB_DANGER_RELEASE(pParamTypeDescr);
338 if (pCppReturn && pUnoReturn != pCppReturn)
351 for (; nTempIndices--;)
353 sal_Int32
nIndex = pTempIndices[nTempIndices];
355 uno_destructData(pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndices], cpp_release);
356 TYPELIB_DANGER_RELEASE(ppTempParamTypeDescr[nTempIndices]);
359 if (pReturnTypeDescr)
360 TYPELIB_DANGER_RELEASE(pReturnTypeDescr);
368 void* pReturn,
void* pArgs[],
uno_Any** ppException)
375 switch (pMemberDescr->eTypeClass)
377 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
380 reinterpret_cast<typelib_InterfaceAttributeTypeDescription const*
>(pMemberDescr)));
387 ((typelib_InterfaceAttributeTypeDescription*)pMemberDescr)->pAttributeTypeRef,
389 pReturn, pArgs, ppException);
394 typelib_MethodParameter aParam;
396 = ((typelib_InterfaceAttributeTypeDescription*)pMemberDescr)->pAttributeTypeRef;
400 typelib_TypeDescriptionReference* pReturnTypeRef = 0;
401 OUString aVoidName(
"void");
406 aVtableSlot.
index += 1;
407 cpp_call(pThis, aVtableSlot, pReturnTypeRef, 1, &aParam, pReturn, pArgs,
415 case typelib_TypeClass_INTERFACE_METHOD:
418 reinterpret_cast<typelib_InterfaceMethodTypeDescription const*
>(pMemberDescr)));
419 switch (aVtableSlot.
index)
423 (*pUnoI->acquire)(pUnoI);
427 (*pUnoI->release)(pUnoI);
433 TYPELIB_DANGER_GET(&pTD,
reinterpret_cast<Type*
>(pArgs[0])->getTypeLibType());
436 uno_Interface* pInterface = 0;
439 (typelib_InterfaceTypeDescription*)pTD);
443 ::uno_any_construct(
reinterpret_cast<uno_Any*
>(pReturn), &pInterface,
445 (*pInterface->release)(pInterface);
446 TYPELIB_DANGER_RELEASE(pTD);
450 TYPELIB_DANGER_RELEASE(pTD);
457 ((typelib_InterfaceMethodTypeDescription*)pMemberDescr)->pReturnTypeRef,
458 ((typelib_InterfaceMethodTypeDescription*)pMemberDescr)->nParams,
459 ((typelib_InterfaceMethodTypeDescription*)pMemberDescr)->pParams, pReturn,
466 ::com::sun::star::uno::RuntimeException aExc(
467 "illegal member type description!",
472 ::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))
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()