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>
29 #include <unointerfaceproxy.hxx>
30 #include <vtables.hxx>
31 #include <com/sun/star/uno/Exception.hpp>
32 #include <com/sun/star/uno/RuntimeException.hpp>
33 #include <com/sun/star/uno/genfunc.hxx>
34 #include <rtl/textenc.h>
35 #include <rtl/ustring.hxx>
36 #include <sal/alloca.h>
37 #include <sal/types.h>
38 #include <typelib/typeclass.h>
39 #include <typelib/typedescription.h>
44 #include <msvc/arm64.hxx>
48 extern "C" void callVirtualFunction(sal_uInt64
* stack
, sal_uInt64
* frame
, sal_uInt64 function
,
51 void pushArgument(sal_uInt64 value
, sal_uInt64
* stack
, sal_Int32
& sp
, sal_uInt64
* regs
,
54 (nregs
!= 8 ? regs
[nregs
++] : stack
[sp
++]) = value
;
57 void call(bridges::cpp_uno::shared::UnoInterfaceProxy
* pProxy
,
58 bridges::cpp_uno::shared::VtableSlot slot
, typelib_TypeDescriptionReference
* returnType
,
59 const sal_Int32 count
, typelib_MethodParameter
* parameters
, void* returnValue
,
60 void** arguments
, uno_Any
** exception
)
62 static_assert(sizeof(sal_uInt64
) == sizeof(void*));
63 typelib_TypeDescription
* aReturnTD
= nullptr;
64 TYPELIB_DANGER_GET(&aReturnTD
, returnType
);
65 const ReturnKind eRetKind
= getReturnKind(aReturnTD
);
66 const bool retConv
= bridges::cpp_uno::shared::relatesToInterfaceType(aReturnTD
);
67 void* ret
= retConv
? alloca(aReturnTD
->nSize
) : returnValue
;
69 sal_uInt64
** thisPtr
= reinterpret_cast<sal_uInt64
**>(pProxy
->getCppI()) + slot
.offset
;
71 sal_uInt64
* gpr
= static_cast<sal_uInt64
*>(alloca((count
+ 16) * sizeof(sal_uInt64
) + 32));
72 sal_uInt64
* fpr
= &gpr
[8];
73 sal_uInt64
* stack
= &gpr
[16];
74 sal_uInt64
* frame
= &gpr
[16 + count
];
75 void** cppArgs
= static_cast<void**>(alloca(count
* sizeof(void*)));
76 typelib_TypeDescription
** ptds
77 = static_cast<typelib_TypeDescription
**>(alloca(count
* sizeof(typelib_TypeDescription
*)));
82 gpr
[nGPR
++] = reinterpret_cast<sal_uInt64
>(thisPtr
);
84 for (sal_Int32 i
= 0; i
!= count
; ++i
)
86 if (!parameters
[i
].bOut
&& bridges::cpp_uno::shared::isSimpleType(parameters
[i
].pTypeRef
))
89 switch (parameters
[i
].pTypeRef
->eTypeClass
)
91 case typelib_TypeClass_BOOLEAN
:
92 pushArgument(*static_cast<sal_Bool
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
94 case typelib_TypeClass_BYTE
:
95 pushArgument(*static_cast<sal_Int8
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
97 case typelib_TypeClass_SHORT
:
98 pushArgument(*static_cast<sal_Int16
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
100 case typelib_TypeClass_UNSIGNED_SHORT
:
101 pushArgument(*static_cast<sal_uInt16
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
103 case typelib_TypeClass_LONG
:
104 case typelib_TypeClass_ENUM
:
105 pushArgument(*static_cast<sal_Int32
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
107 case typelib_TypeClass_UNSIGNED_LONG
:
108 pushArgument(*static_cast<sal_uInt32
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
110 case typelib_TypeClass_HYPER
:
111 pushArgument(*static_cast<sal_Int64
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
113 case typelib_TypeClass_UNSIGNED_HYPER
:
114 pushArgument(*static_cast<sal_uInt64
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
116 case typelib_TypeClass_FLOAT
:
117 pushArgument(*static_cast<sal_uInt32
*>(arguments
[i
]), stack
, sp
, fpr
, nFPR
);
119 case typelib_TypeClass_DOUBLE
:
120 pushArgument(*static_cast<sal_uInt64
*>(arguments
[i
]), stack
, sp
, fpr
, nFPR
);
122 case typelib_TypeClass_CHAR
:
123 pushArgument(*static_cast<sal_Unicode
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
131 typelib_TypeDescription
* ptd
= 0;
132 TYPELIB_DANGER_GET(&ptd
, parameters
[i
].pTypeRef
);
133 if (!parameters
[i
].bIn
)
135 cppArgs
[i
] = alloca(ptd
->nSize
);
136 uno_constructData(cppArgs
[i
], ptd
);
138 pushArgument(reinterpret_cast<sal_uInt64
>(cppArgs
[i
]), stack
, sp
, gpr
, nGPR
);
140 else if (bridges::cpp_uno::shared::relatesToInterfaceType(ptd
))
142 cppArgs
[i
] = alloca(ptd
->nSize
);
143 uno_copyAndConvertData(cppArgs
[i
], arguments
[i
], ptd
,
144 pProxy
->getBridge()->getUno2Cpp());
146 pushArgument(reinterpret_cast<sal_uInt64
>(cppArgs
[i
]), stack
, sp
, gpr
, nGPR
);
151 pushArgument(reinterpret_cast<sal_uInt64
>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
152 TYPELIB_DANGER_RELEASE(ptd
);
159 callVirtualFunction(stack
, frame
, (*thisPtr
)[slot
.index
], ret
);
161 __except (msvc_filterCppException(GetExceptionInformation(), *exception
,
162 pProxy
->getBridge()->getCpp2Uno()))
164 for (sal_Int32 i
= 0; i
!= count
; ++i
)
168 uno_destructData(cppArgs
[i
], ptds
[i
],
169 reinterpret_cast<uno_ReleaseFunc
>(css::uno::cpp_release
));
170 TYPELIB_DANGER_RELEASE(ptds
[i
]);
173 TYPELIB_DANGER_RELEASE(aReturnTD
);
178 for (sal_Int32 i
= 0; i
!= count
; ++i
)
182 if (parameters
[i
].bOut
)
184 if (parameters
[i
].bIn
)
186 uno_destructData(arguments
[i
], ptds
[i
], 0);
188 uno_copyAndConvertData(arguments
[i
], cppArgs
[i
], ptds
[i
],
189 pProxy
->getBridge()->getCpp2Uno());
191 uno_destructData(cppArgs
[i
], ptds
[i
],
192 reinterpret_cast<uno_ReleaseFunc
>(css::uno::cpp_release
));
193 TYPELIB_DANGER_RELEASE(ptds
[i
]);
199 case RETURN_KIND_REG
:
200 switch (aReturnTD
->eTypeClass
)
202 case typelib_TypeClass_VOID
:
204 case typelib_TypeClass_BOOLEAN
:
205 case typelib_TypeClass_BYTE
:
206 case typelib_TypeClass_SHORT
:
207 case typelib_TypeClass_UNSIGNED_SHORT
:
208 case typelib_TypeClass_LONG
:
209 case typelib_TypeClass_UNSIGNED_LONG
:
210 case typelib_TypeClass_HYPER
:
211 case typelib_TypeClass_UNSIGNED_HYPER
:
212 case typelib_TypeClass_CHAR
:
213 case typelib_TypeClass_ENUM
:
214 case typelib_TypeClass_STRUCT
:
215 std::memcpy(ret
, gpr
, aReturnTD
->nSize
);
217 case typelib_TypeClass_FLOAT
:
218 case typelib_TypeClass_DOUBLE
:
219 std::memcpy(ret
, fpr
, aReturnTD
->nSize
);
225 case RETURN_KIND_HFA_FLOAT
:
226 switch (aReturnTD
->nSize
)
229 std::memcpy(static_cast<char*>(ret
) + 12, fpr
+ 3, 4);
232 std::memcpy(static_cast<char*>(ret
) + 8, fpr
+ 2, 4);
235 std::memcpy(static_cast<char*>(ret
) + 4, fpr
+ 1, 4);
238 std::memcpy(ret
, fpr
, 4);
244 case RETURN_KIND_HFA_DOUBLE
:
245 std::memcpy(ret
, fpr
, aReturnTD
->nSize
);
247 case RETURN_KIND_INDIRECT
:
253 uno_copyAndConvertData(returnValue
, ret
, aReturnTD
, pProxy
->getBridge()->getCpp2Uno());
254 uno_destructData(ret
, aReturnTD
, reinterpret_cast<uno_ReleaseFunc
>(css::uno::cpp_release
));
256 TYPELIB_DANGER_RELEASE(aReturnTD
);
260 namespace bridges::cpp_uno::shared
262 void unoInterfaceProxyDispatch(uno_Interface
* pUnoI
, typelib_TypeDescription
const* pMemberDescr
,
263 void* pReturn
, void** pArgs
, uno_Any
** ppException
)
265 UnoInterfaceProxy
* pProxy
= static_cast<UnoInterfaceProxy
*>(pUnoI
);
266 switch (pMemberDescr
->eTypeClass
)
268 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
270 typelib_InterfaceAttributeTypeDescription
const* atd
271 = reinterpret_cast<typelib_InterfaceAttributeTypeDescription
const*>(pMemberDescr
);
272 VtableSlot
slot(getVtableSlot(atd
));
275 call(pProxy
, slot
, atd
->pAttributeTypeRef
, 0, 0, pReturn
, pArgs
, ppException
);
279 typelib_MethodParameter param
= { 0, atd
->pAttributeTypeRef
, true, false };
280 typelib_TypeDescriptionReference
* pReturnTD
= nullptr;
281 typelib_typedescriptionreference_new(&pReturnTD
, typelib_TypeClass_VOID
,
282 OUString("void").pData
);
284 call(pProxy
, slot
, pReturnTD
, 1, ¶m
, pReturn
, pArgs
, ppException
);
285 typelib_typedescriptionreference_release(pReturnTD
);
289 case typelib_TypeClass_INTERFACE_METHOD
:
291 typelib_InterfaceMethodTypeDescription
const* mtd
292 = reinterpret_cast<typelib_InterfaceMethodTypeDescription
const*>(pMemberDescr
);
293 VtableSlot
slot(getVtableSlot(mtd
));
297 pUnoI
->acquire(pUnoI
);
301 pUnoI
->release(pUnoI
);
306 typelib_TypeDescription
* td
= 0;
308 &td
, (reinterpret_cast<css::uno::Type
*>(pArgs
[0])->getTypeLibType()));
311 uno_Interface
* ifc
= 0;
312 pProxy
->pBridge
->getUnoEnv()->getRegisteredInterface(
313 pProxy
->pBridge
->getUnoEnv(), reinterpret_cast<void**>(&ifc
),
315 reinterpret_cast<typelib_InterfaceTypeDescription
*>(td
));
318 uno_any_construct(reinterpret_cast<uno_Any
*>(pReturn
), &ifc
, td
, 0);
320 TYPELIB_DANGER_RELEASE(td
);
324 TYPELIB_DANGER_RELEASE(td
);
329 call(pProxy
, slot
, mtd
->pReturnTypeRef
, mtd
->nParams
, mtd
->pParams
, pReturn
,
341 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */