Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

posix: signal: include_next to get the libc signal() decl #60948

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/zephyr/posix/posix_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ typedef uint32_t clockid_t;
typedef unsigned long timer_t;
#endif

#ifdef CONFIG_PTHREAD_IPC
/* Thread attributes */
struct pthread_attr {
int priority;
Expand Down Expand Up @@ -101,8 +100,6 @@ typedef struct pthread_rwlock_obj {
k_tid_t wr_owner;
} pthread_rwlock_t;

#endif /* CONFIG_PTHREAD_IPC */

#ifdef __cplusplus
}
#endif
Expand Down
15 changes: 10 additions & 5 deletions include/zephyr/posix/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@

#include "posix_types.h"

#ifdef __cplusplus
extern "C" {
#endif
#define SIG_DFL ((sighandler_t)0)
#define SIG_ERR ((sighandler_t)1)
#define SIG_IGN ((sighandler_t)-1)

#ifdef CONFIG_POSIX_SIGNAL
#define SIGHUP 1 /**< Hangup */
#define SIGINT 2 /**< Interrupt */
#define SIGQUIT 3 /**< Quit */
Expand Down Expand Up @@ -51,6 +50,10 @@ extern "C" {

BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= 0);

#ifdef __cplusplus
extern "C" {
#endif

typedef struct {
unsigned long sig[DIV_ROUND_UP(_NSIG, BITS_PER_LONG)];
} sigset_t;
Expand All @@ -61,7 +64,6 @@ 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);
#endif /* CONFIG_POSIX_SIGNAL */

#ifndef SIGEV_NONE
#define SIGEV_NONE 1
Expand Down Expand Up @@ -92,6 +94,9 @@ typedef struct sigevent {
#endif
} sigevent;

typedef void (*sighandler_t)(int signo);
sighandler_t signal(int signum, sighandler_t handler);

#ifdef __cplusplus
}
#endif
Expand Down
1 change: 1 addition & 0 deletions lib/libc/minimal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ set(STRERROR_TABLE_H ${GEN_DIR}/libc/minimal/strerror_table.h)
zephyr_library_cc_option(-fno-builtin)

zephyr_library_sources(
source/signal/signal.c
source/stdlib/atoi.c
source/stdlib/strtol.c
source/stdlib/strtoul.c
Expand Down
29 changes: 29 additions & 0 deletions lib/libc/minimal/include/signal.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_
#define ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_

#define SIG_DFL ((sighandler_t)0)
#define SIG_ERR ((sighandler_t)1)
#define SIG_IGN ((sighandler_t)-1)

#ifdef __cplusplus
extern "C" {
#endif

typedef int sig_atomic_t; /* Atomic entity type (ANSI) */

/* Note: sighandler_t is a gnu-ism, but it simplifies the declaration below */
typedef void (*sighandler_t)(int signo);

sighandler_t signal(int signum, sighandler_t handler);
cfriedt marked this conversation as resolved.
Show resolved Hide resolved

#ifdef __cplusplus
}
#endif

#endif /* ZEPHYR_LIB_LIBC_MINIMAL_INCLUDE_SIGNAL_H_ */
12 changes: 12 additions & 0 deletions lib/libc/minimal/source/signal/signal.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <signal.h>

sighandler_t signal(int signum, sighandler_t handler)
{
return SIG_DFL;
}
3 changes: 2 additions & 1 deletion lib/posix/Kconfig.signal
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,15 @@ config POSIX_SIGNAL
help
Enable support for POSIX signal APIs.

if POSIX_SIGNAL
config POSIX_RTSIG_MAX
int "Maximum number of realtime signals"
default 31
help
Define the maximum number of realtime signals (RTSIG_MAX).
The range of realtime signals is [SIGRTMIN .. (SIGRTMIN+RTSIG_MAX)]

if POSIX_SIGNAL

config POSIX_SIGNAL_STRING_DESC
bool "Use full description for the strsignal API"
default y
Expand Down
4 changes: 4 additions & 0 deletions lib/posix/Kconfig.timer
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ type = timer_t
type-function = timer_create
source "lib/posix/Kconfig.template.pooled_type"

config POSIX_TIMER
bool
imply POSIX_SIGNAL

config TIMER_CREATE_WAIT
int "Time to wait for timer availability (in msec) in POSIX application"
default 100
Expand Down
2 changes: 2 additions & 0 deletions lib/posix/signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#include <zephyr/posix/signal.h>

BUILD_ASSERT(CONFIG_POSIX_RTSIG_MAX >= 0);

#define SIGNO_WORD_IDX(_signo) (signo / BITS_PER_LONG)
#define SIGNO_WORD_BIT(_signo) (signo & BIT_MASK(LOG2(BITS_PER_LONG)))

Expand Down
20 changes: 20 additions & 0 deletions tests/lib/c_lib/src/test_signal_decl.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2023 Meta
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <signal.h>

#include <zephyr/ztest.h>

ZTEST(test_c_lib, test_signal_decl)
{
/*
* Even though the use of the ANSI-C function "signal()" is not yet
* supported in Zephyr, some users depend on it being declared (i.e.
* without CONFIG_POSIX_API=y and with with CONFIG_POSIX_SIGNAL=n).
*/

zassert_not_null(signal);
}
1 change: 1 addition & 0 deletions tests/posix/headers/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ CONFIG_POSIX_CLOCK=y
CONFIG_POSIX_MQUEUE=y
CONFIG_EVENTFD=y
CONFIG_GETOPT=y
CONFIG_POSIX_SIGNAL=y
60 changes: 30 additions & 30 deletions tests/posix/headers/src/signal_h.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@
*/
ZTEST(posix_headers, test_signal_h)
{
/* part of ANSI C */
zassert_not_null(signal);
/* part of ISO C */
zassert_not_equal(sizeof(sig_atomic_t), 0);

#ifdef CONFIG_POSIX_API
/* zassert_not_equal(-1, SIG_DFL); */ /* not implemented */
/* zassert_not_equal(-1, SIG_ERR); */ /* not implemented */
/* zassert_not_equal(-1, SIG_HOLD); */ /* not implemented */
/* zassert_not_equal(-1, SIG_IGN); */ /* not implemented */

/* zassert_not_equal((sig_atomic_t)-1, (sig_atomic_t)0); */ /* not implemented */
/* zassert_not_equal((pid_t)-1, (pid_t)0); */ /* not implemented */

zassert_not_equal(-1, offsetof(struct sigevent, sigev_notify));
Expand Down Expand Up @@ -130,7 +135,6 @@ ZTEST(posix_headers, test_signal_h)
/* zassert_not_equal(-1, SI_ASYNCIO); */ /* not implemented */
/* zassert_not_equal(-1, SI_MESGQ); */ /* not implemented */

#ifdef CONFIG_POSIX_SIGNAL
zassert_true(SIGRTMIN >= 0);
zassert_true(SIGRTMAX >= SIGRTMIN);
zassert_not_equal(-1, SIGABRT);
Expand All @@ -157,38 +161,34 @@ 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_equal(sizeof(sigset_t), 0);
zassert_not_null(sigemptyset);
zassert_not_null(sigfillset);
zassert_not_null(sigaddset);
zassert_not_null(sigdelset);
zassert_not_null(sigismember);
zassert_not_null(strsignal);
#endif /* CONFIG_POSIX_SIGNAL */

if (IS_ENABLED(CONFIG_POSIX_API)) {
/* zassert_not_null(kill); */ /* not implemented */
/* zassert_not_null(killpg); */ /* not implemented */
/* zassert_not_null(psiginfo); */ /* not implemented */
/* zassert_not_null(psignal); */ /* not implemented */
/* zassert_not_null(pthread_kill); */ /* not implemented */
/* zassert_not_null(pthread_sigmask); */ /* not implemented */
/* zassert_not_null(raise); */ /* not implemented */
/* zassert_not_null(sigaction); */ /* not implemented */
/* zassert_not_null(sigaltstack); */ /* not implemented */
/* zassert_not_null(sighold); */ /* not implemented */
/* zassert_not_null(sigignore); */ /* not implemented */
/* zassert_not_null(siginterrupt); */ /* not implemented */
/* zassert_not_null(signal); */ /* not implemented */
/* zassert_not_null(sigpause); */ /* not implemented */
/* zassert_not_null(sigpending); */ /* not implemented */
/* zassert_not_null(sigprocmask); */ /* not implemented */
/* zassert_not_null(sigqueue); */ /* not implemented */
/* zassert_not_null(sigrelse); */ /* not implemented */
/* zassert_not_null(sigset); */ /* not implemented */
/* zassert_not_null(sigsuspend); */ /* not implemented */
/* zassert_not_null(sigtimedwait); */ /* not implemented */
/* zassert_not_null(sigwait); */ /* not implemented */
/* zassert_not_null(sigwaitinfo); */ /* not implemented */
}
/* zassert_not_null(kill); */ /* not implemented */
/* zassert_not_null(killpg); */ /* not implemented */
/* zassert_not_null(psiginfo); */ /* not implemented */
/* zassert_not_null(psignal); */ /* not implemented */
/* zassert_not_null(pthread_kill); */ /* not implemented */
/* zassert_not_null(pthread_sigmask); */ /* not implemented */
/* zassert_not_null(raise); */ /* not implemented */
/* zassert_not_null(sigaction); */ /* not implemented */
/* zassert_not_null(sigaltstack); */ /* not implemented */
/* zassert_not_null(sighold); */ /* not implemented */
/* zassert_not_null(sigignore); */ /* not implemented */
/* zassert_not_null(siginterrupt); */ /* not implemented */
/* zassert_not_null(sigpause); */ /* not implemented */
/* zassert_not_null(sigpending); */ /* not implemented */
/* zassert_not_null(sigprocmask); */ /* not implemented */
/* zassert_not_null(sigqueue); */ /* not implemented */
/* zassert_not_null(sigrelse); */ /* not implemented */
/* zassert_not_null(sigset); */ /* not implemented */
/* zassert_not_null(sigsuspend); */ /* not implemented */
/* zassert_not_null(sigtimedwait); */ /* not implemented */
/* zassert_not_null(sigwait); */ /* not implemented */
/* zassert_not_null(sigwaitinfo); */ /* not implemented */
#endif
}
Loading