This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] Memory fencing problem in pthread cancellation


On 01/14/2013 03:11 PM, Carlos O'Donell wrote:
On 01/14/2013 03:24 PM, Jeff Law wrote:


You need to fix the assembly also.
[ ... ]


Thus you need something like this completely untested patch:


diff --git a/ports/sysdeps/arm/bits/atomic.h b/ports/sysdeps/arm/bits/atomic.h
index 6e20df7..b0f45ad 100644
--- a/ports/sysdeps/arm/bits/atomic.h
+++ b/ports/sysdeps/arm/bits/atomic.h
@@ -42,6 +42,7 @@ void __arm_link_error (void);
  # define atomic_full_barrier() __sync_synchronize ()
  #else
  # define atomic_full_barrier() __arm_assisted_full_barrier ()
+# define atomic_asm_full_barrier() __arm_asm_assisted_full_barrier ()
  #endif
Added.


/* An OS-specific bits/atomic.h file will define this macro if diff --git a/ports/sysdeps/unix/sysv/linux/arm/bits/atomic.h b/ports/sysdeps/unix/sysv/linux/arm/bits/atomic.h index c76b8f3..726d3ce 100644 --- a/ports/sysdeps/unix/sysv/linux/arm/bits/atomic.h +++ b/ports/sysdeps/unix/sysv/linux/arm/bits/atomic.h @@ -17,7 +17,8 @@ <http://www.gnu.org/licenses/>. */

  /* If the compiler doesn't provide a primitive, we'll use this macro
-   to get assistance from the kernel.  */
+   to get assistance from the kernel. This should call the
+   __kuser_memory_barrier helper in the kernel.  */
  #ifdef __thumb2__
  # define __arm_assisted_full_barrier() \
       __asm__ __volatile__                                                    \
@@ -25,6 +26,11 @@
               "movt\tip, #0xffff\n\t"                                         \
               "blx\tip"                                                       \
               : : : "ip", "lr", "cc", "memory");
+/* The asm variant is used as an insert into existing asm statements.  */
+# define __arm_asm_assisted_full_barrier() \
+       "       movw    ip, #0x0fa0\n" \
+       "       movt    ip, #0xffff\n" \
+       "       blx     ip"
  #else
  # define __arm_assisted_full_barrier() \
       __asm__ __volatile__                                                    \
@@ -32,6 +38,11 @@
               "mov\tlr, pc\n\t"                                               \
               "add\tpc, ip, #(0xffff0fa0 - 0xffff0fff)"                       \
               : : : "ip", "lr", "cc", "memory");
+/* The asm variant is used as an insert into existing asm statements.  */
+# define __arm_asm_assisted_full_barrier() \
+       "       mov     ip, #0xffff0fff\n" \
+       "       mov     lr, pc\n" \
+       "       add     pc, ip, #(0xffff0fa0 - 0xffff0fff)"
  #endif
Added.



/* Atomic compare and exchange. This sequence relies on the kernel to diff --git a/ports/sysdeps/unix/sysv/linux/arm/nptl/unwind-forcedunwind.c b/ports/sysdeps/unix/sysv/linux/arm/nptl/unwind-forcedunwind.c index 58ca9ac..d7ac847 100644 --- a/ports/sysdeps/unix/sysv/linux/arm/nptl/unwind-forcedunwind.c +++ b/ports/sysdeps/unix/sysv/linux/arm/nptl/unwind-forcedunwind.c @@ -104,6 +104,7 @@ asm ( " mov r6, r0\n" " cmp r3, #0\n" " beq 4f\n" + atomic_asm_full_barrier() "5: mov r0, r6\n" " ldmfd sp!, {r4, r5, r6, lr}\n" " " CFI_ADJUST_CFA_OFFSET (-16) "\n" @@ -123,7 +124,7 @@ asm ( #else "1: .word _GLOBAL_OFFSET_TABLE_ - 3b - 8\n" #endif -"2: .word libgcc_s_resume(GOTOFF)\n" +"2: .word libgcc_s_handle(GOTOFF)\n" " .size _Unwind_Resume, .-_Unwind_Resume\n" );
Not added as there's a later revision.

jeff



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]