diff --git a/include/zephyr/posix/signal.h b/include/zephyr/posix/signal.h index 165050f2ded9..7a1efdbd449c 100644 --- a/include/zephyr/posix/signal.h +++ b/include/zephyr/posix/signal.h @@ -77,6 +77,16 @@ typedef struct { #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 { @@ -92,12 +102,34 @@ struct sigevent { 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); +}; + +unsigned int alarm(unsigned int seconds); +int kill(pid_t pid, int sig); +int pause(void); +int raise(int signo); +int sigaction(int sig, const struct sigaction *ZRESTRICT act, struct sigaction *ZRESTRICT oact); +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); +void (*signal(int signo, void (*)(int signo)))(int signo); 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); diff --git a/lib/libc/Kconfig b/lib/libc/Kconfig index 6607f62c521f..7a509fb06e59 100644 --- a/lib/libc/Kconfig +++ b/lib/libc/Kconfig @@ -105,6 +105,7 @@ config NEWLIB_LIBC imply POSIX_FD_MGMT_ALIAS_LSEEK imply POSIX_FILE_SYSTEM_ALIAS_FSTAT imply POSIX_MULTI_PROCESS_ALIAS_GETPID + imply POSIX_SIGNALS_ALIAS_KILL help Build with newlib library. The newlib library is expected to be part of the SDK in this case. diff --git a/lib/posix/options/Kconfig.signal b/lib/posix/options/Kconfig.signal index 4507302e3f32..1e84a55de598 100644 --- a/lib/posix/options/Kconfig.signal +++ b/lib/posix/options/Kconfig.signal @@ -24,6 +24,7 @@ endif # POSIX_REALTIME_SIGNALS config POSIX_SIGNALS bool "POSIX signals [EXPERIMENTAL]" select EXPERIMENTAL + select POSIX_MULTI_PROCESS help Enable support for POSIX signals. @@ -36,6 +37,12 @@ config POSIX_SIGNAL_STRING_DESC Use full description for the strsignal API. Will use 256 bytes of ROM. +# These options are intended to be used for compatibility with external POSIX +# implementations such as those in Newlib or Picolibc. + +config POSIX_SIGNALS_ALIAS_KILL + bool + endif endmenu # "Signal support" diff --git a/lib/posix/options/signal.c b/lib/posix/options/signal.c index cb282f69bdc8..84171fde0f07 100644 --- a/lib/posix/options/signal.c +++ b/lib/posix/options/signal.c @@ -118,3 +118,62 @@ int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset errno = ENOSYS; return -1; } + +/* + * The functions below are provided so that conformant POSIX applications and libraries can still + * link. + */ + +unsigned int alarm(unsigned int seconds) +{ + ARG_UNUSED(seconds); + return 0; +} + +int kill(pid_t pid, int sig) +{ + ARG_UNUSED(pid); + ARG_UNUSED(sig); + errno = ENOSYS; + return -1; +} +#ifdef CONFIG_POSIX_SIGNALS_ALIAS_KILL +FUNC_ALIAS(kill, _kill, int); +#endif /* CONFIG_POSIX_SIGNALS_ALIAS_KILL */ + +int pause(void) +{ + errno = ENOSYS; + return -1; +} + +int sigaction(int sig, const struct sigaction *ZRESTRICT act, struct sigaction *ZRESTRICT oact) +{ + ARG_UNUSED(sig); + ARG_UNUSED(act); + ARG_UNUSED(oact); + errno = ENOSYS; + return -1; +} + +int sigpending(sigset_t *set) +{ + ARG_UNUSED(set); + errno = ENOSYS; + return -1; +} + +int sigsuspend(const sigset_t *sigmask) +{ + ARG_UNUSED(sigmask); + errno = ENOSYS; + return -1; +} + +int sigwait(const sigset_t *ZRESTRICT set, int *ZRESTRICT sig) +{ + ARG_UNUSED(set); + ARG_UNUSED(sig); + errno = ENOSYS; + return -1; +}