1*61dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*61dff127SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*61dff127SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*61dff127SAndrew Rist * distributed with this work for additional information
6*61dff127SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*61dff127SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*61dff127SAndrew Rist * "License"); you may not use this file except in compliance
9*61dff127SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
11*61dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
13*61dff127SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*61dff127SAndrew Rist * software distributed under the License is distributed on an
15*61dff127SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*61dff127SAndrew Rist * KIND, either express or implied. See the License for the
17*61dff127SAndrew Rist * specific language governing permissions and limitations
18*61dff127SAndrew Rist * under the License.
19cdf0e10cSrcweir *
20*61dff127SAndrew Rist *************************************************************/
21*61dff127SAndrew Rist
22*61dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #include <malloc.h>
25cdf0e10cSrcweir #include <hash_map>
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <rtl/alloc.h>
28cdf0e10cSrcweir #include <osl/mutex.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
31cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
32cdf0e10cSrcweir #include <uno/data.h>
33cdf0e10cSrcweir #include <typelib/typedescription.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
36cdf0e10cSrcweir #include "bridges/cpp_uno/shared/cppinterfaceproxy.hxx"
37cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
38cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtablefactory.hxx"
39cdf0e10cSrcweir
40cdf0e10cSrcweir #include "share.hxx"
41cdf0e10cSrcweir
42cdf0e10cSrcweir #include <dlfcn.h>
43cdf0e10cSrcweir
44cdf0e10cSrcweir
45cdf0e10cSrcweir using namespace ::osl;
46cdf0e10cSrcweir using namespace ::rtl;
47cdf0e10cSrcweir using namespace ::com::sun::star::uno;
48cdf0e10cSrcweir
49cdf0e10cSrcweir namespace
50cdf0e10cSrcweir {
51cdf0e10cSrcweir
cpp2uno_call(bridges::cpp_uno::shared::CppInterfaceProxy * pThis,const typelib_TypeDescription * pMemberTypeDescr,typelib_TypeDescriptionReference * pReturnTypeRef,sal_Int32 nParams,typelib_MethodParameter * pParams,void ** pCallStack,sal_Int64 * pRegisterReturn)52cdf0e10cSrcweir static typelib_TypeClass cpp2uno_call(
53cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy* pThis,
54cdf0e10cSrcweir const typelib_TypeDescription * pMemberTypeDescr,
55cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef,
56cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams,
57cdf0e10cSrcweir void ** pCallStack,
58cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
59cdf0e10cSrcweir {
60cdf0e10cSrcweir // pCallStack: ret, [return ptr], this, params
61cdf0e10cSrcweir char * pTopStack = (char *)(pCallStack + 0);
62cdf0e10cSrcweir char * pCppStack = pTopStack;
63cdf0e10cSrcweir
64cdf0e10cSrcweir // return
65cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
66cdf0e10cSrcweir if (pReturnTypeRef)
67cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
68cdf0e10cSrcweir
69cdf0e10cSrcweir void * pUnoReturn = 0;
70cdf0e10cSrcweir // complex return ptr: if != 0 && != pUnoReturn, reconversion need
71cdf0e10cSrcweir void * pCppReturn = 0;
72cdf0e10cSrcweir
73cdf0e10cSrcweir if (pReturnTypeDescr)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir if (!arm::return_in_hidden_param(pReturnTypeRef))
76cdf0e10cSrcweir pUnoReturn = pRegisterReturn; // direct way for simple types
77cdf0e10cSrcweir else // complex return via ptr (pCppReturn)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir pCppReturn = *(void **)pCppStack;
80cdf0e10cSrcweir pCppStack += sizeof(void *);
81cdf0e10cSrcweir
82cdf0e10cSrcweir pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType(
83cdf0e10cSrcweir pReturnTypeDescr )
84cdf0e10cSrcweir ? alloca( pReturnTypeDescr->nSize )
85cdf0e10cSrcweir : pCppReturn); // direct way
86cdf0e10cSrcweir }
87cdf0e10cSrcweir }
88cdf0e10cSrcweir // pop this
89cdf0e10cSrcweir pCppStack += sizeof( void* );
90cdf0e10cSrcweir
91cdf0e10cSrcweir // stack space
92cdf0e10cSrcweir OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32),
93cdf0e10cSrcweir "### unexpected size!" );
94cdf0e10cSrcweir // parameters
95cdf0e10cSrcweir void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
96cdf0e10cSrcweir void ** pCppArgs = pUnoArgs + nParams;
97cdf0e10cSrcweir // indizes of values this have to be converted (interface conversion
98cdf0e10cSrcweir // cpp<=>uno)
99cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
100cdf0e10cSrcweir // type descriptions for reconversions
101cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr =
102cdf0e10cSrcweir (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
103cdf0e10cSrcweir
104cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
105cdf0e10cSrcweir
106cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
107cdf0e10cSrcweir {
108cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
109cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
110cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
111cdf0e10cSrcweir
112cdf0e10cSrcweir if (!rParam.bOut &&
113cdf0e10cSrcweir bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
114cdf0e10cSrcweir {
115cdf0e10cSrcweir #ifdef __ARM_EABI__
116cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
117cdf0e10cSrcweir {
118cdf0e10cSrcweir case typelib_TypeClass_HYPER:
119cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
120cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
121cdf0e10cSrcweir if ((pCppStack - pTopStack) % 8) pCppStack+=sizeof(sal_Int32); //align to 8
122cdf0e10cSrcweir break;
123cdf0e10cSrcweir default:
124cdf0e10cSrcweir break;
125cdf0e10cSrcweir }
126cdf0e10cSrcweir #endif
127cdf0e10cSrcweir
128cdf0e10cSrcweir pCppArgs[nPos] = pCppStack;
129cdf0e10cSrcweir pUnoArgs[nPos] = pCppStack;
130cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir case typelib_TypeClass_HYPER:
133cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
134cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
135cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // extra long
136cdf0e10cSrcweir break;
137cdf0e10cSrcweir default:
138cdf0e10cSrcweir break;
139cdf0e10cSrcweir }
140cdf0e10cSrcweir // no longer needed
141cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
142cdf0e10cSrcweir }
143cdf0e10cSrcweir else // ptr to complex value | ref
144cdf0e10cSrcweir {
145cdf0e10cSrcweir pCppArgs[nPos] = *(void **)pCppStack;
146cdf0e10cSrcweir
147cdf0e10cSrcweir if (! rParam.bIn) // is pure out
148cdf0e10cSrcweir {
149cdf0e10cSrcweir // uno out is unconstructed mem!
150cdf0e10cSrcweir pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
151cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos;
152cdf0e10cSrcweir // will be released at reconversion
153cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
154cdf0e10cSrcweir }
155cdf0e10cSrcweir // is in/inout
156cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType(
157cdf0e10cSrcweir pParamTypeDescr ))
158cdf0e10cSrcweir {
159cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nPos] =
160cdf0e10cSrcweir alloca( pParamTypeDescr->nSize ),
161cdf0e10cSrcweir *(void **)pCppStack, pParamTypeDescr,
162cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
163cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
164cdf0e10cSrcweir // will be released at reconversion
165cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir else // direct way
168cdf0e10cSrcweir {
169cdf0e10cSrcweir pUnoArgs[nPos] = *(void **)pCppStack;
170cdf0e10cSrcweir // no longer needed
171cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
172cdf0e10cSrcweir }
173cdf0e10cSrcweir }
174cdf0e10cSrcweir pCppStack += sizeof(sal_Int32); // standard parameter length
175cdf0e10cSrcweir }
176cdf0e10cSrcweir
177cdf0e10cSrcweir // ExceptionHolder
178cdf0e10cSrcweir uno_Any aUnoExc; // Any will be constructed by callee
179cdf0e10cSrcweir uno_Any * pUnoExc = &aUnoExc;
180cdf0e10cSrcweir
181cdf0e10cSrcweir // invoke uno dispatch call
182cdf0e10cSrcweir (*pThis->getUnoI()->pDispatcher)(
183cdf0e10cSrcweir pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
184cdf0e10cSrcweir
185cdf0e10cSrcweir // in case an exception occured...
186cdf0e10cSrcweir if (pUnoExc)
187cdf0e10cSrcweir {
188cdf0e10cSrcweir // destruct temporary in/inout params
189cdf0e10cSrcweir for ( ; nTempIndizes--; )
190cdf0e10cSrcweir {
191cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
192cdf0e10cSrcweir
193cdf0e10cSrcweir if (pParams[nIndex].bIn) // is in/inout => was constructed
194cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex],
195cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes], 0 );
196cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
197cdf0e10cSrcweir }
198cdf0e10cSrcweir if (pReturnTypeDescr)
199cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
200cdf0e10cSrcweir
201cdf0e10cSrcweir CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc,
202cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() ); // has to destruct the any
203cdf0e10cSrcweir // is here for dummy
204cdf0e10cSrcweir return typelib_TypeClass_VOID;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir else // else no exception occured...
207cdf0e10cSrcweir {
208cdf0e10cSrcweir // temporary params
209cdf0e10cSrcweir for ( ; nTempIndizes--; )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
212cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr =
213cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes];
214cdf0e10cSrcweir
215cdf0e10cSrcweir if (pParams[nIndex].bOut) // inout/out
216cdf0e10cSrcweir {
217cdf0e10cSrcweir // convert and assign
218cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], pParamTypeDescr,
219cdf0e10cSrcweir cpp_release );
220cdf0e10cSrcweir uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex],
221cdf0e10cSrcweir pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
222cdf0e10cSrcweir }
223cdf0e10cSrcweir // destroy temp uno param
224cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
225cdf0e10cSrcweir
226cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
227cdf0e10cSrcweir }
228cdf0e10cSrcweir // return
229cdf0e10cSrcweir if (pCppReturn) // has complex return
230cdf0e10cSrcweir {
231cdf0e10cSrcweir if (pUnoReturn != pCppReturn) // needs reconversion
232cdf0e10cSrcweir {
233cdf0e10cSrcweir uno_copyAndConvertData( pCppReturn, pUnoReturn,
234cdf0e10cSrcweir pReturnTypeDescr, pThis->getBridge()->getUno2Cpp() );
235cdf0e10cSrcweir // destroy temp uno return
236cdf0e10cSrcweir uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
237cdf0e10cSrcweir }
238cdf0e10cSrcweir // complex return ptr is set to eax
239cdf0e10cSrcweir *(void **)pRegisterReturn = pCppReturn;
240cdf0e10cSrcweir }
241cdf0e10cSrcweir if (pReturnTypeDescr)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir typelib_TypeClass eRet =
244cdf0e10cSrcweir (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
245cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
246cdf0e10cSrcweir return eRet;
247cdf0e10cSrcweir }
248cdf0e10cSrcweir else
249cdf0e10cSrcweir return typelib_TypeClass_VOID;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir }
252cdf0e10cSrcweir
253cdf0e10cSrcweir
254cdf0e10cSrcweir //=====================================================================
cpp_mediate(sal_Int32 nFunctionIndex,sal_Int32 nVtableOffset,void ** pCallStack,sal_Int64 * pRegisterReturn)255cdf0e10cSrcweir static typelib_TypeClass cpp_mediate(
256cdf0e10cSrcweir sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
257cdf0e10cSrcweir void ** pCallStack,
258cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir OSL_ENSURE( sizeof(sal_Int32)==sizeof(void *), "### unexpected!" );
261cdf0e10cSrcweir
262cdf0e10cSrcweir // pCallStack: [ret *], this, params
263cdf0e10cSrcweir // _this_ ptr is patched cppu_XInterfaceProxy object
264cdf0e10cSrcweir void *pThis;
265cdf0e10cSrcweir if( nFunctionIndex & 0x80000000 )
266cdf0e10cSrcweir {
267cdf0e10cSrcweir nFunctionIndex &= 0x7fffffff;
268cdf0e10cSrcweir pThis = pCallStack[1];
269cdf0e10cSrcweir }
270cdf0e10cSrcweir else
271cdf0e10cSrcweir {
272cdf0e10cSrcweir pThis = pCallStack[0];
273cdf0e10cSrcweir }
274cdf0e10cSrcweir
275cdf0e10cSrcweir pThis = static_cast< char * >(pThis) - nVtableOffset;
276cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy * pCppI =
277cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
278cdf0e10cSrcweir pThis);
279cdf0e10cSrcweir
280cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
281cdf0e10cSrcweir
282cdf0e10cSrcweir OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex,
283cdf0e10cSrcweir "### illegal vtable index!" );
284cdf0e10cSrcweir if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
285cdf0e10cSrcweir {
286cdf0e10cSrcweir throw RuntimeException(
287cdf0e10cSrcweir OUString::createFromAscii("illegal vtable index!"),
288cdf0e10cSrcweir (XInterface *)pCppI );
289cdf0e10cSrcweir }
290cdf0e10cSrcweir
291cdf0e10cSrcweir // determine called method
292cdf0e10cSrcweir OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex,
293cdf0e10cSrcweir "### illegal vtable index!" );
294cdf0e10cSrcweir sal_Int32 nMemberPos =
295cdf0e10cSrcweir pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
296cdf0e10cSrcweir OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers,
297cdf0e10cSrcweir "### illegal member index!" );
298cdf0e10cSrcweir
299cdf0e10cSrcweir TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
300cdf0e10cSrcweir
301cdf0e10cSrcweir typelib_TypeClass eRet;
302cdf0e10cSrcweir switch (aMemberDescr.get()->eTypeClass)
303cdf0e10cSrcweir {
304cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
305cdf0e10cSrcweir {
306cdf0e10cSrcweir if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] ==
307cdf0e10cSrcweir nFunctionIndex)
308cdf0e10cSrcweir {
309cdf0e10cSrcweir // is GET method
310cdf0e10cSrcweir eRet = cpp2uno_call(
311cdf0e10cSrcweir pCppI, aMemberDescr.get(),
312cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
313cdf0e10cSrcweir 0, 0, // no params
314cdf0e10cSrcweir pCallStack, pRegisterReturn );
315cdf0e10cSrcweir }
316cdf0e10cSrcweir else
317cdf0e10cSrcweir {
318cdf0e10cSrcweir // is SET method
319cdf0e10cSrcweir typelib_MethodParameter aParam;
320cdf0e10cSrcweir aParam.pTypeRef =
321cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
322cdf0e10cSrcweir aParam.bIn = sal_True;
323cdf0e10cSrcweir aParam.bOut = sal_False;
324cdf0e10cSrcweir
325cdf0e10cSrcweir eRet = cpp2uno_call(
326cdf0e10cSrcweir pCppI, aMemberDescr.get(),
327cdf0e10cSrcweir 0, // indicates void return
328cdf0e10cSrcweir 1, &aParam,
329cdf0e10cSrcweir pCallStack, pRegisterReturn );
330cdf0e10cSrcweir }
331cdf0e10cSrcweir break;
332cdf0e10cSrcweir }
333cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
334cdf0e10cSrcweir {
335cdf0e10cSrcweir // is METHOD
336cdf0e10cSrcweir switch (nFunctionIndex)
337cdf0e10cSrcweir {
338cdf0e10cSrcweir case 1: // acquire()
339cdf0e10cSrcweir pCppI->acquireProxy(); // non virtual call!
340cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
341cdf0e10cSrcweir break;
342cdf0e10cSrcweir case 2: // release()
343cdf0e10cSrcweir pCppI->releaseProxy(); // non virtual call!
344cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
345cdf0e10cSrcweir break;
346cdf0e10cSrcweir case 0: // queryInterface() opt
347cdf0e10cSrcweir {
348cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
349cdf0e10cSrcweir TYPELIB_DANGER_GET(&pTD,
350cdf0e10cSrcweir reinterpret_cast<Type *>(pCallStack[2])->getTypeLibType());
351cdf0e10cSrcweir if (pTD)
352cdf0e10cSrcweir {
353cdf0e10cSrcweir XInterface * pInterface = 0;
354cdf0e10cSrcweir (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
355cdf0e10cSrcweir pCppI->getBridge()->getCppEnv(),
356cdf0e10cSrcweir (void **)&pInterface, pCppI->getOid().pData,
357cdf0e10cSrcweir (typelib_InterfaceTypeDescription *)pTD );
358cdf0e10cSrcweir
359cdf0e10cSrcweir if (pInterface)
360cdf0e10cSrcweir {
361cdf0e10cSrcweir ::uno_any_construct(
362cdf0e10cSrcweir reinterpret_cast< uno_Any * >( pCallStack[0] ),
363cdf0e10cSrcweir &pInterface, pTD, cpp_acquire );
364cdf0e10cSrcweir pInterface->release();
365cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
366cdf0e10cSrcweir *(void **)pRegisterReturn = pCallStack[0];
367cdf0e10cSrcweir eRet = typelib_TypeClass_ANY;
368cdf0e10cSrcweir break;
369cdf0e10cSrcweir }
370cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
371cdf0e10cSrcweir }
372cdf0e10cSrcweir } // else perform queryInterface()
373cdf0e10cSrcweir default:
374cdf0e10cSrcweir eRet = cpp2uno_call(
375cdf0e10cSrcweir pCppI, aMemberDescr.get(),
376cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
377cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
378cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
379cdf0e10cSrcweir pCallStack, pRegisterReturn );
380cdf0e10cSrcweir }
381cdf0e10cSrcweir break;
382cdf0e10cSrcweir }
383cdf0e10cSrcweir default:
384cdf0e10cSrcweir {
385cdf0e10cSrcweir throw RuntimeException(
386cdf0e10cSrcweir OUString::createFromAscii("no member description found!"),
387cdf0e10cSrcweir (XInterface *)pCppI );
388cdf0e10cSrcweir // is here for dummy
389cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
390cdf0e10cSrcweir }
391cdf0e10cSrcweir }
392cdf0e10cSrcweir
393cdf0e10cSrcweir return eRet;
394cdf0e10cSrcweir }
395cdf0e10cSrcweir }
396cdf0e10cSrcweir
397cdf0e10cSrcweir //=======================================================================
398cdf0e10cSrcweir /**
399cdf0e10cSrcweir * is called on incoming vtable calls
400cdf0e10cSrcweir * (called by asm snippets)
401cdf0e10cSrcweir */
402cdf0e10cSrcweir
cpp_vtable_call(long * pFunctionAndOffset,void ** pCallStack)403cdf0e10cSrcweir extern "C" sal_Int64 cpp_vtable_call( long *pFunctionAndOffset,
404cdf0e10cSrcweir void **pCallStack )
405cdf0e10cSrcweir {
406cdf0e10cSrcweir sal_Int64 nRegReturn;
407cdf0e10cSrcweir typelib_TypeClass aType = cpp_mediate( pFunctionAndOffset[0], pFunctionAndOffset[1], pCallStack,
408cdf0e10cSrcweir &nRegReturn );
409cdf0e10cSrcweir
410cdf0e10cSrcweir switch( aType )
411cdf0e10cSrcweir {
412cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
413cdf0e10cSrcweir case typelib_TypeClass_BYTE:
414cdf0e10cSrcweir nRegReturn = (unsigned long)(*(unsigned char *)&nRegReturn);
415cdf0e10cSrcweir break;
416cdf0e10cSrcweir case typelib_TypeClass_CHAR:
417cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
418cdf0e10cSrcweir case typelib_TypeClass_SHORT:
419cdf0e10cSrcweir nRegReturn = (unsigned long)(*(unsigned short *)&nRegReturn);
420cdf0e10cSrcweir break;
421cdf0e10cSrcweir case typelib_TypeClass_ENUM:
422cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
423cdf0e10cSrcweir case typelib_TypeClass_LONG:
424cdf0e10cSrcweir nRegReturn = (unsigned long)(*(unsigned int *)&nRegReturn);
425cdf0e10cSrcweir break;
426cdf0e10cSrcweir case typelib_TypeClass_VOID:
427cdf0e10cSrcweir default:
428cdf0e10cSrcweir break;
429cdf0e10cSrcweir }
430cdf0e10cSrcweir
431cdf0e10cSrcweir return nRegReturn;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir
434cdf0e10cSrcweir extern "C" void privateSnippetExecutor(void);
435cdf0e10cSrcweir
436cdf0e10cSrcweir namespace
437cdf0e10cSrcweir {
438cdf0e10cSrcweir const int codeSnippetSize = 20;
439cdf0e10cSrcweir
codeSnippet(unsigned char * code,sal_Int32 functionIndex,sal_Int32 vtableOffset,bool bHasHiddenParam)440cdf0e10cSrcweir unsigned char *codeSnippet(unsigned char* code, sal_Int32 functionIndex,
441cdf0e10cSrcweir sal_Int32 vtableOffset, bool bHasHiddenParam)
442cdf0e10cSrcweir {
443cdf0e10cSrcweir if (bHasHiddenParam)
444cdf0e10cSrcweir functionIndex |= 0x80000000;
445cdf0e10cSrcweir
446cdf0e10cSrcweir unsigned long * p = (unsigned long *)code;
447cdf0e10cSrcweir
448cdf0e10cSrcweir *p++ = 0xE1A0C00F;
449cdf0e10cSrcweir *p++ = 0xE59FF004;
450cdf0e10cSrcweir *p++ = (unsigned long)functionIndex;
451cdf0e10cSrcweir *p++ = (unsigned long)vtableOffset;
452cdf0e10cSrcweir *p++ = (unsigned long)privateSnippetExecutor;
453cdf0e10cSrcweir
454cdf0e10cSrcweir return code + codeSnippetSize;
455cdf0e10cSrcweir }
456cdf0e10cSrcweir }
457cdf0e10cSrcweir
458cdf0e10cSrcweir struct bridges::cpp_uno::shared::VtableFactory::Slot { void * fn; };
459cdf0e10cSrcweir
460cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
mapBlockToVtable(void * block)461cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
462cdf0e10cSrcweir {
463cdf0e10cSrcweir return static_cast< Slot * >(block) + 2;
464cdf0e10cSrcweir }
465cdf0e10cSrcweir
getBlockSize(sal_Int32 slotCount)466cdf0e10cSrcweir sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
467cdf0e10cSrcweir sal_Int32 slotCount)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
470cdf0e10cSrcweir }
471cdf0e10cSrcweir
472cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
initializeBlock(void * block,sal_Int32 slotCount)473cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::initializeBlock(
474cdf0e10cSrcweir void * block, sal_Int32 slotCount)
475cdf0e10cSrcweir {
476cdf0e10cSrcweir Slot * slots = mapBlockToVtable(block);
477cdf0e10cSrcweir slots[-2].fn = 0;
478cdf0e10cSrcweir slots[-1].fn = 0;
479cdf0e10cSrcweir return slots + slotCount;
480cdf0e10cSrcweir }
481cdf0e10cSrcweir
addLocalFunctions(Slot ** slots,unsigned char * code,sal_PtrDiff writetoexecdiff,typelib_InterfaceTypeDescription const * type,sal_Int32 functionOffset,sal_Int32 functionCount,sal_Int32 vtableOffset)482cdf0e10cSrcweir unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
483cdf0e10cSrcweir Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
484cdf0e10cSrcweir typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
485cdf0e10cSrcweir sal_Int32 functionCount, sal_Int32 vtableOffset)
486cdf0e10cSrcweir {
487cdf0e10cSrcweir (*slots) -= functionCount;
488cdf0e10cSrcweir Slot * s = *slots;
489cdf0e10cSrcweir for (sal_Int32 i = 0; i < type->nMembers; ++i)
490cdf0e10cSrcweir {
491cdf0e10cSrcweir typelib_TypeDescription * member = 0;
492cdf0e10cSrcweir TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
493cdf0e10cSrcweir OSL_ASSERT(member != 0);
494cdf0e10cSrcweir switch (member->eTypeClass)
495cdf0e10cSrcweir {
496cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
497cdf0e10cSrcweir {
498cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription *pAttrTD =
499cdf0e10cSrcweir reinterpret_cast<typelib_InterfaceAttributeTypeDescription *>( member );
500cdf0e10cSrcweir
501cdf0e10cSrcweir // Getter:
502cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
503cdf0e10cSrcweir code = codeSnippet(
504cdf0e10cSrcweir code, functionOffset++, vtableOffset,
505cdf0e10cSrcweir arm::return_in_hidden_param( pAttrTD->pAttributeTypeRef ));
506cdf0e10cSrcweir
507cdf0e10cSrcweir // Setter:
508cdf0e10cSrcweir if (!pAttrTD->bReadOnly)
509cdf0e10cSrcweir {
510cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
511cdf0e10cSrcweir code = codeSnippet(
512cdf0e10cSrcweir code, functionOffset++, vtableOffset, false);
513cdf0e10cSrcweir }
514cdf0e10cSrcweir break;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
517cdf0e10cSrcweir {
518cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
519cdf0e10cSrcweir
520cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription *pMethodTD =
521cdf0e10cSrcweir reinterpret_cast<
522cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription * >(member);
523cdf0e10cSrcweir
524cdf0e10cSrcweir code = codeSnippet(code, functionOffset++, vtableOffset,
525cdf0e10cSrcweir arm::return_in_hidden_param(pMethodTD->pReturnTypeRef));
526cdf0e10cSrcweir break;
527cdf0e10cSrcweir }
528cdf0e10cSrcweir default:
529cdf0e10cSrcweir OSL_ASSERT(false);
530cdf0e10cSrcweir break;
531cdf0e10cSrcweir }
532cdf0e10cSrcweir TYPELIB_DANGER_RELEASE(member);
533cdf0e10cSrcweir }
534cdf0e10cSrcweir return code;
535cdf0e10cSrcweir }
536cdf0e10cSrcweir
flushCode(unsigned char const * beg,unsigned char const * end)537cdf0e10cSrcweir void bridges::cpp_uno::shared::VtableFactory::flushCode(
538cdf0e10cSrcweir unsigned char const *beg, unsigned char const *end)
539cdf0e10cSrcweir {
540cdf0e10cSrcweir static void (*clear_cache)(unsigned char const*, unsigned char const*)
541cdf0e10cSrcweir = (void (*)(unsigned char const*, unsigned char const*))
542cdf0e10cSrcweir dlsym(RTLD_DEFAULT, "__clear_cache");
543cdf0e10cSrcweir (*clear_cache)(beg, end);
544cdf0e10cSrcweir }
545cdf0e10cSrcweir
546cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
547