Skip to contentSkip to conversation

cpus.c: Use pthread_sigmask() rather than sigprocmask()

PATCH In review Peter Maydell 2 participants 3 messages May 16, 2016 – May 17, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cpus.c: Use pthread_sigmask() rather than sigprocmask()

On Linux, sigprocmask() and pthread_sigmask() are in practice the same thing (they only set the signal mask for the calling thread), but the documentation states that the behaviour of sigprocmask() in a multithreaded process is undefined. Use pthread_sigmask() instead (which is what we do in almost all places in QEMU that alter the signal mask already).

---
 cpus.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cpus.c +1 -1
index cbeb1f6..1d0fc53 100644
@@ -778,7 +778,7 @@ static void sigbus_reraise(void)
         raise(SIGBUS);
         sigemptyset(&set);
         sigaddset(&set, SIGBUS);
-        sigprocmask(SIG_UNBLOCK, &set, NULL);
+        pthread_sigmask(SIG_UNBLOCK, &set, NULL);
     }
     perror("Failed to re-raise SIGBUS!\n");
     abort();
Signature · 1 line
1.9.1
#1 lore raw
Quoted 6 lines · Peter Maydell

On Linux, sigprocmask() and pthread_sigmask() are in practice the same thing (they only set the signal mask for the calling thread), but the documentation states that the behaviour of sigprocmask() in a multithreaded process is undefined. Use pthread_sigmask() instead (which is what we do in almost all places in QEMU that alter the signal mask already).

The only other sigprocmask() uses are in linux-user, apart from a couple in net/tap.c, where they're used as part of forking and spawning the helper process. I suspect this should be using qemu_fork() instead of doing it all by hand, wrongly...

thanks
-- PMM

#2 lore raw
Quoted 4 lines · Peter Maydell

The only other sigprocmask() uses are in linux-user, apart from a couple in net/tap.c, where they're used as part of forking and spawning the helper process. I suspect this should be using qemu_fork() instead of doing it all by hand, wrongly...

In all fairness those predate qemu_fork(). :)

Your patch also changes a Linux-only function, but it's cleaner to user pthread_sigmask so I've queued it for the next pull request.

Paolo