1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_bridges.hxx"
26 
27 #include <typeinfo>
28 #include <exception>
29 #include <cstddef>
30 #include <cxxabi.h>
31 #include <stdlib.h>
32 #include <string.h>
33 
34 #include "rtl/alloc.h"
35 #include "rtl/ustrbuf.hxx"
36 
37 #include <com/sun/star/uno/genfunc.hxx>
38 #include "com/sun/star/uno/RuntimeException.hpp"
39 #include <uno/data.h>
40 
41 #include <bridges/cpp_uno/shared/bridge.hxx>
42 #include <bridges/cpp_uno/shared/types.hxx>
43 #include "bridges/cpp_uno/shared/unointerfaceproxy.hxx"
44 #include "bridges/cpp_uno/shared/vtables.hxx"
45 
46 #include "abi.hxx"
47 #include "share.hxx"
48 
49 using namespace ::rtl;
50 using namespace ::com::sun::star::uno;
51 #ifdef __GLIBCXX__
52 using CPPU_CURRENT_NAMESPACE::__cxa_get_globals;
53 #else
54 using __cxxabiv1::__cxa_get_globals;
55 #endif
56 
57 //==================================================================================================
58 static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
59                               void * pRegisterReturn, typelib_TypeDescriptionReference * pReturnTypeRef, bool bSimpleReturn,
60                               sal_uInt64 *pStack, sal_uInt32 nStack,
61                               sal_uInt64 *pGPR, sal_uInt32 nGPR,
62                               double *pFPR, sal_uInt32 nFPR) __attribute__((noinline));
63 
64 static void callVirtualMethod(void * pThis, sal_uInt32 nVtableIndex,
65                               void * pRegisterReturn, typelib_TypeDescriptionReference * pReturnTypeRef, bool bSimpleReturn,
66                               sal_uInt64 *pStack, sal_uInt32 nStack,
67                               sal_uInt64 *pGPR, sal_uInt32 nGPR,
68                               double *pFPR, sal_uInt32 nFPR)
69 {
70 #if OSL_DEBUG_LEVEL > 1
71     // Let's figure out what is really going on here
72     {
73         fprintf( stderr, "= callVirtualMethod() =\nGPR's (%d): ", nGPR );
74         for ( unsigned int i = 0; i < nGPR; ++i )
75             fprintf( stderr, "0x%lx, ", pGPR[i] );
76         fprintf( stderr, "\nFPR's (%d): ", nFPR );
77         for ( unsigned int i = 0; i < nFPR; ++i )
78             fprintf( stderr, "%f, ", pFPR[i] );
79         fprintf( stderr, "\nStack (%d): ", nStack );
80         for ( unsigned int i = 0; i < nStack; ++i )
81             fprintf( stderr, "0x%lx, ", pStack[i] );
82         fprintf( stderr, "\n" );
83     }
84 #endif
85 
86     // The call instruction within the asm section of callVirtualMethod may throw
87     // exceptions.  So that the compiler handles this correctly, it is important
88     // that (a) callVirtualMethod might call dummy_can_throw_anything (although this
89     // never happens at runtime), which in turn can throw exceptions, and (b)
90     // callVirtualMethod is not inlined at its call site (so that any exceptions are
91     // caught which are thrown from the instruction calling callVirtualMethod):
92     if ( !pThis )
93         CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything( "xxx" ); // address something
94 
95     // Should not happen, but...
96     if ( nFPR > x86_64::MAX_SSE_REGS )
97         nFPR = x86_64::MAX_SSE_REGS;
98     if ( nGPR > x86_64::MAX_GPR_REGS )
99         nGPR = x86_64::MAX_GPR_REGS;
100 
101     // Get pointer to method
102     sal_uInt64 pMethod = *((sal_uInt64 *)pThis);
103     pMethod += 8 * nVtableIndex;
104     pMethod = *((sal_uInt64 *)pMethod);
105 
106     // Load parameters to stack, if necessary
107     sal_uInt64* pCallStack = NULL;
108     if ( nStack )
109     {
110         // 16-bytes aligned
111         sal_uInt32 nStackBytes = ( ( nStack + 1 ) >> 1 ) * 16;
112         pCallStack = (sal_uInt64*) __builtin_alloca( nStackBytes );
113         memcpy( pCallStack, pStack, nStackBytes );
114     }
115 
116     // Return values
117     sal_uInt64 rax;
118     sal_uInt64 rdx;
119     double xmm0;
120     double xmm1;
121 
122     asm volatile (
123         // Fill the xmm registers
124         "movq %2, %%rax\n\t"
125 
126         "movsd   (%%rax), %%xmm0\n\t"
127         "movsd  8(%%rax), %%xmm1\n\t"
128         "movsd 16(%%rax), %%xmm2\n\t"
129         "movsd 24(%%rax), %%xmm3\n\t"
130         "movsd 32(%%rax), %%xmm4\n\t"
131         "movsd 40(%%rax), %%xmm5\n\t"
132         "movsd 48(%%rax), %%xmm6\n\t"
133         "movsd 56(%%rax), %%xmm7\n\t"
134 
135         // Fill the general purpose registers
136         "movq %1, %%rax\n\t"
137 
138         "movq    (%%rax), %%rdi\n\t"
139         "movq   8(%%rax), %%rsi\n\t"
140         "movq  16(%%rax), %%rdx\n\t"
141         "movq  24(%%rax), %%rcx\n\t"
142         "movq  32(%%rax), %%r8\n\t"
143         "movq  40(%%rax), %%r9\n\t"
144 
145         // Perform the call
146         "movq %0, %%r11\n\t"
147         "movq %3, %%rax\n\t"
148         "call *%%r11\n\t"
149 
150         // Fill the return values
151         "movq   %%rax, %4\n\t"
152         "movq   %%rdx, %5\n\t"
153         "movsd %%xmm0, %6\n\t"
154         "movsd %%xmm1, %7\n\t"
155         :
156         : "m" ( pMethod ), "m" ( pGPR ), "m" ( pFPR ), "m" ( nFPR ),
157           "m" ( rax ), "m" ( rdx ), "m" ( xmm0 ), "m" ( xmm1 ),
158           "m" (pCallStack) // dummy input to prevent the compiler from optimizing the alloca out
159         : "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r11"
160     );
161 
162     switch (pReturnTypeRef->eTypeClass)
163     {
164     case typelib_TypeClass_HYPER:
165     case typelib_TypeClass_UNSIGNED_HYPER:
166         *reinterpret_cast<sal_uInt64 *>( pRegisterReturn ) = rax;
167         break;
168     case typelib_TypeClass_LONG:
169     case typelib_TypeClass_UNSIGNED_LONG:
170     case typelib_TypeClass_ENUM:
171         *reinterpret_cast<sal_uInt32 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt32*>( &rax );
172         break;
173     case typelib_TypeClass_CHAR:
174     case typelib_TypeClass_SHORT:
175     case typelib_TypeClass_UNSIGNED_SHORT:
176         *reinterpret_cast<sal_uInt16 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt16*>( &rax );
177         break;
178     case typelib_TypeClass_BOOLEAN:
179     case typelib_TypeClass_BYTE:
180         *reinterpret_cast<sal_uInt8 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt8*>( &rax );
181         break;
182     case typelib_TypeClass_FLOAT:
183     case typelib_TypeClass_DOUBLE:
184         *reinterpret_cast<double *>( pRegisterReturn ) = xmm0;
185         break;
186     default:
187         {
188             sal_Int32 const nRetSize = pReturnTypeRef->pType->nSize;
189             if (bSimpleReturn && nRetSize <= 16 && nRetSize > 0)
190             {
191                 sal_uInt64 longs[2];
192                 longs[0] = rax;
193                 longs[1] = rdx;
194 
195                 double doubles[2];
196                 doubles[0] = xmm0;
197                 doubles[1] = xmm1;
198                 x86_64::fill_struct( pReturnTypeRef, &longs[0], &doubles[0], pRegisterReturn);
199             }
200             break;
201         }
202     }
203 }
204 
205 //==================================================================================================
206 
207 // Macros for easier insertion of values to registers or stack
208 // pSV - pointer to the source
209 // nr - order of the value [will be increased if stored to register]
210 // pFPR, pGPR - pointer to the registers
211 // pDS - pointer to the stack [will be increased if stored here]
212 
213 // The value in %xmm register is already prepared to be retrieved as a float,
214 // thus we treat float and double the same
215 #define INSERT_FLOAT_DOUBLE( pSV, nr, pFPR, pDS ) \
216 	if ( nr < x86_64::MAX_SSE_REGS ) \
217 		pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \
218 	else \
219 		*pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
220 
221 #define INSERT_INT64( pSV, nr, pGPR, pDS ) \
222 	if ( nr < x86_64::MAX_GPR_REGS ) \
223 		pGPR[nr++] = *reinterpret_cast<sal_uInt64 *>( pSV ); \
224 	else \
225 		*pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV );
226 
227 #define INSERT_INT32( pSV, nr, pGPR, pDS ) \
228 	if ( nr < x86_64::MAX_GPR_REGS ) \
229 		pGPR[nr++] = *reinterpret_cast<sal_uInt32 *>( pSV ); \
230 	else \
231 		*pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV );
232 
233 #define INSERT_INT16( pSV, nr, pGPR, pDS ) \
234 	if ( nr < x86_64::MAX_GPR_REGS ) \
235 		pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \
236 	else \
237 		*pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
238 
239 #define INSERT_INT8( pSV, nr, pGPR, pDS ) \
240 	if ( nr < x86_64::MAX_GPR_REGS ) \
241 		pGPR[nr++] = *reinterpret_cast<sal_uInt8 *>( pSV ); \
242 	else \
243 		*pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV );
244 
245 //==================================================================================================
246 
247 namespace {
248 
249 void appendCString(OUStringBuffer & buffer, char const * text) {
250     if (text != 0) {
251         buffer.append(
252             OStringToOUString(OString(text), RTL_TEXTENCODING_ISO_8859_1));
253             // use 8859-1 to avoid conversion failure
254     }
255 }
256 
257 }
258 
259 static void cpp_call(
260 	bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
261 	bridges::cpp_uno::shared::VtableSlot aVtableSlot,
262 	typelib_TypeDescriptionReference * pReturnTypeRef,
263 	sal_Int32 nParams, typelib_MethodParameter * pParams,
264 	void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
265 {
266 	// Maxium space for [complex ret ptr], values | ptr ...
267 	// (but will be used less - some of the values will be in pGPR and pFPR)
268   	sal_uInt64 *pStack = (sal_uInt64 *)__builtin_alloca( (nParams + 3) * sizeof(sal_uInt64) );
269   	sal_uInt64 *pStackStart = pStack;
270 
271 	sal_uInt64 pGPR[x86_64::MAX_GPR_REGS];
272 	sal_uInt32 nGPR = 0;
273 
274 	double pFPR[x86_64::MAX_SSE_REGS];
275 	sal_uInt32 nFPR = 0;
276 
277 	// Return
278 	typelib_TypeDescription * pReturnTypeDescr = 0;
279 	TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
280 	OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
281 
282 	void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion (see below)
283 
284 	bool bSimpleReturn = true;
285 	if ( pReturnTypeDescr )
286 	{
287 		if ( x86_64::return_in_hidden_param( pReturnTypeRef ) )
288 			bSimpleReturn = false;
289 
290 		if ( bSimpleReturn )
291 			pCppReturn = pUnoReturn; // direct way for simple types
292 		else
293 		{
294 			// complex return via ptr
295 			pCppReturn = bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )?
296 						 __builtin_alloca( pReturnTypeDescr->nSize ) : pUnoReturn;
297 			INSERT_INT64( &pCppReturn, nGPR, pGPR, pStack );
298 		}
299 	}
300 
301 	// Push "this" pointer
302 	void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset;
303 	INSERT_INT64( &pAdjustedThisPtr, nGPR, pGPR, pStack );
304 
305 	// Args
306 	void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
307 	// Indizes of values this have to be converted (interface conversion cpp<=>uno)
308 	sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
309 	// Type descriptions for reconversions
310 	typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
311 
312 	sal_Int32 nTempIndizes = 0;
313 
314 	for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
315 	{
316 		const typelib_MethodParameter & rParam = pParams[nPos];
317 		typelib_TypeDescription * pParamTypeDescr = 0;
318 		TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
319 
320 		if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
321 		{
322 			uno_copyAndConvertData( pCppArgs[nPos] = alloca( 8 ), pUnoArgs[nPos], pParamTypeDescr,
323 									pThis->getBridge()->getUno2Cpp() );
324 
325 			switch (pParamTypeDescr->eTypeClass)
326 			{
327 			case typelib_TypeClass_HYPER:
328 			case typelib_TypeClass_UNSIGNED_HYPER:
329 				INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack );
330 				break;
331 			case typelib_TypeClass_LONG:
332 			case typelib_TypeClass_UNSIGNED_LONG:
333 			case typelib_TypeClass_ENUM:
334 				INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack );
335 				break;
336 			case typelib_TypeClass_SHORT:
337 			case typelib_TypeClass_CHAR:
338 			case typelib_TypeClass_UNSIGNED_SHORT:
339 				INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack );
340 				break;
341 			case typelib_TypeClass_BOOLEAN:
342 			case typelib_TypeClass_BYTE:
343 				INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack );
344 				break;
345 			case typelib_TypeClass_FLOAT:
346 			case typelib_TypeClass_DOUBLE:
347 				INSERT_FLOAT_DOUBLE( pCppArgs[nPos], nFPR, pFPR, pStack );
348 				break;
349 			default:
350 				break;
351 			}
352 
353 			// no longer needed
354 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
355 		}
356 		else // ptr to complex value | ref
357 		{
358 			if (! rParam.bIn) // is pure out
359 			{
360 				// cpp out is constructed mem, uno out is not!
361 				uno_constructData(
362 					pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
363 					pParamTypeDescr );
364 				pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
365 				// will be released at reconversion
366 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
367 			}
368 			// is in/inout
369 			else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
370 			{
371 				uno_copyAndConvertData(
372 					pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
373 					pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
374 
375 				pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
376 				// will be released at reconversion
377 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
378 			}
379 			else // direct way
380 			{
381 				pCppArgs[nPos] = pUnoArgs[nPos];
382 				// no longer needed
383 				TYPELIB_DANGER_RELEASE( pParamTypeDescr );
384 			}
385 			INSERT_INT64( &(pCppArgs[nPos]), nGPR, pGPR, pStack );
386 		}
387 	}
388 
389 	try
390 	{
391         try {
392             callVirtualMethod(
393                 pAdjustedThisPtr, aVtableSlot.index,
394                 pCppReturn, pReturnTypeRef, bSimpleReturn,
395                 pStackStart, ( pStack - pStackStart ),
396                 pGPR, nGPR,
397                 pFPR, nFPR );
398         } catch (Exception &) {
399             throw;
400         } catch (std::exception & e) {
401             OUStringBuffer buf;
402             buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("C++ code threw "));
403             appendCString(buf, typeid(e).name());
404             buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(": "));
405             appendCString(buf, e.what());
406             throw RuntimeException(
407                 buf.makeStringAndClear(), Reference< XInterface >());
408         } catch (...) {
409             throw RuntimeException(
410                 OUString(
411                     RTL_CONSTASCII_USTRINGPARAM(
412                         "C++ code threw unknown exception")),
413                 Reference< XInterface >());
414         }
415 
416 		// NO exception occurred...
417 		*ppUnoExc = 0;
418 
419 		// reconvert temporary params
420 		for ( ; nTempIndizes--; )
421 		{
422 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
423 			typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
424 
425 			if (pParams[nIndex].bIn)
426 			{
427 				if (pParams[nIndex].bOut) // inout
428 				{
429 					uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
430 					uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
431 											pThis->getBridge()->getCpp2Uno() );
432 				}
433 			}
434 			else // pure out
435 			{
436 				uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
437 										pThis->getBridge()->getCpp2Uno() );
438 			}
439 			// destroy temp cpp param => cpp: every param was constructed
440 			uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
441 
442 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
443 		}
444 		// return value
445 		if (pCppReturn && pUnoReturn != pCppReturn)
446 		{
447 			uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
448 									pThis->getBridge()->getCpp2Uno() );
449 			uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
450 		}
451 	}
452  	catch (...)
453  	{
454   		// fill uno exception
455 		CPPU_CURRENT_NAMESPACE::fillUnoException( __cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
456 
457 		// temporary params
458 		for ( ; nTempIndizes--; )
459 		{
460 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
461 			// destroy temp cpp param => cpp: every param was constructed
462 			uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
463 			TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
464 		}
465 		// return type
466 		if (pReturnTypeDescr)
467 			TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
468 	}
469 }
470 
471 //==================================================================================================
472 
473 namespace bridges { namespace cpp_uno { namespace shared {
474 
475 void unoInterfaceProxyDispatch(
476 	uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
477 	void * pReturn, void * pArgs[], uno_Any ** ppException )
478 {
479 	// is my surrogate
480 	bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
481 		= static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
482 #if OSL_DEBUG_LEVEL > 0
483 	typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
484 #endif
485 
486 	switch (pMemberDescr->eTypeClass)
487 	{
488 	case typelib_TypeClass_INTERFACE_ATTRIBUTE:
489 	{
490 #if OSL_DEBUG_LEVEL > 0
491 		// determine vtable call index
492 		sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
493 		OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
494 #endif
495 		VtableSlot aVtableSlot(
496 				getVtableSlot(
497 					reinterpret_cast<
498 					typelib_InterfaceAttributeTypeDescription const * >(
499 						pMemberDescr)));
500 
501 		if (pReturn)
502 		{
503 			// dependent dispatch
504 			cpp_call(
505 				pThis, aVtableSlot,
506 				((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
507 				0, 0, // no params
508 				pReturn, pArgs, ppException );
509 		}
510 		else
511 		{
512 			// is SET
513 			typelib_MethodParameter aParam;
514 			aParam.pTypeRef =
515 				((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
516 			aParam.bIn		= sal_True;
517 			aParam.bOut		= sal_False;
518 
519 			typelib_TypeDescriptionReference * pReturnTypeRef = 0;
520 			OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
521 			typelib_typedescriptionreference_new(
522 				&pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
523 
524 			// dependent dispatch
525 			aVtableSlot.index += 1; // get, then set method
526 			cpp_call(
527 				pThis, aVtableSlot, // get, then set method
528 				pReturnTypeRef,
529 				1, &aParam,
530 				pReturn, pArgs, ppException );
531 
532 			typelib_typedescriptionreference_release( pReturnTypeRef );
533 		}
534 
535 		break;
536 	}
537 	case typelib_TypeClass_INTERFACE_METHOD:
538 	{
539 #if OSL_DEBUG_LEVEL > 0
540 		// determine vtable call index
541 		sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
542 		OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
543 #endif
544 		VtableSlot aVtableSlot(
545 				getVtableSlot(
546 					reinterpret_cast<
547 					typelib_InterfaceMethodTypeDescription const * >(
548 						pMemberDescr)));
549 
550 		switch (aVtableSlot.index)
551 		{
552 			// standard calls
553 		case 1: // acquire uno interface
554 			(*pUnoI->acquire)( pUnoI );
555 			*ppException = 0;
556 			break;
557 		case 2: // release uno interface
558 			(*pUnoI->release)( pUnoI );
559 			*ppException = 0;
560 			break;
561 		case 0: // queryInterface() opt
562 		{
563 			typelib_TypeDescription * pTD = 0;
564 			TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
565 			if (pTD)
566 			{
567                 uno_Interface * pInterface = 0;
568                 (*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
569                     pThis->getBridge()->getUnoEnv(),
570                     (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
571 
572                 if (pInterface)
573                 {
574                     ::uno_any_construct(
575                         reinterpret_cast< uno_Any * >( pReturn ),
576                         &pInterface, pTD, 0 );
577                     (*pInterface->release)( pInterface );
578                     TYPELIB_DANGER_RELEASE( pTD );
579                     *ppException = 0;
580                     break;
581                 }
582                 TYPELIB_DANGER_RELEASE( pTD );
583             }
584 		} // else perform queryInterface()
585 		default:
586 			// dependent dispatch
587 			cpp_call(
588 				pThis, aVtableSlot,
589 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
590 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
591 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
592 				pReturn, pArgs, ppException );
593 		}
594 		break;
595 	}
596 	default:
597 	{
598 		::com::sun::star::uno::RuntimeException aExc(
599 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
600 			::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
601 
602 		Type const & rExcType = ::getCppuType( &aExc );
603 		// binary identical null reference
604 		::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
605 	}
606 	}
607 }
608 
609 } } }
610