Hello. This patch ports reading of stack base from TEB on AArch64 at cygload.cc and __getreent.
Radek --- >From 08f9be50573a085fd3e5cb840455ea5fc3b1e82a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Radek=20Barto=C5=88?= <[email protected]> Date: Wed, 4 Jun 2025 13:38:10 +0200 Subject: [PATCH] Cygwin: obtain stack base on AArch64 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Radek BartoĊ <[email protected]> --- winsup/cygwin/include/cygwin/config.h | 7 ++++++- winsup/testsuite/winsup.api/cygload.cc | 7 +++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/winsup/cygwin/include/cygwin/config.h b/winsup/cygwin/include/cygwin/config.h index 2a7083278..d9f911d47 100644 --- a/winsup/cygwin/include/cygwin/config.h +++ b/winsup/cygwin/include/cygwin/config.h @@ -36,8 +36,13 @@ __attribute__((__gnu_inline__)) extern inline struct _reent *__getreent (void) { register char *ret; -#ifdef __x86_64__ +#if defined(__x86_64__) __asm __volatile__ ("movq %%gs:8,%0" : "=r" (ret)); +#elif defined(__aarch64__) + /* x18 register points to TEB, offset 0x8 points to stack base. + See _TEB structure definition in winsup\cygwin\local_includes\ntdll.h + for more details. */ + __asm __volatile__ ("ldr %0, [x18, #0x8]" : "=r" (ret)); #else #error unimplemented for this target #endif diff --git a/winsup/testsuite/winsup.api/cygload.cc b/winsup/testsuite/winsup.api/cygload.cc index afd3ee90f..08372a302 100644 --- a/winsup/testsuite/winsup.api/cygload.cc +++ b/winsup/testsuite/winsup.api/cygload.cc @@ -82,6 +82,13 @@ cygwin::padding::padding () "movl %%fs:4, %0" :"=r"(stackbase) ); +# elif __aarch64__ + // x18 register points to TEB. See _TEB structure definition in + // winsup\cygwin\local_includes\ntdll.h + __asm__ volatile ( + "ldr %0, [x18, #0x8]" + :"=r" (stackbase) + ); # else # error Unknown architecture # endif -- 2.49.0.vfs.0.4
0001-Cygwin-obtain-stack-base-on-AArch64.patch
Description: 0001-Cygwin-obtain-stack-base-on-AArch64.patch
