Apply changes from https://github.com/dotnet/runtime/commit/eb1756e97d23df13bc6fe798e...
[mono-project.git] / mono / metadata / abi-details.h
bloba2376816e331a3c25d09ddad0cbebc6df4add697
1 /**
2 * \file
3 * Copyright 2014 Xamarin Inc
4 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
5 */
6 #ifndef __MONO_METADATA_ABI_DETAILS_H__
7 #define __MONO_METADATA_ABI_DETAILS_H__
9 #include <config.h>
10 #include <glib.h>
13 * This file defines macros to compute sizes/alignments/field offsets which depend on
14 * the ABI. It is needed during cross compiling since the generated code needs to
15 * contain offsets which correspond to the ABI of the target, not the host.
16 * It defines the following macros:
17 * - MONO_ABI_SIZEOF(type) for every basic type
18 * - MONO_ABI_ALIGNOF(type) for every basic type
19 * - MONO_STRUCT_OFFSET(struct, field) for various runtime structures
20 * When not cross compiling, these correspond to the host ABI (i.e. sizeof/offsetof).
21 * When cross compiling, these are defined in a generated header file which is
22 * generated by the offsets tool in tools/offsets-tool. The name of the file
23 * is given by the --with-cross-offsets= configure argument.
26 typedef enum {
27 MONO_ALIGN_gint8,
28 MONO_ALIGN_gint16,
29 MONO_ALIGN_gint32,
30 MONO_ALIGN_gint64,
31 MONO_ALIGN_float,
32 MONO_ALIGN_double,
33 MONO_ALIGN_gpointer,
34 MONO_ALIGN_COUNT
35 } CoreTypeAlign;
37 int mono_abi_alignment (CoreTypeAlign type);
39 #define MONO_ABI_ALIGNOF(type) mono_abi_alignment (MONO_ALIGN_ ## type)
40 #define MONO_ABI_SIZEOF(type) (MONO_STRUCT_SIZE (type))
41 #define MONO_CURRENT_ABI_SIZEOF(type) ((int)sizeof(type))
43 #undef DECL_OFFSET2
44 #define DECL_OFFSET(struct,field) MONO_OFFSET_ ## struct ## _ ## field = -1,
45 #define DECL_OFFSET2(struct,field,offset) MONO_OFFSET_ ## struct ## _ ## field = offset,
46 #define DECL_ALIGN2(type,size)
47 #define DECL_SIZE(type) MONO_SIZEOF_ ##type = -1,
48 #define DECL_SIZE2(type,size) MONO_SIZEOF_ ##type = size,
51 enum {
52 #include "object-offsets.h"
55 #ifdef USED_CROSS_COMPILER_OFFSETS
56 #define MONO_STRUCT_OFFSET(struct,field) MONO_OFFSET_ ## struct ## _ ## field
57 #define MONO_STRUCT_OFFSET_CONSTANT(struct,field) MONO_STRUCT_OFFSET(struct,field)
58 #define MONO_STRUCT_SIZE(struct) MONO_SIZEOF_ ## struct
59 #else
60 /* This macro is expanding to something that uses the comma operator in C [0].
61 * The first part introduces an expression that uses the `MONO_OFFSET_*`
62 * define. The result isn't used, but it forces the compiler to bail out if the
63 * define doesn't exist; this happens when we forgot to add an entry in
64 * `object-offsets.h` accordingly.
66 * [0] https://en.wikipedia.org/wiki/Comma_operator
68 #define MONO_STRUCT_OFFSET(struct,field) (MONO_OFFSET_ ## struct ## _ ## field == -1, G_STRUCT_OFFSET (struct,field))
69 #define MONO_STRUCT_OFFSET_CONSTANT(struct,field) G_STRUCT_OFFSET (struct,field)
70 #define MONO_STRUCT_SIZE(struct) (MONO_SIZEOF_ ## struct == -1, (int)sizeof(struct))
71 #endif
73 // #define MONO_SIZEOF_MonoObject (2 * MONO_ABI_SIZEOF(gpointer))
74 #define MONO_SIZEOF_MonoObject (2 * MONO_SIZEOF_gpointer)
75 #endif