From 43c549305bdb0770a3fbebe7347b3da8b2d9ceec Mon Sep 17 00:00:00 2001 From: Yong Cong Sin Date: Tue, 18 Jul 2023 13:00:59 +0800 Subject: [PATCH] posix: signal: check RTSIG limit Use build assert to make sure that the realtime signal constants are configured properly in the Kconfig. Signed-off-by: Yong Cong Sin --- lib/posix/Kconfig | 1 + lib/posix/Kconfig.limits | 13 +++++++++++++ lib/posix/signal.c | 3 +++ 3 files changed, 17 insertions(+) create mode 100644 lib/posix/Kconfig.limits diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index 59414797328c1e..199ed956af2503 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -44,6 +44,7 @@ source "lib/posix/Kconfig.fnmatch" source "lib/posix/Kconfig.fs" source "lib/posix/Kconfig.getopt" source "lib/posix/Kconfig.key" +source "lib/posix/Kconfig.limits" source "lib/posix/Kconfig.mqueue" source "lib/posix/Kconfig.mutex" source "lib/posix/Kconfig.pthread" diff --git a/lib/posix/Kconfig.limits b/lib/posix/Kconfig.limits new file mode 100644 index 00000000000000..cc651203961c8f --- /dev/null +++ b/lib/posix/Kconfig.limits @@ -0,0 +1,13 @@ +# Copyright (c) 2023 Meta +# +# SPDX-License-Identifier: Apache-2.0 + +if POSIX_SIGNAL +config POSIX_LIMITS_RTSIG_MAX + int "_POSIX_RTSIG_MAX value in limits.h" + default 8 + help + Define the _POSIX_RTSIG_MAX value in limits.h. + IEEE 1003.1 defines this to be 8. + +endif diff --git a/lib/posix/signal.c b/lib/posix/signal.c index e1d7feab299d93..809ba84dc3a6e6 100644 --- a/lib/posix/signal.c +++ b/lib/posix/signal.c @@ -13,6 +13,9 @@ #define SIGNO_WORD_IDX(_signo) (signo / BITS_PER_LONG) #define SIGNO_WORD_BIT(_signo) (signo & BIT_MASK(LOG2(BITS_PER_LONG))) +BUILD_ASSERT(CONFIG_POSIX_LIMITS_RTSIG_MAX >= 0); +BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= CONFIG_POSIX_LIMITS_RTSIG_MAX); + static inline bool signo_valid(int signo) { return ((signo > 0) && (signo < _NSIG));