LibreOffice Module bridges (master) 1
gcc3_linux_hppa/cpp2uno.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#include <malloc.h>
21#include <typeinfo>
22
23#include <rtl/alloc.h>
24
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>
30
31#include "bridge.hxx"
32#include "cppinterfaceproxy.hxx"
33#include "types.hxx"
34#include "vtablefactory.hxx"
35
36#include "share.hxx"
37
38#include <dlfcn.h>
39
40
41using namespace ::osl;
42using namespace ::com::sun::star::uno;
43
44namespace
45{
46
47 static typelib_TypeClass cpp2uno_call(
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 */ )
54 {
55 void ** startovrflw = ovrflw;
56 int nregs = 0; //number of words passed in registers
57
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 );
65
66 void * pUnoReturn = 0;
67 // complex return ptr: if != 0 && != pUnoReturn, reconversion need
68 void * pCppReturn = 0;
69
70 if (pReturnTypeDescr)
71 {
72 if (hppa::isRegisterReturn(pReturnTypeRef))
73 {
74#if OSL_DEBUG_LEVEL > 2
75 fprintf(stderr, "simple return\n");
76#endif
77 pUnoReturn = pRegisterReturn; // direct way for simple types
78 }
79 else
80 {
81#if OSL_DEBUG_LEVEL > 2
82 fprintf(stderr, "complex return via r8\n");
83#endif
84 pCppReturn = (void *)r8;
85
86 pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
87 ? alloca( pReturnTypeDescr->nSize )
88 : pCppReturn); // direct way
89 }
90 }
91 // pop this
92 gpreg++;
93 fpreg++;
94 nregs++;
95
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));
107
108 sal_Int32 nTempIndices = 0;
109 bool bOverflowUsed = false;
110 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
111 {
112 const typelib_MethodParameter & rParam = pParams[nPos];
113 typelib_TypeDescription * pParamTypeDescr = 0;
114 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
115
116 if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
117 {
118 switch (pParamTypeDescr->eTypeClass)
119 {
120 case typelib_TypeClass_DOUBLE:
121 if (nregs < hppa::MAX_WORDS_IN_REGS && (nregs & 1))
122 {
123 gpreg++;
124 fpreg++;
125 nregs++;
126 }
127 if (nregs < hppa::MAX_WORDS_IN_REGS-1)
128 {
129 fpreg++;
130 pCppArgs[nPos] = pUnoArgs[nPos] = fpreg;
131 gpreg+=2;
132 fpreg+=2;
133 nregs+=2;
134 }
135 else
136 {
137 if ((startovrflw-ovrflw) & 1)
138 ovrflw--;
139 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw - 4);
140 bOverflowUsed = true;
141 }
142 if (bOverflowUsed) ovrflw-=2;
143 break;
144 case typelib_TypeClass_FLOAT:
145 if (nregs < hppa::MAX_WORDS_IN_REGS)
146 {
147 pCppArgs[nPos] = pUnoArgs[nPos] = fpreg;
148 gpreg++;
149 fpreg++;
150 nregs++;
151 }
152 else
153 {
154 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
155 bOverflowUsed = true;
156 }
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))
162 {
163 gpreg++;
164 fpreg++;
165 nregs++;
166 }
167 if (nregs < hppa::MAX_WORDS_IN_REGS-1)
168 {
169 pCppArgs[nPos] = pUnoArgs[nPos] = gpreg;
170 gpreg+=2;
171 fpreg+=2;
172 nregs+=2;
173 }
174 else
175 {
176 if ((startovrflw-ovrflw) & 1)
177 ovrflw--;
178 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw - 4);
179 bOverflowUsed = true;
180 }
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)
186 {
187 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)gpreg + 3);
188 gpreg++;
189 fpreg++;
190 nregs++;
191 }
192 else
193 {
194 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw+3);
195 bOverflowUsed = true;
196 }
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)
203 {
204 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)gpreg+2);
205 gpreg++;
206 fpreg++;
207 nregs++;
208 }
209 else
210 {
211 pCppArgs[nPos] = pUnoArgs[nPos] = ((char*)ovrflw+2);
212 bOverflowUsed = true;
213 }
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)
221 {
222 pCppArgs[nPos] = pUnoArgs[nPos] = gpreg;
223 gpreg++;
224 fpreg++;
225 nregs++;
226 }
227 else
228 {
229 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
230 bOverflowUsed = true;
231 }
232 if (bOverflowUsed) ovrflw--;
233 break;
234 }
235 // no longer needed
236 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
237 }
238 else // ptr to complex value | ref
239 {
240 void *pCppStack;
241
242 if (nregs < hppa::MAX_WORDS_IN_REGS)
243 {
244 pCppArgs[nPos] = pCppStack = *gpreg;
245 gpreg++;
246 fpreg++;
247 nregs++;
248 }
249 else
250 {
251 pCppArgs[nPos] = pCppStack = *ovrflw;
252 bOverflowUsed = true;
253 }
254 if (bOverflowUsed) ovrflw--;
255
256 if (! rParam.bIn) // is pure out
257 {
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;
263 }
264 // is in/inout
266 pParamTypeDescr ))
267 {
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;
274 }
275 else // direct way
276 {
277 pUnoArgs[nPos] = pCppStack;
278 // no longer needed
279 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
280 }
281 }
282 }
283
284 // ExceptionHolder
285 uno_Any aUnoExc; // Any will be constructed by callee
286 uno_Any * pUnoExc = &aUnoExc;
287
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 );
294
295#if OSL_DEBUG_LEVEL > 2
296 fprintf(stderr, "after dispatch\n");
297#endif
298
299 // in case an exception occurred...
300 if (pUnoExc)
301 {
302 // destruct temporary in/inout params
303 for ( ; nTempIndices--; )
304 {
305 sal_Int32 nIndex = pTempIndices[nTempIndices];
306
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] );
311 }
312 if (pReturnTypeDescr)
313 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
314
316 pThis->getBridge()->getUno2Cpp() ); // has to destruct the any
317 // is here for dummy
318 return typelib_TypeClass_VOID;
319 }
320 else // else no exception occurred...
321 {
322 // temporary params
323 for ( ; nTempIndices--; )
324 {
325 sal_Int32 nIndex = pTempIndices[nTempIndices];
326 typelib_TypeDescription * pParamTypeDescr =
327 ppTempParamTypeDescr[nTempIndices];
328
329 if (pParams[nIndex].bOut) // inout/out
330 {
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() );
336 }
337 // destroy temp uno param
338 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
339
340 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
341 }
342 // return
343 if (pCppReturn) // has complex return
344 {
345 if (pUnoReturn != pCppReturn) // needs reconversion
346 {
347 uno_copyAndConvertData( pCppReturn, pUnoReturn,
348 pReturnTypeDescr, pThis->getBridge()->getUno2Cpp() );
349 // destroy temp uno return
350 uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
351 }
352 // complex return ptr is set to eax
353 *(void **)pRegisterReturn = pCppReturn;
354 }
355 if (pReturnTypeDescr)
356 {
357 typelib_TypeClass eRet =
358 (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
359 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
360 return eRet;
361 }
362 else
363 return typelib_TypeClass_VOID;
364 }
365 }
366
367
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 */ )
373
374 {
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!");
389
390 // gpreg: [ret *], this, [other gpr params]
391 // fpreg: [fpr params]
392 // ovrflw: [gpr or fpr params (properly aligned)]
393
394 void * pThis;
395 if (nFunctionIndex & 0x80000000 )
396 {
397 nFunctionIndex &= 0x7fffffff;
398 pThis = gpreg[1];
399#if OSL_DEBUG_LEVEL > 2
400 fprintf(stderr, "pThis is gpreg[1]\n");
401#endif
402 }
403 else
404 {
405 pThis = gpreg[0];
406#if OSL_DEBUG_LEVEL > 2
407 fprintf(stderr, "pThis is gpreg[0]\n");
408#endif
409 }
410
411 pThis = static_cast< char * >(pThis) - nVtableOffset;
412
415 pThis);
416
417 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
418
419 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
420 {
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);
431 }
432
433 // determine called method
434 assert(nFunctionIndex < pTypeDescr->nMapFunctionIndexToMemberIndex);
435 sal_Int32 nMemberPos =
436 pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
437 assert(nMemberPos < pTypeDescr->nAllMembers);
438
439 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
440
441 typelib_TypeClass eRet;
442 switch (aMemberDescr.get()->eTypeClass)
443 {
444 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
445 {
446 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] ==
447 nFunctionIndex)
448 {
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 );
455 }
456 else
457 {
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;
464
465 eRet = cpp2uno_call(
466 pCppI, aMemberDescr.get(),
467 0, // indicates void return
468 1, &aParam,
469 r8, gpreg, fpreg, ovrflw, pRegisterReturn );
470 }
471 break;
472 }
473 case typelib_TypeClass_INTERFACE_METHOD:
474 {
475 // is METHOD
476 switch (nFunctionIndex)
477 {
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
487 {
488 typelib_TypeDescription * pTD = 0;
489 TYPELIB_DANGER_GET(&pTD,
490 reinterpret_cast<Type *>(gpreg[1])->getTypeLibType());
491 if (pTD)
492 {
493 XInterface * pInterface = 0;
494 (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
495 pCppI->getBridge()->getCppEnv(),
496 (void **)&pInterface, pCppI->getOid().pData,
497 (typelib_InterfaceTypeDescription *)pTD );
498
499 if (pInterface)
500 {
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;
509 }
510 TYPELIB_DANGER_RELEASE( pTD );
511 }
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 );
520 }
521 break;
522 }
523 default:
524 {
525 throw RuntimeException( "no member description found!", (XInterface *)pCppI );
526 }
527 }
528
529 return eRet;
530 }
531}
532
538sal_Int64 cpp_vtable_call( sal_uInt32 in0, sal_uInt32 in1, sal_uInt32 in2, sal_uInt32 in3, sal_uInt32 firstonstack )
539{
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;
546
547 long sp = (long)&firstonstack;
548
549 sal_uInt32 gpreg[hppa::MAX_GPR_REGS];
550 gpreg[0] = in0;
551 gpreg[1] = in1;
552 gpreg[2] = in2;
553 gpreg[3] = in3;
554
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;
560
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;
566
567
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
577
578 sal_Int64 nRegReturn;
579
580 typelib_TypeClass aType =
581 cpp_mediate( functionIndex, vtableOffset, (void**)gpreg, dpreg, sp, r8, &nRegReturn);
582
583 switch( aType )
584 {
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;
593 }
594
595 return nRegReturn;
596}
597
598
599namespace
600{
601 const int codeSnippetSize = 44;
602
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
606
607 unsigned char *codeSnippet(unsigned char* code, sal_Int32 functionIndex,
608 sal_Int32 vtableOffset, bool bHasHiddenParam)
609 {
610 if (bHasHiddenParam)
611 functionIndex |= 0x80000000;
612
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
617
618 *(unsigned long*)&p[12] = 0x22A00000 | L21(functionIndex); // ldil L<functionIndex>,r21
619 *(unsigned long*)&p[16] = 0x36B50000 | R11(functionIndex); // ldo R<functionIndex>,r21
620
621 *(unsigned long*)&p[20] = 0x22C00000 | L21(vtableOffset); // ldil L<vtableOffset>,r22
622 *(unsigned long*)&p[24] = 0x36D60000 | R11(vtableOffset); // ldo R<vtableOffset>,r22
623
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);
628
629 return code + codeSnippetSize;
630 }
631}
632
634
637{
638 return static_cast< Slot * >(block) + 2;
639}
640
642 sal_Int32 slotCount)
643{
644 return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
645}
646
647namespace {
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:
650struct ProxyRtti {};
651}
652
655 void * block, sal_Int32 slotCount, sal_Int32,
656 typelib_InterfaceTypeDescription *)
657{
658 Slot * slots = mapBlockToVtable(block);
659 slots[-2].fn = 0;
660 slots[-1].fn = &typeid(ProxyRtti);
661 return slots + slotCount;
662}
663
665 Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
666 typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
667 sal_Int32 functionCount, sal_Int32 vtableOffset)
668{
669 (*slots) -= functionCount;
670 Slot * s = *slots;
671 for (sal_Int32 i = 0; i < type->nMembers; ++i)
672 {
673 typelib_TypeDescription * member = 0;
674 TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
675 assert(member != 0);
676 switch (member->eTypeClass)
677 {
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)
686 {
687 (s++)->fn = code + writetoexecdiff;
688 code = codeSnippet(code, functionOffset++, vtableOffset, false);
689 }
690 break;
691 case typelib_TypeClass_INTERFACE_METHOD:
692 {
693 (s++)->fn = code + writetoexecdiff;
694 code = codeSnippet(code, functionOffset++, vtableOffset, false);
695 break;
696 }
697 default:
698 assert(false);
699 break;
700 }
701 TYPELIB_DANGER_RELEASE(member);
702 }
703 return code;
704}
705
707 unsigned char const *beg, unsigned char const *end)
708{
709 void *p = (void*)((size_t)beg & ~31);
710 size_t stride = 32;
711 while (p < end)
712 {
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");
717 }
718}
719
720/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
uno_Mapping * getUno2Cpp()
Definition: bridge.hxx:73
uno_ExtEnvironment * getCppEnv()
Definition: bridge.hxx:69
uno_Mapping * getCpp2Uno()
Definition: bridge.hxx:72
A cpp proxy wrapping a uno interface.
static CppInterfaceProxy * castInterfaceToProxy(void *pInterface)
typelib_InterfaceTypeDescription * getTypeDescr()
static Slot * mapBlockToVtable(void *block)
Given a pointer to a block, turn it into a vtable pointer.
static void flushCode(unsigned char const *begin, unsigned char const *end)
Flush all the generated code snippets of a vtable, on platforms that require it.
static unsigned char * addLocalFunctions(Slot **slots, unsigned char *code, sal_PtrDiff writetoexecdiff, typelib_InterfaceTypeDescription const *type, sal_Int32 functionOffset, sal_Int32 functionCount, sal_Int32 vtableOffset)
Fill the vtable slots corresponding to all local (i.e., not inherited) functions of a given interface...
static Slot * initializeBlock(void *block, sal_Int32 slotCount, sal_Int32 vtableNumber, typelib_InterfaceTypeDescription *type)
Initialize a raw vtable block.
static std::size_t getBlockSize(sal_Int32 slotCount)
Calculate the size of a raw vtable block.
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
void SAL_CALL uno_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
#define L21(v)
sal_Int64 cpp_vtable_call(sal_uInt32 in0, sal_uInt32 in1, sal_uInt32 in2, sal_uInt32 in3, sal_uInt32 firstonstack)
is called on incoming vtable calls (called by asm snippets)
#define R11(v)
const int codeSnippetSize
static unsigned char * codeSnippet(unsigned char *code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset, bool bHasHiddenParam)
static int cpp2uno_call(bridges::cpp_uno::shared::CppInterfaceProxy *pThis, const typelib_TypeDescription *pMemberTypeDescr, typelib_TypeDescriptionReference *pReturnTypeRef, sal_Int32 nParams, typelib_MethodParameter *pParams, void **gpreg, void **fpreg, void **ovrflw, sal_uInt64 *pRegisterReturn)
sal_Int32 nIndex
void * p
sal_uInt16 nPos
#define SAL_WARN(area, stream)
struct _typelib_TypeDescription typelib_TypeDescription
Definition: msvc/except.hxx:53
struct _uno_Any uno_Any
Definition: msvc/except.hxx:32
typelib_TypeClass __cdecl cpp_mediate(void **pCallStack, const sal_Int32 nFunctionIndex, const sal_Int32 nVtableOffset, sal_Int64 *const pRegisterReturn)
void raiseException(uno_Any *pUnoExc, uno_Mapping *pUno2Cpp)
bool isSimpleType(typelib_TypeClass typeClass)
Determines whether a type is a "simple" type (VOID, BOOLEAN, BYTE, SHORT, UNSIGNED SHORT,...
Definition: types.cxx:28
bool relatesToInterfaceType(typelib_TypeDescription const *type)
Determines whether a type relates to an interface type (is itself an interface type,...
Definition: types.cxx:41
Type
int i
bool isRegisterReturn(typelib_TypeDescriptionReference *pTypeRef)
sal_Unicode code
#define sal_True
#define sal_False
ResultType type