xref: /trunk/main/bridges/source/cpp_uno/msvc_win64_x86-64/abi.cxx (revision 45c5a00162811bd03b87fcb4fe9996782f2b59ec)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_bridges.hxx"
26 
27 #include "abi.hxx"
28 
29 #include <rtl/ustring.hxx>
30 
31 using namespace x86_64;
32 
33 bool x86_64::return_in_hidden_param( typelib_TypeDescriptionReference *pTypeRef )
34 {
35     switch ( pTypeRef->eTypeClass )
36     {
37         case typelib_TypeClass_VOID:
38             return false;
39         case typelib_TypeClass_CHAR:
40         case typelib_TypeClass_BOOLEAN:
41         case typelib_TypeClass_BYTE:
42         case typelib_TypeClass_SHORT:
43         case typelib_TypeClass_UNSIGNED_SHORT:
44         case typelib_TypeClass_LONG:
45         case typelib_TypeClass_UNSIGNED_LONG:
46         case typelib_TypeClass_HYPER:
47         case typelib_TypeClass_UNSIGNED_HYPER:
48         case typelib_TypeClass_ENUM:
49             return false;
50         case typelib_TypeClass_FLOAT:
51             return false;
52         case typelib_TypeClass_DOUBLE:
53             return false;
54         case typelib_TypeClass_STRING:
55         case typelib_TypeClass_TYPE:
56         case typelib_TypeClass_ANY:
57         case typelib_TypeClass_TYPEDEF:
58         case typelib_TypeClass_UNION:
59         case typelib_TypeClass_SEQUENCE:
60         case typelib_TypeClass_ARRAY:
61         case typelib_TypeClass_INTERFACE:
62             return true;
63         case typelib_TypeClass_STRUCT:
64         case typelib_TypeClass_EXCEPTION:
65             /* MSVC returns a class/struct in RAX only when it is a POD of
66              * 1/2/4/8 bytes.  Every UNO struct cppumaker emits has
67              * user-declared constructors, which makes it non-trivial, so MSVC
68              * always returns one through a hidden pointer -- regardless of
69              * size.  Verified by disassembling cppobj.uno.dll: echoOneByte
70              * (1 byte), echoTwoFloats (8) and echoBigStruct (64) are all
71              * (rcx=this, rdx=hidden return, r8=&arg), writing the result
72              * through [rdx] and returning it in rax.
73              *
74              * Sizing this on nSize > 8 left every <=8-byte struct return one
75              * argument short: the bridge passed (this, &arg) where the callee
76              * expected (this, retptr, &arg), so r8 held garbage and the first
77              * such call -- echoTwoFloats -- took an access violation. */
78             return true;
79 
80         default:
81 #if OSL_DEBUG_LEVEL > 1
82             OSL_TRACE( "Unhandled case: pType->eTypeClass == %d\n", pTypeRef->eTypeClass );
83 #endif
84             OSL_ASSERT(0);
85     }
86     return 0; /* Never reached.  */
87 }
88