176cf6069SPedro Giffuni /**************************************************************
276cf6069SPedro Giffuni *
376cf6069SPedro Giffuni * Licensed to the Apache Software Foundation (ASF) under one
476cf6069SPedro Giffuni * or more contributor license agreements. See the NOTICE file
576cf6069SPedro Giffuni * distributed with this work for additional information
676cf6069SPedro Giffuni * regarding copyright ownership. The ASF licenses this file
776cf6069SPedro Giffuni * to you under the Apache License, Version 2.0 (the
876cf6069SPedro Giffuni * "License"); you may not use this file except in compliance
976cf6069SPedro Giffuni * with the License. You may obtain a copy of the License at
1076cf6069SPedro Giffuni *
1176cf6069SPedro Giffuni * http://www.apache.org/licenses/LICENSE-2.0
1276cf6069SPedro Giffuni *
1376cf6069SPedro Giffuni * Unless required by applicable law or agreed to in writing,
1476cf6069SPedro Giffuni * software distributed under the License is distributed on an
1576cf6069SPedro Giffuni * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1676cf6069SPedro Giffuni * KIND, either express or implied. See the License for the
1776cf6069SPedro Giffuni * specific language governing permissions and limitations
1876cf6069SPedro Giffuni * under the License.
1976cf6069SPedro Giffuni *
2076cf6069SPedro Giffuni *************************************************************/
2176cf6069SPedro Giffuni
2276cf6069SPedro Giffuni
2376cf6069SPedro Giffuni
2476cf6069SPedro Giffuni // MARKER(update_precomp.py): autogen include statement, do not remove
2576cf6069SPedro Giffuni #include "precompiled_bridges.hxx"
2676cf6069SPedro Giffuni
2776cf6069SPedro Giffuni #include <com/sun/star/uno/genfunc.hxx>
2876cf6069SPedro Giffuni #include <uno/data.h>
2976cf6069SPedro Giffuni #include <typelib/typedescription.hxx>
3076cf6069SPedro Giffuni
31*a0c169eaSCurtis Hamilton #include <osl/endian.h>
3276cf6069SPedro Giffuni #include "bridges/cpp_uno/shared/bridge.hxx"
3376cf6069SPedro Giffuni #include "bridges/cpp_uno/shared/cppinterfaceproxy.hxx"
3476cf6069SPedro Giffuni #include "bridges/cpp_uno/shared/types.hxx"
3576cf6069SPedro Giffuni #include "bridges/cpp_uno/shared/vtablefactory.hxx"
3676cf6069SPedro Giffuni
3776cf6069SPedro Giffuni #include "share.hxx"
3876cf6069SPedro Giffuni #include <stdio.h>
3976cf6069SPedro Giffuni #include <string.h>
4076cf6069SPedro Giffuni
41*a0c169eaSCurtis Hamilton #ifdef OSL_BIGENDIAN
42*a0c169eaSCurtis Hamilton #define IS_BIG_ENDIAN 1
43*a0c169eaSCurtis Hamilton #else
44*a0c169eaSCurtis Hamilton #define IS_BIG_ENDIAN 0
45*a0c169eaSCurtis Hamilton #endif
4676cf6069SPedro Giffuni
4776cf6069SPedro Giffuni using namespace ::com::sun::star::uno;
4876cf6069SPedro Giffuni
4976cf6069SPedro Giffuni namespace
5076cf6069SPedro Giffuni {
5176cf6069SPedro Giffuni
5276cf6069SPedro Giffuni //==================================================================================================
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_Int64 * pRegisterReturn)5376cf6069SPedro Giffuni static typelib_TypeClass cpp2uno_call(
5476cf6069SPedro Giffuni bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
5576cf6069SPedro Giffuni const typelib_TypeDescription * pMemberTypeDescr,
5676cf6069SPedro Giffuni typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
5776cf6069SPedro Giffuni sal_Int32 nParams, typelib_MethodParameter * pParams,
5876cf6069SPedro Giffuni void ** gpreg, void ** fpreg, void ** ovrflw,
5976cf6069SPedro Giffuni sal_Int64 * pRegisterReturn /* space for register return */ )
6076cf6069SPedro Giffuni {
6176cf6069SPedro Giffuni #ifdef CMC_DEBUG
6276cf6069SPedro Giffuni fprintf(stderr, "as far as cpp2uno_call\n");
6376cf6069SPedro Giffuni #endif
6476cf6069SPedro Giffuni
6576cf6069SPedro Giffuni int ng = 0; //number of gpr registers used
6676cf6069SPedro Giffuni int nf = 0; //number of fpr regsiters used
6776cf6069SPedro Giffuni
6876cf6069SPedro Giffuni // gpreg: [ret *], this, [gpr params]
6976cf6069SPedro Giffuni // fpreg: [fpr params]
7076cf6069SPedro Giffuni // ovrflw: [gpr or fpr params (properly aligned)]
7176cf6069SPedro Giffuni
7276cf6069SPedro Giffuni // return
7376cf6069SPedro Giffuni typelib_TypeDescription * pReturnTypeDescr = 0;
7476cf6069SPedro Giffuni if (pReturnTypeRef)
7576cf6069SPedro Giffuni TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
7676cf6069SPedro Giffuni
7776cf6069SPedro Giffuni void * pUnoReturn = 0;
7876cf6069SPedro Giffuni void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
7976cf6069SPedro Giffuni
8076cf6069SPedro Giffuni if (pReturnTypeDescr)
8176cf6069SPedro Giffuni {
8276cf6069SPedro Giffuni if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
8376cf6069SPedro Giffuni {
8476cf6069SPedro Giffuni pUnoReturn = pRegisterReturn; // direct way for simple types
8576cf6069SPedro Giffuni }
8676cf6069SPedro Giffuni else // complex return via ptr (pCppReturn)
8776cf6069SPedro Giffuni {
8876cf6069SPedro Giffuni pCppReturn = *(void **)gpreg;
8976cf6069SPedro Giffuni gpreg++;
9076cf6069SPedro Giffuni ng++;
9176cf6069SPedro Giffuni
9276cf6069SPedro Giffuni pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
9376cf6069SPedro Giffuni ? alloca( pReturnTypeDescr->nSize )
9476cf6069SPedro Giffuni : pCppReturn); // direct way
9576cf6069SPedro Giffuni }
9676cf6069SPedro Giffuni }
9776cf6069SPedro Giffuni // pop this
9876cf6069SPedro Giffuni gpreg++;
9976cf6069SPedro Giffuni ng++;
10076cf6069SPedro Giffuni
10176cf6069SPedro Giffuni // stack space
10276cf6069SPedro Giffuni OSL_ENSURE( sizeof(void *) == sizeof(sal_Int64), "### unexpected size!" );
10376cf6069SPedro Giffuni // parameters
10476cf6069SPedro Giffuni void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
10576cf6069SPedro Giffuni void ** pCppArgs = pUnoArgs + nParams;
10676cf6069SPedro Giffuni // indizes of values this have to be converted (interface conversion cpp<=>uno)
10776cf6069SPedro Giffuni sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
10876cf6069SPedro Giffuni // type descriptions for reconversions
10976cf6069SPedro Giffuni typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
11076cf6069SPedro Giffuni
11176cf6069SPedro Giffuni sal_Int32 nTempIndizes = 0;
11276cf6069SPedro Giffuni bool bOverFlowUsed = false;
11376cf6069SPedro Giffuni for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
11476cf6069SPedro Giffuni {
11576cf6069SPedro Giffuni const typelib_MethodParameter & rParam = pParams[nPos];
11676cf6069SPedro Giffuni typelib_TypeDescription * pParamTypeDescr = 0;
11776cf6069SPedro Giffuni TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
11876cf6069SPedro Giffuni
11976cf6069SPedro Giffuni #ifdef CMC_DEBUG
12076cf6069SPedro Giffuni fprintf(stderr, "arg %d of %d\n", nPos, nParams);
12176cf6069SPedro Giffuni #endif
12276cf6069SPedro Giffuni
12376cf6069SPedro Giffuni if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
12476cf6069SPedro Giffuni {
12576cf6069SPedro Giffuni #ifdef CMC_DEBUG
12676cf6069SPedro Giffuni fprintf(stderr, "simple\n");
12776cf6069SPedro Giffuni #endif
12876cf6069SPedro Giffuni
12976cf6069SPedro Giffuni switch (pParamTypeDescr->eTypeClass)
13076cf6069SPedro Giffuni {
13176cf6069SPedro Giffuni case typelib_TypeClass_FLOAT:
13276cf6069SPedro Giffuni case typelib_TypeClass_DOUBLE:
13376cf6069SPedro Giffuni if (nf < ppc64::MAX_SSE_REGS)
13476cf6069SPedro Giffuni {
13576cf6069SPedro Giffuni if (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT)
13676cf6069SPedro Giffuni {
13776cf6069SPedro Giffuni float tmp = (float) (*((double *)fpreg));
13876cf6069SPedro Giffuni (*((float *) fpreg)) = tmp;
13976cf6069SPedro Giffuni }
14076cf6069SPedro Giffuni pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
14176cf6069SPedro Giffuni nf++;
14276cf6069SPedro Giffuni }
14376cf6069SPedro Giffuni else
14476cf6069SPedro Giffuni {
14576cf6069SPedro Giffuni pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
14676cf6069SPedro Giffuni bOverFlowUsed = true;
14776cf6069SPedro Giffuni }
14876cf6069SPedro Giffuni if (bOverFlowUsed) ovrflw++;
14976cf6069SPedro Giffuni break;
15076cf6069SPedro Giffuni case typelib_TypeClass_BYTE:
15176cf6069SPedro Giffuni case typelib_TypeClass_BOOLEAN:
15276cf6069SPedro Giffuni if (ng < ppc64::MAX_GPR_REGS)
15376cf6069SPedro Giffuni {
154*a0c169eaSCurtis Hamilton pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 7*IS_BIG_ENDIAN);
15576cf6069SPedro Giffuni ng++;
15676cf6069SPedro Giffuni gpreg++;
15776cf6069SPedro Giffuni }
15876cf6069SPedro Giffuni else
15976cf6069SPedro Giffuni {
160*a0c169eaSCurtis Hamilton pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 7*IS_BIG_ENDIAN);
16176cf6069SPedro Giffuni bOverFlowUsed = true;
16276cf6069SPedro Giffuni }
16376cf6069SPedro Giffuni if (bOverFlowUsed) ovrflw++;
16476cf6069SPedro Giffuni break;
16576cf6069SPedro Giffuni case typelib_TypeClass_CHAR:
16676cf6069SPedro Giffuni case typelib_TypeClass_SHORT:
16776cf6069SPedro Giffuni case typelib_TypeClass_UNSIGNED_SHORT:
16876cf6069SPedro Giffuni if (ng < ppc64::MAX_GPR_REGS)
16976cf6069SPedro Giffuni {
170*a0c169eaSCurtis Hamilton pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 6*IS_BIG_ENDIAN);
17176cf6069SPedro Giffuni ng++;
17276cf6069SPedro Giffuni gpreg++;
17376cf6069SPedro Giffuni }
17476cf6069SPedro Giffuni else
17576cf6069SPedro Giffuni {
176*a0c169eaSCurtis Hamilton pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 6*IS_BIG_ENDIAN);
17776cf6069SPedro Giffuni bOverFlowUsed = true;
17876cf6069SPedro Giffuni }
17976cf6069SPedro Giffuni if (bOverFlowUsed) ovrflw++;
18076cf6069SPedro Giffuni break;
18176cf6069SPedro Giffuni case typelib_TypeClass_ENUM:
18276cf6069SPedro Giffuni case typelib_TypeClass_LONG:
18376cf6069SPedro Giffuni case typelib_TypeClass_UNSIGNED_LONG:
18476cf6069SPedro Giffuni if (ng < ppc64::MAX_GPR_REGS)
18576cf6069SPedro Giffuni {
186*a0c169eaSCurtis Hamilton pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 4*IS_BIG_ENDIAN);
18776cf6069SPedro Giffuni ng++;
18876cf6069SPedro Giffuni gpreg++;
18976cf6069SPedro Giffuni }
19076cf6069SPedro Giffuni else
19176cf6069SPedro Giffuni {
192*a0c169eaSCurtis Hamilton pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 4*IS_BIG_ENDIAN);
19376cf6069SPedro Giffuni bOverFlowUsed = true;
19476cf6069SPedro Giffuni }
19576cf6069SPedro Giffuni if (bOverFlowUsed) ovrflw++;
19676cf6069SPedro Giffuni break;
19776cf6069SPedro Giffuni default:
19876cf6069SPedro Giffuni if (ng < ppc64::MAX_GPR_REGS)
19976cf6069SPedro Giffuni {
20076cf6069SPedro Giffuni pCppArgs[nPos] = pUnoArgs[nPos] = gpreg++;
20176cf6069SPedro Giffuni ng++;
20276cf6069SPedro Giffuni }
20376cf6069SPedro Giffuni else
20476cf6069SPedro Giffuni {
20576cf6069SPedro Giffuni pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
20676cf6069SPedro Giffuni bOverFlowUsed = true;
20776cf6069SPedro Giffuni }
20876cf6069SPedro Giffuni if (bOverFlowUsed) ovrflw++;
20976cf6069SPedro Giffuni break;
21076cf6069SPedro Giffuni }
21176cf6069SPedro Giffuni
21276cf6069SPedro Giffuni // no longer needed
21376cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( pParamTypeDescr );
21476cf6069SPedro Giffuni }
21576cf6069SPedro Giffuni else // ptr to complex value | ref
21676cf6069SPedro Giffuni {
21776cf6069SPedro Giffuni #ifdef CMC_DEBUG
21876cf6069SPedro Giffuni fprintf(stderr, "complex, ng is %d\n", ng);
21976cf6069SPedro Giffuni #endif
22076cf6069SPedro Giffuni void *pCppStack; //temporary stack pointer
22176cf6069SPedro Giffuni
22276cf6069SPedro Giffuni if (ng < ppc64::MAX_GPR_REGS)
22376cf6069SPedro Giffuni {
22476cf6069SPedro Giffuni pCppArgs[nPos] = pCppStack = *gpreg++;
22576cf6069SPedro Giffuni ng++;
22676cf6069SPedro Giffuni }
22776cf6069SPedro Giffuni else
22876cf6069SPedro Giffuni {
22976cf6069SPedro Giffuni pCppArgs[nPos] = pCppStack = *ovrflw;
23076cf6069SPedro Giffuni bOverFlowUsed = true;
23176cf6069SPedro Giffuni }
23276cf6069SPedro Giffuni if (bOverFlowUsed) ovrflw++;
23376cf6069SPedro Giffuni
23476cf6069SPedro Giffuni if (! rParam.bIn) // is pure out
23576cf6069SPedro Giffuni {
23676cf6069SPedro Giffuni // uno out is unconstructed mem!
23776cf6069SPedro Giffuni pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
23876cf6069SPedro Giffuni pTempIndizes[nTempIndizes] = nPos;
23976cf6069SPedro Giffuni // will be released at reconversion
24076cf6069SPedro Giffuni ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
24176cf6069SPedro Giffuni }
24276cf6069SPedro Giffuni // is in/inout
24376cf6069SPedro Giffuni else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
24476cf6069SPedro Giffuni {
24576cf6069SPedro Giffuni uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
24676cf6069SPedro Giffuni pCppStack, pParamTypeDescr,
24776cf6069SPedro Giffuni pThis->getBridge()->getCpp2Uno() );
24876cf6069SPedro Giffuni pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
24976cf6069SPedro Giffuni // will be released at reconversion
25076cf6069SPedro Giffuni ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
25176cf6069SPedro Giffuni }
25276cf6069SPedro Giffuni else // direct way
25376cf6069SPedro Giffuni {
25476cf6069SPedro Giffuni pUnoArgs[nPos] = pCppStack;
25576cf6069SPedro Giffuni // no longer needed
25676cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( pParamTypeDescr );
25776cf6069SPedro Giffuni }
25876cf6069SPedro Giffuni }
25976cf6069SPedro Giffuni }
26076cf6069SPedro Giffuni
26176cf6069SPedro Giffuni #ifdef CMC_DEBUG
26276cf6069SPedro Giffuni fprintf(stderr, "end of params\n");
26376cf6069SPedro Giffuni #endif
26476cf6069SPedro Giffuni
26576cf6069SPedro Giffuni // ExceptionHolder
26676cf6069SPedro Giffuni uno_Any aUnoExc; // Any will be constructed by callee
26776cf6069SPedro Giffuni uno_Any * pUnoExc = &aUnoExc;
26876cf6069SPedro Giffuni
26976cf6069SPedro Giffuni // invoke uno dispatch call
27076cf6069SPedro Giffuni (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
27176cf6069SPedro Giffuni
27276cf6069SPedro Giffuni // in case an exception occurred...
27376cf6069SPedro Giffuni if (pUnoExc)
27476cf6069SPedro Giffuni {
27576cf6069SPedro Giffuni // destruct temporary in/inout params
27676cf6069SPedro Giffuni for ( ; nTempIndizes--; )
27776cf6069SPedro Giffuni {
27876cf6069SPedro Giffuni sal_Int32 nIndex = pTempIndizes[nTempIndizes];
27976cf6069SPedro Giffuni
28076cf6069SPedro Giffuni if (pParams[nIndex].bIn) // is in/inout => was constructed
28176cf6069SPedro Giffuni uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 );
28276cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
28376cf6069SPedro Giffuni }
28476cf6069SPedro Giffuni if (pReturnTypeDescr)
28576cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
28676cf6069SPedro Giffuni
28776cf6069SPedro Giffuni CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() );
28876cf6069SPedro Giffuni // has to destruct the any
28976cf6069SPedro Giffuni // is here for dummy
29076cf6069SPedro Giffuni return typelib_TypeClass_VOID;
29176cf6069SPedro Giffuni }
29276cf6069SPedro Giffuni else // else no exception occurred...
29376cf6069SPedro Giffuni {
29476cf6069SPedro Giffuni // temporary params
29576cf6069SPedro Giffuni for ( ; nTempIndizes--; )
29676cf6069SPedro Giffuni {
29776cf6069SPedro Giffuni sal_Int32 nIndex = pTempIndizes[nTempIndizes];
29876cf6069SPedro Giffuni typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
29976cf6069SPedro Giffuni
30076cf6069SPedro Giffuni if (pParams[nIndex].bOut) // inout/out
30176cf6069SPedro Giffuni {
30276cf6069SPedro Giffuni // convert and assign
30376cf6069SPedro Giffuni uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
30476cf6069SPedro Giffuni uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
30576cf6069SPedro Giffuni pThis->getBridge()->getUno2Cpp() );
30676cf6069SPedro Giffuni }
30776cf6069SPedro Giffuni // destroy temp uno param
30876cf6069SPedro Giffuni uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
30976cf6069SPedro Giffuni
31076cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( pParamTypeDescr );
31176cf6069SPedro Giffuni }
31276cf6069SPedro Giffuni // return
31376cf6069SPedro Giffuni if (pCppReturn) // has complex return
31476cf6069SPedro Giffuni {
31576cf6069SPedro Giffuni if (pUnoReturn != pCppReturn) // needs reconversion
31676cf6069SPedro Giffuni {
31776cf6069SPedro Giffuni uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
31876cf6069SPedro Giffuni pThis->getBridge()->getUno2Cpp() );
31976cf6069SPedro Giffuni // destroy temp uno return
32076cf6069SPedro Giffuni uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
32176cf6069SPedro Giffuni }
32276cf6069SPedro Giffuni // complex return ptr is set to return reg
32376cf6069SPedro Giffuni *(void **)pRegisterReturn = pCppReturn;
32476cf6069SPedro Giffuni }
32576cf6069SPedro Giffuni if (pReturnTypeDescr)
32676cf6069SPedro Giffuni {
32776cf6069SPedro Giffuni typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
32876cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
32976cf6069SPedro Giffuni return eRet;
33076cf6069SPedro Giffuni }
33176cf6069SPedro Giffuni else
33276cf6069SPedro Giffuni return typelib_TypeClass_VOID;
33376cf6069SPedro Giffuni }
33476cf6069SPedro Giffuni }
33576cf6069SPedro Giffuni
336*a0c169eaSCurtis Hamilton #if defined(_CALL_ELF) && _CALL_ELF == 2
337*a0c169eaSCurtis Hamilton # define PARAMSAVE 32
338*a0c169eaSCurtis Hamilton #else
339*a0c169eaSCurtis Hamilton # define PARAMSAVE 48
340*a0c169eaSCurtis Hamilton #endif
34176cf6069SPedro Giffuni
cpp_mediate(sal_uInt64 nOffsetAndIndex,void ** gpreg,void ** fpreg,long sp,sal_Int64 * pRegisterReturn)342*a0c169eaSCurtis Hamilton extern "C" typelib_TypeClass cpp_mediate(
34376cf6069SPedro Giffuni sal_uInt64 nOffsetAndIndex,
34476cf6069SPedro Giffuni void ** gpreg, void ** fpreg, long sp,
34576cf6069SPedro Giffuni sal_Int64 * pRegisterReturn /* space for register return */ )
34676cf6069SPedro Giffuni {
347*a0c169eaSCurtis Hamilton static_assert(sizeof(sal_Int64)==sizeof(void *), "### unexpected!");
34876cf6069SPedro Giffuni
34976cf6069SPedro Giffuni sal_Int32 nVtableOffset = (nOffsetAndIndex >> 32);
35076cf6069SPedro Giffuni sal_Int32 nFunctionIndex = (nOffsetAndIndex & 0xFFFFFFFF);
35176cf6069SPedro Giffuni
35276cf6069SPedro Giffuni long sf = *(long*)sp;
353*a0c169eaSCurtis Hamilton void ** ovrflw = (void**)(sf + PARAMSAVE + 64);
35476cf6069SPedro Giffuni
35576cf6069SPedro Giffuni // gpreg: [ret *], this, [other gpr params]
35676cf6069SPedro Giffuni // fpreg: [fpr params]
35776cf6069SPedro Giffuni // ovrflw: [gpr or fpr params (properly aligned)]
35876cf6069SPedro Giffuni
35976cf6069SPedro Giffuni void * pThis;
36076cf6069SPedro Giffuni if (nFunctionIndex & 0x80000000 )
36176cf6069SPedro Giffuni {
36276cf6069SPedro Giffuni nFunctionIndex &= 0x7fffffff;
36376cf6069SPedro Giffuni pThis = gpreg[1];
36476cf6069SPedro Giffuni #ifdef CMC_DEBUG
36576cf6069SPedro Giffuni fprintf(stderr, "pThis is gpreg[1]\n");
36676cf6069SPedro Giffuni #endif
36776cf6069SPedro Giffuni }
36876cf6069SPedro Giffuni else
36976cf6069SPedro Giffuni {
37076cf6069SPedro Giffuni pThis = gpreg[0];
37176cf6069SPedro Giffuni #ifdef CMC_DEBUG
37276cf6069SPedro Giffuni fprintf(stderr, "pThis is gpreg[0]\n");
37376cf6069SPedro Giffuni #endif
37476cf6069SPedro Giffuni }
37576cf6069SPedro Giffuni
37676cf6069SPedro Giffuni #ifdef CMC_DEBUG
37776cf6069SPedro Giffuni fprintf(stderr, "pThis is %lx\n", pThis);
37876cf6069SPedro Giffuni #endif
37976cf6069SPedro Giffuni
38076cf6069SPedro Giffuni pThis = static_cast< char * >(pThis) - nVtableOffset;
38176cf6069SPedro Giffuni
38276cf6069SPedro Giffuni #ifdef CMC_DEBUG
38376cf6069SPedro Giffuni fprintf(stderr, "pThis is now %lx\n", pThis);
38476cf6069SPedro Giffuni #endif
38576cf6069SPedro Giffuni
38676cf6069SPedro Giffuni bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
38776cf6069SPedro Giffuni = bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
38876cf6069SPedro Giffuni pThis);
38976cf6069SPedro Giffuni
39076cf6069SPedro Giffuni typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
39176cf6069SPedro Giffuni
39276cf6069SPedro Giffuni #ifdef CMC_DEBUG
39376cf6069SPedro Giffuni fprintf(stderr, "indexes are %d %d\n", nFunctionIndex, pTypeDescr->nMapFunctionIndexToMemberIndex);
39476cf6069SPedro Giffuni #endif
39576cf6069SPedro Giffuni
39676cf6069SPedro Giffuni OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
39776cf6069SPedro Giffuni if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
39876cf6069SPedro Giffuni {
39976cf6069SPedro Giffuni throw RuntimeException(
40076cf6069SPedro Giffuni rtl::OUString::createFromAscii("illegal vtable index!"),
40176cf6069SPedro Giffuni (XInterface *)pThis );
40276cf6069SPedro Giffuni }
40376cf6069SPedro Giffuni
40476cf6069SPedro Giffuni // determine called method
40576cf6069SPedro Giffuni sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
40676cf6069SPedro Giffuni OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" );
40776cf6069SPedro Giffuni
40876cf6069SPedro Giffuni #ifdef CMC_DEBUG
40976cf6069SPedro Giffuni fprintf(stderr, "members are %d %d\n", nMemberPos, pTypeDescr->nAllMembers);
41076cf6069SPedro Giffuni #endif
41176cf6069SPedro Giffuni
41276cf6069SPedro Giffuni TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
41376cf6069SPedro Giffuni
41476cf6069SPedro Giffuni typelib_TypeClass eRet;
41576cf6069SPedro Giffuni switch (aMemberDescr.get()->eTypeClass)
41676cf6069SPedro Giffuni {
41776cf6069SPedro Giffuni case typelib_TypeClass_INTERFACE_ATTRIBUTE:
41876cf6069SPedro Giffuni {
41976cf6069SPedro Giffuni if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
42076cf6069SPedro Giffuni {
42176cf6069SPedro Giffuni // is GET method
42276cf6069SPedro Giffuni eRet = cpp2uno_call(
42376cf6069SPedro Giffuni pCppI, aMemberDescr.get(),
42476cf6069SPedro Giffuni ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
42576cf6069SPedro Giffuni 0, 0, // no params
42676cf6069SPedro Giffuni gpreg, fpreg, ovrflw, pRegisterReturn );
42776cf6069SPedro Giffuni }
42876cf6069SPedro Giffuni else
42976cf6069SPedro Giffuni {
43076cf6069SPedro Giffuni // is SET method
43176cf6069SPedro Giffuni typelib_MethodParameter aParam;
43276cf6069SPedro Giffuni aParam.pTypeRef =
43376cf6069SPedro Giffuni ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
43476cf6069SPedro Giffuni aParam.bIn = sal_True;
43576cf6069SPedro Giffuni aParam.bOut = sal_False;
43676cf6069SPedro Giffuni
43776cf6069SPedro Giffuni eRet = cpp2uno_call(
43876cf6069SPedro Giffuni pCppI, aMemberDescr.get(),
43976cf6069SPedro Giffuni 0, // indicates void return
44076cf6069SPedro Giffuni 1, &aParam,
44176cf6069SPedro Giffuni gpreg, fpreg, ovrflw, pRegisterReturn );
44276cf6069SPedro Giffuni }
44376cf6069SPedro Giffuni break;
44476cf6069SPedro Giffuni }
44576cf6069SPedro Giffuni case typelib_TypeClass_INTERFACE_METHOD:
44676cf6069SPedro Giffuni {
44776cf6069SPedro Giffuni // is METHOD
44876cf6069SPedro Giffuni switch (nFunctionIndex)
44976cf6069SPedro Giffuni {
45076cf6069SPedro Giffuni case 1: // acquire()
45176cf6069SPedro Giffuni pCppI->acquireProxy(); // non virtual call!
45276cf6069SPedro Giffuni eRet = typelib_TypeClass_VOID;
45376cf6069SPedro Giffuni break;
45476cf6069SPedro Giffuni case 2: // release()
45576cf6069SPedro Giffuni pCppI->releaseProxy(); // non virtual call!
45676cf6069SPedro Giffuni eRet = typelib_TypeClass_VOID;
45776cf6069SPedro Giffuni break;
45876cf6069SPedro Giffuni case 0: // queryInterface() opt
45976cf6069SPedro Giffuni {
46076cf6069SPedro Giffuni typelib_TypeDescription * pTD = 0;
46176cf6069SPedro Giffuni TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
46276cf6069SPedro Giffuni if (pTD)
46376cf6069SPedro Giffuni {
46476cf6069SPedro Giffuni XInterface * pInterface = 0;
46576cf6069SPedro Giffuni (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
46676cf6069SPedro Giffuni pCppI->getBridge()->getCppEnv(),
46776cf6069SPedro Giffuni (void **)&pInterface, pCppI->getOid().pData,
46876cf6069SPedro Giffuni (typelib_InterfaceTypeDescription *)pTD );
46976cf6069SPedro Giffuni
47076cf6069SPedro Giffuni if (pInterface)
47176cf6069SPedro Giffuni {
47276cf6069SPedro Giffuni ::uno_any_construct(
47376cf6069SPedro Giffuni reinterpret_cast< uno_Any * >( gpreg[0] ),
47476cf6069SPedro Giffuni &pInterface, pTD, cpp_acquire );
47576cf6069SPedro Giffuni pInterface->release();
47676cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( pTD );
47776cf6069SPedro Giffuni *(void **)pRegisterReturn = gpreg[0];
47876cf6069SPedro Giffuni eRet = typelib_TypeClass_ANY;
47976cf6069SPedro Giffuni break;
48076cf6069SPedro Giffuni }
48176cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE( pTD );
48276cf6069SPedro Giffuni }
48376cf6069SPedro Giffuni } // else perform queryInterface()
48476cf6069SPedro Giffuni default:
48576cf6069SPedro Giffuni eRet = cpp2uno_call(
48676cf6069SPedro Giffuni pCppI, aMemberDescr.get(),
48776cf6069SPedro Giffuni ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
48876cf6069SPedro Giffuni ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
48976cf6069SPedro Giffuni ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
49076cf6069SPedro Giffuni gpreg, fpreg, ovrflw, pRegisterReturn );
49176cf6069SPedro Giffuni }
49276cf6069SPedro Giffuni break;
49376cf6069SPedro Giffuni }
49476cf6069SPedro Giffuni default:
49576cf6069SPedro Giffuni {
49676cf6069SPedro Giffuni #ifdef CMC_DEBUG
49776cf6069SPedro Giffuni fprintf(stderr, "screwed\n");
49876cf6069SPedro Giffuni #endif
49976cf6069SPedro Giffuni
50076cf6069SPedro Giffuni throw RuntimeException(
50176cf6069SPedro Giffuni rtl::OUString::createFromAscii("no member description found!"),
50276cf6069SPedro Giffuni (XInterface *)pThis );
50376cf6069SPedro Giffuni // is here for dummy
50476cf6069SPedro Giffuni eRet = typelib_TypeClass_VOID;
50576cf6069SPedro Giffuni }
50676cf6069SPedro Giffuni }
50776cf6069SPedro Giffuni
50876cf6069SPedro Giffuni #ifdef CMC_DEBUG
50976cf6069SPedro Giffuni fprintf(stderr, "end of cpp_mediate\n");
51076cf6069SPedro Giffuni #endif
51176cf6069SPedro Giffuni return eRet;
51276cf6069SPedro Giffuni }
51376cf6069SPedro Giffuni
514*a0c169eaSCurtis Hamilton extern "C" void privateSnippetExecutor( ... );
515*a0c169eaSCurtis Hamilton #if 0
51676cf6069SPedro Giffuni {
51776cf6069SPedro Giffuni sal_uInt64 gpreg[ppc64::MAX_GPR_REGS];
518*a0c169eaSCurtis Hamilton
519*a0c169eaSCurtis Hamilton register long r3 asm("r3"); gpreg[0] = r3;
520*a0c169eaSCurtis Hamilton register long r4 asm("r4"); gpreg[1] = r4;
521*a0c169eaSCurtis Hamilton register long r5 asm("r5"); gpreg[2] = r5;
522*a0c169eaSCurtis Hamilton register long r6 asm("r6"); gpreg[3] = r6;
523*a0c169eaSCurtis Hamilton register long r7 asm("r7"); gpreg[4] = r7;
524*a0c169eaSCurtis Hamilton register long r8 asm("r8"); gpreg[5] = r8;
525*a0c169eaSCurtis Hamilton register long r9 asm("r9"); gpreg[6] = r9;
526*a0c169eaSCurtis Hamilton register long r10 asm("r10"); gpreg[7] = r10;
527*a0c169eaSCurtis Hamilton
52876cf6069SPedro Giffuni double fpreg[ppc64::MAX_SSE_REGS];
52976cf6069SPedro Giffuni
53076cf6069SPedro Giffuni __asm__ __volatile__ (
531*a0c169eaSCurtis Hamilton "stfd 1, 0(%0)\t\n"
532*a0c169eaSCurtis Hamilton "stfd 2, 8(%0)\t\n"
533*a0c169eaSCurtis Hamilton "stfd 3, 16(%0)\t\n"
534*a0c169eaSCurtis Hamilton "stfd 4, 24(%0)\t\n"
535*a0c169eaSCurtis Hamilton "stfd 5, 32(%0)\t\n"
536*a0c169eaSCurtis Hamilton "stfd 6, 40(%0)\t\n"
537*a0c169eaSCurtis Hamilton "stfd 7, 48(%0)\t\n"
538*a0c169eaSCurtis Hamilton "stfd 8, 56(%0)\t\n"
539*a0c169eaSCurtis Hamilton "stfd 9, 64(%0)\t\n"
540*a0c169eaSCurtis Hamilton "stfd 10, 72(%0)\t\n"
541*a0c169eaSCurtis Hamilton "stfd 11, 80(%0)\t\n"
542*a0c169eaSCurtis Hamilton "stfd 12, 88(%0)\t\n"
543*a0c169eaSCurtis Hamilton "stfd 13, 96(%0)\t\n"
544*a0c169eaSCurtis Hamilton : : "r" (fpreg)
545*a0c169eaSCurtis Hamilton : "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9",
54676cf6069SPedro Giffuni "fr10", "fr11", "fr12", "fr13"
54776cf6069SPedro Giffuni );
54876cf6069SPedro Giffuni
549*a0c169eaSCurtis Hamilton register long r11 asm("r11");
550*a0c169eaSCurtis Hamilton const long nOffsetAndIndex = r11;
55176cf6069SPedro Giffuni
552*a0c169eaSCurtis Hamilton register long r1 asm("r1");
553*a0c169eaSCurtis Hamilton const long sp = r1;
55476cf6069SPedro Giffuni
555*a0c169eaSCurtis Hamilton #if defined(_CALL_ELF) && _CALL_ELF == 2
556*a0c169eaSCurtis Hamilton volatile long nRegReturn[2];
557*a0c169eaSCurtis Hamilton #else
55876cf6069SPedro Giffuni volatile long nRegReturn[1];
559*a0c169eaSCurtis Hamilton #endif
56076cf6069SPedro Giffuni
56176cf6069SPedro Giffuni typelib_TypeClass aType =
56276cf6069SPedro Giffuni cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, sp, (sal_Int64*)nRegReturn);
56376cf6069SPedro Giffuni
56476cf6069SPedro Giffuni switch( aType )
56576cf6069SPedro Giffuni {
56676cf6069SPedro Giffuni case typelib_TypeClass_VOID:
56776cf6069SPedro Giffuni break;
56876cf6069SPedro Giffuni case typelib_TypeClass_BOOLEAN:
56976cf6069SPedro Giffuni case typelib_TypeClass_BYTE:
57076cf6069SPedro Giffuni __asm__( "lbz 3,%0\n\t"
57176cf6069SPedro Giffuni : : "m" (nRegReturn[0]) );
57276cf6069SPedro Giffuni break;
57376cf6069SPedro Giffuni case typelib_TypeClass_CHAR:
57476cf6069SPedro Giffuni case typelib_TypeClass_UNSIGNED_SHORT:
57576cf6069SPedro Giffuni __asm__( "lhz 3,%0\n\t"
57676cf6069SPedro Giffuni : : "m" (nRegReturn[0]) );
57776cf6069SPedro Giffuni break;
57876cf6069SPedro Giffuni case typelib_TypeClass_SHORT:
57976cf6069SPedro Giffuni __asm__( "lha 3,%0\n\t"
58076cf6069SPedro Giffuni : : "m" (nRegReturn[0]) );
58176cf6069SPedro Giffuni break;
58276cf6069SPedro Giffuni case typelib_TypeClass_ENUM:
58376cf6069SPedro Giffuni case typelib_TypeClass_UNSIGNED_LONG:
58476cf6069SPedro Giffuni __asm__( "lwz 3,%0\n\t"
58576cf6069SPedro Giffuni : : "m"(nRegReturn[0]) );
58676cf6069SPedro Giffuni break;
58776cf6069SPedro Giffuni case typelib_TypeClass_LONG:
58876cf6069SPedro Giffuni __asm__( "lwa 3,%0\n\t"
58976cf6069SPedro Giffuni : : "m"(nRegReturn[0]) );
59076cf6069SPedro Giffuni break;
59176cf6069SPedro Giffuni case typelib_TypeClass_FLOAT:
59276cf6069SPedro Giffuni __asm__( "lfs 1,%0\n\t"
59376cf6069SPedro Giffuni : : "m" (*((float*)nRegReturn)) );
59476cf6069SPedro Giffuni break;
59576cf6069SPedro Giffuni case typelib_TypeClass_DOUBLE:
59676cf6069SPedro Giffuni __asm__( "lfd 1,%0\n\t"
59776cf6069SPedro Giffuni : : "m" (*((double*)nRegReturn)) );
59876cf6069SPedro Giffuni break;
59976cf6069SPedro Giffuni default:
60076cf6069SPedro Giffuni __asm__( "ld 3,%0\n\t"
60176cf6069SPedro Giffuni : : "m" (nRegReturn[0]) );
602*a0c169eaSCurtis Hamilton #if defined(_CALL_ELF) && _CALL_ELF == 2
603*a0c169eaSCurtis Hamilton __asm__( "ld 4,%0\n\t"
604*a0c169eaSCurtis Hamilton : : "m" (nRegReturn[1]) );
605*a0c169eaSCurtis Hamilton #endif
60676cf6069SPedro Giffuni break;
60776cf6069SPedro Giffuni }
60876cf6069SPedro Giffuni }
609*a0c169eaSCurtis Hamilton #endif
61076cf6069SPedro Giffuni
611*a0c169eaSCurtis Hamilton #if defined(_CALL_ELF) && _CALL_ELF == 2
612*a0c169eaSCurtis Hamilton const int codeSnippetSize = 32;
613*a0c169eaSCurtis Hamilton #else
61476cf6069SPedro Giffuni const int codeSnippetSize = 24;
615*a0c169eaSCurtis Hamilton #endif
61676cf6069SPedro Giffuni
codeSnippet(unsigned char * code,sal_Int32 nFunctionIndex,sal_Int32 nVtableOffset,bool simpleRetType)61776cf6069SPedro Giffuni unsigned char * codeSnippet( unsigned char * code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
61876cf6069SPedro Giffuni bool simpleRetType)
61976cf6069SPedro Giffuni {
62076cf6069SPedro Giffuni #ifdef CMC_DEBUG
62176cf6069SPedro Giffuni fprintf(stderr,"in codeSnippet functionIndex is %x\n", nFunctionIndex);
62276cf6069SPedro Giffuni fprintf(stderr,"in codeSnippet vtableOffset is %x\n", nVtableOffset);
62376cf6069SPedro Giffuni #endif
62476cf6069SPedro Giffuni
62576cf6069SPedro Giffuni sal_uInt64 nOffsetAndIndex = ( ( (sal_uInt64) nVtableOffset ) << 32 ) | ( (sal_uInt64) nFunctionIndex );
62676cf6069SPedro Giffuni
62776cf6069SPedro Giffuni if ( !simpleRetType )
62876cf6069SPedro Giffuni nOffsetAndIndex |= 0x80000000;
629*a0c169eaSCurtis Hamilton #if defined(_CALL_ELF) && _CALL_ELF == 2
630*a0c169eaSCurtis Hamilton unsigned int *raw = (unsigned int *)&code[0];
63176cf6069SPedro Giffuni
632*a0c169eaSCurtis Hamilton raw[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
633*a0c169eaSCurtis Hamilton raw[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
634*a0c169eaSCurtis Hamilton raw[2] = 0x7d8903a6; /* mtctr 12 */
635*a0c169eaSCurtis Hamilton raw[3] = 0x4e800420; /* bctr */
636*a0c169eaSCurtis Hamilton /* 1: .quad function_addr */
637*a0c169eaSCurtis Hamilton /* 2: .quad context */
638*a0c169eaSCurtis Hamilton *(void **)&raw[4] = (void *)privateSnippetExecutor;
639*a0c169eaSCurtis Hamilton *(void **)&raw[6] = (void*)nOffsetAndIndex;
640*a0c169eaSCurtis Hamilton #else
64176cf6069SPedro Giffuni void ** raw = (void **)&code[0];
64276cf6069SPedro Giffuni memcpy(raw, (char*) privateSnippetExecutor, 16);
64376cf6069SPedro Giffuni raw[2] = (void*) nOffsetAndIndex;
644*a0c169eaSCurtis Hamilton #endif
64576cf6069SPedro Giffuni #ifdef CMC_DEBUG
64676cf6069SPedro Giffuni fprintf(stderr, "in: offset/index is %x %x %d, %lx\n",
64776cf6069SPedro Giffuni nFunctionIndex, nVtableOffset, !simpleRetType, raw[2]);
64876cf6069SPedro Giffuni #endif
64976cf6069SPedro Giffuni return (code + codeSnippetSize);
65076cf6069SPedro Giffuni }
65176cf6069SPedro Giffuni
65276cf6069SPedro Giffuni }
65376cf6069SPedro Giffuni
flushCode(unsigned char const * bptr,unsigned char const * eptr)65476cf6069SPedro Giffuni void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const * bptr, unsigned char const * eptr)
65576cf6069SPedro Giffuni {
65676cf6069SPedro Giffuni int const lineSize = 32;
65776cf6069SPedro Giffuni for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
65876cf6069SPedro Giffuni __asm__ volatile ("dcbst 0, %0" : : "r"(p) : "memory");
65976cf6069SPedro Giffuni }
66076cf6069SPedro Giffuni __asm__ volatile ("sync" : : : "memory");
66176cf6069SPedro Giffuni for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
66276cf6069SPedro Giffuni __asm__ volatile ("icbi 0, %0" : : "r"(p) : "memory");
66376cf6069SPedro Giffuni }
66476cf6069SPedro Giffuni __asm__ volatile ("isync" : : : "memory");
66576cf6069SPedro Giffuni }
66676cf6069SPedro Giffuni
66776cf6069SPedro Giffuni struct bridges::cpp_uno::shared::VtableFactory::Slot { void * fn; };
66876cf6069SPedro Giffuni
66976cf6069SPedro Giffuni bridges::cpp_uno::shared::VtableFactory::Slot *
mapBlockToVtable(void * block)67076cf6069SPedro Giffuni bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
67176cf6069SPedro Giffuni {
67276cf6069SPedro Giffuni return static_cast< Slot * >(block) + 2;
67376cf6069SPedro Giffuni }
67476cf6069SPedro Giffuni
getBlockSize(sal_Int32 slotCount)67576cf6069SPedro Giffuni sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
67676cf6069SPedro Giffuni sal_Int32 slotCount)
67776cf6069SPedro Giffuni {
67876cf6069SPedro Giffuni return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
67976cf6069SPedro Giffuni }
68076cf6069SPedro Giffuni
68176cf6069SPedro Giffuni bridges::cpp_uno::shared::VtableFactory::Slot *
initializeBlock(void * block,sal_Int32 slotCount)68276cf6069SPedro Giffuni bridges::cpp_uno::shared::VtableFactory::initializeBlock(
68376cf6069SPedro Giffuni void * block, sal_Int32 slotCount)
68476cf6069SPedro Giffuni {
68576cf6069SPedro Giffuni Slot * slots = mapBlockToVtable(block);
68676cf6069SPedro Giffuni slots[-2].fn = 0;
68776cf6069SPedro Giffuni slots[-1].fn = 0;
68876cf6069SPedro Giffuni return slots + slotCount;
68976cf6069SPedro Giffuni }
69076cf6069SPedro Giffuni
addLocalFunctions(Slot ** slots,unsigned char * code,sal_PtrDiff writetoexecdiff,typelib_InterfaceTypeDescription const * type,sal_Int32 functionOffset,sal_Int32 functionCount,sal_Int32 vtableOffset)69176cf6069SPedro Giffuni unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
69276cf6069SPedro Giffuni Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
69376cf6069SPedro Giffuni typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
69476cf6069SPedro Giffuni sal_Int32 functionCount, sal_Int32 vtableOffset)
69576cf6069SPedro Giffuni {
69676cf6069SPedro Giffuni (*slots) -= functionCount;
69776cf6069SPedro Giffuni Slot * s = *slots;
69876cf6069SPedro Giffuni #ifdef CMC_DEBUG
69976cf6069SPedro Giffuni fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
70076cf6069SPedro Giffuni fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
70176cf6069SPedro Giffuni #endif
70276cf6069SPedro Giffuni
70376cf6069SPedro Giffuni for (sal_Int32 i = 0; i < type->nMembers; ++i) {
70476cf6069SPedro Giffuni typelib_TypeDescription * member = 0;
70576cf6069SPedro Giffuni TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
70676cf6069SPedro Giffuni OSL_ASSERT(member != 0);
70776cf6069SPedro Giffuni switch (member->eTypeClass) {
70876cf6069SPedro Giffuni case typelib_TypeClass_INTERFACE_ATTRIBUTE:
70976cf6069SPedro Giffuni // Getter:
71076cf6069SPedro Giffuni (s++)->fn = code + writetoexecdiff;
71176cf6069SPedro Giffuni code = codeSnippet(
71276cf6069SPedro Giffuni code, functionOffset++, vtableOffset,
71376cf6069SPedro Giffuni bridges::cpp_uno::shared::isSimpleType(
71476cf6069SPedro Giffuni reinterpret_cast<
71576cf6069SPedro Giffuni typelib_InterfaceAttributeTypeDescription * >(
71676cf6069SPedro Giffuni member)->pAttributeTypeRef));
71776cf6069SPedro Giffuni
71876cf6069SPedro Giffuni // Setter:
71976cf6069SPedro Giffuni if (!reinterpret_cast<
72076cf6069SPedro Giffuni typelib_InterfaceAttributeTypeDescription * >(
72176cf6069SPedro Giffuni member)->bReadOnly)
72276cf6069SPedro Giffuni {
72376cf6069SPedro Giffuni (s++)->fn = code + writetoexecdiff;
72476cf6069SPedro Giffuni code = codeSnippet(code, functionOffset++, vtableOffset, true);
72576cf6069SPedro Giffuni }
72676cf6069SPedro Giffuni break;
72776cf6069SPedro Giffuni
72876cf6069SPedro Giffuni case typelib_TypeClass_INTERFACE_METHOD:
72976cf6069SPedro Giffuni (s++)->fn = code + writetoexecdiff;
73076cf6069SPedro Giffuni code = codeSnippet(
73176cf6069SPedro Giffuni code, functionOffset++, vtableOffset,
73276cf6069SPedro Giffuni bridges::cpp_uno::shared::isSimpleType(
73376cf6069SPedro Giffuni reinterpret_cast<
73476cf6069SPedro Giffuni typelib_InterfaceMethodTypeDescription * >(
73576cf6069SPedro Giffuni member)->pReturnTypeRef));
73676cf6069SPedro Giffuni break;
73776cf6069SPedro Giffuni
73876cf6069SPedro Giffuni default:
73976cf6069SPedro Giffuni OSL_ASSERT(false);
74076cf6069SPedro Giffuni break;
74176cf6069SPedro Giffuni }
74276cf6069SPedro Giffuni TYPELIB_DANGER_RELEASE(member);
74376cf6069SPedro Giffuni }
74476cf6069SPedro Giffuni return code;
74576cf6069SPedro Giffuni }
74676cf6069SPedro Giffuni
74776cf6069SPedro Giffuni /* vi:set tabstop=4 shiftwidth=4 expandtab: */
748