about summary refs log tree commit diff
path: root/nptl
diff options
context:
space:
mode:
Diffstat (limited to 'nptl')
-rw-r--r--nptl/ChangeLog16
-rw-r--r--nptl/Makefile6
-rw-r--r--nptl/descr.h6
-rw-r--r--nptl/pthread_create.c4
-rw-r--r--nptl/res.c10
-rw-r--r--nptl/tst-_res1.c69
-rw-r--r--nptl/tst-_res1mod1.c23
-rw-r--r--nptl/tst-_res1mod2.c1
8 files changed, 124 insertions, 11 deletions
diff --git a/nptl/ChangeLog b/nptl/ChangeLog
index 12ab1a811e..8d36515b7c 100644
--- a/nptl/ChangeLog
+++ b/nptl/ChangeLog
@@ -1,3 +1,19 @@
+2003-07-22  Jakub Jelinek  <jakub@redhat.com>
+
+	* res.c (__res_state): Return __resp.
+	* descr.h: Include resolv.h.
+	(struct pthread): Add res field.
+	* pthread_create.c: Include resolv.h.
+	(start_thread): Initialize __resp.
+	* Makefile (tests): Add tst-_res1.
+	(module-names): Add tst-_res1mod1, tst-_res1mod2.
+	($(objpfx)tst-_res1mod2.so): Depend on $(objpfx)tst-_res1mod1.so.
+	($(objpfx)tst-_res1): Depend on $(objpfx)tst-_res1mod2.so and
+	libpthread.
+	* tst-_res1.c: New file.
+	* tst-_res1mod1.c: New file.
+	* tst-_res1mod2.c: New file.
+
 2003-07-21  Ulrich Drepper  <drepper@redhat.com>
 
 	* sysdeps/pthread/createthread.c: Don't define CLONE_STOPPED.
diff --git a/nptl/Makefile b/nptl/Makefile
index 66e33a7c0f..6cf30c440f 100644
--- a/nptl/Makefile
+++ b/nptl/Makefile
@@ -250,10 +250,10 @@ tests += tst-cancelx2 tst-cancelx3 tst-cancelx4 tst-cancelx5 \
 	 tst-oncex3 tst-oncex4
 endif
 ifeq ($(build-shared),yes)
-tests += tst-atfork2 tst-tls3
+tests += tst-atfork2 tst-tls3 tst-_res1
 endif
 
-modules-names = tst-atfork2mod tst-tls3mod
+modules-names = tst-atfork2mod tst-tls3mod tst-_res1mod1 tst-_res1mod2
 extra-objs += $(addsuffix .os,$(strip $(modules-names)))
 test-extras += $(modules-names)
 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
@@ -400,6 +400,8 @@ $(objpfx)tst-cancelx17: $(common-objpfx)rt/librt.so
 $(objpfx)tst-cancel18: $(common-objpfx)rt/librt.so
 $(objpfx)tst-cancelx18: $(common-objpfx)rt/librt.so
 $(objpfx)tst-clock2: $(common-objpfx)rt/librt.so
+$(objpfx)tst-_res1mod2.so: $(objpfx)tst-_res1mod1.so
+$(objpfx)tst-_res1: $(objpfx)tst-_res1mod2.so $(shared-thread-library)
 else
 $(objpfx)tst-cond11: $(common-objpfx)rt/librt.a
 $(objpfx)tst-cancel17: $(common-objpfx)rt/librt.a
diff --git a/nptl/descr.h b/nptl/descr.h
index fb364b95ca..6c7f2317c9 100644
--- a/nptl/descr.h
+++ b/nptl/descr.h
@@ -35,7 +35,8 @@
 #ifdef HAVE_FORCED_UNWIND
 # include <unwind.h>
 #endif
-
+#define __need_res_state
+#include <resolv.h>
 
 #ifndef TCB_ALIGNMENT
 # define TCB_ALIGNMENT	sizeof (double)
@@ -235,6 +236,9 @@ struct pthread
   size_t stackblock_size;
   /* Size of the included guard area.  */
   size_t guardsize;
+
+  /* Resolver state.  */
+  struct __res_state res;
 } __attribute ((aligned (TCB_ALIGNMENT)));
 
 
diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c
index 7565826997..ae97f4a62d 100644
--- a/nptl/pthread_create.c
+++ b/nptl/pthread_create.c
@@ -26,6 +26,7 @@
 #include <ldsodefs.h>
 #include <atomic.h>
 #include <libc-internal.h>
+#include <resolv.h>
 
 #include <shlib-compat.h>
 
@@ -238,6 +239,9 @@ start_thread (void *arg)
   THREAD_SETMEM (pd, cpuclock_offset, now);
 #endif
 
+  /* Initialize resolver state pointer.  */
+  __resp = &pd->res;
+
   /* This is where the try/finally block should be created.  For
      compilers without that support we do use setjmp.  */
   struct pthread_unwind_buf unwind_buf;
diff --git a/nptl/res.c b/nptl/res.c
index 6c2e3f8867..ba4f81d06f 100644
--- a/nptl/res.c
+++ b/nptl/res.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 2002 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003 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,16 +18,10 @@
 
 #include <features.h>
 #include <resolv.h>
-#undef _res
-
 #include <tls.h>
 
-/* With __thread support, this per-thread variable is used in all cases.  */
-extern __thread struct __res_state _res;
-
-
 struct __res_state *
 __res_state (void)
 {
-  return &_res;
+  return __resp;
 }
diff --git a/nptl/tst-_res1.c b/nptl/tst-_res1.c
new file mode 100644
index 0000000000..651e3cc40d
--- /dev/null
+++ b/nptl/tst-_res1.c
@@ -0,0 +1,69 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+   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.  */
+
+/* Test whether _res in glibc 2.1.x and earlier (before __res_state()
+   was introduced) works.  Portable programs should never do the
+   dirty things below.  */
+
+#include <pthread.h>
+#include <resolv.h>
+#include <stdlib.h>
+#include <stdio.h>
+
+void *tf (void *resp)
+{
+  if (resp == &_res || resp == __res_state ())
+    abort ();
+  _res.retry = 24;
+  return NULL;
+}
+
+void do_test (struct __res_state *resp)
+{
+  if (resp != &_res || resp != __res_state ())
+    abort ();
+  if (_res.retry != 12)
+    abort ();
+}
+
+int main (void)
+{
+#undef _res
+  extern struct __res_state _res;
+  pthread_t th;
+
+  _res.retry = 12;
+  if (pthread_create (&th, NULL, tf, &_res) != 0)
+    {
+      puts ("create failed");
+      exit (1);
+    }
+
+  do_test (&_res);
+
+  if (pthread_join (th, NULL) != 0)
+    {
+      puts ("join failed");
+      exit (1);
+    }
+
+  do_test (&_res);
+
+  exit (0);
+}
diff --git a/nptl/tst-_res1mod1.c b/nptl/tst-_res1mod1.c
new file mode 100644
index 0000000000..73b190e6ba
--- /dev/null
+++ b/nptl/tst-_res1mod1.c
@@ -0,0 +1,23 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+   Contributed by Jakub Jelinek <jakub@redhat.com>, 2003.
+
+   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 <resolv.h>
+#undef _res
+
+struct __res_state _res;
diff --git a/nptl/tst-_res1mod2.c b/nptl/tst-_res1mod2.c
new file mode 100644
index 0000000000..d2a3509c6d
--- /dev/null
+++ b/nptl/tst-_res1mod2.c
@@ -0,0 +1 @@
+/* Nothing.  */