cid#1636693 COPY_INSTEAD_OF_MOVE
[LibreOffice.git] / bridges / source / cpp_uno / gcc3_linux_hppa / cpp2uno.cxx
blob7e8524d1c726e41e4c45a3ba6b74fa7e7dfdc248
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 .
20 #include <malloc.h>
21 #include <typeinfo>
23 #include <rtl/alloc.h>
25 #include <com/sun/star/uno/genfunc.hxx>
26 #include "com/sun/star/uno/RuntimeException.hpp"
27 #include <sal/log.hxx>
28 #include <uno/data.h>
29 #include <typelib/typedescription.hxx>
31 #include "bridge.hxx"
32 #include "cppinterfaceproxy.hxx"
33 #include "types.hxx"
34 #include "vtablefactory.hxx"
36 #include "share.hxx"
38 #include <dlfcn.h>
41 using namespace ::osl;
42 using namespace ::com::sun::star::uno;
44 namespace
47 static typelib_TypeClass cpp2uno_call(
48 bridges::cpp_uno::shared::CppInterfaceProxy* pThis,
49 const typelib_TypeDescription * pMemberTypeDescr,
50 typelib_TypeDescriptionReference * pReturnTypeRef,
51 sal_Int32 nParams, typelib_MethodParameter * pParams,
52 long r8, void ** gpreg, double *fpreg, void ** ovrflw,
53 sal_Int64 * pRegisterReturn /* space for register return */ )
55 void ** startovrflw = ovrflw;
56 int nregs = 0; //number of words passed in registers
58 #if OSL_DEBUG_LEVEL > 2
59 fprintf(stderr, "cpp2uno_call\n");
60 #endif
61 // return
62 typelib_TypeDescription * pReturnTypeDescr = 0;
63 if (pReturnTypeRef)
64 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
66 void * pUnoReturn = 0;
67 // complex return ptr: if != 0 && != pUnoReturn, reconversion need
68 void * pCppReturn = 0;
70 if (pReturnTypeDescr)
72 if (hppa::isRegisterReturn(pReturnTypeRef))
74 #if OSL_DEBUG_LEVEL > 2
75 fprintf(stderr, "simple return\n");
76 #endif
77 pUnoReturn = pRegisterReturn; // direct way for simple types
79 else
81 #if OSL_DEBUG_LEVEL > 2
82 fprintf(stderr, "complex return via r8\n");
83 #endif
84 pCppReturn = (void *)r8;
86 pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
87 ? alloca( pReturnTypeDescr->nSize )
88 : pCppReturn); // direct way
91 // pop this
92 gpreg++;
93 fpreg++;
94 nregs++;
96 // stack space
97 static_assert(sizeof(void *) == sizeof(sal_Int32), "### 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
102 // cpp<=>uno)
103 sal_Int32 * pTempIndices = (sal_Int32 *)(pUnoArgs + (2 * nParams));
104 // type descriptions for reconversions
105 typelib_TypeDescription ** ppTempParamTypeDescr =
106 (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
108 sal_Int32 nTempIndices = 0;
109 bool bOverflowUsed = false;
110 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
112 const typelib_MethodParameter & rParam = pParams[nPos];
113 typelib_TypeDescription * pParamTypeDescr = 0;
114 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
116 if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
118 switch (pParamTypeDescr->eTypeClass)
120 case typelib_TypeClass_DOUBLE:
121 if (nregs < hppa::MAX_WORDS_IN_REGS && (nregs & 1))
123 gpreg++;
124 fpreg++;
125 nregs++;
127 if (nregs < hppa::MAX_WORDS_IN_REGS-1)
129 fpreg++;
130 pCppArgs[nPos] = pUnoArgs[nPos] = fpreg;
131 gpreg+=2;
132 fpreg+=2;
133 nregs+=2;
135 else
137 if ((startovrflw-ovrflw) & 1)
138 ovrflw--;
139 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw - 4);
140 bOverflowUsed = true;
142 if (bOverflowUsed) ovrflw-=2;
143 break;
144 case typelib_TypeClass_FLOAT:
145 if (nregs < hppa::MAX_WORDS_IN_REGS)
147 pCppArgs[nPos] = pUnoArgs[nPos] = fpreg;
148 gpreg++;
149 fpreg++;
150 nregs++;
152 else
154 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
155 bOverflowUsed = true;
157 if (bOverflowUsed) ovrflw--;
158 break;
159 case typelib_TypeClass_HYPER:
160 case typelib_TypeClass_UNSIGNED_HYPER:
161 if (nregs < hppa::MAX_WORDS_IN_REGS && (nregs & 1))
163 gpreg++;
164 fpreg++;
165 nregs++;
167 if (nregs < hppa::MAX_WORDS_IN_REGS-1)
169 pCppArgs[nPos] = pUnoArgs[nPos] = gpreg;
170 gpreg+=2;
171 fpreg+=2;
172 nregs+=2;
174 else
176 if ((startovrflw-ovrflw) & 1)
177 ovrflw--;
178 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw - 4);
179 bOverflowUsed = true;
181 if (bOverflowUsed) ovrflw-=2;
182 break;
183 case typelib_TypeClass_BYTE:
184 case typelib_TypeClass_BOOLEAN:
185 if (nregs < hppa::MAX_WORDS_IN_REGS)
187 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)gpreg + 3);
188 gpreg++;
189 fpreg++;
190 nregs++;
192 else
194 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw+3);
195 bOverflowUsed = true;
197 if (bOverflowUsed) ovrflw--;
198 break;
199 case typelib_TypeClass_CHAR:
200 case typelib_TypeClass_SHORT:
201 case typelib_TypeClass_UNSIGNED_SHORT:
202 if (nregs < hppa::MAX_WORDS_IN_REGS)
204 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)gpreg+2);
205 gpreg++;
206 fpreg++;
207 nregs++;
209 else
211 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw+2);
212 bOverflowUsed = true;
214 if (bOverflowUsed) ovrflw--;
215 break;
216 case typelib_TypeClass_ENUM:
217 case typelib_TypeClass_LONG:
218 case typelib_TypeClass_UNSIGNED_LONG:
219 default:
220 if (nregs < hppa::MAX_WORDS_IN_REGS)
222 pCppArgs[nPos] = pUnoArgs[nPos] = gpreg;
223 gpreg++;
224 fpreg++;
225 nregs++;
227 else
229 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
230 bOverflowUsed = true;
232 if (bOverflowUsed) ovrflw--;
233 break;
235 // no longer needed
236 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
238 else // ptr to complex value | ref
240 void *pCppStack;
242 if (nregs < hppa::MAX_WORDS_IN_REGS)
244 pCppArgs[nPos] = pCppStack = *gpreg;
245 gpreg++;
246 fpreg++;
247 nregs++;
249 else
251 pCppArgs[nPos] = pCppStack = *ovrflw;
252 bOverflowUsed = true;
254 if (bOverflowUsed) ovrflw--;
256 if (! rParam.bIn) // is pure out
258 // uno out is unconstructed mem!
259 pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
260 pTempIndices[nTempIndices] = nPos;
261 // will be released at reconversion
262 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
264 // is in/inout
265 else if (bridges::cpp_uno::shared::relatesToInterfaceType(
266 pParamTypeDescr ))
268 uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
269 pCppStack, pParamTypeDescr,
270 pThis->getBridge()->getCpp2Uno() );
271 pTempIndices[nTempIndices] = nPos; // has to be reconverted
272 // will be released at reconversion
273 ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
275 else // direct way
277 pUnoArgs[nPos] = pCppStack;
278 // no longer needed
279 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
284 // ExceptionHolder
285 uno_Any aUnoExc; // Any will be constructed by callee
286 uno_Any * pUnoExc = &aUnoExc;
288 #if OSL_DEBUG_LEVEL > 2
289 fprintf(stderr, "before dispatch\n");
290 #endif
291 // invoke uno dispatch call
292 (*pThis->getUnoI()->pDispatcher)(
293 pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
295 #if OSL_DEBUG_LEVEL > 2
296 fprintf(stderr, "after dispatch\n");
297 #endif
299 // in case an exception occurred...
300 if (pUnoExc)
302 // destruct temporary in/inout params
303 for ( ; nTempIndices--; )
305 sal_Int32 nIndex = pTempIndices[nTempIndices];
307 if (pParams[nIndex].bIn) // is in/inout => was constructed
308 uno_destructData( pUnoArgs[nIndex],
309 ppTempParamTypeDescr[nTempIndices], 0 );
310 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
312 if (pReturnTypeDescr)
313 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
315 CPPU_CURRENT_NAMESPACE::raiseException( &aUnoExc,
316 pThis->getBridge()->getUno2Cpp() ); // has to destruct the any
317 // is here for dummy
318 return typelib_TypeClass_VOID;
320 else // else no exception occurred...
322 // temporary params
323 for ( ; nTempIndices--; )
325 sal_Int32 nIndex = pTempIndices[nTempIndices];
326 typelib_TypeDescription * pParamTypeDescr =
327 ppTempParamTypeDescr[nTempIndices];
329 if (pParams[nIndex].bOut) // inout/out
331 // convert and assign
332 uno_destructData( pCppArgs[nIndex], pParamTypeDescr,
333 cpp_release );
334 uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex],
335 pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
337 // destroy temp uno param
338 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
340 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
342 // return
343 if (pCppReturn) // has complex return
345 if (pUnoReturn != pCppReturn) // needs reconversion
347 uno_copyAndConvertData( pCppReturn, pUnoReturn,
348 pReturnTypeDescr, pThis->getBridge()->getUno2Cpp() );
349 // destroy temp uno return
350 uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
352 // complex return ptr is set to eax
353 *(void **)pRegisterReturn = pCppReturn;
355 if (pReturnTypeDescr)
357 typelib_TypeClass eRet =
358 (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
359 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
360 return eRet;
362 else
363 return typelib_TypeClass_VOID;
368 static typelib_TypeClass cpp_mediate(
369 sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
370 void ** gpreg, double* fpreg,
371 long sp, long r8,
372 sal_Int64 * pRegisterReturn /* space for register return */ )
375 void ** ovrflw = (void**)(sp);
376 #if OSL_DEBUG_LEVEL > 2
377 fprintf(stderr, "cpp_mediate with\n");
378 fprintf(stderr, "%x %x\n", nFunctionIndex, nVtableOffset);
379 fprintf(stderr, "and %x %x\n", (long)(ovrflw[0]), (long)(ovrflw[-1]));
380 fprintf(stderr, "and %x %x\n", (long)(ovrflw[-2]), (long)(ovrflw[-3]));
381 fprintf(stderr, "and %x %x\n", (long)(ovrflw[-4]), (long)(ovrflw[-5]));
382 fprintf(stderr, "and %x %x\n", (long)(ovrflw[-6]), (long)(ovrflw[-7]));
383 fprintf(stderr, "and %x %x\n", (long)(ovrflw[-8]), (long)(ovrflw[-9]));
384 fprintf(stderr, "and %x %x\n", (long)(ovrflw[-10]), (long)(ovrflw[-11]));
385 fprintf(stderr, "and %x %x\n", (long)(ovrflw[-12]), (long)(ovrflw[-13]));
386 fprintf(stderr, "and %x %x\n", (long)(ovrflw[-14]), (long)(ovrflw[-15]));
387 #endif
388 static_assert(sizeof(sal_Int32)==sizeof(void *), "### unexpected!");
390 // gpreg: [ret *], this, [other gpr params]
391 // fpreg: [fpr params]
392 // ovrflw: [gpr or fpr params (properly aligned)]
394 void * pThis;
395 if (nFunctionIndex & 0x80000000 )
397 nFunctionIndex &= 0x7fffffff;
398 pThis = gpreg[1];
399 #if OSL_DEBUG_LEVEL > 2
400 fprintf(stderr, "pThis is gpreg[1]\n");
401 #endif
403 else
405 pThis = gpreg[0];
406 #if OSL_DEBUG_LEVEL > 2
407 fprintf(stderr, "pThis is gpreg[0]\n");
408 #endif
411 pThis = static_cast< char * >(pThis) - nVtableOffset;
413 bridges::cpp_uno::shared::CppInterfaceProxy * pCppI =
414 bridges::cpp_uno::shared::CppInterfaceProxy::castInterfaceToProxy(
415 pThis);
417 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
419 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
421 SAL_WARN(
422 "bridges",
423 "illegal " << OUString::unacquired(&pTypeDescr->aBase.pTypeName)
424 << " vtable index " << nFunctionIndex << "/"
425 << pTypeDescr->nMapFunctionIndexToMemberIndex);
426 throw RuntimeException(
427 ("illegal " + OUString::unacquired(&pTypeDescr->aBase.pTypeName)
428 + " vtable index " + OUString::number(nFunctionIndex) + "/"
429 + OUString::number(pTypeDescr->nMapFunctionIndexToMemberIndex)),
430 (XInterface *)pCppI);
433 // determine called method
434 assert(nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex);
435 sal_Int32 nMemberPos =
436 pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
437 assert(nMemberPos < pTypeDescr->nAllMembers);
439 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
441 typelib_TypeClass eRet;
442 switch (aMemberDescr.get()->eTypeClass)
444 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
446 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] ==
447 nFunctionIndex)
449 // is GET method
450 eRet = cpp2uno_call(
451 pCppI, aMemberDescr.get(),
452 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
453 0, 0, // no params
454 r8, gpreg, fpreg, ovrflw, pRegisterReturn );
456 else
458 // is SET method
459 typelib_MethodParameter aParam;
460 aParam.pTypeRef =
461 ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
462 aParam.bIn = sal_True;
463 aParam.bOut = sal_False;
465 eRet = cpp2uno_call(
466 pCppI, aMemberDescr.get(),
467 0, // indicates void return
468 1, &aParam,
469 r8, gpreg, fpreg, ovrflw, pRegisterReturn );
471 break;
473 case typelib_TypeClass_INTERFACE_METHOD:
475 // is METHOD
476 switch (nFunctionIndex)
478 case 1: // acquire()
479 pCppI->acquireProxy(); // non virtual call!
480 eRet = typelib_TypeClass_VOID;
481 break;
482 case 2: // release()
483 pCppI->releaseProxy(); // non virtual call!
484 eRet = typelib_TypeClass_VOID;
485 break;
486 case 0: // queryInterface() opt
488 typelib_TypeDescription * pTD = 0;
489 TYPELIB_DANGER_GET(&pTD,
490 reinterpret_cast<Type *>(gpreg[1])->getTypeLibType());
491 if (pTD)
493 XInterface * pInterface = 0;
494 (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
495 pCppI->getBridge()->getCppEnv(),
496 (void **)&pInterface, pCppI->getOid().pData,
497 (typelib_InterfaceTypeDescription *)pTD );
499 if (pInterface)
501 ::uno_any_construct(
502 reinterpret_cast< uno_Any * >( r8 ),
503 &pInterface, pTD, cpp_acquire );
504 pInterface->release();
505 TYPELIB_DANGER_RELEASE( pTD );
506 *(void **)pRegisterReturn = (void*)r8;
507 eRet = typelib_TypeClass_ANY;
508 break;
510 TYPELIB_DANGER_RELEASE( pTD );
512 } // else perform queryInterface()
513 default:
514 eRet = cpp2uno_call(
515 pCppI, aMemberDescr.get(),
516 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
517 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
518 ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
519 r8, gpreg, fpreg, ovrflw, pRegisterReturn );
521 break;
523 default:
525 throw RuntimeException( "no member description found!", (XInterface *)pCppI );
529 return eRet;
534 * is called on incoming vtable calls
535 * (called by asm snippets)
538 sal_Int64 cpp_vtable_call( sal_uInt32 in0, sal_uInt32 in1, sal_uInt32 in2, sal_uInt32 in3, sal_uInt32 firstonstack )
540 register sal_Int32 r21 asm("r21");
541 register sal_Int32 r22 asm("r22");
542 register sal_Int32 r28 asm("r28");
543 sal_Int32 functionIndex = r21;
544 sal_Int32 vtableOffset = r22;
545 sal_Int32 r8 = r28;
547 long sp = (long)&firstonstack;
549 sal_uInt32 gpreg[hppa::MAX_GPR_REGS];
550 gpreg[0] = in0;
551 gpreg[1] = in1;
552 gpreg[2] = in2;
553 gpreg[3] = in3;
555 float fpreg[hppa::MAX_SSE_REGS]; //todo
556 register float f0 asm("fr4"); fpreg[0] = f0;
557 register float f1 asm("fr5"); fpreg[1] = f1;
558 register float f2 asm("fr6"); fpreg[2] = f2;
559 register float f3 asm("fr7"); fpreg[3] = f3;
561 double dpreg[hppa::MAX_SSE_REGS]; //todo
562 register double d0 asm("fr4"); dpreg[0] = d0;
563 register double d1 asm("fr5"); dpreg[1] = d1;
564 register double d2 asm("fr6"); dpreg[2] = d2;
565 register double d3 asm("fr7"); dpreg[3] = d3;
568 #if OSL_DEBUG_LEVEL > 2
569 fprintf(stderr, "got to cpp_vtable_call with %x %x\n", functionIndex, vtableOffset);
570 for (int i = 0; i < hppa::MAX_GPR_REGS; ++i)
571 fprintf(stderr, "reg %d is %d %x\n", i, gpreg[i], gpreg[i]);
572 for (int i = 0; i < hppa::MAX_SSE_REGS; ++i)
573 fprintf(stderr, "float reg %d is %f %x\n", i, fpreg[i], ((long*)fpreg)[i]);
574 for (int i = 0; i < 4; ++i)
575 fprintf(stderr, "double reg %d is %f %llx\n", i, dpreg[i], ((long long*)dpreg)[i]);
576 #endif
578 sal_Int64 nRegReturn;
580 typelib_TypeClass aType =
581 cpp_mediate( functionIndex, vtableOffset, (void**)gpreg, dpreg, sp, r8, &nRegReturn);
583 switch( aType )
585 case typelib_TypeClass_FLOAT:
586 f0 = (*((float*)&nRegReturn));
587 break;
588 case typelib_TypeClass_DOUBLE:
589 d0 = (*((double*)&nRegReturn));
590 break;
591 default:
592 break;
595 return nRegReturn;
599 namespace
601 const int codeSnippetSize = 44;
603 # define unldil(v) (((v & 0x7c) << 14) | ((v & 0x180) << 7) | ((v & 0x3) << 12) | ((v & 0xffe00) >> 8) | ((v & 0x100000) >> 20))
604 # define L21(v) unldil(((unsigned long)(v) >> 11) & 0x1fffff) //Left 21 bits
605 # define R11(v) (((unsigned long)(v) & 0x7FF) << 1) //Right 11 bits
607 unsigned char *codeSnippet(unsigned char* code, sal_Int32 functionIndex,
608 sal_Int32 vtableOffset, bool bHasHiddenParam)
610 if (bHasHiddenParam)
611 functionIndex |= 0x80000000;
613 unsigned char * p = code;
614 *(unsigned long*)&p[0] = 0xeaa00000; // b,l 0x8,r21
615 *(unsigned long*)&p[4] = 0xd6a01c1e; // depwi 0,31,2,r21
616 *(unsigned long*)&p[8] = 0x4aa10040; // ldw 32(r21),r1
618 *(unsigned long*)&p[12] = 0x22A00000 | L21(functionIndex); // ldil L<functionIndex>,r21
619 *(unsigned long*)&p[16] = 0x36B50000 | R11(functionIndex); // ldo R<functionIndex>,r21
621 *(unsigned long*)&p[20] = 0x22C00000 | L21(vtableOffset); // ldil L<vtableOffset>,r22
622 *(unsigned long*)&p[24] = 0x36D60000 | R11(vtableOffset); // ldo R<vtableOffset>,r22
624 *(unsigned long*)&p[28] = 0x0c201094; // ldw 0(r1),r20
625 *(unsigned long*)&p[32] = 0xea80c000; // bv r0(r20)
626 *(unsigned long*)&p[36] = 0x0c281093; // ldw 4(r1),r19
627 *(unsigned long*)&p[40] = ((unsigned long)(cpp_vtable_call) & ~2);
629 return code + codeSnippetSize;
633 struct bridges::cpp_uno::shared::VtableFactory::Slot { void const * fn; };
635 bridges::cpp_uno::shared::VtableFactory::Slot *
636 bridges::cpp_uno::shared::VtableFactory::mapBlockToVtable(void * block)
638 return static_cast< Slot * >(block) + 2;
641 std::size_t bridges::cpp_uno::shared::VtableFactory::getBlockSize(
642 sal_Int32 slotCount)
644 return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
647 namespace {
648 // Some dummy type whose RTTI is used in the synthesized proxy vtables to make uses of dynamic_cast
649 // on such proxy objects not crash:
650 struct ProxyRtti {};
653 bridges::cpp_uno::shared::VtableFactory::Slot *
654 bridges::cpp_uno::shared::VtableFactory::initializeBlock(
655 void * block, sal_Int32 slotCount, sal_Int32,
656 typelib_InterfaceTypeDescription *)
658 Slot * slots = mapBlockToVtable(block);
659 slots[-2].fn = 0;
660 slots[-1].fn = &typeid(ProxyRtti);
661 return slots + slotCount;
664 unsigned char * bridges::cpp_uno::shared::VtableFactory::addLocalFunctions(
665 Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
666 typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
667 sal_Int32 functionCount, sal_Int32 vtableOffset)
669 (*slots) -= functionCount;
670 Slot * s = *slots;
671 for (sal_Int32 i = 0; i < type->nMembers; ++i)
673 typelib_TypeDescription * member = 0;
674 TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
675 assert(member != 0);
676 switch (member->eTypeClass)
678 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
679 // Getter:
680 (s++)->fn = code + writetoexecdiff;
681 code = codeSnippet(code, functionOffset++, vtableOffset, false);
682 // Setter:
683 if (!reinterpret_cast<
684 typelib_InterfaceAttributeTypeDescription * >(
685 member)->bReadOnly)
687 (s++)->fn = code + writetoexecdiff;
688 code = codeSnippet(code, functionOffset++, vtableOffset, false);
690 break;
691 case typelib_TypeClass_INTERFACE_METHOD:
693 (s++)->fn = code + writetoexecdiff;
694 code = codeSnippet(code, functionOffset++, vtableOffset, false);
695 break;
697 default:
698 assert(false);
699 break;
701 TYPELIB_DANGER_RELEASE(member);
703 return code;
706 void bridges::cpp_uno::shared::VtableFactory::flushCode(
707 unsigned char const *beg, unsigned char const *end)
709 void *p = (void*)((size_t)beg & ~31);
710 size_t stride = 32;
711 while (p < end)
713 asm volatile("fdc (%0)\n\t"
714 "sync\n\t"
715 "fic,m %1(%%sr4, %0)\n\t"
716 "sync" : "+r"(p) : "r"(stride) : "memory");
720 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */