From 32bf8eaa5a343816ce953149f06970c67fed0ec6 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 83258c781ab00..c87d04d5590d6 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 200c3e8c41ad65625ad319290b2a646d9ab455ef 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 c87d04d5590d6..c2f9e914d05ee 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 1d5babc688ac44815165d48ac8cb0a4f29425221 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 c2f9e914d05ee..9585a0c7272d7 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