From schwab@redhat.com Thu Jul 1 12:49:00 2010 From: schwab@redhat.com (Andreas Schwab) Date: Thu, 01 Jul 2010 12:49:00 -0000 Subject: [PATCH] Work around kernel rejecting valid absolute timestamps Message-ID: 2010-07-01 Andreas Schwab * Makefile (tests): Add tst-abstime. * tst-abstime.c: New file. * sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S (__lll_timedlock_wait): Check for timestamp before the Epoch. * sysdeps/unix/sysv/linux/x86_64/lowlevellock.S (__lll_timedlock_wait): Likewise. * sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S (__lll_robust_timedlock_wait): Likewise. * sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S (__pthread_cond_timedwait): Likewise. * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S (pthread_rwlock_timedrdlock): Likewise. * sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S (pthread_rwlock_timedwrlock): Likewise. * sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S (sem_timedwait): Likewise. --- nptl/Makefile | 1 + .../unix/sysv/linux/i386/i486/lowlevellock.S | 10 +++- nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S | 9 ++- .../unix/sysv/linux/x86_64/lowlevelrobustlock.S | 10 +++- .../sysv/linux/x86_64/pthread_cond_timedwait.S | 4 + .../sysv/linux/x86_64/pthread_rwlock_timedrdlock.S | 3 + .../sysv/linux/x86_64/pthread_rwlock_timedwrlock.S | 3 + .../sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S | 5 ++ nptl/tst-abstime.c | 65 ++++++++++++++++++++ 9 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 nptl/tst-abstime.c diff --git a/nptl/Makefile b/nptl/Makefile index f21167d..7a9509b 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -256,6 +256,7 @@ tests = tst-typesizes \ tst-sched1 \ tst-backtrace1 \ tst-oddstacklimit \ + tst-abstime \ tst-vfork1 tst-vfork2 tst-vfork1x tst-vfork2x \ tst-getpid1 tst-getpid2 tst-getpid3 \ tst-initializers1 $(patsubst %,tst-initializers1-%,c89 gnu89 c99 gnu99) diff --git a/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S index 7578c7e..4db8991 100644 --- a/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S +++ b/nptl/sysdeps/unix/sysv/linux/i386/i486/lowlevellock.S @@ -1,4 +1,5 @@ -/* Copyright (C) 2002-2004, 2006, 2007, 2009 Free Software Foundation, Inc. +/* Copyright (C) 2002-2004, 2006, 2007, 2009, 2010 + Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -198,7 +199,10 @@ __lll_timedlock_wait: cmpl %edx, %eax jne 2f -1: movl $SYS_futex, %eax +1: cmpl $0, (%esi) + js 8f + + movl $SYS_futex, %eax movl $2, %edx ENTER_KERNEL @@ -222,6 +226,8 @@ __lll_timedlock_wait: cfi_adjust_cfa_offset(-4) cfi_restore(%ebp) ret +8: movl $ETIMEDOUT, %eax + jmp 7b # ifndef __ASSUME_FUTEX_CLOCK_REALTIME .Lreltmo: diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S index 8de9cf4..60b8c41 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevellock.S @@ -180,7 +180,10 @@ __lll_timedlock_wait: cmpl %edx, %eax jne 2f -1: movl $SYS_futex, %eax +1: cmpq $0, (%r10) + js 5f + + movl $SYS_futex, %eax movl $2, %edx syscall @@ -197,10 +200,12 @@ __lll_timedlock_wait: negl %edx 3: movl %edx, %eax - popq %r9 +6: popq %r9 cfi_adjust_cfa_offset(-8) cfi_restore(%r9) retq +5: movl $ETIMEDOUT, %eax + jmp 6b # ifndef __ASSUME_FUTEX_CLOCK_REALTIME .Lreltmo: diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S index 02db0a4..ed91b28 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/lowlevelrobustlock.S @@ -1,4 +1,4 @@ -/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009 +/* Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper , 2002. @@ -146,7 +146,10 @@ __lll_robust_timedlock_wait: movq $0, %rcx /* Must use mov to avoid changing cc. */ jnz 6f -5: movl $SYS_futex, %eax +5: cmpq $0, (%r10) + js 7f + + movl $SYS_futex, %eax syscall movl %eax, %ecx @@ -168,6 +171,9 @@ __lll_robust_timedlock_wait: cfi_adjust_cfa_offset(8) cfi_rel_offset(%r9, 0) +7: movl $ETIMEDOUT, %eax + jmp 3b + /* Check whether the time expired. */ 2: cmpl $-ETIMEDOUT, %ecx je 4f diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S index be14fc8..093e660 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S @@ -144,6 +144,10 @@ __pthread_cond_timedwait: movq %r9, 24(%rsp) movl %edx, 4(%rsp) + cmpq $0, (%r13) + movq $-ETIMEDOUT, %r14 + js 36f + 38: movl cond_futex(%rdi), %r12d /* Unlock. */ diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S index 23b218a..22a4744 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedrdlock.S @@ -102,6 +102,9 @@ pthread_rwlock_timedrdlock: je .Lreltmo #endif + cmpq $0, (%r13) + js 16f /* Time is already up. */ + movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, %esi xorl PSHARED(%r12), %esi movq %r13, %r10 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S index cd867b6..41ba8f0 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/pthread_rwlock_timedwrlock.S @@ -99,6 +99,9 @@ pthread_rwlock_timedwrlock: je .Lreltmo #endif + cmpq $0, (%r13) + js 16f /* Time is already up. */ + movl $FUTEX_PRIVATE_FLAG|FUTEX_WAIT_BITSET|FUTEX_CLOCK_REALTIME, %esi xorl PSHARED(%r12), %esi movq %r13, %r10 diff --git a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S index 0291beb..e2e970e 100644 --- a/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S +++ b/nptl/sysdeps/unix/sysv/linux/x86_64/sem_timedwait.S @@ -87,6 +87,10 @@ sem_timedwait: LOCK addq $1, NWAITERS(%rdi) + cmpq $0, (%r13) + movq $-ETIMEDOUT, %r9 + js 4f + .LcleanupSTART: 13: call __pthread_enable_asynccancel movl %eax, %r8d @@ -144,6 +148,7 @@ sem_timedwait: cfi_adjust_cfa_offset(8) 3: negq %r9 +4: #if USE___THREAD movq errno@gottpoff(%rip), %rdx movl %r9d, %fs:(%rdx) diff --git a/nptl/tst-abstime.c b/nptl/tst-abstime.c new file mode 100644 index 0000000..73105f7 --- /dev/null +++ b/nptl/tst-abstime.c @@ -0,0 +1,65 @@ +/* Copyright (C) 2010 Free Software Foundation, Inc. + This file is part of the GNU C Library. + Contributed by Andreas Schwab , 2010. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include +#include +#include + +pthread_cond_t c = PTHREAD_COND_INITIALIZER; +pthread_mutex_t m1 = PTHREAD_MUTEX_INITIALIZER; +pthread_mutex_t m2 = PTHREAD_MUTEX_INITIALIZER; +pthread_rwlock_t rw1 = PTHREAD_RWLOCK_INITIALIZER; +pthread_rwlock_t rw2 = PTHREAD_RWLOCK_INITIALIZER; + +static void * +th (void *arg) +{ + int r; + struct timespec t = { -2, 0 }; + + r = pthread_mutex_timedlock (&m1, &t); + assert (r == ETIMEDOUT); + r = pthread_rwlock_timedrdlock (&rw1, &t); + assert (r == ETIMEDOUT); + r = pthread_rwlock_timedwrlock (&rw2, &t); + assert (r == ETIMEDOUT); + return 0; +} + +int +do_test (void) +{ + int r; + struct timespec t = { -2, 0 }; + pthread_t pth; + + pthread_mutex_lock (&m1); + pthread_rwlock_wrlock (&rw1); + pthread_rwlock_rdlock (&rw2); + pthread_mutex_lock (&m2); + pthread_create (&pth, 0, th, 0); + r = pthread_cond_timedwait (&c, &m2, &t); + assert (r == ETIMEDOUT); + pthread_join (pth, 0); + return 0; +} + + +#define TEST_FUNCTION do_test () +#include "../test-skeleton.c" -- 1.7.1 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different." From drepper@redhat.com Fri Jul 2 02:08:00 2010 From: drepper@redhat.com (Ulrich Drepper) Date: Fri, 02 Jul 2010 02:08:00 -0000 Subject: [PATCH] Work around kernel rejecting valid absolute timestamps In-Reply-To: References: Message-ID: <4C2D4A29.8040100@redhat.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 The patch contained a number of inefficiencies and a few bugs which I corrected. - -- ??? Ulrich Drepper ??? Red Hat, Inc. ??? 444 Castro St ??? Mountain View, CA ??? -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.14 (GNU/Linux) iEYEARECAAYFAkwtSikACgkQ2ijCOnn/RHT0eACguJYWfXpb3NH6sb1bS/N2cFL5 Ir0An3c8PeQA2JlRq/5T1tse/AkiD1Hr =UTt/ -----END PGP SIGNATURE----- From schwab@redhat.com Tue Jul 6 12:20:00 2010 From: schwab@redhat.com (Andreas Schwab) Date: Tue, 06 Jul 2010 12:20:00 -0000 Subject: [PATCH] Fix type mismatch Message-ID: 2010-07-06 Andreas Schwab * sysdeps/unix/sysv/linux/pthread_getname.c (pthread_getname_np): Fix type mismatch. --- nptl/sysdeps/unix/sysv/linux/pthread_getname.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/nptl/sysdeps/unix/sysv/linux/pthread_getname.c b/nptl/sysdeps/unix/sysv/linux/pthread_getname.c index 593219b..6e7786f 100644 --- a/nptl/sysdeps/unix/sysv/linux/pthread_getname.c +++ b/nptl/sysdeps/unix/sysv/linux/pthread_getname.c @@ -42,7 +42,7 @@ pthread_getname_np (th, buf, len) if (len < TASK_COMM_LEN) return ERANGE; - if (th == THREAD_SELF) + if (pd == THREAD_SELF) return prctl (PR_GET_NAME, buf) ? errno : 0; #define FMT "/proc/self/task/%u/comm" -- 1.7.1 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different." From schwab@redhat.com Tue Jul 6 12:55:00 2010 From: schwab@redhat.com (Andreas Schwab) Date: Tue, 06 Jul 2010 12:55:00 -0000 Subject: [PATCH] Don't pass NULL occation to dl_signal_cerror Message-ID: 2010-07-06 Andreas Schwab * elf/dl-version.c (match_symbol): Don't pass NULL occation to dl_signal_cerror. --- elf/dl-version.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/elf/dl-version.c b/elf/dl-version.c index c59a6c3..4415817 100644 --- a/elf/dl-version.c +++ b/elf/dl-version.c @@ -169,7 +169,7 @@ no version information available (required by ", name, ")"); result = 1; call_cerror: _dl_signal_cerror (0, map->l_name[0] ? map->l_name : rtld_progname, - NULL, errstring); + N_("version lookup error"), errstring); return result; } -- 1.7.1 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different." From schwab@redhat.com Wed Jul 21 12:30:00 2010 From: schwab@redhat.com (Andreas Schwab) Date: Wed, 21 Jul 2010 12:30:00 -0000 Subject: [PATCH] Add strcasestr-nonascii to i386 build Message-ID: 2010-07-21 Andreas Schwab * sysdeps/i386/i686/multiarch/Makefile (sysdep_routines): Add strcasestr-nonascii. (CFLAGS-strcasestr-nonascii.c): Define. * sysdeps/i386/i686/multiarch/strcasestr-nonascii.c: New file. * sysdeps/x86_64/multiarch/strcasestr-nonascii.c (STRSTR_SSE42): Remove unused attribute. --- sysdeps/i386/i686/multiarch/Makefile | 3 ++- sysdeps/i386/i686/multiarch/strcasestr-nonascii.c | 2 ++ sysdeps/x86_64/multiarch/strcasestr-nonascii.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 sysdeps/i386/i686/multiarch/strcasestr-nonascii.c diff --git a/sysdeps/i386/i686/multiarch/Makefile b/sysdeps/i386/i686/multiarch/Makefile index 1245950..12bcfc2 100644 --- a/sysdeps/i386/i686/multiarch/Makefile +++ b/sysdeps/i386/i686/multiarch/Makefile @@ -9,7 +9,7 @@ sysdep_routines += bzero-sse2 memset-sse2 memcpy-ssse3 mempcpy-ssse3 \ memmove-ssse3-rep bcopy-ssse3 bcopy-ssse3-rep \ memset-sse2-rep bzero-sse2-rep strcmp-ssse3 \ strcmp-sse4 strncmp-c strncmp-ssse3 strncmp-sse4 \ - memcmp-ssse3 memcmp-sse4 + memcmp-ssse3 memcmp-sse4 strcasestr-nonascii ifeq (yes,$(config-cflags-sse4)) sysdep_routines += strcspn-c strpbrk-c strspn-c strstr-c strcasestr-c CFLAGS-strcspn-c.c += -msse4 @@ -17,6 +17,7 @@ CFLAGS-strpbrk-c.c += -msse4 CFLAGS-strspn-c.c += -msse4 CFLAGS-strstr.c += -msse4 CFLAGS-strcasestr.c += -msse4 +CFLAGS-strcasestr-nonascii.c += -msse4 endif endif diff --git a/sysdeps/i386/i686/multiarch/strcasestr-nonascii.c b/sysdeps/i386/i686/multiarch/strcasestr-nonascii.c new file mode 100644 index 0000000..4cc4444 --- /dev/null +++ b/sysdeps/i386/i686/multiarch/strcasestr-nonascii.c @@ -0,0 +1,2 @@ +#include +#include diff --git a/sysdeps/x86_64/multiarch/strcasestr-nonascii.c b/sysdeps/x86_64/multiarch/strcasestr-nonascii.c index 0804e96..b401e4b 100644 --- a/sysdeps/x86_64/multiarch/strcasestr-nonascii.c +++ b/sysdeps/x86_64/multiarch/strcasestr-nonascii.c @@ -46,5 +46,5 @@ __m128i_strloadu_tolower (const unsigned char * p) #define STRCASESTR_NONASCII #define USE_AS_STRCASESTR -#define STRSTR_SSE42 attribute_hidden __strcasestr_sse42_nonascii +#define STRSTR_SSE42 __strcasestr_sse42_nonascii #include "strstr.c" -- 1.7.1.1 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different." From schwab@redhat.com Mon Jul 26 14:37:00 2010 From: schwab@redhat.com (Andreas Schwab) Date: Mon, 26 Jul 2010 14:37:00 -0000 Subject: [PATCH] Document M_PERTURB Message-ID: 2010-07-26 Andreas Schwab * manual/memory.texi (Malloc Tunable Parameters): Document M_PERTURB. diff --git a/manual/memory.texi b/manual/memory.texi index 59ea1ee..6ae408d 100644 --- a/manual/memory.texi +++ b/manual/memory.texi @@ -702,6 +702,11 @@ be allocated via @code{mmap}. @item M_MMAP_MAX The maximum number of chunks to allocate with @code{mmap}. Setting this to zero disables all use of @code{mmap}. +@item M_PERTURB +If non-zero, memory blocks are filled with a value depending on +this parameter when they are allocated (except when allocated by +@code{calloc}) and freed. This can be used to debug the use of +uninitialized or freed heap memory. @end table @end deftypefun -- 1.7.1.1 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different." From roland@redhat.com Mon Jul 26 20:01:00 2010 From: roland@redhat.com (Roland McGrath) Date: Mon, 26 Jul 2010 20:01:00 -0000 Subject: [PATCH] Document M_PERTURB In-Reply-To: Andreas Schwab's message of Monday, 26 July 2010 16:37:45 +0200 References: Message-ID: <20100726200111.3A695400DD@magilla.sf.frob.com> I would s/a value/values/ since there is one value for alloc and one value for free, both based on the perturb byte. I think it should also say "... depending on the low-order byte of this value," so nobody can think that passing in more than 8 bits has any effect. With those tweaks, it's fine to commit it. Thanks, Roland From jakub@redhat.com Mon Jul 26 20:17:00 2010 From: jakub@redhat.com (Jakub Jelinek) Date: Mon, 26 Jul 2010 20:17:00 -0000 Subject: [PATCH] Document M_PERTURB In-Reply-To: <20100726200111.3A695400DD@magilla.sf.frob.com> References: <20100726200111.3A695400DD@magilla.sf.frob.com> Message-ID: <20100726201637.GH4815@sunsite.ms.mff.cuni.cz> On Mon, Jul 26, 2010 at 01:01:11PM -0700, Roland McGrath wrote: > I would s/a value/values/ since there is one value for alloc and one value > for free, both based on the perturb byte. I think it should also say > "... depending on the low-order byte of this value," so nobody can think > that passing in more than 8 bits has any effect. It actually has. MALLOC_PERTURB_=0 doesn't do anything, while MALLOC_PERTURB_=256 does. Jakub From schwab@redhat.com Tue Jul 27 09:13:00 2010 From: schwab@redhat.com (Andreas Schwab) Date: Tue, 27 Jul 2010 09:13:00 -0000 Subject: [PATCH] Document M_PERTURB In-Reply-To: <20100726200111.3A695400DD@magilla.sf.frob.com> (Roland McGrath's message of "Mon, 26 Jul 2010 13:01:11 -0700 (PDT)") References: <20100726200111.3A695400DD@magilla.sf.frob.com> Message-ID: Roland McGrath writes: > I think it should also say "... depending on the low-order byte of > this value," so nobody can think that passing in more than 8 bits has > any effect. Depends on how much of it is considered an implementation detail. Andreas. -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different." From roland@redhat.com Tue Jul 27 09:32:00 2010 From: roland@redhat.com (Roland McGrath) Date: Tue, 27 Jul 2010 09:32:00 -0000 Subject: [PATCH] Document M_PERTURB In-Reply-To: Andreas Schwab's message of Tuesday, 27 July 2010 11:13:29 +0200 References: <20100726200111.3A695400DD@magilla.sf.frob.com> Message-ID: <20100727093207.65BBE400DD@magilla.sf.frob.com> > Roland McGrath writes: > > > I think it should also say "... depending on the low-order byte of > > this value," so nobody can think that passing in more than 8 bits has > > any effect. > > Depends on how much of it is considered an implementation detail. True. Perhaps just say "some low-order bits of this parameter".