Merge pull request #2832 from razzfazz/handle_eintr
[mono.git] / mono / metadata / metadata-cross-helpers.c
1 #include <stdio.h>
2
3 #include "config.h"
4 #include <mono/metadata/abi-details.h>
5
6 #include <mono/metadata/class-internals.h>
7 #include <mono/metadata/object-internals.h>
8 #include <mono/metadata/monitor.h>
9 #ifdef HAVE_SGEN_GC
10 #include <mono/sgen/sgen-gc.h>
11 #endif
12
13 static int
14 dump_arch (void)
15 {
16 #if defined (TARGET_X86)
17         g_print ("#ifdef TARGET_X86\n");
18 #elif defined (TARGET_AMD64)
19         g_print ("#ifdef TARGET_AMD64\n");
20 #elif defined (TARGET_ARM)
21         g_print ("#ifdef TARGET_ARM\n");
22 #elif defined (TARGET_ARM64)
23         g_print ("#ifdef TARGET_ARM64\n");
24 #else
25         return 0;
26 #endif
27         return 1;
28 }
29
30 static int
31 dump_os (void)
32 {
33 #if defined (PLATFORM_WIN32)
34         g_print ("#ifdef TARGET_WIN32\n");
35 #elif defined (PLATFORM_ANDROID)
36         g_print ("#ifdef TARGET_ANDROID\n");
37 #elif defined (PLATFORM_MACOSX)
38         g_print ("#ifdef TARGET_OSX\n");
39 #elif defined (PLATFORM_IOS)
40         g_print ("#ifdef TARGET_IOS\n");
41 #else
42         return 0;
43 #endif
44         return 1;
45 }
46
47 void
48 mono_dump_metadata_offsets (void);
49
50 void
51 mono_dump_metadata_offsets (void)
52 {
53 #ifdef USED_CROSS_COMPILER_OFFSETS
54         g_print ("not using native offsets\n");
55 #else
56         g_print ("#ifndef USED_CROSS_COMPILER_OFFSETS\n");
57
58         if (!dump_arch ()) {
59                 g_print ("#error failed to figure out the current arch\n");
60                 return;
61         }
62
63         if (!dump_os ()) {
64                 g_print ("#error failed to figure out the current OS\n");
65                 return;
66         }
67
68 #ifdef HAVE_SGEN_GC
69         g_print ("#ifndef HAVE_BOEHM_GC\n");
70 #elif HAVE_BOEHM_GC
71         g_print ("#ifndef HAVE_SGEN_GC\n");
72 #else
73         g_print ("#error no gc conf not supported\n");
74         return;
75 #endif
76
77         g_print ("#define HAS_CROSS_COMPILER_OFFSETS\n");
78         g_print ("#if defined (USE_CROSS_COMPILE_OFFSETS) || defined (MONO_CROSS_COMPILE)\n");
79         g_print ("#if !defined (DISABLE_METADATA_OFFSETS)\n");
80         g_print ("#define USED_CROSS_COMPILER_OFFSETS\n");
81
82 #define DISABLE_JIT_OFFSETS
83 #define DECL_OFFSET2(struct,field,offset) this_should_not_happen
84 #define DECL_ALIGN2(type,size) this_should_not_happen
85
86 #define DECL_OFFSET(struct,field) g_print ("DECL_OFFSET2(%s,%s,%d)\n", #struct, #field, (int)MONO_STRUCT_OFFSET (struct, field));
87 #define DECL_ALIGN(type) g_print ("DECL_ALIGN2(%s,%d)\n", #type, (int)MONO_ABI_ALIGNOF (type));
88 #define DECL_SIZE(type) g_print ("DECL_SIZE2(%s,%d)\n", #type, (int)MONO_ABI_SIZEOF (type));
89 #include <mono/metadata/object-offsets.h>
90
91         g_print ("#endif //disable metadata check\n");
92         g_print ("#endif //gc check\n");
93 #endif
94 }
95
96 void
97 mono_metadata_cross_helpers_run (void);
98
99 void
100 mono_metadata_cross_helpers_run (void)
101 {
102 #if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE)
103         gboolean is_broken = FALSE;
104
105 #define DISABLE_JIT_OFFSETS
106 #define USE_CROSS_COMPILE_OFFSETS
107 #define DECL_OFFSET(struct,field) this_should_not_happen_for_cross_fields
108 #define DECL_OFFSET2(struct,field,offset) \
109          if ((int)G_STRUCT_OFFSET (struct, field) != offset) { \
110                 g_print (#struct ":" #field " invalid struct offset %d (expected %d)\n",        \
111                         offset, \
112                         (int)G_STRUCT_OFFSET (struct, field));  \
113                 is_broken = TRUE;       \
114         }
115 #define DECL_ALIGN(type) this_should_not_happen_for_cross_align
116 #define DECL_ALIGN2(name,size) \
117          if (MONO_ALIGN_ ## name != size) { \
118                 g_print (#name ": invalid alignment %d (expected %d)\n",        \
119                 size,   \
120                 MONO_ALIGN_ ## name);   \
121                 is_broken = TRUE;       \
122         }
123 #define DECL_SIZE(type) this_should_not_happen_for_cross_size
124 #define DECL_SIZE2(name,size) \
125          if (MONO_SIZEOF_ ## name != size) { \
126                 g_print (#name ": invalid size %d (expected %d)\n",     \
127                 size,   \
128                 MONO_SIZEOF_ ## name);  \
129                 is_broken = TRUE;       \
130         }
131
132 #include <mono/metadata/object-offsets.h>
133
134         g_assert (!is_broken);
135 #endif
136 }
137