[Mono] Look for Native Signal SIMD Context (#89467)
authorFan Yang <52458914+fanyang-mono@users.noreply.github.com>
Thu, 27 Jul 2023 16:03:37 +0000 (12:03 -0400)
committerGitHub <noreply@github.com>
Thu, 27 Jul 2023 16:03:37 +0000 (12:03 -0400)
* Find Navtive Signal SIMD Context

* Fix coding format

* Set fregs to 0 when SIMD registers were not found

src/mono/mono/utils/mono-context.c

index 83258c7..9585a0c 100644 (file)
@@ -534,11 +534,32 @@ 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)
-               mctx->fregs [i] = fpctx->vregs [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));
+
+       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