Checks
Context |
Check |
Description |
redhat-pt-bot/TryBot-apply_patch |
success
|
Patch applied to master at the time it was sent
|
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 |
success
|
Build passed
|
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 |
success
|
Test passed
|
linaro-tcwg-bot/tcwg_glibc_build--master-arm |
success
|
Build passed
|
redhat-pt-bot/TryBot-32bit |
success
|
Build for i686
|
linaro-tcwg-bot/tcwg_glibc_check--master-arm |
success
|
Test passed
|
Commit Message
POSIX.1-2024 introduces a portable way to get the highest possible
signal number (plus one): sysconf(_SC_NSIG). This is equivalent to
glibc's non-portable NSIG macro.
Link: https://www.austingroupbugs.net/view.php?id=741
Signed-off-by: Tavian Barnes <tavianator@tavianator.com>
---
There is also a new NSIG_MAX constant, but I'm less sure how to expose
that. That is supposed to be the highest possible signal number (plus
one) that sigset_t could support, so that new signals can be added
without breaking ABI. If that's not a concern, we could just do
#define NSIG_MAX NSIG
Otherwise, it would have to be something like
#define NSIG_MAX (CHAR_BIT * sizeof(sigset_t) + 1)
but that's not usable in preprocessor conditionals. (I'm not sure it
has to be, but most of the *_MAX macros are I think.)
---
bits/confname.h | 5 ++++-
posix/getconf.c | 2 ++
posix/sysconf.c | 2 ++
posix/tst-getconf.sh | 1 +
sysdeps/posix/sysconf.c | 7 +++++++
5 files changed, 16 insertions(+), 1 deletion(-)
Comments
On 24/01/25 13:28, Tavian Barnes wrote:
> POSIX.1-2024 introduces a portable way to get the highest possible
> signal number (plus one): sysconf(_SC_NSIG). This is equivalent to
> glibc's non-portable NSIG macro.
>
> Link: https://www.austingroupbugs.net/view.php?id=741
> Signed-off-by: Tavian Barnes <tavianator@tavianator.com>
LGTM, thanks.
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
>
> ---
>
> There is also a new NSIG_MAX constant, but I'm less sure how to expose
> that. That is supposed to be the highest possible signal number (plus
> one) that sigset_t could support, so that new signals can be added
> without breaking ABI. If that's not a concern, we could just do
>
> #define NSIG_MAX NSIG
>
> Otherwise, it would have to be something like
>
> #define NSIG_MAX (CHAR_BIT * sizeof(sigset_t) + 1)
>
> but that's not usable in preprocessor conditionals. (I'm not sure it
> has to be, but most of the *_MAX macros are I think.)
POSIX defines that NSIG_MAX should be a symbolic constant and this
should be suitable for use in #if preprocessing. However, we already
do not follow it for some other constant, like MINSIGSTKSZ; due other
constraints.
Maybe we can do something like:
#define NSIG_MAX (CHAR_BIT * _SIGSET_NWORDS * __SIZEOF_LONG__ + 1)
And define _SIGSET_NWORDS for Hurd. I think we can even define __SIZEOF_LONG__
based __WORDSIZE to avoid relying on the pre-processor.
>
> ---
> bits/confname.h | 5 ++++-
> posix/getconf.c | 2 ++
> posix/sysconf.c | 2 ++
> posix/tst-getconf.sh | 1 +
> sysdeps/posix/sysconf.c | 7 +++++++
> 5 files changed, 16 insertions(+), 1 deletion(-)
>
> diff --git a/bits/confname.h b/bits/confname.h
> index 2eaf8a2eb2..9084e3ac90 100644
> --- a/bits/confname.h
> +++ b/bits/confname.h
> @@ -531,8 +531,11 @@ enum
> _SC_MINSIGSTKSZ,
> #define _SC_MINSIGSTKSZ _SC_MINSIGSTKSZ
>
> - _SC_SIGSTKSZ
> + _SC_SIGSTKSZ,
> #define _SC_SIGSTKSZ _SC_SIGSTKSZ
> +
> + _SC_NSIG
> +#define _SC_NSIG _SC_NSIG
> };
>
> /* Values for the NAME argument to `confstr'. */
> diff --git a/posix/getconf.c b/posix/getconf.c
> index 4ba9c0dee8..29933ceeb5 100644
> --- a/posix/getconf.c
> +++ b/posix/getconf.c
> @@ -405,6 +405,8 @@ static const struct conf vars[] =
> { "_POSIX_IPV6", _SC_IPV6, SYSCONF },
> { "_POSIX_RAW_SOCKETS", _SC_RAW_SOCKETS, SYSCONF },
>
> + { "NSIG", _SC_NSIG, SYSCONF },
> +
> { NULL, 0, SYSCONF }
> };
>
> diff --git a/posix/sysconf.c b/posix/sysconf.c
> index c3bf3b78fa..0f93305fe9 100644
> --- a/posix/sysconf.c
> +++ b/posix/sysconf.c
> @@ -269,6 +269,8 @@ __sysconf (int name)
> case _SC_MINSIGSTKSZ:
> case _SC_SIGSTKSZ:
>
> + case _SC_NSIG:
> +
> break;
> }
>
> diff --git a/posix/tst-getconf.sh b/posix/tst-getconf.sh
> index eeb4c51d84..30f442b83a 100644
> --- a/posix/tst-getconf.sh
> +++ b/posix/tst-getconf.sh
> @@ -56,6 +56,7 @@ _NPROCESSORS_CONF
> NPROCESSORS_CONF
> _NPROCESSORS_ONLN
> NPROCESSORS_ONLN
> +NSIG
> MQ_OPEN_MAX
> MQ_PRIO_MAX
> OPEN_MAX
> diff --git a/sysdeps/posix/sysconf.c b/sysdeps/posix/sysconf.c
> index 8f9a0adab2..853fd42a23 100644
> --- a/sysdeps/posix/sysconf.c
> +++ b/sysdeps/posix/sysconf.c
> @@ -1209,6 +1209,13 @@ __sysconf (int name)
> #else
> return -1;
> #endif
> +
> + case _SC_NSIG:
> +#ifdef NSIG
> + return NSIG;
> +#else
> + return -1;
> +#endif
> }
> }
>
@@ -531,8 +531,11 @@ enum
_SC_MINSIGSTKSZ,
#define _SC_MINSIGSTKSZ _SC_MINSIGSTKSZ
- _SC_SIGSTKSZ
+ _SC_SIGSTKSZ,
#define _SC_SIGSTKSZ _SC_SIGSTKSZ
+
+ _SC_NSIG
+#define _SC_NSIG _SC_NSIG
};
/* Values for the NAME argument to `confstr'. */
@@ -405,6 +405,8 @@ static const struct conf vars[] =
{ "_POSIX_IPV6", _SC_IPV6, SYSCONF },
{ "_POSIX_RAW_SOCKETS", _SC_RAW_SOCKETS, SYSCONF },
+ { "NSIG", _SC_NSIG, SYSCONF },
+
{ NULL, 0, SYSCONF }
};
@@ -269,6 +269,8 @@ __sysconf (int name)
case _SC_MINSIGSTKSZ:
case _SC_SIGSTKSZ:
+ case _SC_NSIG:
+
break;
}
@@ -56,6 +56,7 @@ _NPROCESSORS_CONF
NPROCESSORS_CONF
_NPROCESSORS_ONLN
NPROCESSORS_ONLN
+NSIG
MQ_OPEN_MAX
MQ_PRIO_MAX
OPEN_MAX
@@ -1209,6 +1209,13 @@ __sysconf (int name)
#else
return -1;
#endif
+
+ case _SC_NSIG:
+#ifdef NSIG
+ return NSIG;
+#else
+ return -1;
+#endif
}
}