This is the mail archive of the libc-hacker@sources.redhat.com mailing list for the glibc project.

Note that libc-hacker is a closed list. You may look at the archives of this list, but subscription and posting are not open.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH] Use FLOATING_STACKS on IA-64


Hi!

This patch changes IA-64 to use FLOATING_STACKS.
I had to tweak pthread_allocate_stack a little bit for this.
Glibc builds with this just fine on IA-64 and passes make check too (on
07-09 checkout, so test-gencat fails but that has been fixed since then and
is unrelated).
I think Alpha/Sparc32/Sparc64 could turn FLOATING_STACKS too, it will just
need testing (but IMHO it should just work there).

2001-07-19  Jakub Jelinek  <jakub@redhat.com>

	* sysdeps/i386/useldt.h: Fix typo in ARCH_STACK_MAX_SIZE comment.

	* sysdeps/ia64/pt-machine.h (FLOATING_STACKS): New.
	(ARCH_STACK_MAX_SIZE): New.
	* manager.c (pthread_allocate_stack): Handle FLOATING_STACKS with
	NEED_SEPARATE_REGISTER_STACK.

--- libc/linuxthreads/sysdeps/i386/useldt.h.jj	Wed Apr 25 06:07:51 2001
+++ libc/linuxthreads/sysdeps/i386/useldt.h	Thu Jul 19 09:00:17 2001
@@ -201,5 +201,5 @@ extern int __modify_ldt (int, struct mod
 /* We want the OS to assign stack addresses.  */
 #define FLOATING_STACKS	1
 
-/* Maximum size o fthe stack if the rlimit is unlimited.  */
+/* Maximum size of the stack if the rlimit is unlimited.  */
 #define ARCH_STACK_MAX_SIZE	8*1024*1024
--- libc/linuxthreads/sysdeps/ia64/pt-machine.h.jj	Mon Jan  8 12:58:35 2001
+++ libc/linuxthreads/sysdeps/ia64/pt-machine.h	Thu Jul 19 09:01:18 2001
@@ -31,6 +31,12 @@
 
 #define NEED_SEPARATE_REGISTER_STACK
 
+/* We want the OS to assign stack addresses.  */
+#define FLOATING_STACKS 1
+
+/* Maximum size of the stack if the rlimit is unlimited.  */
+#define ARCH_STACK_MAX_SIZE     32*1024*1024
+
 /* Get some notion of the current stack.  Need not be exactly the top
    of the stack, just something somewhere in the current frame.
    r12 (sp) is the stack pointer. */
--- libc/linuxthreads/manager.c.jj	Mon Jun 25 07:31:17 2001
+++ libc/linuxthreads/manager.c	Thu Jul 19 11:12:38 2001
@@ -353,7 +353,53 @@ static int pthread_allocate_stack(const 
       void *map_addr;
 
       /* Allocate space for stack and thread descriptor at default address */
-#ifdef NEED_SEPARATE_REGISTER_STACK
+#if FLOATING_STACKS
+      if (attr != NULL)
+	{
+	  guardsize = page_roundup (attr->__guardsize, granularity);
+	  stacksize = __pthread_max_stacksize - guardsize;
+	  stacksize = MIN (stacksize,
+			   page_roundup (attr->__stacksize, granularity));
+	}
+      else
+	{
+	  guardsize = granularity;
+	  stacksize = __pthread_max_stacksize - guardsize;
+	}
+
+      map_addr = mmap(NULL, stacksize + guardsize,
+		      PROT_READ | PROT_WRITE | PROT_EXEC,
+		      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+      if (map_addr == MAP_FAILED)
+        /* No more memory available.  */
+        return -1;
+
+# ifdef NEED_SEPARATE_REGISTER_STACK
+      guardaddr = map_addr + stacksize / 2;
+      if (guardsize > 0)
+	mprotect (guardaddr, guardsize, PROT_NONE);
+
+      new_thread_bottom = (char *) map_addr;
+      new_thread = ((pthread_descr) (new_thread_bottom + stacksize
+				     + guardsize)) - 1;
+# elif _STACK_GROWS_DOWN
+      guardaddr = map_addr;
+      if (guardsize > 0)
+	mprotect (guardaddr, guardsize, PROT_NONE);
+
+      new_thread_bottom = (char *) map_addr + guardsize;
+      new_thread = ((pthread_descr) (new_thread_bottom + stacksize)) - 1;
+# elif _STACK_GROWS_UP
+      guardaddr = map_addr + stacksize;
+      if (guardsize > 0)
+	mprotect (guardaddr, guardsize, PROT_NONE);
+
+      new_thread = (pthread_descr) map_addr;
+      new_thread_bottom = (char *) (new_thread + 1);
+# else
+#  error You must define a stack direction
+# endif /* Stack direction */
+#else /* !FLOATING_STACKS */
       void *res_addr;
 
       if (attr != NULL)
@@ -369,6 +415,7 @@ static int pthread_allocate_stack(const 
 	  stacksize = STACK_SIZE - granularity;
 	}
 
+# ifdef NEED_SEPARATE_REGISTER_STACK
       new_thread = default_new_thread;
       new_thread_bottom = (char *) (new_thread + 1) - stacksize - guardsize;
       /* Includes guard area, unlike the normal case.  Use the bottom
@@ -379,8 +426,6 @@ static int pthread_allocate_stack(const 
        in the same region.  The cost is that we might be able to map
        slightly fewer stacks.  */
 
-      /* XXX Fix for floating stacks with variable sizes.  */
-
       /* First the main stack: */
       map_addr = (caddr_t)((char *)(new_thread + 1) - stacksize / 2);
       res_addr = mmap(map_addr, stacksize / 2,
@@ -409,61 +454,7 @@ static int pthread_allocate_stack(const 
 
       guardaddr = new_thread_bottom + stacksize/2;
       /* We leave the guard area in the middle unmapped.	*/
-#else  /* !NEED_SEPARATE_REGISTER_STACK */
-# if FLOATING_STACKS
-      if (attr != NULL)
-	{
-	  guardsize = page_roundup (attr->__guardsize, granularity);
-	  stacksize = __pthread_max_stacksize - guardsize;
-	  stacksize = MIN (stacksize,
-			   page_roundup (attr->__stacksize, granularity));
-	}
-      else
-	{
-	  guardsize = granularity;
-	  stacksize = __pthread_max_stacksize - guardsize;
-	}
-
-      map_addr = mmap(NULL, stacksize + guardsize,
-		      PROT_READ | PROT_WRITE | PROT_EXEC,
-		      MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
-      if (map_addr == MAP_FAILED)
-        /* No more memory available.  */
-        return -1;
-
-#  ifdef _STACK_GROWS_DOWN
-      guardaddr = map_addr;
-      if (guardsize > 0)
-	mprotect (guardaddr, guardsize, PROT_NONE);
-
-      new_thread_bottom = (char *) map_addr + guardsize;
-      new_thread = ((pthread_descr) (new_thread_bottom + stacksize)) - 1;
-#  elif _STACK_GROWS_UP
-      guardaddr = map_addr + stacksize;
-      if (guardsize > 0)
-	mprotect (guardaddr, guardsize, PROT_NONE);
-
-      new_thread = (pthread_descr) map_addr;
-      new_thread_bottom = (char *) (new_thread + 1);
-#  else
-#    error You must define a stack direction
-#  endif /* Stack direction */
-# else /* !FLOATING_STACKS */
-      void *res_addr;
-
-      if (attr != NULL)
-	{
-	  guardsize = page_roundup (attr->__guardsize, granularity);
-	  stacksize = STACK_SIZE - guardsize;
-	  stacksize = MIN (stacksize,
-			   page_roundup (attr->__stacksize, granularity));
-	}
-      else
-	{
-	  guardsize = granularity;
-	  stacksize = STACK_SIZE - granularity;
-	}
-
+# else  /* !NEED_SEPARATE_REGISTER_STACK */
 #  ifdef _STACK_GROWS_DOWN
       new_thread = default_new_thread;
       new_thread_bottom = (char *) (new_thread + 1) - stacksize;
@@ -501,8 +492,8 @@ static int pthread_allocate_stack(const 
 	  mprotect (guardaddr, guardsize, PROT_NONE);
 
 #  endif /* stack direction */
-# endif
-#endif /* !NEED_SEPARATE_REGISTER_STACK */
+# endif  /* !NEED_SEPARATE_REGISTER_STACK */
+#endif   /* !FLOATING_STACKS */
     }
   *out_new_thread = new_thread;
   *out_new_thread_bottom = new_thread_bottom;

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]