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