diff mbox

[v2] linux-user/signal.c: define __SIGRTMIN/MAX for non-GNU platforms

Message ID 1401868140-20928-1-git-send-email-ncopa@alpinelinux.org
State New
Headers show

Commit Message

Natanael Copa June 4, 2014, 7:49 a.m. UTC
The __SIGRTMIN and __SIGRTMAX are glibc internals and are not available
on all platforms, so we define those if they are missing. We also check
that those corresponds with the posix variables SIGRTMIN/SIGRTMAX which
may only be available during runtime.

This is needed for musl libc.

Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
---
Changes v1 -> v2:
 - replace NSIG with _NSIG since thats use everywhere else in the code.
 - add runtime asserts.

 linux-user/signal.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Comments

Riku Voipio June 6, 2014, 8:27 a.m. UTC | #1
Hi,

On Wed, Jun 04, 2014 at 09:49:00AM +0200, Natanael Copa wrote:
> The __SIGRTMIN and __SIGRTMAX are glibc internals and are not available
> on all platforms, so we define those if they are missing. We also check
> that those corresponds with the posix variables SIGRTMIN/SIGRTMAX which
> may only be available during runtime.
> 
> This is needed for musl libc.

After all, the idea of asserts doesn't work on glibc it seems:

qemu-arm qemu-smoke/armel/busybox ls -ld .
qemu-arm: linux-user/signal.c:393: signal_init: Assertion `32 == (__libc_current_sigrtmin ())' failed.
Aborted

Quick test on my amd64/glibc 2.18 system:

printf("RTMIN: %d RTMAX: %d\n", SIGRTMIN, SIGRTMAX);
RTMIN: 34 RTMAX: 64

While: /usr/include/bits/signum.h
#define __SIGRTMIN  32


> Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
> ---
> Changes v1 -> v2:
>  - replace NSIG with _NSIG since thats use everywhere else in the code.
>  - add runtime asserts.
> 
>  linux-user/signal.c | 14 ++++++++++++++
>  1 file changed, 14 insertions(+)
> 
> diff --git a/linux-user/signal.c b/linux-user/signal.c
> index 5b8a01f..67771ad 100644
> --- a/linux-user/signal.c
> +++ b/linux-user/signal.c
> @@ -32,6 +32,13 @@
>  
>  //#define DEBUG_SIGNAL
>  
> +#ifndef __SIGRTMIN
> +#define __SIGRTMIN 32
> +#endif
> +#ifndef __SIGRTMAX
> +#define __SIGRTMAX (_NSIG-1)
> +#endif
> +
>  static struct target_sigaltstack target_sigaltstack_used = {
>      .ss_sp = 0,
>      .ss_size = 0,
> @@ -379,6 +386,13 @@ void signal_init(void)
>      int i, j;
>      int host_sig;
>  
> +    /* SIGRTMIN/SIGRTMAX might be runtime variables so we cannot use them
> +       to declare the host_to_target_signal table. But we are interacting
> +       with a given kernel where the values will be fixed. Check that the
> +       runtime values actually corresponds. */
> +    assert(__SIGRTMIN == SIGRTMIN);
> +    assert(__SIGRTMAX == SIGRTMAX);
> +
>      /* generate signal conversion tables */
>      for(i = 1; i < _NSIG; i++) {
>          if (host_to_target_signal_table[i] == 0)
> -- 
> 2.0.0
>
Paolo Bonzini June 6, 2014, 9:48 a.m. UTC | #2
Il 06/06/2014 10:27, Riku Voipio ha scritto:
> Hi,
>
> On Wed, Jun 04, 2014 at 09:49:00AM +0200, Natanael Copa wrote:
>> The __SIGRTMIN and __SIGRTMAX are glibc internals and are not available
>> on all platforms, so we define those if they are missing. We also check
>> that those corresponds with the posix variables SIGRTMIN/SIGRTMAX which
>> may only be available during runtime.
>>
>> This is needed for musl libc.
>
> After all, the idea of asserts doesn't work on glibc it seems:
>
> qemu-arm qemu-smoke/armel/busybox ls -ld .
> qemu-arm: linux-user/signal.c:393: signal_init: Assertion `32 == (__libc_current_sigrtmin ())' failed.
> Aborted
>
> Quick test on my amd64/glibc 2.18 system:
>
> printf("RTMIN: %d RTMAX: %d\n", SIGRTMIN, SIGRTMAX);
> RTMIN: 34 RTMAX: 64
>
> While: /usr/include/bits/signum.h
> #define __SIGRTMIN  32

That's because glibc reserves two signals (one for cancellation, the 
other to implement set*id system calls).  Basically you'd need to extend 
the hack of host_to_target_signal_table to all signals in the 
[__SIGRTMIN, SIGRTMIN) range, computing the table at run-time.

Paolo
diff mbox

Patch

diff --git a/linux-user/signal.c b/linux-user/signal.c
index 5b8a01f..67771ad 100644
--- a/linux-user/signal.c
+++ b/linux-user/signal.c
@@ -32,6 +32,13 @@ 
 
 //#define DEBUG_SIGNAL
 
+#ifndef __SIGRTMIN
+#define __SIGRTMIN 32
+#endif
+#ifndef __SIGRTMAX
+#define __SIGRTMAX (_NSIG-1)
+#endif
+
 static struct target_sigaltstack target_sigaltstack_used = {
     .ss_sp = 0,
     .ss_size = 0,
@@ -379,6 +386,13 @@  void signal_init(void)
     int i, j;
     int host_sig;
 
+    /* SIGRTMIN/SIGRTMAX might be runtime variables so we cannot use them
+       to declare the host_to_target_signal table. But we are interacting
+       with a given kernel where the values will be fixed. Check that the
+       runtime values actually corresponds. */
+    assert(__SIGRTMIN == SIGRTMIN);
+    assert(__SIGRTMAX == SIGRTMAX);
+
     /* generate signal conversion tables */
     for(i = 1; i < _NSIG; i++) {
         if (host_to_target_signal_table[i] == 0)