Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[abi-details] add explaining comment for macro magic #31802

Merged
merged 1 commit into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions src/mono/mono/metadata/abi-details.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,20 @@ enum {

#ifdef USED_CROSS_COMPILER_OFFSETS
#define MONO_STRUCT_OFFSET(struct,field) MONO_OFFSET_ ## struct ## _ ## field
#define MONO_STRUCT_OFFSET_CONSTANT(struct,field) MONO_STRUCT_OFFSET(struct,field)
#define MONO_STRUCT_SIZE(struct) MONO_SIZEOF_ ## struct
#else
#if defined(HAS_CROSS_COMPILER_OFFSETS) || defined(MONO_CROSS_COMPILE)
/* This macro is expanding to something that uses the comma operator in C [0].
* The first part introduces an expression that uses the `MONO_OFFSET_*`
* define. The result isn't used, but it forces the compiler to bail out if the
* define doesn't exist; this happens when we forgot to add an entry in
* `object-offsets.h` accordingly.
*
* [0] https://en.wikipedia.org/wiki/Comma_operator
*/
#define MONO_STRUCT_OFFSET(struct,field) (MONO_OFFSET_ ## struct ## _ ## field == -1, G_STRUCT_OFFSET (struct,field))
#define MONO_STRUCT_OFFSET_CONSTANT(struct,field) G_STRUCT_OFFSET (struct,field)
#define MONO_STRUCT_SIZE(struct) (MONO_SIZEOF_ ## struct == -1, (int)sizeof(struct))
#else
#define MONO_STRUCT_OFFSET(struct,field) G_STRUCT_OFFSET (struct,field)
#define MONO_STRUCT_SIZE(struct) ((int)sizeof(struct))
#endif
#endif

// #define MONO_SIZEOF_MonoObject (2 * MONO_ABI_SIZEOF(gpointer))
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/metadata/object-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct _MonoArray {
mono_64bitaligned_t vector [MONO_ZERO_LEN_ARRAY];
};

#define MONO_SIZEOF_MONO_ARRAY (MONO_STRUCT_OFFSET (MonoArray, vector))
#define MONO_SIZEOF_MONO_ARRAY (MONO_STRUCT_OFFSET_CONSTANT (MonoArray, vector))

struct _MonoString {
MonoObject object;
Expand Down
16 changes: 16 additions & 0 deletions src/mono/mono/metadata/object-offsets.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ DECL_OFFSET(MonoString, length)
DECL_OFFSET(MonoString, chars)

DECL_OFFSET(MonoException, message)
DECL_OFFSET(MonoException, caught_in_unmanaged)

DECL_OFFSET(MonoTypedRef, type)
DECL_OFFSET(MonoTypedRef, klass)
Expand Down Expand Up @@ -159,6 +160,9 @@ DECL_OFFSET(MonoMethodRuntimeGenericContext, class_vtable)
DECL_OFFSET(MonoJitTlsData, lmf)
DECL_OFFSET(MonoJitTlsData, class_cast_from)
DECL_OFFSET(MonoJitTlsData, class_cast_to)
#ifdef TARGET_WIN32
DECL_OFFSET(MonoJitTlsData, stack_restore_ctx)
#endif

DECL_OFFSET(MonoGSharedVtMethodRuntimeInfo, locals_size)
DECL_OFFSET(MonoGSharedVtMethodRuntimeInfo, entries) //XXX more to fix here
Expand Down Expand Up @@ -211,6 +215,10 @@ DECL_OFFSET(MonoLMF, rsp)
DECL_OFFSET(MonoLMF, rbp)

DECL_OFFSET(DynCallArgs, res)
DECL_OFFSET(DynCallArgs, fregs)
DECL_OFFSET(DynCallArgs, has_fp)
DECL_OFFSET(DynCallArgs, nstack_args)
DECL_OFFSET(DynCallArgs, regs)

DECL_OFFSET(MonoLMFTramp, ctx)
DECL_OFFSET(MonoLMFTramp, lmf_addr)
Expand Down Expand Up @@ -290,6 +298,14 @@ DECL_OFFSET(GSharedVtCallInfo, ret_marshal)
DECL_OFFSET(GSharedVtCallInfo, gsharedvt_in)
#endif

#if defined(TARGET_AMD64)
DECL_OFFSET(GSharedVtCallInfo, ret_marshal)
DECL_OFFSET(GSharedVtCallInfo, vret_arg_reg)
DECL_OFFSET(GSharedVtCallInfo, vret_slot)
DECL_OFFSET(GSharedVtCallInfo, stack_usage)
DECL_OFFSET(GSharedVtCallInfo, gsharedvt_in)
#endif

DECL_OFFSET(MonoFtnDesc, arg)
DECL_OFFSET(MonoFtnDesc, addr)

Expand Down