tdf#130857 qt weld: Support mail merge "Server Auth" dialog
[LibreOffice.git] / bridges / source / cpp_uno / gcc3_linux_powerpc64 / cpp2uno.cxx
blobd1a5ee6f4e76bb6fcafd15f9c2e1ac7facc10885
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <com/sun/star/uno/genfunc.hxx>
22 #include <sal/log.hxx>
23 #include <uno/data.h>
24 #include <typelib/typedescription.hxx>
25 #include <osl/endian.h>
26 #include "bridge.hxx"
27 #include "cppinterfaceproxy.hxx"
28 #include "types.hxx"
29 #include "vtablefactory.hxx"
31 #include "share.hxx"
32 #include <stdio.h>
33 #include <string.h>
34 #include <typeinfo>
36 #ifdef OSL_BIGENDIAN
37 #define IS_BIG_ENDIAN 1
38 #else
39 #define IS_BIG_ENDIAN 0
40 #endif
42 using namespace ::com::sun::star::uno;
44 namespace
48 static typelib_TypeClass cpp2uno_call(
49 bridges::cpp_uno::shared::CppInterfaceProxy * pThis,
50 const typelib_TypeDescription * pMemberTypeDescr,
51 typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
52 sal_Int32 nParams, typelib_MethodParameter * pParams,
53 void ** gpreg, void ** fpreg, void ** ovrflw,
54 sal_Int64 * pRegisterReturn /* space for register return */ )
56 #if OSL_DEBUG_LEVEL > 2
57 fprintf(stderr, "as far as cpp2uno_call\n");
58 #endif
60 int ng = 0; //number of gpr registers used
61 int nf = 0; //number of fpr registers used
63 // gpreg: [ret *], this, [gpr params]
64 // fpreg: [fpr params]
65 // ovrflw: [gpr or fpr params (properly aligned)]
67 // return
68 typelib_TypeDescription * pReturnTypeDescr = 0;
69 if (pReturnTypeRef)
70 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
72 void * pUnoReturn = 0;
73 void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
75 if (pReturnTypeDescr)
77 if (!ppc64::return_in_hidden_param(pReturnTypeRef))
79 pUnoReturn = pRegisterReturn; // direct way for simple types
81 else // complex return via ptr (pCppReturn)
83 pCppReturn = *(void **)gpreg;
84 gpreg++;
85 ng++;
87 pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
88 ? alloca( pReturnTypeDescr->nSize )
89 : pCppReturn); // direct way
92 // pop this
93 gpreg++;
94 ng++;
96 // stack space
97 static_assert(sizeof(void *) == sizeof(sal_Int64), "### unexpected size!");
98 // parameters
99 void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
100 void ** pCppArgs = pUnoArgs + nParams;
101 // indices of values this have to be converted (interface conversion cpp<=>uno)
102 sal_Int32 * pTempIndices = (sal_Int32 *)(pUnoArgs + (2 * nParams));
103 // type descriptions for reconversions
104 typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
106 sal_Int32 nTempIndices = 0;
107 bool bOverflowUsed = false;
108 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
110 const typelib_MethodParameter & rParam = pParams[nPos];
111 typelib_TypeDescription * pParamTypeDescr = 0;
112 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
114 #if OSL_DEBUG_LEVEL > 2
115 fprintf(stderr, "arg %d of %d\n", nPos, nParams);
116 #endif
118 if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
120 #if OSL_DEBUG_LEVEL > 2
121 fprintf(stderr, "simple\n");
122 #endif
124 switch (pParamTypeDescr->eTypeClass)
126 case typelib_TypeClass_FLOAT:
127 case typelib_TypeClass_DOUBLE:
128 if (nf < ppc64::MAX_SSE_REGS)
130 if (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT)
132 float tmp = (float) (*((double *)fpreg));
133 (*((float *) fpreg)) = tmp;
135 pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
136 nf++;
138 if (ng < ppc64::MAX_GPR_REGS)
140 ng++;
141 gpreg++;
144 else
146 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
147 bOverflowUsed = true;
149 if (bOverflowUsed) ovrflw++;
150 break;
151 case typelib_TypeClass_BYTE:
152 case typelib_TypeClass_BOOLEAN:
153 if (ng < ppc64::MAX_GPR_REGS)
155 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 7*IS_BIG_ENDIAN);
156 ng++;
157 gpreg++;
159 else
161 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 7*IS_BIG_ENDIAN);
162 bOverflowUsed = true;
164 if (bOverflowUsed) ovrflw++;
165 break;
166 case typelib_TypeClass_CHAR:
167 case typelib_TypeClass_SHORT:
168 case typelib_TypeClass_UNSIGNED_SHORT:
169 if (ng < ppc64::MAX_GPR_REGS)
171 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 6*IS_BIG_ENDIAN);
172 ng++;
173 gpreg++;
175 else
177 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 6*IS_BIG_ENDIAN);
178 bOverflowUsed = true;
180 if (bOverflowUsed) ovrflw++;
181 break;
182 case typelib_TypeClass_ENUM:
183 case typelib_TypeClass_LONG:
184 case typelib_TypeClass_UNSIGNED_LONG:
185 if (ng < ppc64::MAX_GPR_REGS)
187 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 4*IS_BIG_ENDIAN);
188 ng++;
189 gpreg++;
191 else
193 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 4*IS_BIG_ENDIAN);
194 bOverflowUsed = true;
196 if (bOverflowUsed) ovrflw++;
197 break;
198 default:
199 if (ng < ppc64::MAX_GPR_REGS)
201 pCppArgs[nPos] = pUnoArgs[nPos] = gpreg++;
202 ng++;
204 else
206 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
207 bOverflowUsed = true;
209 if (bOverflowUsed) ovrflw++;
210 break;
213 // no longer needed
214 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
216 else // ptr to complex value | ref
218 #if OSL_DEBUG_LEVEL > 2
219 fprintf(stderr, "complex, ng is %d\n", ng);
220 #endif
221 void *pCppStack; //temporary stack pointer
223 if (ng < ppc64::MAX_GPR_REGS)
225 pCppArgs[nPos] = pCppStack = *gpreg++;
226 ng++;
228 else
230 pCppArgs[nPos] = pCppStack = *ovrflw;
231 bOverflowUsed = true;
233 if (bOverflowUsed) ovrflw++;
235 if (! rParam.bIn) // is pure out
237 // uno out is unconstructed mem!
238 pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
239 pTempIndices[nTempIndices] = nPos;
240 // will be released at reconversion
241 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
243 // is in/inout
244 else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
246 uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
247 pCppStack, pParamTypeDescr,
248 pThis->getBridge()->getCpp2Uno() );
249 pTempIndices[nTempIndices] = nPos; // has to be reconverted
250 // will be released at reconversion
251 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
253 else // direct way
255 pUnoArgs[nPos] = pCppStack;
256 // no longer needed
257 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
262 #if OSL_DEBUG_LEVEL > 2
263 fprintf(stderr, "end of params\n");
264 #endif
266 // ExceptionHolder
267 uno_Any aUnoExc; // Any will be constructed by callee
268 uno_Any * pUnoExc = &aUnoExc;
270 // invoke uno dispatch call
271 (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
273 // in case an exception occurred...
274 if (pUnoExc)
276 // destruct temporary in/inout params
277 for ( ; nTempIndices--; )
279 sal_Int32 nIndex = pTempIndices[nTempIndices];
281 if (pParams[nIndex].bIn) // is in/inout => was constructed
282 uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndices], 0 );
283 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
285 if (pReturnTypeDescr)
286 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
288 CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc, pThis->getBridge()->getUno2Cpp() );
289 // has to destruct the any
290 // is here for dummy
291 return typelib_TypeClass_VOID;
293 else // else no exception occurred...
295 // temporary params
296 for ( ; nTempIndices--; )
298 sal_Int32 nIndex = pTempIndices[nTempIndices];
299 typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
301 if (pParams[nIndex].bOut) // inout/out
303 // convert and assign
304 uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
305 uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
306 pThis->getBridge()->getUno2Cpp() );
308 // destroy temp uno param
309 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
311 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
313 // return
314 if (pCppReturn) // has complex return
316 if (pUnoReturn != pCppReturn) // needs reconversion
318 uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
319 pThis->getBridge()->getUno2Cpp() );
320 // destroy temp uno return
321 uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
323 // complex return ptr is set to return reg
324 *(void **)pRegisterReturn = pCppReturn;
326 if (pReturnTypeDescr)
328 typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
329 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
330 return eRet;
332 else
333 return typelib_TypeClass_VOID;
337 #if defined(_CALL_ELF) && _CALL_ELF == 2
338 # define PARAMSAVE 32
339 #else
340 # define PARAMSAVE 48
341 #endif
343 static typelib_TypeClass cpp_mediate(
344 sal_uInt64 nOffsetAndIndex,
345 void ** gpreg, void ** fpreg, long sp,
346 sal_Int64 * pRegisterReturn /* space for register return */ )
348 static_assert(sizeof(sal_Int64)==sizeof(void *), "### unexpected!");
350 sal_Int32 nVtableOffset = (nOffsetAndIndex >> 32);
351 sal_Int32 nFunctionIndex = (nOffsetAndIndex & 0xFFFFFFFF);
353 long sf = *(long*)sp;
354 void ** ovrflw = (void**)(sf + PARAMSAVE + 64);
356 // gpreg: [ret *], this, [other gpr params]
357 // fpreg: [fpr params]
358 // ovrflw: [gpr or fpr params (properly aligned)]
360 void * pThis;
361 if (nFunctionIndex & 0x80000000 )
363 nFunctionIndex &= 0x7fffffff;
364 pThis = gpreg[1];
365 #if OSL_DEBUG_LEVEL > 2
366 fprintf(stderr, "pThis is gpreg[1]\n");
367 #endif
369 else
371 pThis = gpreg[0];
372 #if OSL_DEBUG_LEVEL > 2
373 fprintf(stderr, "pThis is gpreg[0]\n");
374 #endif
377 #if OSL_DEBUG_LEVEL > 2
378 fprintf(stderr, "pThis is %lx\n", pThis);
379 #endif
381 pThis = static_cast< char * >(pThis) - nVtableOffset;
383 #if OSL_DEBUG_LEVEL > 2
384 fprintf(stderr, "pThis is now %lx\n", pThis);
385 #endif
387 bridges::cpp_uno::shared::CppInterfaceProxy * pCppI
388 = bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
389 pThis);
391 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
393 #if OSL_DEBUG_LEVEL > 2
394 fprintf(stderr, "indexes are %d %d\n", nFunctionIndex, pTypeDescr->nMapFunctionIndexToMemberIndex);
395 #endif
397 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
399 SAL_WARN(
400 "bridges",
401 "illegal " << OUString::unacquired(&pTypeDescr->aBase.pTypeName)
402 << " vtable index " << nFunctionIndex << "/"
403 << pTypeDescr->nMapFunctionIndexToMemberIndex);
404 throw RuntimeException(
405 ("illegal " + OUString::unacquired(&pTypeDescr->aBase.pTypeName)
406 + " vtable index " + OUString::number(nFunctionIndex) + "/"
407 + OUString::number(pTypeDescr->nMapFunctionIndexToMemberIndex)),
408 (XInterface *)pThis);
411 // determine called method
412 sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
413 assert(nMemberPos < pTypeDescr->nAllMembers);
415 #if OSL_DEBUG_LEVEL > 2
416 fprintf(stderr, "members are %d %d\n", nMemberPos, pTypeDescr->nAllMembers);
417 #endif
419 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
421 typelib_TypeClass eRet;
422 switch (aMemberDescr.get()->eTypeClass)
424 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
426 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
428 // is GET method
429 eRet = cpp2uno_call(
430 pCppI, aMemberDescr.get(),
431 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
432 0, 0, // no params
433 gpreg, fpreg, ovrflw, pRegisterReturn );
435 else
437 // is SET method
438 typelib_MethodParameter aParam;
439 aParam.pTypeRef =
440 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
441 aParam.bIn = sal_True;
442 aParam.bOut = sal_False;
444 eRet = cpp2uno_call(
445 pCppI, aMemberDescr.get(),
446 0, // indicates void return
447 1, &aParam,
448 gpreg, fpreg, ovrflw, pRegisterReturn );
450 break;
452 case typelib_TypeClass_INTERFACE_METHOD:
454 // is METHOD
455 switch (nFunctionIndex)
457 case 1: // acquire()
458 pCppI->acquireProxy(); // non virtual call!
459 eRet = typelib_TypeClass_VOID;
460 break;
461 case 2: // release()
462 pCppI->releaseProxy(); // non virtual call!
463 eRet = typelib_TypeClass_VOID;
464 break;
465 case 0: // queryInterface() opt
467 typelib_TypeDescription * pTD = 0;
468 TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
469 if (pTD)
471 XInterface * pInterface = 0;
472 (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
473 pCppI->getBridge()->getCppEnv(),
474 (void **)&pInterface, pCppI->getOid().pData,
475 (typelib_InterfaceTypeDescription *)pTD );
477 if (pInterface)
479 ::uno_any_construct(
480 reinterpret_cast< uno_Any * >( gpreg[0] ),
481 &pInterface, pTD, cpp_acquire );
482 pInterface->release();
483 TYPELIB_DANGER_RELEASE( pTD );
484 *(void **)pRegisterReturn = gpreg[0];
485 eRet = typelib_TypeClass_ANY;
486 break;
488 TYPELIB_DANGER_RELEASE( pTD );
490 } // else perform queryInterface()
491 default:
492 eRet = cpp2uno_call(
493 pCppI, aMemberDescr.get(),
494 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
495 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
496 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
497 gpreg, fpreg, ovrflw, pRegisterReturn );
499 break;
501 default:
503 #if OSL_DEBUG_LEVEL > 2
504 fprintf(stderr, "screwed\n");
505 #endif
507 throw RuntimeException( "no member description found!", (XInterface *)pThis );
511 #if OSL_DEBUG_LEVEL > 2
512 fprintf(stderr, "end of cpp_mediate\n");
513 #endif
514 return eRet;
517 extern "C" void privateSnippetExecutor( ... )
519 sal_uInt64 gpreg[ppc64::MAX_GPR_REGS];
521 register long r3 asm("r3"); gpreg[0] = r3;
522 register long r4 asm("r4"); gpreg[1] = r4;
523 register long r5 asm("r5"); gpreg[2] = r5;
524 register long r6 asm("r6"); gpreg[3] = r6;
525 register long r7 asm("r7"); gpreg[4] = r7;
526 register long r8 asm("r8"); gpreg[5] = r8;
527 register long r9 asm("r9"); gpreg[6] = r9;
528 register long r10 asm("r10"); gpreg[7] = r10;
530 double fpreg[ppc64::MAX_SSE_REGS];
532 __asm__ __volatile__ (
533 "stfd 1, 0(%0)\t\n"
534 "stfd 2, 8(%0)\t\n"
535 "stfd 3, 16(%0)\t\n"
536 "stfd 4, 24(%0)\t\n"
537 "stfd 5, 32(%0)\t\n"
538 "stfd 6, 40(%0)\t\n"
539 "stfd 7, 48(%0)\t\n"
540 "stfd 8, 56(%0)\t\n"
541 "stfd 9, 64(%0)\t\n"
542 "stfd 10, 72(%0)\t\n"
543 "stfd 11, 80(%0)\t\n"
544 "stfd 12, 88(%0)\t\n"
545 "stfd 13, 96(%0)\t\n"
546 : : "r" (fpreg)
547 : "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9",
548 "fr10", "fr11", "fr12", "fr13"
551 register long r11 asm("r11");
552 const long nOffsetAndIndex = r11;
554 register long r1 asm("r1");
555 const long sp = r1;
557 #if defined(_CALL_ELF) && _CALL_ELF == 2
558 volatile long nRegReturn[2];
559 #else
560 volatile long nRegReturn[1];
561 #endif
563 typelib_TypeClass aType =
564 cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, sp, (sal_Int64*)nRegReturn);
566 switch( aType )
568 case typelib_TypeClass_VOID:
569 break;
570 case typelib_TypeClass_BOOLEAN:
571 case typelib_TypeClass_BYTE:
572 __asm__( "lbz 3,%0\n\t"
573 : : "m" (nRegReturn[0]) );
574 break;
575 case typelib_TypeClass_CHAR:
576 case typelib_TypeClass_UNSIGNED_SHORT:
577 __asm__( "lhz 3,%0\n\t"
578 : : "m" (nRegReturn[0]) );
579 break;
580 case typelib_TypeClass_SHORT:
581 __asm__( "lha 3,%0\n\t"
582 : : "m" (nRegReturn[0]) );
583 break;
584 case typelib_TypeClass_ENUM:
585 case typelib_TypeClass_UNSIGNED_LONG:
586 __asm__( "lwz 3,%0\n\t"
587 : : "m"(nRegReturn[0]) );
588 break;
589 case typelib_TypeClass_LONG:
590 __asm__( "lwa 3,%0\n\t"
591 : : "m"(nRegReturn[0]) );
592 break;
593 case typelib_TypeClass_FLOAT:
594 __asm__( "lfs 1,%0\n\t"
595 : : "m" (*((float*)nRegReturn)) );
596 break;
597 case typelib_TypeClass_DOUBLE:
598 __asm__( "lfd 1,%0\n\t"
599 : : "m" (*((double*)nRegReturn)) );
600 break;
601 default:
602 __asm__( "ld 3,%0\n\t"
603 : : "m" (nRegReturn[0]) );
604 #if defined(_CALL_ELF) && _CALL_ELF == 2
605 __asm__( "ld 4,%0\n\t"
606 : : "m" (nRegReturn[1]) );
607 #endif
608 break;
612 #if defined(_CALL_ELF) && _CALL_ELF == 2
613 const int codeSnippetSize = 32;
614 #else
615 const int codeSnippetSize = 24;
616 #endif
618 unsigned char * codeSnippet( unsigned char * code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
619 bool bHasHiddenParam)
621 #if OSL_DEBUG_LEVEL > 2
622 fprintf(stderr,"in codeSnippet functionIndex is %x\n", nFunctionIndex);
623 fprintf(stderr,"in codeSnippet vtableOffset is %x\n", nVtableOffset);
624 #endif
626 sal_uInt64 nOffsetAndIndex = ( ( (sal_uInt64) nVtableOffset ) << 32 ) | ( (sal_uInt64) nFunctionIndex );
628 if ( bHasHiddenParam )
629 nOffsetAndIndex |= 0x80000000;
630 #if defined(_CALL_ELF) && _CALL_ELF == 2
631 unsigned int *raw = (unsigned int *)&code[0];
633 raw[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
634 raw[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
635 raw[2] = 0x7d8903a6; /* mtctr 12 */
636 raw[3] = 0x4e800420; /* bctr */
637 /* 1: .quad function_addr */
638 /* 2: .quad context */
639 *(void **)&raw[4] = (void *)privateSnippetExecutor;
640 *(void **)&raw[6] = (void*)nOffsetAndIndex;
641 #else
642 void ** raw = (void **)&code[0];
643 memcpy(raw, (char*) privateSnippetExecutor, 16);
644 raw[2] = (void*) nOffsetAndIndex;
645 #endif
646 #if OSL_DEBUG_LEVEL > 2
647 fprintf(stderr, "in: offset/index is %x %x %d, %lx\n",
648 nFunctionIndex, nVtableOffset, bHasHiddenParam, raw[2]);
649 #endif
650 return (code + codeSnippetSize);
655 void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const * bptr, unsigned char const * eptr)
657 int const lineSize = 32;
658 for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
659 __asm__ volatile ("dcbst 0, %0" : : "r"(p) : "memory");
661 __asm__ volatile ("sync" : : : "memory");
662 for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
663 __asm__ volatile ("icbi 0, %0" : : "r"(p) : "memory");
665 __asm__ volatile ("isync" : : : "memory");
668 struct bridges::cpp_uno::shared::VtableFactory::Slot { void const * fn; };
670 bridges::cpp_uno::shared::VtableFactory::Slot *
671 bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
673 return static_cast< Slot * >(block) + 2;
676 std::size_t bridges::cpp_uno::shared::VtableFactory::getBlockSize(
677 sal_Int32 slotCount)
679 return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
682 namespace {
683 // Some dummy type whose RTTI is used in the synthesized proxy vtables to make uses of dynamic_cast
684 // on such proxy objects not crash:
685 struct ProxyRtti {};
688 bridges::cpp_uno::shared::VtableFactory::Slot *
689 bridges::cpp_uno::shared::VtableFactory::initializeBlock(
690 void * block, sal_Int32 slotCount, sal_Int32,
691 typelib_InterfaceTypeDescription *)
693 Slot * slots = mapBlockToVtable(block);
694 slots[-2].fn = 0;
695 slots[-1].fn = &typeid(ProxyRtti);
696 return slots + slotCount;
699 unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
700 Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
701 typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
702 sal_Int32 functionCount, sal_Int32 vtableOffset)
704 (*slots) -= functionCount;
705 Slot * s = *slots;
706 #if OSL_DEBUG_LEVEL > 2
707 fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
708 fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
709 #endif
711 for (sal_Int32 i = 0; i < type->nMembers; ++i) {
712 typelib_TypeDescription * member = 0;
713 TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
714 assert(member != 0);
715 switch (member->eTypeClass) {
716 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
717 // Getter:
718 (s++)->fn = code + writetoexecdiff;
719 code = codeSnippet(
720 code, functionOffset++, vtableOffset,
721 ppc64::return_in_hidden_param(
722 reinterpret_cast<
723 typelib_InterfaceAttributeTypeDescription * >(
724 member)->pAttributeTypeRef));
726 // Setter:
727 if (!reinterpret_cast<
728 typelib_InterfaceAttributeTypeDescription * >(
729 member)->bReadOnly)
731 (s++)->fn = code + writetoexecdiff;
732 code = codeSnippet(code, functionOffset++, vtableOffset, false);
734 break;
736 case typelib_TypeClass_INTERFACE_METHOD:
737 (s++)->fn = code + writetoexecdiff;
738 code = codeSnippet(
739 code, functionOffset++, vtableOffset,
740 ppc64::return_in_hidden_param(
741 reinterpret_cast<
742 typelib_InterfaceMethodTypeDescription * >(
743 member)->pReturnTypeRef));
744 break;
746 default:
747 assert(false);
748 break;
750 TYPELIB_DANGER_RELEASE(member);
752 return code;
755 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */