git: 5202ca77aaf5 - main - libc/aarch64: Add a non-trivial getcontextx

From: Andrew Turner <andrew_at_FreeBSD.org>
Date: Thu, 21 Mar 2024 10:13:45 UTC
The branch main has been updated by andrew:

URL: https://cgit.FreeBSD.org/src/commit/?id=5202ca77aaf552310bcbaccba750ee9f0888d0d8

commit 5202ca77aaf552310bcbaccba750ee9f0888d0d8
Author:     Andrew Turner <andrew@FreeBSD.org>
AuthorDate: 2024-03-06 12:51:18 +0000
Commit:     Andrew Turner <andrew@FreeBSD.org>
CommitDate: 2024-03-21 10:13:24 +0000

    libc/aarch64: Add a non-trivial getcontextx
    
    Add support for extra registers to the arm64 getcontextx. As no
    registers are defined this just adds the extra register list and an end
    context.
    
    Reviewed by:    kib
    Sponsored by:   Arm Ltd
    Differential Revision:  https://reviews.freebsd.org/D44255
---
 lib/libc/aarch64/gen/getcontextx.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/libc/aarch64/gen/getcontextx.c b/lib/libc/aarch64/gen/getcontextx.c
index b9d4522d96ee..9972d3208d08 100644
--- a/lib/libc/aarch64/gen/getcontextx.c
+++ b/lib/libc/aarch64/gen/getcontextx.c
@@ -32,13 +32,26 @@
 int
 __getcontextx_size(void)
 {
+	size_t size;
 
-	return (sizeof(ucontext_t));
+	size = sizeof(ucontext_t);
+	size += sizeof(struct arm64_reg_context); /* Space for ARM64_CTX_END */
+
+	return (size);
 }
 
 int
 __fillcontextx2(char *ctx)
 {
+	struct arm64_reg_context *reg_ctx;
+	ucontext_t *ucp;
+
+	ucp = (ucontext_t *)ctx;
+	ucp->uc_mcontext.mc_ptr = (uint64_t)(ucp + 1);
+
+	reg_ctx = (struct arm64_reg_context *)ucp->uc_mcontext.mc_ptr;
+	reg_ctx->ctx_id = ARM64_CTX_END;
+	reg_ctx->ctx_size = sizeof(struct arm64_reg_context);
 
 	return (0);
 }
@@ -49,7 +62,10 @@ __fillcontextx(char *ctx)
 	ucontext_t *ucp;
 
 	ucp = (ucontext_t *)ctx;
-	return (getcontext(ucp));
+	if (getcontext(ucp) == -1)
+		return (-1);
+	__fillcontextx2(ctx);
+	return (0);
 }
 
 __weak_reference(__getcontextx, getcontextx);