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 
35 #ifdef OSL_BIGENDIAN
36 #define IS_BIG_ENDIAN 1
37 #else
38 #define IS_BIG_ENDIAN 0
39 #endif
40 
41 using namespace ::com::sun::star::uno;
42 
43 namespace
44 {
45 
46 
47 static typelib_TypeClass cpp2uno_call(
49  const typelib_TypeDescription * pMemberTypeDescr,
50  typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return
51  sal_Int32 nParams, typelib_MethodParameter * pParams,
52  void ** gpreg, void ** fpreg, void ** ovrflw,
53  sal_Int64 * pRegisterReturn /* space for register return */ )
54 {
55 #if OSL_DEBUG_LEVEL > 2
56  fprintf(stderr, "as far as cpp2uno_call\n");
57 #endif
58 
59  int ng = 0; //number of gpr registers used
60  int nf = 0; //number of fpr registers used
61 
62  // gpreg: [ret *], this, [gpr params]
63  // fpreg: [fpr params]
64  // ovrflw: [gpr or fpr params (properly aligned)]
65 
66  // return
67  typelib_TypeDescription * pReturnTypeDescr = 0;
68  if (pReturnTypeRef)
69  TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
70 
71  void * pUnoReturn = 0;
72  void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need
73 
74  if (pReturnTypeDescr)
75  {
76  if (!ppc64::return_in_hidden_param(pReturnTypeRef))
77  {
78  pUnoReturn = pRegisterReturn; // direct way for simple types
79  }
80  else // complex return via ptr (pCppReturn)
81  {
82  pCppReturn = *(void **)gpreg;
83  gpreg++;
84  ng++;
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  ng++;
94 
95  // stack space
96  static_assert(sizeof(void *) == sizeof(sal_Int64), "### unexpected size!");
97  // parameters
98  void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams );
99  void ** pCppArgs = pUnoArgs + nParams;
100  // indices of values this have to be converted (interface conversion cpp<=>uno)
101  sal_Int32 * pTempIndices = (sal_Int32 *)(pUnoArgs + (2 * nParams));
102  // type descriptions for reconversions
103  typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams));
104 
105  sal_Int32 nTempIndices = 0;
106  bool bOverflowUsed = false;
107  for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
108  {
109  const typelib_MethodParameter & rParam = pParams[nPos];
110  typelib_TypeDescription * pParamTypeDescr = 0;
111  TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
112 
113 #if OSL_DEBUG_LEVEL > 2
114  fprintf(stderr, "arg %d of %d\n", nPos, nParams);
115 #endif
116 
117  if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
118  {
119 #if OSL_DEBUG_LEVEL > 2
120  fprintf(stderr, "simple\n");
121 #endif
122 
123  switch (pParamTypeDescr->eTypeClass)
124  {
125  case typelib_TypeClass_FLOAT:
126  case typelib_TypeClass_DOUBLE:
127  if (nf < ppc64::MAX_SSE_REGS)
128  {
129  if (pParamTypeDescr->eTypeClass == typelib_TypeClass_FLOAT)
130  {
131  float tmp = (float) (*((double *)fpreg));
132  (*((float *) fpreg)) = tmp;
133  }
134  pCppArgs[nPos] = pUnoArgs[nPos] = fpreg++;
135  nf++;
136 
137  if (ng < ppc64::MAX_GPR_REGS)
138  {
139  ng++;
140  gpreg++;
141  }
142  }
143  else
144  {
145  pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
146  bOverflowUsed = true;
147  }
148  if (bOverflowUsed) ovrflw++;
149  break;
150  case typelib_TypeClass_BYTE:
151  case typelib_TypeClass_BOOLEAN:
152  if (ng < ppc64::MAX_GPR_REGS)
153  {
154  pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 7*IS_BIG_ENDIAN);
155  ng++;
156  gpreg++;
157  }
158  else
159  {
160  pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 7*IS_BIG_ENDIAN);
161  bOverflowUsed = true;
162  }
163  if (bOverflowUsed) ovrflw++;
164  break;
165  case typelib_TypeClass_CHAR:
166  case typelib_TypeClass_SHORT:
167  case typelib_TypeClass_UNSIGNED_SHORT:
168  if (ng < ppc64::MAX_GPR_REGS)
169  {
170  pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 6*IS_BIG_ENDIAN);
171  ng++;
172  gpreg++;
173  }
174  else
175  {
176  pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 6*IS_BIG_ENDIAN);
177  bOverflowUsed = true;
178  }
179  if (bOverflowUsed) ovrflw++;
180  break;
181  case typelib_TypeClass_ENUM:
182  case typelib_TypeClass_LONG:
183  case typelib_TypeClass_UNSIGNED_LONG:
184  if (ng < ppc64::MAX_GPR_REGS)
185  {
186  pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)gpreg) + 4*IS_BIG_ENDIAN);
187  ng++;
188  gpreg++;
189  }
190  else
191  {
192  pCppArgs[nPos] = pUnoArgs[nPos] = (((char *)ovrflw) + 4*IS_BIG_ENDIAN);
193  bOverflowUsed = true;
194  }
195  if (bOverflowUsed) ovrflw++;
196  break;
197  default:
198  if (ng < ppc64::MAX_GPR_REGS)
199  {
200  pCppArgs[nPos] = pUnoArgs[nPos] = gpreg++;
201  ng++;
202  }
203  else
204  {
205  pCppArgs[nPos] = pUnoArgs[nPos] = ovrflw;
206  bOverflowUsed = true;
207  }
208  if (bOverflowUsed) ovrflw++;
209  break;
210  }
211 
212  // no longer needed
213  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
214  }
215  else // ptr to complex value | ref
216  {
217 #if OSL_DEBUG_LEVEL > 2
218  fprintf(stderr, "complex, ng is %d\n", ng);
219 #endif
220  void *pCppStack; //temporary stack pointer
221 
222  if (ng < ppc64::MAX_GPR_REGS)
223  {
224  pCppArgs[nPos] = pCppStack = *gpreg++;
225  ng++;
226  }
227  else
228  {
229  pCppArgs[nPos] = pCppStack = *ovrflw;
230  bOverflowUsed = true;
231  }
232  if (bOverflowUsed) ovrflw++;
233 
234  if (! rParam.bIn) // is pure out
235  {
236  // uno out is unconstructed mem!
237  pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize );
238  pTempIndices[nTempIndices] = nPos;
239  // will be released at reconversion
240  ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
241  }
242  // is in/inout
243  else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
244  {
245  uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ),
246  pCppStack, pParamTypeDescr,
247  pThis->getBridge()->getCpp2Uno() );
248  pTempIndices[nTempIndices] = nPos; // has to be reconverted
249  // will be released at reconversion
250  ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
251  }
252  else // direct way
253  {
254  pUnoArgs[nPos] = pCppStack;
255  // no longer needed
256  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
257  }
258  }
259  }
260 
261 #if OSL_DEBUG_LEVEL > 2
262  fprintf(stderr, "end of params\n");
263 #endif
264 
265  // ExceptionHolder
266  uno_Any aUnoExc; // Any will be constructed by callee
267  uno_Any * pUnoExc = &aUnoExc;
268 
269  // invoke uno dispatch call
270  (*pThis->getUnoI()->pDispatcher)( pThis->getUnoI(), pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc );
271 
272  // in case an exception occurred...
273  if (pUnoExc)
274  {
275  // destruct temporary in/inout params
276  for ( ; nTempIndices--; )
277  {
278  sal_Int32 nIndex = pTempIndices[nTempIndices];
279 
280  if (pParams[nIndex].bIn) // is in/inout => was constructed
281  uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndices], 0 );
282  TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
283  }
284  if (pReturnTypeDescr)
285  TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
286 
288  // has to destruct the any
289  // is here for dummy
290  return typelib_TypeClass_VOID;
291  }
292  else // else no exception occurred...
293  {
294  // temporary params
295  for ( ; nTempIndices--; )
296  {
297  sal_Int32 nIndex = pTempIndices[nTempIndices];
298  typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
299 
300  if (pParams[nIndex].bOut) // inout/out
301  {
302  // convert and assign
303  uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
304  uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr,
305  pThis->getBridge()->getUno2Cpp() );
306  }
307  // destroy temp uno param
308  uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 );
309 
310  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
311  }
312  // return
313  if (pCppReturn) // has complex return
314  {
315  if (pUnoReturn != pCppReturn) // needs reconversion
316  {
317  uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr,
318  pThis->getBridge()->getUno2Cpp() );
319  // destroy temp uno return
320  uno_destructData( pUnoReturn, pReturnTypeDescr, 0 );
321  }
322  // complex return ptr is set to return reg
323  *(void **)pRegisterReturn = pCppReturn;
324  }
325  if (pReturnTypeDescr)
326  {
327  typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass;
328  TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
329  return eRet;
330  }
331  else
332  return typelib_TypeClass_VOID;
333  }
334 }
335 
336 #if defined(_CALL_ELF) && _CALL_ELF == 2
337 # define PARAMSAVE 32
338 #else
339 # define PARAMSAVE 48
340 #endif
341 
342 static typelib_TypeClass cpp_mediate(
343  sal_uInt64 nOffsetAndIndex,
344  void ** gpreg, void ** fpreg, long sp,
345  sal_Int64 * pRegisterReturn /* space for register return */ )
346 {
347  static_assert(sizeof(sal_Int64)==sizeof(void *), "### unexpected!");
348 
349  sal_Int32 nVtableOffset = (nOffsetAndIndex >> 32);
350  sal_Int32 nFunctionIndex = (nOffsetAndIndex & 0xFFFFFFFF);
351 
352  long sf = *(long*)sp;
353  void ** ovrflw = (void**)(sf + PARAMSAVE + 64);
354 
355  // gpreg: [ret *], this, [other gpr params]
356  // fpreg: [fpr params]
357  // ovrflw: [gpr or fpr params (properly aligned)]
358 
359  void * pThis;
360  if (nFunctionIndex & 0x80000000 )
361  {
362  nFunctionIndex &= 0x7fffffff;
363  pThis = gpreg[1];
364 #if OSL_DEBUG_LEVEL > 2
365  fprintf(stderr, "pThis is gpreg[1]\n");
366 #endif
367  }
368  else
369  {
370  pThis = gpreg[0];
371 #if OSL_DEBUG_LEVEL > 2
372  fprintf(stderr, "pThis is gpreg[0]\n");
373 #endif
374  }
375 
376 #if OSL_DEBUG_LEVEL > 2
377  fprintf(stderr, "pThis is %lx\n", pThis);
378 #endif
379 
380  pThis = static_cast< char * >(pThis) - nVtableOffset;
381 
382 #if OSL_DEBUG_LEVEL > 2
383  fprintf(stderr, "pThis is now %lx\n", pThis);
384 #endif
385 
388  pThis);
389 
390  typelib_InterfaceTypeDescription * pTypeDescr = pCppI->getTypeDescr();
391 
392 #if OSL_DEBUG_LEVEL > 2
393  fprintf(stderr, "indexes are %d %d\n", nFunctionIndex, pTypeDescr->nMapFunctionIndexToMemberIndex);
394 #endif
395 
396  if (nFunctionIndex >= pTypeDescr->nMapFunctionIndexToMemberIndex)
397  {
398  SAL_WARN(
399  "bridges",
400  "illegal " << OUString::unacquired(&pTypeDescr->aBase.pTypeName)
401  << " vtable index " << nFunctionIndex << "/"
402  << pTypeDescr->nMapFunctionIndexToMemberIndex);
403  throw RuntimeException(
404  ("illegal " + OUString::unacquired(&pTypeDescr->aBase.pTypeName)
405  + " vtable index " + OUString::number(nFunctionIndex) + "/"
406  + OUString::number(pTypeDescr->nMapFunctionIndexToMemberIndex)),
407  (XInterface *)pThis);
408  }
409 
410  // determine called method
411  sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nFunctionIndex];
412  assert(nMemberPos < pTypeDescr->nAllMembers);
413 
414 #if OSL_DEBUG_LEVEL > 2
415  fprintf(stderr, "members are %d %d\n", nMemberPos, pTypeDescr->nAllMembers);
416 #endif
417 
418  TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] );
419 
420  typelib_TypeClass eRet;
421  switch (aMemberDescr.get()->eTypeClass)
422  {
423  case typelib_TypeClass_INTERFACE_ATTRIBUTE:
424  {
425  if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nFunctionIndex)
426  {
427  // is GET method
428  eRet = cpp2uno_call(
429  pCppI, aMemberDescr.get(),
430  ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef,
431  0, 0, // no params
432  gpreg, fpreg, ovrflw, pRegisterReturn );
433  }
434  else
435  {
436  // is SET method
437  typelib_MethodParameter aParam;
438  aParam.pTypeRef =
439  ((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef;
440  aParam.bIn = sal_True;
441  aParam.bOut = sal_False;
442 
443  eRet = cpp2uno_call(
444  pCppI, aMemberDescr.get(),
445  0, // indicates void return
446  1, &aParam,
447  gpreg, fpreg, ovrflw, pRegisterReturn );
448  }
449  break;
450  }
451  case typelib_TypeClass_INTERFACE_METHOD:
452  {
453  // is METHOD
454  switch (nFunctionIndex)
455  {
456  case 1: // acquire()
457  pCppI->acquireProxy(); // non virtual call!
458  eRet = typelib_TypeClass_VOID;
459  break;
460  case 2: // release()
461  pCppI->releaseProxy(); // non virtual call!
462  eRet = typelib_TypeClass_VOID;
463  break;
464  case 0: // queryInterface() opt
465  {
466  typelib_TypeDescription * pTD = 0;
467  TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() );
468  if (pTD)
469  {
470  XInterface * pInterface = 0;
471  (*pCppI->getBridge()->getCppEnv()->getRegisteredInterface)(
472  pCppI->getBridge()->getCppEnv(),
473  (void **)&pInterface, pCppI->getOid().pData,
474  (typelib_InterfaceTypeDescription *)pTD );
475 
476  if (pInterface)
477  {
478  ::uno_any_construct(
479  reinterpret_cast< uno_Any * >( gpreg[0] ),
480  &pInterface, pTD, cpp_acquire );
481  pInterface->release();
482  TYPELIB_DANGER_RELEASE( pTD );
483  *(void **)pRegisterReturn = gpreg[0];
484  eRet = typelib_TypeClass_ANY;
485  break;
486  }
487  TYPELIB_DANGER_RELEASE( pTD );
488  }
489  } // else perform queryInterface()
490  default:
491  eRet = cpp2uno_call(
492  pCppI, aMemberDescr.get(),
493  ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef,
494  ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams,
495  ((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams,
496  gpreg, fpreg, ovrflw, pRegisterReturn );
497  }
498  break;
499  }
500  default:
501  {
502 #if OSL_DEBUG_LEVEL > 2
503  fprintf(stderr, "screwed\n");
504 #endif
505 
506  throw RuntimeException( "no member description found!", (XInterface *)pThis );
507  }
508  }
509 
510 #if OSL_DEBUG_LEVEL > 2
511  fprintf(stderr, "end of cpp_mediate\n");
512 #endif
513  return eRet;
514 }
515 
516 extern "C" void privateSnippetExecutor( ... )
517 {
518  sal_uInt64 gpreg[ppc64::MAX_GPR_REGS];
519 
520  register long r3 asm("r3"); gpreg[0] = r3;
521  register long r4 asm("r4"); gpreg[1] = r4;
522  register long r5 asm("r5"); gpreg[2] = r5;
523  register long r6 asm("r6"); gpreg[3] = r6;
524  register long r7 asm("r7"); gpreg[4] = r7;
525  register long r8 asm("r8"); gpreg[5] = r8;
526  register long r9 asm("r9"); gpreg[6] = r9;
527  register long r10 asm("r10"); gpreg[7] = r10;
528 
529  double fpreg[ppc64::MAX_SSE_REGS];
530 
531  __asm__ __volatile__ (
532  "stfd 1, 0(%0)\t\n"
533  "stfd 2, 8(%0)\t\n"
534  "stfd 3, 16(%0)\t\n"
535  "stfd 4, 24(%0)\t\n"
536  "stfd 5, 32(%0)\t\n"
537  "stfd 6, 40(%0)\t\n"
538  "stfd 7, 48(%0)\t\n"
539  "stfd 8, 56(%0)\t\n"
540  "stfd 9, 64(%0)\t\n"
541  "stfd 10, 72(%0)\t\n"
542  "stfd 11, 80(%0)\t\n"
543  "stfd 12, 88(%0)\t\n"
544  "stfd 13, 96(%0)\t\n"
545  : : "r" (fpreg)
546  : "fr1", "fr2", "fr3", "fr4", "fr5", "fr6", "fr7", "fr8", "fr9",
547  "fr10", "fr11", "fr12", "fr13"
548  );
549 
550  register long r11 asm("r11");
551  const long nOffsetAndIndex = r11;
552 
553  register long r1 asm("r1");
554  const long sp = r1;
555 
556 #if defined(_CALL_ELF) && _CALL_ELF == 2
557  volatile long nRegReturn[2];
558 #else
559  volatile long nRegReturn[1];
560 #endif
561 
562  typelib_TypeClass aType =
563  cpp_mediate( nOffsetAndIndex, (void**)gpreg, (void**)fpreg, sp, (sal_Int64*)nRegReturn);
564 
565  switch( aType )
566  {
567  case typelib_TypeClass_VOID:
568  break;
569  case typelib_TypeClass_BOOLEAN:
570  case typelib_TypeClass_BYTE:
571  __asm__( "lbz 3,%0\n\t"
572  : : "m" (nRegReturn[0]) );
573  break;
574  case typelib_TypeClass_CHAR:
575  case typelib_TypeClass_UNSIGNED_SHORT:
576  __asm__( "lhz 3,%0\n\t"
577  : : "m" (nRegReturn[0]) );
578  break;
579  case typelib_TypeClass_SHORT:
580  __asm__( "lha 3,%0\n\t"
581  : : "m" (nRegReturn[0]) );
582  break;
583  case typelib_TypeClass_ENUM:
584  case typelib_TypeClass_UNSIGNED_LONG:
585  __asm__( "lwz 3,%0\n\t"
586  : : "m"(nRegReturn[0]) );
587  break;
588  case typelib_TypeClass_LONG:
589  __asm__( "lwa 3,%0\n\t"
590  : : "m"(nRegReturn[0]) );
591  break;
592  case typelib_TypeClass_FLOAT:
593  __asm__( "lfs 1,%0\n\t"
594  : : "m" (*((float*)nRegReturn)) );
595  break;
596  case typelib_TypeClass_DOUBLE:
597  __asm__( "lfd 1,%0\n\t"
598  : : "m" (*((double*)nRegReturn)) );
599  break;
600  default:
601  __asm__( "ld 3,%0\n\t"
602  : : "m" (nRegReturn[0]) );
603 #if defined(_CALL_ELF) && _CALL_ELF == 2
604  __asm__( "ld 4,%0\n\t"
605  : : "m" (nRegReturn[1]) );
606 #endif
607  break;
608  }
609 }
610 
611 #if defined(_CALL_ELF) && _CALL_ELF == 2
612 const int codeSnippetSize = 32;
613 #else
614 const int codeSnippetSize = 24;
615 #endif
616 
617 unsigned char * codeSnippet( unsigned char * code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset,
618  bool bHasHiddenParam)
619 {
620 #if OSL_DEBUG_LEVEL > 2
621  fprintf(stderr,"in codeSnippet functionIndex is %x\n", nFunctionIndex);
622  fprintf(stderr,"in codeSnippet vtableOffset is %x\n", nVtableOffset);
623 #endif
624 
625  sal_uInt64 nOffsetAndIndex = ( ( (sal_uInt64) nVtableOffset ) << 32 ) | ( (sal_uInt64) nFunctionIndex );
626 
627  if ( bHasHiddenParam )
628  nOffsetAndIndex |= 0x80000000;
629 #if defined(_CALL_ELF) && _CALL_ELF == 2
630  unsigned int *raw = (unsigned int *)&code[0];
631 
632  raw[0] = 0xe96c0018; /* 0: ld 11,2f-0b(12) */
633  raw[1] = 0xe98c0010; /* ld 12,1f-0b(12) */
634  raw[2] = 0x7d8903a6; /* mtctr 12 */
635  raw[3] = 0x4e800420; /* bctr */
636  /* 1: .quad function_addr */
637  /* 2: .quad context */
638  *(void **)&raw[4] = (void *)privateSnippetExecutor;
639  *(void **)&raw[6] = (void*)nOffsetAndIndex;
640 #else
641  void ** raw = (void **)&code[0];
642  memcpy(raw, (char*) privateSnippetExecutor, 16);
643  raw[2] = (void*) nOffsetAndIndex;
644 #endif
645 #if OSL_DEBUG_LEVEL > 2
646  fprintf(stderr, "in: offset/index is %x %x %d, %lx\n",
647  nFunctionIndex, nVtableOffset, bHasHiddenParam, raw[2]);
648 #endif
649  return (code + codeSnippetSize);
650 }
651 
652 }
653 
654 void bridges::cpp_uno::shared::VtableFactory::flushCode(unsigned char const * bptr, unsigned char const * eptr)
655 {
656  int const lineSize = 32;
657  for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
658  __asm__ volatile ("dcbst 0, %0" : : "r"(p) : "memory");
659  }
660  __asm__ volatile ("sync" : : : "memory");
661  for (unsigned char const * p = bptr; p < eptr + lineSize; p += lineSize) {
662  __asm__ volatile ("icbi 0, %0" : : "r"(p) : "memory");
663  }
664  __asm__ volatile ("isync" : : : "memory");
665 }
666 
668 
671 {
672  return static_cast< Slot * >(block) + 2;
673 }
674 
676  sal_Int32 slotCount)
677 {
678  return (slotCount + 2) * sizeof (Slot) + slotCount * codeSnippetSize;
679 }
680 
683  void * block, sal_Int32 slotCount, sal_Int32,
684  typelib_InterfaceTypeDescription *)
685 {
686  Slot * slots = mapBlockToVtable(block);
687  slots[-2].fn = 0;
688  slots[-1].fn = 0;
689  return slots + slotCount;
690 }
691 
693  Slot ** slots, unsigned char * code, sal_PtrDiff writetoexecdiff,
694  typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset,
695  sal_Int32 functionCount, sal_Int32 vtableOffset)
696 {
697  (*slots) -= functionCount;
698  Slot * s = *slots;
699 #if OSL_DEBUG_LEVEL > 2
700  fprintf(stderr, "in addLocalFunctions functionOffset is %x\n",functionOffset);
701  fprintf(stderr, "in addLocalFunctions vtableOffset is %x\n",vtableOffset);
702 #endif
703 
704  for (sal_Int32 i = 0; i < type->nMembers; ++i) {
705  typelib_TypeDescription * member = 0;
706  TYPELIB_DANGER_GET(&member, type->ppMembers[i]);
707  assert(member != 0);
708  switch (member->eTypeClass) {
709  case typelib_TypeClass_INTERFACE_ATTRIBUTE:
710  // Getter:
711  (s++)->fn = code + writetoexecdiff;
712  code = codeSnippet(
713  code, functionOffset++, vtableOffset,
715  reinterpret_cast<
716  typelib_InterfaceAttributeTypeDescription * >(
717  member)->pAttributeTypeRef));
718 
719  // Setter:
720  if (!reinterpret_cast<
721  typelib_InterfaceAttributeTypeDescription * >(
722  member)->bReadOnly)
723  {
724  (s++)->fn = code + writetoexecdiff;
725  code = codeSnippet(code, functionOffset++, vtableOffset, false);
726  }
727  break;
728 
729  case typelib_TypeClass_INTERFACE_METHOD:
730  (s++)->fn = code + writetoexecdiff;
731  code = codeSnippet(
732  code, functionOffset++, vtableOffset,
734  reinterpret_cast<
735  typelib_InterfaceMethodTypeDescription * >(
736  member)->pReturnTypeRef));
737  break;
738 
739  default:
740  assert(false);
741  break;
742  }
743  TYPELIB_DANGER_RELEASE(member);
744  }
745  return code;
746 }
747 
748 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void(* privateSnippetExecutor)()
sal_Int32 nIndex
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
bool isSimpleType(typelib_TypeClass typeClass)
Determines whether a type is a "simple" type (VOID, BOOLEAN, BYTE, SHORT, UNSIGNED SHORT...
Definition: types.cxx:28
static std::size_t getBlockSize(sal_Int32 slotCount)
Calculate the size of a raw vtable block.
const int codeSnippetSize
bool relatesToInterfaceType(typelib_TypeDescription const *type)
Determines whether a type relates to an interface type (is itself an interface type, or might contain entities of interface type).
Definition: types.cxx:41
static Slot * initializeBlock(void *block, sal_Int32 slotCount, sal_Int32 vtableNumber, typelib_InterfaceTypeDescription *type)
Initialize a raw vtable block.
typelib_TypeClass __cdecl cpp_mediate(void **pCallStack, const sal_Int32 nFunctionIndex, const sal_Int32 nVtableOffset, sal_Int64 *const pRegisterReturn)
static Slot * mapBlockToVtable(void *block)
Given a pointer to a block, turn it into a vtable pointer.
struct _uno_Any uno_Any
Definition: msvc/except.hxx:31
uno_Mapping * getUno2Cpp()
Definition: bridge.hxx:73
uno_ExtEnvironment * getCppEnv()
Definition: bridge.hxx:69
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...
typelib_InterfaceTypeDescription * getTypeDescr()
#define IS_BIG_ENDIAN
A cpp proxy wrapping a uno interface.
int i
#define sal_True
void SAL_CALL uno_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
struct _typelib_TypeDescription typelib_TypeDescription
Definition: msvc/except.hxx:52
uno_Mapping * getCpp2Uno()
Definition: bridge.hxx:72
register sal_uInt32 r28 __asm__("%r28")
void raiseException(uno_Any *pUnoExc, uno_Mapping *pUno2Cpp)
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)
bool return_in_hidden_param(typelib_TypeDescriptionReference *pTypeRef)
Does function that returns this type use a hidden parameter, or registers?
static unsigned char * codeSnippet(unsigned char *code, sal_Int32 nFunctionIndex, sal_Int32 nVtableOffset, bool bHasHiddenParam)
#define sal_False
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.
void * p
#define SAL_WARN(area, stream)
static CppInterfaceProxy * castInterfaceToProxy(void *pInterface)
sal_uInt16 nPos