[newlib-cygwin] Cygwin: obtain stack pointer on AArch64

Jeremy Drake via Cygwin-cvs <[email protected]>
Newsgroups gmane.os.cygwin.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=d8ba663f355e55c537761a626c88cefaf1f3bc8e

commit d8ba663f355e55c537761a626c88cefaf1f3bc8e
Author: Radek Bartoň <[email protected]>
Date:   Fri Jun 6 10:21:10 2025 +0200

    Cygwin: obtain stack pointer on AArch64
    
    Signed-off-by: Radek Bartoň <[email protected]>

Diff:
---
 winsup/cygwin/fork.cc                 | 4 +++-
 winsup/cygwin/local_includes/cygtls.h | 6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fork.cc b/winsup/cygwin/fork.cc
index f88acdbbf..4abc52598 100644
--- a/winsup/cygwin/fork.cc
+++ b/winsup/cygwin/fork.cc
@@ -660,8 +660,10 @@ dofork (void **proc, bool *with_forkables)
     ischild = !!setjmp (grouped.ch.jmp);
 
     volatile char * volatile stackp;
-#ifdef __x86_64__
+#if defined(__x86_64__)
     __asm__ volatile ("movq %%rsp,%0": "=r" (stackp));
+#elif defined(__aarch64__)
+    __asm__ volatile ("mov %0, sp" : "=r" (stackp));
 #else
 #error unimplemented for this target
 #endif
diff --git a/winsup/cygwin/local_includes/cygtls.h b/winsup/cygwin/local_includes/cygtls.h
index 615361d3f..29a539d83 100644
--- a/winsup/cygwin/local_includes/cygtls.h
+++ b/winsup/cygwin/local_includes/cygtls.h
@@ -322,7 +322,13 @@ public:
        address of the _except block to restore the context correctly.
        See comment preceeding myfault_altstack_handler in exception.cc. */
     ret = (DWORD64) _ret;
+#if defined(__x86_64__)
     __asm__ volatile ("movq %%rsp,%0": "=o" (frame));
+#elif defined(__aarch64__)
+    __asm__ volatile ("mov %0, sp" : "=r" (frame));
+#else
+#error unimplemented for this target
+#endif
   }
   ~san () __attribute__ ((always_inline))
   {
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.