Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormonojenkins <jo.shields+jenkins@xamarin.com>2020-04-03 13:36:06 +0300
committerGitHub <noreply@github.com>2020-04-03 13:36:06 +0300
commitfdbba4a34ecd7637065ec6e1751b2063455fd2a5 (patch)
tree10f0fb278ff9baf274256785d04c9db4c2e4daf4
parent1278c2f35eaf2c9db56b2554fe89590a39e9ef22 (diff)
[2019-12] [amd64] align application stack pointer in signal handler (#19368)
[2019-12] [amd64] align application stack pointer in signal handler 16byte stack pointer alignment is only required in certain places by the ABI, so the assumption that it holds all the time is wrong (though, it passed CI 😅). We have to setup the frame properly, i.e. we have to ensure the stack pointer is properly aligned. That's what we have done previously too. Regression of https://github.com/mono/mono/pull/17922 Fixes https://github.com/mono/mono/issues/18006 Backport of #18021. /cc @lewurm
-rw-r--r--mono/eglib/glib.h6
-rw-r--r--mono/mini/exceptions-amd64.c3
2 files changed, 3 insertions, 6 deletions
diff --git a/mono/eglib/glib.h b/mono/eglib/glib.h
index 2c45d580f57..898360eb2f0 100644
--- a/mono/eglib/glib.h
+++ b/mono/eglib/glib.h
@@ -247,13 +247,11 @@ typedef guint32 gunichar;
#define ABS(a) ((a) > 0 ? (a) : -(a))
#endif
-#ifndef ALIGN_TO
#define ALIGN_TO(val,align) ((((gssize)val) + ((align) - 1)) & ~((align) - 1))
-#endif
-#ifndef ALIGN_PTR_TO
+#define ALIGN_DOWN_TO(val,align) (((gssize)val) & ~((align) - 1))
+
#define ALIGN_PTR_TO(ptr,align) (gpointer)((((gssize)(ptr)) + (align - 1)) & (~(align - 1)))
-#endif
#define G_STRUCT_OFFSET(p_type,field) offsetof(p_type,field)
diff --git a/mono/mini/exceptions-amd64.c b/mono/mini/exceptions-amd64.c
index e838d4c1f79..d5fb237bf87 100644
--- a/mono/mini/exceptions-amd64.c
+++ b/mono/mini/exceptions-amd64.c
@@ -926,8 +926,7 @@ mono_arch_handle_altstack_exception (void *sigctx, MONO_SIG_HANDLER_INFO_TYPE *s
* requires allocation on the stack, as this wouldn't be encoded in unwind
* information for the caller frame.
*/
- sp = (gpointer *)UCONTEXT_REG_RSP (sigctx);
- g_assertf (((unsigned long) sp & 15) == 0, "sp: %p\n", sp);
+ sp = (gpointer *) ALIGN_DOWN_TO (UCONTEXT_REG_RSP (sigctx), 16);
sp [-1] = (gpointer)UCONTEXT_REG_RIP (sigctx);
mono_sigctx_to_monoctx (sigctx, copied_ctx);
/* at the return from the signal handler execution starts in altstack_handle_and_restore() */