LibreOffice Module bridges (master) 1
gcc3_linux_powerpc64/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
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"
30
31#include "share.hxx"
32#include <stdio.h>
33#include <string.h>
34#include <typeinfo>
35
36#ifdef OSL_BIGENDIAN
37#define IS_BIG_ENDIAN 1
38#else
39#define IS_BIG_ENDIAN 0
40#endif
41
42using namespace ::com::sun::star::uno;
43
44namespace
45{
46
47
48static typelib_TypeClass cpp2uno_call(
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 */ )
55{
56#if OSL_DEBUG_LEVEL > 2
57 fprintf(stderr, "as far as cpp2uno_call\n");
58#endif
59
60 int ng = 0; //number of gpr registers used
61 int nf = 0; //number of fpr registers used
62
63 // gpreg: [ret *], this, [gpr params]
64 // fpreg: [fpr params]
65 // ovrflw: [gpr or fpr params (properly aligned)]
66
67 // return
68 typelib_TypeDescription * pReturnTypeDescr = 0;
69 if (pReturnTypeRef)
70 TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
71
72 void * pUnoReturn = 0;
73 void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
74
75 if (pReturnTypeDescr)
76 {
77 if (!ppc64::return_in_hidden_param(pReturnTypeRef))
78 {
79 pUnoReturn = pRegisterReturn; // direct way for simple types
80 }
81 else // complex return via ptr (pCppReturn)
82 {
83 pCppReturn = *(void **)gpreg;
84 gpreg++;
85 ng++;
86
87 pUnoReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
88 ? alloca( pReturnTypeDescr->nSize )
89 : pCppReturn); // direct way
90 }
91 }
92 // pop this
93 gpreg++;
94 ng++;
95
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));
105
106 sal_Int32 nTempIndices = 0;
107 bool bOverflowUsed = false;
108 for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
109 {
110 const typelib_MethodParameter & rParam = pParams[nPos];
111 typelib_TypeDescription * pParamTypeDescr = 0;
112 TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
113
114#if OSL_DEBUG_LEVEL > 2
115 fprintf(stderr, "arg %d of %d\n", nPos, nParams);
116#endif
117
118 if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
119 {
120#if OSL_DEBUG_LEVEL > 2
121 fprintf(stderr, "simple\n");
122#endif
123
124 switch (pParamTypeDescr->eTypeClass)
125 {
126 case typelib_TypeClass_FLOAT:
127 case typelib_TypeClass_DOUBLE:
128 if (nf < ppc64::MAX_SSE_REGS)
129 {
130 if (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT)
131 {
132 float tmp = (float) (*((double *)fpreg));
133 (*((float *) fpreg)) = tmp;
134 }
135 pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
136 nf++;
137
138 if (ng < ppc64::MAX_GPR_REGS)
139 {
140 ng++;
141 gpreg++;
142 }
143 }
144 else
145 {
146 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
147 bOverflowUsed = true;
148 }
149 if (bOverflowUsed) ovrflw++;
150 break;
151 case typelib_TypeClass_BYTE:
152 case typelib_TypeClass_BOOLEAN:
153 if (ng < ppc64::MAX_GPR_REGS)
154 {
155 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 7*IS_BIG_ENDIAN);
156 ng++;
157 gpreg++;
158 }
159 else
160 {
161 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 7*IS_BIG_ENDIAN);
162 bOverflowUsed = true;
163 }
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)
170 {
171 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 6*IS_BIG_ENDIAN);
172 ng++;
173 gpreg++;
174 }
175 else
176 {
177 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 6*IS_BIG_ENDIAN);
178 bOverflowUsed = true;
179 }
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)
186 {
187 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 4*IS_BIG_ENDIAN);
188 ng++;
189 gpreg++;
190 }
191 else
192 {
193 pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 4*IS_BIG_ENDIAN);
194 bOverflowUsed = true;
195 }
196 if (bOverflowUsed) ovrflw++;
197 break;
198 default:
199 if (ng < ppc64::MAX_GPR_REGS)
200 {
201 pCppArgs[nPos] = pUnoArgs[nPos] = gpreg++;
202 ng++;
203 }
204 else
205 {
206 pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
207 bOverflowUsed = true;
208 }
209 if (bOverflowUsed) ovrflw++;
210 break;
211 }
212
213 // no longer needed
214 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
215 }
216 else // ptr to complex value | ref
217 {
218#if OSL_DEBUG_LEVEL > 2
219 fprintf(stderr, "complex, ng is %d\n", ng);
220#endif
221 void *pCppStack; //temporary stack pointer
222
223 if (ng < ppc64::MAX_GPR_REGS)
224 {
225 pCppArgs[nPos] = pCppStack = *gpreg++;
226 ng++;
227 }
228 else
229 {
230 pCppArgs[nPos] = pCppStack = *ovrflw;
231 bOverflowUsed = true;
232 }
233 if (bOverflowUsed) ovrflw++;
234
235 if (! rParam.bIn) // is pure out
236 {
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;
242 }
243 // is in/inout
244 else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
245 {
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;
252 }
253 else // direct way
254 {
255 pUnoArgs[nPos] = pCppStack;
256 // no longer needed
257 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
258 }
259 }
260 }
261
262#if OSL_DEBUG_LEVEL > 2
263 fprintf(stderr, "end of params\n");
264#endif
265
266 // ExceptionHolder
267 uno_Any aUnoExc; // Any will be constructed by callee
268 uno_Any * pUnoExc = &aUnoExc;
269
270 // invoke uno dispatch call
271 (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
272
273 // in case an exception occurred...
274 if (pUnoExc)
275 {
276 // destruct temporary in/inout params
277 for ( ; nTempIndices--; )
278 {
279 sal_Int32 nIndex = pTempIndices[nTempIndices];
280
281 if (pParams[nIndex].bIn) // is in/inout => was constructed
282 uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndices], 0 );
283 TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
284 }
285 if (pReturnTypeDescr)
286 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
287
289 // has to destruct the any
290 // is here for dummy
291 return typelib_TypeClass_VOID;
292 }
293 else // else no exception occurred...
294 {
295 // temporary params
296 for ( ; nTempIndices--; )
297 {
298 sal_Int32 nIndex = pTempIndices[nTempIndices];
299 typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
300
301 if (pParams[nIndex].bOut) // inout/out
302 {
303 // convert and assign
304 uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
305 uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
306 pThis->getBridge()->getUno2Cpp() );
307 }
308 // destroy temp uno param
309 uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
310
311 TYPELIB_DANGER_RELEASE( pParamTypeDescr );
312 }
313 // return
314 if (pCppReturn) // has complex return
315 {
316 if (pUnoReturn != pCppReturn) // needs reconversion
317 {
318 uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
319 pThis->getBridge()->getUno2Cpp() );
320 // destroy temp uno return
321 uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
322 }
323 // complex return ptr is set to return reg
324 *(void **)pRegisterReturn = pCppReturn;
325 }
326 if (pReturnTypeDescr)
327 {
328 typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
329 TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
330 return eRet;
331 }
332 else
333 return typelib_TypeClass_VOID;
334 }
335}
336
337#if defined(_CALL_ELF) && _CALL_ELF == 2
338# define PARAMSAVE 32
339#else
340# define PARAMSAVE 48
341#endif
342
343static typelib_TypeClass cpp_mediate(
344 sal_uInt64 nOffsetAndIndex,
345 void ** gpreg, void ** fpreg, long sp,
346 sal_Int64 * pRegisterReturn /* space for register return */ )
347{
348 static_assert(sizeof(sal_Int64)==sizeof(void *), "### unexpected!");
349
350 sal_Int32 nVtableOffset = (nOffsetAndIndex >> 32);
351 sal_Int32 nFunctionIndex = (nOffsetAndIndex & 0xFFFFFFFF);
352
353 long sf = *(long*)sp;
354 void ** ovrflw = (void**)(sf + PARAMSAVE + 64);
355
356 // gpreg: [ret *], this, [other gpr params]
357 // fpreg: [fpr params]
358 // ovrflw: [gpr or fpr params (properly aligned)]
359
360 void * pThis;
361 if (nFunctionIndex & 0x80000000 )
362 {
363 nFunctionIndex &= 0x7fffffff;
364 pThis = gpreg[1];
365#if OSL_DEBUG_LEVEL > 2
366 fprintf(stderr, "pThis is gpreg[1]\n");
367#endif
368 }
369 else
370 {
371 pThis = gpreg[0];
372#if OSL_DEBUG_LEVEL > 2
373 fprintf(stderr, "pThis is gpreg[0]\n");
374#endif
375 }
376
377#if OSL_DEBUG_LEVEL > 2
378 fprintf(stderr, "pThis is %lx\n", pThis);
379#endif
380
381 pThis = static_cast< char * >(pThis) - nVtableOffset;
382
383#if OSL_DEBUG_LEVEL > 2
384 fprintf(stderr, "pThis is now %lx\n", pThis);
385#endif
386
389 pThis);
390
391 typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
392
393#if OSL_DEBUG_LEVEL > 2
394 fprintf(stderr, "indexes are %d %d\n", nFunctionIndex, pTypeDescr->nMapFunctionIndexToMemberIndex);
395#endif
396
397 if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
398 {
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);
409 }
410
411 // determine called method
412 sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
413 assert(nMemberPos < pTypeDescr->nAllMembers);
414
415#if OSL_DEBUG_LEVEL > 2
416 fprintf(stderr, "members are %d %d\n", nMemberPos, pTypeDescr->nAllMembers);
417#endif
418
419 TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
420
421 typelib_TypeClass eRet;
422 switch (aMemberDescr.get()->eTypeClass)
423 {
424 case typelib_TypeClass_INTERFACE_ATTRIBUTE:
425 {
426 if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
427 {
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 );
434 }
435 else
436 {
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;
443
444 eRet = cpp2uno_call(
445 pCppI, aMemberDescr.get(),
446 0, // indicates void return
447 1, &aParam,
448 gpreg, fpreg, ovrflw, pRegisterReturn );
449 }
450 break;
451 }
452 case typelib_TypeClass_INTERFACE_METHOD:
453 {
454 // is METHOD
455 switch (nFunctionIndex)
456 {
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
466 {
467 typelib_TypeDescription * pTD = 0;
468 TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
469 if (pTD)
470 {
471 XInterface * pInterface = 0;
472 (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
473 pCppI->getBridge()->getCppEnv(),
474 (void **)&pInterface, pCppI->getOid().pData,
475 (typelib_InterfaceTypeDescription *)pTD );
476
477 if (pInterface)
478 {
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;
487 }
488 TYPELIB_DANGER_RELEASE( pTD );
489 }
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 );
498 }
499 break;
500 }
501 default:
502 {
503#if OSL_DEBUG_LEVEL > 2
504 fprintf(stderr, "screwed\n");
505#endif
506
507 throw RuntimeException( "no member description found!", (XInterface *)pThis );
508 }
509 }
510
511#if OSL_DEBUG_LEVEL > 2
512 fprintf(stderr, "end of cpp_mediate\n");
513#endif
514 return eRet;
515}
516
517extern "C" void privateSnippetExecutor( ... )
518{
519 sal_uInt64 gpreg[ppc64::MAX_GPR_REGS];
520
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;
529
530 double fpreg[ppc64::MAX_SSE_REGS];
531
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"
549 );
550
551 register long r11 asm("r11");
552 const long nOffsetAndIndex = r11;
553
554 register long r1 asm("r1");
555 const long sp = r1;
556
557#if defined(_CALL_ELF) && _CALL_ELF == 2
558 volatile long nRegReturn[2];
559#else
560 volatile long nRegReturn[1];
561#endif
562
563 typelib_TypeClass aType =
564 cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, sp, (sal_Int64*)nRegReturn);
565
566 switch( aType )
567 {
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;
609 }
610}
611
612#if defined(_CALL_ELF) && _CALL_ELF == 2
613const int codeSnippetSize = 32;
614#else
615const int codeSnippetSize = 24;
616#endif
617
618unsigned char * codeSnippet( unsigned char * code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
619 bool bHasHiddenParam)
620{
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
625
626 sal_uInt64 nOffsetAndIndex = ( ( (sal_uInt64) nVtableOffset ) << 32 ) | ( (sal_uInt64) nFunctionIndex );
627
628 if ( bHasHiddenParam )
629 nOffsetAndIndex |= 0x80000000;
630#if defined(_CALL_ELF) && _CALL_ELF == 2
631 unsigned int *raw = (unsigned int *)&code[0];
632
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);
651}
652
653}
654
655void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const * bptr, unsigned char const * eptr)
656{
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");
660 }
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");
664 }
665 __asm__ volatile ("isync" : : : "memory");
666}
667
669
672{
673 return static_cast< Slot * >(block) + 2;
674}
675
677 sal_Int32 slotCount)
678{
679 return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
680}
681
682namespace {
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:
685struct ProxyRtti {};
686}
687
690 void * block, sal_Int32 slotCount, sal_Int32,
691 typelib_InterfaceTypeDescription *)
692{
693 Slot * slots = mapBlockToVtable(block);
694 slots[-2].fn = 0;
695 slots[-1].fn = &typeid(ProxyRtti);
696 return slots + slotCount;
697}
698
700 Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
701 typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
702 sal_Int32 functionCount, sal_Int32 vtableOffset)
703{
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
710
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;
720 code, functionOffset++, vtableOffset,
722 reinterpret_cast<
723 typelib_InterfaceAttributeTypeDescription * >(
724 member)->pAttributeTypeRef));
725
726 // Setter:
727 if (!reinterpret_cast<
728 typelib_InterfaceAttributeTypeDescription * >(
729 member)->bReadOnly)
730 {
731 (s++)->fn = code + writetoexecdiff;
732 code = codeSnippet(code, functionOffset++, vtableOffset, false);
733 }
734 break;
735
736 case typelib_TypeClass_INTERFACE_METHOD:
737 (s++)->fn = code + writetoexecdiff;
739 code, functionOffset++, vtableOffset,
741 reinterpret_cast<
742 typelib_InterfaceMethodTypeDescription * >(
743 member)->pReturnTypeRef));
744 break;
745
746 default:
747 assert(false);
748 break;
749 }
750 TYPELIB_DANGER_RELEASE(member);
751 }
752 return code;
753}
754
755/* 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()
register sal_uInt32 r28 __asm__("%r28")
void(* privateSnippetExecutor)()
#define IS_BIG_ENDIAN
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 return_in_hidden_param(typelib_TypeDescriptionReference *pTypeRef)
sal_Unicode code
#define sal_True
#define sal_False
ResultType type