LibreOffice Module bridges (master)  1
gcc3_linux_arm/uno2cpp.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 <rtl/alloc.h>
22 
23 #include <com/sun/star/uno/genfunc.hxx>
24 #include <com/sun/star/uno/Exception.hpp>
25 #include <com/sun/star/uno/RuntimeException.hpp>
27 #include <uno/data.h>
28 
29 #include <bridge.hxx>
30 #include <types.hxx>
31 #include <unointerfaceproxy.hxx>
32 #include <vtables.hxx>
33 
34 #include "share.hxx"
35 
36 #include <exception>
37 #include <stdio.h>
38 #include <string.h>
39 #include <typeinfo>
40 
41 /*
42  * Based on http://gcc.gnu.org/PR41443
43  * References to __SOFTFP__ are incorrect for EABI; the __SOFTFP__ code
44  * should be used for *soft-float ABI* whether or not VFP is enabled,
45  * and __SOFTFP__ does specifically mean soft-float not soft-float ABI.
46  *
47  * Changing the conditionals to __SOFTFP__ || __ARM_EABI__ then
48  * -mfloat-abi=softfp should work. -mfloat-abi=hard won't; that would
49  * need both a new macro to identify the hard-VFP ABI.
50  */
51 #if !defined(__ARM_EABI__) && !defined(__SOFTFP__)
52 #error Not Implemented
53 
54 /*
55  some possibly handy code to detect that we have VFP registers
56  */
57 
58 #include <sys/types.h>
59 #include <sys/stat.h>
60 #include <fcntl.h>
61 #include <unistd.h>
62 #include <elf.h>
63 
64 #define HWCAP_ARM_VFP 64
65 
66 int hasVFP()
67 {
68  int fd = open ("/proc/self/auxv", O_RDONLY);
69  if (fd == -1)
70  return -1;
71 
72  int ret = -1;
73 
74  Elf32_auxv_t buf[128];
75  ssize_t n;
76  while ((ret == -1) && ((n = read(fd, buf, sizeof (buf))) > 0))
77  {
78  for (int i = 0; i < 128; ++i)
79  {
80  if (buf[i].a_type == AT_HWCAP)
81  {
82  ret = (buf[i].a_un.a_val & HWCAP_ARM_VFP) ? true : false;
83  break;
84  }
85  else if (buf[i].a_type == AT_NULL)
86  {
87  ret = -2;
88  break;
89  }
90  }
91  }
92 
93  close (fd);
94  return ret;
95 }
96 
97 #endif
98 
99 using namespace ::com::sun::star::uno;
100 
101 namespace arm
102 {
103  static bool is_complex_struct(const typelib_TypeDescription * type)
104  {
105  const typelib_CompoundTypeDescription * p
106  = reinterpret_cast< const typelib_CompoundTypeDescription * >(type);
107  for (sal_Int32 i = 0; i < p->nMembers; ++i)
108  {
109  if (p->ppTypeRefs[i]->eTypeClass == typelib_TypeClass_STRUCT ||
110  p->ppTypeRefs[i]->eTypeClass == typelib_TypeClass_EXCEPTION)
111  {
112  typelib_TypeDescription * t = nullptr;
113  TYPELIB_DANGER_GET(&t, p->ppTypeRefs[i]);
114  bool b = is_complex_struct(t);
115  TYPELIB_DANGER_RELEASE(t);
116  if (b) {
117  return true;
118  }
119  }
120  else if (!bridges::cpp_uno::shared::isSimpleType(p->ppTypeRefs[i]->eTypeClass))
121  return true;
122  }
123  if (p->pBaseTypeDescription != nullptr)
124  return is_complex_struct(&p->pBaseTypeDescription->aBase);
125  return false;
126  }
127 
128 #ifdef __ARM_PCS_VFP
129  static bool is_float_only_struct(const typelib_TypeDescription * type)
130  {
131  const typelib_CompoundTypeDescription * p
132  = reinterpret_cast< const typelib_CompoundTypeDescription * >(type);
133  for (sal_Int32 i = 0; i < p->nMembers; ++i)
134  {
135  if (p->ppTypeRefs[i]->eTypeClass != typelib_TypeClass_FLOAT &&
136  p->ppTypeRefs[i]->eTypeClass != typelib_TypeClass_DOUBLE)
137  return false;
138  }
139  return true;
140  }
141 #endif
142  bool return_in_hidden_param( typelib_TypeDescriptionReference *pTypeRef )
143  {
145  return false;
146  else if (pTypeRef->eTypeClass == typelib_TypeClass_STRUCT || pTypeRef->eTypeClass == typelib_TypeClass_EXCEPTION)
147  {
148  typelib_TypeDescription * pTypeDescr = nullptr;
149  TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
150 
151  //A Composite Type not larger than 4 bytes is returned in r0
152  bool bRet = pTypeDescr->nSize > 4 || is_complex_struct(pTypeDescr);
153 
154 #ifdef __ARM_PCS_VFP
155  // In the VFP ABI, structs with only float/double values that fit in
156  // 16 bytes are returned in registers
157  if( pTypeDescr->nSize <= 16 && is_float_only_struct(pTypeDescr))
158  bRet = false;
159 #endif
160 
161  TYPELIB_DANGER_RELEASE( pTypeDescr );
162  return bRet;
163  }
164  return true;
165  }
166 }
167 
168 static void MapReturn(sal_uInt32 r0, sal_uInt32 r1, typelib_TypeDescriptionReference * pReturnType, sal_uInt32* pRegisterReturn)
169 {
170  switch( pReturnType->eTypeClass )
171  {
172  case typelib_TypeClass_HYPER:
173  case typelib_TypeClass_UNSIGNED_HYPER:
174  pRegisterReturn[1] = r1;
175  [[fallthrough]];
176  case typelib_TypeClass_LONG:
177  case typelib_TypeClass_UNSIGNED_LONG:
178  case typelib_TypeClass_ENUM:
179  case typelib_TypeClass_CHAR:
180  case typelib_TypeClass_SHORT:
181  case typelib_TypeClass_UNSIGNED_SHORT:
182  case typelib_TypeClass_BOOLEAN:
183  case typelib_TypeClass_BYTE:
184  pRegisterReturn[0] = r0;
185  break;
186  case typelib_TypeClass_FLOAT:
187 #if !defined(__ARM_PCS_VFP) && (defined(__ARM_EABI__) || defined(__SOFTFP__))
188  pRegisterReturn[0] = r0;
189 #else
190 #pragma clang diagnostic push
191 #pragma clang diagnostic ignored "-Wuninitialized"
192  register float fret asm("s0");
193  *reinterpret_cast<float *>(pRegisterReturn) = fret;
194 #pragma clang diagnostic pop
195 #endif
196  break;
197  case typelib_TypeClass_DOUBLE:
198 #if !defined(__ARM_PCS_VFP) && (defined(__ARM_EABI__) || defined(__SOFTFP__))
199  pRegisterReturn[1] = r1;
200  pRegisterReturn[0] = r0;
201 #else
202 #pragma clang diagnostic push
203 #pragma clang diagnostic ignored "-Wuninitialized"
204  register double dret asm("d0");
205  *reinterpret_cast<double *>(pRegisterReturn) = dret;
206 #pragma clang diagnostic pop
207 #endif
208  break;
209  case typelib_TypeClass_STRUCT:
210  case typelib_TypeClass_EXCEPTION:
211  {
212  if (!arm::return_in_hidden_param(pReturnType))
213  pRegisterReturn[0] = r0;
214  break;
215  }
216  default:
217  break;
218  }
219 }
220 
221 namespace
222 {
223 
224 void callVirtualMethod(
225  void * pThis,
226  sal_Int32 nVtableIndex,
227  void * pRegisterReturn,
228  typelib_TypeDescriptionReference * pReturnType,
229  sal_uInt32 *pStack,
230  sal_uInt32 nStack,
231  sal_uInt32 *pGPR,
232  sal_uInt32 nGPR,
233  double *pFPR) __attribute__((noinline));
234 
235 void callVirtualMethod(
236  void * pThis,
237  sal_Int32 nVtableIndex,
238  void * pRegisterReturn,
239  typelib_TypeDescriptionReference * pReturnType,
240  sal_uInt32 *pStack,
241  sal_uInt32 nStack,
242  sal_uInt32 *pGPR,
243  sal_uInt32 nGPR,
244  double *pFPR)
245 {
246  // never called
247  if (! pThis)
248  CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
249 
250  if ( nStack )
251  {
252  // 8-bytes aligned
253  sal_uInt32 nStackBytes = ( ( nStack + 1 ) >> 1 ) * 8;
254  sal_uInt32 *stack = static_cast<sal_uInt32 *>(__builtin_alloca( nStackBytes * sizeof(sal_uInt32)));
255  memcpy( stack, pStack, nStackBytes );
256  }
257 
258  // Should not happen, but...
259  if ( nGPR > arm::MAX_GPR_REGS )
260  nGPR = arm::MAX_GPR_REGS;
261 
262  sal_uInt32 pMethod = *static_cast<sal_uInt32 *>(pThis);
263  pMethod += 4 * nVtableIndex;
264  pMethod = *reinterpret_cast<sal_uInt32 *>(pMethod);
265 
266  //Return registers
267  sal_uInt32 r0;
268  sal_uInt32 r1;
269 
270  __asm__ __volatile__ (
271  //Fill in general purpose register arguments
272  "ldr r4, %[pgpr]\n\t"
273  "ldmia r4, {r0-r3}\n\t"
274 
275 #ifdef __ARM_PCS_VFP
276  //Fill in VFP register arguments as double precision values
277  "ldr r4, %[pfpr]\n\t"
278  "vldmia r4, {d0-d7}\n\t"
279 #endif
280  //Make the call
281  "ldr r5, %[pmethod]\n\t"
282 #ifndef __ARM_ARCH_4T__
283  "blx r5\n\t"
284 #else
285  "mov lr, pc ; bx r5\n\t"
286 #endif
287 
288  //Fill in return values
289  "mov %[r0], r0\n\t"
290  "mov %[r1], r1\n\t"
291  : [r0]"=r" (r0), [r1]"=r" (r1)
292  : [pmethod]"m" (pMethod), [pgpr]"m" (pGPR), [pfpr]"m" (pFPR)
293  : "r0", "r1", "r2", "r3", "r4", "r5");
294 
295  MapReturn(r0, r1, pReturnType, static_cast<sal_uInt32*>(pRegisterReturn));
296 }
297 }
298 
299 #define INSERT_INT32( pSV, nr, pGPR, pDS ) \
300  if ( nr < arm::MAX_GPR_REGS ) \
301  pGPR[nr++] = reinterpret_cast<sal_uInt32>( pSV ); \
302  else \
303  *pDS++ = reinterpret_cast<sal_uInt32>( pSV );
304 
305 #ifdef __ARM_EABI__
306 #define INSERT_INT64( pSV, nr, pGPR, pDS, pStart ) \
307  if ( (nr < arm::MAX_GPR_REGS) && (nr % 2) ) \
308  { \
309  ++nr; \
310  } \
311  if ( nr < arm::MAX_GPR_REGS ) \
312  { \
313  *reinterpret_cast<sal_uInt32 *>(pGPR[nr++]) = *static_cast<sal_uInt32 *>( pSV ); \
314  *reinterpret_cast<sal_uInt32 *>(pGPR[nr++]) = *(static_cast<sal_uInt32 *>( pSV ) + 1); \
315  } \
316  else \
317  { \
318  if ( (pDS - pStart) % 2) \
319  { \
320  ++pDS; \
321  } \
322  *reinterpret_cast<sal_uInt32 *>(*pDS++) = static_cast<sal_uInt32 *>( pSV )[0]; \
323  *reinterpret_cast<sal_uInt32 *>(*pDS++) = static_cast<sal_uInt32 *>( pSV )[1]; \
324  }
325 #else
326 #define INSERT_INT64( pSV, nr, pGPR, pDS, pStart ) \
327  INSERT_INT32( pSV, nr, pGPR, pDS ) \
328  INSERT_INT32( ((sal_uInt32*)pSV)+1, nr, pGPR, pDS )
329 #endif
330 
331 #ifdef __ARM_PCS_VFP
332 // Since single and double arguments share the same register bank the filling of the
333 // registers is not always linear. Single values go to the first available single register,
334 // while doubles need to have an 8 byte alignment, so only go into double registers starting
335 // at every other single register. For ex a float, double, float sequence will fill registers
336 // s0, d1, and s1, actually corresponding to the linear order s0,s1, d1.
337 //
338 // These use the single/double register array and counters and ignore the pGPR argument
339 // nSR and nDR are the number of single and double precision registers that are no longer
340 // available
341 #define INSERT_FLOAT( pSV, nr, pGPR, pDS ) \
342  if (nSR % 2 == 0) {\
343  nSR = 2*nDR; \
344  }\
345  if ( nSR < arm::MAX_FPR_REGS*2 ) {\
346  pSPR[nSR++] = *static_cast<float const *>( pSV ); \
347  if ((nSR % 2 == 1) && (nSR > 2*nDR)) {\
348  nDR++; \
349  }\
350  }\
351  else \
352  {\
353  *pDS++ = *static_cast<float const *>( pSV );\
354  }
355 #define INSERT_DOUBLE( pSV, nr, pGPR, pDS, pStart ) \
356  if ( nDR < arm::MAX_FPR_REGS ) { \
357  pFPR[nDR++] = *static_cast<double const *>( pSV ); \
358  }\
359  else\
360  {\
361  if ( (pDS - pStart) % 2) \
362  { \
363  ++pDS; \
364  } \
365  *reinterpret_cast<double *>(pDS) = *static_cast<double const *>( pSV );\
366  pDS += 2;\
367  }
368 #else
369 #define INSERT_FLOAT( pSV, nr, pFPR, pDS ) \
370  INSERT_INT32( pSV, nr, pGPR, pDS )
371 
372 #define INSERT_DOUBLE( pSV, nr, pFPR, pDS, pStart ) \
373  INSERT_INT64( pSV, nr, pGPR, pDS, pStart )
374 #endif
375 
376 #define INSERT_INT16( pSV, nr, pGPR, pDS ) \
377  if ( nr < arm::MAX_GPR_REGS ) \
378  pGPR[nr++] = *static_cast<sal_uInt16 const *>( pSV ); \
379  else \
380  *pDS++ = *static_cast<sal_uInt16 const *>( pSV );
381 
382 #define INSERT_INT8( pSV, nr, pGPR, pDS ) \
383  if ( nr < arm::MAX_GPR_REGS ) \
384  pGPR[nr++] = *static_cast<sal_uInt8 const *>( pSV ); \
385  else \
386  *pDS++ = *static_cast<sal_uInt8 const *>( pSV );
387 
388 namespace {
389 
390 void cpp_call(
393  typelib_TypeDescriptionReference * pReturnTypeRef,
394  sal_Int32 nParams, typelib_MethodParameter * pParams,
395  void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
396 {
397  // max space for: [complex ret ptr], values|ptr ...
398  sal_uInt32 * pStack = static_cast<sal_uInt32 *>(__builtin_alloca(
399  sizeof(sal_Int32) + ((nParams+2) * sizeof(sal_Int64)) ));
400  sal_uInt32 * pStackStart = pStack;
401 
402  sal_uInt32 pGPR[arm::MAX_GPR_REGS];
403  sal_uInt32 nGPR = 0;
404 
405  // storage and counters for single and double precision VFP registers
406  double pFPR[arm::MAX_FPR_REGS];
407 #ifdef __ARM_PCS_VFP
408  sal_uInt32 nDR = 0;
409  float *pSPR = reinterpret_cast< float *>(&pFPR);
410  sal_uInt32 nSR = 0;
411 #endif
412 
413  // return
414  typelib_TypeDescription * pReturnTypeDescr = nullptr;
415  TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
416  assert(pReturnTypeDescr);
417 
418  void * pCppReturn = nullptr; // if != 0 && != pUnoReturn, needs reconversion
419 
420  if (pReturnTypeDescr)
421  {
422  bool bSimpleReturn = !arm::return_in_hidden_param( pReturnTypeRef );
423 
424  if (bSimpleReturn)
425  pCppReturn = pUnoReturn; // direct way for simple types
426  else
427  {
428  // complex return via ptr
429  pCppReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
430  ? __builtin_alloca( pReturnTypeDescr->nSize )
431  : pUnoReturn); // direct way
432 
433  INSERT_INT32( &pCppReturn, nGPR, pGPR, pStack );
434  }
435  }
436  // push this
437  void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
438  + aVtableSlot.offset;
439  INSERT_INT32( &pAdjustedThisPtr, nGPR, pGPR, pStack );
440 
441  // stack space
442  static_assert(sizeof(void *) == sizeof(sal_Int32), "### unexpected size!");
443  // args
444  void ** pCppArgs = static_cast<void **>(alloca( 3 * sizeof(void *) * nParams ));
445  // indices of values this have to be converted (interface conversion cpp<=>uno)
446  sal_Int32 * pTempIndices = reinterpret_cast<sal_Int32 *>(pCppArgs + nParams);
447  // type descriptions for reconversions
448  typelib_TypeDescription ** ppTempParamTypeDescr = reinterpret_cast<typelib_TypeDescription **>(pCppArgs + (2 * nParams));
449 
450  sal_Int32 nTempIndices = 0;
451 
452  for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
453  {
454  const typelib_MethodParameter & rParam = pParams[nPos];
455  typelib_TypeDescription * pParamTypeDescr = nullptr;
456  TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
457 
458  if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
459  {
460 // uno_copyAndConvertData( pCppArgs[nPos] = pStack, pUnoArgs[nPos],
461  uno_copyAndConvertData( pCppArgs[nPos] = alloca(8), pUnoArgs[nPos],
462  pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
463 
464  switch (pParamTypeDescr->eTypeClass)
465  {
466  case typelib_TypeClass_HYPER:
467  case typelib_TypeClass_UNSIGNED_HYPER:
468 #if OSL_DEBUG_LEVEL > 2
469  fprintf(stderr, "hyper is %p\n", pCppArgs[nPos]);
470 #endif
471  INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack, pStackStart );
472  break;
473  case typelib_TypeClass_LONG:
474  case typelib_TypeClass_UNSIGNED_LONG:
475  case typelib_TypeClass_ENUM:
476 #if OSL_DEBUG_LEVEL > 2
477  fprintf(stderr, "long is %p\n", pCppArgs[nPos]);
478 #endif
479  INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack );
480  break;
481  case typelib_TypeClass_SHORT:
482  case typelib_TypeClass_CHAR:
483  case typelib_TypeClass_UNSIGNED_SHORT:
484  INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack );
485  break;
486  case typelib_TypeClass_BOOLEAN:
487  case typelib_TypeClass_BYTE:
488  INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack );
489  break;
490  case typelib_TypeClass_FLOAT:
491  INSERT_FLOAT( pCppArgs[nPos], nGPR, pGPR, pStack );
492  break;
493  case typelib_TypeClass_DOUBLE:
494  INSERT_DOUBLE( pCppArgs[nPos], nGPR, pGPR, pStack, pStackStart );
495  break;
496  default:
497  break;
498  }
499  // no longer needed
500  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
501  }
502  else // ptr to complex value | ref
503  {
504  if (! rParam.bIn) // is pure out
505  {
506  // cpp out is constructed mem, uno out is not!
508  pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
509  pParamTypeDescr );
510  pTempIndices[nTempIndices] = nPos; // default constructed for cpp call
511  // will be released at reconversion
512  ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
513  }
514  // is in/inout
515  else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
516  {
518  pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
519  pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
520 
521  pTempIndices[nTempIndices] = nPos; // has to be reconverted
522  // will be released at reconversion
523  ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
524  }
525  else // direct way
526  {
527  pCppArgs[nPos] = pUnoArgs[nPos];
528  // no longer needed
529  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
530  }
531  INSERT_INT32( &(pCppArgs[nPos]), nGPR, pGPR, pStack );
532  }
533  }
534 
535  try
536  {
537  try {
539  pAdjustedThisPtr, aVtableSlot.index,
540  pCppReturn, pReturnTypeRef,
541  pStackStart,
542  (pStack - pStackStart),
543  pGPR, nGPR,
544  pFPR);
545  } catch (css::uno::Exception &) {
546  throw;
547  } catch (std::exception & e) {
548  throw css::uno::RuntimeException(
549  "C++ code threw " + o3tl::runtimeToOUString(typeid(e).name()) + ": "
550  + o3tl::runtimeToOUString(e.what()));
551  } catch (...) {
552  throw css::uno::RuntimeException("C++ code threw unknown exception");
553  }
554 
555  // NO exception occurred...
556  *ppUnoExc = nullptr;
557 
558  // reconvert temporary params
559  for ( ; nTempIndices--; )
560  {
561  sal_Int32 nIndex = pTempIndices[nTempIndices];
562  typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
563 
564  if (pParams[nIndex].bIn)
565  {
566  if (pParams[nIndex].bOut) // inout
567  {
568  uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, nullptr ); // destroy uno value
569  uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
570  pThis->getBridge()->getCpp2Uno() );
571  }
572  }
573  else // pure out
574  {
575  uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
576  pThis->getBridge()->getCpp2Uno() );
577  }
578  // destroy temp cpp param => cpp: every param was constructed
579  uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
580 
581  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
582  }
583  // return value
584  if (pCppReturn && pUnoReturn != pCppReturn)
585  {
586  uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
587  pThis->getBridge()->getCpp2Uno() );
588  uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
589  }
590  }
591  catch (...)
592  {
593  // fill uno exception
595 
596  // temporary params
597  for ( ; nTempIndices--; )
598  {
599  sal_Int32 nIndex = pTempIndices[nTempIndices];
600  // destroy temp cpp param => cpp: every param was constructed
601  uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndices], cpp_release );
602  TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
603  }
604 
605  // return type
606  if (pReturnTypeDescr)
607  TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
608  }
609 }
610 }
611 
612 namespace bridges::cpp_uno::shared {
613 
615  uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
616  void * pReturn, void * pArgs[], uno_Any ** ppException )
617 {
618  // is my surrogate
620  = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
621 #if OSL_DEBUG_LEVEL > 0
622  typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
623 #endif
624 
625  switch (pMemberDescr->eTypeClass)
626  {
627  case typelib_TypeClass_INTERFACE_ATTRIBUTE:
628  {
629 #if OSL_DEBUG_LEVEL > 0
630  // determine vtable call index
631  sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
632  assert(nMemberPos < pTypeDescr->nAllMembers);
633 #endif
634 
635  VtableSlot aVtableSlot(
637  reinterpret_cast<typelib_InterfaceAttributeTypeDescription const *>
638  (pMemberDescr)));
639 
640  if (pReturn)
641  {
642  // dependent dispatch
643  cpp_call(
644  pThis, aVtableSlot,
645  reinterpret_cast<typelib_InterfaceAttributeTypeDescription const *>(pMemberDescr)->pAttributeTypeRef,
646  0, nullptr, // no params
647  pReturn, pArgs, ppException );
648  }
649  else
650  {
651  // is SET
652  typelib_MethodParameter aParam;
653  aParam.pTypeRef =
654  reinterpret_cast<typelib_InterfaceAttributeTypeDescription const *>(pMemberDescr)->pAttributeTypeRef;
655  aParam.bIn = true;
656  aParam.bOut = false;
657 
658  typelib_TypeDescriptionReference * pReturnTypeRef = nullptr;
659  OUString aVoidName("void");
661  &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
662 
663  // dependent dispatch
664  aVtableSlot.index += 1;
665  cpp_call(
666  pThis, aVtableSlot, // get, then set method
667  pReturnTypeRef,
668  1, &aParam,
669  pReturn, pArgs, ppException );
670 
672  }
673 
674  break;
675  }
676  case typelib_TypeClass_INTERFACE_METHOD:
677  {
678 #if OSL_DEBUG_LEVEL > 0
679  // determine vtable call index
680  sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
681  assert(nMemberPos < pTypeDescr->nAllMembers);
682 #endif
683 
684  VtableSlot aVtableSlot(
686  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>
687  (pMemberDescr)));
688 
689  switch (aVtableSlot.index)
690  {
691  // standard calls
692  case 1: // acquire uno interface
693  (*pUnoI->acquire)( pUnoI );
694  *ppException = nullptr;
695  break;
696  case 2: // release uno interface
697  (*pUnoI->release)( pUnoI );
698  *ppException = nullptr;
699  break;
700  case 0: // queryInterface() opt
701  {
702  typelib_TypeDescription * pTD = nullptr;
703  TYPELIB_DANGER_GET( &pTD, static_cast< Type * >( pArgs[0] )->getTypeLibType() );
704  if (pTD)
705  {
706  uno_Interface * pInterface = nullptr;
707  (*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
708  pThis->getBridge()->getUnoEnv(),
709  reinterpret_cast<void **>(&pInterface), pThis->oid.pData, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
710 
711  if (pInterface)
712  {
713  ::uno_any_construct(
714  static_cast< uno_Any * >( pReturn ),
715  &pInterface, pTD, nullptr );
716  (*pInterface->release)( pInterface );
717  TYPELIB_DANGER_RELEASE( pTD );
718  *ppException = nullptr;
719  break;
720  }
721  TYPELIB_DANGER_RELEASE( pTD );
722  }
723  } [[fallthrough]]; // else perform queryInterface()
724  default:
725  // dependent dispatch
726  cpp_call(
727  pThis, aVtableSlot,
728  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>(pMemberDescr)->pReturnTypeRef,
729  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>(pMemberDescr)->nParams,
730  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>(pMemberDescr)->pParams,
731  pReturn, pArgs, ppException );
732  }
733  break;
734  }
735  default:
736  {
737  ::com::sun::star::uno::RuntimeException aExc(
738  "illegal member type description!",
740 
741  Type const & rExcType = cppu::UnoType<decltype(aExc)>::get();
742  // binary identical null reference
743  ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), nullptr );
744  }
745  }
746 }
747 
748 }
749 
750 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Type
sal_Int32 nIndex
void SAL_CALL uno_destructData(void *pValue, typelib_TypeDescription *pTypeDescr, uno_ReleaseFunc release) SAL_THROW_EXTERN_C()
static bool is_complex_struct(const typelib_TypeDescription *type)
Represents a vtable slot of a C++ class.
Definition: vtables.hxx:59
void fillUnoException(uno_Any *pExc, uno_Mapping *pCpp2Uno)
sal_Int64 n
bool isSimpleType(typelib_TypeClass typeClass)
Determines whether a type is a "simple" type (VOID, BOOLEAN, BYTE, SHORT, UNSIGNED SHORT...
Definition: types.cxx:28
int hasVFP()
sal_Int32 index
The index within the vtable.
Definition: vtables.hxx:76
#define INSERT_INT64(pSV, nr, pGPR, pDS, pStart)
A uno proxy wrapping a cpp interface.
void callVirtualMethod(void *pThis, sal_uInt32 nVtableIndex, void *pRegisterReturn, typelib_TypeDescription *pReturnTypeDescr, bool bRegisterReturn, sal_uInt32 *pStack, sal_uInt32 nStack, sal_uInt32 *pGPR, double *pFPR) __attribute__((noinline))
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
#define HWCAP_ARM_VFP
void unoInterfaceProxyDispatch(uno_Interface *pUnoI, const typelib_TypeDescription *pMemberDescr, void *pReturn, void *pArgs[], uno_Any **ppException)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
#define INSERT_INT32(pSV, nr, pGPR, pDS)
uno_ExtEnvironment * getUnoEnv()
Definition: bridge.hxx:70
struct _uno_Any uno_Any
Definition: msvc/except.hxx:31
uno_Mapping * getUno2Cpp()
Definition: bridge.hxx:73
#define INSERT_FLOAT(pSV, nr, pFPR, pDS)
static void cpp_call(bridges::cpp_uno::shared::UnoInterfaceProxy *pThis, bridges::cpp_uno::shared::VtableSlot aVtableSlot, typelib_TypeDescriptionReference *pReturnTypeRef, sal_Int32 nParams, typelib_MethodParameter *pParams, void *pUnoReturn, void *pUnoArgs[], uno_Any **ppUnoExc)
unsigned _Unwind_Word __attribute__((__mode__(__word__)))
Definition: unwind-cxx.h:45
#define INSERT_INT16(pSV, nr, pGPR, pDS)
sal_Int32 offset
The offset of the vtable.
Definition: vtables.hxx:68
#define INSERT_DOUBLE(pSV, nr, pFPR, pDS, pStart)
int i
typelib_InterfaceTypeDescription * pTypeDescr
void SAL_CALL uno_constructData(void *pMem, typelib_TypeDescription *pTypeDescr) SAL_THROW_EXTERN_C()
void SAL_CALL uno_copyAndConvertData(void *pDest, void *pSource, typelib_TypeDescription *pTypeDescr, uno_Mapping *mapping) SAL_THROW_EXTERN_C()
void SAL_CALL typelib_typedescriptionreference_release(typelib_TypeDescriptionReference *pRef) SAL_THROW_EXTERN_C()
struct _typelib_TypeDescription typelib_TypeDescription
Definition: msvc/except.hxx:52
uno_Mapping * getCpp2Uno()
Definition: bridge.hxx:72
VtableSlot getVtableSlot(typelib_InterfaceAttributeTypeDescription const *ifcMember)
Calculates the vtable slot associated with an interface attribute member.
Definition: vtables.cxx:132
XPropertyListType t
void SAL_CALL typelib_typedescriptionreference_new(typelib_TypeDescriptionReference **ppTDR, typelib_TypeClass eTypeClass, rtl_uString *pTypeName) SAL_THROW_EXTERN_C()
bool close
register sal_uInt32 r28 __asm__("%r28")
bool return_in_hidden_param(typelib_TypeDescriptionReference *pTypeRef)
Does function that returns this type use a hidden parameter, or registers?
#define INSERT_INT8(pSV, nr, pGPR, pDS)
OUString runtimeToOUString(char const *runtimeString)
void * p
void dummy_can_throw_anything(char const *)
static void MapReturn(sal_uInt32 r0, sal_uInt32 r1, typelib_TypeDescriptionReference *pReturnType, sal_uInt32 *pRegisterReturn)
com::sun::star::uno::XInterface * getCppI()
sal_uInt16 nPos
char const * name