Line 0
Link Here
|
|
|
1 |
/************************************************************************* |
2 |
* |
3 |
* $RCSfile: cpp2uno.cxx,v $ |
4 |
* |
5 |
* $Revision: 1.1.2.3 $ |
6 |
* |
7 |
* last change: $Author: khendricks $ $Date: 2002/05/19 11:25:52 $ |
8 |
* |
9 |
* The Contents of this file are made available subject to the terms of |
10 |
* either of the following licenses |
11 |
* |
12 |
* - GNU Lesser General Public License Version 2.1 |
13 |
* - Sun Industry Standards Source License Version 1.1 |
14 |
* |
15 |
* Sun Microsystems Inc., October, 2000 |
16 |
* |
17 |
* GNU Lesser General Public License Version 2.1 |
18 |
* ============================================= |
19 |
* Copyright 2000 by Sun Microsystems, Inc. |
20 |
* 901 San Antonio Road, Palo Alto, CA 94303, USA |
21 |
* |
22 |
* This library is free software; you can redistribute it and/or |
23 |
* modify it under the terms of the GNU Lesser General Public |
24 |
* License version 2.1, as published by the Free Software Foundation. |
25 |
* |
26 |
* This library is distributed in the hope that it will be useful, |
27 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
28 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
29 |
* Lesser General Public License for more details. |
30 |
* |
31 |
* You should have received a copy of the GNU Lesser General Public |
32 |
* License along with this library; if not, write to the Free Software |
33 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
34 |
* MA 02111-1307 USA |
35 |
* |
36 |
* |
37 |
* Sun Industry Standards Source License Version 1.1 |
38 |
* ================================================= |
39 |
* The contents of this file are subject to the Sun Industry Standards |
40 |
* Source License Version 1.1 (the "License"); You may not use this file |
41 |
* except in compliance with the License. You may obtain a copy of the |
42 |
* License at http://www.openoffice.org/license.html. |
43 |
* |
44 |
* Software provided under this License is provided on an "AS IS" basis, |
45 |
* WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, |
46 |
* WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS, |
47 |
* MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING. |
48 |
* See the License for the specific provisions governing your rights and |
49 |
* obligations concerning the Software. |
50 |
* |
51 |
* The Initial Developer of the Original Code is: Sun Microsystems, Inc. |
52 |
* |
53 |
* Copyright: 2000 by Sun Microsystems, Inc. |
54 |
* |
55 |
* All Rights Reserved. |
56 |
* |
57 |
* Contributor(s): _______________________________________ |
58 |
* |
59 |
* |
60 |
************************************************************************/ |
61 |
|
62 |
#include <malloc.h> |
63 |
#include <hash_map> |
64 |
|
65 |
#include <rtl/alloc.h> |
66 |
#include <osl/mutex.hxx> |
67 |
|
68 |
#include <uno/data.h> |
69 |
#include <typelib/typedescription.hxx> |
70 |
|
71 |
#include <bridges/cpp_uno/bridge.hxx> |
72 |
#include <bridges/cpp_uno/type_misc.hxx> |
73 |
|
74 |
#include "share.hxx" |
75 |
|
76 |
|
77 |
using namespace ::osl; |
78 |
using namespace ::rtl; |
79 |
using namespace ::com::sun::star::uno; |
80 |
|
81 |
namespace CPPU_CURRENT_NAMESPACE |
82 |
{ |
83 |
|
84 |
//================================================================================================== |
85 |
rtl_StandardModuleCount g_moduleCount = MODULE_COUNT_INIT; |
86 |
|
87 |
//================================================================================================== |
88 |
static typelib_TypeClass cpp2uno_call( |
89 |
cppu_cppInterfaceProxy * pThis, |
90 |
const typelib_TypeDescription * pMemberTypeDescr, |
91 |
typelib_TypeDescriptionReference * pReturnTypeRef, // 0 indicates void return |
92 |
sal_Int32 nParams, typelib_MethodParameter * pParams, |
93 |
void ** gpreg, void ** fpreg, void ** ovrflw, |
94 |
sal_Int64 * pRegisterReturn /* space for register return */ ) |
95 |
{ |
96 |
int ng = 0; //number of gpr registers used |
97 |
int nf = 0; //number of fpr regsiters used |
98 |
void ** pCppStack; //temporary stack pointer |
99 |
|
100 |
// gpreg: [ret *], this, [gpr params] |
101 |
// fpreg: [fpr params] |
102 |
// ovrflw: [gpr or fpr params (properly aligned)] |
103 |
|
104 |
// return |
105 |
typelib_TypeDescription * pReturnTypeDescr = 0; |
106 |
if (pReturnTypeRef) |
107 |
TYPELIB_DANGER_GET( &pReturnTypeDescr, pReturnTypeRef ); |
108 |
|
109 |
void * pUnoReturn = 0; |
110 |
void * pCppReturn = 0; // complex return ptr: if != 0 && != pUnoReturn, reconversion need |
111 |
|
112 |
if (pReturnTypeDescr) |
113 |
{ |
114 |
if (cppu_isSimpleType( pReturnTypeDescr )) |
115 |
{ |
116 |
pUnoReturn = pRegisterReturn; // direct way for simple types |
117 |
} |
118 |
else // complex return via ptr (pCppReturn) |
119 |
{ |
120 |
pCppReturn = *(void **)gpreg; |
121 |
gpreg++; |
122 |
ng++; |
123 |
|
124 |
pUnoReturn = (cppu_relatesToInterface( pReturnTypeDescr ) |
125 |
? alloca( pReturnTypeDescr->nSize ) |
126 |
: pCppReturn); // direct way |
127 |
} |
128 |
} |
129 |
// pop this |
130 |
gpreg++; |
131 |
ng++; |
132 |
|
133 |
// stack space |
134 |
OSL_ENSURE( sizeof(void *) == sizeof(sal_Int32), "### unexpected size!" ); |
135 |
// parameters |
136 |
void ** pUnoArgs = (void **)alloca( 4 * sizeof(void *) * nParams ); |
137 |
void ** pCppArgs = pUnoArgs + nParams; |
138 |
// indizes of values this have to be converted (interface conversion cpp<=>uno) |
139 |
sal_Int32 * pTempIndizes = (sal_Int32 *)(pUnoArgs + (2 * nParams)); |
140 |
// type descriptions for reconversions |
141 |
typelib_TypeDescription ** ppTempParamTypeDescr = (typelib_TypeDescription **)(pUnoArgs + (3 * nParams)); |
142 |
|
143 |
sal_Int32 nTempIndizes = 0; |
144 |
|
145 |
for ( sal_Int32 nPos = 0; nPos < nParams; ++nPos ) |
146 |
{ |
147 |
const typelib_MethodParameter & rParam = pParams[nPos]; |
148 |
typelib_TypeDescription * pParamTypeDescr = 0; |
149 |
TYPELIB_DANGER_GET( &pParamTypeDescr, rParam.pTypeRef ); |
150 |
|
151 |
if (!rParam.bOut && cppu_isSimpleType( pParamTypeDescr )) // value |
152 |
{ |
153 |
|
154 |
switch (pParamTypeDescr->eTypeClass) |
155 |
{ |
156 |
|
157 |
case typelib_TypeClass_DOUBLE: |
158 |
if (nf < 2) { |
159 |
pCppArgs[nPos] = fpreg; |
160 |
pUnoArgs[nPos] = fpreg; |
161 |
nf++; |
162 |
fpreg += 2; |
163 |
} else { |
164 |
pCppArgs[nPos] = ovrflw; |
165 |
pUnoArgs[nPos] = ovrflw; |
166 |
ovrflw += 2; |
167 |
} |
168 |
break; |
169 |
|
170 |
case typelib_TypeClass_FLOAT: |
171 |
// fpreg are all double values so need to |
172 |
// modify fpreg to be a single word float value |
173 |
if (nf < 2) { |
174 |
// float tmp = (float) (*((double *)fpreg)); |
175 |
// (*((float *) fpreg)) = tmp; |
176 |
pCppArgs[nPos] = fpreg; |
177 |
pUnoArgs[nPos] = fpreg; |
178 |
nf++; |
179 |
fpreg += 2; |
180 |
} else { |
181 |
pCppArgs[nPos] = ovrflw; |
182 |
pUnoArgs[nPos] = ovrflw; |
183 |
ovrflw += 1; |
184 |
} |
185 |
break; |
186 |
|
187 |
case typelib_TypeClass_HYPER: |
188 |
case typelib_TypeClass_UNSIGNED_HYPER: |
189 |
if (ng < 4) { |
190 |
pCppArgs[nPos] = gpreg; |
191 |
pUnoArgs[nPos] = gpreg; |
192 |
ng += 2; |
193 |
gpreg += 2; |
194 |
} else { |
195 |
pCppArgs[nPos] = ovrflw; |
196 |
pUnoArgs[nPos] = ovrflw; |
197 |
ovrflw += 2; |
198 |
} |
199 |
break; |
200 |
|
201 |
case typelib_TypeClass_BYTE: |
202 |
case typelib_TypeClass_BOOLEAN: |
203 |
if (ng < 5) { |
204 |
pCppArgs[nPos] = (((char *)gpreg) + 3); |
205 |
pUnoArgs[nPos] = (((char *)gpreg) + 3); |
206 |
ng++; |
207 |
gpreg++; |
208 |
} else { |
209 |
pCppArgs[nPos] = (((char *)ovrflw) + 3); |
210 |
pUnoArgs[nPos] = (((char *)ovrflw) + 3); |
211 |
ovrflw++; |
212 |
} |
213 |
break; |
214 |
|
215 |
|
216 |
case typelib_TypeClass_CHAR: |
217 |
case typelib_TypeClass_SHORT: |
218 |
case typelib_TypeClass_UNSIGNED_SHORT: |
219 |
if (ng < 5) { |
220 |
pCppArgs[nPos] = (((char *)gpreg)+ 2); |
221 |
pUnoArgs[nPos] = (((char *)gpreg)+ 2); |
222 |
ng++; |
223 |
gpreg++; |
224 |
} else { |
225 |
pCppArgs[nPos] = (((char *)ovrflw) + 2); |
226 |
pUnoArgs[nPos] = (((char *)ovrflw) + 2); |
227 |
ovrflw++; |
228 |
} |
229 |
break; |
230 |
|
231 |
|
232 |
default: |
233 |
if (ng < 5) { |
234 |
pCppArgs[nPos] = gpreg; |
235 |
pUnoArgs[nPos] = gpreg; |
236 |
ng++; |
237 |
gpreg++; |
238 |
} else { |
239 |
pCppArgs[nPos] = ovrflw; |
240 |
pUnoArgs[nPos] = ovrflw; |
241 |
ovrflw++; |
242 |
} |
243 |
break; |
244 |
|
245 |
} |
246 |
// no longer needed |
247 |
TYPELIB_DANGER_RELEASE( pParamTypeDescr ); |
248 |
} |
249 |
else // ptr to complex value | ref |
250 |
{ |
251 |
|
252 |
if (ng < 5) { |
253 |
pCppArgs[nPos] = *(void **)gpreg; |
254 |
pCppStack = gpreg; |
255 |
ng++; |
256 |
gpreg++; |
257 |
} else { |
258 |
pCppArgs[nPos] = *(void **)ovrflw; |
259 |
pCppStack = ovrflw; |
260 |
ovrflw++; |
261 |
} |
262 |
|
263 |
if (! rParam.bIn) // is pure out |
264 |
{ |
265 |
// uno out is unconstructed mem! |
266 |
pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ); |
267 |
pTempIndizes[nTempIndizes] = nPos; |
268 |
// will be released at reconversion |
269 |
ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr; |
270 |
} |
271 |
// is in/inout |
272 |
else if (cppu_relatesToInterface( pParamTypeDescr )) |
273 |
{ |
274 |
uno_copyAndConvertData( pUnoArgs[nPos] = alloca( pParamTypeDescr->nSize ), |
275 |
*(void **)pCppStack, pParamTypeDescr, |
276 |
&pThis->pBridge->aCpp2Uno ); |
277 |
pTempIndizes[nTempIndizes] = nPos; // has to be reconverted |
278 |
// will be released at reconversion |
279 |
ppTempParamTypeDescr[nTempIndizes++] = pParamTypeDescr; |
280 |
} |
281 |
else // direct way |
282 |
{ |
283 |
pUnoArgs[nPos] = *(void **)pCppStack; |
284 |
// no longer needed |
285 |
TYPELIB_DANGER_RELEASE( pParamTypeDescr ); |
286 |
} |
287 |
} |
288 |
} |
289 |
|
290 |
// ExceptionHolder |
291 |
uno_Any aUnoExc; // Any will be constructed by callee |
292 |
uno_Any * pUnoExc = &aUnoExc; |
293 |
|
294 |
// invoke uno dispatch call |
295 |
(*pThis->pUnoI->pDispatcher)( pThis->pUnoI, pMemberTypeDescr, pUnoReturn, pUnoArgs, &pUnoExc ); |
296 |
|
297 |
// in case an exception occured... |
298 |
if (pUnoExc) |
299 |
{ |
300 |
// destruct temporary in/inout params |
301 |
for ( ; nTempIndizes--; ) |
302 |
{ |
303 |
sal_Int32 nIndex = pTempIndizes[nTempIndizes]; |
304 |
|
305 |
if (pParams[nIndex].bIn) // is in/inout => was constructed |
306 |
uno_destructData( pUnoArgs[nIndex], ppTempParamTypeDescr[nTempIndizes], 0 ); |
307 |
TYPELIB_DANGER_RELEASE( ppTempParamTypeDescr[nTempIndizes] ); |
308 |
} |
309 |
if (pReturnTypeDescr) |
310 |
TYPELIB_DANGER_RELEASE( pReturnTypeDescr ); |
311 |
|
312 |
raiseException( &aUnoExc, &pThis->pBridge->aUno2Cpp ); // has to destruct the any |
313 |
// is here for dummy |
314 |
return typelib_TypeClass_VOID; |
315 |
} |
316 |
else // else no exception occured... |
317 |
{ |
318 |
// temporary params |
319 |
for ( ; nTempIndizes--; ) |
320 |
{ |
321 |
sal_Int32 nIndex = pTempIndizes[nTempIndizes]; |
322 |
typelib_TypeDescription * pParamTypeDescr = ppTempParamTypeDescr[nTempIndizes]; |
323 |
|
324 |
if (pParams[nIndex].bOut) // inout/out |
325 |
{ |
326 |
// convert and assign |
327 |
uno_destructData( pCppArgs[nIndex], pParamTypeDescr, cpp_release ); |
328 |
uno_copyAndConvertData( pCppArgs[nIndex], pUnoArgs[nIndex], pParamTypeDescr, |
329 |
&pThis->pBridge->aUno2Cpp ); |
330 |
} |
331 |
// destroy temp uno param |
332 |
uno_destructData( pUnoArgs[nIndex], pParamTypeDescr, 0 ); |
333 |
|
334 |
TYPELIB_DANGER_RELEASE( pParamTypeDescr ); |
335 |
} |
336 |
// return |
337 |
if (pCppReturn) // has complex return |
338 |
{ |
339 |
if (pUnoReturn != pCppReturn) // needs reconversion |
340 |
{ |
341 |
uno_copyAndConvertData( pCppReturn, pUnoReturn, pReturnTypeDescr, |
342 |
&pThis->pBridge->aUno2Cpp ); |
343 |
// destroy temp uno return |
344 |
uno_destructData( pUnoReturn, pReturnTypeDescr, 0 ); |
345 |
} |
346 |
// complex return ptr is set to return reg |
347 |
*(void **)pRegisterReturn = pCppReturn; |
348 |
} |
349 |
if (pReturnTypeDescr) |
350 |
{ |
351 |
typelib_TypeClass eRet = (typelib_TypeClass)pReturnTypeDescr->eTypeClass; |
352 |
TYPELIB_DANGER_RELEASE( pReturnTypeDescr ); |
353 |
return eRet; |
354 |
} |
355 |
else |
356 |
return typelib_TypeClass_VOID; |
357 |
} |
358 |
} |
359 |
|
360 |
|
361 |
//================================================================================================== |
362 |
static typelib_TypeClass cpp_mediate( |
363 |
sal_Int32 nVtableCall, |
364 |
void ** gpreg, void ** fpreg, void ** ovrflw, |
365 |
sal_Int64 * pRegisterReturn /* space for register return */ ) |
366 |
{ |
367 |
OSL_ENSURE( sizeof(sal_Int32)==sizeof(void *), "### unexpected!" ); |
368 |
|
369 |
// gpreg: [ret *], this, [other gpr params] |
370 |
// fpreg: [fpr params] |
371 |
// ovrflw: [gpr or fpr params (properly aligned)] |
372 |
|
373 |
// _this_ ptr is patched cppu_XInterfaceProxy object |
374 |
cppu_cppInterfaceProxy * pCppI = NULL; |
375 |
if( nVtableCall & 0x80000000 ) |
376 |
{ |
377 |
nVtableCall &= 0x7fffffff; |
378 |
pCppI = (cppu_cppInterfaceProxy *)(XInterface *)*(gpreg +1); |
379 |
} |
380 |
else |
381 |
{ |
382 |
pCppI = (cppu_cppInterfaceProxy *)(XInterface *)*(gpreg); |
383 |
} |
384 |
|
385 |
typelib_InterfaceTypeDescription * pTypeDescr = pCppI->pTypeDescr; |
386 |
|
387 |
OSL_ENSURE( nVtableCall < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" ); |
388 |
if (nVtableCall >= pTypeDescr->nMapFunctionIndexToMemberIndex) |
389 |
{ |
390 |
throw RuntimeException( |
391 |
OUString::createFromAscii("illegal vtable index!"), |
392 |
(XInterface *)pCppI ); |
393 |
} |
394 |
|
395 |
// determine called method |
396 |
OSL_ENSURE( nVtableCall < pTypeDescr->nMapFunctionIndexToMemberIndex, "### illegal vtable index!" ); |
397 |
sal_Int32 nMemberPos = pTypeDescr->pMapFunctionIndexToMemberIndex[nVtableCall]; |
398 |
OSL_ENSURE( nMemberPos < pTypeDescr->nAllMembers, "### illegal member index!" ); |
399 |
|
400 |
TypeDescription aMemberDescr( pTypeDescr->ppAllMembers[nMemberPos] ); |
401 |
|
402 |
typelib_TypeClass eRet; |
403 |
switch (aMemberDescr.get()->eTypeClass) |
404 |
{ |
405 |
case typelib_TypeClass_INTERFACE_ATTRIBUTE: |
406 |
{ |
407 |
if (pTypeDescr->pMapMemberIndexToFunctionIndex[nMemberPos] == nVtableCall) |
408 |
{ |
409 |
// is GET method |
410 |
eRet = cpp2uno_call( |
411 |
pCppI, aMemberDescr.get(), |
412 |
((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef, |
413 |
0, 0, // no params |
414 |
gpreg, fpreg, ovrflw, pRegisterReturn ); |
415 |
} |
416 |
else |
417 |
{ |
418 |
// is SET method |
419 |
typelib_MethodParameter aParam; |
420 |
aParam.pTypeRef = |
421 |
((typelib_InterfaceAttributeTypeDescription *)aMemberDescr.get())->pAttributeTypeRef; |
422 |
aParam.bIn = sal_True; |
423 |
aParam.bOut = sal_False; |
424 |
|
425 |
eRet = cpp2uno_call( |
426 |
pCppI, aMemberDescr.get(), |
427 |
0, // indicates void return |
428 |
1, &aParam, |
429 |
gpreg, fpreg, ovrflw, pRegisterReturn ); |
430 |
} |
431 |
break; |
432 |
} |
433 |
case typelib_TypeClass_INTERFACE_METHOD: |
434 |
{ |
435 |
// is METHOD |
436 |
switch (nVtableCall) |
437 |
{ |
438 |
case 1: // acquire() |
439 |
pCppI->acquireProxy(); // non virtual call! |
440 |
eRet = typelib_TypeClass_VOID; |
441 |
break; |
442 |
case 2: // release() |
443 |
pCppI->releaseProxy(); // non virtual call! |
444 |
eRet = typelib_TypeClass_VOID; |
445 |
break; |
446 |
case 0: // queryInterface() opt |
447 |
{ |
448 |
typelib_TypeDescription * pTD = 0; |
449 |
TYPELIB_DANGER_GET( &pTD, reinterpret_cast< Type * >( gpreg[2] )->getTypeLibType() ); |
450 |
if (pTD) |
451 |
{ |
452 |
XInterface * pInterface = 0; |
453 |
(*pCppI->pBridge->pCppEnv->getRegisteredInterface)( |
454 |
pCppI->pBridge->pCppEnv, |
455 |
(void **)&pInterface, pCppI->oid.pData, (typelib_InterfaceTypeDescription *)pTD ); |
456 |
|
457 |
if (pInterface) |
458 |
{ |
459 |
::uno_any_construct( |
460 |
reinterpret_cast< uno_Any * >( gpreg[0] ), |
461 |
&pInterface, pTD, cpp_acquire ); |
462 |
pInterface->release(); |
463 |
TYPELIB_DANGER_RELEASE( pTD ); |
464 |
*(void **)pRegisterReturn = gpreg[0]; |
465 |
eRet = typelib_TypeClass_ANY; |
466 |
break; |
467 |
} |
468 |
TYPELIB_DANGER_RELEASE( pTD ); |
469 |
} |
470 |
} // else perform queryInterface() |
471 |
default: |
472 |
eRet = cpp2uno_call( |
473 |
pCppI, aMemberDescr.get(), |
474 |
((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pReturnTypeRef, |
475 |
((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->nParams, |
476 |
((typelib_InterfaceMethodTypeDescription *)aMemberDescr.get())->pParams, |
477 |
gpreg, fpreg, ovrflw, pRegisterReturn ); |
478 |
} |
479 |
break; |
480 |
} |
481 |
default: |
482 |
{ |
483 |
throw RuntimeException( |
484 |
OUString::createFromAscii("no member description found!"), |
485 |
(XInterface *)pCppI ); |
486 |
// is here for dummy |
487 |
eRet = typelib_TypeClass_VOID; |
488 |
} |
489 |
} |
490 |
|
491 |
return eRet; |
492 |
} |
493 |
|
494 |
//================================================================================================== |
495 |
/** |
496 |
* is called on incoming vtable calls |
497 |
* (called by asm snippets) |
498 |
*/ |
499 |
static void cpp_vtable_call( int nTableEntry, void** gpregptr, void** fpregptr, void** ovrflw) |
500 |
{ |
501 |
sal_Int32 gpreg[8]; |
502 |
double fpreg[8]; |
503 |
|
504 |
memcpy( gpreg, gpregptr, 32); |
505 |
memcpy( fpreg, fpregptr, 64); |
506 |
|
507 |
volatile long nRegReturn[2]; |
508 |
|
509 |
sal_Bool bComplex = nTableEntry & 0x80000000 ? sal_True : sal_False; |
510 |
|
511 |
typelib_TypeClass aType = |
512 |
cpp_mediate( nTableEntry, (void**)gpreg, (void**)fpreg, ovrflw, (sal_Int64*)nRegReturn ); |
513 |
|
514 |
switch( aType ) |
515 |
{ |
516 |
|
517 |
// move return value into register space |
518 |
// (will be loaded by machine code snippet) |
519 |
|
520 |
case typelib_TypeClass_BOOLEAN: |
521 |
{ |
522 |
unsigned long tmp = (unsigned long)(*(unsigned char *)nRegReturn); |
523 |
__asm__ volatile ( "l 2,%0\n\t" : : |
524 |
"m"(tmp) : "2" ); |
525 |
break; |
526 |
} |
527 |
case typelib_TypeClass_BYTE: |
528 |
{ |
529 |
long tmp = (long)(*(signed char *)nRegReturn); |
530 |
__asm__ volatile ( "l 2,%0\n\t" : : |
531 |
"m"(tmp) : "2" ); |
532 |
break; |
533 |
} |
534 |
case typelib_TypeClass_CHAR: |
535 |
case typelib_TypeClass_UNSIGNED_SHORT: |
536 |
{ |
537 |
unsigned long tmp = (unsigned long)(*(unsigned short *)nRegReturn); |
538 |
__asm__ volatile ( "l 2,%0\n\t" : : |
539 |
"m"(tmp) : "2" ); |
540 |
break; |
541 |
} |
542 |
case typelib_TypeClass_SHORT: |
543 |
{ |
544 |
long tmp = (long)(*(short *)nRegReturn); |
545 |
__asm__ volatile ( "l 2,%0\n\t" : : |
546 |
"m"(tmp) : "2" ); |
547 |
break; |
548 |
} |
549 |
case typelib_TypeClass_FLOAT: |
550 |
__asm__ volatile ( "le 0,%0\n\t" : : |
551 |
"m" (*((float*)nRegReturn)) : "16" ); |
552 |
break; |
553 |
|
554 |
case typelib_TypeClass_DOUBLE: |
555 |
__asm__ volatile ( "ld 0,%0\n\t" : : |
556 |
"m" (*((double*)nRegReturn)) : "16" ); |
557 |
break; |
558 |
|
559 |
case typelib_TypeClass_HYPER: |
560 |
case typelib_TypeClass_UNSIGNED_HYPER: |
561 |
__asm__ volatile ( "lm 2,3,%0\n\t" : : |
562 |
"m"(nRegReturn[0]) : "2", "3" ); |
563 |
break; |
564 |
|
565 |
default: |
566 |
__asm__ volatile ( "l 2,%0\n\t" : : |
567 |
"m"(nRegReturn[0]) : "2" ); |
568 |
break; |
569 |
} |
570 |
} |
571 |
|
572 |
|
573 |
//================================================================================================== |
574 |
class MediateClassData |
575 |
{ |
576 |
typedef ::std::hash_map< OUString, void *, OUStringHash > t_classdata_map; |
577 |
t_classdata_map m_map; |
578 |
Mutex m_mutex; |
579 |
|
580 |
public: |
581 |
void const * get_vtable( typelib_InterfaceTypeDescription * pTD ) SAL_THROW( () ); |
582 |
|
583 |
inline MediateClassData() SAL_THROW( () ) |
584 |
{} |
585 |
~MediateClassData() SAL_THROW( () ); |
586 |
}; |
587 |
//__________________________________________________________________________________________________ |
588 |
MediateClassData::~MediateClassData() SAL_THROW( () ) |
589 |
{ |
590 |
OSL_TRACE( "> calling ~MediateClassData(): freeing mediate vtables." ); |
591 |
|
592 |
for ( t_classdata_map::const_iterator iPos( m_map.begin() ); iPos != m_map.end(); ++iPos ) |
593 |
{ |
594 |
::rtl_freeMemory( iPos->second ); |
595 |
} |
596 |
} |
597 |
//-------------------------------------------------------------------------------------------------- |
598 |
static inline void codeSnippet( long * code, sal_uInt32 vtable_pos, bool simple_ret_type ) SAL_THROW( () ) |
599 |
{ |
600 |
if (! simple_ret_type) |
601 |
vtable_pos |= 0x80000000; |
602 |
OSL_ASSERT( sizeof (long) == 4 ); |
603 |
|
604 |
/* generate this code */ |
605 |
// lr %r0,%r13 |
606 |
// bras %r13,0x6 |
607 |
// .long cpp_vtable_call |
608 |
// .long vtable_pos |
609 |
// stm %r2,%r6,8(%r15) |
610 |
// std %f0,64(%r15) |
611 |
// std %f2,72(%r15) |
612 |
|
613 |
// l %r2,4(%r13) |
614 |
// la %r3,8(%r15) |
615 |
// la %r4,64(%r15) |
616 |
// la %r5,96(%r15) |
617 |
// l %r1,0(%r13) |
618 |
// lr %r13,%r0 |
619 |
// br %r1 |
620 |
|
621 |
|
622 |
* ((short*)code)++ = 0x180d; |
623 |
* code++ = 0xa7d50006; |
624 |
* code++ = cpp_vtable_call; |
625 |
* code++ = vtable_pos; |
626 |
* code++ = 0x9026f008; |
627 |
* code++ = 0x6000f040; |
628 |
* code++ = 0x6020f048; |
629 |
* code++ = 0x5820d004; |
630 |
* code++ = 0x4130f008; |
631 |
* code++ = 0x4140f040; |
632 |
* code++ = 0x4150f060; |
633 |
* code++ = 0x5810d000; |
634 |
* ((short*)code)++ = 0x18d0; |
635 |
* ((short*)code)++ = 0x07f1; |
636 |
|
637 |
} |
638 |
//__________________________________________________________________________________________________ |
639 |
void const * MediateClassData::get_vtable( typelib_InterfaceTypeDescription * pTD ) SAL_THROW( () ) |
640 |
{ |
641 |
void * buffer; |
642 |
const int nSnippetSize = 50; |
643 |
|
644 |
// avoiding locked counts |
645 |
OUString const & unoName = *(OUString const *)&((typelib_TypeDescription *)pTD)->pTypeName; |
646 |
{ |
647 |
MutexGuard aGuard( m_mutex ); |
648 |
t_classdata_map::const_iterator iFind( m_map.find( unoName ) ); |
649 |
if (iFind == m_map.end()) |
650 |
{ |
651 |
// create new vtable |
652 |
sal_Int32 nSlots = pTD->nMapFunctionIndexToMemberIndex; |
653 |
buffer = ::rtl_allocateMemory( ((2+ nSlots) * sizeof (void *)) + (nSlots *nSnippetSize) ); |
654 |
|
655 |
::std::pair< t_classdata_map::iterator, bool > insertion( |
656 |
m_map.insert( t_classdata_map::value_type( unoName, buffer ) ) ); |
657 |
OSL_ENSURE( insertion.second, "### inserting new vtable buffer failed?!" ); |
658 |
|
659 |
void ** slots = (void **)buffer; |
660 |
*slots++ = 0; |
661 |
*slots++ = 0; // rtti |
662 |
char * code = (char *)(slots + nSlots); |
663 |
|
664 |
sal_uInt32 vtable_pos = 0; |
665 |
sal_Int32 nAllMembers = pTD->nAllMembers; |
666 |
typelib_TypeDescriptionReference ** ppAllMembers = pTD->ppAllMembers; |
667 |
for ( sal_Int32 nPos = 0; nPos < nAllMembers; ++nPos ) |
668 |
{ |
669 |
typelib_TypeDescription * pTD = 0; |
670 |
TYPELIB_DANGER_GET( &pTD, ppAllMembers[ nPos ] ); |
671 |
OSL_ASSERT( pTD ); |
672 |
if (typelib_TypeClass_INTERFACE_ATTRIBUTE == pTD->eTypeClass) |
673 |
{ |
674 |
bool simple_ret = cppu_isSimpleType( |
675 |
((typelib_InterfaceAttributeTypeDescription *)pTD)->pAttributeTypeRef->eTypeClass ); |
676 |
// get method |
677 |
*slots = code; |
678 |
codeSnippet( (long *)code, vtable_pos++, simple_ret ); |
679 |
code += nSnippetSize; |
680 |
slots++; |
681 |
if (! ((typelib_InterfaceAttributeTypeDescription *)pTD)->bReadOnly) |
682 |
{ |
683 |
// set method |
684 |
*slots = code; |
685 |
codeSnippet( (long *)code, vtable_pos++, true ); |
686 |
code += nSnippetSize; |
687 |
slots++; |
688 |
} |
689 |
} |
690 |
else |
691 |
{ |
692 |
bool simple_ret = cppu_isSimpleType( |
693 |
((typelib_InterfaceMethodTypeDescription *)pTD)->pReturnTypeRef->eTypeClass ); |
694 |
*slots = code; |
695 |
codeSnippet( (long *)code, vtable_pos++, simple_ret ); |
696 |
code += nSnippetSize; |
697 |
slots++; |
698 |
} |
699 |
TYPELIB_DANGER_RELEASE( pTD ); |
700 |
} |
701 |
OSL_ASSERT( vtable_pos == nSlots ); |
702 |
} |
703 |
else |
704 |
{ |
705 |
buffer = iFind->second; |
706 |
} |
707 |
} |
708 |
|
709 |
return ((void **)buffer +2); |
710 |
} |
711 |
|
712 |
//================================================================================================== |
713 |
void SAL_CALL cppu_cppInterfaceProxy_patchVtable( |
714 |
XInterface * pCppI, typelib_InterfaceTypeDescription * pTypeDescr ) throw () |
715 |
{ |
716 |
static MediateClassData * s_pMediateClassData = 0; |
717 |
if (! s_pMediateClassData) |
718 |
{ |
719 |
MutexGuard aGuard( Mutex::getGlobalMutex() ); |
720 |
if (! s_pMediateClassData) |
721 |
{ |
722 |
#ifdef LEAK_STATIC_DATA |
723 |
s_pMediateClassData = new MediateClassData(); |
724 |
#else |
725 |
static MediateClassData s_aMediateClassData; |
726 |
s_pMediateClassData = &s_aMediateClassData; |
727 |
#endif |
728 |
} |
729 |
} |
730 |
*(void const **)pCppI = s_pMediateClassData->get_vtable( pTypeDescr ); |
731 |
} |
732 |
|
733 |
} |
734 |
|
735 |
extern "C" |
736 |
{ |
737 |
//################################################################################################## |
738 |
sal_Bool SAL_CALL component_canUnload( TimeValue * pTime ) |
739 |
SAL_THROW_EXTERN_C() |
740 |
{ |
741 |
return CPPU_CURRENT_NAMESPACE::g_moduleCount.canUnload( |
742 |
&CPPU_CURRENT_NAMESPACE::g_moduleCount, pTime ); |
743 |
} |
744 |
//################################################################################################## |
745 |
void SAL_CALL uno_initEnvironment( uno_Environment * pCppEnv ) |
746 |
SAL_THROW_EXTERN_C() |
747 |
{ |
748 |
CPPU_CURRENT_NAMESPACE::cppu_cppenv_initEnvironment( |
749 |
pCppEnv ); |
750 |
} |
751 |
//################################################################################################## |
752 |
void SAL_CALL uno_ext_getMapping( |
753 |
uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo ) |
754 |
SAL_THROW_EXTERN_C() |
755 |
{ |
756 |
CPPU_CURRENT_NAMESPACE::cppu_ext_getMapping( |
757 |
ppMapping, pFrom, pTo ); |
758 |
} |
759 |
} |