/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ #include <com/sun/star/uno/genfunc.hxx> #include <sal/log.hxx> #include <typelib/typedescription.hxx> #include <uno/data.h> #include <osl/endian.h> #include"bridge.hxx" #include"cppinterfaceproxy.hxx" #include"types.hxx" #include"vtablefactory.hxx" #include"share.hxx"
static typelib_TypeClass cpp2uno_call(
bridges::cpp_uno::shared::CppInterfaceProxy * pThis, const typelib_TypeDescription * pMemberTypeDescr,
typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
sal_Int32 nParams, typelib_MethodParameter * pParams, void ** gpreg, void ** /*fpreg*/, void ** ovrflw,
sal_Int64 * pRegisterReturn /* space for register return */ )
{ /* Most MIPS ABIs view the arguments as a struct, of which the first N words go in registers and the rest go on the stack. If I < N, the Ith word might go in Ith integer argument register or the Ith floating-point one. For these ABIs, we only need to remember the number of words passed so far. We are interested only in o32 ABI,so it is the case.
*/ int nw = 0; // number of words used by arguments
/* C++ has [ret *] or this as the first arguments, so no arguments will * be passed in floating-point registers?
*/ //int int_seen = 0; // have we seen integer arguments?
if (! rParam.bIn) // is pure out
{ // uno out is unconstructed mem!
pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
pTempIndices[nTempIndices] = nPos; // will be released at reconversion
ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
} // is in/inout elseif (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
{
uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
*(void **)pCppStack, pParamTypeDescr,
pThis->getBridge()->getCpp2Uno() );
pTempIndices[nTempIndices] = nPos; // has to be reconverted // will be released at reconversion
ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr; #ifdef BRDEBUG
fprintf(stderr,"cpp2uno_call:related to interface,%p,%d,pUnoargs[%d]=%p\n",*(void**)pCppStack,pParamTypeDescr->nSize,nPos,pUnoArgs[nPos]); #endif
} else// direct way
{
pUnoArgs[nPos] = *(void **)pCppStack; #ifdef BRDEBUG
fprintf(stderr,"cpp2uno_call:direct,pUnoArgs[%d]=%p\n",nPos,pUnoArgs[nPos]); #endif // no longer needed
TYPELIB_DANGER_RELEASE( pParamTypeDescr );
}
}
} #ifdef BRDEBUG
fprintf(stderr,"cpp2uno_call2,%p,unoargs=%p\n",pThis->getUnoI()->pDispatcher,pUnoArgs); #endif
// ExceptionHolder
uno_Any aUnoExc; // Any will be constructed by callee
uno_Any * pUnoExc = &aUnoExc;
// in case an exception occurred... if (pUnoExc)
{ // destruct temporary in/inout params for ( ; nTempIndices--; )
{
sal_Int32 nIndex = pTempIndices[nTempIndices];
if (pParams[nIndex].bIn) // is in/inout => was constructed
uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndices], 0 );
TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
} if (pReturnTypeDescr)
TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() ); // has to destruct the any // is here for dummy return typelib_TypeClass_VOID;
} else// else no exception occurred...
{ // temporary params for ( ; nTempIndices--; )
{
sal_Int32 nIndex = pTempIndices[nTempIndices];
typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
#ifdef BRDEBUG
fprintf(stderr,"in codeSnippet functionIndex is %d\n", functionIndex);
fprintf(stderr,"in codeSnippet vtableOffset is %d\n", vtableOffset);
fflush(stderr); #endif
if (! simpleRetType )
functionIndex |= 0x80000000;
unsignedlong * p = (unsignedlong *) code;
// static_assert( sizeof (long) == 4 );
assert((((unsignedlong)code) & 0x3) == 0 ); //aligned to 4 otherwise a mistake
/* generate this code */ /* #save regs into argument space required by mips abi c: afa40000 sw a0,0(sp) 10: afa50004 sw a1,4(sp) 14: afa60008 sw a2,8(sp) 18: afa7000c sw a3,12(sp) #a0=index 1c: 3c040000 lui a0,0x0 20: 34840000 ori a0,a0,0x0 #a1=offset 24: 3c050000 lui a1,0x0 28: 34a50000 ori a1,a1,0x0 #a2=gpregptr 2c: 27a60000 addiu a2,sp,0 #a3=ovrflw 30: 27a70010 addiu a3,sp,16 #load cpp_vtable_call addr 34: 3c190000 lui t9,0x0 38: 37390000 ori t9,t9,0 #jmp to the function,note: we don't use jalr, that will destroy $ra #but be sure to use t9! gp calculation depends on it 3c: 03200008 jr t9 40: 00000000 nop
be careful, we use the argument space reserved by the caller to write down regs. This can avoid the need to make use of arbitrary far away stack space or to allocate a function frame for this code snippet itself. Since only functions with variable arguments will overwrite the space, cpp_vtable_call should be safe. ??? gcc seems change this behavior! cpp_vtable_call overwrite the space!
*/
namespace { // Some dummy type whose RTTI is used in the synthesized proxy vtables to make uses of dynamic_cast // on such proxy objects not crash: struct ProxyRtti {};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.