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