Skip to content

Commit

Permalink
posix: add stubs for signal.h functions that need process support
Browse files Browse the repository at this point in the history
Since Zephyr itself does not currently support processes, but
conformant applications should still be able to link, add stubs
for the remaining POSIX functions in the POSIX_SIGNALS Option
Group.

The POSIX_SIGNALS Option Group is required for PSE51, PSE52,
PSE53, PSE54, and likely many other POSIX Subprofiles.

Signed-off-by: Chris Friedt <cfriedt@tenstorrent.com>
  • Loading branch information
cfriedt authored and nashif committed Jun 27, 2024
1 parent be086f1 commit b2243af
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 0 deletions.
32 changes: 32 additions & 0 deletions include/zephyr/posix/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lib/libc/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 7 additions & 0 deletions lib/posix/options/Kconfig.signal
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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"
59 changes: 59 additions & 0 deletions lib/posix/options/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit b2243af

Please sign in to comment.