All of lore.kernel.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@baldric.uwo.ca>
To: libc-alpha <libc-alpha@sources.redhat.com>,
	parisc-linux@lists.parisc-linux.org
Subject: [parisc-linux] [PATCH] _STACK_GROWS_UP fixes.
Date: Sun, 12 Oct 2003 17:37:34 -0400	[thread overview]
Message-ID: <20031012213734.GJ23999@systemhalted> (raw)

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
 

             reply	other threads:[~2003-10-12 21:40 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-10-12 21:37 Carlos O'Donell [this message]
2003-10-15  5:34 ` [parisc-linux] Re: [PATCH] _STACK_GROWS_UP fixes 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
2003-10-12 21:37 [parisc-linux] " Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20031012213734.GJ23999@systemhalted \
    --to=carlos@baldric.uwo.ca \
    --cc=libc-alpha@sources.redhat.com \
    --cc=parisc-linux@lists.parisc-linux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.