about summary refs log tree commit diff
path: root/nptl/allocatestack.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2003-09-24 03:22:56 +0000
committerUlrich Drepper <drepper@redhat.com>2003-09-24 03:22:56 +0000
commit54ee14b3882bc7f2fcace383ee12da765e86e2ee (patch)
tree63e8a3a0e4eba8a081f0db111d6df51668ebaf3c /nptl/allocatestack.c
parent16a76cd23ce9d3924fa192395e730423e3dc8b36 (diff)
downloadglibc-54ee14b3882bc7f2fcace383ee12da765e86e2ee.tar.gz
glibc-54ee14b3882bc7f2fcace383ee12da765e86e2ee.tar.xz
glibc-54ee14b3882bc7f2fcace383ee12da765e86e2ee.zip
Update.
2003-09-23  Ulrich Drepper  <drepper@redhat.com>

	* sysdeps/unix/sysv/linux/powerpc/powerpc32/Versions [libc]
	(GLIBC_2.3.3): Add setcontext, getcontext, swapcontext, and
	makecontext.
	* sysdeps/unix/sysv/linux/powerpc/sys/ucontext.h: Correct change
	for include Altivec support for PPC32.  It was not compatible.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/ucontext_i.h: Adjust
	offsets for ucontext_t change.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/getcontext.S: Adjust
	for ucontext_t change.  Add compatibility code.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/makecontext.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/setcontext.S: Likewise.
	* sysdeps/unix/sysv/linux/powerpc/powerpc32/swapcontext.S: Likewise.
	Patch by Paul Mackerras <paulus@samba.org>.

2003-02-25  Randolph Chung  <tausq@debian.org>

	* sysdeps/hppa/Makefile: Include compat code in build.
	* sysdeps/hppa/libgcc-compat.c: New file.
	* sysdeps/hppa/Dist: Add libgcc-compat.c.
	* sysdeps/hppa/Versions [GLIBC_2.2]: Add __clz_tab.
Diffstat (limited to 'nptl/allocatestack.c')
-rw-r--r--nptl/allocatestack.c53
1 files changed, 46 insertions, 7 deletions
diff --git a/nptl/allocatestack.c b/nptl/allocatestack.c
index 6ada1fe138..dc501650b8 100644
--- a/nptl/allocatestack.c
+++ b/nptl/allocatestack.c
@@ -351,11 +351,12 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
     }
   else
     {
-      /* Allocate some anonymous memory.  If possible use the
-	 cache.  */
+      /* Allocate some anonymous memory.  If possible use the cache.  */
       size_t guardsize;
       size_t reqsize;
       void *mem;
+      const int prot = (PROT_READ | PROT_WRITE
+			| ((GL(dl_stack_flags) & PF_X) ? PROT_EXEC : 0));
 
 #if COLORING_INCREMENT != 0
       /* Add one more page for stack coloring.  Don't do it for stacks
@@ -392,7 +393,7 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 	    size += pagesize_m1 + 1;
 #endif
 
-	  mem = mmap (NULL, size, PROT_READ | PROT_WRITE | PROT_EXEC,
+	  mem = mmap (NULL, size, prot,
 		      MAP_PRIVATE | MAP_ANONYMOUS | ARCH_MAP_FLAGS, -1, 0);
 
 	  if (__builtin_expect (mem == MAP_FAILED, 0))
@@ -546,17 +547,16 @@ allocate_stack (const struct pthread_attr *attr, struct pthread **pdp,
 	  char *oldguard = mem + (((size - pd->guardsize) / 2) & ~pagesize_m1);
 
 	  if (oldguard < guard
-	      && mprotect (oldguard, guard - oldguard,
-			   PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
+	      && mprotect (oldguard, guard - oldguard, prot) != 0)
 	    goto mprot_error;
 
 	  if (mprotect (guard + guardsize,
 			oldguard + pd->guardsize - guard - guardsize,
-			PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
+			prot) != 0)
 	    goto mprot_error;
 #else
 	  if (mprotect ((char *) mem + guardsize, pd->guardsize - guardsize,
-			PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
+			prot) != 0)
 	    goto mprot_error;
 #endif
 
@@ -616,6 +616,45 @@ __deallocate_stack (struct pthread *pd)
 }
 
 
+int
+internal_function
+__make_stacks_executable (void)
+{
+#ifdef NEED_SEPARATE_REGISTER_STACK
+  const size_t pagemask = ~(__getpagesize () - 1);
+#endif
+
+  lll_lock (stack_cache_lock);
+
+  int err = 0;
+  list_t *runp;
+  list_for_each (runp, &stack_used)
+    {
+      struct pthread *const pd = list_entry (runp, struct pthread, list);
+#ifdef NEED_SEPARATE_REGISTER_STACK
+      void *stack = (pd->stackblock
+		     + (((((pd->stackblock_size - pd->guardsize) / 2)
+			  & pagemask) + pd->guardsize) & pagemask));
+      size_t len = pd->stackblock + pd->stackblock_size - stack;
+#else
+      void *stack = pd->stackblock + pd->guardsize;
+      size_t len = pd->stackblock_size - pd->guardsize;
+#endif
+      if (mprotect (stack, len, PROT_READ | PROT_WRITE | PROT_EXEC) != 0)
+	{
+	  err = errno;
+	  break;
+	}
+    }
+
+  lll_unlock (stack_cache_lock);
+
+  _dl_make_stack_executable ();
+
+  return err;
+}
+
+
 /* In case of a fork() call the memory allocation in the child will be
    the same but only one thread is running.  All stacks except that of
    the one running thread are not used anymore.  We have to recycle