aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-12-18 00:53:21 +0000
committerUlrich Drepper <drepper@redhat.com>2002-12-18 00:53:21 +0000
commitf077a4a9f027b938bd091583e3ec34725cba428c (patch)
tree6052d47da431d7cd5e745dab1a908a5f54ffbfc7
parenta7d5c29129aab547faff1fd2cfe0d9095ec4689b (diff)
downloadglibc-f077a4a9f027b938bd091583e3ec34725cba428c.zip
glibc-f077a4a9f027b938bd091583e3ec34725cba428c.tar.gz
glibc-f077a4a9f027b938bd091583e3ec34725cba428c.tar.bz2
Update.
2002-12-17 Jakub Jelinek <jakub@redhat.com> * malloc/thread-m.h (mutex_init, mutex_lock, mutex_trylock, mutex_unlock): If not building NPTL, use __libc_maybe_call2 if available, otherwise __libc_maybe_call. * sysdeps/unix/sysv/linux/x86_64/recv.c: Add support for cancellation handling. * sysdeps/unix/sysv/linux/x86_64/send.c: Likewise.
-rw-r--r--ChangeLog9
-rw-r--r--malloc/thread-m.h37
-rw-r--r--nptl/ChangeLog14
-rw-r--r--nptl/Makefile14
-rw-r--r--nptl/tst-cancel-wrappers.sh94
-rw-r--r--nptl/tst-cancel6.c79
-rw-r--r--nptl/tst-locale1.c6
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/recv.c14
-rw-r--r--sysdeps/unix/sysv/linux/x86_64/send.c13
9 files changed, 266 insertions, 14 deletions
diff --git a/ChangeLog b/ChangeLog
index e1168cb..e9eba10 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2002-12-17 Jakub Jelinek <jakub@redhat.com>
+
+ * malloc/thread-m.h (mutex_init, mutex_lock, mutex_trylock,
+ mutex_unlock): If not building NPTL, use __libc_maybe_call2 if
+ available, otherwise __libc_maybe_call.
+ * sysdeps/unix/sysv/linux/x86_64/recv.c: Add support for
+ cancellation handling.
+ * sysdeps/unix/sysv/linux/x86_64/send.c: Likewise.
+
2002-12-17 Isamu Hasegawa <isamu@yamato.ibm.com>
* posix/regcomp.c (free_workarea_compile): Free the new member
diff --git a/malloc/thread-m.h b/malloc/thread-m.h
index 34fea0e..49db784 100644
--- a/malloc/thread-m.h
+++ b/malloc/thread-m.h
@@ -35,21 +35,42 @@
#ifdef PTHREAD_MUTEX_INITIALIZER
-/* mutex */
__libc_lock_define (typedef, mutex_t)
-/* Even if not linking with libpthread, ensure usability of mutex as
- an `in use' flag, see also the NO_THREADS case below. Assume
- pthread_mutex_t is at least one int wide. */
+#if defined(LLL_LOCK_INITIALIZER) && !defined(NOT_IN_libc)
+
+/* Assume NPTL. */
+
+#define mutex_init(m) __libc_lock_init (*(m))
+#define mutex_lock(m) __libc_lock_lock (*(m))
+#define mutex_trylock(m) __libc_lock_trylock (*(m))
+#define mutex_unlock(m) __libc_lock_unlock (*(m))
+
+#elif defined(__libc_maybe_call2)
#define mutex_init(m) \
- __libc_lock_init (*m)
+ __libc_maybe_call2 (pthread_mutex_init, (m, NULL), (*(int *)(m) = 0))
#define mutex_lock(m) \
- __libc_lock_lock (*m)
+ __libc_maybe_call2 (pthread_mutex_lock, (m), ((*(int *)(m) = 1), 0))
#define mutex_trylock(m) \
- __libc_lock_trylock (*m)
+ __libc_maybe_call2 (pthread_mutex_trylock, (m), \
+ (*(int *)(m) ? 1 : ((*(int *)(m) = 1), 0)))
#define mutex_unlock(m) \
- __libc_lock_unlock (*m)
+ __libc_maybe_call2 (pthread_mutex_unlock, (m), (*(int *)(m) = 0))
+
+#else
+
+#define mutex_init(m) \
+ __libc_maybe_call (__pthread_mutex_init, (m, NULL), (*(int *)(m) = 0))
+#define mutex_lock(m) \
+ __libc_maybe_call (__pthread_mutex_lock, (m), ((*(int *)(m) = 1), 0))
+#define mutex_trylock(m) \
+ __libc_maybe_call (__pthread_mutex_trylock, (m), \
+ (*(int *)(m) ? 1 : ((*(int *)(m) = 1), 0)))
+#define mutex_unlock(m) \
+ __libc_maybe_call (__pthread_mutex_unlock, (m), (*(int *)(m) = 0))
+
+#endif
#define thread_atfork(prepare, parent, child) \
(__pthread_atfork != NULL ? __pthread_atfork(prepare, parent, child) : 0)
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 0b7bbd4..ea32d2a 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,5 +1,19 @@
2002-12-17 Jakub Jelinek <jakub@redhat.com>
+ * Makefile (libpthread-shared-only-routines): Add pt-allocrtsig.
+ (tests): Depend on $(objpfx)tst-cancel-wrappers.out.
+ ($(objpfx)tst-cancel-wrappers.out): New rule.
+ * tst-cancel-wrappers.sh: New test.
+ * tst-locale1.c: Include signal.h.
+ (uselocale): Test static linking of __libc_current_sigrt*.
+
+2002-12-17 Ulrich Drepper <drepper@redhat.com>
+
+ * Makefile (tests): Add tst-cancel6.
+ * tst-cancel6.c: New file
+
+2002-12-17 Jakub Jelinek <jakub@redhat.com>
+
* sysdeps/unix/sysv/linux/i386/sysdep-cancel.h (SINGLE_THREAD_P):
Define meaningfully for assembler as well.
* pthreadP.h (struct pthread_functions): Remove
diff --git a/nptl/Makefile b/nptl/Makefile
index 88f038d..6b09f08 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -107,6 +107,8 @@ libpthread-routines = init events \
herrno res pt-allocrtsig \
pthread_kill_other_threads
+libpthread-shared-only-routines = pt-allocrtsig
+
libpthread-nonshared = pthread_atfork
@@ -126,6 +128,7 @@ tests = tst-mutex1 tst-mutex2 tst-mutex3 tst-mutex4 tst-mutex5 tst-mutex6 \
tst-fork1 tst-fork2 tst-fork3 \
tst-atfork1 \
tst-cancel1 tst-cancel2 tst-cancel3 tst-cancel4 tst-cancel5 \
+ tst-cancel6 \
tst-cleanup1 \
tst-flock1 tst-flock2 \
tst-signal1 tst-signal2 tst-signal3 \
@@ -241,3 +244,14 @@ $(objpfx)crti.o: $(objpfx)crti.S $(objpfx)defs.h
generated += crti.S defs.h pt-initfini.s
endif
+
+ifeq (no,$(cross-compiling))
+ifeq (yes,$(build-shared))
+tests: $(objpfx)tst-cancel-wrappers.out
+$(objpfx)tst-cancel-wrappers.out: tst-cancel-wrappers.sh
+ $(SHELL) $< $(common-objpfx)libc_pic.a \
+ $(common-objpfx)libc.a \
+ $(objpfx)libpthread_pic.a \
+ $(objpfx)libpthread.a > $@
+endif
+endif
diff --git a/nptl/tst-cancel-wrappers.sh b/nptl/tst-cancel-wrappers.sh
new file mode 100644
index 0000000..39ded2e
--- /dev/null
+++ b/nptl/tst-cancel-wrappers.sh
@@ -0,0 +1,94 @@
+#! /bin/sh
+# Test whether all cancellable functions are cancellable.
+# Copyright (C) 2002 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+# Contributed by Jakub Jelinek <jakub@redhat.com>, 2002.
+
+# 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.
+
+while [ $# -gt 0 ]; do
+ ( nm -P $1; echo 'end[end]:' ) | awk ' BEGIN {
+C["accept"]=1
+C["close"]=1
+C["connect"]=1
+C["creat"]=1
+C["fcntl"]=1
+C["fsync"]=1
+C["llseek"]=1
+C["lseek"]=1
+C["msgrcv"]=1
+C["msgsnd"]=1
+C["msync"]=1
+C["nanosleep"]=1
+C["open"]=1
+C["open64"]=1
+C["pause"]=1
+C["poll"]=1
+C["pread"]=1
+C["pread64"]=1
+C["pselect"]=1
+C["pwrite"]=1
+C["pwrite64"]=1
+C["read"]=1
+C["readv"]=1
+C["recv"]=1
+C["recvfrom"]=1
+C["recvmsg"]=1
+C["select"]=1
+C["send"]=1
+C["sendmsg"]=1
+C["sendto"]=1
+C["sigpause"]=1
+C["sigsuspend"]=1
+C["sigwait"]=1
+C["sigwaitinfo"]=1
+C["system"]=1
+C["tcdrain"]=1
+C["wait"]=1
+C["waitid"]=1
+C["waitpid"]=1
+C["write"]=1
+C["writev"]=1
+C["__xpg_sigpause"]=1
+}
+/:$/ {
+ if (seen)
+ {
+ if (!seen_enable || !seen_disable)
+ {
+ printf "in '$1'(%s) %s'\''s cancellation missing\n", object, seen
+ ret = 1
+ }
+ }
+ seen=""
+ seen_enable=""
+ seen_disable=""
+ object=gensub(/^.*\[(.*)\]:$/,"\\1","",$0)
+ next
+}
+{
+ if (C[$1] && $2 ~ /^[TW]$/)
+ seen=$1
+ else if ($1 ~ /^__(libc|pthread)_enable_asynccancel$/ && $2 == "U")
+ seen_enable=1
+ else if ($1 ~ /^__(libc|pthread)_disable_asynccancel$/ && $2 == "U")
+ seen_disable=1
+}
+END {
+ exit ret
+}' || exit
+ shift
+done
diff --git a/nptl/tst-cancel6.c b/nptl/tst-cancel6.c
new file mode 100644
index 0000000..94de858
--- /dev/null
+++ b/nptl/tst-cancel6.c
@@ -0,0 +1,79 @@
+/* Copyright (C) 2002 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2002.
+
+ 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 <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+
+static void *
+tf (void *arg)
+{
+ char buf[100];
+ fgets (buf, sizeof (buf), arg);
+ /* This call should never return. */
+ return NULL;
+}
+
+
+static int
+do_test (void)
+{
+ int fd[2];
+ if (pipe (fd) != 0)
+ {
+ puts ("pipe failed");
+ return 1;
+ }
+
+ FILE *fp = fdopen (fd[0], "r");
+ if (fp == NULL)
+ {
+ puts ("fdopen failed");
+ return 1;
+ }
+
+ pthread_t th;
+ if (pthread_create (&th, NULL, tf, fp) != 0)
+ {
+ puts ("pthread_create failed");
+ return 1;
+ }
+
+ sleep (1);
+
+ if (pthread_cancel (th) != 0)
+ {
+ puts ("pthread_cancel failed");
+ return 1;
+ }
+
+ void *r;
+ if (pthread_join (th, &r) != 0)
+ {
+ puts ("pthread_join failed");
+ return 1;
+ }
+
+ return r != PTHREAD_CANCELED;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
diff --git a/nptl/tst-locale1.c b/nptl/tst-locale1.c
index 3c88e72..08b4370 100644
--- a/nptl/tst-locale1.c
+++ b/nptl/tst-locale1.c
@@ -4,10 +4,14 @@
#include "../locale/tst-C-locale.c"
#include <pthread.h>
+#include <signal.h>
/* This is never called, just here to get pthreads linked in. */
-void
+int
useless (void)
{
pthread_create (0, 0, 0, 0);
+ /* This is to check __libc_current_sigrt* can be used in statically
+ linked apps. */
+ return SIGRTMIN;
}
diff --git a/sysdeps/unix/sysv/linux/x86_64/recv.c b/sysdeps/unix/sysv/linux/x86_64/recv.c
index 9ffeb5e..2fa1794 100644
--- a/sysdeps/unix/sysv/linux/x86_64/recv.c
+++ b/sysdeps/unix/sysv/linux/x86_64/recv.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2001 Free Software Foundation, Inc.
+/* Copyright (C) 2001, 2002 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
@@ -18,7 +18,7 @@
#include <errno.h>
#include <sys/socket.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
/* Read N bytes into BUF from socket FD.
Returns the number read or -1 for errors. */
@@ -26,8 +26,16 @@
ssize_t
__libc_recv (int fd, void *buf, size_t n, int flags)
{
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, NULL, NULL);
- return INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, NULL, NULL);
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = INLINE_SYSCALL (recvfrom, 6, fd, buf, n, flags, NULL, NULL);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
}
weak_alias (__libc_recv, __recv)
diff --git a/sysdeps/unix/sysv/linux/x86_64/send.c b/sysdeps/unix/sysv/linux/x86_64/send.c
index bfbd212..c484ce6 100644
--- a/sysdeps/unix/sysv/linux/x86_64/send.c
+++ b/sysdeps/unix/sysv/linux/x86_64/send.c
@@ -18,13 +18,22 @@
#include <errno.h>
#include <sys/socket.h>
-#include <sysdep.h>
+#include <sysdep-cancel.h>
/* Send N bytes of BUF to socket FD. Returns the number sent or -1. */
ssize_t
__libc_send (int fd, const void *buf, size_t n, int flags)
{
- return INLINE_SYSCALL (sendto, 6, fd, buf, n, flags, NULL, NULL);
+ if (SINGLE_THREAD_P)
+ return INLINE_SYSCALL (sendto, 6, fd, buf, n, flags, NULL, NULL);
+
+ int oldtype = LIBC_CANCEL_ASYNC ();
+
+ ssize_t result = INLINE_SYSCALL (sendto, 6, fd, buf, n, flags, NULL, NULL);
+
+ LIBC_CANCEL_RESET (oldtype);
+
+ return result;
}
weak_alias (__libc_send, __send)