Merge pull request #4503 from BrzVlad/fix-appdomain-unload
[mono.git] / mono / mini / mini-cross-helpers.c
1 #include "config.h"
2
3 #include <stdio.h>
4
5 #include "config.h"
6
7 #include "mini.h"
8 #include "tasklets.h"
9 #include <mono/metadata/abi-details.h>
10
11 void
12 mono_dump_metadata_offsets (void);
13
14 void
15 mono_metadata_cross_helpers_run (void);
16
17
18 static void
19 mono_dump_jit_offsets (void)
20 {
21 #ifdef USED_CROSS_COMPILER_OFFSETS
22         g_print ("#error not using native offsets\n");
23 #else
24         mono_dump_metadata_offsets ();
25
26         g_print ("#ifndef DISABLE_JIT_OFFSETS\n");
27         g_print ("#define USED_CROSS_COMPILER_OFFSETS\n");
28 #define DISABLE_METADATA_OFFSETS
29 #define DECL_OFFSET2(struct,field,offset) this_should_not_happen
30 #define DECL_ALIGN2(type,size) this_should_not_happen
31
32 #define DECL_OFFSET(struct,field) g_print ("DECL_OFFSET2(%s,%s,%d)\n", #struct, #field, (int)MONO_STRUCT_OFFSET (struct, field));
33 #define DECL_ALIGN(type)
34 #define DECL_SIZE2(type,size) this_should_not_happen
35 #define DECL_SIZE(type)
36 #include <mono/metadata/object-offsets.h>
37
38         g_print ("#endif //disable jit check\n");
39         g_print ("#endif //cross compiler checks\n");
40         g_print ("#endif //gc check\n");
41         g_print ("#endif //os check\n");
42         g_print ("#endif //arch check\n");
43         g_print ("#endif //USED_CROSS_COMPILER_OFFSETS check\n");
44 #endif
45 }
46
47 /*
48  * mono_cross_helpers_run:
49  *
50  *   Check that the offsets given by object-offsets.h match the offsets
51  * on the host.
52  */
53 void
54 mono_cross_helpers_run (void)
55 {
56 #if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE)
57         gboolean is_broken = FALSE;
58 #endif
59
60 #ifndef USED_CROSS_COMPILER_OFFSETS
61         if (g_getenv ("DUMP_CROSS_OFFSETS"))
62                 mono_dump_jit_offsets ();
63 #endif
64         
65 #if defined (HAS_CROSS_COMPILER_OFFSETS) && !defined (MONO_CROSS_COMPILE)
66         mono_metadata_cross_helpers_run ();
67
68         /* The metadata offsets are already checked above */
69 #define DISABLE_METADATA_OFFSETS
70 #define USE_CROSS_COMPILE_OFFSETS
71 #define DECL_OFFSET(struct,field) this_should_not_happen_for_cross_fields
72 #define DECL_OFFSET2(struct,field,offset) \
73          if ((int)G_STRUCT_OFFSET (struct, field) != offset) { \
74                 g_print (#struct ":" #field " invalid struct offset %d (expected %d)\n",        \
75                         offset, \
76                         (int)G_STRUCT_OFFSET (struct, field));  \
77                 is_broken = TRUE;       \
78         }
79 #define DECL_ALIGN(name,type) this_should_not_happen_for_cross_align
80 #define DECL_ALIGN2(name,size) \
81          if (MONO_ALIGN_ ## name != size) { \
82                 g_print (#name ": invalid alignment %d (expected %d)\n",        \
83                 size,   \
84                 MONO_ALIGN_ ## name);   \
85                 is_broken = TRUE;       \
86         }
87 #define DECL_SIZE(type) this_should_not_happen_for_cross_size
88 #define DECL_SIZE2(name,size) \
89          if (MONO_SIZEOF_ ## name != size) { \
90                 g_print (#name ": invalid size %d (expected %d)\n",     \
91                 size,   \
92                 MONO_SIZEOF_ ## name);  \
93                 is_broken = TRUE;       \
94         }
95
96 #include <mono/metadata/object-offsets.h>
97
98         g_assert (!is_broken);
99 #endif
100 }