xref: /trunk/main/bridges/source/cpp_uno/msvc_win64_x86-64/abi.cxx (revision d91b741f1e44bf860b73c598e45198aefbdc7ebf)
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             {
66                 typelib_TypeDescription * pTypeDescr = 0;
67                 TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
68 
69                 /* A struct is returned in a register only when its size is
70                  * 1/2/4/8 bytes; otherwise (here: > 8) it is returned via a
71                  * hidden pointer (in memory).  This logic was inverted, which
72                  * corrupted struct/exception return marshalling on x64 — e.g.
73                  * getAllExtensions returning nested Sequences (ref 0c2e3065a0). */
74                 if ( pTypeDescr->nSize > 8 )
75                 {
76                     TYPELIB_DANGER_RELEASE( pTypeDescr );
77                     return true;
78                 }
79                 else
80                 {
81                     TYPELIB_DANGER_RELEASE( pTypeDescr );
82                     return false;
83                 }
84             }
85 
86         default:
87 #if OSL_DEBUG_LEVEL > 1
88             OSL_TRACE( "Unhandled case: pType->eTypeClass == %d\n", pTypeRef->eTypeClass );
89 #endif
90             OSL_ASSERT(0);
91     }
92     return 0; /* Never reached.  */
93 }
94