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 #if defined __clang__
191 #pragma clang diagnostic push
192 #pragma clang diagnostic ignored "-Wuninitialized"
193 #endif
194  register float fret asm("s0");
195  *reinterpret_cast<float *>(pRegisterReturn) = fret;
196 #if defined __clang__
197 #pragma clang diagnostic pop
198 #endif
199 #endif
200  break;
201  case typelib_TypeClass_DOUBLE:
202 #if !defined(__ARM_PCS_VFP) && (defined(__ARM_EABI__) || defined(__SOFTFP__))
203  pRegisterReturn[1] = r1;
204  pRegisterReturn[0] = r0;
205 #else
206 #if defined __clang__
207 #pragma clang diagnostic push
208 #pragma clang diagnostic ignored "-Wuninitialized"
209 #endif
210  register double dret asm("d0");
211  *reinterpret_cast<double *>(pRegisterReturn) = dret;
212 #if defined __clang__
213 #pragma clang diagnostic pop
214 #endif
215 #endif
216  break;
217  case typelib_TypeClass_STRUCT:
218  case typelib_TypeClass_EXCEPTION:
219  {
220  if (!arm::return_in_hidden_param(pReturnType))
221  pRegisterReturn[0] = r0;
222  break;
223  }
224  default:
225  break;
226  }
227 }
228 
229 namespace
230 {
231 
232 void callVirtualMethod(
233  void * pThis,
234  sal_Int32 nVtableIndex,
235  void * pRegisterReturn,
236  typelib_TypeDescriptionReference * pReturnType,
237  sal_uInt32 *pStack,
238  sal_uInt32 nStack,
239  sal_uInt32 *pGPR,
240  sal_uInt32 nGPR,
241  double *pFPR) __attribute__((noinline));
242 
243 void callVirtualMethod(
244  void * pThis,
245  sal_Int32 nVtableIndex,
246  void * pRegisterReturn,
247  typelib_TypeDescriptionReference * pReturnType,
248  sal_uInt32 *pStack,
249  sal_uInt32 nStack,
250  sal_uInt32 *pGPR,
251  sal_uInt32 nGPR,
252  double *pFPR)
253 {
254  // never called
255  if (! pThis)
256  CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
257 
258  if ( nStack )
259  {
260  // 8-bytes aligned
261  sal_uInt32 nStackBytes = ( ( nStack + 1 ) >> 1 ) * 8;
262  sal_uInt32 *stack = static_cast<sal_uInt32 *>(__builtin_alloca( nStackBytes ));
263  memcpy( stack, pStack, nStackBytes );
264  }
265 
266  // Should not happen, but...
267  if ( nGPR > arm::MAX_GPR_REGS )
268  nGPR = arm::MAX_GPR_REGS;
269 
270  sal_uInt32 pMethod = *static_cast<sal_uInt32 *>(pThis);
271  pMethod += 4 * nVtableIndex;
272  pMethod = *reinterpret_cast<sal_uInt32 *>(pMethod);
273 
274  //Return registers
275  sal_uInt32 r0;
276  sal_uInt32 r1;
277 
278  __asm__ __volatile__ (
279  //Fill in general purpose register arguments
280  "ldr r4, %[pgpr]\n\t"
281  "ldmia r4, {r0-r3}\n\t"
282 
283 #ifdef __ARM_PCS_VFP
284  //Fill in VFP register arguments as double precision values
285  "ldr r4, %[pfpr]\n\t"
286  "vldmia r4, {d0-d7}\n\t"
287 #endif
288  //Make the call
289  "ldr r5, %[pmethod]\n\t"
290 #ifndef __ARM_ARCH_4T__
291  "blx r5\n\t"
292 #else
293  "mov lr, pc ; bx r5\n\t"
294 #endif
295 
296  //Fill in return values
297  "mov %[r0], r0\n\t"
298  "mov %[r1], r1\n\t"
299  : [r0]"=r" (r0), [r1]"=r" (r1)
300  : [pmethod]"m" (pMethod), [pgpr]"m" (pGPR), [pfpr]"m" (pFPR)
301  : "r0", "r1", "r2", "r3", "r4", "r5");
302 
303  MapReturn(r0, r1, pReturnType, static_cast<sal_uInt32*>(pRegisterReturn));
304 }
305 }
306 
307 #define INSERT_INT32( pSV, nr, pGPR, pDS ) \
308  if ( nr < arm::MAX_GPR_REGS ) \
309  pGPR[nr++] = *reinterpret_cast<const sal_uInt32*>( pSV ); \
310  else \
311  *pDS++ = *reinterpret_cast<const sal_uInt32*>( pSV );
312 
313 #ifdef __ARM_EABI__
314 #define INSERT_INT64( pSV, nr, pGPR, pDS, pStart ) \
315  if ( (nr < arm::MAX_GPR_REGS) && (nr % 2) ) \
316  { \
317  ++nr; \
318  } \
319  if ( nr < arm::MAX_GPR_REGS ) \
320  { \
321  pGPR[nr++] = *static_cast<const sal_uInt32 *>( pSV ); \
322  pGPR[nr++] = *(static_cast<const sal_uInt32 *>( pSV ) + 1); \
323  } \
324  else \
325  { \
326  if ( (pDS - pStart) % 2) \
327  { \
328  ++pDS; \
329  } \
330  *pDS++ = static_cast<sal_uInt32 *>( pSV )[0]; \
331  *pDS++ = static_cast<sal_uInt32 *>( pSV )[1]; \
332  }
333 #else
334 #define INSERT_INT64( pSV, nr, pGPR, pDS, pStart ) \
335  INSERT_INT32( pSV, nr, pGPR, pDS ) \
336  INSERT_INT32( ((sal_uInt32*)pSV)+1, nr, pGPR, pDS )
337 #endif
338 
339 #ifdef __ARM_PCS_VFP
340 // Since single and double arguments share the same register bank the filling of the
341 // registers is not always linear. Single values go to the first available single register,
342 // while doubles need to have an 8 byte alignment, so only go into double registers starting
343 // at every other single register. For ex a float, double, float sequence will fill registers
344 // s0, d1, and s1, actually corresponding to the linear order s0,s1, d1.
345 //
346 // These use the single/double register array and counters and ignore the pGPR argument
347 // nSR and nDR are the number of single and double precision registers that are no longer
348 // available
349 #define INSERT_FLOAT( pSV, nr, pGPR, pDS ) \
350  if (nSR % 2 == 0) {\
351  nSR = 2*nDR; \
352  }\
353  if ( nSR < arm::MAX_FPR_REGS*2 ) {\
354  pSPR[nSR++] = *static_cast<float const *>( pSV ); \
355  if ((nSR % 2 == 1) && (nSR > 2*nDR)) {\
356  nDR++; \
357  }\
358  }\
359  else \
360  {\
361  *pDS++ = *static_cast<float const *>( pSV );\
362  }
363 #define INSERT_DOUBLE( pSV, nr, pGPR, pDS, pStart ) \
364  if ( nDR < arm::MAX_FPR_REGS ) { \
365  pFPR[nDR++] = *static_cast<double const *>( pSV ); \
366  }\
367  else\
368  {\
369  if ( (pDS - pStart) % 2) \
370  { \
371  ++pDS; \
372  } \
373  *reinterpret_cast<double *>(pDS) = *static_cast<double const *>( pSV );\
374  pDS += 2;\
375  }
376 #else
377 #define INSERT_FLOAT( pSV, nr, pFPR, pDS ) \
378  INSERT_INT32( pSV, nr, pGPR, pDS )
379 
380 #define INSERT_DOUBLE( pSV, nr, pFPR, pDS, pStart ) \
381  INSERT_INT64( pSV, nr, pGPR, pDS, pStart )
382 #endif
383 
384 #define INSERT_INT16( pSV, nr, pGPR, pDS ) \
385  if ( nr < arm::MAX_GPR_REGS ) \
386  pGPR[nr++] = *static_cast<sal_uInt16 const *>( pSV ); \
387  else \
388  *pDS++ = *static_cast<sal_uInt16 const *>( pSV );
389 
390 #define INSERT_INT8( pSV, nr, pGPR, pDS ) \
391  if ( nr < arm::MAX_GPR_REGS ) \
392  pGPR[nr++] = *static_cast<sal_uInt8 const *>( pSV ); \
393  else \
394  *pDS++ = *static_cast<sal_uInt8 const *>( pSV );
395 
396 namespace {
397 
398 void cpp_call(
401  typelib_TypeDescriptionReference * pReturnTypeRef,
402  sal_Int32 nParams, typelib_MethodParameter * pParams,
403  void * pUnoReturn, void * pUnoArgs[], uno_Any ** ppUnoExc )
404 {
405  // max space for: [complex ret ptr], values|ptr ...
406  sal_uInt32 * pStack = static_cast<sal_uInt32 *>(__builtin_alloca(
407  sizeof(sal_Int32) + ((nParams+2) * sizeof(sal_Int64)) ));
408  sal_uInt32 * pStackStart = pStack;
409 
410  sal_uInt32 pGPR[arm::MAX_GPR_REGS];
411  sal_uInt32 nGPR = 0;
412 
413  // storage and counters for single and double precision VFP registers
414  double pFPR[arm::MAX_FPR_REGS];
415 #ifdef __ARM_PCS_VFP
416  sal_uInt32 nDR = 0;
417  float *pSPR = reinterpret_cast< float *>(&pFPR);
418  sal_uInt32 nSR = 0;
419 #endif
420 
421  // return
422  typelib_TypeDescription * pReturnTypeDescr = nullptr;
423  TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef );
424  assert(pReturnTypeDescr);
425 
426  void * pCppReturn = nullptr; // if != 0 && != pUnoReturn, needs reconversion
427 
428  if (pReturnTypeDescr)
429  {
430  bool bSimpleReturn = !arm::return_in_hidden_param( pReturnTypeRef );
431 
432  if (bSimpleReturn)
433  pCppReturn = pUnoReturn; // direct way for simple types
434  else
435  {
436  // complex return via ptr
437  pCppReturn = (bridges::cpp_uno::shared::relatesToInterfaceType( pReturnTypeDescr )
438  ? __builtin_alloca( pReturnTypeDescr->nSize )
439  : pUnoReturn); // direct way
440 
441  INSERT_INT32( &pCppReturn, nGPR, pGPR, pStack );
442  }
443  }
444  // push this
445  void * pAdjustedThisPtr = reinterpret_cast< void ** >(pThis->getCppI())
446  + aVtableSlot.offset;
447  INSERT_INT32( &pAdjustedThisPtr, nGPR, pGPR, pStack );
448 
449  // stack space
450  static_assert(sizeof(void *) == sizeof(sal_Int32), "### unexpected size!");
451  // args
452  void ** pCppArgs = static_cast<void **>(alloca( 3 * sizeof(void *) * nParams ));
453  // indices of values this have to be converted (interface conversion cpp<=>uno)
454  sal_Int32 * pTempIndices = reinterpret_cast<sal_Int32 *>(pCppArgs + nParams);
455  // type descriptions for reconversions
456  typelib_TypeDescription ** ppTempParamTypeDescr = reinterpret_cast<typelib_TypeDescription **>(pCppArgs + (2 * nParams));
457 
458  sal_Int32 nTempIndices = 0;
459 
460  for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos )
461  {
462  const typelib_MethodParameter & rParam = pParams[nPos];
463  typelib_TypeDescription * pParamTypeDescr = nullptr;
464  TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef );
465 
466  if (!rParam.bOut && bridges::cpp_uno::shared::isSimpleType( pParamTypeDescr ))
467  {
468 // uno_copyAndConvertData( pCppArgs[nPos] = pStack, pUnoArgs[nPos],
469  uno_copyAndConvertData( pCppArgs[nPos] = alloca(8), pUnoArgs[nPos],
470  pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
471 
472  switch (pParamTypeDescr->eTypeClass)
473  {
474  case typelib_TypeClass_HYPER:
475  case typelib_TypeClass_UNSIGNED_HYPER:
476 #if OSL_DEBUG_LEVEL > 2
477  fprintf(stderr, "hyper is %p\n", pCppArgs[nPos]);
478 #endif
479  INSERT_INT64( pCppArgs[nPos], nGPR, pGPR, pStack, pStackStart );
480  break;
481  case typelib_TypeClass_LONG:
482  case typelib_TypeClass_UNSIGNED_LONG:
483  case typelib_TypeClass_ENUM:
484 #if OSL_DEBUG_LEVEL > 2
485  fprintf(stderr, "long is %p\n", pCppArgs[nPos]);
486 #endif
487  INSERT_INT32( pCppArgs[nPos], nGPR, pGPR, pStack );
488  break;
489  case typelib_TypeClass_SHORT:
490  case typelib_TypeClass_CHAR:
491  case typelib_TypeClass_UNSIGNED_SHORT:
492  INSERT_INT16( pCppArgs[nPos], nGPR, pGPR, pStack );
493  break;
494  case typelib_TypeClass_BOOLEAN:
495  case typelib_TypeClass_BYTE:
496  INSERT_INT8( pCppArgs[nPos], nGPR, pGPR, pStack );
497  break;
498  case typelib_TypeClass_FLOAT:
499  INSERT_FLOAT( pCppArgs[nPos], nGPR, pGPR, pStack );
500  break;
501  case typelib_TypeClass_DOUBLE:
502  INSERT_DOUBLE( pCppArgs[nPos], nGPR, pGPR, pStack, pStackStart );
503  break;
504  default:
505  break;
506  }
507  // no longer needed
508  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
509  }
510  else // ptr to complex value | ref
511  {
512  if (! rParam.bIn) // is pure out
513  {
514  // cpp out is constructed mem, uno out is not!
516  pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
517  pParamTypeDescr );
518  pTempIndices[nTempIndices] = nPos; // default constructed for cpp call
519  // will be released at reconversion
520  ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
521  }
522  // is in/inout
523  else if (bridges::cpp_uno::shared::relatesToInterfaceType( pParamTypeDescr ))
524  {
526  pCppArgs[nPos] = alloca( pParamTypeDescr->nSize ),
527  pUnoArgs[nPos], pParamTypeDescr, pThis->getBridge()->getUno2Cpp() );
528 
529  pTempIndices[nTempIndices] = nPos; // has to be reconverted
530  // will be released at reconversion
531  ppTempParamTypeDescr[nTempIndices++] = pParamTypeDescr;
532  }
533  else // direct way
534  {
535  pCppArgs[nPos] = pUnoArgs[nPos];
536  // no longer needed
537  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
538  }
539  INSERT_INT32( &(pCppArgs[nPos]), nGPR, pGPR, pStack );
540  }
541  }
542 
543  try
544  {
545  try {
547  pAdjustedThisPtr, aVtableSlot.index,
548  pCppReturn, pReturnTypeRef,
549  pStackStart,
550  (pStack - pStackStart),
551  pGPR, nGPR,
552  pFPR);
553  } catch (css::uno::Exception &) {
554  throw;
555  } catch (std::exception & e) {
556  throw css::uno::RuntimeException(
557  "C++ code threw " + o3tl::runtimeToOUString(typeid(e).name()) + ": "
558  + o3tl::runtimeToOUString(e.what()));
559  } catch (...) {
560  throw css::uno::RuntimeException("C++ code threw unknown exception");
561  }
562 
563  // NO exception occurred...
564  *ppUnoExc = nullptr;
565 
566  // reconvert temporary params
567  for ( ; nTempIndices--; )
568  {
569  sal_Int32 nIndex = pTempIndices[nTempIndices];
570  typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndices];
571 
572  if (pParams[nIndex].bIn)
573  {
574  if (pParams[nIndex].bOut) // inout
575  {
576  uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, nullptr ); // destroy uno value
577  uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
578  pThis->getBridge()->getCpp2Uno() );
579  }
580  }
581  else // pure out
582  {
583  uno_copyAndConvertData( pUnoArgs[nIndex], pCppArgs[nIndex], pParamTypeDescr,
584  pThis->getBridge()->getCpp2Uno() );
585  }
586  // destroy temp cpp param => cpp: every param was constructed
587  uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release );
588 
589  TYPELIB_DANGER_RELEASE( pParamTypeDescr );
590  }
591  // return value
592  if (pCppReturn && pUnoReturn != pCppReturn)
593  {
594  uno_copyAndConvertData( pUnoReturn, pCppReturn, pReturnTypeDescr,
595  pThis->getBridge()->getCpp2Uno() );
596  uno_destructData( pCppReturn, pReturnTypeDescr, cpp_release );
597  }
598  }
599  catch (...)
600  {
601  // fill uno exception
603 
604  // temporary params
605  for ( ; nTempIndices--; )
606  {
607  sal_Int32 nIndex = pTempIndices[nTempIndices];
608  // destroy temp cpp param => cpp: every param was constructed
609  uno_destructData( pCppArgs[nIndex], ppTempParamTypeDescr[nTempIndices], cpp_release );
610  TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndices] );
611  }
612 
613  // return type
614  if (pReturnTypeDescr)
615  TYPELIB_DANGER_RELEASE( pReturnTypeDescr );
616  }
617 }
618 }
619 
620 namespace bridges::cpp_uno::shared {
621 
623  uno_Interface * pUnoI, const typelib_TypeDescription * pMemberDescr,
624  void * pReturn, void * pArgs[], uno_Any ** ppException )
625 {
626  // is my surrogate
628  = static_cast< bridges::cpp_uno::shared::UnoInterfaceProxy * >(pUnoI);
629 #if OSL_DEBUG_LEVEL > 0
630  typelib_InterfaceTypeDescription * pTypeDescr = pThis->pTypeDescr;
631 #endif
632 
633  switch (pMemberDescr->eTypeClass)
634  {
635  case typelib_TypeClass_INTERFACE_ATTRIBUTE:
636  {
637 #if OSL_DEBUG_LEVEL > 0
638  // determine vtable call index
639  sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
640  assert(nMemberPos < pTypeDescr->nAllMembers);
641 #endif
642 
643  VtableSlot aVtableSlot(
645  reinterpret_cast<typelib_InterfaceAttributeTypeDescription const *>
646  (pMemberDescr)));
647 
648  if (pReturn)
649  {
650  // dependent dispatch
651  cpp_call(
652  pThis, aVtableSlot,
653  reinterpret_cast<typelib_InterfaceAttributeTypeDescription const *>(pMemberDescr)->pAttributeTypeRef,
654  0, nullptr, // no params
655  pReturn, pArgs, ppException );
656  }
657  else
658  {
659  // is SET
660  typelib_MethodParameter aParam;
661  aParam.pTypeRef =
662  reinterpret_cast<typelib_InterfaceAttributeTypeDescription const *>(pMemberDescr)->pAttributeTypeRef;
663  aParam.bIn = true;
664  aParam.bOut = false;
665 
666  typelib_TypeDescriptionReference * pReturnTypeRef = nullptr;
667  OUString aVoidName("void");
669  &pReturnTypeRef, typelib_TypeClass_VOID, aVoidName.pData );
670 
671  // dependent dispatch
672  aVtableSlot.index += 1;
673  cpp_call(
674  pThis, aVtableSlot, // get, then set method
675  pReturnTypeRef,
676  1, &aParam,
677  pReturn, pArgs, ppException );
678 
680  }
681 
682  break;
683  }
684  case typelib_TypeClass_INTERFACE_METHOD:
685  {
686 #if OSL_DEBUG_LEVEL > 0
687  // determine vtable call index
688  sal_Int32 nMemberPos = ((typelib_InterfaceMemberTypeDescription *)pMemberDescr)->nPosition;
689  assert(nMemberPos < pTypeDescr->nAllMembers);
690 #endif
691 
692  VtableSlot aVtableSlot(
694  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>
695  (pMemberDescr)));
696 
697  switch (aVtableSlot.index)
698  {
699  // standard calls
700  case 1: // acquire uno interface
701  (*pUnoI->acquire)( pUnoI );
702  *ppException = nullptr;
703  break;
704  case 2: // release uno interface
705  (*pUnoI->release)( pUnoI );
706  *ppException = nullptr;
707  break;
708  case 0: // queryInterface() opt
709  {
710  typelib_TypeDescription * pTD = nullptr;
711  TYPELIB_DANGER_GET( &pTD, static_cast< Type * >( pArgs[0] )->getTypeLibType() );
712  if (pTD)
713  {
714  uno_Interface * pInterface = nullptr;
715  (*pThis->getBridge()->getUnoEnv()->getRegisteredInterface)(
716  pThis->getBridge()->getUnoEnv(),
717  reinterpret_cast<void **>(&pInterface), pThis->oid.pData, reinterpret_cast<typelib_InterfaceTypeDescription *>(pTD) );
718 
719  if (pInterface)
720  {
721  ::uno_any_construct(
722  static_cast< uno_Any * >( pReturn ),
723  &pInterface, pTD, nullptr );
724  (*pInterface->release)( pInterface );
725  TYPELIB_DANGER_RELEASE( pTD );
726  *ppException = nullptr;
727  break;
728  }
729  TYPELIB_DANGER_RELEASE( pTD );
730  }
731  } [[fallthrough]]; // else perform queryInterface()
732  default:
733  // dependent dispatch
734  cpp_call(
735  pThis, aVtableSlot,
736  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>(pMemberDescr)->pReturnTypeRef,
737  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>(pMemberDescr)->nParams,
738  reinterpret_cast<typelib_InterfaceMethodTypeDescription const *>(pMemberDescr)->pParams,
739  pReturn, pArgs, ppException );
740  }
741  break;
742  }
743  default:
744  {
745  ::com::sun::star::uno::RuntimeException aExc(
746  "illegal member type description!",
748 
749  Type const & rExcType = cppu::UnoType<decltype(aExc)>::get();
750  // binary identical null reference
751  ::uno_type_any_construct( *ppException, &aExc, rExcType.getTypeLibType(), nullptr );
752  }
753  }
754 }
755 
756 }
757 
758 /* 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)
#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