From a130fb4fb8bfb893f2bd0d402cb7490de48da235 Mon Sep 17 00:00:00 2001 From: Petr Shumilov Date: Mon, 28 Oct 2024 00:39:09 +0400 Subject: [PATCH] Fix getcontext return value for aarch64/darwin Signed-off-by: Petr Shumilov --- common/ucontext/darwin/aarch64/context.cpp | 35 ++++++++++++---------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/common/ucontext/darwin/aarch64/context.cpp b/common/ucontext/darwin/aarch64/context.cpp index d5150554b..685de4b82 100644 --- a/common/ucontext/darwin/aarch64/context.cpp +++ b/common/ucontext/darwin/aarch64/context.cpp @@ -78,23 +78,8 @@ asm(".global " NAME(getcontext_portable) ";\n" ".align 2;\n" NAME(getcontext_portable) ":\n" "str xzr, [x0, #((184) + ((0) * (8)))]\n" // #REG_OFFSET(0) - /* save GPRs */ - "stp x0, x1, [x0, #((184) + ((0) * (8)))]\n" // REG_OFFSET(0) + /* save x2 and x3 for reuse */ "stp x2, x3, [x0, #((184) + ((2) * (8)))]\n" // REG_OFFSET(2) - "stp x4, x5, [x0, #((184) + ((4) * (8)))]\n" // REG_OFFSET(4) - "stp x6, x7, [x0, #((184) + ((6) * (8)))]\n" // REG_OFFSET(6) - "stp x8, x9, [x0, #((184) + ((8) * (8)))]\n" // REG_OFFSET(8) - "stp x10, x11, [x0, #((184) + ((10) * (8)))]\n" // REG_OFFSET(10) - "stp x12, x13, [x0, #((184) + ((12) * (8)))]\n" // REG_OFFSET(12) - "stp x14, x15, [x0, #((184) + ((14) * (8)))]\n" // REG_OFFSET(14) - "stp x16, x17, [x0, #((184) + ((16) * (8)))]\n" // REG_OFFSET(16) - "stp x18, x19, [x0, #((184) + ((18) * (8)))]\n" // REG_OFFSET(18) - "stp x20, x21, [x0, #((184) + ((20) * (8)))]\n" // REG_OFFSET(20) - "stp x22, x23, [x0, #((184) + ((22) * (8)))]\n" // REG_OFFSET(22) - "stp x24, x25, [x0, #((184) + ((24) * (8)))]\n" // REG_OFFSET(24) - "stp x26, x27, [x0, #((184) + ((26) * (8)))]\n" // REG_OFFSET(26) - "stp x28, x29, [x0, #((184) + ((28) * (8)))]\n" // REG_OFFSET(28) - "str x30, [x0, #((184) + ((30) * (8)))]\n" // REG_OFFSET(30) /* save current program counter in link register */ "str x30, [x0, #440]\n" // PC_OFFSET /* save current stack pointer */ @@ -107,7 +92,25 @@ asm(".global " NAME(getcontext_portable) ";\n" "stp q10, q11, [x2, #176]\n" "stp q12, q13, [x2, #208]\n" "stp q14, q15, [x2, #240]\n" + /* save GPRs and return value 0 */ + "mov x2, x0\n" "mov x0, #0\n" + "stp x0, x1, [x2, #((184) + ((0) * (8)))]\n" // REG_OFFSET(0) + /* x2 and x3 have already been saved */ + "stp x4, x5, [x2, #((184) + ((4) * (8)))]\n" // REG_OFFSET(4) + "stp x6, x7, [x2, #((184) + ((6) * (8)))]\n" // REG_OFFSET(6) + "stp x8, x9, [x2, #((184) + ((8) * (8)))]\n" // REG_OFFSET(8) + "stp x10, x11, [x2, #((184) + ((10) * (8)))]\n" // REG_OFFSET(10) + "stp x12, x13, [x2, #((184) + ((12) * (8)))]\n" // REG_OFFSET(12) + "stp x14, x15, [x2, #((184) + ((14) * (8)))]\n" // REG_OFFSET(14) + "stp x16, x17, [x2, #((184) + ((16) * (8)))]\n" // REG_OFFSET(16) + "stp x18, x19, [x2, #((184) + ((18) * (8)))]\n" // REG_OFFSET(18) + "stp x20, x21, [x2, #((184) + ((20) * (8)))]\n" // REG_OFFSET(20) + "stp x22, x23, [x2, #((184) + ((22) * (8)))]\n" // REG_OFFSET(22) + "stp x24, x25, [x2, #((184) + ((24) * (8)))]\n" // REG_OFFSET(24) + "stp x26, x27, [x2, #((184) + ((26) * (8)))]\n" // REG_OFFSET(26) + "stp x28, x29, [x2, #((184) + ((28) * (8)))]\n" // REG_OFFSET(28) + "str x30, [x2, #((184) + ((30) * (8)))]\n" // REG_OFFSET(30) "ret\n"); asm(".global " NAME(setcontext_portable) ";\n"