1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
24 #include <cppu/macros.hxx>
25 #include <sal/types.h>
26 #include <typelib/typeclass.h>
27 #include <typelib/typedescription.h>
30 #include "callvirtualmethod.hxx"
32 // The call instruction within the asm block of callVirtualMethod may throw
33 // exceptions. At least GCC 4.7.0 with -O0 would create (unnecessary)
34 // .gcc_exception_table call-site table entries around all other calls in this
35 // function that can throw, leading to std::terminate if the asm call throws an
36 // exception and the unwinding C++ personality routine finds the unexpected hole
37 // in the .gcc_exception_table. Therefore, make sure this function explicitly
38 // only calls nothrow-functions (so GCC 4.7.0 with -O0 happens to not create a
39 // .gcc_exception_table section at all for this function). For some reason,
40 // this also needs to be in a source file of its own.
42 // Also, this file should be compiled with -fnon-call-exceptions, and ideally
43 // there would be a way to tell the compiler that the asm block contains calls
44 // to functions that can potentially throw; see the mail thread starting at
45 // <http://gcc.gnu.org/ml/gcc/2012-03/msg00454.html> "C++: Letting compiler know
46 // asm block can call function that can throw?"
48 void CPPU_CURRENT_NAMESPACE::callVirtualMethod(
49 void * pThis
, sal_uInt32 nVtableIndex
, void * pRegisterReturn
,
50 typelib_TypeDescriptionReference
* pReturnTypeRef
, bool bSimpleReturn
,
51 sal_uInt64
*pStack
, sal_uInt32 nStack
, sal_uInt64
*pGPR
, double * pFPR
)
53 // Work around -fsanitize=address "inline assembly requires more registers
54 // than available" error:
72 // Get pointer to method
73 sal_uInt64 pMethod
= *static_cast<sal_uInt64
*>(pThis
);
74 pMethod
+= 8 * nVtableIndex
;
75 data
.pMethod
= *reinterpret_cast<sal_uInt64
*>(pMethod
);
78 // Push arguments to stack
79 "movq %%rsp, %%r12\n\t"
80 "movl 16%0, %%ecx\n\t"
82 "xor %%rax, %%rax\n\t"
83 "leaq (%%rax, %%rcx, 8), %%rax\n\t"
84 "subq %%rax, %%rsp\n\t"
85 "andq $-9, %%rsp\n\t" // 16-bytes aligned
89 "movq (%%rsi, %%rcx, 8), %%rax\n\t"
90 "movq %%rax, (%%rsp, %%rcx, 8)\n\t"
94 // Fill the xmm registers
95 "movq 32%0, %%rax\n\t"
97 "movsd (%%rax), %%xmm0\n\t"
98 "movsd 8(%%rax), %%xmm1\n\t"
99 "movsd 16(%%rax), %%xmm2\n\t"
100 "movsd 24(%%rax), %%xmm3\n\t"
101 "movsd 32(%%rax), %%xmm4\n\t"
102 "movsd 40(%%rax), %%xmm5\n\t"
103 "movsd 48(%%rax), %%xmm6\n\t"
104 "movsd 56(%%rax), %%xmm7\n\t"
106 // Fill the general purpose registers
107 "movq 24%0, %%rax\n\t"
109 "movq (%%rax), %%rdi\n\t"
110 "movq 8(%%rax), %%rsi\n\t"
111 "movq 16(%%rax), %%rdx\n\t"
112 "movq 24(%%rax), %%rcx\n\t"
113 "movq 32(%%rax), %%r8\n\t"
114 "movq 40(%%rax), %%r9\n\t"
117 "movq 0%0, %%r11\n\t"
120 // Fill the return values
121 "movq %%rax, 40%0\n\t"
122 "movq %%rdx, 48%0\n\t"
123 "movsd %%xmm0, 56%0\n\t"
124 "movsd %%xmm1, 64%0\n\t"
127 "movq %%r12, %%rsp\n\t"
129 : "rax", "rdi", "rsi", "rdx", "rcx", "r8", "r9", "r10", "r11", "r12",
130 "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7",
131 "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15",
135 switch (pReturnTypeRef
->eTypeClass
)
137 case typelib_TypeClass_HYPER
:
138 case typelib_TypeClass_UNSIGNED_HYPER
:
139 *static_cast<sal_uInt64
*>( pRegisterReturn
) = data
.rax
;
141 case typelib_TypeClass_LONG
:
142 case typelib_TypeClass_UNSIGNED_LONG
:
143 case typelib_TypeClass_ENUM
:
144 *static_cast<sal_uInt32
*>( pRegisterReturn
) = *reinterpret_cast<sal_uInt32
*>( &data
.rax
);
146 case typelib_TypeClass_CHAR
:
147 case typelib_TypeClass_SHORT
:
148 case typelib_TypeClass_UNSIGNED_SHORT
:
149 *static_cast<sal_uInt16
*>( pRegisterReturn
) = *reinterpret_cast<sal_uInt16
*>( &data
.rax
);
151 case typelib_TypeClass_BOOLEAN
:
152 case typelib_TypeClass_BYTE
:
153 *static_cast<sal_uInt8
*>( pRegisterReturn
) = *reinterpret_cast<sal_uInt8
*>( &data
.rax
);
155 case typelib_TypeClass_FLOAT
:
156 case typelib_TypeClass_DOUBLE
:
157 *static_cast<double *>( pRegisterReturn
) = data
.xmm0
;
161 sal_Int32
const nRetSize
= pReturnTypeRef
->pType
->nSize
;
162 if (bSimpleReturn
&& nRetSize
<= 16 && nRetSize
> 0)
169 doubles
[0] = data
.xmm0
;
170 doubles
[1] = data
.xmm1
;
171 x86_64::fill_struct( pReturnTypeRef
, &longs
[0], &doubles
[0], pRegisterReturn
);
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */