diff options
Diffstat (limited to 'nptl')
-rw-r--r-- | nptl/ChangeLog | 36 | ||||
-rw-r--r-- | nptl/allocatestack.c | 20 | ||||
-rw-r--r-- | nptl/init.c | 16 | ||||
-rw-r--r-- | nptl/pthreadP.h | 5 | ||||
-rw-r--r-- | nptl/pthread_mutex_lock.c | 1 | ||||
-rw-r--r-- | nptl/sysdeps/pthread/list.h | 15 | ||||
-rw-r--r-- | nptl/sysdeps/pthread/unwind-forcedunwind.c | 61 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S | 103 | ||||
-rw-r--r-- | nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h | 6 |
9 files changed, 215 insertions, 48 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog index e3c752ee63..eb0f345cd8 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,39 @@ +2009-01-29 Ulrich Drepper <drepper@redhat.com> + + * sysdeps/pthread/unwind-forcedunwind.c: Encrypt all function + pointer variables. + + * allocatestack.c (__free_stacks): Renamed from free_stacks. + (__free_stack_cache): Removed. Change callers to call __free_stacks. + * init.c (nptl_freeres): New function. + (pthread_functions): Initialize ptr_freeres to nptl_freeres. + * pthreadP.h: Don't declare __free_stack_cache. Declare __free_stacks. + * sysdeps/pthread/unwind-forcedunwind.c (libgcc_s_handle): New + variable. + (pthread_cancel_init): Depend in libgcc_s_handle for decision to + load DSO. Assign last. + (__unwind_freeres): New function. + + * allocatestack.c (__reclaim_stacks): Reset in_flight_stack later + for better debugging. No need to use stack_list_add here. + +2009-01-14 Kaz Kojima <kkojima@rr.iij4u.or.jp> + + * sysdeps/unix/sysv/linux/sh/lowlevellock.S + (__lll_timedlock_wait): Use FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME + instead of computing relative timeout. + * sysdeps/unix/sysv/linux/sh/lowlevellock.h: Define + FUTEX_CLOCK_REALTIME and FUTEX_BITSET_MATCH_ANY. + +2009-01-25 Ulrich Drepper <drepper@redhat.com> + + * pthread_mutex_lock.c (__pthread_mutex_lock): Remove unused label out. + +2009-01-08 Ulrich Drepper <drepper@redhat.com> + + * sysdeps/pthread/list.h (list_add): Initialize new element first. + (list_add_tail): Removed. + 2009-01-04 Ulrich Drepper <drepper@redhat.com> * init.c (__pthread_initialize_minimal_internal): Optimize test diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c index ce05770e56..67ea0c68f8 100644 --- a/nptl/allocatestack.c +++ b/nptl/allocatestack.c @@ -248,8 +248,8 @@ get_cached_stack (size_t *sizep, void **memp) /* Free stacks until cache size is lower than LIMIT. */ -static void -free_stacks (size_t limit) +void +__free_stacks (size_t limit) { /* We reduce the size of the cache. Remove the last entries until the size is below the limit. */ @@ -299,15 +299,7 @@ queue_stack (struct pthread *stack) stack_cache_actsize += stack->stackblock_size; if (__builtin_expect (stack_cache_actsize > stack_cache_maxsize, 0)) - free_stacks (stack_cache_maxsize); -} - - -/* This function is called indirectly from the freeres code in libc. */ -void -__free_stack_cache (void) -{ - free_stacks (0); + __free_stacks (stack_cache_maxsize); } @@ -849,8 +841,6 @@ __reclaim_stacks (void) elem->next->prev = elem->prev; elem->prev->next = elem->next; } - - in_flight_stack = 0; } /* Mark all stacks except the still running one as free. */ @@ -913,11 +903,13 @@ __reclaim_stacks (void) if (__builtin_expect (THREAD_GETMEM (self, user_stack), 0)) list_add (&self->list, &__stack_user); else - stack_list_add (&self->list, &stack_used); + list_add (&self->list, &stack_used); /* There is one thread running. */ __nptl_nthreads = 1; + in_flight_stack = 0; + /* Initialize the lock. */ stack_cache_lock = LLL_LOCK_INITIALIZER; } diff --git a/nptl/init.c b/nptl/init.c index 7a6dec5935..d0f1fc3be7 100644 --- a/nptl/init.c +++ b/nptl/init.c @@ -67,6 +67,8 @@ static const char nptl_version[] __attribute_used__ = VERSION; extern void __libc_setup_tls (size_t tcbsize, size_t tcbalign); #endif +static void nptl_freeres (void); + #ifdef SHARED static const struct pthread_functions pthread_functions = @@ -128,7 +130,7 @@ static const struct pthread_functions pthread_functions = .ptr__nptl_deallocate_tsd = __nptl_deallocate_tsd, .ptr__nptl_setxid = __nptl_setxid, /* For now only the stack cache needs to be freed. */ - .ptr_freeres = __free_stack_cache + .ptr_freeres = nptl_freeres }; # define ptr_pthread_functions &pthread_functions #else @@ -136,6 +138,18 @@ static const struct pthread_functions pthread_functions = #endif +/* This function is called indirectly from the freeres code in libc. */ +static void +__libc_freeres_fn_section +nptl_freeres (void) +{ +#ifdef SHARED + __unwind_freeres (); +#endif + __free_stacks (0); +} + + /* For asynchronous cancellation we use a signal. This is the handler. */ static void sigcancel_handler (int sig, siginfo_t *si, void *ctx) diff --git a/nptl/pthreadP.h b/nptl/pthreadP.h index 17b6492ad8..ed9fc625ba 100644 --- a/nptl/pthreadP.h +++ b/nptl/pthreadP.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2002,2003,2004,2005,2006,2007 Free Software Foundation, Inc. +/* Copyright (C) 2002-2007, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -247,6 +247,7 @@ hidden_proto (__pthread_register_cancel) hidden_proto (__pthread_unregister_cancel) # ifdef SHARED extern void attribute_hidden pthread_cancel_init (void); +extern void __unwind_freeres (void); # endif #endif @@ -564,7 +565,7 @@ extern void __nptl_deallocate_tsd (void) attribute_hidden; extern int __nptl_setxid (struct xid_command *cmdp) attribute_hidden; -extern void __free_stack_cache (void) attribute_hidden; +extern void __free_stacks (size_t limit) attribute_hidden; extern void __wait_lookup_done (void) attribute_hidden; diff --git a/nptl/pthread_mutex_lock.c b/nptl/pthread_mutex_lock.c index 4cb98beefb..406e588fdb 100644 --- a/nptl/pthread_mutex_lock.c +++ b/nptl/pthread_mutex_lock.c @@ -121,7 +121,6 @@ __pthread_mutex_lock (mutex) goto simple; } - out: /* Record the ownership. */ mutex->__data.__owner = id; #ifndef NO_INCR diff --git a/nptl/sysdeps/pthread/list.h b/nptl/sysdeps/pthread/list.h index 43186a2d51..6ddccb9fb9 100644 --- a/nptl/sysdeps/pthread/list.h +++ b/nptl/sysdeps/pthread/list.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -46,24 +46,13 @@ typedef struct list_head static inline void list_add (list_t *newp, list_t *head) { - head->next->prev = newp; newp->next = head->next; newp->prev = head; + head->next->prev = newp; head->next = newp; } -/* Add new element at the tail of the list. */ -static inline void -list_add_tail (list_t *newp, list_t *head) -{ - head->prev->next = newp; - newp->next = head; - newp->prev = head->prev; - head->prev = newp; -} - - /* Remove element from list. */ static inline void list_del (list_t *elem) diff --git a/nptl/sysdeps/pthread/unwind-forcedunwind.c b/nptl/sysdeps/pthread/unwind-forcedunwind.c index 6792d719d3..402591f6e4 100644 --- a/nptl/sysdeps/pthread/unwind-forcedunwind.c +++ b/nptl/sysdeps/pthread/unwind-forcedunwind.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2005, 2006 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2005, 2006, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Jakub Jelinek <jakub@redhat.com>. @@ -21,7 +21,9 @@ #include <stdio.h> #include <unwind.h> #include <pthreadP.h> +#include <sysdep.h> +static void *libgcc_s_handle; static void (*libgcc_s_resume) (struct _Unwind_Exception *exc); static _Unwind_Reason_Code (*libgcc_s_personality) (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *, @@ -34,10 +36,13 @@ void __attribute_noinline__ pthread_cancel_init (void) { - void *resume, *personality, *forcedunwind, *getcfa; + void *resume; + void *personality; + void *forcedunwind; + void *getcfa; void *handle; - if (__builtin_expect (libgcc_s_getcfa != NULL, 1)) + if (__builtin_expect (libgcc_s_handle != NULL, 1)) { /* Force gcc to reload all values. */ asm volatile ("" ::: "memory"); @@ -58,23 +63,42 @@ pthread_cancel_init (void) ) __libc_fatal ("libgcc_s.so.1 must be installed for pthread_cancel to work\n"); + PTR_MANGLE (resume); libgcc_s_resume = resume; + PTR_MANGLE (personality); libgcc_s_personality = personality; + PTR_MANGLE (forcedunwind); libgcc_s_forcedunwind = forcedunwind; - /* Make sure libgcc_s_getcfa is written last. Otherwise, + PTR_MANGLE (getcfa); + libgcc_s_getcfa = getcfa; + /* Make sure libgcc_s_handle is written last. Otherwise, pthread_cancel_init might return early even when the pointer the caller is interested in is not initialized yet. */ atomic_write_barrier (); - libgcc_s_getcfa = getcfa; + libgcc_s_handle = handle; +} + +void +__libc_freeres_fn_section +__unwind_freeres (void) +{ + void *handle = libgcc_s_handle; + if (handle != NULL) + { + libgcc_s_handle = NULL; + __libc_dlclose (handle); + } } void _Unwind_Resume (struct _Unwind_Exception *exc) { - if (__builtin_expect (libgcc_s_resume == NULL, 0)) + if (__builtin_expect (libgcc_s_handle == NULL, 0)) pthread_cancel_init (); - libgcc_s_resume (exc); + void (*resume) (struct _Unwind_Exception *exc) = libgcc_s_resume; + PTR_DEMANGLE (resume); + resume (exc); } _Unwind_Reason_Code @@ -83,28 +107,37 @@ __gcc_personality_v0 (int version, _Unwind_Action actions, struct _Unwind_Exception *ue_header, struct _Unwind_Context *context) { - if (__builtin_expect (libgcc_s_personality == NULL, 0)) + if (__builtin_expect (libgcc_s_handle == NULL, 0)) pthread_cancel_init (); - return libgcc_s_personality (version, actions, exception_class, - ue_header, context); + _Unwind_Reason_Code (*personality) + (int, _Unwind_Action, _Unwind_Exception_Class, struct _Unwind_Exception *, + struct _Unwind_Context *) = libgcc_s_personality; + PTR_DEMANGLE (personality); + return personality (version, actions, exception_class, ue_header, context); } _Unwind_Reason_Code _Unwind_ForcedUnwind (struct _Unwind_Exception *exc, _Unwind_Stop_Fn stop, void *stop_argument) { - if (__builtin_expect (libgcc_s_forcedunwind == NULL, 0)) + if (__builtin_expect (libgcc_s_handle == NULL, 0)) pthread_cancel_init (); - return libgcc_s_forcedunwind (exc, stop, stop_argument); + _Unwind_Reason_Code (*forcedunwind) + (struct _Unwind_Exception *, _Unwind_Stop_Fn, void *) + = libgcc_s_forcedunwind; + PTR_DEMANGLE (forcedunwind); + return forcedunwind (exc, stop, stop_argument); } _Unwind_Word _Unwind_GetCFA (struct _Unwind_Context *context) { - if (__builtin_expect (libgcc_s_getcfa == NULL, 0)) + if (__builtin_expect (libgcc_s_handle == NULL, 0)) pthread_cancel_init (); - return libgcc_s_getcfa (context); + _Unwind_Word (*getcfa) (struct _Unwind_Context *) = libgcc_s_getcfa; + PTR_DEMANGLE (getcfa); + return getcfa (context); } diff --git a/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S index d8279173d7..c051192cee 100644 --- a/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S +++ b/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.S @@ -1,4 +1,4 @@ -/* Copyright (C) 2003, 2004, 2005, 2007, 2008 +/* Copyright (C) 2003, 2004, 2005, 2007, 2008, 2009 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -36,6 +36,13 @@ mov #(FUTEX_WAIT | FUTEX_PRIVATE_FLAG), tmp; \ extu.b tmp, tmp; \ xor tmp, reg +# define LOAD_FUTEX_WAIT_ABS(reg,tmp,tmp2) \ + mov #(FUTEX_WAIT_BITSET | FUTEX_PRIVATE_FLAG), tmp; \ + extu.b tmp, tmp; \ + mov #(FUTEX_CLOCK_REALTIME >> 8), tmp2; \ + swap.b tmp2, tmp2; \ + or tmp2, tmp; \ + xor tmp, reg # define LOAD_FUTEX_WAKE(reg,tmp,tmp2) \ mov #(FUTEX_WAKE | FUTEX_PRIVATE_FLAG), tmp; \ extu.b tmp, tmp; \ @@ -96,6 +103,22 @@ and tmp2, reg ; \ mov #FUTEX_WAIT, tmp ; \ or tmp, reg +# define LOAD_FUTEX_WAIT_ABS(reg,tmp,tmp2) \ + stc gbr, tmp ; \ + mov.w 99f, tmp2 ; \ + add tmp2, tmp ; \ + mov.l @tmp, tmp2 ; \ + bra 98f ; \ + mov #FUTEX_PRIVATE_FLAG, tmp ; \ +99: .word PRIVATE_FUTEX - TLS_PRE_TCB_SIZE ; \ +98: extu.b tmp, tmp ; \ + xor tmp, reg ; \ + and tmp2, reg ; \ + mov #FUTEX_WAIT_BITSET, tmp ; \ + mov #(FUTEX_CLOCK_REALTIME >> 8), tmp2; \ + swap.b tmp2, tmp2; \ + or tmp2, tmp; \ + or tmp, reg # endif # define LOAD_FUTEX_WAKE(reg,tmp,tmp2) \ stc gbr, tmp ; \ @@ -193,12 +216,85 @@ __lll_lock_wait: cfi_endproc .size __lll_lock_wait,.-__lll_lock_wait + /* r5 (r8): futex + r7 (r11): flags + r6 (r9): timeout + r4 (r10): futex value + */ .globl __lll_timedlock_wait .type __lll_timedlock_wait,@function .hidden __lll_timedlock_wait .align 5 cfi_startproc __lll_timedlock_wait: + mov.l r12, @-r15 + cfi_adjust_cfa_offset(4) + cfi_rel_offset (r12, 0) + +# ifndef __ASSUME_FUTEX_CLOCK_REALTIME + mov.l .Lhave, r1 +# ifdef PIC + mova .Lgot, r0 + mov.l .Lgot, r12 + add r0, r12 + add r12, r1 +# endif + mov.l @r1, r0 + tst r0, r0 + bt .Lreltmo +# endif + + mov r4, r2 + mov r5, r4 + mov r7, r5 + mov r6, r7 + LOAD_FUTEX_WAIT_ABS (r5, r0, r1) + + mov #2, r6 + cmp/eq r6, r2 + bf/s 2f + mov r2, r6 + +1: + mov #2, r6 + mov #-1, r1 + mov #SYS_futex, r3 + extu.b r3, r3 + trapa #0x16 + SYSCALL_INST_PAD + mov r0, r6 + +2: + XCHG (r2, @r4, r3) /* NB: lock is implied */ + + tst r3, r3 + bt/s 3f + mov r6, r0 + + cmp/eq #-ETIMEDOUT, r0 + bt 4f + cmp/eq #-EINVAL, r0 + bf 1b +4: + neg r0, r3 +3: + mov r3, r0 + rts + mov.l @r15+, r12 + + .align 2 +# ifdef PIC +.Lgot: + .long _GLOBAL_OFFSET_TABLE_ +.Lhave: + .long __have_futex_clock_realtime@GOTOFF +# else +.Lhave: + .long __have_futex_clock_realtime +# endif + +# ifndef __ASSUME_FUTEX_CLOCK_REALTIME +.Lreltmo: /* Check for a valid timeout value. */ mov.l @(4,r6), r1 mov.l .L1g, r0 @@ -290,12 +386,15 @@ __lll_timedlock_wait: mov.l @r15+, r8 mov.l @r15+, r9 mov.l @r15+, r10 + mov.l @r15+, r11 rts - mov.l @r15+, r11 + mov.l @r15+, r12 3: + mov.l @r15+, r12 rts mov #EINVAL, r0 +# endif cfi_endproc .L1k: diff --git a/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h b/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h index e709667e54..853a2daf1b 100644 --- a/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h +++ b/nptl/sysdeps/unix/sysv/linux/sh/lowlevellock.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2003, 2004, 2006, 2007, 2008 Free Software Foundation, Inc. +/* Copyright (C) 2003, 2004, 2006, 2007, 2008, 2009 + Free Software Foundation, Inc. This file is part of the GNU C Library. The GNU C Library is free software; you can redistribute it and/or @@ -37,6 +38,9 @@ #define FUTEX_WAIT_BITSET 9 #define FUTEX_WAKE_BITSET 10 #define FUTEX_PRIVATE_FLAG 128 +#define FUTEX_CLOCK_REALTIME 256 + +#define FUTEX_BITSET_MATCH_ANY 0xffffffff #define FUTEX_OP_CLEAR_WAKE_IF_GT_ONE ((4 << 24) | 1) |