msvcrt: Support 64-bit RTTI in __RTtypeid function.
[wine] / dlls / msvcrt / cxx.h
1 /*
2  * Copyright 2012 Piotr Caban for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #ifdef __i386__  /* thiscall functions are i386-specific */
20
21 #define THISCALL(func) __thiscall_ ## func
22 #define THISCALL_NAME(func) __ASM_NAME("__thiscall_" #func)
23 #define __thiscall __stdcall
24 #define DEFINE_THISCALL_WRAPPER(func,args) \
25     extern void THISCALL(func)(void); \
26     __ASM_GLOBAL_FUNC(__thiscall_ ## func, \
27                       "popl %eax\n\t" \
28                       "pushl %ecx\n\t" \
29                       "pushl %eax\n\t" \
30                       "jmp " __ASM_NAME(#func) __ASM_STDCALL(args) )
31 #else /* __i386__ */
32
33 #define THISCALL(func) func
34 #define THISCALL_NAME(func) __ASM_NAME(#func)
35 #define __thiscall __cdecl
36 #define DEFINE_THISCALL_WRAPPER(func,args) /* nothing */
37
38 #endif /* __i386__ */
39
40 #ifdef _WIN64
41
42 #define VTABLE_ADD_FUNC(name) "\t.quad " THISCALL_NAME(name) "\n"
43
44 #define __ASM_VTABLE(name,funcs) \
45     __asm__(".data\n" \
46             "\t.align 8\n" \
47             "\t.quad " __ASM_NAME(#name "_rtti") "\n" \
48             "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
49             __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
50             funcs "\n\t.text")
51
52 #else
53
54 #define VTABLE_ADD_FUNC(name) "\t.long " THISCALL_NAME(name) "\n"
55
56 #define __ASM_VTABLE(name,funcs) \
57     __asm__(".data\n" \
58             "\t.align 4\n" \
59             "\t.long " __ASM_NAME(#name "_rtti") "\n" \
60             "\t.globl " __ASM_NAME("MSVCRT_" #name "_vtable") "\n" \
61             __ASM_NAME("MSVCRT_" #name "_vtable") ":\n" \
62             funcs "\n\t.text")
63
64 #endif /* _WIN64 */
65
66 #define DEFINE_RTTI_DATA(name, off, base_classes, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
67     static const type_info name ## _type_info = { \
68         &MSVCRT_type_info_vtable, \
69         NULL, \
70         mangled_name \
71     }; \
72 \
73 static const rtti_base_descriptor name ## _rtti_base_descriptor = { \
74     &name ##_type_info, \
75     base_classes, \
76     { 0, -1, 0}, \
77     64 \
78 }; \
79 \
80 static const rtti_base_array name ## _rtti_base_array = { \
81     { \
82         &name ## _rtti_base_descriptor, \
83         cl1, \
84         cl2, \
85         cl3, \
86         cl4, \
87         cl5, \
88         cl6, \
89         cl7, \
90         cl8, \
91         cl9, \
92     } \
93 }; \
94 \
95 static const rtti_object_hierarchy name ## _hierarchy = { \
96     0, \
97     0, \
98     base_classes+1, \
99     &name ## _rtti_base_array \
100 }; \
101 \
102 const rtti_object_locator name ## _rtti = { \
103     0, \
104     off, \
105     0, \
106     &name ## _type_info, \
107     &name ## _hierarchy \
108 }
109
110 #define DEFINE_RTTI_DATA0(name, off, mangled_name) \
111     DEFINE_RTTI_DATA(name, off, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
112 #define DEFINE_RTTI_DATA1(name, off, cl1, mangled_name) \
113     DEFINE_RTTI_DATA(name, off, 1, cl1, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
114 #define DEFINE_RTTI_DATA2(name, off, cl1, cl2, mangled_name) \
115     DEFINE_RTTI_DATA(name, off, 2, cl1, cl2, NULL, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
116 #define DEFINE_RTTI_DATA3(name, off, cl1, cl2, cl3, mangled_name) \
117     DEFINE_RTTI_DATA(name, off, 3, cl1, cl2, cl3, NULL, NULL, NULL, NULL, NULL, NULL, mangled_name)
118 #define DEFINE_RTTI_DATA4(name, off, cl1, cl2, cl3, cl4, mangled_name) \
119     DEFINE_RTTI_DATA(name, off, 4, cl1, cl2, cl3, cl4, NULL, NULL, NULL, NULL, NULL, mangled_name)
120 #define DEFINE_RTTI_DATA8(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, mangled_name) \
121     DEFINE_RTTI_DATA(name, off, 8, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, NULL, mangled_name)
122 #define DEFINE_RTTI_DATA9(name, off, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name) \
123     DEFINE_RTTI_DATA(name, off, 9, cl1, cl2, cl3, cl4, cl5, cl6, cl7, cl8, cl9, mangled_name)
124
125 /* rtti */
126 typedef struct _rtti_base_descriptor
127 {
128     const type_info *type_descriptor;
129     int num_base_classes;
130     this_ptr_offsets offsets;    /* offsets for computing the this pointer */
131     unsigned int attributes;
132 } rtti_base_descriptor;
133
134 typedef struct _rtti_base_array
135 {
136     const rtti_base_descriptor *bases[10]; /* First element is the class itself */
137 } rtti_base_array;
138
139 typedef struct _rtti_object_hierarchy
140 {
141     unsigned int signature;
142     unsigned int attributes;
143     int array_len; /* Size of the array pointed to by 'base_classes' */
144     const rtti_base_array *base_classes;
145 } rtti_object_hierarchy;
146
147 typedef struct _rtti_object_locator
148 {
149     unsigned int signature;
150     int base_class_offset;
151     unsigned int flags;
152     const type_info *type_descriptor;
153     const rtti_object_hierarchy *type_hierarchy;
154 } rtti_object_locator;