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
* regs
, sal_uInt64
* stack
, sal_Int32 sp
,
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 void** cppArgs
= static_cast<void**>(alloca(count
* sizeof(void*)));
72 typelib_TypeDescription
** ptds
73 = static_cast<typelib_TypeDescription
**>(alloca(count
* sizeof(typelib_TypeDescription
*)));
75 sal_uInt64
* gpr
= static_cast<sal_uInt64
*>(alloca(16 * sizeof(sal_uInt64
)));
76 sal_uInt64
* fpr
= &gpr
[8];
77 sal_uInt64
* stack
= static_cast<sal_uInt64
*>(alloca(count
* sizeof(sal_uInt64
)));
82 gpr
[nGPR
++] = reinterpret_cast<sal_uInt64
>(thisPtr
);
83 if (eRetKind
== RETURN_KIND_INDIRECT
)
85 gpr
[nGPR
++] = reinterpret_cast<sal_uInt64
>(ret
);
88 for (sal_Int32 i
= 0; i
!= count
; ++i
)
90 if (!parameters
[i
].bOut
&& bridges::cpp_uno::shared::isSimpleType(parameters
[i
].pTypeRef
))
93 switch (parameters
[i
].pTypeRef
->eTypeClass
)
95 case typelib_TypeClass_BOOLEAN
:
96 pushArgument(*static_cast<sal_Bool
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
98 case typelib_TypeClass_BYTE
:
99 pushArgument(*static_cast<sal_Int8
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
101 case typelib_TypeClass_SHORT
:
102 pushArgument(*static_cast<sal_Int16
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
104 case typelib_TypeClass_UNSIGNED_SHORT
:
105 pushArgument(*static_cast<sal_uInt16
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
107 case typelib_TypeClass_LONG
:
108 case typelib_TypeClass_ENUM
:
109 pushArgument(*static_cast<sal_Int32
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
111 case typelib_TypeClass_UNSIGNED_LONG
:
112 pushArgument(*static_cast<sal_uInt32
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
114 case typelib_TypeClass_HYPER
:
115 pushArgument(*static_cast<sal_Int64
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
117 case typelib_TypeClass_UNSIGNED_HYPER
:
118 pushArgument(*static_cast<sal_uInt64
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
120 case typelib_TypeClass_FLOAT
:
121 pushArgument(*static_cast<sal_uInt32
*>(arguments
[i
]), stack
, sp
, fpr
, nFPR
);
123 case typelib_TypeClass_DOUBLE
:
124 pushArgument(*static_cast<sal_uInt64
*>(arguments
[i
]), stack
, sp
, fpr
, nFPR
);
126 case typelib_TypeClass_CHAR
:
127 pushArgument(*static_cast<sal_Unicode
*>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
135 typelib_TypeDescription
* ptd
= 0;
136 TYPELIB_DANGER_GET(&ptd
, parameters
[i
].pTypeRef
);
137 if (!parameters
[i
].bIn
)
139 cppArgs
[i
] = alloca(ptd
->nSize
);
140 uno_constructData(cppArgs
[i
], ptd
);
142 pushArgument(reinterpret_cast<sal_uInt64
>(cppArgs
[i
]), stack
, sp
, gpr
, nGPR
);
144 else if (bridges::cpp_uno::shared::relatesToInterfaceType(ptd
))
146 cppArgs
[i
] = alloca(ptd
->nSize
);
147 uno_copyAndConvertData(cppArgs
[i
], arguments
[i
], ptd
,
148 pProxy
->getBridge()->getUno2Cpp());
150 pushArgument(reinterpret_cast<sal_uInt64
>(cppArgs
[i
]), stack
, sp
, gpr
, nGPR
);
155 pushArgument(reinterpret_cast<sal_uInt64
>(arguments
[i
]), stack
, sp
, gpr
, nGPR
);
156 TYPELIB_DANGER_RELEASE(ptd
);
163 callVirtualFunction(gpr
, stack
, sp
, (*thisPtr
)[slot
.index
]);
165 __except (msvc_filterCppException(GetExceptionInformation(), *exception
,
166 pProxy
->getBridge()->getCpp2Uno()))
168 for (sal_Int32 i
= 0; i
!= count
; ++i
)
172 uno_destructData(cppArgs
[i
], ptds
[i
],
173 reinterpret_cast<uno_ReleaseFunc
>(css::uno::cpp_release
));
174 TYPELIB_DANGER_RELEASE(ptds
[i
]);
177 TYPELIB_DANGER_RELEASE(aReturnTD
);
182 for (sal_Int32 i
= 0; i
!= count
; ++i
)
186 if (parameters
[i
].bOut
)
188 if (parameters
[i
].bIn
)
190 uno_destructData(arguments
[i
], ptds
[i
], 0);
192 uno_copyAndConvertData(arguments
[i
], cppArgs
[i
], ptds
[i
],
193 pProxy
->getBridge()->getCpp2Uno());
195 uno_destructData(cppArgs
[i
], ptds
[i
],
196 reinterpret_cast<uno_ReleaseFunc
>(css::uno::cpp_release
));
197 TYPELIB_DANGER_RELEASE(ptds
[i
]);
203 case RETURN_KIND_REG
:
204 switch (aReturnTD
->eTypeClass
)
206 case typelib_TypeClass_VOID
:
208 case typelib_TypeClass_BOOLEAN
:
209 case typelib_TypeClass_BYTE
:
210 case typelib_TypeClass_SHORT
:
211 case typelib_TypeClass_UNSIGNED_SHORT
:
212 case typelib_TypeClass_LONG
:
213 case typelib_TypeClass_UNSIGNED_LONG
:
214 case typelib_TypeClass_HYPER
:
215 case typelib_TypeClass_UNSIGNED_HYPER
:
216 case typelib_TypeClass_CHAR
:
217 case typelib_TypeClass_ENUM
:
218 case typelib_TypeClass_STRUCT
:
219 std::memcpy(ret
, gpr
, aReturnTD
->nSize
);
221 case typelib_TypeClass_FLOAT
:
222 case typelib_TypeClass_DOUBLE
:
223 std::memcpy(ret
, fpr
, aReturnTD
->nSize
);
229 case RETURN_KIND_INDIRECT
:
235 uno_copyAndConvertData(returnValue
, ret
, aReturnTD
, pProxy
->getBridge()->getCpp2Uno());
236 uno_destructData(ret
, aReturnTD
, reinterpret_cast<uno_ReleaseFunc
>(css::uno::cpp_release
));
238 TYPELIB_DANGER_RELEASE(aReturnTD
);
242 namespace bridges::cpp_uno::shared
244 void unoInterfaceProxyDispatch(uno_Interface
* pUnoI
, typelib_TypeDescription
const* pMemberDescr
,
245 void* pReturn
, void** pArgs
, uno_Any
** ppException
)
247 UnoInterfaceProxy
* pProxy
= static_cast<UnoInterfaceProxy
*>(pUnoI
);
248 switch (pMemberDescr
->eTypeClass
)
250 case typelib_TypeClass_INTERFACE_ATTRIBUTE
:
252 typelib_InterfaceAttributeTypeDescription
const* atd
253 = reinterpret_cast<typelib_InterfaceAttributeTypeDescription
const*>(pMemberDescr
);
254 VtableSlot
slot(getVtableSlot(atd
));
257 call(pProxy
, slot
, atd
->pAttributeTypeRef
, 0, 0, pReturn
, pArgs
, ppException
);
261 typelib_MethodParameter param
= { 0, atd
->pAttributeTypeRef
, true, false };
262 typelib_TypeDescriptionReference
* pReturnTD
= nullptr;
263 typelib_typedescriptionreference_new(&pReturnTD
, typelib_TypeClass_VOID
,
264 OUString("void").pData
);
266 call(pProxy
, slot
, pReturnTD
, 1, ¶m
, pReturn
, pArgs
, ppException
);
267 typelib_typedescriptionreference_release(pReturnTD
);
271 case typelib_TypeClass_INTERFACE_METHOD
:
273 typelib_InterfaceMethodTypeDescription
const* mtd
274 = reinterpret_cast<typelib_InterfaceMethodTypeDescription
const*>(pMemberDescr
);
275 VtableSlot
slot(getVtableSlot(mtd
));
279 pUnoI
->acquire(pUnoI
);
283 pUnoI
->release(pUnoI
);
288 typelib_TypeDescription
* td
= 0;
290 &td
, (reinterpret_cast<css::uno::Type
*>(pArgs
[0])->getTypeLibType()));
293 uno_Interface
* ifc
= 0;
294 pProxy
->pBridge
->getUnoEnv()->getRegisteredInterface(
295 pProxy
->pBridge
->getUnoEnv(), reinterpret_cast<void**>(&ifc
),
297 reinterpret_cast<typelib_InterfaceTypeDescription
*>(td
));
300 uno_any_construct(reinterpret_cast<uno_Any
*>(pReturn
), &ifc
, td
, 0);
302 TYPELIB_DANGER_RELEASE(td
);
306 TYPELIB_DANGER_RELEASE(td
);
311 call(pProxy
, slot
, mtd
->pReturnTypeRef
, mtd
->nParams
, mtd
->pParams
, pReturn
,
323 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */