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 // 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
39cdf0e10cSrcweir extern "C" { extern void (*privateSnippetExecutor)(); }
40cdf0e10cSrcweir
41cdf0e10cSrcweir using namespace ::com::sun::star::uno;
42cdf0e10cSrcweir
43cdf0e10cSrcweir namespace
44cdf0e10cSrcweir {
45cdf0e10cSrcweir //==================================================================================================
cpp2uno_call(bridges::cpp_uno::shared::CppInterfaceProxy * pThis,const typelib_TypeDescription * pMemberTypeDescr,typelib_TypeDescriptionReference * pReturnTypeRef,sal_Int32 nParams,typelib_MethodParameter * pParams,long r8,void ** gpreg,void ** fpreg,void ** ovrflw,sal_Int64 * pRegisterReturn)46cdf0e10cSrcweir static typelib_TypeClass cpp2uno_call(
47cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
48cdf0e10cSrcweir const typelib_TypeDescription * pMemberTypeDescr,
49cdf0e10cSrcweir typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
50cdf0e10cSrcweir sal_Int32 nParams, typelib_MethodParameter * pParams, long r8,
51cdf0e10cSrcweir void ** gpreg, void ** fpreg, void ** ovrflw,
52cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
53cdf0e10cSrcweir {
54cdf0e10cSrcweir #ifdef CMC_DEBUG
55cdf0e10cSrcweir fprintf(stderr, "as far as cpp2uno_call\n");
56cdf0e10cSrcweir #endif
57cdf0e10cSrcweir
58cdf0e10cSrcweir int ng = 0; //number of gpr registers used
59cdf0e10cSrcweir int nf = 0; //number of fpr regsiters used
60cdf0e10cSrcweir
61cdf0e10cSrcweir // gpreg: [ret *], this, [gpr params]
62cdf0e10cSrcweir // fpreg: [fpr params]
63cdf0e10cSrcweir // ovrflw: [gpr or fpr params (properly aligned)]
64cdf0e10cSrcweir
65cdf0e10cSrcweir // return
66cdf0e10cSrcweir typelib_TypeDescription * pReturnTypeDescr = 0;
67cdf0e10cSrcweir if (pReturnTypeRef)
68cdf0e10cSrcweir TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
69cdf0e10cSrcweir
70cdf0e10cSrcweir void * pUnoReturn = 0;
71cdf0e10cSrcweir void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
72cdf0e10cSrcweir
73cdf0e10cSrcweir if (pReturnTypeDescr)
74cdf0e10cSrcweir {
75cdf0e10cSrcweir if ( ia64::return_in_hidden_param( pReturnTypeRef ) ) // complex return via ptr passed as hidden parameter reg (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 else if ( ia64::return_via_r8_buffer( pReturnTypeRef ) ) // complex return via ptr passed in r8
86cdf0e10cSrcweir {
87cdf0e10cSrcweir pCppReturn = (void *)r8;
88cdf0e10cSrcweir
89cdf0e10cSrcweir pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
90cdf0e10cSrcweir ? alloca( pReturnTypeDescr->nSize )
91cdf0e10cSrcweir : pCppReturn); // direct way
92cdf0e10cSrcweir }
93cdf0e10cSrcweir
94cdf0e10cSrcweir else
95cdf0e10cSrcweir pUnoReturn = pRegisterReturn; // direct way for simple types
96cdf0e10cSrcweir }
97cdf0e10cSrcweir // pop this
98cdf0e10cSrcweir gpreg++;
99cdf0e10cSrcweir ng++;
100cdf0e10cSrcweir
101cdf0e10cSrcweir // stack space
102cdf0e10cSrcweir OSL_ENSURE( sizeof(void *) == sizeof(sal_Int64), "### unexpected size!" );
103cdf0e10cSrcweir // parameters
104cdf0e10cSrcweir void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
105cdf0e10cSrcweir void ** pCppArgs = pUnoArgs + nParams;
106cdf0e10cSrcweir // indizes of values this have to be converted (interface conversion cpp<=>uno)
107cdf0e10cSrcweir sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams));
108cdf0e10cSrcweir // type descriptions for reconversions
109cdf0e10cSrcweir typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
110cdf0e10cSrcweir
111cdf0e10cSrcweir sal_Int32 nTempIndizes = 0;
112cdf0e10cSrcweir bool bOverFlowUsed = false;
113cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
114cdf0e10cSrcweir {
115cdf0e10cSrcweir const typelib_MethodParameter & rParam = pParams[nPos];
116cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = 0;
117cdf0e10cSrcweir TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
118cdf0e10cSrcweir
119cdf0e10cSrcweir #ifdef CMC_DEBUG
120cdf0e10cSrcweir fprintf(stderr, "arg %d of %d\n", nPos, nParams);
121cdf0e10cSrcweir #endif
122cdf0e10cSrcweir
123cdf0e10cSrcweir //I think it is impossible to get UNO to pass structs as parameters by copy
124cdf0e10cSrcweir if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
125cdf0e10cSrcweir {
126cdf0e10cSrcweir #ifdef CMC_DEBUG
127cdf0e10cSrcweir fprintf(stderr, "simple\n");
128cdf0e10cSrcweir #endif
129cdf0e10cSrcweir
130cdf0e10cSrcweir switch (pParamTypeDescr->eTypeClass)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
133cdf0e10cSrcweir if (nf < ia64::MAX_SSE_REGS && ng < ia64::MAX_GPR_REGS)
134cdf0e10cSrcweir {
135cdf0e10cSrcweir float tmp = (float) (*((double *)fpreg));
136cdf0e10cSrcweir (*((float *) fpreg)) = tmp;
137cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
138cdf0e10cSrcweir nf++;
139cdf0e10cSrcweir gpreg++;
140cdf0e10cSrcweir ng++;
141cdf0e10cSrcweir }
142cdf0e10cSrcweir else
143cdf0e10cSrcweir {
144cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
145cdf0e10cSrcweir bOverFlowUsed = true;
146cdf0e10cSrcweir }
147cdf0e10cSrcweir if (bOverFlowUsed) ovrflw++;
148cdf0e10cSrcweir break;
149cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
150cdf0e10cSrcweir if (nf < ia64::MAX_SSE_REGS && ng < ia64::MAX_GPR_REGS)
151cdf0e10cSrcweir {
152cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
153cdf0e10cSrcweir nf++;
154cdf0e10cSrcweir gpreg++;
155cdf0e10cSrcweir ng++;
156cdf0e10cSrcweir }
157cdf0e10cSrcweir else
158cdf0e10cSrcweir {
159cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
160cdf0e10cSrcweir bOverFlowUsed = true;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir if (bOverFlowUsed) ovrflw++;
163cdf0e10cSrcweir break;
164cdf0e10cSrcweir case typelib_TypeClass_BYTE:
165cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
166cdf0e10cSrcweir case typelib_TypeClass_CHAR:
167cdf0e10cSrcweir case typelib_TypeClass_SHORT:
168cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
169cdf0e10cSrcweir case typelib_TypeClass_ENUM:
170cdf0e10cSrcweir case typelib_TypeClass_LONG:
171cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
172cdf0e10cSrcweir default:
173cdf0e10cSrcweir if (ng < ia64::MAX_GPR_REGS)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = gpreg++;
176cdf0e10cSrcweir ng++;
177cdf0e10cSrcweir }
178cdf0e10cSrcweir else
179cdf0e10cSrcweir {
180cdf0e10cSrcweir pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
181cdf0e10cSrcweir bOverFlowUsed = true;
182cdf0e10cSrcweir }
183cdf0e10cSrcweir if (bOverFlowUsed) ovrflw++;
184cdf0e10cSrcweir break;
185cdf0e10cSrcweir }
186cdf0e10cSrcweir
187cdf0e10cSrcweir // no longer needed
188cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
189cdf0e10cSrcweir }
190cdf0e10cSrcweir else // ptr to complex value | ref
191cdf0e10cSrcweir {
192cdf0e10cSrcweir #ifdef CMC_DEBUG
193cdf0e10cSrcweir fprintf(stderr, "complex, ng is %d\n", ng);
194cdf0e10cSrcweir #endif
195cdf0e10cSrcweir void *pCppStack; //temporary stack pointer
196cdf0e10cSrcweir
197cdf0e10cSrcweir if (ng < ia64::MAX_GPR_REGS)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir pCppArgs[nPos] = pCppStack = *gpreg++;
200cdf0e10cSrcweir ng++;
201cdf0e10cSrcweir }
202cdf0e10cSrcweir else
203cdf0e10cSrcweir {
204cdf0e10cSrcweir pCppArgs[nPos] = pCppStack = *ovrflw;
205cdf0e10cSrcweir bOverFlowUsed = true;
206cdf0e10cSrcweir }
207cdf0e10cSrcweir if (bOverFlowUsed) ovrflw++;
208cdf0e10cSrcweir
209cdf0e10cSrcweir if (! rParam.bIn) // is pure out
210cdf0e10cSrcweir {
211cdf0e10cSrcweir // uno out is unconstructed mem!
212cdf0e10cSrcweir pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
213cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos;
214cdf0e10cSrcweir // will be released at reconversion
215cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir // is in/inout
218cdf0e10cSrcweir else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
219cdf0e10cSrcweir {
220cdf0e10cSrcweir uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
221cdf0e10cSrcweir pCppStack, pParamTypeDescr,
222cdf0e10cSrcweir pThis->getBridge()->getCpp2Uno() );
223cdf0e10cSrcweir pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
224cdf0e10cSrcweir // will be released at reconversion
225cdf0e10cSrcweir ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
226cdf0e10cSrcweir }
227cdf0e10cSrcweir else // direct way
228cdf0e10cSrcweir {
229cdf0e10cSrcweir pUnoArgs[nPos] = pCppStack;
230cdf0e10cSrcweir // no longer needed
231cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
232cdf0e10cSrcweir }
233cdf0e10cSrcweir }
234cdf0e10cSrcweir }
235cdf0e10cSrcweir
236cdf0e10cSrcweir #ifdef CMC_DEBUG
237cdf0e10cSrcweir fprintf(stderr, "end of params\n");
238cdf0e10cSrcweir #endif
239cdf0e10cSrcweir
240cdf0e10cSrcweir // ExceptionHolder
241cdf0e10cSrcweir uno_Any aUnoExc; // Any will be constructed by callee
242cdf0e10cSrcweir uno_Any * pUnoExc = &aUnoExc;
243cdf0e10cSrcweir
244cdf0e10cSrcweir // invoke uno dispatch call
245cdf0e10cSrcweir (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
246cdf0e10cSrcweir
247cdf0e10cSrcweir // in case an exception occured...
248cdf0e10cSrcweir if (pUnoExc)
249cdf0e10cSrcweir {
250cdf0e10cSrcweir // destruct temporary in/inout params
251cdf0e10cSrcweir for ( ; nTempIndizes--; )
252cdf0e10cSrcweir {
253cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
254cdf0e10cSrcweir
255cdf0e10cSrcweir if (pParams[nIndex].bIn) // is in/inout => was constructed
256cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 );
257cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir if (pReturnTypeDescr)
260cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
261cdf0e10cSrcweir
262cdf0e10cSrcweir CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() );
263cdf0e10cSrcweir // has to destruct the any
264cdf0e10cSrcweir // is here for dummy
265cdf0e10cSrcweir return typelib_TypeClass_VOID;
266cdf0e10cSrcweir }
267cdf0e10cSrcweir else // else no exception occured...
268cdf0e10cSrcweir {
269cdf0e10cSrcweir // temporary params
270cdf0e10cSrcweir for ( ; nTempIndizes--; )
271cdf0e10cSrcweir {
272cdf0e10cSrcweir sal_Int32 nIndex = pTempIndizes[nTempIndizes];
273cdf0e10cSrcweir typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
274cdf0e10cSrcweir
275cdf0e10cSrcweir if (pParams[nIndex].bOut) // inout/out
276cdf0e10cSrcweir {
277cdf0e10cSrcweir // convert and assign
278cdf0e10cSrcweir uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
279cdf0e10cSrcweir uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
280cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
281cdf0e10cSrcweir }
282cdf0e10cSrcweir // destroy temp uno param
283cdf0e10cSrcweir uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
284cdf0e10cSrcweir
285cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pParamTypeDescr );
286cdf0e10cSrcweir }
287cdf0e10cSrcweir // return
288cdf0e10cSrcweir if (pCppReturn) // has complex return
289cdf0e10cSrcweir {
290cdf0e10cSrcweir if (pUnoReturn != pCppReturn) // needs reconversion
291cdf0e10cSrcweir {
292cdf0e10cSrcweir uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
293cdf0e10cSrcweir pThis->getBridge()->getUno2Cpp() );
294cdf0e10cSrcweir // destroy temp uno return
295cdf0e10cSrcweir uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
296cdf0e10cSrcweir }
297cdf0e10cSrcweir // complex return ptr is set to return reg
298cdf0e10cSrcweir *(void **)pRegisterReturn = pCppReturn;
299cdf0e10cSrcweir }
300cdf0e10cSrcweir if (pReturnTypeDescr)
301cdf0e10cSrcweir {
302cdf0e10cSrcweir typelib_TypeClass eRet = ia64::return_via_r8_buffer(pReturnTypeRef) ? typelib_TypeClass_VOID : (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
303cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
304cdf0e10cSrcweir return eRet;
305cdf0e10cSrcweir }
306cdf0e10cSrcweir else
307cdf0e10cSrcweir return typelib_TypeClass_VOID;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir }
310cdf0e10cSrcweir
311cdf0e10cSrcweir
312cdf0e10cSrcweir //==================================================================================================
cpp_mediate(sal_uInt64 nOffsetAndIndex,void ** gpreg,void ** fpreg,long sp,long r8,sal_Int64 * pRegisterReturn)313cdf0e10cSrcweir static typelib_TypeClass cpp_mediate(
314cdf0e10cSrcweir sal_uInt64 nOffsetAndIndex,
315cdf0e10cSrcweir void ** gpreg, void ** fpreg, long sp, long r8,
316cdf0e10cSrcweir sal_Int64 * pRegisterReturn /* space for register return */ )
317cdf0e10cSrcweir {
318cdf0e10cSrcweir OSL_ENSURE( sizeof(sal_Int64)==sizeof(void *), "### unexpected!" );
319cdf0e10cSrcweir
320cdf0e10cSrcweir sal_Int32 nVtableOffset = (nOffsetAndIndex >> 32);
321cdf0e10cSrcweir sal_Int32 nFunctionIndex = (nOffsetAndIndex & 0xFFFFFFFF);
322cdf0e10cSrcweir
323cdf0e10cSrcweir void ** ovrflw = (void**)(sp);
324cdf0e10cSrcweir
325cdf0e10cSrcweir // gpreg: [ret *], this, [other gpr params]
326cdf0e10cSrcweir // fpreg: [fpr params]
327cdf0e10cSrcweir // ovrflw: [gpr or fpr params (properly aligned)]
328cdf0e10cSrcweir
329cdf0e10cSrcweir void * pThis;
330cdf0e10cSrcweir if (nFunctionIndex & 0x80000000 )
331cdf0e10cSrcweir {
332cdf0e10cSrcweir nFunctionIndex &= 0x7fffffff;
333cdf0e10cSrcweir pThis = gpreg[1];
334cdf0e10cSrcweir #ifdef CMC_DEBUG
335cdf0e10cSrcweir fprintf(stderr, "pThis is gpreg[1]\n");
336cdf0e10cSrcweir #endif
337cdf0e10cSrcweir }
338cdf0e10cSrcweir else
339cdf0e10cSrcweir {
340cdf0e10cSrcweir pThis = gpreg[0];
341cdf0e10cSrcweir #ifdef CMC_DEBUG
342cdf0e10cSrcweir fprintf(stderr, "pThis is gpreg[0]\n");
343cdf0e10cSrcweir #endif
344cdf0e10cSrcweir }
345cdf0e10cSrcweir
346cdf0e10cSrcweir #ifdef CMC_DEBUG
347cdf0e10cSrcweir fprintf(stderr, "pThis is %p\n", pThis);
348cdf0e10cSrcweir #endif
349cdf0e10cSrcweir
350cdf0e10cSrcweir pThis = static_cast< char * >(pThis) - nVtableOffset;
351cdf0e10cSrcweir
352cdf0e10cSrcweir #ifdef CMC_DEBUG
353cdf0e10cSrcweir fprintf(stderr, "pThis is now %p\n", pThis);
354cdf0e10cSrcweir #endif
355cdf0e10cSrcweir
356cdf0e10cSrcweir bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
357cdf0e10cSrcweir = bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
358cdf0e10cSrcweir pThis);
359cdf0e10cSrcweir
360cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
361cdf0e10cSrcweir
362cdf0e10cSrcweir #ifdef CMC_DEBUG
363cdf0e10cSrcweir fprintf(stderr, "indexes are %d %d\n", nFunctionIndex, pTypeDescr->nMapFunctionIndexToMemberIndex);
364cdf0e10cSrcweir #endif
365cdf0e10cSrcweir
366cdf0e10cSrcweir OSL_ENSURE( nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" );
367cdf0e10cSrcweir if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
368cdf0e10cSrcweir {
369cdf0e10cSrcweir throw RuntimeException(
370cdf0e10cSrcweir rtl::OUString::createFromAscii("illegal vtable index!"),
371cdf0e10cSrcweir (XInterface *)pThis );
372cdf0e10cSrcweir }
373cdf0e10cSrcweir
374cdf0e10cSrcweir // determine called method
375cdf0e10cSrcweir sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
376cdf0e10cSrcweir OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" );
377cdf0e10cSrcweir
378cdf0e10cSrcweir #ifdef CMC_DEBUG
379cdf0e10cSrcweir fprintf(stderr, "members are %d %d\n", nMemberPos, pTypeDescr->nAllMembers);
380cdf0e10cSrcweir #endif
381cdf0e10cSrcweir
382cdf0e10cSrcweir TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
383cdf0e10cSrcweir
384cdf0e10cSrcweir typelib_TypeClass eRet;
385cdf0e10cSrcweir switch (aMemberDescr.get()->eTypeClass)
386cdf0e10cSrcweir {
387cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
388cdf0e10cSrcweir {
389cdf0e10cSrcweir if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
390cdf0e10cSrcweir {
391cdf0e10cSrcweir // is GET method
392cdf0e10cSrcweir eRet = cpp2uno_call(
393cdf0e10cSrcweir pCppI, aMemberDescr.get(),
394cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
395cdf0e10cSrcweir 0, 0, // no params
396cdf0e10cSrcweir r8, gpreg, fpreg, ovrflw, pRegisterReturn );
397cdf0e10cSrcweir }
398cdf0e10cSrcweir else
399cdf0e10cSrcweir {
400cdf0e10cSrcweir // is SET method
401cdf0e10cSrcweir typelib_MethodParameter aParam;
402cdf0e10cSrcweir aParam.pTypeRef =
403cdf0e10cSrcweir ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
404cdf0e10cSrcweir aParam.bIn = sal_True;
405cdf0e10cSrcweir aParam.bOut = sal_False;
406cdf0e10cSrcweir
407cdf0e10cSrcweir eRet = cpp2uno_call(
408cdf0e10cSrcweir pCppI, aMemberDescr.get(),
409cdf0e10cSrcweir 0, // indicates void return
410cdf0e10cSrcweir 1, &aParam,
411cdf0e10cSrcweir r8, gpreg, fpreg, ovrflw, pRegisterReturn );
412cdf0e10cSrcweir }
413cdf0e10cSrcweir break;
414cdf0e10cSrcweir }
415cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
416cdf0e10cSrcweir {
417cdf0e10cSrcweir // is METHOD
418cdf0e10cSrcweir switch (nFunctionIndex)
419cdf0e10cSrcweir {
420cdf0e10cSrcweir case 1: // acquire()
421cdf0e10cSrcweir pCppI->acquireProxy(); // non virtual call!
422cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
423cdf0e10cSrcweir break;
424cdf0e10cSrcweir case 2: // release()
425cdf0e10cSrcweir pCppI->releaseProxy(); // non virtual call!
426cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
427cdf0e10cSrcweir break;
428cdf0e10cSrcweir case 0: // queryInterface() opt
429cdf0e10cSrcweir {
430cdf0e10cSrcweir typelib_TypeDescription * pTD = 0;
431cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
432cdf0e10cSrcweir if (pTD)
433cdf0e10cSrcweir {
434cdf0e10cSrcweir XInterface * pInterface = 0;
435cdf0e10cSrcweir (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
436cdf0e10cSrcweir pCppI->getBridge()->getCppEnv(),
437cdf0e10cSrcweir (void **)&pInterface, pCppI->getOid().pData,
438cdf0e10cSrcweir (typelib_InterfaceTypeDescription *)pTD );
439cdf0e10cSrcweir
440cdf0e10cSrcweir if (pInterface)
441cdf0e10cSrcweir {
442cdf0e10cSrcweir ::uno_any_construct(
443cdf0e10cSrcweir reinterpret_cast< uno_Any * >( gpreg[0] ),
444cdf0e10cSrcweir &pInterface, pTD, cpp_acquire );
445cdf0e10cSrcweir pInterface->release();
446cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
447cdf0e10cSrcweir *(void **)pRegisterReturn = gpreg[0];
448cdf0e10cSrcweir eRet = typelib_TypeClass_ANY;
449cdf0e10cSrcweir break;
450cdf0e10cSrcweir }
451cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD );
452cdf0e10cSrcweir }
453cdf0e10cSrcweir } // else perform queryInterface()
454cdf0e10cSrcweir default:
455cdf0e10cSrcweir eRet = cpp2uno_call(
456cdf0e10cSrcweir pCppI, aMemberDescr.get(),
457cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
458cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
459cdf0e10cSrcweir ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
460cdf0e10cSrcweir r8, gpreg, fpreg, ovrflw, pRegisterReturn );
461cdf0e10cSrcweir }
462cdf0e10cSrcweir break;
463cdf0e10cSrcweir }
464cdf0e10cSrcweir default:
465cdf0e10cSrcweir {
466cdf0e10cSrcweir #ifdef CMC_DEBUG
467cdf0e10cSrcweir fprintf(stderr, "screwed\n");
468cdf0e10cSrcweir #endif
469cdf0e10cSrcweir
470cdf0e10cSrcweir throw RuntimeException(
471cdf0e10cSrcweir rtl::OUString::createFromAscii("no member description found!"),
472cdf0e10cSrcweir (XInterface *)pThis );
473cdf0e10cSrcweir // is here for dummy
474cdf0e10cSrcweir eRet = typelib_TypeClass_VOID;
475cdf0e10cSrcweir }
476cdf0e10cSrcweir }
477cdf0e10cSrcweir
478cdf0e10cSrcweir #ifdef CMC_DEBUG
479cdf0e10cSrcweir fprintf(stderr, "end of cpp_mediate\n");
480cdf0e10cSrcweir #endif
481cdf0e10cSrcweir return eRet;
482cdf0e10cSrcweir }
483cdf0e10cSrcweir }
484cdf0e10cSrcweir
cpp_vtable_call(long in0,long in1,long in2,long in3,long in4,long in5,long in6,long in7,long firstonstack)485cdf0e10cSrcweir extern "C" ia64::RegReturn cpp_vtable_call(
486cdf0e10cSrcweir long in0, long in1, long in2, long in3, long in4, long in5, long in6, long in7,
487cdf0e10cSrcweir long firstonstack
488cdf0e10cSrcweir )
489cdf0e10cSrcweir {
490cdf0e10cSrcweir register long r15 asm("r15");
491cdf0e10cSrcweir long r8 = r15;
492cdf0e10cSrcweir
493cdf0e10cSrcweir register long r14 asm("r14");
494cdf0e10cSrcweir long nOffsetAndIndex = r14;
495cdf0e10cSrcweir
496cdf0e10cSrcweir long sp = (long)&firstonstack;
497cdf0e10cSrcweir
498cdf0e10cSrcweir sal_uInt64 gpreg[ia64::MAX_GPR_REGS];
499cdf0e10cSrcweir gpreg[0] = in0;
500cdf0e10cSrcweir gpreg[1] = in1;
501cdf0e10cSrcweir gpreg[2] = in2;
502cdf0e10cSrcweir gpreg[3] = in3;
503cdf0e10cSrcweir gpreg[4] = in4;
504cdf0e10cSrcweir gpreg[5] = in5;
505cdf0e10cSrcweir gpreg[6] = in6;
506cdf0e10cSrcweir gpreg[7] = in7;
507cdf0e10cSrcweir
508cdf0e10cSrcweir double fpreg[ia64::MAX_SSE_REGS];
509cdf0e10cSrcweir register double f8 asm("f8"); fpreg[0] = f8;
510cdf0e10cSrcweir register double f9 asm("f9"); fpreg[1] = f9;
511cdf0e10cSrcweir register double f10 asm("f10"); fpreg[2] = f10;
512cdf0e10cSrcweir register double f11 asm("f11"); fpreg[3] = f11;
513cdf0e10cSrcweir register double f12 asm("f12"); fpreg[4] = f12;
514cdf0e10cSrcweir register double f13 asm("f13"); fpreg[5] = f13;
515cdf0e10cSrcweir register double f14 asm("f14"); fpreg[6] = f14;
516cdf0e10cSrcweir register double f15 asm("f15"); fpreg[7] = f15;
517cdf0e10cSrcweir
518cdf0e10cSrcweir #ifdef CMC_DEBUG
519cdf0e10cSrcweir fprintf(stderr, "cpp_vtable_call called with %lx\n", nOffsetAndIndex);
520cdf0e10cSrcweir fprintf(stderr, "adump is %lx %lx %lx %lx %lx %lx %lx %lx\n", in0, in1, in2, in3, in4, in5, in6, in7);
521cdf0e10cSrcweir fprintf(stderr, "bdump is %f %f %f %f %f %f %f %f\n", f8, f9, f10, f11, f12, f13, f14, f15);
522cdf0e10cSrcweir #endif
523cdf0e10cSrcweir
524cdf0e10cSrcweir volatile long nRegReturn[4] = { 0 };
525cdf0e10cSrcweir
526cdf0e10cSrcweir typelib_TypeClass aType =
527cdf0e10cSrcweir cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, sp, r8, (sal_Int64*)&nRegReturn[0]);
528cdf0e10cSrcweir
529cdf0e10cSrcweir ia64::RegReturn ret;
530cdf0e10cSrcweir switch( aType )
531cdf0e10cSrcweir {
532cdf0e10cSrcweir case typelib_TypeClass_VOID:
533cdf0e10cSrcweir break;
534cdf0e10cSrcweir case typelib_TypeClass_BOOLEAN:
535cdf0e10cSrcweir case typelib_TypeClass_BYTE:
536cdf0e10cSrcweir case typelib_TypeClass_CHAR:
537cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_SHORT:
538cdf0e10cSrcweir case typelib_TypeClass_SHORT:
539cdf0e10cSrcweir case typelib_TypeClass_ENUM:
540cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_LONG:
541cdf0e10cSrcweir case typelib_TypeClass_LONG:
542cdf0e10cSrcweir case typelib_TypeClass_UNSIGNED_HYPER:
543cdf0e10cSrcweir case typelib_TypeClass_HYPER:
544cdf0e10cSrcweir ret.r8 = nRegReturn[0];
545cdf0e10cSrcweir break;
546cdf0e10cSrcweir case typelib_TypeClass_FLOAT:
547cdf0e10cSrcweir asm volatile("ldfs f8=%0" : : "m"((*((float*)&nRegReturn))) : "f8");
548cdf0e10cSrcweir break;
549cdf0e10cSrcweir case typelib_TypeClass_DOUBLE:
550cdf0e10cSrcweir asm volatile("ldfd f8=%0" : : "m"((*((double*)&nRegReturn))) : "f8");
551cdf0e10cSrcweir break;
552cdf0e10cSrcweir case typelib_TypeClass_STRUCT:
553cdf0e10cSrcweir case typelib_TypeClass_EXCEPTION:
554cdf0e10cSrcweir {
555cdf0e10cSrcweir ret.r8 = nRegReturn[0];
556cdf0e10cSrcweir ret.r9 = nRegReturn[1];
557cdf0e10cSrcweir ret.r10 = nRegReturn[2];
558cdf0e10cSrcweir ret.r11 = nRegReturn[3];
559cdf0e10cSrcweir break;
560cdf0e10cSrcweir }
561cdf0e10cSrcweir default:
562cdf0e10cSrcweir break;
563cdf0e10cSrcweir }
564cdf0e10cSrcweir return ret;
565cdf0e10cSrcweir }
566cdf0e10cSrcweir
567cdf0e10cSrcweir namespace
568cdf0e10cSrcweir {
569cdf0e10cSrcweir const int codeSnippetSize = 40;
570cdf0e10cSrcweir
codeSnippet(unsigned char * code,sal_PtrDiff writetoexecdiff,sal_Int32 nFunctionIndex,sal_Int32 nVtableOffset,bool bHasHiddenParam)571cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot codeSnippet( unsigned char * code, sal_PtrDiff writetoexecdiff, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
572cdf0e10cSrcweir bool bHasHiddenParam )
573cdf0e10cSrcweir {
574cdf0e10cSrcweir #ifdef CMC_DEBUG
575cdf0e10cSrcweir fprintf(stderr, "size is %d\n", codeSnippetSize);
576cdf0e10cSrcweir fprintf(stderr,"in codeSnippet functionIndex is %x\n", nFunctionIndex);
577cdf0e10cSrcweir fprintf(stderr,"in codeSnippet vtableOffset is %x\n", nVtableOffset);
578cdf0e10cSrcweir #endif
579cdf0e10cSrcweir
580cdf0e10cSrcweir sal_uInt64 nOffsetAndIndex = ( ( (sal_uInt64) nVtableOffset ) << 32 ) | ( (sal_uInt64) nFunctionIndex );
581cdf0e10cSrcweir
582cdf0e10cSrcweir if ( bHasHiddenParam )
583cdf0e10cSrcweir nOffsetAndIndex |= 0x80000000;
584cdf0e10cSrcweir
585cdf0e10cSrcweir long *raw = (long *)code;
586cdf0e10cSrcweir
587cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot* destination = (bridges::cpp_uno::shared::VtableFactory::Slot*)cpp_vtable_call;
588cdf0e10cSrcweir
589cdf0e10cSrcweir raw[0] = (long)&privateSnippetExecutor;
590cdf0e10cSrcweir raw[1] = (long)&raw[2];
591cdf0e10cSrcweir raw[2] = nOffsetAndIndex;
592cdf0e10cSrcweir raw[3] = destination->gp_value;
593cdf0e10cSrcweir
594cdf0e10cSrcweir return *(bridges::cpp_uno::shared::VtableFactory::Slot*)(code+writetoexecdiff);
595cdf0e10cSrcweir }
596cdf0e10cSrcweir }
597cdf0e10cSrcweir
flushCode(unsigned char const *,unsigned char const *)598cdf0e10cSrcweir void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const *, unsigned char const *)
599cdf0e10cSrcweir {
600cdf0e10cSrcweir }
601cdf0e10cSrcweir
mapBlockToVtable(void * block)602cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot * bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
603cdf0e10cSrcweir {
604cdf0e10cSrcweir return static_cast< Slot * >(block) + 2;
605cdf0e10cSrcweir }
606cdf0e10cSrcweir
607cdf0e10cSrcweir
getBlockSize(sal_Int32 slotCount)608cdf0e10cSrcweir sal_Size bridges::cpp_uno::shared::VtableFactory::getBlockSize(
609cdf0e10cSrcweir sal_Int32 slotCount)
610cdf0e10cSrcweir {
611cdf0e10cSrcweir return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
612cdf0e10cSrcweir }
613cdf0e10cSrcweir
initializeBlock(void * block,sal_Int32 slotCount)614cdf0e10cSrcweir bridges::cpp_uno::shared::VtableFactory::Slot* bridges::cpp_uno::shared::VtableFactory::initializeBlock(void * block, sal_Int32 slotCount)
615cdf0e10cSrcweir {
616cdf0e10cSrcweir Slot * slots = mapBlockToVtable(block);
617cdf0e10cSrcweir Slot foo = {0,0};
618cdf0e10cSrcweir slots[-2] = foo;
619cdf0e10cSrcweir slots[-1] = foo;
620cdf0e10cSrcweir return slots + slotCount;
621cdf0e10cSrcweir }
622cdf0e10cSrcweir
addLocalFunctions(Slot ** in_slots,unsigned char * code,sal_PtrDiff writetoexecdiff,typelib_InterfaceTypeDescription const * type,sal_Int32 functionOffset,sal_Int32 functionCount,sal_Int32 vtableOffset)623cdf0e10cSrcweir unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
624cdf0e10cSrcweir Slot ** in_slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
625cdf0e10cSrcweir typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
626cdf0e10cSrcweir sal_Int32 functionCount, sal_Int32 vtableOffset)
627cdf0e10cSrcweir {
628cdf0e10cSrcweir (*in_slots) -= functionCount;
629cdf0e10cSrcweir Slot * slots = *in_slots;
630cdf0e10cSrcweir #ifdef CMC_DEBUG
631cdf0e10cSrcweir fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
632cdf0e10cSrcweir fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
633cdf0e10cSrcweir #endif
634cdf0e10cSrcweir
635cdf0e10cSrcweir for (sal_Int32 i = 0; i < type->nMembers; ++i) {
636cdf0e10cSrcweir typelib_TypeDescription * member = 0;
637cdf0e10cSrcweir TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
638cdf0e10cSrcweir OSL_ASSERT(member != 0);
639cdf0e10cSrcweir switch (member->eTypeClass) {
640cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_ATTRIBUTE:
641cdf0e10cSrcweir // Getter:
642cdf0e10cSrcweir *slots++ = codeSnippet(
643cdf0e10cSrcweir code, writetoexecdiff, functionOffset++, vtableOffset,
644cdf0e10cSrcweir ia64::return_in_hidden_param(
645cdf0e10cSrcweir reinterpret_cast<
646cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >(
647cdf0e10cSrcweir member)->pAttributeTypeRef));
648cdf0e10cSrcweir code += codeSnippetSize;
649cdf0e10cSrcweir
650cdf0e10cSrcweir
651cdf0e10cSrcweir // Setter:
652cdf0e10cSrcweir if (!reinterpret_cast<
653cdf0e10cSrcweir typelib_InterfaceAttributeTypeDescription * >(
654cdf0e10cSrcweir member)->bReadOnly)
655cdf0e10cSrcweir {
656cdf0e10cSrcweir *slots++ = codeSnippet(code, writetoexecdiff, functionOffset++, vtableOffset, false);
657cdf0e10cSrcweir code += codeSnippetSize;
658cdf0e10cSrcweir }
659cdf0e10cSrcweir break;
660cdf0e10cSrcweir
661cdf0e10cSrcweir case typelib_TypeClass_INTERFACE_METHOD:
662cdf0e10cSrcweir *slots++ = codeSnippet(
663cdf0e10cSrcweir code, writetoexecdiff, functionOffset++, vtableOffset,
664cdf0e10cSrcweir ia64::return_in_hidden_param(
665cdf0e10cSrcweir reinterpret_cast<
666cdf0e10cSrcweir typelib_InterfaceMethodTypeDescription * >(
667cdf0e10cSrcweir member)->pReturnTypeRef));
668cdf0e10cSrcweir code += codeSnippetSize;
669cdf0e10cSrcweir break;
670cdf0e10cSrcweir
671cdf0e10cSrcweir default:
672cdf0e10cSrcweir OSL_ASSERT(false);
673cdf0e10cSrcweir break;
674cdf0e10cSrcweir }
675cdf0e10cSrcweir TYPELIB_DANGER_RELEASE(member);
676cdf0e10cSrcweir }
677cdf0e10cSrcweir return code;
678cdf0e10cSrcweir }
679cdf0e10cSrcweir
680cdf0e10cSrcweir /* vi:set tabstop=4 shiftwidth=4 expandtab: */
681