qemu-trivial.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Barcelo <abarcelo@ac.upc.edu>
To: qemu-devel <qemu-devel@nongnu.org>
Cc: qemu-trivial@nongnu.org, Riku Voipio <riku.voipio@iki.fi>
Subject: Re: [Qemu-trivial] [TRIVIAL v2] Bad zero comparison for sas_ss_flags on powerpc
Date: Fri, 10 Feb 2012 10:57:05 +0100	[thread overview]
Message-ID: <CAFKAgTfOTniTEteFa5Rkms6PYXxDBFOS7g1VQNU4szXmC6T5Pw@mail.gmail.com> (raw)
In-Reply-To: <CAFKAgTcgMqVpopxTw8+8N005OSOoNM33L2a8DLJvn7Tpa-BGvQ@mail.gmail.com>

// Test source and desired /real output:

#include <signal.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

void handler(int sig)
{
   unsigned int a;
   // to prevent uninitialized stack, normally a = 0
   if ( a>10 ) a = 0;
   a = a + 1;
   printf ("new value: %d\n" , a );
   if (a > 7) _exit(a);
   return;
}

int main()
{
   int ret;
   char * stackA = malloc(SIGSTKSZ);
   char * stackB = malloc(SIGSTKSZ);
   stack_t ssA = {
       .ss_size = SIGSTKSZ,
       .ss_sp = stackA,
   };
   stack_t ssB = {
       .ss_size = SIGSTKSZ,
       .ss_sp = stackB,
   };
   struct sigaction sa = {
       .sa_handler = handler,
       .sa_flags = SA_ONSTACK
   };

   // no error checking, only debug output
   ret = sigfillset(&sa.sa_mask);
   printf ( "Sigfillset: %d\n" , ret );
   ret = sigaction(SIGUSR1, &sa, 0);
   printf ( "Sigaction: %d\n" , ret );

   while (1) {
       printf ("On stack A -- " );
       ret = sigaltstack(&ssA, 0);
       printf ( "sigaltstack return: %d -- " , ret );
       kill(0, SIGUSR1);
       sleep(1);
       printf ("                                    -- " );
       kill(0, SIGUSR1);
       sleep(1);

       printf ("On stack B -- " );
       ret = sigaltstack(&ssB, 0);
       printf ( "sigaltstack return: %d -- " , ret );
       kill(0, SIGUSR1);
       sleep(1);
   }
}

/* Desired output:
Sigfillset: 0
Sigaction: 0
On stack A -- sigaltstack return: 0 -- new value: 1
                                   -- new value: 2
On stack B -- sigaltstack return: 0 -- new value: 1
On stack A -- sigaltstack return: 0 -- new value: 3
                                   -- new value: 4
On stack B -- sigaltstack return: 0 -- new value: 2
On stack A -- sigaltstack return: 0 -- new value: 5
                                   -- new value: 6
On stack B -- sigaltstack return: 0 -- new value: 3
On stack A -- sigaltstack return: 0 -- new value: 7
                                   -- new value: 8

Output for ppc without patch:
Sigfillset: 0
Sigaction: 0
On stack A -- sigaltstack return: 0 -- new value: 1
                                   -- new value: 2
On stack B -- sigaltstack return: 0 -- new value: 3 // WRONG!!
On stack A -- sigaltstack return: 0 -- new value: 4
                                   -- new value: 5 // WRONG AGAIN!
...
*/


  reply	other threads:[~2012-02-10  9:57 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-02-10  9:55 [Qemu-trivial] [TRIVIAL v2] Bad zero comparison for sas_ss_flags on powerpc Alex Barcelo
2012-02-10  9:57 ` Alex Barcelo [this message]
2012-02-15  6:55   ` Alex Barcelo
2012-02-15  8:35     ` [Qemu-trivial] [Qemu-devel] " Alexander Graf
2012-02-15 13:00       ` Alex Barcelo

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=CAFKAgTfOTniTEteFa5Rkms6PYXxDBFOS7g1VQNU4szXmC6T5Pw@mail.gmail.com \
    --to=abarcelo@ac.upc.edu \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    --cc=riku.voipio@iki.fi \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).