diff --git a/components/dfs/include/dfs_select.h b/components/dfs/include/dfs_select.h index 458691df204a6e42908e09d5b55cee7a9fd5200c..e0572c5059f401948c4b14aa11b34b43b101f13d 100644 --- a/components/dfs/include/dfs_select.h +++ b/components/dfs/include/dfs_select.h @@ -10,7 +10,7 @@ #ifndef DFS_SELECT_H__ #define DFS_SELECT_H__ -#include +#include #ifdef __cplusplus extern "C" { diff --git a/components/libc/aio/posix_aio.c b/components/libc/aio/posix_aio.c index 66f15e4c578d57d04bbbb9147dd5b9ab9e4546d7..66cced86872ef77ab499653c8549b57cae8d76af 100644 --- a/components/libc/aio/posix_aio.c +++ b/components/libc/aio/posix_aio.c @@ -9,14 +9,8 @@ */ #include -#include - #include -#include -#include - #include - #include "posix_aio.h" struct rt_workqueue* aio_queue = NULL; diff --git a/components/libc/aio/posix_aio.h b/components/libc/aio/posix_aio.h index de117385153fb07193ae5a9d291219ee5cd55161..4e25e1d15b4f719d8768995462b7512f35122efc 100644 --- a/components/libc/aio/posix_aio.h +++ b/components/libc/aio/posix_aio.h @@ -11,6 +11,10 @@ #ifndef POSIX_AIO_H__ #define POSIX_AIO_H__ +#include +#include +#include + struct aiocb { int aio_fildes; /* File descriptor. */ diff --git a/components/libc/compilers/common/none-gcc/sys/errno.h b/components/libc/compilers/common/none-gcc/sys/errno.h index ad3614024ddf2ea92f764931a729ce784c352731..ff1abca3875f641a3a674c253c390de650af1933 100644 --- a/components/libc/compilers/common/none-gcc/sys/errno.h +++ b/components/libc/compilers/common/none-gcc/sys/errno.h @@ -7,8 +7,8 @@ * Date Author Notes * 2021-05-22 Meco Man The first version. */ -#ifndef _SYS_ERRNO_H -#define _SYS_ERRNO_H +#ifndef __SYS_ERRNO_H__ +#define __SYS_ERRNO_H__ #if defined(__ARMCC_VERSION) /* diff --git a/components/libc/compilers/common/none-gcc/sys/stat.h b/components/libc/compilers/common/none-gcc/sys/stat.h index c4b42083c4933ee4f0a12120c631fa8107fc4caf..c8f65df435ba02a1bdd5b7e3e00fdd0782633855 100644 --- a/components/libc/compilers/common/none-gcc/sys/stat.h +++ b/components/libc/compilers/common/none-gcc/sys/stat.h @@ -6,3 +6,8 @@ * Change Logs: * Date Author Notes */ + + #ifndef __SYS_STAT_H__ + #define __SYS_STAT_H__ + + #endif diff --git a/components/libc/compilers/common/none-gcc/sys/types.h b/components/libc/compilers/common/none-gcc/sys/types.h index 7222326a2ae203c2acb65cd250a823967b722a9b..e9f44f776230b5b9a783bc311a83125a3f4dffb2 100644 --- a/components/libc/compilers/common/none-gcc/sys/types.h +++ b/components/libc/compilers/common/none-gcc/sys/types.h @@ -8,8 +8,8 @@ * 2020-09-05 Meco Man fix bugs * 2020-12-16 Meco Man add useconds_t */ -#ifndef __TYPES_H__ -#define __TYPES_H__ +#ifndef __SYS_TYPES_H__ +#define __SYS_TYPES_H__ #include diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h index 2f01f660b3c731b9fee450266bd3a1a041a80661..ea2d674b0f0ba04daf1b4a4497e96136e4a9f7c0 100644 --- a/components/libc/compilers/common/none-gcc/sys/unistd.h +++ b/components/libc/compilers/common/none-gcc/sys/unistd.h @@ -7,8 +7,8 @@ * Date Author Notes * 2020-12-16 Meco Man add usleep */ -#ifndef _SYS_UNISTD_H -#define _SYS_UNISTD_H +#ifndef __SYS_UNISTD_H__ +#define __SYS_UNISTD_H__ #include #include "types.h" diff --git a/components/libc/compilers/common/sys/select.h b/components/libc/compilers/common/sys/select.h new file mode 100644 index 0000000000000000000000000000000000000000..db42b6ebccd9485a9b65c2a101fdaab0182b2e8a --- /dev/null +++ b/components/libc/compilers/common/sys/select.h @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-07-21 Meco Man The first version + */ + +#ifndef __SYS_SELECT_H__ +#define __SYS_SELECT_H__ + +#include +#include + +#ifndef FD_SETSIZE +#define FD_SETSIZE 32 +#endif + +#ifdef SAL_USING_POSIX +#ifdef FD_SETSIZE +#undef FD_SETSIZE +#endif +#define FD_SETSIZE DFS_FD_MAX +#endif /* SAL_USING_POSIX */ + +#define NBBY 8 /* number of bits in a byte */ + +typedef long fd_mask; + +#define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ +#ifndef howmany +#define howmany(x,y) (((x)+((y)-1))/(y)) +#endif + +#ifndef _SYS_TYPES_FD_SET /* MIPS */ +typedef struct _types_fd_set { + fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; +} _types_fd_set; +#define fd_set _types_fd_set + +#define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) +#define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) +#define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) +#define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) +#endif /* _SYS_TYPES_FD_SET */ + +#endif /* __SYS_SELECT_H__ */ diff --git a/include/libc/libc_signal.h b/components/libc/compilers/common/sys/signal.h similarity index 61% rename from include/libc/libc_signal.h rename to components/libc/compilers/common/sys/signal.h index 1fb81946437dbbfd8fb4117235fd2f8f5ab60cd1..9787958a3740d71f23066870dbd9aa9d661aa9fc 100644 --- a/include/libc/libc_signal.h +++ b/components/libc/compilers/common/sys/signal.h @@ -6,33 +6,27 @@ * Change Logs: * Date Author Notes * 2017-09-12 Bernard The first version + * 2021-07-21 Meco Man move to libc/common */ -#ifndef LIBC_SIGNAL_H__ -#define LIBC_SIGNAL_H__ +#ifndef __SYS_SIGNAL_H__ +#define __SYS_SIGNAL_H__ #ifdef __cplusplus extern "C" { #endif #include -#ifdef HAVE_CCONFIG_H -#include -#endif -#ifndef HAVE_SIGVAL /* Signal Generation and Delivery, P1003.1b-1993, p. 63 NOTE: P1003.1c/D10, p. 34 adds sigev_notify_function and sigev_notify_attributes to the sigevent structure. */ - union sigval { int sival_int; /* Integer signal value */ void *sival_ptr; /* Pointer signal value */ }; -#endif -#ifndef HAVE_SIGEVENT struct sigevent { int sigev_notify; /* Notification type */ @@ -42,9 +36,7 @@ struct sigevent /* Notification function */ void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */ }; -#endif -#ifndef HAVE_SIGINFO struct siginfo { uint16_t si_signo; @@ -53,26 +45,37 @@ struct siginfo union sigval si_value; }; typedef struct siginfo siginfo_t; -#endif #define SI_USER 0x01 /* Signal sent by kill(). */ #define SI_QUEUE 0x02 /* Signal sent by sigqueue(). */ -#define SI_TIMER 0x03 /* Signal generated by expiration of a - timer set by timer_settime(). */ -#define SI_ASYNCIO 0x04 /* Signal generated by completion of an - asynchronous I/O request. */ -#define SI_MESGQ 0x05 /* Signal generated by arrival of a - message on an empty message queue. */ - -#if !defined(RT_USING_NEWLIB) +#define SI_TIMER 0x03 /* Signal generated by expiration of a timer set by timer_settime(). */ +#define SI_ASYNCIO 0x04 /* Signal generated by completion of an asynchronous I/O request. */ +#define SI_MESGQ 0x05 /* Signal generated by arrival of a message on an empty message queue. */ + typedef void (*_sig_func_ptr)(int); typedef unsigned long sigset_t; -#endif -#include +struct sigaction +{ + _sig_func_ptr sa_handler; + sigset_t sa_mask; + int sa_flags; +}; -#ifdef __ARMCC_VERSION +#define SIG_SETMASK 0 /* set mask with sigprocmask() */ +#define SIG_BLOCK 1 /* set of signals to block */ +#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ +#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) +#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) +#define sigemptyset(what) (*(what) = 0, 0) +#define sigfillset(what) (*(what) = ~(0), 0) +#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) + +int sigprocmask (int how, const sigset_t *set, sigset_t *oset); +int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); + +#ifdef __ARMCC_VERSION #define SIGHUP 1 /* #define SIGINT 2 */ #define SIGQUIT 3 @@ -103,28 +106,9 @@ typedef unsigned long sigset_t; #define SIGRTMAX 31 #define NSIG 32 -#define SIG_SETMASK 0 /* set mask with sigprocmask() */ -#define SIG_BLOCK 1 /* set of signals to block */ -#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ - -struct sigaction -{ - _sig_func_ptr sa_handler; - sigset_t sa_mask; - int sa_flags; -}; - -#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) -#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) -#define sigemptyset(what) (*(what) = 0, 0) -#define sigfillset(what) (*(what) = ~(0), 0) -#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) - -int sigprocmask (int how, const sigset_t *set, sigset_t *oset); -int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); +#include #elif defined(__IAR_SYSTEMS_ICC__) - #define SIGHUP 1 #define SIGINT 2 #define SIGQUIT 3 @@ -155,25 +139,51 @@ int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact) #define SIGRTMAX 31 #define NSIG 32 -#define SIG_SETMASK 0 /* set mask with sigprocmask() */ -#define SIG_BLOCK 1 /* set of signals to block */ -#define SIG_UNBLOCK 2 /* set of signals to, well, unblock */ - -struct sigaction -{ - _sig_func_ptr sa_handler; - sigset_t sa_mask; - int sa_flags; -}; +#include -#define sigaddset(what,sig) (*(what) |= (1<<(sig)), 0) -#define sigdelset(what,sig) (*(what) &= ~(1<<(sig)), 0) -#define sigemptyset(what) (*(what) = 0, 0) -#define sigfillset(what) (*(what) = ~(0), 0) -#define sigismember(what,sig) (((*(what)) & (1<<(sig))) != 0) +#elif defined(__GNUC__) +#define SIGHUP 1 /* hangup */ +#define SIGINT 2 /* interrupt */ +#define SIGQUIT 3 /* quit */ +#define SIGILL 4 /* illegal instruction (not reset when caught) */ +#define SIGTRAP 5 /* trace trap (not reset when caught) */ +#define SIGIOT 6 /* IOT instruction */ +#define SIGABRT 6 /* used by abort, replace SIGIOT in the future */ +#define SIGEMT 7 /* EMT instruction */ +#define SIGFPE 8 /* floating point exception */ +#define SIGKILL 9 /* kill (cannot be caught or ignored) */ +#define SIGBUS 10 /* bus error */ +#define SIGSEGV 11 /* segmentation violation */ +#define SIGSYS 12 /* bad argument to system call */ +#define SIGPIPE 13 /* write on a pipe with no one to read it */ +#define SIGALRM 14 /* alarm clock */ +#define SIGTERM 15 /* software termination signal from kill */ +#define SIGURG 16 /* urgent condition on IO channel */ +#define SIGSTOP 17 /* sendable stop signal not from tty */ +#define SIGTSTP 18 /* stop signal from tty */ +#define SIGCONT 19 /* continue a stopped process */ +#define SIGCHLD 20 /* to parent on child stop or exit */ +#define SIGCLD 20 /* System V name for SIGCHLD */ +#define SIGTTIN 21 /* to readers pgrp upon background tty read */ +#define SIGTTOU 22 /* like TTIN for output if (tp->t_local<OSTOP) */ +#define SIGIO 23 /* input/output possible signal */ +#define SIGPOLL SIGIO /* System V name for SIGIO */ +#define SIGXCPU 24 /* exceeded CPU time limit */ +#define SIGXFSZ 25 /* exceeded file size limit */ +#define SIGVTALRM 26 /* virtual time alarm */ +#define SIGPROF 27 /* profiling time alarm */ +#define SIGWINCH 28 /* window changed */ +#define SIGLOST 29 /* resource lost (eg, record-lock lost) */ +#define SIGUSR1 30 /* user defined signal 1 */ +#define SIGUSR2 31 /* user defined signal 2 */ +#define NSIG 32 /* signal 0 implied */ + +#ifndef _SIGNAL_H_ +/* Some applications take advantage of the fact that + * and are equivalent in glibc. Allow for that here. */ +#include +#endif -int sigprocmask (int how, const sigset_t *set, sigset_t *oset); -int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact); #endif #ifdef __cplusplus diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c index 1af0ab2919d9b7c7cd9c9abac68cff50f808ff09..a59c7a445b43782daa306a0bea8962c877ce4a39 100644 --- a/components/libc/pthreads/mqueue.c +++ b/components/libc/pthreads/mqueue.c @@ -8,6 +8,7 @@ */ #include +#include #include "mqueue.h" #include "pthread_internal.h" diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c index 1cb561d428ada9c3b6f68955e85adfac93c9d7f8..45646f63ea5f6ae7317f4d962e98c29cd98bcfca 100644 --- a/components/libc/signal/posix_signal.c +++ b/components/libc/signal/posix_signal.c @@ -7,6 +7,7 @@ * Date Author Notes * 2017/10/1 Bernard The first version */ + #include #include @@ -14,6 +15,7 @@ #include #include "posix_signal.h" + #define sig_valid(sig_no) (sig_no >= 0 && sig_no < RT_SIG_MAX) void (*signal(int sig, void (*func)(int))) (int) @@ -79,13 +81,10 @@ int sigtimedwait(const sigset_t *set, siginfo_t *info, int ret = 0; int tick = RT_WAITING_FOREVER; -#ifdef RT_USING_PTHREADS if (timeout) { - extern int clock_time_to_tick(const struct timespec *time); tick = clock_time_to_tick(timeout); } -#endif ret = rt_signal_wait(set, info, tick); if (ret == 0) return 0; diff --git a/components/libc/signal/posix_signal.h b/components/libc/signal/posix_signal.h index fa8ad38fa6acf4248b97521c58136d610d2dab84..f04b54c5f802b1ed7edcada5f362eeef2cd1f8a8 100644 --- a/components/libc/signal/posix_signal.h +++ b/components/libc/signal/posix_signal.h @@ -15,7 +15,6 @@ extern "C" { #endif -#include #include enum rt_signal_value{ diff --git a/include/libc/libc_fdset.h b/include/libc/libc_fdset.h deleted file mode 100644 index c542e6855cec470867c2959e51c9d8a80dba9542..0000000000000000000000000000000000000000 --- a/include/libc/libc_fdset.h +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017-10-30 Bernard The first version - */ - -#ifndef LIBC_FDSET_H__ -#define LIBC_FDSET_H__ - -#include - -#if defined(RT_USING_NEWLIB) || defined(_WIN32) || (defined( __GNUC__ ) && !defined(__ARMCC_VERSION)) -#include -#if defined(HAVE_SYS_SELECT_H) -#include -#endif - -#else - -#ifdef SAL_USING_POSIX - -#ifdef FD_SETSIZE -#undef FD_SETSIZE -#endif - -#define FD_SETSIZE DFS_FD_MAX -#endif - -# ifndef FD_SETSIZE -# define FD_SETSIZE 32 -# endif - -# define NBBY 8 /* number of bits in a byte */ - -typedef long fd_mask; -# define NFDBITS (sizeof (fd_mask) * NBBY) /* bits per mask */ -# ifndef howmany -# define howmany(x,y) (((x)+((y)-1))/(y)) -# endif - -/* We use a macro for fd_set so that including Sockets.h afterwards - can work. */ -typedef struct _types_fd_set { - fd_mask fds_bits[howmany(FD_SETSIZE, NFDBITS)]; -} _types_fd_set; - -#define fd_set _types_fd_set - -# define FD_SET(n, p) ((p)->fds_bits[(n)/NFDBITS] |= (1L << ((n) % NFDBITS))) -# define FD_CLR(n, p) ((p)->fds_bits[(n)/NFDBITS] &= ~(1L << ((n) % NFDBITS))) -# define FD_ISSET(n, p) ((p)->fds_bits[(n)/NFDBITS] & (1L << ((n) % NFDBITS))) -# define FD_ZERO(p) memset((void*)(p), 0, sizeof(*(p))) - -#endif - -#endif diff --git a/include/rtdef.h b/include/rtdef.h index 394bbca5d2d59c21550c8160ada29d87da709fbf..62d0a53685b4f8977fd5dc9ec887bf1d6e90b02b 100644 --- a/include/rtdef.h +++ b/include/rtdef.h @@ -510,7 +510,7 @@ typedef struct rt_timer *rt_timer_t; * @addtogroup Signal */ #ifdef RT_USING_SIGNALS -#include +#include typedef unsigned long rt_sigset_t; typedef void (*rt_sighandler_t)(int signo); typedef siginfo_t rt_siginfo_t; diff --git a/include/rtlibc.h b/include/rtlibc.h index ac44a97831964dd4f8ced4d11a8fd8a02a9ab713..4b145b1b1b00cd9ce43042dcedae848ad32b0b4b 100644 --- a/include/rtlibc.h +++ b/include/rtlibc.h @@ -13,11 +13,8 @@ /* definitions for libc if toolchain has no these definitions */ #include "libc/libc_stat.h" - #include "libc/libc_fcntl.h" #include "libc/libc_dirent.h" -#include "libc/libc_signal.h" -#include "libc/libc_fdset.h" #ifndef RT_USING_LIBC #if defined(__ARMCC_VERSION) || defined(__IAR_SYSTEMS_ICC__)