diff --git a/include/zephyr/posix/mqueue.h b/include/zephyr/posix/mqueue.h index 40db073337490..d3fb90ca72110 100644 --- a/include/zephyr/posix/mqueue.h +++ b/include/zephyr/posix/mqueue.h @@ -7,8 +7,9 @@ #ifndef ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_ #define ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_ +#include + #include -#include #include #include #include diff --git a/include/zephyr/posix/posix_features.h b/include/zephyr/posix/posix_features.h index a78b4c2a8d941..935e3ce2fe1ea 100644 --- a/include/zephyr/posix/posix_features.h +++ b/include/zephyr/posix/posix_features.h @@ -56,10 +56,6 @@ #define _POSIX_CLOCK_SELECTION _POSIX_VERSION #endif -#ifdef CONFIG_POSIX_CPUTIME -#define _POSIX_CPUTIME _POSIX_VERSION -#endif - #ifdef CONFIG_POSIX_FSYNC #define _POSIX_FSYNC _POSIX_VERSION #endif @@ -90,10 +86,6 @@ #define _POSIX_MESSAGE_PASSING _POSIX_VERSION #endif -#ifdef CONFIG_POSIX_MONOTONIC_CLOCK -#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION -#endif - /* #define _POSIX_PRIORITIZED_IO (-1L) */ #ifdef CONFIG_POSIX_PRIORITY_SCHEDULING @@ -161,10 +153,6 @@ /* #define _POSIX_THREAD_ROBUST_PRIO_INHERIT (-1L) */ /* #define _POSIX_THREAD_ROBUST_PRIO_PROTECT (-1L) */ -#ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS -#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION -#endif - /* #define _POSIX_THREAD_SPORADIC_SERVER (-1L) */ #ifdef CONFIG_POSIX_THREADS @@ -177,10 +165,6 @@ #define _POSIX_TIMEOUTS _POSIX_VERSION #endif -#ifdef CONFIG_POSIX_TIMERS -#define _POSIX_TIMERS _POSIX_VERSION -#endif - /* #define _POSIX_TRACE (-1L) */ /* #define _POSIX_TRACE_EVENT_FILTER (-1L) */ /* #define _POSIX_TRACE_INHERIT (-1L) */ diff --git a/include/zephyr/posix/posix_limits.h b/include/zephyr/posix/posix_limits.h index 4441f9497cf35..9c225b4b4d4e0 100644 --- a/include/zephyr/posix/posix_limits.h +++ b/include/zephyr/posix/posix_limits.h @@ -7,6 +7,8 @@ #ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_LIMITS_H_ #define ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_LIMITS_H_ +#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) + /* * clang-format and checkpatch disagree on formatting here, so rely on checkpatch and disable * clang-format since checkpatch cannot be selectively disabled. @@ -122,4 +124,6 @@ /* clang-format on */ +#endif + #endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_LIMITS_H_ */ diff --git a/include/zephyr/posix/posix_time.h b/include/zephyr/posix/posix_time.h new file mode 100644 index 0000000000000..0b9a8c840cc0c --- /dev/null +++ b/include/zephyr/posix/posix_time.h @@ -0,0 +1,195 @@ +/* + * Copyright The Zephyr Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_ +#define ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_ + +#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) + +#include + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* clock_t must be defined in the libc time.h */ +/* size_t must be defined in the libc stddef.h */ +/* time_t must be defined in the libc time.h */ + +#if !defined(_CLOCKID_T_DECLARED) && !defined(__clockid_t_defined) +typedef unsigned long clockid_t; +#define _CLOCKID_T_DECLARED +#define __clockid_t_defined +#endif + +#if !defined(_TIMER_T_DECLARED) && !defined(__timer_t_defined) +typedef unsigned long timer_t; +#define _TIMER_T_DECLARED +#define __timer_t_defined +#endif + +#if !defined(_LOCALE_T_DECLARED) && !defined(__locale_t_defined) +#ifdef CONFIG_NEWLIB_LIBC +struct __locale_t; +typedef struct __locale_t *locale_t; +#else +typedef void *locale_t; +#endif +#define _LOCALE_T_DECLARED +#define __locale_t_defined +#endif + +#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined) +typedef int pid_t; +#define _PID_T_DECLARED +#define __pid_t_defined +#endif + +#if defined(_POSIX_REALTIME_SIGNALS) +struct sigevent; +#endif + +/* struct tm must be defined in the libc time.h */ + +#if __STDC_VERSION__ >= 201112L +/* struct timespec must be defined in the libc time.h */ +#else +#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined) +typedef struct { + time_t tv_sec; + long tv_nsec; +} timespec_t; +#define _TIMESPEC_DECLARED +#define __timespec_defined +#endif +#endif + +#if !defined(_ITIMERSPEC_DECLARED) && !defined(__itimerspec_defined) +struct itimerspec { + struct timespec it_interval; + struct timespec it_value; +}; +#define _ITIMERSPEC_DECLARED +#define __itimerspec_defined +#endif + +/* NULL must be defined in the libc stddef.h */ + +#ifndef CLOCK_REALTIME +#define CLOCK_REALTIME ((clockid_t)SYS_CLOCK_REALTIME) +#endif + +#ifndef CLOCKS_PER_SEC +#if defined(_XOPEN_SOURCE) +#define CLOCKS_PER_SEC 1000000 +#else +#define CLOCKS_PER_SEC CONFIG_TICKS_PER_SECOND +#endif +#endif + +#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__) +#ifndef CLOCK_PROCESS_CPUTIME_ID +#define CLOCK_PROCESS_CPUTIME_ID ((clockid_t)2) +#endif +#endif + +#if defined(_POSIX_THREAD_CPUTIME) || defined(__DOXYGEN__) +#ifndef CLOCK_THREAD_CPUTIME_ID +#define CLOCK_THREAD_CPUTIME_ID ((clockid_t)3) +#endif +#endif + +#if defined(_POSIX_MONOTONIC_CLOCK) || defined(__DOXYGEN__) +#ifndef CLOCK_MONOTONIC +#define CLOCK_MONOTONIC ((clockid_t)SYS_CLOCK_MONOTONIC) +#endif +#endif + +#ifndef TIMER_ABSTIME +#define TIMER_ABSTIME SYS_TIMER_ABSTIME +#endif + +/* asctime() must be declared in the libc time.h */ +#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__) +char *asctime_r(const struct tm *ZRESTRICT tm, char *ZRESTRICT buf); +#endif +/* clock() must be declared in the libc time.h */ +#if defined(_POSIX_CPUTIME) || defined(__DOXYGEN__) +int clock_getcpuclockid(pid_t pid, clockid_t *clock_id); +#endif +#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__) +int clock_getres(clockid_t clock_id, struct timespec *ts); +int clock_gettime(clockid_t clock_id, struct timespec *ts); +#endif +#if defined(_POSIX_CLOCK_SELECTION) || defined(__DOXYGEN__) +int clock_nanosleep(clockid_t clock_id, int flags, + const struct timespec *rqtp, struct timespec *rmtp); +#endif +#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__) +int clock_settime(clockid_t clock_id, const struct timespec *ts); +#endif +/* ctime() must be declared in the libc time.h */ +#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__) +char *ctime_r(const time_t *clock, char *buf); +#endif +/* difftime() must be declared in the libc time.h */ +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +struct tm *getdate(const char *string); +#endif +/* gmtime() must be declared in the libc time.h */ +#if __STDC_VERSION__ >= 202311L +/* gmtime_r() must be declared in the libc time.h */ +#else +#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__) +struct tm *gmtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result); +#endif +#endif +/* localtime() must be declared in the libc time.h */ +#if __STDC_VERSION__ >= 202311L +/* localtime_r() must be declared in the libc time.h */ +#else +#if defined(_POSIX_THREAD_SAFE_FUNCTIONS) || defined(__DOXYGEN__) +struct tm *localtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result); +#endif +#endif +/* mktime() must be declared in the libc time.h */ +#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__) +int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); +#endif +/* strftime() must be declared in the libc time.h */ +size_t strftime_l(char *ZRESTRICT s, size_t maxsize, + const char *ZRESTRICT format, const struct tm *ZRESTRICT timeptr, + locale_t locale); +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +char *strptime(const char *ZRESTRICT s, const char *ZRESTRICT format, struct tm *ZRESTRICT tm); +#endif +/* time() must be declared in the libc time.h */ +#if defined(_POSIX_TIMERS) || defined(__DOXYGEN__) +int timer_create(clockid_t clockId, struct sigevent *ZRESTRICT evp, timer_t *ZRESTRICT timerid); +int timer_delete(timer_t timerid); +int timer_getoverrun(timer_t timerid); +int timer_gettime(timer_t timerid, struct itimerspec *its); +int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, + struct itimerspec *ovalue); +#endif + +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +extern int daylight; +extern long timezone; +#endif + +extern char *tzname[]; + +#ifdef __cplusplus +} +#endif + +#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */ + +#endif /* ZEPHYR_INCLUDE_ZEPHYR_POSIX_POSIX_TIME_H_ */ diff --git a/include/zephyr/posix/pthread.h b/include/zephyr/posix/pthread.h index 685a8d9a9316e..8b9b03e490c54 100644 --- a/include/zephyr/posix/pthread.h +++ b/include/zephyr/posix/pthread.h @@ -9,9 +9,9 @@ #include #include +#include #include -#include #include #include diff --git a/include/zephyr/posix/semaphore.h b/include/zephyr/posix/semaphore.h index e3f6014cfec45..943df122cff59 100644 --- a/include/zephyr/posix/semaphore.h +++ b/include/zephyr/posix/semaphore.h @@ -6,7 +6,8 @@ #ifndef ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_ #define ZEPHYR_INCLUDE_POSIX_SEMAPHORE_H_ -#include +#include + #include #ifdef __cplusplus diff --git a/include/zephyr/posix/signal.h b/include/zephyr/posix/signal.h index 7513bfd104753..45dfb0caee4f2 100644 --- a/include/zephyr/posix/signal.h +++ b/include/zephyr/posix/signal.h @@ -6,6 +6,8 @@ #ifndef ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ #define ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ +#include + /* include posix_types.h before posix_features.h (here) to avoid build errors against newlib */ #include #include "posix_features.h" diff --git a/include/zephyr/posix/time.h b/include/zephyr/posix/time.h deleted file mode 100644 index df2980601722e..0000000000000 --- a/include/zephyr/posix/time.h +++ /dev/null @@ -1,114 +0,0 @@ -/* - * Copyright (c) 2018 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_INCLUDE_POSIX_TIME_H_ -#define ZEPHYR_INCLUDE_POSIX_TIME_H_ - -/* Read standard header. This may find since they - * refer to the same file when include/posix is in the search path. - */ -#include - -#ifdef CONFIG_NEWLIB_LIBC -/* Kludge to support outdated newlib version as used in SDK 0.10 for Xtensa */ -#include - -#ifdef __NEWLIB__ -/* Newever Newlib 3.x+ */ -#include -#else /* __NEWLIB__ */ -/* Workaround for older Newlib 2.x, as used by Xtensa. It lacks sys/_timeval.h, - * so mimic it here. - */ -#include -#ifndef __timespec_defined - -#ifdef __cplusplus -extern "C" { -#endif - -struct timespec { - time_t tv_sec; - long tv_nsec; -}; - -struct itimerspec { - struct timespec it_interval; /* Timer interval */ - struct timespec it_value; /* Timer expiration */ -}; - -#ifdef __cplusplus -} -#endif - -#endif /* __timespec_defined */ -#endif /* __NEWLIB__ */ - -#else /* CONFIG_NEWLIB_LIBC */ -/* Not Newlib */ -# if defined(CONFIG_ARCH_POSIX) && defined(CONFIG_EXTERNAL_LIBC) -# include -# include -# else -# include -# endif -#endif /* CONFIG_NEWLIB_LIBC */ - -#include -#include -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef CLOCK_REALTIME -#define CLOCK_REALTIME SYS_CLOCK_REALTIME -#endif - -#ifndef CLOCK_PROCESS_CPUTIME_ID -#define CLOCK_PROCESS_CPUTIME_ID 2 -#endif - -#ifndef CLOCK_THREAD_CPUTIME_ID -#define CLOCK_THREAD_CPUTIME_ID 3 -#endif - -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC SYS_CLOCK_MONOTONIC -#endif - -#ifndef TIMER_ABSTIME -#define TIMER_ABSTIME SYS_TIMER_ABSTIME -#endif - -int clock_gettime(clockid_t clock_id, struct timespec *ts); -int clock_getres(clockid_t clock_id, struct timespec *ts); -int clock_settime(clockid_t clock_id, const struct timespec *ts); -int clock_getcpuclockid(pid_t pid, clockid_t *clock_id); -/* Timer APIs */ -int timer_create(clockid_t clockId, struct sigevent *evp, timer_t *timerid); -int timer_delete(timer_t timerid); -struct itimerspec; -int timer_gettime(timer_t timerid, struct itimerspec *its); -int timer_settime(timer_t timerid, int flags, const struct itimerspec *value, - struct itimerspec *ovalue); -int timer_getoverrun(timer_t timerid); -int nanosleep(const struct timespec *rqtp, struct timespec *rmtp); -int clock_nanosleep(clockid_t clock_id, int flags, - const struct timespec *rqtp, struct timespec *rmtp); - -#ifdef __cplusplus -} -#endif - -#else /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */ -/* Read the toolchain header when finds itself on the - * first attempt. - */ -#include_next -#endif /* ZEPHYR_INCLUDE_POSIX_TIME_H_ */ diff --git a/include/zephyr/posix/unistd.h b/include/zephyr/posix/unistd.h index 10d44bfd4a8d2..89f698159e1b4 100644 --- a/include/zephyr/posix/unistd.h +++ b/include/zephyr/posix/unistd.h @@ -6,6 +6,8 @@ #ifndef ZEPHYR_INCLUDE_POSIX_UNISTD_H_ #define ZEPHYR_INCLUDE_POSIX_UNISTD_H_ +#include + #include #ifdef CONFIG_POSIX_API diff --git a/lib/libc/arcmwdt/include/limits.h b/lib/libc/arcmwdt/include/limits.h index 96982ad6e4146..2e9a4d3fb4c68 100644 --- a/lib/libc/arcmwdt/include/limits.h +++ b/lib/libc/arcmwdt/include/limits.h @@ -8,23 +8,10 @@ #define LIB_LIBC_ARCMWDT_INCLUDE_LIMITS_H_ #include_next - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) - #include -#else - +#ifndef PATH_MAX #define PATH_MAX 256 - -#endif - -#ifdef __cplusplus -} #endif -#endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_LIMITS_H_ */ +#endif /* LIB_LIBC_ARCMWDT_INCLUDE_LIMITS_H_ */ diff --git a/lib/libc/arcmwdt/include/time.h b/lib/libc/arcmwdt/include/time.h index 245bd3a77d236..1d9ed0a7a9a05 100644 --- a/lib/libc/arcmwdt/include/time.h +++ b/lib/libc/arcmwdt/include/time.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Synopsys + * Copyright The Zephyr Project Contributors * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,18 +8,6 @@ #define LIB_LIBC_ARCMWDT_INCLUDE_TIME_H_ #include_next +#include -#ifdef __cplusplus -extern "C" { -#endif - -extern char *asctime_r(const struct tm *tp, char *buf); -extern char *ctime_r(const time_t *clock, char *buf); -extern struct tm *gmtime_r(const time_t *timep, struct tm *result); -extern struct tm *localtime_r(const time_t *timer, struct tm *result); - -#ifdef __cplusplus -} -#endif - -#endif /* LIB_LIBC_ARCMWDT_INCLUDE_TIME_H_ */ +#endif /* LIB_LIBC_ARCMWDT_INCLUDE_TIME_H_ */ diff --git a/lib/libc/armstdc/include/limits.h b/lib/libc/armstdc/include/limits.h index 13206aa68b566..54dabd8fdaa4a 100644 --- a/lib/libc/armstdc/include/limits.h +++ b/lib/libc/armstdc/include/limits.h @@ -8,23 +8,10 @@ #define ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_LIMITS_H_ #include_next - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) - #include -#else - +#ifndef PATH_MAX #define PATH_MAX 256 - -#endif - -#ifdef __cplusplus -} #endif #endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_LIMITS_H_ */ diff --git a/lib/libc/armstdc/include/time.h b/lib/libc/armstdc/include/time.h new file mode 100644 index 0000000000000..1432916b21188 --- /dev/null +++ b/lib/libc/armstdc/include/time.h @@ -0,0 +1,13 @@ +/* + * Copyright The Zephyr Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_TIME_H_ +#define ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_TIME_H_ + +#include_next +#include + +#endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_TIME_H_ */ diff --git a/lib/libc/iar/include/limits.h b/lib/libc/iar/include/limits.h index 6db549c355e92..010f0509649e7 100644 --- a/lib/libc/iar/include/limits.h +++ b/lib/libc/iar/include/limits.h @@ -8,23 +8,10 @@ #define ZEPHYR_LIB_LIBC_IAR_INCLUDE_LIMITS_H_ #include_next - -#ifdef __cplusplus -extern "C" { -#endif - -#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) - #include -#else - +#ifndef PATH_MAX #define PATH_MAX 256 - -#endif - -#ifdef __cplusplus -} #endif #endif /* ZEPHYR_LIB_LIBC_IAR_INCLUDE_LIMITS_H_ */ diff --git a/lib/libc/iar/include/time.h b/lib/libc/iar/include/time.h index b095987857418..2d4d2d9007578 100644 --- a/lib/libc/iar/include/time.h +++ b/lib/libc/iar/include/time.h @@ -1,31 +1,14 @@ /* - * Copyright (c) 2025 IAR Systems AB + * Copyright The Zephyr Project Contributors * * SPDX-License-Identifier: Apache-2.0 */ -/** - * @file - * @brief Declares additional time related functions based on POSIX - */ - #ifndef ZEPHYR_LIB_LIBC_IAR_INCLUDE_TIME_H_ #define ZEPHYR_LIB_LIBC_IAR_INCLUDE_TIME_H_ #include #include_next +#include -#ifdef __cplusplus -extern "C" { -#endif - -char *asctime_r(const struct tm *ZRESTRICT tp, char *ZRESTRICT buf); -char *ctime_r(const time_t *clock, char *buf); -struct tm *gmtime_r(const time_t *ZRESTRICT timep, struct tm *ZRESTRICT result); -struct tm *localtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result); - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_LIB_LIBC_IAR_INCLUDE_TIME_H_ */ +#endif /* ZEPHYR_LIB_LIBC_IAR_INCLUDE_TIME_H_ */ diff --git a/lib/libc/minimal/include/time.h b/lib/libc/minimal/include/time.h index 62ec45b03a171..3e795f0db4817 100644 --- a/lib/libc/minimal/include/time.h +++ b/lib/libc/minimal/include/time.h @@ -58,12 +58,12 @@ struct tm *gmtime_r(const time_t *ZRESTRICT timep, char *asctime(const struct tm *timeptr); struct tm *localtime(const time_t *timer); char *ctime(const time_t *clock); -char *asctime_r(const struct tm *ZRESTRICT tp, char *ZRESTRICT buf); -char *ctime_r(const time_t *clock, char *buf); struct tm *localtime_r(const time_t *ZRESTRICT timer, struct tm *ZRESTRICT result); time_t time(time_t *tloc); +#include + #ifdef __cplusplus } #endif diff --git a/lib/libc/newlib/include/limits.h b/lib/libc/newlib/include/limits.h new file mode 100644 index 0000000000000..81f9bbd406611 --- /dev/null +++ b/lib/libc/newlib/include/limits.h @@ -0,0 +1,13 @@ +/* + * Copyright The Zephyr Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_LIMITS_H_ +#define ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_LIMITS_H_ + +#include_next +#include + +#endif /* ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_LIMITS_H_ */ diff --git a/lib/libc/picolibc/CMakeLists.txt b/lib/libc/picolibc/CMakeLists.txt index 752379dd76d44..280a16a89454e 100644 --- a/lib/libc/picolibc/CMakeLists.txt +++ b/lib/libc/picolibc/CMakeLists.txt @@ -10,6 +10,7 @@ zephyr_library_sources( locks.c stdio.c ) +zephyr_include_directories(include) zephyr_library_compile_options($) diff --git a/lib/libc/picolibc/include/time.h b/lib/libc/picolibc/include/time.h new file mode 100644 index 0000000000000..47113c10d81af --- /dev/null +++ b/lib/libc/picolibc/include/time.h @@ -0,0 +1,33 @@ +/* + * Copyright The Zephyr Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_TIME_H_ +#define ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_TIME_H_ + + +#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) + +/* temporary workaround for https://github.com/picolibc/picolibc/pull/1079 */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */ + +#include_next + +#endif /* ZEPHYR_LIB_LIBC_ARMSTDC_INCLUDE_TIME_H_ */ diff --git a/lib/posix/CMakeLists.txt b/lib/posix/CMakeLists.txt index d62108b66f007..9a40cad191b26 100644 --- a/lib/posix/CMakeLists.txt +++ b/lib/posix/CMakeLists.txt @@ -1,4 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 -add_subdirectory(options) +# zephyr-keep-sorted-start +add_subdirectory_ifdef(CONFIG_EVENTFD eventfd) +add_subdirectory_ifdef(CONFIG_POSIX_C_LANG_SUPPORT_R c_lang_support_r) +add_subdirectory_ifdef(CONFIG_POSIX_C_LIB_EXT c_lib_ext) add_subdirectory_ifdef(CONFIG_POSIX_SHELL shell) +add_subdirectory_ifdef(CONFIG_POSIX_SYSTEM_INTERFACES options) +# zephyr-keep-sorted-stop diff --git a/lib/posix/Kconfig b/lib/posix/Kconfig index 534baf08cd240..4b93901ae17a5 100644 --- a/lib/posix/Kconfig +++ b/lib/posix/Kconfig @@ -1,10 +1,45 @@ # Copyright (c) 2024 Meta +# Copyright (c) 2025 Tenstorrent AI ULC # # SPDX-License-Identifier: Apache-2.0 menu "POSIX API Support" +# POSIX Subprofile Definitions +rsource "Kconfig.profile" + +# Toolchain hooks for external implementations +rsource "Kconfig.toolchain" + +# POSIX C Library Extensions +# This menu is for POSIX Option Groups that do not require OS support. +menu "POSIX C Library Extensions" +rsource "c_lang_support_r/Kconfig" +rsource "c_lib_ext/Kconfig" +endmenu + +# POSIX System Interfaces +menuconfig POSIX_SYSTEM_INTERFACES + bool "POSIX System Interfaces" + depends on !NATIVE_APPLICATION + select NATIVE_LIBC_INCOMPATIBLE + help + Select 'y' here to support POSIX System Interfaces within Zephyr. + + Options in this menu are organized by POSIX subprofiling Option Group. + + For more information, see + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + + +if POSIX_SYSTEM_INTERFACES rsource "options/Kconfig" + +# POSIX Shell utilities rsource "shell/Kconfig" +endif + +endmenu -endmenu # "POSIX API Support" +# Eventfd Support (not officially POSIX) +rsource "eventfd/Kconfig" diff --git a/lib/posix/options/Kconfig.profile b/lib/posix/Kconfig.profile similarity index 78% rename from lib/posix/options/Kconfig.profile rename to lib/posix/Kconfig.profile index 99dc78c20ea24..eed95528f5e6a 100644 --- a/lib/posix/options/Kconfig.profile +++ b/lib/posix/Kconfig.profile @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: Apache-2.0 -config POSIX_SYSTEM_HEADERS +config POSIX_SYSTEM_INTERFACES bool select NATIVE_LIBC_INCOMPATIBLE help @@ -10,8 +10,7 @@ config POSIX_SYSTEM_HEADERS config POSIX_API bool "POSIX APIs" - select NATIVE_LIBC_INCOMPATIBLE - select POSIX_SYSTEM_HEADERS + select POSIX_SYSTEM_INTERFACES select POSIX_BASE_DEFINITIONS # clock_gettime(), pthread_create(), sem_get(), etc select POSIX_AEP_REALTIME_MINIMAL # CLOCK_MONOTONIC, pthread_attr_setstack(), etc select POSIX_NETWORKING if NETWORKING # inet_ntoa(), socket(), etc @@ -27,7 +26,7 @@ config POSIX_API choice POSIX_AEP_CHOICE prompt "POSIX Subprofile" - default POSIX_AEP_CHOICE_NONE + default POSIX_AEP_CHOICE_ZEPHYR help This choice is intended to help users select the correct POSIX profile for their application. Choices are based on IEEE 1003.13-2003 (now inactive / reserved) and @@ -38,13 +37,35 @@ choice POSIX_AEP_CHOICE https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html config POSIX_AEP_CHOICE_NONE - bool "No pre-defined POSIX subprofile" + bool "No POSIX subprofile" + help + No POSIX subprofile is selected. + +config POSIX_AEP_CHOICE_ZEPHYR + bool "Minimal Zephyr System Profile" + select POSIX_C_LIB_EXT + select POSIX_C_LANG_SUPPORT_R help - No pre-defined POSIX profile is selected. + Zephyr expects certain POSIX functions to be available throughout the build environment, + such as gmtime_r(), strnlen(), strtok_r(), and possibly others. + + These functions are divided into two standalone Option Groups that may be enabled + independently of the remainder of the POSIX API implementation; namely POSIX_C_LIB_EXT and + POSIX_C_LANG_SUPPORT_R. If not referenced by the Zephyr kernel or application, there are no + resource implications for enabling these option groups. + + Unlike pre-defined, standard POSIX subprofiles, this subprofile is custom to Zephyr and + therefore does not need to include the base definitions or system interfaces that would + otherwise be required for a conformant POSIX system or subprofile. This system profile + does not itself meet the requirements for POSIX implementation conformance. + + For more information, see + https://docs.zephyrproject.org/latest/contribute/coding_guidelines/index.html + https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html config POSIX_AEP_CHOICE_BASE - bool "Base definitions (system interfaces)" - select NATIVE_LIBC_INCOMPATIBLE + bool "Minimal POSIX System Profile" + select POSIX_SYSTEM_INTERFACES select POSIX_BASE_DEFINITIONS help Only enable the base definitions required for all POSIX systems. @@ -54,7 +75,7 @@ config POSIX_AEP_CHOICE_BASE config POSIX_AEP_CHOICE_PSE51 bool "Minimal Realtime System Profile (PSE51)" - select NATIVE_LIBC_INCOMPATIBLE + select POSIX_SYSTEM_INTERFACES select POSIX_BASE_DEFINITIONS select POSIX_AEP_REALTIME_MINIMAL help @@ -67,7 +88,7 @@ config POSIX_AEP_CHOICE_PSE51 config POSIX_AEP_CHOICE_PSE52 bool "Realtime Controller System Profile (PSE52)" - select NATIVE_LIBC_INCOMPATIBLE + select POSIX_SYSTEM_INTERFACES select POSIX_BASE_DEFINITIONS select POSIX_AEP_REALTIME_MINIMAL select POSIX_AEP_REALTIME_CONTROLLER @@ -81,7 +102,7 @@ config POSIX_AEP_CHOICE_PSE52 config POSIX_AEP_CHOICE_PSE53 bool "Dedicated Realtime System Profile (PSE53)" - select NATIVE_LIBC_INCOMPATIBLE + select POSIX_SYSTEM_INTERFACES select POSIX_BASE_DEFINITIONS select POSIX_AEP_REALTIME_MINIMAL select POSIX_AEP_REALTIME_CONTROLLER @@ -98,10 +119,11 @@ config POSIX_AEP_CHOICE_PSE53 endchoice # POSIX_AEP_CHOICE -# Base Definitions (System Interfaces) +if POSIX_SYSTEM_INTERFACES + +# Mandatory POSIX System Interfaces (base profile) config POSIX_BASE_DEFINITIONS bool - select POSIX_SYSTEM_HEADERS select POSIX_ASYNCHRONOUS_IO select POSIX_BARRIERS select POSIX_CLOCK_SELECTION @@ -187,3 +209,5 @@ config POSIX_AEP_REALTIME_DEDICATED For more information, please see https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_subprofiles.html + +endif # POSIX_SYSTEM_INTERFACE diff --git a/lib/posix/options/Kconfig.toolchain b/lib/posix/Kconfig.toolchain similarity index 100% rename from lib/posix/options/Kconfig.toolchain rename to lib/posix/Kconfig.toolchain diff --git a/lib/posix/c_lang_support_r/CMakeLists.txt b/lib/posix/c_lang_support_r/CMakeLists.txt new file mode 100644 index 0000000000000..db1e5c8d3a917 --- /dev/null +++ b/lib/posix/c_lang_support_r/CMakeLists.txt @@ -0,0 +1,8 @@ +# Copyright The Zephyr Project Contributors +# SPDX-License-Identifier: Apache-2.0 + +set(POSIX_VERSION 200809L) + +if (CONFIG_POSIX_C_LANG_SUPPORT_R) + zephyr_compile_definitions(-D_POSIX_THREAD_SAFE_FUNCTIONS=${POSIX_VERSION}) +endif() diff --git a/lib/posix/options/Kconfig.c_lang_r b/lib/posix/c_lang_support_r/Kconfig similarity index 100% rename from lib/posix/options/Kconfig.c_lang_r rename to lib/posix/c_lang_support_r/Kconfig diff --git a/lib/posix/c_lib_ext/CMakeLists.txt b/lib/posix/c_lib_ext/CMakeLists.txt new file mode 100644 index 0000000000000..a4c3e09d839f2 --- /dev/null +++ b/lib/posix/c_lib_ext/CMakeLists.txt @@ -0,0 +1,17 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_include_directories(getopt) + +if (CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT) + return() +endif() + +zephyr_library() +zephyr_library_sources( + fnmatch.c + getentropy.c + getopt/getopt.c + getopt/getopt_common.c +) + +zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG getopt/getopt_long.c) diff --git a/lib/posix/options/Kconfig.c_lib_ext b/lib/posix/c_lib_ext/Kconfig similarity index 100% rename from lib/posix/options/Kconfig.c_lib_ext rename to lib/posix/c_lib_ext/Kconfig diff --git a/lib/posix/options/fnmatch.c b/lib/posix/c_lib_ext/fnmatch.c similarity index 100% rename from lib/posix/options/fnmatch.c rename to lib/posix/c_lib_ext/fnmatch.c diff --git a/lib/posix/options/getentropy.c b/lib/posix/c_lib_ext/getentropy.c similarity index 100% rename from lib/posix/options/getentropy.c rename to lib/posix/c_lib_ext/getentropy.c diff --git a/lib/posix/options/getopt/README b/lib/posix/c_lib_ext/getopt/README similarity index 100% rename from lib/posix/options/getopt/README rename to lib/posix/c_lib_ext/getopt/README diff --git a/lib/posix/options/getopt/getopt.c b/lib/posix/c_lib_ext/getopt/getopt.c similarity index 100% rename from lib/posix/options/getopt/getopt.c rename to lib/posix/c_lib_ext/getopt/getopt.c diff --git a/lib/posix/options/getopt/getopt.h b/lib/posix/c_lib_ext/getopt/getopt.h similarity index 100% rename from lib/posix/options/getopt/getopt.h rename to lib/posix/c_lib_ext/getopt/getopt.h diff --git a/lib/posix/options/getopt/getopt_common.c b/lib/posix/c_lib_ext/getopt/getopt_common.c similarity index 100% rename from lib/posix/options/getopt/getopt_common.c rename to lib/posix/c_lib_ext/getopt/getopt_common.c diff --git a/lib/posix/options/getopt/getopt_common.h b/lib/posix/c_lib_ext/getopt/getopt_common.h similarity index 100% rename from lib/posix/options/getopt/getopt_common.h rename to lib/posix/c_lib_ext/getopt/getopt_common.h diff --git a/lib/posix/options/getopt/getopt_long.c b/lib/posix/c_lib_ext/getopt/getopt_long.c similarity index 100% rename from lib/posix/options/getopt/getopt_long.c rename to lib/posix/c_lib_ext/getopt/getopt_long.c diff --git a/lib/posix/eventfd/CMakeLists.txt b/lib/posix/eventfd/CMakeLists.txt new file mode 100644 index 0000000000000..2736572dd0061 --- /dev/null +++ b/lib/posix/eventfd/CMakeLists.txt @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: Apache-2.0 + +zephyr_library() +zephyr_library_sources(eventfd.c) diff --git a/lib/posix/options/Kconfig.compat b/lib/posix/eventfd/Kconfig similarity index 87% rename from lib/posix/options/Kconfig.compat rename to lib/posix/eventfd/Kconfig index e15cc869a7be6..019daef4a3524 100644 --- a/lib/posix/options/Kconfig.compat +++ b/lib/posix/eventfd/Kconfig @@ -3,8 +3,6 @@ # # SPDX-License-Identifier: Apache-2.0 -menu "Miscellaneous POSIX-related options" - config EVENTFD bool "Support for eventfd" select ZVFS @@ -13,5 +11,3 @@ config EVENTFD Enable support for event file descriptors, eventfd. An eventfd can be used as an event wait/notify mechanism together with POSIX calls like read, write and poll. - -endmenu diff --git a/lib/posix/options/eventfd.c b/lib/posix/eventfd/eventfd.c similarity index 100% rename from lib/posix/options/eventfd.c rename to lib/posix/eventfd/eventfd.c diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index 5ef2032e5a91c..ac11617c28b84 100644 --- a/lib/posix/options/CMakeLists.txt +++ b/lib/posix/options/CMakeLists.txt @@ -1,12 +1,15 @@ # SPDX-License-Identifier: Apache-2.0 +set(POSIX_VERSION 200809L) set(GEN_DIR ${ZEPHYR_BINARY_DIR}/include/generated) +zephyr_compile_definitions(-D_POSIX_C_SOURCE=${POSIX_VERSION}) + zephyr_syscall_header_ifdef(CONFIG_POSIX_CLOCK_SELECTION posix_clock.h) zephyr_syscall_header_ifdef(CONFIG_POSIX_TIMERS posix_clock.h) zephyr_syscall_header_ifdef(CONFIG_XSI_SINGLE_PROCESS posix_clock.h) -if(CONFIG_POSIX_SYSTEM_HEADERS) +if(CONFIG_POSIX_SYSTEM_INTERFACES) zephyr_include_directories(${ZEPHYR_BASE}/include/zephyr/posix) endif() @@ -27,8 +30,8 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_SIGNALS) endif() if(CONFIG_POSIX_API OR CONFIG_POSIX_THREADS OR CONFIG_POSIX_TIMERS OR - CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM OR CONFIG_EVENTFD OR - CONFIG_POSIX_C_LIB_EXT OR CONFIG_POSIX_SINGLE_PROCESS) + CONFIG_POSIX_MESSAGE_PASSING OR CONFIG_POSIX_FILE_SYSTEM 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>) @@ -36,7 +39,6 @@ if(CONFIG_POSIX_API OR CONFIG_POSIX_THREADS OR CONFIG_POSIX_TIMERS OR endif() zephyr_library() -zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c) if (NOT CONFIG_TC_PROVIDES_POSIX_ASYNCHRONOUS_IO) zephyr_library_sources_ifdef(CONFIG_POSIX_ASYNCHRONOUS_IO aio.c) @@ -50,15 +52,6 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_CLOCK_SELECTION) zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK_SELECTION clock_selection.c) endif() -if (NOT CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT) - zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT - fnmatch.c - getentropy.c - getopt/getopt.c - getopt/getopt_common.c - ) -endif() - if (NOT CONFIG_TC_PROVIDES_POSIX_DEVICE_IO) zephyr_library_sources_ifdef(CONFIG_POSIX_DEVICE_IO # perror should be moved to the common libc @@ -80,6 +73,9 @@ endif() if (NOT CONFIG_TC_PROVIDES_POSIX_FILE_SYSTEM_R) zephyr_library_sources_ifdef(CONFIG_POSIX_FILE_SYSTEM_R file_system_r.c) endif() +if (CONFIG_POSIX_FILE_SYSTEM_R) + zephyr_compile_definitions(-D_POSIX_THREAD_SAFE_FUNCTIONS=${POSIX_VERSION}) +endif() if (NOT CONFIG_TC_PROVIDES_POSIX_MEMORY_PROTECTION) zephyr_library_sources_ifdef(CONFIG_POSIX_MEMORY_PROTECTION mprotect.c) @@ -125,6 +121,15 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_TIMERS) timespec_to_timeout.c ) endif() +if (CONFIG_POSIX_TIMERS) + zephyr_compile_definitions(-D_POSIX_TIMERS=${POSIX_VERSION}) + # FIXME: Until we have CONFIG_XSI_ADVANCED_REALTIME define _POSIX_CPUTIME and + # _POSIX_MONOTONIC_CLOCK with _POSIX_TIMERS. + # For more information on the Advanced Realtime Option Group, please see + # https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap02.html + zephyr_compile_definitions(-D_POSIX_CPUTIME=${POSIX_VERSION}) + zephyr_compile_definitions(-D_POSIX_MONOTONIC_CLOCK=${POSIX_VERSION}) +endif() if (NOT CONFIG_TC_PROVIDES_POSIX_READER_WRITER_LOCKS) # Note: the Option is _POSIX_READER_WRITER_LOCKS, while the Option Group is POSIX_RW_LOCKS. @@ -171,13 +176,6 @@ if (NOT CONFIG_TC_PROVIDES_XSI_SYSTEM_LOGGING) zephyr_library_sources_ifdef(CONFIG_XSI_SYSTEM_LOGGING syslog.c) endif() -zephyr_library_sources_ifdef(CONFIG_GETOPT_LONG - getopt/getopt_long.c -) -zephyr_include_directories_ifdef(CONFIG_POSIX_C_LIB_EXT - getopt/ -) - zephyr_library_include_directories( ${ZEPHYR_BASE}/kernel/include ${ARCH_DIR}/${ARCH}/include diff --git a/lib/posix/options/Kconfig b/lib/posix/options/Kconfig index 6c2b129170e30..3f072a293f6be 100644 --- a/lib/posix/options/Kconfig +++ b/lib/posix/options/Kconfig @@ -4,14 +4,9 @@ # # SPDX-License-Identifier: Apache-2.0 -menu "POSIX Options" - -rsource "Kconfig.profile" - +# zephyr-keep-sorted-start rsource "Kconfig.aio" rsource "Kconfig.barrier" -rsource "Kconfig.c_lang_r" -rsource "Kconfig.c_lib_ext" rsource "Kconfig.device_io" rsource "Kconfig.fd_mgmt" rsource "Kconfig.file_system_r" @@ -29,19 +24,16 @@ rsource "Kconfig.signal" rsource "Kconfig.spinlock" rsource "Kconfig.sync_io" rsource "Kconfig.timer" +# zephyr-keep-sorted-stop menu "X/Open system interfaces" +# zephyr-keep-sorted-start rsource "Kconfig.xsi_realtime" rsource "Kconfig.xsi_single_process" rsource "Kconfig.xsi_streams" rsource "Kconfig.xsi_system_logging" rsource "Kconfig.xsi_threads_ext" +# zephyr-keep-sorted-stop endmenu # "X/Open system interfaces" - -rsource "Kconfig.compat" - -rsource "Kconfig.toolchain" - -endmenu # "POSIX Options" diff --git a/lib/posix/options/Kconfig.pthread b/lib/posix/options/Kconfig.pthread index 438506fe2182f..37aab14d472bd 100644 --- a/lib/posix/options/Kconfig.pthread +++ b/lib/posix/options/Kconfig.pthread @@ -157,6 +157,10 @@ config POSIX_THREAD_PRIO_PROTECT For more information, please see https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutexattr_getprotocol.html +# FIXME: this is an option, not an option group, and probably should be removed. +# Furthermore, it should also depend on POSIX_FILE_LOCKING and POSIX_SYSTEM_DATABASE_R rather +# than select any other options. The feature test macro _POSIX_THREAD_SAFE_FUNCTIONS should be +# enabled when dependencies are satisfied. config POSIX_THREAD_SAFE_FUNCTIONS bool "POSIX thread-safe functions" select POSIX_FILE_SYSTEM_R diff --git a/lib/posix/options/clock.c b/lib/posix/options/clock.c index 466974705ac3a..faa85cae775fc 100644 --- a/lib/posix/options/clock.c +++ b/lib/posix/options/clock.c @@ -10,7 +10,6 @@ #include #include -#include #include #include diff --git a/lib/posix/options/clock_selection.c b/lib/posix/options/clock_selection.c index 5717221b596ec..67e5a89eaccfe 100644 --- a/lib/posix/options/clock_selection.c +++ b/lib/posix/options/clock_selection.c @@ -12,7 +12,6 @@ #include #include -#include #include #include diff --git a/lib/posix/options/grp.c b/lib/posix/options/grp.c index 32c840e10164f..af395c88fa00c 100644 --- a/lib/posix/options/grp.c +++ b/lib/posix/options/grp.c @@ -9,8 +9,6 @@ #include #include -#ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS - int getgrnam_r(const char *name, struct group *grp, char *buffer, size_t bufsize, struct group **result) { @@ -33,5 +31,3 @@ int getgrgid_r(gid_t gid, struct group *grp, char *buffer, size_t bufsize, struc return ENOSYS; } - -#endif /* CONFIG_POSIX_THREAD_SAFE_FUNCTIONS */ diff --git a/lib/posix/options/pwd.c b/lib/posix/options/pwd.c index f806767f3df90..5cafbb0a3a94a 100644 --- a/lib/posix/options/pwd.c +++ b/lib/posix/options/pwd.c @@ -9,8 +9,6 @@ #include #include -#ifdef CONFIG_POSIX_THREAD_SAFE_FUNCTIONS - int getpwnam_r(const char *nam, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) { @@ -33,5 +31,3 @@ int getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, stru return ENOSYS; } - -#endif /* CONFIG_POSIX_THREAD_SAFE_FUNCTIONS */ diff --git a/lib/posix/options/timer.c b/lib/posix/options/timer.c index 257fdce59ef36..ae2a263ff64b1 100644 --- a/lib/posix/options/timer.c +++ b/lib/posix/options/timer.c @@ -11,12 +11,12 @@ #include "posix_clock.h" #include +#include #include #include #include #include -#include #define ACTIVE 1 #define NOT_ACTIVE 0 diff --git a/tests/lib/c_lib/thrd/src/thrd.h b/tests/lib/c_lib/thrd/src/thrd.h index 103b30a4f5f63..35d71eb07ab86 100644 --- a/tests/lib/c_lib/thrd/src/thrd.h +++ b/tests/lib/c_lib/thrd/src/thrd.h @@ -8,8 +8,8 @@ #define TESTS_LIB_CLIB_SRC_TEST_THRD_H_ #include +#include -#include #include #include diff --git a/tests/posix/common/src/clock.c b/tests/posix/common/src/clock.c index a1b1336d0ce27..2467ac4df4bb9 100644 --- a/tests/posix/common/src/clock.c +++ b/tests/posix/common/src/clock.c @@ -9,6 +9,7 @@ #include #include +#include #include #include diff --git a/tests/posix/common/src/mutex.c b/tests/posix/common/src/mutex.c index 40987d50297a0..20b992620eb8a 100644 --- a/tests/posix/common/src/mutex.c +++ b/tests/posix/common/src/mutex.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -182,7 +183,7 @@ static void *test_mutex_timedlock_fn(void *arg) struct timespec time_point; pthread_mutex_t *mtx = (pthread_mutex_t *)arg; - zassume_ok(clock_gettime(CLOCK_MONOTONIC, &time_point)); + zassume_ok(clock_gettime(CLOCK_REALTIME, &time_point)); timespec_add_ms(&time_point, TIMEDLOCK_TIMEOUT_MS); return INT_TO_POINTER(pthread_mutex_timedlock(mtx, &time_point)); diff --git a/tests/posix/common/src/pthread.c b/tests/posix/common/src/pthread.c index 035730ee4dc73..96a16f7ddb33b 100644 --- a/tests/posix/common/src/pthread.c +++ b/tests/posix/common/src/pthread.c @@ -6,6 +6,7 @@ #include #include +#include #include #include @@ -409,8 +410,8 @@ ZTEST(pthread, test_pthread_timedjoin) }; /* setup timespecs when the thread is still running and when it is done */ - clock_gettime(CLOCK_MONOTONIC, ¬_done); - clock_gettime(CLOCK_MONOTONIC, &done); + clock_gettime(CLOCK_REALTIME, ¬_done); + clock_gettime(CLOCK_REALTIME, &done); not_done.tv_nsec += sleep_duration_ms / 2 * NSEC_PER_MSEC; done.tv_nsec += sleep_duration_ms * 1.5 * NSEC_PER_MSEC; while (not_done.tv_nsec >= NSEC_PER_SEC) { diff --git a/tests/posix/semaphores/src/main.c b/tests/posix/semaphores/src/main.c index 4ea118af926ce..c8b566349a644 100644 --- a/tests/posix/semaphores/src/main.c +++ b/tests/posix/semaphores/src/main.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include diff --git a/tests/posix/single_process/prj.conf b/tests/posix/single_process/prj.conf index 7422432b9d0b8..ceec42c12c048 100644 --- a/tests/posix/single_process/prj.conf +++ b/tests/posix/single_process/prj.conf @@ -1,4 +1,5 @@ CONFIG_ZTEST=y +CONFIG_POSIX_SYSTEM_INTERFACES=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 diff --git a/tests/posix/timers/src/timer.c b/tests/posix/timers/src/timer.c index 1d4936d6a4be6..49e896f991e43 100644 --- a/tests/posix/timers/src/timer.c +++ b/tests/posix/timers/src/timer.c @@ -9,6 +9,7 @@ #include #include +#include #define SECS_TO_SLEEP 2 #define DURATION_SECS 1