aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Turner <andrew@FreeBSD.org>2026-01-06 10:35:55 +0000
committerMark Johnston <markj@FreeBSD.org>2026-01-26 14:45:34 +0000
commitbcd6bb8067d13d28d13a309e32818cda9e0d29ff (patch)
tree7f57a64af5bc79a60c18901b002fdd3c9202a653
parenta2d1fa2a2b1fcbedd80a35e4ba17172f646ad3d2 (diff)
arm64: Correctly align the SVE signal context
The SVE signal context needs to be correctly aligned. Fix this by creating a new macro to calculate the needed size to provide this alignment, and use it when setting and checking the saved SVE signal context. Reported by: cperciva Reviewed by: cperciva, markj Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D54396 (cherry picked from commit a9e77eb7016df70723c208fc09fbd01ec23a732d)
-rw-r--r--sys/arm64/arm64/exec_machdep.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/sys/arm64/arm64/exec_machdep.c b/sys/arm64/arm64/exec_machdep.c
index 67760850c56a..aba338762139 100644
--- a/sys/arm64/arm64/exec_machdep.c
+++ b/sys/arm64/arm64/exec_machdep.c
@@ -60,6 +60,10 @@
#include <machine/vfp.h>
#endif
+#define CTX_SIZE_SVE(buf_size) \
+ roundup2(sizeof(struct sve_context) + (buf_size), \
+ _Alignof(struct sve_context))
+
_Static_assert(sizeof(mcontext_t) == 880, "mcontext_t size incorrect");
_Static_assert(sizeof(ucontext_t) == 960, "ucontext_t size incorrect");
_Static_assert(sizeof(siginfo_t) == 80, "siginfo_t size incorrect");
@@ -545,8 +549,7 @@ set_mcontext(struct thread *td, mcontext_t *mcp)
buf_size = sve_buf_size(td);
/* Check the size is valid */
- if (ctx.ctx_size !=
- (sizeof(sve_ctx) + buf_size))
+ if (ctx.ctx_size != CTX_SIZE_SVE(buf_size))
return (EINVAL);
memset(pcb->pcb_svesaved, 0,
@@ -689,7 +692,7 @@ sendsig_ctx_sve(struct thread *td, vm_offset_t *addrp)
{
struct sve_context ctx;
struct pcb *pcb;
- size_t buf_size;
+ size_t buf_size, ctx_size;
vm_offset_t ctx_addr;
pcb = td->td_pcb;
@@ -700,14 +703,15 @@ sendsig_ctx_sve(struct thread *td, vm_offset_t *addrp)
MPASS(pcb->pcb_svesaved != NULL);
buf_size = sve_buf_size(td);
+ ctx_size = CTX_SIZE_SVE(buf_size);
/* Address for the full context */
- *addrp -= sizeof(ctx) + buf_size;
+ *addrp -= ctx_size;
ctx_addr = *addrp;
memset(&ctx, 0, sizeof(ctx));
ctx.sve_ctx.ctx_id = ARM64_CTX_SVE;
- ctx.sve_ctx.ctx_size = sizeof(ctx) + buf_size;
+ ctx.sve_ctx.ctx_size = ctx_size;
ctx.sve_vector_len = pcb->pcb_sve_len;
ctx.sve_flags = 0;