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           "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7"
154     );
155 
156     switch (pReturnTypeRef->eTypeClass)
157     {
158     case typelib_TypeClass_HYPER:
159     case typelib_TypeClass_UNSIGNED_HYPER:
160         *reinterpret_cast<sal_uInt64 *>( pRegisterReturn ) = rax;
161         break;
162     case typelib_TypeClass_LONG:
163     case typelib_TypeClass_UNSIGNED_LONG:
164     case typelib_TypeClass_ENUM:
165         *reinterpret_cast<sal_uInt32 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt32*>( &rax );
166         break;
167     case typelib_TypeClass_CHAR:
168     case typelib_TypeClass_SHORT:
169     case typelib_TypeClass_UNSIGNED_SHORT:
170         *reinterpret_cast<sal_uInt16 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt16*>( &rax );
171         break;
172     case typelib_TypeClass_BOOLEAN:
173     case typelib_TypeClass_BYTE:
174         *reinterpret_cast<sal_uInt8 *>( pRegisterReturn ) = *reinterpret_cast<sal_uInt8*>( &rax );
175         break;
176     case typelib_TypeClass_FLOAT:
177     case typelib_TypeClass_DOUBLE:
178         *reinterpret_cast<double *>( pRegisterReturn ) = xmm0;
179         break;
180     default:
181         {
182             sal_Int32 const nRetSize = pReturnTypeRef->pType->nSize;
183             if (bSimpleReturn && nRetSize <= 16 && nRetSize > 0)
184             {
185                 sal_uInt64 longs[2];
186                 longs[0] = rax;
187                 longs[1] = rdx;
188 
189                 double doubles[2];
190                 doubles[0] = xmm0;
191                 doubles[1] = xmm1;
192                 x86_64::fill_struct( pReturnTypeRef, &longs[0], &doubles[0], pRegisterReturn);
193             }
194             break;
195         }
196     }
197 }
198 
199 //==================================================================================================
200 
201 // Macros for easier insertion of values to registers or stack
202 // pSV - pointer to the source
203 // nr - order of the value [will be increased if stored to register]
204 // pFPR, pGPR - pointer to the registers
205 // pDS - pointer to the stack [will be increased if stored here]
206 
207 // The value in %xmm register is already prepared to be retrieved as a float,
208 // thus we treat float and double the same
209 #define INSERT_FLOAT_DOUBLE( pSV, nr, pFPR, pDS ) \
210 	if ( nr < x86_64::MAX_SSE_REGS ) \
211 		pFPR[nr++] = *reinterpret_cast<double *>( pSV ); \
212 	else \
213 		*pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV ); // verbatim!
214 
215 #define INSERT_INT64( pSV, nr, pGPR, pDS ) \
216 	if ( nr < x86_64::MAX_GPR_REGS ) \
217 		pGPR[nr++] = *reinterpret_cast<sal_uInt64 *>( pSV ); \
218 	else \
219 		*pDS++ = *reinterpret_cast<sal_uInt64 *>( pSV );
220 
221 #define INSERT_INT32( pSV, nr, pGPR, pDS ) \
222 	if ( nr < x86_64::MAX_GPR_REGS ) \
223 		pGPR[nr++] = *reinterpret_cast<sal_uInt32 *>( pSV ); \
224 	else \
225 		*pDS++ = *reinterpret_cast<sal_uInt32 *>( pSV );
226 
227 #define INSERT_INT16( pSV, nr, pGPR, pDS ) \
228 	if ( nr < x86_64::MAX_GPR_REGS ) \
229 		pGPR[nr++] = *reinterpret_cast<sal_uInt16 *>( pSV ); \
230 	else \
231 		*pDS++ = *reinterpret_cast<sal_uInt16 *>( pSV );
232 
233 #define INSERT_INT8( pSV, nr, pGPR, pDS ) \
234 	if ( nr < x86_64::MAX_GPR_REGS ) \
235 		pGPR[nr++] = *reinterpret_cast<sal_uInt8 *>( pSV ); \
236 	else \
237 		*pDS++ = *reinterpret_cast<sal_uInt8 *>( pSV );
238 
239 //==================================================================================================
240 
241 namespace {
242 
243 void appendCString(OUStringBuffer & buffer, char const * text) {
244     if (text != 0) {
245         buffer.append(
246             OStringToOUString(OString(text), RTL_TEXTENCODING_ISO_8859_1));
247             // use 8859-1 to avoid conversion failure
248     }
249 }
250 
251 }
252 
253 static void cpp_call(
254 	bridges::cpp_uno::shared::UnoInterfaceProxy * pThis,
255 	bridges::cpp_uno::shared::VtableSlot aVtableSlot,
256 	typelib_TypeDescriptionReference * pReturnTypeRef,
257 	sal_Int32 nParams, typelib_MethodParameter * pParams,
258 	void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
259 {
260 	// Maxium space for [complex ret ptr], values | ptr ...
261 	// (but will be used less - some of the values will be in pGPR and pFPR)
262   	sal_uInt64 *pStack = (sal_uInt64 *)__builtin_alloca( (nParams + 3) * sizeof(sal_uInt64) );
263   	sal_uInt64 *pStackStart = pStack;
264 
265 	sal_uInt64 pGPR[x86_64::MAX_GPR_REGS];
266 	sal_uInt32 nGPR = 0;
267 
268 	double pFPR[x86_64::MAX_SSE_REGS];
269 	sal_uInt32 nFPR = 0;
270 
271 	// Return
272 	typelib_TypeDescription * pReturnTypeDescr = 0;
273 	TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
274 	OSL_ENSURE( pReturnTypeDescr, "### expected return type description!" );
275 
276 	void * pCppReturn = 0; // if != 0 && != pUnoReturn, needs reconversion (see below)
277 
278 	bool bSimpleReturn = true;
279 	if ( pReturnTypeDescr )
280 	{
281 		if ( x86_64::return_in_hidden_param( pReturnTypeRef ) )
282 			bSimpleReturn = false;
283 
284 		if ( bSimpleReturn )
285 			pCppReturn = pUnoReturn; // direct way for simple types
286 		else
287 		{
288 			// complex return via ptr
289 			pCppReturn = bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )?
290 						 __builtin_alloca( pReturnTypeDescr->nSize ) : pUnoReturn;
291 			INSERT_INT64( &pCppReturn, nGPR, pGPR, pStack );
292 		}
293 	}
294 
295 	// Push "this" pointer
296 	void * pAdjustedThisPtr = reinterpret_cast< void ** >( pThis->getCppI() ) + aVtableSlot.offset;
297 	INSERT_INT64( &pAdjustedThisPtr, nGPR, pGPR, pStack );
298 
299 	// Args
300 	void ** pCppArgs = (void **)alloca( 3 * sizeof(void *) * nParams );
301 	// Indizes of values this have to be converted (interface conversion cpp<=>uno)
302 	sal_Int32 * pTempIndizes = (sal_Int32 *)(pCppArgs + nParams);
303 	// Type descriptions for reconversions
304 	typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pCppArgs + (2 * nParams));
305 
306 	sal_Int32 nTempIndizes = 0;
307 
308 	for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
309 	{
310 		const typelib_MethodParameter & rParam = pParams[nPos];
311 		typelib_TypeDescription * pParamTypeDescr = 0;
312 		TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
313 
314 		if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
315 		{
316 			uno_copyAndConvertData( pCppArgs[nPos] = alloca( 8 ), pUnoArgs[nPos], pParamTypeDescr,
317 									pThis->getBridge()->getUno2Cpp() );
318 
319 			switch (pParamTypeDescr->eTypeClass)
320 			{
321 			case typelib_TypeClass_HYPER:
322 			case typelib_TypeClass_UNSIGNED_HYPER:
323 				INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack );
324 				break;
325 			case typelib_TypeClass_LONG:
326 			case typelib_TypeClass_UNSIGNED_LONG:
327 			case typelib_TypeClass_ENUM:
328 				INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack );
329 				break;
330 			case typelib_TypeClass_SHORT:
331 			case typelib_TypeClass_CHAR:
332 			case typelib_TypeClass_UNSIGNED_SHORT:
333 				INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack );
334 				break;
335 			case typelib_TypeClass_BOOLEAN:
336 			case typelib_TypeClass_BYTE:
337 				INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack );
338 				break;
339 			case typelib_TypeClass_FLOAT:
340 			case typelib_TypeClass_DOUBLE:
341 				INSERT_FLOAT_DOUBLE( pCppArgs[nPos], nFPR, pFPR, pStack );
342 				break;
343 			default:
344 				break;
345 			}
346 
347 			// no longer needed
348 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
349 		}
350 		else // ptr to complex value | ref
351 		{
352 			if (! rParam.bIn) // is pure out
353 			{
354 				// cpp out is constructed mem, uno out is not!
355 				uno_constructData(
356 					pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
357 					pParamTypeDescr );
358 				pTempIndizes[nTempIndizes] = nPos; // default constructed for cpp call
359 				// will be released at reconversion
360 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
361 			}
362 			// is in/inout
363 			else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
364 			{
365 				uno_copyAndConvertData(
366 					pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
367 					pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
368 
369 				pTempIndizes[nTempIndizes] = nPos; // has to be reconverted
370 				// will be released at reconversion
371 				ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr;
372 			}
373 			else // direct way
374 			{
375 				pCppArgs[nPos] = pUnoArgs[nPos];
376 				// no longer needed
377 				TYPELIB_DANGER_RELEASE( pParamTypeDescr );
378 			}
379 			INSERT_INT64( &(pCppArgs[nPos]), nGPR, pGPR, pStack );
380 		}
381 	}
382 
383 	try
384 	{
385         try {
386             callVirtualMethod(
387                 pAdjustedThisPtr, aVtableSlot.index,
388                 pCppReturn, pReturnTypeRef, bSimpleReturn,
389                 pStackStart, ( pStack - pStackStart ),
390                 pGPR, nGPR,
391                 pFPR, nFPR );
392         } catch (Exception &) {
393             throw;
394         } catch (std::exception & e) {
395             OUStringBuffer buf;
396             buf.appendAscii(RTL_CONSTASCII_STRINGPARAM("C++ code threw "));
397             appendCString(buf, typeid(e).name());
398             buf.appendAscii(RTL_CONSTASCII_STRINGPARAM(": "));
399             appendCString(buf, e.what());
400             throw RuntimeException(
401                 buf.makeStringAndClear(), Reference< XInterface >());
402         } catch (...) {
403             throw RuntimeException(
404                 OUString(
405                     RTL_CONSTASCII_USTRINGPARAM(
406                         "C++ code threw unknown exception")),
407                 Reference< XInterface >());
408         }
409 
410 		// NO exception occured...
411 		*ppUnoExc = 0;
412 
413 		// reconvert temporary params
414 		for ( ; nTempIndizes--; )
415 		{
416 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
417 			typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes];
418 
419 			if (pParams[nIndex].bIn)
420 			{
421 				if (pParams[nIndex].bOut) // inout
422 				{
423 					uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); // destroy uno value
424 					uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
425 											pThis->getBridge()->getCpp2Uno() );
426 				}
427 			}
428 			else // pure out
429 			{
430 				uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
431 										pThis->getBridge()->getCpp2Uno() );
432 			}
433 			// destroy temp cpp param => cpp: every param was constructed
434 			uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
435 
436 			TYPELIB_DANGER_RELEASE( pParamTypeDescr );
437 		}
438 		// return value
439 		if (pCppReturn && pUnoReturn != pCppReturn)
440 		{
441 			uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
442 									pThis->getBridge()->getCpp2Uno() );
443 			uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
444 		}
445 	}
446  	catch (...)
447  	{
448   		// fill uno exception
449 		fillUnoException( CPPU_CURRENT_NAMESPACE::__cxa_get_globals()->caughtExceptions, *ppUnoExc, pThis->getBridge()->getCpp2Uno() );
450 
451 		// temporary params
452 		for ( ; nTempIndizes--; )
453 		{
454 			sal_Int32 nIndex = pTempIndizes[nTempIndizes];
455 			// destroy temp cpp param => cpp: every param was constructed
456 			uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], cpp_release );
457 			TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] );
458 		}
459 		// return type
460 		if (pReturnTypeDescr)
461 			TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
462 	}
463 }
464 
465 //==================================================================================================
466 
467 namespace bridges { namespace cpp_uno { namespace shared {
468 
469 void unoInterfaceProxyDispatch(
470 	uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
471 	void * pReturn, void * pArgs[], uno_Any ** ppException )
472 {
473 	// is my surrogate
474 	bridges::cpp_uno::shared::UnoInterfaceProxy * pThis
475 		= static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
476 #if OSL_DEBUG_LEVEL > 0
477 	typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
478 #endif
479 
480 	switch (pMemberDescr->eTypeClass)
481 	{
482 	case typelib_TypeClass_INTERFACE_ATTRIBUTE:
483 	{
484 #if OSL_DEBUG_LEVEL > 0
485 		// determine vtable call index
486 		sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
487 		OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
488 #endif
489 		VtableSlot aVtableSlot(
490 				getVtableSlot(
491 					reinterpret_cast<
492 					typelib_InterfaceAttributeTypeDescription const * >(
493 						pMemberDescr)));
494 
495 		if (pReturn)
496 		{
497 			// dependent dispatch
498 			cpp_call(
499 				pThis, aVtableSlot,
500 				((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef,
501 				0, 0, // no params
502 				pReturn, pArgs, ppException );
503 		}
504 		else
505 		{
506 			// is SET
507 			typelib_MethodParameter aParam;
508 			aParam.pTypeRef =
509 				((typelib_InterfaceAttributeTypeDescription *)pMemberDescr)->pAttributeTypeRef;
510 			aParam.bIn		= sal_True;
511 			aParam.bOut		= sal_False;
512 
513 			typelib_TypeDescriptionReference * pReturnTypeRef = 0;
514 			OUString aVoidName( RTL_CONSTASCII_USTRINGPARAM("void") );
515 			typelib_typedescriptionreference_new(
516 				&pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
517 
518 			// dependent dispatch
519 			aVtableSlot.index += 1; // get, then set method
520 			cpp_call(
521 				pThis, aVtableSlot, // get, then set method
522 				pReturnTypeRef,
523 				1, &aParam,
524 				pReturn, pArgs, ppException );
525 
526 			typelib_typedescriptionreference_release( pReturnTypeRef );
527 		}
528 
529 		break;
530 	}
531 	case typelib_TypeClass_INTERFACE_METHOD:
532 	{
533 #if OSL_DEBUG_LEVEL > 0
534 		// determine vtable call index
535 		sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
536 		OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### member pos out of range!" );
537 #endif
538 		VtableSlot aVtableSlot(
539 				getVtableSlot(
540 					reinterpret_cast<
541 					typelib_InterfaceMethodTypeDescription const * >(
542 						pMemberDescr)));
543 
544 		switch (aVtableSlot.index)
545 		{
546 			// standard calls
547 		case 1: // acquire uno interface
548 			(*pUnoI->acquire)( pUnoI );
549 			*ppException = 0;
550 			break;
551 		case 2: // release uno interface
552 			(*pUnoI->release)( pUnoI );
553 			*ppException = 0;
554 			break;
555 		case 0: // queryInterface() opt
556 		{
557 			typelib_TypeDescription * pTD = 0;
558 			TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( pArgs[0] )->getTypeLibType() );
559 			if (pTD)
560 			{
561                 uno_Interface * pInterface = 0;
562                 (*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
563                     pThis->getBridge()->getUnoEnv(),
564                     (void **)&pInterface, pThis->oid.pData, (typelib_InterfaceTypeDescription *)pTD );
565 
566                 if (pInterface)
567                 {
568                     ::uno_any_construct(
569                         reinterpret_cast< uno_Any * >( pReturn ),
570                         &pInterface, pTD, 0 );
571                     (*pInterface->release)( pInterface );
572                     TYPELIB_DANGER_RELEASE( pTD );
573                     *ppException = 0;
574                     break;
575                 }
576                 TYPELIB_DANGER_RELEASE( pTD );
577             }
578 		} // else perform queryInterface()
579 		default:
580 			// dependent dispatch
581 			cpp_call(
582 				pThis, aVtableSlot,
583 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pReturnTypeRef,
584 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->nParams,
585 				((typelib_InterfaceMethodTypeDescription *)pMemberDescr)->pParams,
586 				pReturn, pArgs, ppException );
587 		}
588 		break;
589 	}
590 	default:
591 	{
592 		::com::sun::star::uno::RuntimeException aExc(
593 			OUString( RTL_CONSTASCII_USTRINGPARAM("illegal member type description!") ),
594 			::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >() );
595 
596 		Type const & rExcType = ::getCppuType( &aExc );
597 		// binary identical null reference
598 		::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), 0 );
599 	}
600 	}
601 }
602 
603 } } }
604