diff mbox

[1/2] stdlib/tst-setcontext.c: Check for clobbering of signal stack.

Message ID 1393829881-22691-1-git-send-email-will.newton@linaro.org
State Superseded
Headers show

Commit Message

Will Newton March 3, 2014, 6:58 a.m. UTC
On aarch64 calling swapcontext clobbers the state of the signal
stack (BZ #16629). Check that the address and size of the signal
stack before and after the call to swapcontext remains the same.

ChangeLog:

2014-02-25  Will Newton  <will.newton@linaro.org>

	* stdlib/tst-setcontext.c: Include signal.h.
	(main): Check that the signal stack before and
	after swapcontext is the same.
---
 stdlib/tst-setcontext.c | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

Comments

Ondřej Bílka March 3, 2014, 11:07 a.m. UTC | #1
On Mon, Mar 03, 2014 at 02:58:00PM +0800, Will Newton wrote:
> On aarch64 calling swapcontext clobbers the state of the signal
> stack (BZ #16629). Check that the address and size of the signal
> stack before and after the call to swapcontext remains the same.
> 
ok with this test.
Siddhesh Poyarekar March 3, 2014, 12:32 p.m. UTC | #2
On Mon, Mar 03, 2014 at 02:58:00PM +0800, Will Newton wrote:
> On aarch64 calling swapcontext clobbers the state of the signal
> stack (BZ #16629). Check that the address and size of the signal
> stack before and after the call to swapcontext remains the same.

The description in bz #16629 seems to indicate that this test would
fail on aarch64.  If that is correct, this test update should
accompany a fix to the problem so that it doesn't fail on mainline.

> 
> ChangeLog:
> 
> 2014-02-25  Will Newton  <will.newton@linaro.org>
> 

Add relevant BZ # here.  The date above is wrong too, but I assume
you'll fix it up later.

> 	* stdlib/tst-setcontext.c: Include signal.h.
> 	(main): Check that the signal stack before and
> 	after swapcontext is the same.

Siddhesh
Will Newton Aug. 4, 2014, 3:53 p.m. UTC | #3
On 3 August 2014 13:57, Mike Frysinger <vapier@gentoo.org> wrote:
> On Mon 03 Mar 2014 14:58:00 Will Newton wrote:
>> +  sigaltstack(NULL, &stack_after);
>
> incorrect style (and below).  fixed with below as obvious.
> -mike

Thanks for noticing and fixing this.

As penance I have gone through the patchwork and cleaned up a number
of patches in various states so we are now back under one page of
patches to review!

> From a1d8c6215d0bcda6985cb383d8c440b03db7253d Mon Sep 17 00:00:00 2001
> From: Mike Frysinger <vapier@gentoo.org>
> Date: Sun, 3 Aug 2014 08:55:20 -0400
> Subject: [PATCH] tst-setcontext: fix style
>
> ---
>  stdlib/tst-setcontext.c | 10 +++++-----
>  1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/stdlib/tst-setcontext.c b/stdlib/tst-setcontext.c
> index 55984a4..74d5133 100644
> --- a/stdlib/tst-setcontext.c
> +++ b/stdlib/tst-setcontext.c
> @@ -74,8 +74,8 @@ f2 (void)
>  }
>
>  void
> -test_stack(volatile int a, volatile int b,
> -           volatile int c, volatile int d)
> +test_stack (volatile int a, volatile int b,
> +           volatile int c, volatile int d)
>  {
>    volatile int e = 5;
>    volatile int f = 6;
> @@ -83,7 +83,7 @@ test_stack(volatile int a, volatile int b,
>
>    /* Test for cases where getcontext is clobbering the callers
>       stack, including parameters.  */
> -  getcontext(&uc);
> +  getcontext (&uc);
>
>    if (a != 1)
>      {
> @@ -147,7 +147,7 @@ main (void)
>    char st1[32768];
>    stack_t stack_before, stack_after;
>
> -  sigaltstack(NULL, &stack_before);
> +  sigaltstack (NULL, &stack_before);
>
>    puts ("making contexts");
>    if (getcontext (&ctx[1]) != 0)
> @@ -211,7 +211,7 @@ main (void)
>    puts ("back at main program");
>    back_in_main = 1;
>
> -  sigaltstack(NULL, &stack_after);
> +  sigaltstack (NULL, &stack_after);
>
>    if (was_in_f1 == 0)
>      {
> --
> 2.0.0
>
>
diff mbox

Patch

diff --git a/stdlib/tst-setcontext.c b/stdlib/tst-setcontext.c
index ac9deb1..55984a4 100644
--- a/stdlib/tst-setcontext.c
+++ b/stdlib/tst-setcontext.c
@@ -16,6 +16,7 @@ 
    <http://www.gnu.org/licenses/>.  */
 
 #include <errno.h>
+#include <signal.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -144,6 +145,9 @@  main (void)
   atexit (check_called);
 
   char st1[32768];
+  stack_t stack_before, stack_after;
+
+  sigaltstack(NULL, &stack_before);
 
   puts ("making contexts");
   if (getcontext (&ctx[1]) != 0)
@@ -207,6 +211,8 @@  main (void)
   puts ("back at main program");
   back_in_main = 1;
 
+  sigaltstack(NULL, &stack_after);
+
   if (was_in_f1 == 0)
     {
       puts ("didn't reach f1");
@@ -218,6 +224,21 @@  main (void)
       exit (1);
     }
 
+  /* Check sigaltstack state is not clobbered as in BZ #16629.  */
+  if (stack_before.ss_sp != stack_after.ss_sp)
+    {
+      printf ("stack ss_sp mismatch: %p %p\n",
+	      stack_before.ss_sp, stack_after.ss_sp);
+      exit (1);
+    }
+
+  if (stack_before.ss_size != stack_after.ss_size)
+    {
+      printf ("stack ss_size mismatch: %zd %zd\n",
+	      stack_before.ss_size, stack_after.ss_size);
+      exit (1);
+    }
+
   puts ("test succeeded");
   return 0;
 }