Hi all,

Please find the attached patch which adds an ARM64 stub for the `_sigbe` 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 976e0f9f6..fdb970f6f 100755
--- a/winsup/cygwin/scripts/gendef
+++ b/winsup/cygwin/scripts/gendef
@@ -423,7 +423,43 @@ _sigfe:
     br      x9                         // Branch to real function
     .seh_endproc

+    .global _sigbe
+    .seh_proc _sigbe
 _sigbe:
+    .seh_endprologue
+    ldr     x10, [x18, #0x8]           // Load TLS base into x10
+    mov     w9, #1                     // Constant value 1 for lock acquisition
+3:  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 set stacklock atomically
+    cbnz    w14, 3b                    // Retry if failed
+    cbz     w13, 4f                    // If lock was free, continue
+    yield
+    b       3b                         // Retry acquiring the lock
+4:
+    mov     x9, #-8                    // Set stack pointer decrement value
+5:  ldr     x11, =_cygtls.stackptr     // Load offset of stack pointer
+    add     x12, x10, x11              // Compute final address of stack 
pointer
+    ldaxr   x13, [x12]                 // Load current stack pointer atomically
+    add     x14, x13, x9               // Compute new stack pointer value
+    stlxr   w15, x14, [x12]            // Attempt to update stack pointer 
atomically
+    cbnz    w15, 5b                    // Retry if atomic update failed
+    sub     x13, x13, #8               // Compute address where LR was saved
+    ldr     x30, [x13]                 // Restore saved LR
+    ldr     x11, =_cygtls.incyg        // Load offset of incyg
+    add     x12, x10, x11              // Compute final address of incyg
+    ldr     w9, [x12]                  // Load current incyg value
+    sub     w9, w9, #1                 // Decrement incyg
+    str     w9, [x12]                  // Store updated incyg value
+    ldr     x11, =_cygtls.stacklock    // Load offset of stacklock
+    add     x12, x10, x11              // Compute final address of stacklock
+    ldr     w9, [x12]                  // Load current stacklock value
+    sub     w9, w9, #1                 // Decrement stacklock (release lock)
+    stlr    w9, [x12]                  // Store stacklock
+    ret                                // Return to caller using restored LR
+    .seh_endproc
+
        .global sigdelayed
        .seh_proc sigdelayed
 sigdelayed:


Attachment: Cygwin-gendef-Implement-_sigbe-function-for-TLS-stac.patch
Description: Cygwin-gendef-Implement-_sigbe-function-for-TLS-stac.patch

Reply via email to