newlib: increase jump buffer length to 24 to fit all non-volatile registers for aarch64-pc-cygwin

Message ID DB9PR83MB0923C1EC285457C32476E0849245A@DB9PR83MB0923.EURPRD83.prod.outlook.com
State New
Headers
Series newlib: increase jump buffer length to 24 to fit all non-volatile registers for aarch64-pc-cygwin |

Commit Message

Radek Barton June 27, 2025, 8:21 p.m. UTC
  Hello.

The `msvcrt` implementation of `setjmp`/`longjmp` saves `x19`-`x28`, `FP`, `LR`, `SP`, `FPCR`, `FPSR`, `d8`-`d15` registers and jump address to the jump buffer.

AFAIK the Cygwin implementation of `setjmp`/`longjmp` should do the same for which the value of `_JBLEN` macro defined here needs to be increased to 24 to fit them all.

Radek

---
From edaea9fa87bebd3a1692a2333e67218f068658bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Radek=20Barto=C5=88?= <radek.barton@microsoft.com>
Date: Thu, 29 May 2025 20:34:56 +0200
Subject: [PATCH] newlib: increase jump buffer length to 24 to fit all
 non-volatile registers for aarch64-pc-cygwin
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
---
 newlib/libc/include/machine/setjmp.h | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)
  

Comments

Corinna Vinschen June 30, 2025, 11:01 a.m. UTC | #1
Hi Radek,

On Jun 27 20:21, Radek Barton wrote:
> Hello.
> 
> The `msvcrt` implementation of `setjmp`/`longjmp` saves `x19`-`x28`,
> `FP`, `LR`, `SP`, `FPCR`, `FPSR`, `d8`-`d15` registers and jump
> address to the jump buffer.
> 
> AFAIK the Cygwin implementation of `setjmp`/`longjmp` should do the
> same for which the value of `_JBLEN` macro defined here needs to be
> increased to 24 to fit them all.

Cygwin's setjmp also stores the tls stackptr in jmpbuf.  In case of
x86_64, we can use an existing member of the Windows jmpbuf layout,
but does that work for aarch64, too?  Otherwise we might have to
define _JBLEN a bit bigger.


Thanks,
Corinna


> 
> Radek
> 
> ---
> >From edaea9fa87bebd3a1692a2333e67218f068658bf Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Radek=20Barto=C5=88?= <radek.barton@microsoft.com>
> Date: Thu, 29 May 2025 20:34:56 +0200
> Subject: [PATCH] newlib: increase jump buffer length to 24 to fit all
>  non-volatile registers for aarch64-pc-cygwin
> MIME-Version: 1.0
> Content-Type: text/plain; charset=UTF-8
> Content-Transfer-Encoding: 8bit
> 
> Signed-off-by: Radek Bartoň <radek.barton@microsoft.com>
> ---
>  newlib/libc/include/machine/setjmp.h | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/newlib/libc/include/machine/setjmp.h b/newlib/libc/include/machine/setjmp.h
> index 102582c8e..d73e5589e 100644
> --- a/newlib/libc/include/machine/setjmp.h
> +++ b/newlib/libc/include/machine/setjmp.h
> @@ -22,7 +22,15 @@ _BEGIN_STD_C
>  #endif
>  
>  #if defined(__aarch64__)
> -#define _JBLEN 22
> +# if defined(__CYGWIN__)
> +/* 
> + * Windows Arm64 ABI requires saving x19-x28, FP, LR, SP, FPCR, FPSR, d8-d15
> + * and jump address to jmp_buf.
> + */
> +#  define _JBLEN 24
> +# else
> +#  define _JBLEN 22
> +# endif
>  #define _JBTYPE long long
>  #endif
>  
> -- 
> 2.49.0.vfs.0.4
>
  

Patch

diff --git a/newlib/libc/include/machine/setjmp.h b/newlib/libc/include/machine/setjmp.h
index 102582c8e..d73e5589e 100644
--- a/newlib/libc/include/machine/setjmp.h
+++ b/newlib/libc/include/machine/setjmp.h
@@ -22,7 +22,15 @@  _BEGIN_STD_C
 #endif
 
 #if defined(__aarch64__)
-#define _JBLEN 22
+# if defined(__CYGWIN__)
+/* 
+ * Windows Arm64 ABI requires saving x19-x28, FP, LR, SP, FPCR, FPSR, d8-d15
+ * and jump address to jmp_buf.
+ */
+#  define _JBLEN 24
+# else
+#  define _JBLEN 22
+# endif
 #define _JBTYPE long long
 #endif