All of lore.kernel.org
 help / color / mirror / Atom feed
* [parisc-linux] [PATCH] _STACK_GROWS_UP fixes.
@ 2003-10-12 21:37 Carlos O'Donell
  2003-10-15  5:34 ` [parisc-linux] " Jakub Jelinek
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Carlos O'Donell @ 2003-10-12 21:37 UTC (permalink / raw)
  To: libc-alpha, parisc-linux

libc-alpha,

Fix stack grows up.
In a stack grows down scenario the stack pointer is between:

BOS <--- SP ---> h_descr

In the stack grows up scenarion we have:

h_descr,BOS <--- SP ---> STACK GUARD

TOS is not stored, and thus the stack guard start address is
used.

This fixes a regression on HPPA where a cancellation signal would
reach the child thread before the thread register had been setup.
In that situation __pthread_self_stack was called to determine
which thread was active, with the logic backwards, and no limit
in place the while loop spun until it encountered garbage that 
caused the logical expression to evaluate to true. This garbage stack 
address was fatal to the proper execution of the program.

Cheers,
Carlos

===
===

2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>

	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
	(__pthread_find_self): Likewise.
	* manager.c (thread_segment): _STACK_GROWS_UP case added.

diff -u -p -r1.131 pthread.c
--- linuxthreads/pthread.c	23 Sep 2003 04:33:01 -0000	1.131
+++ linuxthreads/pthread.c	12 Oct 2003 20:57:53 -0000
@@ -893,7 +893,11 @@ pthread_descr __pthread_find_self(void)
   /* __pthread_handles[0] is the initial thread, __pthread_handles[1] is
      the manager threads handled specially in thread_self(), so start at 2 */
   h = __pthread_handles + 2;
+# ifdef _STACK_GROWS_UP
+  while (! (sp >= (char *) h->h_descr && sp < h->h_descr->p_guardaddr)) h++;
+# else
   while (! (sp <= (char *) h->h_descr && sp >= h->h_bottom)) h++;
+# endif
   return h->h_descr;
 }
 
@@ -908,11 +912,22 @@ pthread_descr __pthread_self_stack(void)
     return manager_thread;
   h = __pthread_handles + 2;
 # ifdef USE_TLS
+#  ifdef _STACK_GROWS_UP
+  while (h->h_descr == NULL
+	 || ! (sp >= h->h_descr->p_stackaddr && 
+	       sp < h->h_descr->p_guardaddr))
+#  else
   while (h->h_descr == NULL
-	 || ! (sp <= (char *) h->h_descr->p_stackaddr && sp >= h->h_bottom))
+	 || ! (sp <= h->h_descr->p_stackaddr && 
+	       sp >= h->h_bottom))
+#  endif
     h++;
 # else
+#  ifdef _STACK_GROWS_UP
+  while (! (sp >= (char *) h->h_descr && sp < h->h_descr->p_guardaddr))
+#  else
   while (! (sp <= (char *) h->h_descr && sp >= h->h_bottom))
+#  endif
     h++;
 # endif
   return h->h_descr;
diff -u -p -r1.95 manager.c
--- linuxthreads/manager.c	12 Aug 2003 03:40:45 -0000	1.95
+++ linuxthreads/manager.c	12 Oct 2003 20:58:00 -0000
@@ -70,8 +70,13 @@ static pthread_descr manager_thread;
 #else
 static inline pthread_descr thread_segment(int seg)
 {
+# ifdef _STACK_GROWS_UP
+  return (pthread_descr)(THREAD_STACK_START_ADDRESS + (seg - 1) * STACK_SIZE)
+         + 1;
+# else
   return (pthread_descr)(THREAD_STACK_START_ADDRESS - (seg - 1) * STACK_SIZE)
          - 1;
+# endif
 }
 #endif
 

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-12 21:37 [parisc-linux] [PATCH] _STACK_GROWS_UP fixes Carlos O'Donell
  2003-10-15  5:34 ` [parisc-linux] " Jakub Jelinek
@ 2003-10-15  5:34 ` Jakub Jelinek
  2003-10-15 16:40   ` Carlos O'Donell
                     ` (3 more replies)
  2003-10-15  5:53 ` Ulrich Drepper
  2003-10-15  5:53 ` Ulrich Drepper
  3 siblings, 4 replies; 9+ messages in thread
From: Jakub Jelinek @ 2003-10-15  5:34 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha, parisc-linux

On Sun, Oct 12, 2003 at 05:37:34PM -0400, Carlos O'Donell wrote:
> 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> 
> 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> 	(__pthread_find_self): Likewise.
> 	* manager.c (thread_segment): _STACK_GROWS_UP case added.

You need to look at linuxthreads/attr.c (__pthread_attr_getstack) too
(the recent code which parses /proc/self/maps and finds stack VMA in there).

	Jakub

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-12 21:37 [parisc-linux] [PATCH] _STACK_GROWS_UP fixes Carlos O'Donell
@ 2003-10-15  5:34 ` Jakub Jelinek
  2003-10-15  5:34 ` Jakub Jelinek
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Jakub Jelinek @ 2003-10-15  5:34 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha, parisc-linux

On Sun, Oct 12, 2003 at 05:37:34PM -0400, Carlos O'Donell wrote:
> 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> 
> 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> 	(__pthread_find_self): Likewise.
> 	* manager.c (thread_segment): _STACK_GROWS_UP case added.

You need to look at linuxthreads/attr.c (__pthread_attr_getstack) too
(the recent code which parses /proc/self/maps and finds stack VMA in there).

	Jakub

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-12 21:37 [parisc-linux] [PATCH] _STACK_GROWS_UP fixes Carlos O'Donell
                   ` (2 preceding siblings ...)
  2003-10-15  5:53 ` Ulrich Drepper
@ 2003-10-15  5:53 ` Ulrich Drepper
  3 siblings, 0 replies; 9+ messages in thread
From: Ulrich Drepper @ 2003-10-15  5:53 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha, parisc-linux

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carlos O'Donell wrote:

> 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> 
> 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> 	(__pthread_find_self): Likewise.
> 	* manager.c (thread_segment): _STACK_GROWS_UP case added.

Applied after cleaning up.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/jOD22ijCOnn/RHQRAtSQAKCSAkx1YFOt3HSr2MBfKcB5OqK43ACgyHQK
ch5Et0rXhEeQqKCszFrYGDY=
=UKA4
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-12 21:37 [parisc-linux] [PATCH] _STACK_GROWS_UP fixes Carlos O'Donell
  2003-10-15  5:34 ` [parisc-linux] " Jakub Jelinek
  2003-10-15  5:34 ` Jakub Jelinek
@ 2003-10-15  5:53 ` Ulrich Drepper
  2003-10-15  5:53 ` Ulrich Drepper
  3 siblings, 0 replies; 9+ messages in thread
From: Ulrich Drepper @ 2003-10-15  5:53 UTC (permalink / raw)
  To: Carlos O'Donell; +Cc: libc-alpha, parisc-linux

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Carlos O'Donell wrote:

> 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> 
> 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> 	(__pthread_find_self): Likewise.
> 	* manager.c (thread_segment): _STACK_GROWS_UP case added.

Applied after cleaning up.

- -- 
- --------------.                        ,-.            444 Castro Street
Ulrich Drepper \    ,-----------------'   \ Mountain View, CA 94041 USA
Red Hat         `--' drepper at redhat.com `---------------------------
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.2 (GNU/Linux)

iD8DBQE/jOD22ijCOnn/RHQRAtSQAKCSAkx1YFOt3HSr2MBfKcB5OqK43ACgyHQK
ch5Et0rXhEeQqKCszFrYGDY=
=UKA4
-----END PGP SIGNATURE-----

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-15  5:34 ` Jakub Jelinek
@ 2003-10-15 16:40   ` Carlos O'Donell
  2003-10-15 16:40   ` Carlos O'Donell
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Carlos O'Donell @ 2003-10-15 16:40 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: libc-alpha, parisc-linux

On Wed, Oct 15, 2003 at 07:34:31AM +0200, Jakub Jelinek wrote:
> On Sun, Oct 12, 2003 at 05:37:34PM -0400, Carlos O'Donell wrote:
> > 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> > 
> > 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> > 	(__pthread_find_self): Likewise.
> > 	* manager.c (thread_segment): _STACK_GROWS_UP case added.
> 
> You need to look at linuxthreads/attr.c (__pthread_attr_getstack) too
> (the recent code which parses /proc/self/maps and finds stack VMA in there).

That should hopefully explain the regression in tst-attr1, I hadn't
tracked it down yet, but I knew that some other STACK_GROWS_UP problems
might exist.

Thanks Jakub.

c.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-15  5:34 ` Jakub Jelinek
  2003-10-15 16:40   ` Carlos O'Donell
@ 2003-10-15 16:40   ` Carlos O'Donell
  2003-10-18 22:55   ` Carlos O'Donell
  2003-10-18 22:55   ` Carlos O'Donell
  3 siblings, 0 replies; 9+ messages in thread
From: Carlos O'Donell @ 2003-10-15 16:40 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: libc-alpha, parisc-linux

On Wed, Oct 15, 2003 at 07:34:31AM +0200, Jakub Jelinek wrote:
> On Sun, Oct 12, 2003 at 05:37:34PM -0400, Carlos O'Donell wrote:
> > 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> > 
> > 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> > 	(__pthread_find_self): Likewise.
> > 	* manager.c (thread_segment): _STACK_GROWS_UP case added.
> 
> You need to look at linuxthreads/attr.c (__pthread_attr_getstack) too
> (the recent code which parses /proc/self/maps and finds stack VMA in there).

That should hopefully explain the regression in tst-attr1, I hadn't
tracked it down yet, but I knew that some other STACK_GROWS_UP problems
might exist.

Thanks Jakub.

c.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-15  5:34 ` Jakub Jelinek
                     ` (2 preceding siblings ...)
  2003-10-18 22:55   ` Carlos O'Donell
@ 2003-10-18 22:55   ` Carlos O'Donell
  3 siblings, 0 replies; 9+ messages in thread
From: Carlos O'Donell @ 2003-10-18 22:55 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: libc-alpha, parisc-linux

On Wed, Oct 15, 2003 at 07:34:31AM +0200, Jakub Jelinek wrote:
> On Sun, Oct 12, 2003 at 05:37:34PM -0400, Carlos O'Donell wrote:
> > 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> > 
> > 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> > 	(__pthread_find_self): Likewise.
> > 	* manager.c (thread_segment): _STACK_GROWS_UP case added.
> 
> You need to look at linuxthreads/attr.c (__pthread_attr_getstack) too
> (the recent code which parses /proc/self/maps and finds stack VMA in there).

Jakub,

What do you think of something like this? Would it not also be valid to
do something like "to - from" for the _STACK_GROWS_DOWN case?

I'm building with this patch right now.

c.

---
2003-10-18  Carlos O'Donell  <carlos@baldric.uwo.ca>

	* attr.c (pthread_getattr_np): Add _STACK_GROWS_UP case when
	converting /proc/self/maps entry to __stackaddr and __stacksize.

Index: linuxthreads/attr.c
===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/attr.c,v
retrieving revision 1.33
diff -u -p -r1.33 attr.c
--- linuxthreads/attr.c	23 Sep 2003 06:12:59 -0000	1.33
+++ linuxthreads/attr.c	18 Oct 2003 22:34:03 -0000
@@ -455,12 +455,19 @@ int pthread_getattr_np (pthread_t thread
 		{
 		  /* Found the entry.  Now we have the info we need.  */
 		  attr->__stacksize = rl.rlim_cur;
+#ifdef _STACK_GROWS_DOWN
 		  attr->__stackaddr = (void *) to;
-
+#else
+                  attr->__stackaddr = (void *) from;
+#endif
 		  /* The limit might be too high.  This is a bogus
 		     situation but try to avoid making it worse.  */
 		  if ((size_t) attr->__stacksize > (size_t) attr->__stackaddr)
+#ifdef _STACK_GROWS_DOWN
 		    attr->__stacksize = (size_t) attr->__stackaddr;
+#else
+                    attr->__stacksize = (size_t)(to - from);
+#endif
 
 		  /* We succeed and no need to look further.  */
 		  ret = 0;

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes.
  2003-10-15  5:34 ` Jakub Jelinek
  2003-10-15 16:40   ` Carlos O'Donell
  2003-10-15 16:40   ` Carlos O'Donell
@ 2003-10-18 22:55   ` Carlos O'Donell
  2003-10-18 22:55   ` Carlos O'Donell
  3 siblings, 0 replies; 9+ messages in thread
From: Carlos O'Donell @ 2003-10-18 22:55 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: libc-alpha, parisc-linux

On Wed, Oct 15, 2003 at 07:34:31AM +0200, Jakub Jelinek wrote:
> On Sun, Oct 12, 2003 at 05:37:34PM -0400, Carlos O'Donell wrote:
> > 2003-10-06  Carlos O'Donell <carlos@baldric.uwo.ca>
> > 
> > 	* pthread.c (__pthread_self_stack): _STACK_GROWS_UP case added.
> > 	(__pthread_find_self): Likewise.
> > 	* manager.c (thread_segment): _STACK_GROWS_UP case added.
> 
> You need to look at linuxthreads/attr.c (__pthread_attr_getstack) too
> (the recent code which parses /proc/self/maps and finds stack VMA in there).

Jakub,

What do you think of something like this? Would it not also be valid to
do something like "to - from" for the _STACK_GROWS_DOWN case?

I'm building with this patch right now.

c.

---
2003-10-18  Carlos O'Donell  <carlos@baldric.uwo.ca>

	* attr.c (pthread_getattr_np): Add _STACK_GROWS_UP case when
	converting /proc/self/maps entry to __stackaddr and __stacksize.

Index: linuxthreads/attr.c
===================================================================
RCS file: /cvs/glibc/libc/linuxthreads/attr.c,v
retrieving revision 1.33
diff -u -p -r1.33 attr.c
--- linuxthreads/attr.c	23 Sep 2003 06:12:59 -0000	1.33
+++ linuxthreads/attr.c	18 Oct 2003 22:34:03 -0000
@@ -455,12 +455,19 @@ int pthread_getattr_np (pthread_t thread
 		{
 		  /* Found the entry.  Now we have the info we need.  */
 		  attr->__stacksize = rl.rlim_cur;
+#ifdef _STACK_GROWS_DOWN
 		  attr->__stackaddr = (void *) to;

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-10-18 22:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-10-12 21:37 [parisc-linux] [PATCH] _STACK_GROWS_UP fixes Carlos O'Donell
2003-10-15  5:34 ` [parisc-linux] " Jakub Jelinek
2003-10-15  5:34 ` Jakub Jelinek
2003-10-15 16:40   ` Carlos O'Donell
2003-10-15 16:40   ` Carlos O'Donell
2003-10-18 22:55   ` Carlos O'Donell
2003-10-18 22:55   ` Carlos O'Donell
2003-10-15  5:53 ` Ulrich Drepper
2003-10-15  5:53 ` Ulrich Drepper

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.