diff --git a/doc/services/portability/posix/aep/index.rst b/doc/services/portability/posix/aep/index.rst index d6cbeb9447f..b720520ebd9 100644 --- a/doc/services/portability/posix/aep/index.rst +++ b/doc/services/portability/posix/aep/index.rst @@ -52,7 +52,7 @@ The *Minimal Realtime System Profile* (PSE51) includes all of the :ref:`POSIX_C_LANG_SUPPORT `, yes, :ref:`POSIX_DEVICE_IO `,, :kconfig:option:`CONFIG_POSIX_DEVICE_IO` :ref:`POSIX_SIGNALS `,, - :ref:`POSIX_SINGLE_PROCESS `, yes, + :ref:`POSIX_SINGLE_PROCESS `, yes, :kconfig:option:`CONFIG_POSIX_SINGLE_PROCESS` :ref:`POSIX_THREADS_BASE `, yes, :ref:`XSI_THREADS_EXT `, yes, diff --git a/doc/services/portability/posix/kconfig/index.rst b/doc/services/portability/posix/kconfig/index.rst index e8d82d6b345..d04779aa96c 100644 --- a/doc/services/portability/posix/kconfig/index.rst +++ b/doc/services/portability/posix/kconfig/index.rst @@ -30,7 +30,6 @@ implementation of the POSIX API. * :kconfig:option:`CONFIG_POSIX_RTSIG_MAX` * :kconfig:option:`CONFIG_POSIX_SIGNAL` * :kconfig:option:`CONFIG_POSIX_SIGNAL_STRING_DESC` -* :kconfig:option:`CONFIG_POSIX_UNAME` * :kconfig:option:`CONFIG_POSIX_UNAME_NODENAME_LEN` * :kconfig:option:`CONFIG_POSIX_UNAME_VERSION_LEN` * :kconfig:option:`CONFIG_PTHREAD` diff --git a/include/zephyr/posix/sys/utsname.h b/include/zephyr/posix/sys/utsname.h index 32046f431d8..542215076a4 100644 --- a/include/zephyr/posix/sys/utsname.h +++ b/include/zephyr/posix/sys/utsname.h @@ -6,15 +6,23 @@ #ifndef ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ #define ZEPHYR_INCLUDE_POSIX_SYS_UTSNAME_H_ +#include + #ifdef __cplusplus extern "C" { #endif +/* These are for compatibility / practicality */ +#define _UTSNAME_NODENAME_LENGTH \ + COND_CODE_1(CONFIG_POSIX_SINGLE_PROCESS, (CONFIG_POSIX_UNAME_VERSION_LEN), (0)) +#define _UTSNAME_VERSION_LENGTH \ + COND_CODE_1(CONFIG_POSIX_SINGLE_PROCESS, (CONFIG_POSIX_UNAME_VERSION_LEN), (0)) + struct utsname { char sysname[sizeof("Zephyr")]; - char nodename[CONFIG_POSIX_UNAME_NODENAME_LEN + 1]; + char nodename[_UTSNAME_NODENAME_LENGTH + 1]; char release[sizeof("99.99.99-rc1")]; - char version[CONFIG_POSIX_UNAME_VERSION_LEN + 1]; + char version[_UTSNAME_VERSION_LENGTH + 1]; char machine[sizeof(CONFIG_ARCH)]; }; diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index 1bf0823752d..509f1d3c0e1 100644 --- a/lib/posix/options/CMakeLists.txt +++ b/lib/posix/options/CMakeLists.txt @@ -25,7 +25,8 @@ if(CONFIG_POSIX_SIGNAL) endif() if(CONFIG_POSIX_API OR CONFIG_PTHREAD_IPC OR CONFIG_POSIX_TIMERS OR - CONFIG_POSIX_MQUEUE OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT) + CONFIG_POSIX_MQUEUE OR CONFIG_POSIX_FS OR CONFIG_EVENTFD OR CONFIG_GETOPT OR + CONFIG_POSIX_SINGLE_PROCESS) # This is a temporary workaround so that Newlib declares the appropriate # types for us. POSIX features to be formalized as part of #51211 zephyr_compile_options($<$:-D_POSIX_THREADS>) @@ -39,13 +40,11 @@ zephyr_library_sources_ifdef(CONFIG_FNMATCH fnmatch.c) zephyr_library_sources_ifdef(CONFIG_GETENTROPY getentropy.c) zephyr_library_sources_ifdef(CONFIG_POSIX_ASYNCHRONOUS_IO aio.c) zephyr_library_sources_ifdef(CONFIG_POSIX_BARRIERS barrier.c) -zephyr_library_sources_ifdef(CONFIG_POSIX_CONFSTR confstr.c) zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO # perror should be moved to the common libc perror.c device_io.c ) -zephyr_library_sources_ifdef(CONFIG_POSIX_ENV env.c) zephyr_library_sources_ifdef(CONFIG_POSIX_FD_MGMT fd_mgmt.c ) @@ -57,13 +56,17 @@ zephyr_library_sources_ifdef(CONFIG_POSIX_MULTI_PROCESS zephyr_library_sources_ifdef(CONFIG_POSIX_NETWORKING net.c) zephyr_library_sources_ifdef(CONFIG_POSIX_PUTMSG stropts.c) zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNAL signal.c ${STRSIGNAL_TABLE_H}) -zephyr_library_sources_ifdef(CONFIG_POSIX_SYSCONF_IMPL_FULL sysconf.c) +zephyr_library_sources_ifdef(CONFIG_POSIX_SINGLE_PROCESS + confstr.c + env.c + sysconf.c + uname.c +) zephyr_library_sources_ifdef(CONFIG_POSIX_SYSLOG syslog.c) zephyr_library_sources_ifdef(CONFIG_POSIX_TIMERS clock.c timer.c ) -zephyr_library_sources_ifdef(CONFIG_POSIX_UNAME uname.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_IPC _common.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_COND cond.c) zephyr_library_sources_ifdef(CONFIG_PTHREAD_KEY key.c) diff --git a/lib/posix/options/Kconfig b/lib/posix/options/Kconfig index 85631445f12..da9b00b9a84 100644 --- a/lib/posix/options/Kconfig +++ b/lib/posix/options/Kconfig @@ -26,9 +26,7 @@ config PTHREAD_IPC rsource "Kconfig.aio" rsource "Kconfig.barrier" rsource "Kconfig.cond" -rsource "Kconfig.confstr" rsource "Kconfig.device_io" -rsource "Kconfig.env" rsource "Kconfig.eventfd" rsource "Kconfig.fd_mgmt" rsource "Kconfig.fnmatch" @@ -36,9 +34,11 @@ rsource "Kconfig.fs" rsource "Kconfig.getentropy" rsource "Kconfig.getopt" rsource "Kconfig.key" +rsource "Kconfig.mem" rsource "Kconfig.mqueue" rsource "Kconfig.mutex" rsource "Kconfig.net" +rsource "Kconfig.proc1" rsource "Kconfig.procN" rsource "Kconfig.pthread" rsource "Kconfig.rwlock" @@ -47,10 +47,8 @@ rsource "Kconfig.semaphore" rsource "Kconfig.signal" rsource "Kconfig.spinlock" rsource "Kconfig.stropts" -rsource "Kconfig.sysconf" rsource "Kconfig.syslog" rsource "Kconfig.timer" -rsource "Kconfig.uname" rsource "Kconfig.xsi" rsource "Kconfig.deprecated" diff --git a/lib/posix/options/Kconfig.confstr b/lib/posix/options/Kconfig.confstr deleted file mode 100644 index 154f14f2d52..00000000000 --- a/lib/posix/options/Kconfig.confstr +++ /dev/null @@ -1,9 +0,0 @@ -# Copyright (c) 2024, Meta -# -# SPDX-License-Identifier: Apache-2.0 - -config POSIX_CONFSTR - bool "Retrieve string system configuration" - default y if POSIX_API - help - This enables the POSIX confstr() function. diff --git a/lib/posix/options/Kconfig.deprecated b/lib/posix/options/Kconfig.deprecated index 8da2f0e21ad..ecac0365d6c 100644 --- a/lib/posix/options/Kconfig.deprecated +++ b/lib/posix/options/Kconfig.deprecated @@ -28,6 +28,24 @@ config POSIX_CLOCK Please use CONFIG_POSIX_TIMERS instead. +config POSIX_CONFSTR + bool "Retrieve string system configuration [DEPRECATED]" + select DEPRECATED + select POSIX_SINGLE_PROCESS + help + This option is deprecated. + + Please use CONFIG_POSIX_SINGLE_PROCESS instead. + +config POSIX_ENV + bool "Support for environ, getenv(), getenv_r(), setenv(), and unsetenv() [DEPRECATED]" + select DEPRECATED + select POSIX_SINGLE_PROCESS + help + This option is deprecated. + + Please use CONFIG_POSIX_SINGLE_PROCESS instead. + config POSIX_LIMITS_RTSIG_MAX int "_POSIX_RTSIG_MAX value in limits.h [DEPRECATED]" default POSIX_RTSIG_MAX if POSIX_REALTIME_SIGNALS @@ -57,6 +75,24 @@ config POSIX_MAX_OPEN_FILES See also CONFIG_ZVFS_OPEN_MAX. +config POSIX_SYSCONF + bool "Support for sysconf() [DEPRECATED]" + select DEPRECATED + select POSIX_SINGLE_PROCESS + help + This option is deprecated. + + Please use CONFIG_POSIX_SINGLE_PROCESS instead. + +config POSIX_UNAME + bool "Support for uname [DEPRECATED]" + select DEPRECATED + select POSIX_SINGLE_PROCESS + help + This option is deprecated. + + Please use CONFIG_POSIX_SINGLE_PROCESS instead. + config PTHREAD_BARRIER bool "pthread_barrier_t support [DEPRECATED]" select DEPRECATED diff --git a/lib/posix/options/Kconfig.env b/lib/posix/options/Kconfig.env deleted file mode 100644 index 222392d2737..00000000000 --- a/lib/posix/options/Kconfig.env +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2023, Meta -# -# SPDX-License-Identifier: Apache-2.0 - -config POSIX_ENV - bool "Support for environ, getenv(), getenv_r(), setenv(), and unsetenv()" - depends on COMMON_LIBC_MALLOC - default y if POSIX_API - help - Select this option to add support for environment variables. - -module = POSIX_ENV -module-str = POSIX env logging -source "subsys/logging/Kconfig.template.log_config" diff --git a/lib/posix/options/Kconfig.mem b/lib/posix/options/Kconfig.mem new file mode 100644 index 00000000000..ad3f0a94ec2 --- /dev/null +++ b/lib/posix/options/Kconfig.mem @@ -0,0 +1,13 @@ +# Copyright (c) 2024 BayLibre SAS +# +# SPDX-License-Identifier: Apache-2.0 + +config POSIX_PAGE_SIZE_BITS + int "Number of bits to use for PAGE_SIZE" + range 6 16 + default 12 if POSIX_API + default 6 + help + Define PAGE_SIZE as BIT(n), where n is the value configured here. + PAGE_SIZE is supported in the range [64, 65536] + If CONFIG_POSIX_API=y, PAGE_SIZE defaults to 4096, otherwise, it is 64 bytes. diff --git a/lib/posix/options/Kconfig.proc1 b/lib/posix/options/Kconfig.proc1 new file mode 100644 index 00000000000..ecdcec802e2 --- /dev/null +++ b/lib/posix/options/Kconfig.proc1 @@ -0,0 +1,57 @@ +# Copyright (c) 2023 Meta +# Copyright (c) 2024 BayLibre SAS +# Copyright (c) 2024 Tenstorrent AI ULC +# +# SPDX-License-Identifier: Apache-2.0 + +menuconfig POSIX_SINGLE_PROCESS + bool "POSIX single process support" + default y if POSIX_API + # imply COMMON_LIBC_MALLOC # for env.c + help + Select 'y' here to use confstr(), environ, errno, getenv(), setenv(), sysconf(), uname(), + or unsetenv(). + + For more information, please see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + +if POSIX_SINGLE_PROCESS + +choice POSIX_SYSCONF_IMPL_CHOICE + default POSIX_SYSCONF_IMPL_FULL if CPP + default POSIX_SYSCONF_IMPL_MACRO + prompt "Sysconf implementation method" + +config POSIX_SYSCONF_IMPL_MACRO + bool "Macro" + help + The sysconf() function is implemented compile-time constant via macros. This is the option + with the least overhead. The downside is that sysconf() is not an addressable function. + +config POSIX_SYSCONF_IMPL_FULL + bool "Full" + help + The sysconf() function is implemented as a large integer-integer array. The advantage if this + option is that all sysconf() options can be queried and that the sysconf() symbol is + addressable. + +endchoice + +config POSIX_UNAME_VERSION_LEN + int "uname version string length" + default 70 + help + Defines the maximum string length of uname version. + +config POSIX_UNAME_NODENAME_LEN + int "uname nodename string length" + default 6 if !NET_HOSTNAME_UNIQUE + default 22 if NET_HOSTNAME_UNIQUE + help + Defines the maximum string length of nodename version. + +module = POSIX_ENV +module-str = POSIX env logging +source "subsys/logging/Kconfig.template.log_config" + +endif # POSIX_SINGLE_PROCESS diff --git a/lib/posix/options/Kconfig.sysconf b/lib/posix/options/Kconfig.sysconf deleted file mode 100644 index 7e904d5b672..00000000000 --- a/lib/posix/options/Kconfig.sysconf +++ /dev/null @@ -1,48 +0,0 @@ -# Copyright (c) 2024 BayLibre SAS -# -# SPDX-License-Identifier: Apache-2.0 - -menu "Sysconf support" - -config POSIX_SYSCONF - bool "Support for sysconf" - default y if POSIX_API - help - The sysconf() function provides a method for the application to determine - the current value of a configurable system limit or option (variable). - -config POSIX_PAGE_SIZE_BITS - int "Number of bits to use for PAGE_SIZE" - range 6 16 - default 12 if POSIX_API - default 6 - help - Define PAGE_SIZE as BIT(n), where n is the value configured here. - PAGE_SIZE is supported in the range [64, 65536] - If CONFIG_POSIX_API=y, PAGE_SIZE defaults to 4096, otherwise, it is 64 bytes. - -if POSIX_SYSCONF - -choice POSIX_SYSCONF_IMPL_CHOICE - default POSIX_SYSCONF_IMPL_FULL if CPP - default POSIX_SYSCONF_IMPL_MACRO - prompt "Sysconf implementation method" - -config POSIX_SYSCONF_IMPL_MACRO - bool "Macro" - help - The sysconf() function is implemented compile-time constant via macros. This is the option - with the least overhead. The downside is that sysconf() is not an addressable function. - -config POSIX_SYSCONF_IMPL_FULL - bool "Full" - help - The sysconf() function is implemented as a large integer-integer array. The advantage if this - option is that all sysconf() options can be queried and that the sysconf() symbol is - addressable. - -endchoice - -endif # POSIX_SYSCONF - -endmenu # "Sysconf support" diff --git a/lib/posix/options/Kconfig.uname b/lib/posix/options/Kconfig.uname deleted file mode 100644 index 8b448225249..00000000000 --- a/lib/posix/options/Kconfig.uname +++ /dev/null @@ -1,26 +0,0 @@ -# Copyright (c) 2023 Meta -# -# SPDX-License-Identifier: Apache-2.0 - -menuconfig POSIX_UNAME - bool "Support for uname" - default y if POSIX_API - help - The uname() function shall store information identifying the current - system in the structure pointed to by name. - -if POSIX_UNAME -config POSIX_UNAME_VERSION_LEN - int "uname version string length" - default 70 - help - Defines the maximum string length of uname version. - -config POSIX_UNAME_NODENAME_LEN - int "uname nodename string length" - default 6 if !NET_HOSTNAME_UNIQUE - default 22 if NET_HOSTNAME_UNIQUE - help - Defines the maximum string length of nodename version. - -endif # POSIX_UNAME diff --git a/lib/posix/options/Kconfig.xsi b/lib/posix/options/Kconfig.xsi index 6cc2bf58509..5124e9eb8c7 100644 --- a/lib/posix/options/Kconfig.xsi +++ b/lib/posix/options/Kconfig.xsi @@ -5,9 +5,8 @@ config XSI_SINGLE_PROCESS bool "X/Open single process" default y if POSIX_API - depends on POSIX_ENV - depends on POSIX_UNAME - depends on POSIX_CLOCK_SELECTION + depends on POSIX_SINGLE_PROCESS + depends on POSIX_TIMERS help Select 'y' here and Zephyr will provide implementations of gethostid(), gettimeofday(), and putenv(). diff --git a/lib/posix/shell/Kconfig.env b/lib/posix/shell/Kconfig.env index d2d5fd53b3e..bbe36bc9cbb 100644 --- a/lib/posix/shell/Kconfig.env +++ b/lib/posix/shell/Kconfig.env @@ -3,7 +3,7 @@ config POSIX_ENV_SHELL bool "Support for shell" - select POSIX_ENV + select POSIX_SINGLE_PROCESS select POSIX_SHELL help This shell provides access to system environment variables. diff --git a/lib/posix/shell/Kconfig.uname b/lib/posix/shell/Kconfig.uname index 11ea1166433..73547e3ac84 100644 --- a/lib/posix/shell/Kconfig.uname +++ b/lib/posix/shell/Kconfig.uname @@ -1,7 +1,7 @@ # Copyright (c) 2024 Meta # SPDX-License-Identifier: Apache-2.0 -if POSIX_UNAME +if POSIX_SINGLE_PROCESS config POSIX_UNAME_SHELL bool "Support for `uname` command" @@ -10,4 +10,4 @@ config POSIX_UNAME_SHELL help Support for `uname` command in the terminal. -endif # POSIX_UNAME +endif # POSIX_SINGLE_PROCESS diff --git a/tests/posix/env/prj.conf b/tests/posix/env/prj.conf index 7529d301e2e..fcf68903a72 100644 --- a/tests/posix/env/prj.conf +++ b/tests/posix/env/prj.conf @@ -1,5 +1,5 @@ CONFIG_ZTEST=y -CONFIG_POSIX_ENV=y +CONFIG_POSIX_SINGLE_PROCESS=y # Let's explicitly choose PICOLIBC, so it is used if supported even if it would not have been the # default (otherwise native targets default to the host C library) CONFIG_PICOLIBC=y