1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 #include "sal/config.h"
31 #include "cppu/macros.hxx"
32 #include "osl/diagnose.h"
33 #include "sal/types.h"
34 #include "typelib/typeclass.h"
35 #include "typelib/typedescription.h"
37 #include "callvirtualmethod.hxx"
39 #include "smallstruct.hxx"
41 // For some reason, callVirtualMethod needs to be in a source file of its own,
42 // so that stack unwinding upon a thrown exception from within the asm block
43 // call works, at least with GCC 4.7.0 and --enable-dbgutil.
45 // The call instruction within the asm section of callVirtualMethod may throw
46 // exceptions. So that the compiler handles this correctly, it is important
47 // that (a) callVirtualMethod might call dummy_can_throw_anything (although this
48 // never happens at runtime), which in turn can throw exceptions, and (b)
49 // callVirtualMethod is not inlined at its call site (so that any exceptions are
50 // caught which are thrown from the instruction calling callVirtualMethod). [It
51 // is unclear how much of this comment is still relevent -- see the above
53 void CPPU_CURRENT_NAMESPACE::callVirtualMethod(
54 void * pAdjustedThisPtr
, sal_Int32 nVtableIndex
, void * pRegisterReturn
,
55 typelib_TypeDescription
const * returnType
, sal_Int32
* pStackLongs
,
56 sal_Int32 nStackLongs
)
58 // parameter list is mixed list of * and values
59 // reference parameters are pointers
61 OSL_ENSURE( pStackLongs
&& pAdjustedThisPtr
, "### null ptr!" );
62 OSL_ENSURE( (sizeof(void *) == 4) && (sizeof(sal_Int32
) == 4), "### unexpected size of int!" );
63 OSL_ENSURE( nStackLongs
&& pStackLongs
, "### no stack in callVirtualMethod !" );
66 if (! pAdjustedThisPtr
) CPPU_CURRENT_NAMESPACE::dummy_can_throw_anything("xxx"); // address something
68 volatile long edx
= 0, eax
= 0; // for register returns
74 "mov %%eax, %%edx\n\t"
85 "mov 0(%%edx), %%edx\n\t"
88 "add %%eax, %%edx\n\t"
89 "mov 0(%%edx), %%edx\n\t"
91 // save return registers
97 : "m"(nStackLongs
), "m"(pStackLongs
), "m"(pAdjustedThisPtr
),
98 "m"(nVtableIndex
), "m"(eax
), "m"(edx
), "m"(stackptr
)
99 : "eax", "ecx", "edx" );
100 switch( returnType
->eTypeClass
)
102 case typelib_TypeClass_VOID
:
104 case typelib_TypeClass_HYPER
:
105 case typelib_TypeClass_UNSIGNED_HYPER
:
106 ((long*)pRegisterReturn
)[1] = edx
;
107 case typelib_TypeClass_LONG
:
108 case typelib_TypeClass_UNSIGNED_LONG
:
109 case typelib_TypeClass_CHAR
:
110 case typelib_TypeClass_ENUM
:
111 ((long*)pRegisterReturn
)[0] = eax
;
113 case typelib_TypeClass_SHORT
:
114 case typelib_TypeClass_UNSIGNED_SHORT
:
115 *(unsigned short*)pRegisterReturn
= eax
;
117 case typelib_TypeClass_BOOLEAN
:
118 case typelib_TypeClass_BYTE
:
119 *(unsigned char*)pRegisterReturn
= eax
;
121 case typelib_TypeClass_FLOAT
:
122 asm ( "fstps %0" : : "m"(*(char *)pRegisterReturn
) );
124 case typelib_TypeClass_DOUBLE
:
125 asm ( "fstpl %0\n\t" : : "m"(*(char *)pRegisterReturn
) );
127 case typelib_TypeClass_STRUCT
:
128 if (bridges::cpp_uno::shared::isSmallStruct(returnType
)) {
129 if (returnType
->nSize
<= 1) {
130 *(unsigned char*)pRegisterReturn
= eax
;
132 else if (returnType
->nSize
<= 2) {
133 *(unsigned short*)pRegisterReturn
= eax
;
135 else if (returnType
->nSize
<= 8) {
136 ((long*)pRegisterReturn
)[0] = eax
;
137 if (returnType
->nSize
> 4) {
138 ((long*)pRegisterReturn
)[1] = edx
;
148 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */