161dff127SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
361dff127SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
461dff127SAndrew Rist * or more contributor license agreements. See the NOTICE file
561dff127SAndrew Rist * distributed with this work for additional information
661dff127SAndrew Rist * regarding copyright ownership. The ASF licenses this file
761dff127SAndrew Rist * to you under the Apache License, Version 2.0 (the
861dff127SAndrew Rist * "License"); you may not use this file except in compliance
961dff127SAndrew Rist * with the License. You may obtain a copy of the License at
1061dff127SAndrew Rist *
1161dff127SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
1261dff127SAndrew Rist *
1361dff127SAndrew Rist * Unless required by applicable law or agreed to in writing,
1461dff127SAndrew Rist * software distributed under the License is distributed on an
1561dff127SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1661dff127SAndrew Rist * KIND, either express or implied. See the License for the
1761dff127SAndrew Rist * specific language governing permissions and limitations
1861dff127SAndrew Rist * under the License.
1961dff127SAndrew Rist *
2061dff127SAndrew Rist *************************************************************/
2161dff127SAndrew Rist
2261dff127SAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_bridges.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <com/sun/star/uno/genfunc.hxx>
28cdf0e10cSrcweir #include <uno/data.h>
29cdf0e10cSrcweir #include <typelib/typedescription.hxx>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include "bridges/cpp_uno/shared/bridge.hxx"
32cdf0e10cSrcweir #include "bridges/cpp_uno/shared/cppinterfaceproxy.hxx"
33cdf0e10cSrcweir #include "bridges/cpp_uno/shared/types.hxx"
34cdf0e10cSrcweir #include "bridges/cpp_uno/shared/vtablefactory.hxx"
35cdf0e10cSrcweir
36cdf0e10cSrcweir #include "share.hxx"
37cdf0e10cSrcweir #include <stdio.h>
38cdf0e10cSrcweir #include <string.h>
39cdf0e10cSrcweir
40cdf0e10cSrcweir using namespace ::com::sun::star::uno;
41cdf0e10cSrcweir
42cdf0e10cSrcweir namespace
43cdf0e10cSrcweir {
44cdf0e10cSrcweir
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)45cdf0e10cSrcweir static typelib_TypeClass cpp2uno_call(
46cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
47cdf0e10cSrcweir const typelib_TypeDescription * pMemberTypeDescr,
48cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
49cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams,
50cdf0e10cSrcweir void ** gpreg, void ** fpreg, void ** ovrflw,
51cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir int ng = 0; //number of gpr registers used
54cdf0e10cSrcweir int nf = 0; //number of fpr regsiters used
55cdf0e10cSrcweir void ** pCppStack; //temporary stack pointer
56cdf0e10cSrcweir
57cdf0e10cSrcweir // gpreg: [ret *], this, [gpr params]
58cdf0e10cSrcweir // fpreg: [fpr params]
59cdf0e10cSrcweir // ovrflw: [gpr or fpr params (properly aligned)]
60cdf0e10cSrcweir
61cdf0e10cSrcweir // return
62cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
63cdf0e10cSrcweir if (pReturnTypeRef)
64cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
65cdf0e10cSrcweir
66cdf0e10cSrcweir void * pUnoReturn = 0;
67cdf0e10cSrcweir void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
68cdf0e10cSrcweir
69cdf0e10cSrcweir if (pReturnTypeDescr)
70cdf0e10cSrcweir {
71cdf0e10cSrcweir if (bridges::cpp_uno::shared::isSimpleType( pReturnTypeDescr ))
72cdf0e10cSrcweir {
73cdf0e10cSrcweir pUnoReturn = pRegisterReturn; // direct way for simple types
74cdf0e10cSrcweir }
75cdf0e10cSrcweir else // complex return via ptr (pCppReturn)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir pCppReturn = *(void **)gpreg;
78cdf0e10cSrcweir gpreg++;
79cdf0e10cSrcweir ng++;
80cdf0e10cSrcweir
81cdf0e10cSrcweir pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
82cdf0e10cSrcweir ? alloca( pReturnTypeDescr->nSize )
83cdf0e10cSrcweir : pCppReturn); // direct way
84cdf0e10cSrcweir }
85cdf0e10cSrcweir }
86cdf0e10cSrcweir // pop this
87cdf0e10cSrcweir gpreg++;
88cdf0e10cSrcweir ng++;
89cdf0e10cSrcweir
90cdf0e10cSrcweir // stack space
91cdf0e10cSrcweir OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" );
92cdf0e10cSrcweir // parameters
93cdf0e10cSrcweir void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
94cdf0e10cSrcweir void ** pCppArgs = pUnoArgs + nParams;
95cdf0e10cSrcweir // indizes of values this have to be converted (interface conversion cpp<=>uno)
96cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
97cdf0e10cSrcweir // type descriptions for reconversions
98cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
99cdf0e10cSrcweir
100cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
101cdf0e10cSrcweir
102cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
103cdf0e10cSrcweir {
104cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
105cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
106cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
107cdf0e10cSrcweir
108cdf0e10cSrcweir if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr )) // value
109cdf0e10cSrcweir {
110cdf0e10cSrcweir
111cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir
114cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
115cdf0e10cSrcweir if (nf < 2) {
116cdf0e10cSrcweir pCppArgs[nPos] = fpreg;
117cdf0e10cSrcweir pUnoArgs[nPos] = fpreg;
118cdf0e10cSrcweir nf++;
119cdf0e10cSrcweir fpreg += 2;
120cdf0e10cSrcweir } else {
121cdf0e10cSrcweir pCppArgs[nPos] = ovrflw;
122cdf0e10cSrcweir pUnoArgs[nPos] = ovrflw;
123cdf0e10cSrcweir ovrflw += 2;
124cdf0e10cSrcweir }
125cdf0e10cSrcweir break;
126cdf0e10cSrcweir
127cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
128cdf0e10cSrcweir // fpreg are all double values so need to
129cdf0e10cSrcweir // modify fpreg to be a single word float value
130cdf0e10cSrcweir if (nf < 2) {
131cdf0e10cSrcweir // float tmp = (float) (*((double *)fpreg));
132cdf0e10cSrcweir // (*((float *) fpreg)) = tmp;
133cdf0e10cSrcweir pCppArgs[nPos] = fpreg;
134cdf0e10cSrcweir pUnoArgs[nPos] = fpreg;
135cdf0e10cSrcweir nf++;
136cdf0e10cSrcweir fpreg += 2;
137cdf0e10cSrcweir } else {
138cdf0e10cSrcweir pCppArgs[nPos] = ovrflw;
139cdf0e10cSrcweir pUnoArgs[nPos] = ovrflw;
140cdf0e10cSrcweir ovrflw += 1;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir break;
143cdf0e10cSrcweir
144cdf0e10cSrcweir case typelib_TypeClass_HYPER:
145cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
146cdf0e10cSrcweir if (ng < 4) {
147cdf0e10cSrcweir pCppArgs[nPos] = gpreg;
148cdf0e10cSrcweir pUnoArgs[nPos] = gpreg;
149cdf0e10cSrcweir ng += 2;
150cdf0e10cSrcweir gpreg += 2;
151cdf0e10cSrcweir } else {
152cdf0e10cSrcweir pCppArgs[nPos] = ovrflw;
153cdf0e10cSrcweir pUnoArgs[nPos] = ovrflw;
154cdf0e10cSrcweir ovrflw += 2;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir break;
157cdf0e10cSrcweir
158cdf0e10cSrcweir case typelib_TypeClass_BYTE:
159cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
160cdf0e10cSrcweir if (ng < 5) {
161cdf0e10cSrcweir pCppArgs[nPos] = (((char *)gpreg) + 3);
162cdf0e10cSrcweir pUnoArgs[nPos] = (((char *)gpreg) + 3);
163cdf0e10cSrcweir ng++;
164cdf0e10cSrcweir gpreg++;
165cdf0e10cSrcweir } else {
166cdf0e10cSrcweir pCppArgs[nPos] = (((char *)ovrflw) + 3);
167cdf0e10cSrcweir pUnoArgs[nPos] = (((char *)ovrflw) + 3);
168cdf0e10cSrcweir ovrflw++;
169cdf0e10cSrcweir }
170cdf0e10cSrcweir break;
171cdf0e10cSrcweir
172cdf0e10cSrcweir
173cdf0e10cSrcweir case typelib_TypeClass_CHAR:
174cdf0e10cSrcweir case typelib_TypeClass_SHORT:
175cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
176cdf0e10cSrcweir if (ng < 5) {
177cdf0e10cSrcweir pCppArgs[nPos] = (((char *)gpreg)+ 2);
178cdf0e10cSrcweir pUnoArgs[nPos] = (((char *)gpreg)+ 2);
179cdf0e10cSrcweir ng++;
180cdf0e10cSrcweir gpreg++;
181cdf0e10cSrcweir } else {
182cdf0e10cSrcweir pCppArgs[nPos] = (((char *)ovrflw) + 2);
183cdf0e10cSrcweir pUnoArgs[nPos] = (((char *)ovrflw) + 2);
184cdf0e10cSrcweir ovrflw++;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir break;
187cdf0e10cSrcweir
188cdf0e10cSrcweir
189cdf0e10cSrcweir default:
190cdf0e10cSrcweir if (ng < 5) {
191cdf0e10cSrcweir pCppArgs[nPos] = gpreg;
192cdf0e10cSrcweir pUnoArgs[nPos] = gpreg;
193cdf0e10cSrcweir ng++;
194cdf0e10cSrcweir gpreg++;
195cdf0e10cSrcweir } else {
196cdf0e10cSrcweir pCppArgs[nPos] = ovrflw;
197cdf0e10cSrcweir pUnoArgs[nPos] = ovrflw;
198cdf0e10cSrcweir ovrflw++;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir break;
201cdf0e10cSrcweir
202cdf0e10cSrcweir }
203cdf0e10cSrcweir // no longer needed
204cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
205cdf0e10cSrcweir }
206cdf0e10cSrcweir else // ptr to complex value | ref
207cdf0e10cSrcweir {
208cdf0e10cSrcweir
209cdf0e10cSrcweir if (ng < 5) {
210cdf0e10cSrcweir pCppArgs[nPos] = *(void **)gpreg;
211cdf0e10cSrcweir pCppStack = gpreg;
212cdf0e10cSrcweir ng++;
213cdf0e10cSrcweir gpreg++;
214cdf0e10cSrcweir } else {
215cdf0e10cSrcweir pCppArgs[nPos] = *(void **)ovrflw;
216cdf0e10cSrcweir pCppStack = ovrflw;
217cdf0e10cSrcweir ovrflw++;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir
220cdf0e10cSrcweir if (! rParam.bIn) // is pure out
221cdf0e10cSrcweir {
222cdf0e10cSrcweir // uno out is unconstructed mem!
223cdf0e10cSrcweir pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
224cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos;
225cdf0e10cSrcweir // will be released at reconversion
226cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
227cdf0e10cSrcweir }
228cdf0e10cSrcweir // is in/inout
229cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
230cdf0e10cSrcweir {
231cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
232cdf0e10cSrcweir *(void **)pCppStack, pParamTypeDescr,
233cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
234cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
235cdf0e10cSrcweir // will be released at reconversion
236cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
237cdf0e10cSrcweir }
238cdf0e10cSrcweir else // direct way
239cdf0e10cSrcweir {
240cdf0e10cSrcweir pUnoArgs[nPos] = *(void **)pCppStack;
241cdf0e10cSrcweir // no longer needed
242cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
243cdf0e10cSrcweir }
244cdf0e10cSrcweir }
245cdf0e10cSrcweir }
246cdf0e10cSrcweir
247cdf0e10cSrcweir // ExceptionHolder
248cdf0e10cSrcweir uno_Any aUnoExc; // Any will be constructed by callee
249cdf0e10cSrcweir uno_Any * pUnoExc = &aUnoExc;
250cdf0e10cSrcweir
251cdf0e10cSrcweir // invoke uno dispatch call
252cdf0e10cSrcweir (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
253cdf0e10cSrcweir
254*07a3d7f1SPedro Giffuni // in case an exception occurred...
255cdf0e10cSrcweir if (pUnoExc)
256cdf0e10cSrcweir {
257cdf0e10cSrcweir // destruct temporary in/inout params
258cdf0e10cSrcweir for ( ; nTempIndizes--; )
259cdf0e10cSrcweir {
260cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
261cdf0e10cSrcweir
262cdf0e10cSrcweir if (pParams[nIndex].bIn) // is in/inout => was constructed
263cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 );
264cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
265cdf0e10cSrcweir }
266cdf0e10cSrcweir if (pReturnTypeDescr)
267cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
268cdf0e10cSrcweir
269cdf0e10cSrcweir CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() ); // has to destruct the any
270cdf0e10cSrcweir // is here for dummy
271cdf0e10cSrcweir return typelib_TypeClass_VOID;
272cdf0e10cSrcweir }
273*07a3d7f1SPedro Giffuni else // else no exception occurred...
274cdf0e10cSrcweir {
275cdf0e10cSrcweir // temporary params
276cdf0e10cSrcweir for ( ; nTempIndizes--; )
277cdf0e10cSrcweir {
278cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
279cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
280cdf0e10cSrcweir
281cdf0e10cSrcweir if (pParams[nIndex].bOut) // inout/out
282cdf0e10cSrcweir {
283cdf0e10cSrcweir // convert and assign
284cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
285cdf0e10cSrcweir uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
286cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
287cdf0e10cSrcweir }
288cdf0e10cSrcweir // destroy temp uno param
289cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
290cdf0e10cSrcweir
291cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
292cdf0e10cSrcweir }
293cdf0e10cSrcweir // return
294cdf0e10cSrcweir if (pCppReturn) // has complex return
295cdf0e10cSrcweir {
296cdf0e10cSrcweir if (pUnoReturn != pCppReturn) // needs reconversion
297cdf0e10cSrcweir {
298cdf0e10cSrcweir uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
299cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
300cdf0e10cSrcweir // destroy temp uno return
301cdf0e10cSrcweir uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
302cdf0e10cSrcweir }
303cdf0e10cSrcweir // complex return ptr is set to return reg
304cdf0e10cSrcweir *(void **)pRegisterReturn = pCppReturn;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir if (pReturnTypeDescr)
307cdf0e10cSrcweir {
308cdf0e10cSrcweir typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
309cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
310cdf0e10cSrcweir return eRet;
311cdf0e10cSrcweir }
312cdf0e10cSrcweir else
313cdf0e10cSrcweir return typelib_TypeClass_VOID;
314cdf0e10cSrcweir }
315cdf0e10cSrcweir }
316cdf0e10cSrcweir
317cdf0e10cSrcweir
318cdf0e10cSrcweir //============================================================================
cpp_mediate(sal_uInt32 nOffsetAndIndex,void ** gpreg,void ** fpreg,void ** ovrflw,sal_Int64 * pRegisterReturn)319cdf0e10cSrcweir static typelib_TypeClass cpp_mediate(
320cdf0e10cSrcweir sal_uInt32 nOffsetAndIndex,
321cdf0e10cSrcweir void ** gpreg, void ** fpreg, void ** ovrflw,
322cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
323cdf0e10cSrcweir {
324cdf0e10cSrcweir OSL_ENSURE( sizeof(sal_Int32)==sizeof(void *), "### unexpected!" );
325cdf0e10cSrcweir
326cdf0e10cSrcweir sal_Int16 nVtableOffset = (nOffsetAndIndex >> 16);
327cdf0e10cSrcweir sal_Int16 nFunctionIndex = (nOffsetAndIndex & 0xFFFF);
328cdf0e10cSrcweir
329cdf0e10cSrcweir // gpreg: [ret *], this, [other gpr params]
330cdf0e10cSrcweir // fpreg: [fpr params]
331cdf0e10cSrcweir // ovrflw: [gpr or fpr params (properly aligned)]
332cdf0e10cSrcweir
333cdf0e10cSrcweir // _this_ ptr is patched cppu_XInterfaceProxy object
334cdf0e10cSrcweir void * pThis;
335cdf0e10cSrcweir if( nFunctionIndex & 0x8000 )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir nFunctionIndex &= 0x7fff;
338cdf0e10cSrcweir pThis = gpreg[1];
339cdf0e10cSrcweir }
340cdf0e10cSrcweir else
341cdf0e10cSrcweir {
342cdf0e10cSrcweir pThis = gpreg[0];
343cdf0e10cSrcweir }
344cdf0e10cSrcweir
345cdf0e10cSrcweir pThis = static_cast< char * >(pThis) - nVtableOffset;
346cdf0e10cSrcweir
347cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
348cdf0e10cSrcweir = bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
349cdf0e10cSrcweir pThis);
350cdf0e10cSrcweir
351cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
352cdf0e10cSrcweir
353cdf0e10cSrcweir
354cdf0e10cSrcweir OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
355cdf0e10cSrcweir if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
356cdf0e10cSrcweir {
357cdf0e10cSrcweir throw RuntimeException(
358cdf0e10cSrcweir rtl::OUString::createFromAscii("illegal vtable index!"),
359cdf0e10cSrcweir (XInterface *)pCppI );
360cdf0e10cSrcweir }
361cdf0e10cSrcweir
362cdf0e10cSrcweir // determine called method
363cdf0e10cSrcweir OSL_ENSURE( nVtableCall < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
364cdf0e10cSrcweir sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
365cdf0e10cSrcweir OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" );
366cdf0e10cSrcweir
367cdf0e10cSrcweir TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
368cdf0e10cSrcweir
369cdf0e10cSrcweir typelib_TypeClass eRet;
370cdf0e10cSrcweir switch (aMemberDescr.get()->eTypeClass)
371cdf0e10cSrcweir {
372cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
373cdf0e10cSrcweir {
374cdf0e10cSrcweir if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
375cdf0e10cSrcweir {
376cdf0e10cSrcweir // is GET method
377cdf0e10cSrcweir eRet = cpp2uno_call(
378cdf0e10cSrcweir pCppI, aMemberDescr.get(),
379cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
380cdf0e10cSrcweir 0, 0, // no params
381cdf0e10cSrcweir gpreg, fpreg, ovrflw, pRegisterReturn );
382cdf0e10cSrcweir }
383cdf0e10cSrcweir else
384cdf0e10cSrcweir {
385cdf0e10cSrcweir // is SET method
386cdf0e10cSrcweir typelib_MethodParameter aParam;
387cdf0e10cSrcweir aParam.pTypeRef =
388cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
389cdf0e10cSrcweir aParam.bIn = sal_True;
390cdf0e10cSrcweir aParam.bOut = sal_False;
391cdf0e10cSrcweir
392cdf0e10cSrcweir eRet = cpp2uno_call(
393cdf0e10cSrcweir pCppI, aMemberDescr.get(),
394cdf0e10cSrcweir 0, // indicates void return
395cdf0e10cSrcweir 1, &aParam,
396cdf0e10cSrcweir gpreg, fpreg, ovrflw, pRegisterReturn );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir break;
399cdf0e10cSrcweir }
400cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
401cdf0e10cSrcweir {
402cdf0e10cSrcweir // is METHOD
403cdf0e10cSrcweir switch (nFunctionIndex)
404cdf0e10cSrcweir {
405cdf0e10cSrcweir case 1: // acquire()
406cdf0e10cSrcweir pCppI->acquireProxy(); // non virtual call!
407cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
408cdf0e10cSrcweir break;
409cdf0e10cSrcweir case 2: // release()
410cdf0e10cSrcweir pCppI->releaseProxy(); // non virtual call!
411cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
412cdf0e10cSrcweir break;
413cdf0e10cSrcweir case 0: // queryInterface() opt
414cdf0e10cSrcweir {
415cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
416cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
417cdf0e10cSrcweir if (pTD)
418cdf0e10cSrcweir {
419cdf0e10cSrcweir XInterface * pInterface = 0;
420cdf0e10cSrcweir (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
421cdf0e10cSrcweir pCppI->getBridge()->getCppEnv(),
422cdf0e10cSrcweir (void **)&pInterface, pCppI->getOid().pData,
423cdf0e10cSrcweir (typelib_InterfaceTypeDescription *)pTD );
424cdf0e10cSrcweir
425cdf0e10cSrcweir if (pInterface)
426cdf0e10cSrcweir {
427cdf0e10cSrcweir ::uno_any_construct(
428cdf0e10cSrcweir reinterpret_cast< uno_Any * >( gpreg[0] ),
429cdf0e10cSrcweir &pInterface, pTD, cpp_acquire );
430cdf0e10cSrcweir pInterface->release();
431cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
432cdf0e10cSrcweir *(void **)pRegisterReturn = gpreg[0];
433cdf0e10cSrcweir eRet = typelib_TypeClass_ANY;
434cdf0e10cSrcweir break;
435cdf0e10cSrcweir }
436cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
437cdf0e10cSrcweir }
438cdf0e10cSrcweir } // else perform queryInterface()
439cdf0e10cSrcweir default:
440cdf0e10cSrcweir eRet = cpp2uno_call(
441cdf0e10cSrcweir pCppI, aMemberDescr.get(),
442cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
443cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
444cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
445cdf0e10cSrcweir gpreg, fpreg, ovrflw, pRegisterReturn );
446cdf0e10cSrcweir }
447cdf0e10cSrcweir break;
448cdf0e10cSrcweir }
449cdf0e10cSrcweir default:
450cdf0e10cSrcweir {
451cdf0e10cSrcweir throw RuntimeException(
452cdf0e10cSrcweir rtl::OUString::createFromAscii("no member description found!"),
453cdf0e10cSrcweir (XInterface *)pCppI );
454cdf0e10cSrcweir // is here for dummy
455cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
456cdf0e10cSrcweir }
457cdf0e10cSrcweir }
458cdf0e10cSrcweir
459cdf0e10cSrcweir return eRet;
460cdf0e10cSrcweir }
461cdf0e10cSrcweir
462cdf0e10cSrcweir //==================================================================================================
463cdf0e10cSrcweir /**
464cdf0e10cSrcweir * is called on incoming vtable calls
465cdf0e10cSrcweir * (called by asm snippets)
466cdf0e10cSrcweir */
privateSnippetExecutor(sal_uInt32 nOffsetAndIndex,void ** gpregptr,void ** fpregptr,void ** ovrflw)467cdf0e10cSrcweir static void privateSnippetExecutor( sal_uInt32 nOffsetAndIndex, void** gpregptr, void** fpregptr, void** ovrflw)
468cdf0e10cSrcweir {
469cdf0e10cSrcweir #ifdef CMC_DEBUG
470cdf0e10cSrcweir fprintf(stderr, "privateSnippetExecutor\n");
471cdf0e10cSrcweir #endif
472cdf0e10cSrcweir
473cdf0e10cSrcweir
474cdf0e10cSrcweir sal_Int32 gpreg[8];
475cdf0e10cSrcweir double fpreg[8];
476cdf0e10cSrcweir
477cdf0e10cSrcweir memcpy( gpreg, gpregptr, 32);
478cdf0e10cSrcweir memcpy( fpreg, fpregptr, 64);
479cdf0e10cSrcweir
480cdf0e10cSrcweir volatile long nRegReturn[2];
481cdf0e10cSrcweir
482cdf0e10cSrcweir typelib_TypeClass aType =
483cdf0e10cSrcweir cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, ovrflw,
484cdf0e10cSrcweir (sal_Int64*)nRegReturn );
485cdf0e10cSrcweir
486cdf0e10cSrcweir switch( aType )
487cdf0e10cSrcweir {
488cdf0e10cSrcweir
489cdf0e10cSrcweir // move return value into register space
490cdf0e10cSrcweir // (will be loaded by machine code snippet)
491cdf0e10cSrcweir
492cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
493cdf0e10cSrcweir {
494cdf0e10cSrcweir unsigned long tmp = (unsigned long)(*(unsigned char *)nRegReturn);
495cdf0e10cSrcweir __asm__ volatile ( "l 2,%0\n\t" : :
496cdf0e10cSrcweir "m"(tmp) : "2" );
497cdf0e10cSrcweir break;
498cdf0e10cSrcweir }
499cdf0e10cSrcweir case typelib_TypeClass_BYTE:
500cdf0e10cSrcweir {
501cdf0e10cSrcweir long tmp = (long)(*(signed char *)nRegReturn);
502cdf0e10cSrcweir __asm__ volatile ( "l 2,%0\n\t" : :
503cdf0e10cSrcweir "m"(tmp) : "2" );
504cdf0e10cSrcweir break;
505cdf0e10cSrcweir }
506cdf0e10cSrcweir case typelib_TypeClass_CHAR:
507cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
508cdf0e10cSrcweir {
509cdf0e10cSrcweir unsigned long tmp = (unsigned long)(*(unsigned short *)nRegReturn);
510cdf0e10cSrcweir __asm__ volatile ( "l 2,%0\n\t" : :
511cdf0e10cSrcweir "m"(tmp) : "2" );
512cdf0e10cSrcweir break;
513cdf0e10cSrcweir }
514cdf0e10cSrcweir case typelib_TypeClass_SHORT:
515cdf0e10cSrcweir {
516cdf0e10cSrcweir long tmp = (long)(*(short *)nRegReturn);
517cdf0e10cSrcweir __asm__ volatile ( "l 2,%0\n\t" : :
518cdf0e10cSrcweir "m"(tmp) : "2" );
519cdf0e10cSrcweir break;
520cdf0e10cSrcweir }
521cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
522cdf0e10cSrcweir __asm__ volatile ( "le 0,%0\n\t" : :
523cdf0e10cSrcweir "m" (*((float*)nRegReturn)) : "16" );
524cdf0e10cSrcweir break;
525cdf0e10cSrcweir
526cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
527cdf0e10cSrcweir __asm__ volatile ( "ld 0,%0\n\t" : :
528cdf0e10cSrcweir "m" (*((double*)nRegReturn)) : "16" );
529cdf0e10cSrcweir break;
530cdf0e10cSrcweir
531cdf0e10cSrcweir case typelib_TypeClass_HYPER:
532cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
533cdf0e10cSrcweir __asm__ volatile ( "lm 2,3,%0\n\t" : :
534cdf0e10cSrcweir "m"(nRegReturn[0]) : "2", "3" );
535cdf0e10cSrcweir break;
536cdf0e10cSrcweir
537cdf0e10cSrcweir default:
538cdf0e10cSrcweir __asm__ volatile ( "l 2,%0\n\t" : :
539cdf0e10cSrcweir "m"(nRegReturn[0]) : "2" );
540cdf0e10cSrcweir break;
541cdf0e10cSrcweir }
542cdf0e10cSrcweir }
543cdf0e10cSrcweir
544cdf0e10cSrcweir const int codeSnippetSize = 50;
545cdf0e10cSrcweir
codeSnippet(unsigned char * code,sal_Int16 nFunctionIndex,sal_Int16 nVtableOffset,bool simple_ret_type)546cdf0e10cSrcweir unsigned char* codeSnippet( unsigned char * code, sal_Int16 nFunctionIndex, sal_Int16 nVtableOffset, bool simple_ret_type )
547cdf0e10cSrcweir {
548cdf0e10cSrcweir sal_uInt32 nOffsetAndIndex = ( ( nVtableOffset ) << 16 ) | ( nFunctionIndex );
549cdf0e10cSrcweir
550cdf0e10cSrcweir if (! simple_ret_type)
551cdf0e10cSrcweir nOffsetAndIndex |= 0x8000;
552cdf0e10cSrcweir
553cdf0e10cSrcweir OSL_ASSERT( sizeof (long) == 4 );
554cdf0e10cSrcweir
555cdf0e10cSrcweir /* generate this code */
556cdf0e10cSrcweir // lr %r0,%r13
557cdf0e10cSrcweir // bras %r13,0x6
558cdf0e10cSrcweir // .long privateSnippetExecutor
559cdf0e10cSrcweir // .long nOffsetAndIndex
560cdf0e10cSrcweir // stm %r2,%r6,8(%r15)
561cdf0e10cSrcweir // std %f0,64(%r15)
562cdf0e10cSrcweir // std %f2,72(%r15)
563cdf0e10cSrcweir
564cdf0e10cSrcweir // l %r2,4(%r13)
565cdf0e10cSrcweir // la %r3,8(%r15)
566cdf0e10cSrcweir // la %r4,64(%r15)
567cdf0e10cSrcweir // la %r5,96(%r15)
568cdf0e10cSrcweir // l %r1,0(%r13)
569cdf0e10cSrcweir // lr %r13,%r0
570cdf0e10cSrcweir // br %r1
571cdf0e10cSrcweir
572cdf0e10cSrcweir unsigned char * p = code;
573cdf0e10cSrcweir *reinterpret_cast< sal_Int16 * >(p) = 0x180d;
574cdf0e10cSrcweir p += sizeof(sal_Int16);
575cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0xa7d50006;
576cdf0e10cSrcweir p += sizeof(sal_Int32);
577cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) =
578cdf0e10cSrcweir reinterpret_cast< sal_Int32 >(privateSnippetExecutor);
579cdf0e10cSrcweir p += sizeof(sal_Int32);
580cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = nOffsetAndIndex;
581cdf0e10cSrcweir p += sizeof(sal_Int32);
582cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x9026f008;
583cdf0e10cSrcweir p += sizeof(sal_Int32);
584cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x6000f040;
585cdf0e10cSrcweir p += sizeof(sal_Int32);
586cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x6020f048;
587cdf0e10cSrcweir p += sizeof(sal_Int32);
588cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x5820d004;
589cdf0e10cSrcweir p += sizeof(sal_Int32);
590cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x4130f008;
591cdf0e10cSrcweir p += sizeof(sal_Int32);
592cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x4140f040;
593cdf0e10cSrcweir p += sizeof(sal_Int32);
594cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x4150f060;
595cdf0e10cSrcweir p += sizeof(sal_Int32);
596cdf0e10cSrcweir *reinterpret_cast< sal_Int32 * >(p) = 0x5810d000;
597cdf0e10cSrcweir p += sizeof(sal_Int32);
598cdf0e10cSrcweir *reinterpret_cast< sal_Int16 * >(p) = 0x18d0;
599cdf0e10cSrcweir p += sizeof(sal_Int16);
600cdf0e10cSrcweir *reinterpret_cast< sal_Int16 * >(p) = 0x07f1;
601cdf0e10cSrcweir p += sizeof(sal_Int16);
602cdf0e10cSrcweir
603cdf0e10cSrcweir return (code + codeSnippetSize);
604cdf0e10cSrcweir }
605cdf0e10cSrcweir }
606cdf0e10cSrcweir
flushCode(unsigned char const *,unsigned char const *)607cdf0e10cSrcweir void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const *, unsigned char const *)
608cdf0e10cSrcweir {
609cdf0e10cSrcweir }
610cdf0e10cSrcweir
611cdf0e10cSrcweir struct bridges::cpp_uno::shared::VtableFactory::Slot { void * fn; };
612cdf0e10cSrcweir
613cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
mapBlockToVtable(void * block)614cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
615cdf0e10cSrcweir {
616cdf0e10cSrcweir return static_cast< Slot * >(block) + 2;
617cdf0e10cSrcweir }
618cdf0e10cSrcweir
getBlockSize(sal_Int32 slotCount)619cdf0e10cSrcweir sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
620cdf0e10cSrcweir sal_Int32 slotCount)
621cdf0e10cSrcweir {
622cdf0e10cSrcweir return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
623cdf0e10cSrcweir }
624cdf0e10cSrcweir
625cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot *
initializeBlock(void * block,sal_Int32 slotCount)626cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::initializeBlock(
627cdf0e10cSrcweir void * block, sal_Int32 slotCount)
628cdf0e10cSrcweir {
629cdf0e10cSrcweir Slot * slots = mapBlockToVtable(block);
630cdf0e10cSrcweir slots[-2].fn = 0;
631cdf0e10cSrcweir slots[-1].fn = 0;
632cdf0e10cSrcweir return slots + slotCount;
633cdf0e10cSrcweir }
634cdf0e10cSrcweir
addLocalFunctions(Slot ** slots,unsigned char * code,sal_PtrDiff writetoexecdiff,typelib_InterfaceTypeDescription const * type,sal_Int32 functionOffset,sal_Int32 functionCount,sal_Int32 vtableOffset)635cdf0e10cSrcweir unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
636cdf0e10cSrcweir Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
637cdf0e10cSrcweir typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
638cdf0e10cSrcweir sal_Int32 functionCount, sal_Int32 vtableOffset)
639cdf0e10cSrcweir {
640cdf0e10cSrcweir (*slots) -= functionCount;
641cdf0e10cSrcweir Slot * s = *slots;
642cdf0e10cSrcweir #ifdef CMC_DEBUG
643cdf0e10cSrcweir fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
644cdf0e10cSrcweir fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
645cdf0e10cSrcweir #endif
646cdf0e10cSrcweir
647cdf0e10cSrcweir for (sal_Int32 i = 0; i < type->nMembers; ++i) {
648cdf0e10cSrcweir typelib_TypeDescription * member = 0;
649cdf0e10cSrcweir TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
650cdf0e10cSrcweir OSL_ASSERT(member != 0);
651cdf0e10cSrcweir switch (member->eTypeClass) {
652cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
653cdf0e10cSrcweir // Getter:
654cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
655cdf0e10cSrcweir code = codeSnippet(
656cdf0e10cSrcweir code, functionOffset++, vtableOffset,
657cdf0e10cSrcweir bridges::cpp_uno::shared::isSimpleType(
658cdf0e10cSrcweir reinterpret_cast<
659cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >(
660cdf0e10cSrcweir member)->pAttributeTypeRef));
661cdf0e10cSrcweir
662cdf0e10cSrcweir // Setter:
663cdf0e10cSrcweir if (!reinterpret_cast<
664cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >(
665cdf0e10cSrcweir member)->bReadOnly)
666cdf0e10cSrcweir {
667cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
668cdf0e10cSrcweir code = codeSnippet(code, functionOffset++, vtableOffset, true);
669cdf0e10cSrcweir }
670cdf0e10cSrcweir break;
671cdf0e10cSrcweir
672cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
673cdf0e10cSrcweir (s++)->fn = code + writetoexecdiff;
674cdf0e10cSrcweir code = codeSnippet(
675cdf0e10cSrcweir code, functionOffset++, vtableOffset,
676cdf0e10cSrcweir bridges::cpp_uno::shared::isSimpleType(
677cdf0e10cSrcweir reinterpret_cast<
678cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription * >(
679cdf0e10cSrcweir member)->pReturnTypeRef));
680cdf0e10cSrcweir break;
681cdf0e10cSrcweir
682cdf0e10cSrcweir default:
683cdf0e10cSrcweir OSL_ASSERT(false);
684cdf0e10cSrcweir break;
685cdf0e10cSrcweir }
686cdf0e10cSrcweir TYPELIB_DANGER_RELEASE(member);
687cdf0e10cSrcweir }
688cdf0e10cSrcweir return code;
689cdf0e10cSrcweir }
690cdf0e10cSrcweir
691cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
692