From d302abad63e8ee7606a590f8fe725e93bdcd28d4 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Tue, 25 Jul 2023 15:53:55 -0400 Subject: [PATCH 1/3] Find Navtive Signal SIMD Context --- src/mono/mono/utils/mono-context.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/mono/mono/utils/mono-context.c b/src/mono/mono/utils/mono-context.c index 83258c781ab008..c87d04d5590d60 100644 --- a/src/mono/mono/utils/mono-context.c +++ b/src/mono/mono/utils/mono-context.c @@ -534,10 +534,28 @@ mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx) #endif #ifdef __linux__ struct fpsimd_context *fpctx = (struct fpsimd_context*)&((ucontext_t*)sigctx)->uc_mcontext.__reserved; - int i; - g_assert (fpctx->head.magic == FPSIMD_MAGIC); - for (i = 0; i < 32; ++i) + size_t size = 0; + do + { + struct fpsimd_context *fpctx_temp = (struct fpsimd_context *)&(((ucontext_t*)sigctx)->uc_mcontext.__reserved[size]); + + if(fpctx_temp->head.magic == FPSIMD_MAGIC) + { + g_assert (fpctx_temp->head.size >= sizeof(struct fpsimd_context)); + g_assert (size + fpctx_temp->head.size <= sizeof(((ucontext_t*)sigctx)->uc_mcontext.__reserved)); + + fpctx = fpctx_temp; + break; + } + + if (fpctx_temp->head.size == 0) + break; + + size += fpctx_temp->head.size; + } while (size + sizeof(struct fpsimd_context) <= sizeof(((ucontext_t*)sigctx)->uc_mcontext.__reserved)); + + for (int i = 0; i < 32; ++i) mctx->fregs [i] = fpctx->vregs [i]; #endif /* FIXME: apple */ From 40f6eebaf287565be7223133c06981d95aec02c1 Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Wed, 26 Jul 2023 10:12:28 -0400 Subject: [PATCH 2/3] Fix coding format --- src/mono/mono/utils/mono-context.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/mono/mono/utils/mono-context.c b/src/mono/mono/utils/mono-context.c index c87d04d5590d60..c2f9e914d05eec 100644 --- a/src/mono/mono/utils/mono-context.c +++ b/src/mono/mono/utils/mono-context.c @@ -536,24 +536,23 @@ mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx) struct fpsimd_context *fpctx = (struct fpsimd_context*)&((ucontext_t*)sigctx)->uc_mcontext.__reserved; size_t size = 0; - do - { - struct fpsimd_context *fpctx_temp = (struct fpsimd_context *)&(((ucontext_t*)sigctx)->uc_mcontext.__reserved[size]); + do { + struct fpsimd_context *fpctx_temp = (struct fpsimd_context*)&(((ucontext_t*)sigctx)->uc_mcontext.__reserved[size]); - if(fpctx_temp->head.magic == FPSIMD_MAGIC) - { - g_assert (fpctx_temp->head.size >= sizeof(struct fpsimd_context)); - g_assert (size + fpctx_temp->head.size <= sizeof(((ucontext_t*)sigctx)->uc_mcontext.__reserved)); + if (fpctx_temp->head.magic == FPSIMD_MAGIC) + { + g_assert (fpctx_temp->head.size >= sizeof (struct fpsimd_context)); + g_assert (size + fpctx_temp->head.size <= sizeof (((ucontext_t*)sigctx)->uc_mcontext.__reserved)); fpctx = fpctx_temp; break; - } + } - if (fpctx_temp->head.size == 0) + if (fpctx_temp->head.size == 0) break; - size += fpctx_temp->head.size; - } while (size + sizeof(struct fpsimd_context) <= sizeof(((ucontext_t*)sigctx)->uc_mcontext.__reserved)); + size += fpctx_temp->head.size; + } while (size + sizeof (struct fpsimd_context) <= sizeof (((ucontext_t*)sigctx)->uc_mcontext.__reserved)); for (int i = 0; i < 32; ++i) mctx->fregs [i] = fpctx->vregs [i]; From 3ce73f91151976abdc67742e75dac65f3a53ca1d Mon Sep 17 00:00:00 2001 From: Fan Yang Date: Wed, 26 Jul 2023 14:48:41 -0400 Subject: [PATCH 3/3] Set fregs to 0 when SIMD registers were not found --- src/mono/mono/utils/mono-context.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/utils/mono-context.c b/src/mono/mono/utils/mono-context.c index c2f9e914d05eec..9585a0c7272d78 100644 --- a/src/mono/mono/utils/mono-context.c +++ b/src/mono/mono/utils/mono-context.c @@ -554,8 +554,12 @@ mono_sigctx_to_monoctx (void *sigctx, MonoContext *mctx) size += fpctx_temp->head.size; } while (size + sizeof (struct fpsimd_context) <= sizeof (((ucontext_t*)sigctx)->uc_mcontext.__reserved)); - for (int i = 0; i < 32; ++i) - mctx->fregs [i] = fpctx->vregs [i]; + if (fpctx->head.magic == FPSIMD_MAGIC) + for (int i = 0; i < 32; ++i) + mctx->fregs [i] = fpctx->vregs [i]; + else + for (int i = 0; i < 32; ++i) + mctx->fregs [i] = 0; #endif /* FIXME: apple */ #endif