Hi all,

Please find the attached patch which adds an ARM64 stub for the `_sigfe` routine
in the gendef script.

Any feedback or nits are very welcome. The changes are documented with inline
comments intended to be self-explanatory. please let me know if any part
of this patch should be adjusted.

Thanks for your time and review.

Thanks & regards
Thirumalai Nagalingam <[email protected]>

In-lined patch:

diff --git a/winsup/cygwin/scripts/gendef b/winsup/cygwin/scripts/gendef
index 52a5b77ca..976e0f9f6 100755
--- a/winsup/cygwin/scripts/gendef
+++ b/winsup/cygwin/scripts/gendef
@@ -385,7 +385,44 @@ _sigfe_maybe:                                      # stack 
is aligned on entry!
        ret
        .seh_endproc

+    .seh_proc _sigfe
 _sigfe:
+    .seh_endprologue
+    ldr     x10, [x18, #0x8]           // Load TLS base into x10
+    mov     w9, #1                     // constant value for lock acquisition
+0:  ldr     x11, =_cygtls.stacklock    // Load offset of stacklock
+    add     x12, x10, x11              // Compute final address of stacklock
+    ldaxr   w13, [x12]                 // Load current stacklock value 
atomically
+    stlxr   w14, w9, [x12]             // Attempt to store 1 to stacklock 
atomically
+    cbnz    w14, 0b                    // Retry if atomic store failed
+    cbz     w13, 1f                    // If lock was free, proceed
+    yield
+    b       0b                         // Retry acquiring the lock
+1:
+    ldr     x11, =_cygtls.incyg        // Load offset of incyg
+    add     x12, x10, x11              // Compute final address of incyg
+    ldr     w9, [x12]                  // Load current incyg value
+    add     w9, w9, #1                 // Increment incyg
+    str     w9, [x12]                  // Store updated incyg value
+    mov     x9, #8                     // Set stack frame size increment (8 
bytes)
+2:  ldr     x11, =_cygtls.stackptr     // Load offset of stack pointer
+    add     x12, x10, x11              // Compute final address of stack 
pointer
+    ldaxr   x13, [x12]                 // Atomically load current stack pointer
+    add     x14, x13, x9               // Compute new stack pointer value
+    stlxr   w15, x14, [x12]            // Attempt to update stack pointer 
atomically
+    cbnz    w15, 2b                    // Retry if atomic update failed
+    str     x30, [x13]                 // Save LR(return address) on stack
+    adr     x11, _sigbe                // Load address of _sigbe
+    mov     x30, x11                   // Set LR = _sigbe
+    ldr     x11, =_cygtls.stacklock    // Load offset of stacklock TLS variable
+    add     x12, x10, x11              // Compute final address of stacklock
+    ldr     w9, [x12]                  // Load current stacklock value
+    sub     w9, w9, #1                 // Decrement stacklock to release lock
+    stlr    w9, [x12]                  // Store stacklock value (release lock)
+    ldr     x9, [sp], #16              // Pop real func address from stack
+    br      x9                         // Branch to real function
+    .seh_endproc
+
 _sigbe:
        .global sigdelayed
        .seh_proc sigdelayed

Attachment: Cygwin-gendef-Implement-_sigfe-function-for-TLS-hand.patch
Description: Cygwin-gendef-Implement-_sigfe-function-for-TLS-hand.patch

Reply via email to