diff --git a/include/zephyr/posix/mqueue.h b/include/zephyr/posix/mqueue.h index 40db073337490..28c42d7e30649 100644 --- a/include/zephyr/posix/mqueue.h +++ b/include/zephyr/posix/mqueue.h @@ -7,10 +7,11 @@ #ifndef ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_ #define ZEPHYR_INCLUDE_POSIX_MESSAGE_PASSING_H_ +#include +#include + #include -#include #include -#include #include #include diff --git a/include/zephyr/posix/posix_features.h b/include/zephyr/posix/posix_features.h index cb0a76e99ee75..b253dbd8fc5a7 100644 --- a/include/zephyr/posix/posix_features.h +++ b/include/zephyr/posix/posix_features.h @@ -52,14 +52,6 @@ #define _POSIX_BARRIERS _POSIX_VERSION #endif -#ifdef CONFIG_POSIX_CLOCK_SELECTION -#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 +82,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 @@ -108,7 +96,6 @@ #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION #endif -/* #define _POSIX_REALTIME_SIGNALS (-1L) */ /* #define _POSIX_REGEXP (-1L) */ /* #define _POSIX_SAVED_IDS (-1L) */ @@ -161,10 +148,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 +160,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_signal.h b/include/zephyr/posix/posix_signal.h new file mode 100644 index 0000000000000..bfb1f30efdc6a --- /dev/null +++ b/include/zephyr/posix/posix_signal.h @@ -0,0 +1,398 @@ +/* + * Copyright (c) 2025 The Zephyr Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ +#ifndef ZEPHYR_INCLUDE_POSIX_POSIX_SIGNAL_H_ +#define ZEPHYR_INCLUDE_POSIX_POSIX_SIGNAL_H_ + +#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* SIG_DFL must be defined by the libc signal.h */ +/* SIG_ERR must be defined by the libc signal.h */ + +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +#define SIG_HOLD ((void *)-2) +#endif + +/* SIG_IGN must be defined by the libc signal.h */ + +#if defined(_POSIX_THREADS) || defined(__DOXYGEN__) + +#if !defined(_PTHREAD_T_DECLARED) && !defined(__pthread_t_defined) +typedef unsigned int pthread_t; +#define _PTHREAD_T_DECLARED +#define __pthread_t_defined +#endif + +#endif /* defined(_POSIX_THREADS) || defined(__DOXYGEN__) */ + +/* size_t must be defined by the libc stddef.h */ +#include + +#if !defined(_UID_T_DECLARED) && !defined(__uid_t_defined) +typedef int uid_t; +#define _UID_T_DECLARED +#define __uid_t_defined +#endif + +#if !defined(_TIME_T_DECLARED) && !defined(__time_t_defined) +typedef long time_t; +#define _TIME_T_DECLARED +#define __time_t_defined +#endif + +#if !defined(_TIMESPEC_DECLARED) && !defined(__timespec_defined) +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#define _TIMESPEC_DECLARED +#define __timespec_defined +#endif + +/* sig_atomic_t must be defined by the libc signal.h */ + +#define SIGRTMIN 32 +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) +BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= 0); +#define SIGRTMAX (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX) +#else +#define SIGRTMAX SIGRTMIN +#endif + +#if !defined(_SIGSET_T_DECLARED) && !defined(__sigset_t_defined) +typedef struct { + unsigned long sig[DIV_ROUND_UP(SIGRTMAX + 1, BITS_PER_LONG)]; +} sigset_t; +#define _SIGSET_T_DECLARED +#define __sigset_t_defined +#endif + +#if !defined(_PID_T_DECLARED) && !defined(__pid_t_defined) +typedef long pid_t; +#define _PID_T_DECLARED +#define __pid_t_defined +#endif + +#if defined(_POSIX_THREADS) || defined(__DOXYGEN__) + +#if !defined(_PTHREAD_ATTR_T_DECLARED) && !defined(__pthread_attr_t_defined) +typedef struct { + void *stack; + unsigned int details[2]; +} pthread_attr_t; +#define _PTHREAD_ATTR_T_DECLARED +#define __pthread_attr_t_defined +#endif + +#endif + +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) + +union sigval; /* forward declaration (to preserve spec order) */ + +#if !defined(_SIGEVENT_DECLARED) && !defined(__sigevent_defined) +typedef struct { +#if defined(_POSIX_THREADS) || defined(__DOXYGEN__) + pthread_attr_t *sigev_thread_attr; +#endif + union sigval sigev_value; + int sigev_notify; + int sigev_signo; +} sigevent_t; +#define _SIGEVENT_DECLARED +#define __sigevent_defined +#endif + +#define SIGEV_NONE 1 +#define SIGEV_SIGNAL 2 +#define SIGEV_THREAD 3 + +/* Signal constants are defined below */ + +#endif /* defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) */ + +#if !defined(_SIGVAL_DECLARED) && !defined(__sigval_defined) +union sigval { + int sival_int; + void *sival_ptr; +}; +#define _SIGVAL_DECLARED +#define __sigval_defined +#endif + +/* SIGRTMIN and SIGRTMAX defined above */ + +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) + +#if !defined(_SIGACTION_DECLARED) && !defined(__sigaction_defined) +struct sigaction { + union { + void (*sa_handler)(int sig); + void (*sa_sigaction)(int sig, siginfo_t *info, void *context); + }; + sigset_t sa_mask; + int sa_flags; +}; +#define _SIGACTION_DECLARED +#define __sigaction_defined +#endif + +#define SIG_BLOCK 1 +#define SIG_UNBLOCK 2 +#define SIG_SETMASK 0 + +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +#define SA_NOCLDSTOP 0x00000001 +#define SA_ONSTACK 0x00000002 +#endif +#define SA_RESETHAND 0x00000004 +#define SA_RESTART 0x00000008 +#define SA_SIGINFO 0x00000010 +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +#define SA_NOCLDWAIT 0x00000020 +#endif +#define SA_NODEFER 0x00000040 +#define SS_ONSTACK 0x00000001 +#define SS_DISABLE 0x00000002 +#define MINSIGSTKSZ 4096 +#define SIGSTKSZ 4096 + +#if !defined(_MCONTEXT_T_DECLARED) && !defined(__mcontext_t_defined) +typedef struct { + /* FIXME: there should be a much better Zephyr-specific structure that can be used here */ + unsigned long gregs[32]; + unsigned long flags; +} mcontext_t; +#define _MCONTEXT_T_DECLARED +#define __mcontext_defined +#endif + +#if !defined(_UCONTEXT_T_DECLARED) && !defined(__ucontext_t_defined) +typedef struct { + struct ucontext *uc_link; + sigset_t uc_sigmask; + stack_t uc_stack; + mcontext_t uc_mcontext; +} ucontext_t; +#define _UCONTEXT_T_DECLARED +#define __ucontext_defined +#endif + +#if !defined(_STACK_T_DECLARED) && !defined(__stack_t_defined) +typedef struct { + void *ss_sp; + size_t ss_size; + int ss_flags; +} stack_t; +#define _STACK_T_DECLARED +#define __stack_t_defined +#endif + +#endif /* defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) */ + +#if !defined(_SIGINFO_T_DECLARED) && !defined(__siginfo_t_defined) +typedef struct { + void *si_addr; +#if defined(_XOPEN_STREAMS) || defined(__DOXYGEN__) + long si_band; +#endif + union sigval si_value; + pid_t si_pid; + uid_t si_uid; + int si_signo; + int si_code; +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) + int si_errno; +#endif + int si_status; +} siginfo_t; +#define _SIGINFO_T_DECLARED +#define __siginfo_t_defined +#endif + +/* Siginfo codes are defined below */ + +#if !defined(_SIGHANDLER_T_DECLARED) && !defined(__sighandler_t_defined) +typedef void (*sighandler_t)(int sig); +#define _SIGHANDLER_T_DECLARED +#define __sighandler_t_defined +#endif + +int kill(pid_t pid, int sig); +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +int killpg(pid_t pgrp, int sig); +#endif +void psiginfo(const siginfo_t *info, const char *message); +void psignal(int sig, const char *message); +#if defined(_POSIX_THREADS) || defined(__DOXYGEN__) +int pthread_kill(pthread_t thread, int sig); +int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); +#endif +/* raise() must be defined by the libc signal.h */ +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) +TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_SHADOW); +int sigaction(int sig, const struct sigaction *ZRESTRICT act, struct sigaction *ZRESTRICT oact); +TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_SHADOW); +#endif +int sigaddset(sigset_t *set, int sig); +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +int sigaltstack(const stack_t *ZRESTRICT ss, stack_t *ZRESTRICT oss); +#endif +int sigdelset(sigset_t *set, int sig); +int sigemptyset(sigset_t *set); +int sigfillset(sigset_t *set); +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +int sighold(int sig); +int sigignore(int sig); +int siginterrupt(int sig, int flag); +#endif +int sigismember(const sigset_t *set, int sig); +/* signal() must be defined by the libc signal.h */ +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +int sigpause(int sig); +#endif +int sigpending(sigset_t *set); +int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) +int sigqueue(pid_t pid, int sig, union sigval value); +#endif +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +int sigrelse(int sig); +sighandler_t sigset(int sig, sighandler_t disp); +#endif +int sigsuspend(const sigset_t *set); +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) +int sigtimedwait(const sigset_t *ZRESTRICT set, siginfo_t *ZRESTRICT info, + const struct timespec *ZRESTRICT timeout); +#endif +int sigwait(const sigset_t *ZRESTRICT set, int *ZRESTRICT sig); +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) +int sigwaitinfo(const sigset_t *ZRESTRICT set, siginfo_t *ZRESTRICT info); +#endif + +/* Note: only ANSI / ISO C signals are guarded below */ + +#define SIGHUP 1 /**< Hangup */ +#if !defined(SIGINT) || defined(__DOXYGEN__) +#define SIGINT 2 /**< Interrupt */ +#endif +#define SIGQUIT 3 /**< Quit */ +#if !defined(SIGILL) || defined(__DOXYGEN__) +#define SIGILL 4 /**< Illegal instruction */ +#endif +#define SIGTRAP 5 /**< Trace/breakpoint trap */ +#if !defined(SIGABRT) || defined(__DOXYGEN__) +#define SIGABRT 6 /**< Aborted */ +#endif +#define SIGBUS 7 /**< Bus error */ +#if !defined(SIGFPE) || defined(__DOXYGEN__) +#define SIGFPE 8 /**< Arithmetic exception */ +#endif +#define SIGKILL 9 /**< Killed */ +#define SIGUSR1 10 /**< User-defined signal 1 */ +#if !defined(SIGSEGV) || defined(__DOXYGEN__) +#define SIGSEGV 11 /**< Invalid memory reference */ +#endif +#define SIGUSR2 12 /**< User-defined signal 2 */ +#define SIGPIPE 13 /**< Broken pipe */ +#define SIGALRM 14 /**< Alarm clock */ +#if !defined(SIGTERM) || defined(__DOXYGEN__) +#define SIGTERM 15 /**< Terminated */ +#endif +/* 16 not used */ +#define SIGCHLD 17 /**< Child status changed */ +#define SIGCONT 18 /**< Continued */ +#define SIGSTOP 19 /**< Stop executing */ +#define SIGTSTP 20 /**< Stopped */ +#define SIGTTIN 21 /**< Stopped (read) */ +#define SIGTTOU 22 /**< Stopped (write) */ +#define SIGURG 23 /**< Urgent I/O condition */ +#define SIGXCPU 24 /**< CPU time limit exceeded */ +#define SIGXFSZ 25 /**< File size limit exceeded */ +#define SIGVTALRM 26 /**< Virtual timer expired */ +#define SIGPROF 27 /**< Profiling timer expired */ +/* 28 not used */ +#define SIGPOLL 29 /**< Pollable event occurred */ +/* 30 not used */ +#define SIGSYS 31 /**< Bad system call */ + +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) + +/* SIGILL */ +#define ILL_ILLOPC 1 /**< Illegal opcode */ +#define ILL_ILLOPN 2 /**< Illegal operand */ +#define ILL_ILLADR 3 /**< Illegal addressing mode */ +#define ILL_ILLTRP 4 /**< Illegal trap */ +#define ILL_PRVOPC 5 /**< Privileged opcode */ +#define ILL_PRVREG 6 /**< Privileged register */ +#define ILL_COPROC 7 /**< Coprocessor error */ +#define ILL_BADSTK 8 /**< Internal stack error */ + +/* SIGFPE */ +#define FPE_INTDIV 9 /**< Integer divide by zero */ +#define FPE_INTOVF 10 /**< Integer overflow */ +#define FPE_FLTDIV 11 /**< Floating-point divide by zero */ +#define FPE_FLTOVF 12 /**< Floating-point overflow */ +#define FPE_FLTUND 13 /**< Floating-point underflow */ +#define FPE_FLTRES 15 /**< Floating-point inexact result */ +#define FPE_FLTINV 16 /**< Invalid floating-point operation */ +#define FPE_FLTSUB 17 /**< Subscript out of range */ + +/* SIGSEGV */ +#define SEGV_MAPERR 18 /**< Address not mapped to object */ +#define SEGV_ACCERR 19 /**< Invalid permissions for mapped object */ + +/* SIGBUS */ +#define BUS_ADRALN 20 /**< Invalid address alignment */ +#define BUS_ADRERR 21 /**< Nonexistent physical address */ +#define BUS_OBJERR 22 /**< Object-specific hardware error */ + +#if defined(_XOPEN_SOURCE) || defined(__DOXYGEN__) +/* SIGTRAP */ +#define TRAP_BRKPT 23 /**< Process breakpoint */ +#define TRAP_TRACE 24 /**< Process trace trap */ +#endif + +/* SIGCHLD */ +#define CLD_EXITED 25 /**< Child has exited */ +#define CLD_KILLED 26 /**< Child has terminated abnormally and did not create a core file */ +#define CLD_DUMPED 27 /**< Child has terminated abnormally and created a core file */ +#define CLD_TRAPPED 28 /**< Traced child has trapped */ +#define CLD_STOPPED 29 /**< Child has stopped */ +#define CLD_CONTINUED 30 /**< Stopped child has continued */ + +#if defined(_XOPEN_STREAMS) || defined(__DOXYGEN__) +/* SIGPOLL */ +#define POLL_IN 31 /**< Data input available */ +#define POLL_OUT 32 /**< Output buffers available */ +#define POLL_MSG 33 /**< Input message available */ +#define POLL_ERR 34 /**< I/O error */ +#define POLL_PRI 35 /**< High priority input available */ +#define POLL_HUP 36 /**< Device disconnected */ +#endif + +/* Any */ +#define SI_USER 37 /**< Signal sent by kill() */ +#define SI_QUEUE 38 /**< Signal sent by sigqueue() */ +#define SI_TIMER 39 /**< Signal generated by expiration of a timer set by timer_settime() */ +#define SI_ASYNCIO 40 /**< Signal generated by completion of an asynchronous I/O request */ +#define SI_MESGQ 41 /**< Signal generated by arrival of a message on an empty message queue */ + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */ + +#endif /* ZEPHYR_INCLUDE_POSIX_POSIX_SIGNAL_H_ */ diff --git a/include/zephyr/posix/posix_time.h b/include/zephyr/posix/posix_time.h new file mode 100644 index 0000000000000..f2027e82875fc --- /dev/null +++ b/include/zephyr/posix/posix_time.h @@ -0,0 +1,194 @@ +/* + * 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_SYS_CLOCK_TICKS_PER_SEC +#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 deleted file mode 100644 index 7513bfd104753..0000000000000 --- a/include/zephyr/posix/signal.h +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Copyright (c) 2018 Intel Corporation - * - * SPDX-License-Identifier: Apache-2.0 - */ -#ifndef ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ -#define ZEPHYR_INCLUDE_POSIX_SIGNAL_H_ - -/* include posix_types.h before posix_features.h (here) to avoid build errors against newlib */ -#include -#include "posix_features.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define SIGHUP 1 /**< Hangup */ -#define SIGINT 2 /**< Interrupt */ -#define SIGQUIT 3 /**< Quit */ -#define SIGILL 4 /**< Illegal instruction */ -#define SIGTRAP 5 /**< Trace/breakpoint trap */ -#define SIGABRT 6 /**< Aborted */ -#define SIGBUS 7 /**< Bus error */ -#define SIGFPE 8 /**< Arithmetic exception */ -#define SIGKILL 9 /**< Killed */ -#define SIGUSR1 10 /**< User-defined signal 1 */ -#define SIGSEGV 11 /**< Invalid memory reference */ -#define SIGUSR2 12 /**< User-defined signal 2 */ -#define SIGPIPE 13 /**< Broken pipe */ -#define SIGALRM 14 /**< Alarm clock */ -#define SIGTERM 15 /**< Terminated */ -/* 16 not used */ -#define SIGCHLD 17 /**< Child status changed */ -#define SIGCONT 18 /**< Continued */ -#define SIGSTOP 19 /**< Stop executing */ -#define SIGTSTP 20 /**< Stopped */ -#define SIGTTIN 21 /**< Stopped (read) */ -#define SIGTTOU 22 /**< Stopped (write) */ -#define SIGURG 23 /**< Urgent I/O condition */ -#define SIGXCPU 24 /**< CPU time limit exceeded */ -#define SIGXFSZ 25 /**< File size limit exceeded */ -#define SIGVTALRM 26 /**< Virtual timer expired */ -#define SIGPROF 27 /**< Profiling timer expired */ -/* 28 not used */ -#define SIGPOLL 29 /**< Pollable event occurred */ -/* 30 not used */ -#define SIGSYS 31 /**< Bad system call */ - -#define SIGRTMIN 32 -#if defined(CONFIG_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) -BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= 0); -#define SIGRTMAX (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX) -#else -#define SIGRTMAX SIGRTMIN -#endif - -typedef struct { - unsigned long sig[DIV_ROUND_UP(SIGRTMAX + 1, BITS_PER_LONG)]; -} sigset_t; - -#ifndef SIGEV_NONE -#define SIGEV_NONE 1 -#endif - -#ifndef SIGEV_SIGNAL -#define SIGEV_SIGNAL 2 -#endif - -#ifndef SIGEV_THREAD -#define SIGEV_THREAD 3 -#endif - -#ifndef SIG_BLOCK -#define SIG_BLOCK 0 -#endif -#ifndef SIG_SETMASK -#define SIG_SETMASK 1 -#endif -#ifndef SIG_UNBLOCK -#define SIG_UNBLOCK 2 -#endif - -#define SIG_DFL ((void *)0) -#define SIG_IGN ((void *)1) -#define SIG_ERR ((void *)-1) - -#define SI_USER 1 -#define SI_QUEUE 2 -#define SI_TIMER 3 -#define SI_ASYNCIO 4 -#define SI_MESGQ 5 - -typedef int sig_atomic_t; /* Atomic entity type (ANSI) */ - -union sigval { - void *sival_ptr; - int sival_int; -}; - -struct sigevent { - void (*sigev_notify_function)(union sigval val); - pthread_attr_t *sigev_notify_attributes; - union sigval sigev_value; - int sigev_notify; - int sigev_signo; -}; - -typedef struct { - int si_signo; - int si_code; - union sigval si_value; -} siginfo_t; - -struct sigaction { - void (*sa_handler)(int signno); - sigset_t sa_mask; - int sa_flags; - void (*sa_sigaction)(int signo, siginfo_t *info, void *context); -}; - -typedef void (*sighandler_t)(int signo); - -unsigned int alarm(unsigned int seconds); -int kill(pid_t pid, int sig); -int pause(void); -int raise(int signo); -TOOLCHAIN_DISABLE_WARNING(TOOLCHAIN_WARNING_SHADOW); -int sigaction(int sig, const struct sigaction *ZRESTRICT act, struct sigaction *ZRESTRICT oact); -TOOLCHAIN_ENABLE_WARNING(TOOLCHAIN_WARNING_SHADOW); -int sigpending(sigset_t *set); -int sigsuspend(const sigset_t *sigmask); -int sigwait(const sigset_t *ZRESTRICT set, int *ZRESTRICT signo); -char *strsignal(int signum); -int sigemptyset(sigset_t *set); -int sigfillset(sigset_t *set); -int sigaddset(sigset_t *set, int signo); -int sigdelset(sigset_t *set, int signo); -int sigismember(const sigset_t *set, int signo); -sighandler_t signal(int signo, sighandler_t handler); -int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); - -int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); - -#ifdef __cplusplus -} -#endif - -#endif /* ZEPHYR_INCLUDE_POSIX_SIGNAL_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 2f07aa636e181..d9498ce9a3e4b 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/signal.h b/lib/libc/arcmwdt/include/signal.h index cdd39d1ff1803..be7e3c2529af0 100644 --- a/lib/libc/arcmwdt/include/signal.h +++ b/lib/libc/arcmwdt/include/signal.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2024 Synopsys + * Copyright (c) 2025 Tenstorrent AI ULC * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +8,36 @@ #ifndef LIB_LIBC_ARCMWDT_INCLUDE_SIGNAL_H_ #define LIB_LIBC_ARCMWDT_INCLUDE_SIGNAL_H_ -#include +#ifdef __cplusplus +extern "C" { +#endif + +#define SIGABRT 6 +#define SIGFPE 8 +#define SIGILL 4 +#define SIGINT 2 +#define SIGSEGV 11 +#define SIGTERM 15 + +#define SIG_DFL ((sighandler_t)0) +#define SIG_IGN ((sighandler_t)1) +#define SIG_ERR ((sighandler_t)(-1)) + +typedef long sig_atomic_t; + +#if !defined(_SIGHANDLER_T_DECLARED) && !defined(__sighandler_t_defined) +typedef void (*sighandler_t)(int sig); +#define _SIGHANDLER_T_DECLARED +#define __sighandler_t_defined +#endif + +sighandler_t signal(int sig, sighandler_t handler); +int raise(int sig); + +#ifdef __cplusplus +} +#endif + +#include #endif /* LIB_LIBC_ARCMWDT_INCLUDE_SIGNAL_H_ */ diff --git a/lib/libc/arcmwdt/include/time.h b/lib/libc/arcmwdt/include/time.h index 245bd3a77d236..9f7a741215204 100644 --- a/lib/libc/arcmwdt/include/time.h +++ b/lib/libc/arcmwdt/include/time.h @@ -9,6 +9,8 @@ #include_next +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/libc/iar/include/time.h b/lib/libc/iar/include/time.h index b095987857418..7916523bf2208 100644 --- a/lib/libc/iar/include/time.h +++ b/lib/libc/iar/include/time.h @@ -12,9 +12,11 @@ #ifndef ZEPHYR_LIB_LIBC_IAR_INCLUDE_TIME_H_ #define ZEPHYR_LIB_LIBC_IAR_INCLUDE_TIME_H_ -#include #include_next +#include +#include + #ifdef __cplusplus extern "C" { #endif diff --git a/lib/libc/minimal/include/signal.h b/lib/libc/minimal/include/signal.h index 3cf00bf374377..c2767d234b0ee 100644 --- a/lib/libc/minimal/include/signal.h +++ b/lib/libc/minimal/include/signal.h @@ -1,5 +1,6 @@ /* * Copyright (c) 2024 Synopsys + * Copyright (c) 2025 Tenstorrent AI ULC * * SPDX-License-Identifier: Apache-2.0 */ @@ -7,6 +8,36 @@ #ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_ #define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_ -#include +#ifdef __cplusplus +extern "C" { +#endif + +#define SIGABRT 6 +#define SIGFPE 8 +#define SIGILL 4 +#define SIGINT 2 +#define SIGSEGV 11 +#define SIGTERM 15 + +#define SIG_DFL ((sighandler_t)0) +#define SIG_IGN ((sighandler_t)1) +#define SIG_ERR ((sighandler_t)(-1)) + +typedef long sig_atomic_t; + +#if !defined(_SIGHANDLER_T_DECLARED) && !defined(__sighandler_t_defined) +typedef void (*sighandler_t)(int sig); +#define _SIGHANDLER_T_DECLARED +#define __sighandler_t_defined +#endif + +sighandler_t signal(int sig, sighandler_t handler); +int raise(int sig); + +#ifdef __cplusplus +} +#endif + +#include #endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_ */ diff --git a/lib/libc/minimal/include/time.h b/lib/libc/minimal/include/time.h index 62ec45b03a171..55c8a0fb6320c 100644 --- a/lib/libc/minimal/include/time.h +++ b/lib/libc/minimal/include/time.h @@ -68,4 +68,6 @@ time_t time(time_t *tloc); } #endif +#include + #endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_STDIO_H_ */ diff --git a/lib/libc/newlib/include/signal.h b/lib/libc/newlib/include/signal.h new file mode 100644 index 0000000000000..6d61c9d65a70b --- /dev/null +++ b/lib/libc/newlib/include/signal.h @@ -0,0 +1,39 @@ +/* + * Copyright The Zephyr Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SIGNAL_H_ +#define ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SIGNAL_H_ + +#include_next + +#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) + +#define SIGRTMIN 32 +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) +#define SIGRTMAX (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX) +#else +#define SIGRTMAX SIGRTMIN +#endif + +/* + * Newlib's macro implementations of the following are unfortunately non-conformant + * + * - sigaddset() + * - sigdelset() + * - sigismember() + * + * For additional info, see + * https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigaddset.html + * https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigdelset.html + * https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigismember.html + */ +#undef sigaddset +#undef sigdelset +#undef sigismember + +#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */ + +#endif /* ZEPHYR_LIB_LIBC_NEWLIB_INCLUDE_SIGNAL_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/signal.h b/lib/libc/picolibc/include/signal.h new file mode 100644 index 0000000000000..a65b544c3fcd1 --- /dev/null +++ b/lib/libc/picolibc/include/signal.h @@ -0,0 +1,52 @@ +/* + * Copyright The Zephyr Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SIGNAL_H_ +#define ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SIGNAL_H_ + +#include_next + +#include + +#if defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) + +#define SIGRTMIN 32 +#if defined(_POSIX_REALTIME_SIGNALS) || defined(__DOXYGEN__) +#define SIGRTMAX (SIGRTMIN + CONFIG_POSIX_RTSIG_MAX) +#else +#define SIGRTMAX SIGRTMIN +#endif + +#ifndef _PID_T_DECLARED +typedef __pid_t pid_t; +#define _PID_T_DECLARED +#endif + +#if defined(_POSIX_THREADS) || defined(__DOXYGEN__) +int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset); +#endif + +/* + * Picolibc's macro implementations of the following are unfortunately non-conformant + * + * - sigaddset() + * - sigdelset() + * - sigismember() + * + * For additional info, see + * https://github.com/picolibc/picolibc/blob/\ + * c1218d79199fbfbad400223502726563d24cb8e7/newlib/libc/include/signal.h#L248 + * https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigaddset.html + * https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigdelset.html + * https://pubs.opengroup.org/onlinepubs/9799919799/functions/sigismember.html + */ +#undef sigaddset +#undef sigdelset +#undef sigismember + +#endif /* defined(_POSIX_C_SOURCE) || defined(__DOXYGEN__) */ + +#endif /* ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_SIGNAL_H_ */ diff --git a/lib/libc/picolibc/include/time.h b/lib/libc/picolibc/include/time.h new file mode 100644 index 0000000000000..b6ff65137e69d --- /dev/null +++ b/lib/libc/picolibc/include/time.h @@ -0,0 +1,32 @@ +/* + * Copyright The Zephyr Project Contributors + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_LIB_LIBC_PICOLIBC_INCLUDE_TIME_H_ +#define ZEPHYR_LIB_LIBC_PICOLIBC_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_PICOLIBC_INCLUDE_TIME_H_ */ diff --git a/lib/posix/options/CMakeLists.txt b/lib/posix/options/CMakeLists.txt index bedbef0acbb52..429f1d3932eb2 100644 --- a/lib/posix/options/CMakeLists.txt +++ b/lib/posix/options/CMakeLists.txt @@ -1,7 +1,10 @@ # 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) @@ -19,22 +22,13 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_SIGNALS) COMMAND ${PYTHON_EXECUTABLE} ${ZEPHYR_BASE}/scripts/build/gen_strsignal_table.py - -i ${ZEPHYR_BASE}/include/zephyr/posix/signal.h + -i ${ZEPHYR_BASE}/include/zephyr/posix/posix_signal.h -o ${STRSIGNAL_TABLE_H} - DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/signal.h + DEPENDS ${ZEPHYR_BASE}/include/zephyr/posix/posix_signal.h ) endif() 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) - # 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>) - zephyr_compile_options($<$:-D_POSIX_THREADS>) -endif() - zephyr_library() zephyr_library_sources_ifdef(CONFIG_EVENTFD eventfd.c) @@ -49,6 +43,9 @@ endif() if (NOT CONFIG_TC_PROVIDES_POSIX_CLOCK_SELECTION) zephyr_library_sources_ifdef(CONFIG_POSIX_CLOCK_SELECTION clock_selection.c) endif() +if (CONFIG_POSIX_CLOCK_SELECTION) + zephyr_compile_definitions(-D_POSIX_CLOCK_SELECTION=${POSIX_VERSION}) +endif() if (NOT CONFIG_TC_PROVIDES_POSIX_C_LIB_EXT) zephyr_library_sources_ifdef(CONFIG_POSIX_C_LIB_EXT @@ -80,6 +77,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) @@ -100,6 +100,10 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_NETWORKING) zephyr_library_sources_ifdef(CONFIG_POSIX_NETWORKING net.c) endif() +if (CONFIG_POSIX_REALTIME_SIGNALS) + zephyr_compile_definitions(-D_POSIX_REALTIME_SIGNALS=${POSIX_VERSION}) +endif() + if (NOT CONFIG_TC_PROVIDES_POSIX_SIGNALS) zephyr_library_sources_ifdef(CONFIG_POSIX_SIGNALS signal.c ${STRSIGNAL_TABLE_H}) endif() @@ -125,6 +129,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 a Kconfig for 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_RW_LOCKS) zephyr_library_sources_ifdef(CONFIG_POSIX_RW_LOCKS rwlock.c) @@ -146,6 +159,9 @@ if (NOT CONFIG_TC_PROVIDES_POSIX_THREADS) pwd.c ) endif() +if (CONFIG_POSIX_THREADS) + zephyr_compile_definitions(-D_POSIX_THREADS=${POSIX_VERSION}) +endif() if(NOT CONFIG_TC_PROVIDES_XSI_REALTIME) zephyr_library_sources_ifdef(CONFIG_POSIX_FSYNC fsync.c) 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/posix_internal.h b/lib/posix/options/posix_internal.h index 0aed495dede25..d149b51e63a62 100644 --- a/lib/posix/options/posix_internal.h +++ b/lib/posix/options/posix_internal.h @@ -9,10 +9,10 @@ #include #include +#include #include #include -#include #include #include diff --git a/lib/posix/options/pthread.c b/lib/posix/options/pthread.c index c505b8564bb30..927dead182b4e 100644 --- a/lib/posix/options/pthread.c +++ b/lib/posix/options/pthread.c @@ -1518,18 +1518,21 @@ int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT SYS_SEM_LOCK_BREAK; } + const unsigned long *const x = (const unsigned long *)set; + unsigned long *const y = (unsigned long *)&t->sigset; + switch (how) { case SIG_BLOCK: - for (size_t i = 0; i < ARRAY_SIZE(set->sig); ++i) { - t->sigset.sig[i] |= set->sig[i]; + for (size_t i = 0; i < sizeof(sigset_t) / sizeof(unsigned long); ++i) { + y[i] |= x[i]; } break; case SIG_SETMASK: t->sigset = *set; break; case SIG_UNBLOCK: - for (size_t i = 0; i < ARRAY_SIZE(set->sig); ++i) { - t->sigset.sig[i] &= ~set->sig[i]; + for (size_t i = 0; i < sizeof(sigset_t) / sizeof(unsigned long); ++i) { + y[i] &= ~x[i]; } break; } diff --git a/lib/posix/options/signal.c b/lib/posix/options/signal.c index 958a2dac6f74a..d3d935109e45d 100644 --- a/lib/posix/options/signal.c +++ b/lib/posix/options/signal.c @@ -6,14 +6,17 @@ #include "posix/strsignal_table.h" #include +#include #include +#include #include -#include #define SIGNO_WORD_IDX(_signo) (_signo / BITS_PER_LONG) #define SIGNO_WORD_BIT(_signo) (_signo & BIT_MASK(LOG2(BITS_PER_LONG))) +#define SIGSET_NLONGS (sizeof(sigset_t) / sizeof(unsigned long)) + static inline bool signo_valid(int signo) { return ((signo > 0) && (signo <= SIGRTMAX)); @@ -24,53 +27,86 @@ static inline bool signo_is_rt(int signo) return ((signo >= SIGRTMIN) && (signo <= SIGRTMAX)); } +static inline bool signo_fits(int signo) +{ + return ((signo > 0) && (signo <= SIGSET_NLONGS * BITS_PER_LONG)); +} + +#undef sigemptyset int sigemptyset(sigset_t *set) { *set = (sigset_t){0}; return 0; } +#undef sigfillset int sigfillset(sigset_t *set) { - for (int i = 0; i < ARRAY_SIZE(set->sig); i++) { - set->sig[i] = -1; + unsigned long *const _set = (unsigned long *)set; + + for (int i = 0; i < SIGSET_NLONGS; i++) { + _set[i] = -1; } return 0; } +#undef sigaddset int sigaddset(sigset_t *set, int signo) { + unsigned long *_set = (unsigned long *)set; + if (!signo_valid(signo)) { errno = EINVAL; return -1; } - WRITE_BIT(set->sig[SIGNO_WORD_IDX(signo)], SIGNO_WORD_BIT(signo), 1); + if (!signo_fits(signo)) { + errno = EINVAL; + return -1; + } + + WRITE_BIT(_set[SIGNO_WORD_IDX(signo)], SIGNO_WORD_BIT(signo), 1); return 0; } +#undef sigdelset int sigdelset(sigset_t *set, int signo) { + unsigned long *_set = (unsigned long *)set; + if (!signo_valid(signo)) { errno = EINVAL; return -1; } - WRITE_BIT(set->sig[SIGNO_WORD_IDX(signo)], SIGNO_WORD_BIT(signo), 0); + if (!signo_fits(signo)) { + errno = EINVAL; + return -1; + } + + WRITE_BIT(_set[SIGNO_WORD_IDX(signo)], SIGNO_WORD_BIT(signo), 0); return 0; } +#undef sigismember int sigismember(const sigset_t *set, int signo) { + const unsigned long *const _set = (const unsigned long *)set; + if (!signo_valid(signo)) { errno = EINVAL; return -1; } - return 1 & (set->sig[SIGNO_WORD_IDX(signo)] >> SIGNO_WORD_BIT(signo)); + if (!signo_fits(signo)) { + errno = EINVAL; + return -1; + } + + return 1 & (_set[SIGNO_WORD_IDX(signo)] >> SIGNO_WORD_BIT(signo)); } char *strsignal(int signum) diff --git a/lib/posix/options/timer.c b/lib/posix/options/timer.c index 257fdce59ef36..90ccce5dda04f 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 -#include #define ACTIVE 1 #define NOT_ACTIVE 0 diff --git a/samples/net/ocpp/src/main.c b/samples/net/ocpp/src/main.c index 5e8b8d0079454..b703428bce46d 100644 --- a/samples/net/ocpp/src/main.c +++ b/samples/net/ocpp/src/main.c @@ -5,6 +5,7 @@ */ #include +#include #include #include @@ -12,7 +13,6 @@ #include #include #include -#include #include #include diff --git a/scripts/build/gen_strsignal_table.py b/scripts/build/gen_strsignal_table.py index b60b23237dc63..33bb74184fc3f 100755 --- a/scripts/build/gen_strsignal_table.py +++ b/scripts/build/gen_strsignal_table.py @@ -15,7 +15,7 @@ def front_matter(): * This file is generated by {__file__} */ -#include +#include ''' @@ -70,7 +70,7 @@ def parse_args(): '--input', dest='input', required=True, - help='input file (e.g. include/zephyr/posix/signal.h)') + help='input file (e.g. include/zephyr/posix/posix_signal.h)') parser.add_argument( '-o', '--output', 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/net/wifi/configs/testcase.yaml b/tests/net/wifi/configs/testcase.yaml index 80ea0ff4b14d5..1ee3cb346ea6c 100644 --- a/tests/net/wifi/configs/testcase.yaml +++ b/tests/net/wifi/configs/testcase.yaml @@ -5,6 +5,7 @@ common: - wifi - net - hostap + - posix platform_allow: - native_sim tests: 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/headers/src/signal_h.c b/tests/posix/headers/src/signal_h.c index 72bf89cd445cc..0b7fea2b66a17 100644 --- a/tests/posix/headers/src/signal_h.c +++ b/tests/posix/headers/src/signal_h.c @@ -6,13 +6,9 @@ #include "_common.h" -#include - -#ifdef CONFIG_POSIX_API +#include #include -#else -#include -#endif +#include /** * @brief existence test for `` @@ -21,18 +17,25 @@ */ ZTEST(posix_headers, test_signal_h) { - typedef void *(*my_sig_handler_t)(int signo); + typedef void (*my_sig_handler_t)(int signo); my_sig_handler_t handler; handler = SIG_DFL; handler = SIG_ERR; handler = SIG_IGN; + +#if defined(CONFIG_POSIX_SIGNALS) /* zassert_not_equal(-1, SIG_HOLD); */ /* not implemented */ +#endif zassert_not_equal((sig_atomic_t)-1, (sig_atomic_t)0); + +#if defined(CONFIG_POSIX_SIGNALS) zassert_not_equal((pid_t)-1, (pid_t)0); +#endif +#if defined(CONFIG_POSIX_REALTIME_SIGNALS) zassert_not_equal(-1, offsetof(struct sigevent, sigev_notify)); zassert_not_equal(-1, offsetof(struct sigevent, sigev_signo)); zassert_not_equal(-1, offsetof(struct sigevent, sigev_value)); @@ -42,7 +45,9 @@ ZTEST(posix_headers, test_signal_h) zassert_not_equal(-1, SIGEV_NONE); zassert_not_equal(-1, SIGEV_SIGNAL); zassert_not_equal(-1, SIGEV_THREAD); +#endif +#if defined(CONFIG_POSIX_SIGNALS) zassert_not_equal(-1, offsetof(union sigval, sival_int)); zassert_not_equal(-1, offsetof(union sigval, sival_ptr)); @@ -55,11 +60,14 @@ ZTEST(posix_headers, test_signal_h) zassert_not_equal(-1, offsetof(struct sigaction, sa_handler)); zassert_not_equal(-1, offsetof(struct sigaction, sa_mask)); zassert_not_equal(-1, offsetof(struct sigaction, sa_flags)); +#if defined(CONFIG_POSIX_REALTIME_SIGNALS) && !defined(CONFIG_NEWLIB_LIBC) zassert_not_equal(-1, offsetof(struct sigaction, sa_sigaction)); +#endif zassert_not_equal(-1, offsetof(siginfo_t, si_signo)); zassert_not_equal(-1, offsetof(siginfo_t, si_code)); zassert_not_equal(-1, offsetof(siginfo_t, si_value)); +#endif /* zassert_not_equal(-1, SA_NOCLDSTOP); */ /* not implemented */ /* zassert_not_equal(-1, SA_ONSTACK); */ /* not implemented */ @@ -164,11 +172,8 @@ ZTEST(posix_headers, test_signal_h) zassert_not_equal(-1, SIGURG); zassert_not_equal(-1, SIGXCPU); zassert_not_equal(-1, SIGXFSZ); - zassert_not_equal(((sigset_t){.sig[0] = 0}).sig[0], ((sigset_t){.sig[0] = -1}).sig[0]); zassert_not_null(abort); - zassert_not_null(alarm); zassert_not_null(kill); - zassert_not_null(pause); zassert_not_null(pthread_sigmask); zassert_not_null(raise); zassert_not_null(sigaction); 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/signals/prj.conf b/tests/posix/signals/prj.conf index 4b2412f20c03c..b5b903f70cb17 100644 --- a/tests/posix/signals/prj.conf +++ b/tests/posix/signals/prj.conf @@ -3,3 +3,7 @@ CONFIG_ZTEST=y CONFIG_POSIX_AEP_CHOICE_PSE51=y CONFIG_POSIX_SIGNALS=y + +CONFIG_DYNAMIC_THREAD=y +CONFIG_THREAD_STACK_INFO=y +CONFIG_DYNAMIC_THREAD_POOL_SIZE=1 diff --git a/tests/posix/signals/src/main.c b/tests/posix/signals/src/main.c index de466c0b24460..680c6fd178e9a 100644 --- a/tests/posix/signals/src/main.c +++ b/tests/posix/signals/src/main.c @@ -12,29 +12,36 @@ #include #include +#define SIGNO_WORD_IDX(_signo) (_signo / BITS_PER_LONG) +#define SIGNO_WORD_BIT(_signo) (_signo & BIT_MASK(LOG2(BITS_PER_LONG))) + +#define SIGSET_NLONGS (sizeof(sigset_t) / sizeof(unsigned long)) + ZTEST(posix_signals, test_sigemptyset) { sigset_t set; + unsigned long *const _set = (unsigned long *)&set; - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - set.sig[i] = -1; + for (int i = 0; i < SIGSET_NLONGS; i++) { + _set[i] = -1; } zassert_ok(sigemptyset(&set)); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], 0u, "set.sig[%d] is not empty: 0x%lx", i, set.sig[i]); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], 0u, "set.sig[%d] is not empty: 0x%lx", i, _set[i]); } } ZTEST(posix_signals, test_sigfillset) { sigset_t set = (sigset_t){0}; + unsigned long *const _set = (unsigned long *)&set; zassert_ok(sigfillset(&set)); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], -1, "set.sig[%d] is not filled: 0x%lx", i, set.sig[i]); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], -1, "set.sig[%d] is not filled: 0x%lx", i, _set[i]); } } @@ -56,46 +63,53 @@ ZTEST(posix_signals, test_sigaddset) { int signo; sigset_t set = (sigset_t){0}; + unsigned long *const _set = (unsigned long *)&set; sigset_t target = (sigset_t){0}; + unsigned long *const _target = (unsigned long *)⌖ signo = SIGHUP; zassert_ok(sigaddset(&set, signo)); - WRITE_BIT(target.sig[0], signo, 1); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + WRITE_BIT(_target[0], signo, 1); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); } signo = SIGSYS; zassert_ok(sigaddset(&set, signo)); - WRITE_BIT(target.sig[0], signo, 1); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + WRITE_BIT(_target[0], signo, 1); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); } signo = SIGRTMIN; /* >=32, will be in the second sig set for 32bit */ zassert_ok(sigaddset(&set, signo)); #ifdef CONFIG_64BIT - WRITE_BIT(target.sig[0], signo, 1); + WRITE_BIT(_target[0], signo, 1); #else /* 32BIT */ - WRITE_BIT(target.sig[1], (signo)-BITS_PER_LONG, 1); + WRITE_BIT(_target[1], (signo)-BITS_PER_LONG, 1); #endif - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); + } + + if (SIGRTMAX >= SIGSET_NLONGS * BITS_PER_LONG) { + /* Some libc's use a sigset_t that is too small for real-time signals */ + return; } signo = SIGRTMAX; zassert_ok(sigaddset(&set, signo)); - WRITE_BIT(target.sig[signo / BITS_PER_LONG], signo % BITS_PER_LONG, 1); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + WRITE_BIT(_target[signo / BITS_PER_LONG], signo % BITS_PER_LONG, 1); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); } } @@ -117,82 +131,106 @@ ZTEST(posix_signals, test_sigdelset) { int signo; sigset_t set = (sigset_t){0}; + unsigned long *const _set = (unsigned long *)&set; sigset_t target = (sigset_t){0}; + unsigned long *const _target = (unsigned long *)⌖ signo = SIGHUP; zassert_ok(sigdelset(&set, signo)); - WRITE_BIT(target.sig[0], signo, 0); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + WRITE_BIT(_target[0], signo, 0); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); } signo = SIGSYS; zassert_ok(sigdelset(&set, signo)); - WRITE_BIT(target.sig[0], signo, 0); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + WRITE_BIT(_target[0], signo, 0); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); } signo = SIGRTMIN; /* >=32, will be in the second sig set for 32bit */ zassert_ok(sigdelset(&set, signo)); #ifdef CONFIG_64BIT - WRITE_BIT(target.sig[0], signo, 0); + WRITE_BIT(_target[0], signo, 0); #else /* 32BIT */ - WRITE_BIT(target.sig[1], (signo)-BITS_PER_LONG, 0); + WRITE_BIT(_target[1], (signo)-BITS_PER_LONG, 0); #endif - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); + } + + if (SIGRTMAX >= SIGSET_NLONGS * BITS_PER_LONG) { + /* For libc's that use a sigset_t that is too small */ + return; + } + + if (SIGRTMAX >= SIGSET_NLONGS * BITS_PER_LONG) { + /* Some libc's use a sigset_t that is too small for real-time signals */ + return; } signo = SIGRTMAX; zassert_ok(sigdelset(&set, signo)); - WRITE_BIT(target.sig[signo / BITS_PER_LONG], signo % BITS_PER_LONG, 0); - for (int i = 0; i < ARRAY_SIZE(set.sig); i++) { - zassert_equal(set.sig[i], target.sig[i], + WRITE_BIT(_target[signo / BITS_PER_LONG], signo % BITS_PER_LONG, 0); + for (int i = 0; i < SIGSET_NLONGS; i++) { + zassert_equal(_set[i], _target[i], "set.sig[%d of %d] has content: %lx, expected %lx", i, - ARRAY_SIZE(set.sig) - 1, set.sig[i], target.sig[i]); + SIGSET_NLONGS - 1, _set[i], _target[i]); } } ZTEST(posix_signals, test_sigismember_oor) { + int res; sigset_t set = {0}; - zassert_equal(sigismember(&set, -1), -1, "rc should be -1"); - zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + res = sigismember(&set, -1); + zexpect_equal(res, -1, "rc should be -1 but is %d", res); + zexpect_equal(errno, EINVAL, "errno should be %s", "EINVAL"); - zassert_equal(sigismember(&set, 0), -1, "rc should be -1"); - zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + res = sigismember(&set, 0); + zexpect_equal(res, -1, "rc should be -1 but is %d", res); + zexpect_equal(errno, EINVAL, "errno should be %s", "EINVAL"); - zassert_equal(sigismember(&set, SIGRTMAX + 1), -1, "rc should be -1"); - zassert_equal(errno, EINVAL, "errno should be %s", "EINVAL"); + res = sigismember(&set, SIGRTMAX + 1); + zexpect_equal(res, -1, "rc should be -1 but is %d", res); + zexpect_equal(errno, EINVAL, "errno should be %s", "EINVAL"); } ZTEST(posix_signals, test_sigismember) { sigset_t set = (sigset_t){0}; + unsigned long *const _set = (unsigned long *)&set; -#ifdef CONFIG_64BIT - set.sig[0] = BIT(SIGHUP) | BIT(SIGSYS) | BIT(SIGRTMIN); -#else /* 32BIT */ - set.sig[0] = BIT(SIGHUP) | BIT(SIGSYS); - set.sig[1] = BIT((SIGRTMIN)-BITS_PER_LONG); -#endif - WRITE_BIT(set.sig[SIGRTMAX / BITS_PER_LONG], SIGRTMAX % BITS_PER_LONG, 1); + _set[0] = BIT(SIGHUP) | BIT(SIGSYS); zassert_equal(sigismember(&set, SIGHUP), 1, "%s expected to be member", "SIGHUP"); zassert_equal(sigismember(&set, SIGSYS), 1, "%s expected to be member", "SIGSYS"); - zassert_equal(sigismember(&set, SIGRTMIN), 1, "%s expected to be member", "SIGRTMIN"); - zassert_equal(sigismember(&set, SIGRTMAX), 1, "%s expected to be member", "SIGRTMAX"); zassert_equal(sigismember(&set, SIGKILL), 0, "%s not expected to be member", "SIGKILL"); zassert_equal(sigismember(&set, SIGTERM), 0, "%s not expected to be member", "SIGTERM"); + + if (SIGRTMAX >= SIGSET_NLONGS * BITS_PER_LONG) { + /* Some libc's use a sigset_t that is too small for real-time signals */ + return; + } + +#ifdef CONFIG_64BIT + _set[0] |= BIT(SIGRTMIN); +#else /* 32BIT */ + _set[1] = BIT((SIGRTMIN)-BITS_PER_LONG); +#endif + + WRITE_BIT(_set[SIGRTMAX / BITS_PER_LONG], SIGRTMAX % BITS_PER_LONG, 1); + zassert_equal(sigismember(&set, SIGRTMIN), 1, "%s expected to be member", "SIGRTMIN"); + zassert_equal(sigismember(&set, SIGRTMAX), 1, "%s expected to be member", "SIGRTMAX"); } ZTEST(posix_signals, test_signal_strsignal) @@ -214,8 +252,10 @@ ZTEST(posix_signals, test_signal_strsignal) zassert_mem_equal(strsignal(SIGHUP), "Hangup", sizeof("Hangup")); zassert_mem_equal(strsignal(SIGSYS), "Bad system call", sizeof("Bad system call")); #else - zassert_mem_equal(strsignal(SIGHUP), "Signal 1", sizeof("Signal 1")); - zassert_mem_equal(strsignal(SIGSYS), "Signal 31", sizeof("Signal 31")); + snprintf(buf, sizeof(buf), "Signal %d", SIGHUP); + zassert_mem_equal(strsignal(SIGHUP), buf, strlen(buf)); + snprintf(buf, sizeof(buf), "Signal %d", SIGSYS); + zassert_mem_equal(strsignal(SIGSYS), buf, strlen(buf)); #endif } @@ -320,14 +360,4 @@ ZTEST(posix_signals, test_sigprocmask) } } -static void before(void *arg) -{ - ARG_UNUSED(arg); - - if (!IS_ENABLED(CONFIG_DYNAMIC_THREAD)) { - /* skip redundant testing if there is no thread pool / heap allocation */ - ztest_test_skip(); - } -} - -ZTEST_SUITE(posix_signals, NULL, NULL, before, NULL, NULL); +ZTEST_SUITE(posix_signals, NULL, NULL, NULL, NULL, NULL); diff --git a/tests/posix/signals/testcase.yaml b/tests/posix/signals/testcase.yaml index de3d7166e223b..94a7579952878 100644 --- a/tests/posix/signals/testcase.yaml +++ b/tests/posix/signals/testcase.yaml @@ -7,27 +7,49 @@ common: platform_key: - arch - simulation - integration_platforms: - - qemu_riscv64 min_flash: 64 min_ram: 32 tests: - portability.posix.signals: {} + portability.posix.signals: + integration_platforms: + - qemu_riscv64 portability.posix.signals.minimal: + integration_platforms: + - qemu_riscv64 extra_configs: - CONFIG_MINIMAL_LIBC=y portability.posix.signals.newlib: + integration_platforms: + - qemu_riscv64 filter: TOOLCHAIN_HAS_NEWLIB == 1 extra_configs: - CONFIG_NEWLIB_LIBC=y portability.posix.signals.picolibc: + integration_platforms: + - qemu_riscv64 tags: picolibc filter: CONFIG_PICOLIBC_SUPPORTED extra_configs: - CONFIG_PICOLIBC=y portability.posix.signals.strginal_no_desc: + integration_platforms: + - qemu_riscv64 extra_configs: - CONFIG_POSIX_SIGNAL_STRING_DESC=n portability.posix.signals.big_nsig: + integration_platforms: + - qemu_riscv64 extra_configs: - CONFIG_POSIX_RTSIG_MAX=1024 + portability.posix.signals.native: + platform_allow: + - native_sim + - native_sim/native/64 + integration_platforms: + - native_sim + - native_sim/native/64 + integration_toolchains: + - host + - llvm + extra_configs: + - CONFIG_PICOLIBC=y diff --git a/tests/posix/timers/src/timer.c b/tests/posix/timers/src/timer.c index 1d4936d6a4be6..0f325bfb933d3 100644 --- a/tests/posix/timers/src/timer.c +++ b/tests/posix/timers/src/timer.c @@ -4,6 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include #include diff --git a/west.yml b/west.yml index 7b89aeaf6f871..475a4bda25ccf 100644 --- a/west.yml +++ b/west.yml @@ -286,7 +286,7 @@ manifest: - hal - name: hostap path: modules/lib/hostap - revision: 0798bf0faff40919bd577f1c8f75a2f9baae6299 + revision: 61182a45fecafaa0f20e98ca7f862d26fbf65293 - name: liblc3 revision: 48bbd3eacd36e99a57317a0a4867002e0b09e183 path: modules/lib/liblc3