Skip to content

Commit b2243af

Browse files
cfriedtnashif
authored andcommitted
posix: add stubs for signal.h functions that need process support
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 <[email protected]>
1 parent be086f1 commit b2243af

File tree

4 files changed

+99
-0
lines changed

4 files changed

+99
-0
lines changed

include/zephyr/posix/signal.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ typedef struct {
7777
#define SIG_UNBLOCK 2
7878
#endif
7979

80+
#define SIG_DFL ((void *)0)
81+
#define SIG_IGN ((void *)1)
82+
#define SIG_ERR ((void *)-1)
83+
84+
#define SI_USER 1
85+
#define SI_QUEUE 2
86+
#define SI_TIMER 3
87+
#define SI_ASYNCIO 4
88+
#define SI_MESGQ 5
89+
8090
typedef int sig_atomic_t; /* Atomic entity type (ANSI) */
8191

8292
union sigval {
@@ -92,12 +102,34 @@ struct sigevent {
92102
int sigev_signo;
93103
};
94104

105+
typedef struct {
106+
int si_signo;
107+
int si_code;
108+
union sigval si_value;
109+
} siginfo_t;
110+
111+
struct sigaction {
112+
void (*sa_handler)(int signno);
113+
sigset_t sa_mask;
114+
int sa_flags;
115+
void (*sa_sigaction)(int signo, siginfo_t *info, void *context);
116+
};
117+
118+
unsigned int alarm(unsigned int seconds);
119+
int kill(pid_t pid, int sig);
120+
int pause(void);
121+
int raise(int signo);
122+
int sigaction(int sig, const struct sigaction *ZRESTRICT act, struct sigaction *ZRESTRICT oact);
123+
int sigpending(sigset_t *set);
124+
int sigsuspend(const sigset_t *sigmask);
125+
int sigwait(const sigset_t *ZRESTRICT set, int *ZRESTRICT signo);
95126
char *strsignal(int signum);
96127
int sigemptyset(sigset_t *set);
97128
int sigfillset(sigset_t *set);
98129
int sigaddset(sigset_t *set, int signo);
99130
int sigdelset(sigset_t *set, int signo);
100131
int sigismember(const sigset_t *set, int signo);
132+
void (*signal(int signo, void (*)(int signo)))(int signo);
101133
int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset);
102134

103135
int pthread_sigmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset);

lib/libc/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ config NEWLIB_LIBC
105105
imply POSIX_FD_MGMT_ALIAS_LSEEK
106106
imply POSIX_FILE_SYSTEM_ALIAS_FSTAT
107107
imply POSIX_MULTI_PROCESS_ALIAS_GETPID
108+
imply POSIX_SIGNALS_ALIAS_KILL
108109
help
109110
Build with newlib library. The newlib library is expected to be
110111
part of the SDK in this case.

lib/posix/options/Kconfig.signal

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ endif # POSIX_REALTIME_SIGNALS
2424
config POSIX_SIGNALS
2525
bool "POSIX signals [EXPERIMENTAL]"
2626
select EXPERIMENTAL
27+
select POSIX_MULTI_PROCESS
2728
help
2829
Enable support for POSIX signals.
2930

@@ -36,6 +37,12 @@ config POSIX_SIGNAL_STRING_DESC
3637
Use full description for the strsignal API.
3738
Will use 256 bytes of ROM.
3839

40+
# These options are intended to be used for compatibility with external POSIX
41+
# implementations such as those in Newlib or Picolibc.
42+
43+
config POSIX_SIGNALS_ALIAS_KILL
44+
bool
45+
3946
endif
4047

4148
endmenu # "Signal support"

lib/posix/options/signal.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,3 +118,62 @@ int sigprocmask(int how, const sigset_t *ZRESTRICT set, sigset_t *ZRESTRICT oset
118118
errno = ENOSYS;
119119
return -1;
120120
}
121+
122+
/*
123+
* The functions below are provided so that conformant POSIX applications and libraries can still
124+
* link.
125+
*/
126+
127+
unsigned int alarm(unsigned int seconds)
128+
{
129+
ARG_UNUSED(seconds);
130+
return 0;
131+
}
132+
133+
int kill(pid_t pid, int sig)
134+
{
135+
ARG_UNUSED(pid);
136+
ARG_UNUSED(sig);
137+
errno = ENOSYS;
138+
return -1;
139+
}
140+
#ifdef CONFIG_POSIX_SIGNALS_ALIAS_KILL
141+
FUNC_ALIAS(kill, _kill, int);
142+
#endif /* CONFIG_POSIX_SIGNALS_ALIAS_KILL */
143+
144+
int pause(void)
145+
{
146+
errno = ENOSYS;
147+
return -1;
148+
}
149+
150+
int sigaction(int sig, const struct sigaction *ZRESTRICT act, struct sigaction *ZRESTRICT oact)
151+
{
152+
ARG_UNUSED(sig);
153+
ARG_UNUSED(act);
154+
ARG_UNUSED(oact);
155+
errno = ENOSYS;
156+
return -1;
157+
}
158+
159+
int sigpending(sigset_t *set)
160+
{
161+
ARG_UNUSED(set);
162+
errno = ENOSYS;
163+
return -1;
164+
}
165+
166+
int sigsuspend(const sigset_t *sigmask)
167+
{
168+
ARG_UNUSED(sigmask);
169+
errno = ENOSYS;
170+
return -1;
171+
}
172+
173+
int sigwait(const sigset_t *ZRESTRICT set, int *ZRESTRICT sig)
174+
{
175+
ARG_UNUSED(set);
176+
ARG_UNUSED(sig);
177+
errno = ENOSYS;
178+
return -1;
179+
}

0 commit comments

Comments
 (0)