diff options
| author | Meco Jianting Man <[email protected]> | 2021-07-30 10:43:19 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-30 10:43:19 -0500 |
| commit | 2589d245325d95f0291e27886f93644d1f762f53 (patch) | |
| tree | 432e10f647be74abf9d6d58e131b0496bfae3fa3 /components | |
| parent | 19c5088bb8b6cfdc9e3cecc63b6f9c116a799c49 (diff) | |
| parent | 56d3abe30148a07dd41d78e8aa190f9baa164266 (diff) | |
Merge branch 'master' into tz
Diffstat (limited to 'components')
| -rw-r--r-- | components/dfs/include/dfs_select.h | 2 | ||||
| -rw-r--r-- | components/drivers/include/ipc/workqueue.h | 5 | ||||
| -rw-r--r-- | components/drivers/src/workqueue.c | 6 | ||||
| -rw-r--r-- | components/libc/aio/posix_aio.c | 6 | ||||
| -rw-r--r-- | components/libc/aio/posix_aio.h | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/none-gcc/sys/errno.h | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/none-gcc/sys/stat.h | 5 | ||||
| -rw-r--r-- | components/libc/compilers/common/none-gcc/sys/types.h | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/none-gcc/sys/unistd.h | 4 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/select.h | 49 | ||||
| -rw-r--r-- | components/libc/compilers/common/sys/signal.h | 194 | ||||
| -rw-r--r-- | components/libc/pthreads/mqueue.c | 1 | ||||
| -rw-r--r-- | components/libc/signal/posix_signal.c | 5 | ||||
| -rw-r--r-- | components/libc/signal/posix_signal.h | 1 | ||||
| -rw-r--r-- | components/net/at/at_socket/at_socket.c | 17 | ||||
| -rw-r--r-- | components/net/at/src/at_client.c | 20 | ||||
| -rw-r--r-- | components/net/sal_socket/include/socket/netdb.h | 2 |
17 files changed, 285 insertions, 44 deletions
diff --git a/components/dfs/include/dfs_select.h b/components/dfs/include/dfs_select.h index 458691df20..e0572c5059 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 <libc/libc_fdset.h> +#include <sys/select.h> #ifdef __cplusplus extern "C" { diff --git a/components/drivers/include/ipc/workqueue.h b/components/drivers/include/ipc/workqueue.h index 03d38b2f4d..a156145641 100644 --- a/components/drivers/include/ipc/workqueue.h +++ b/components/drivers/include/ipc/workqueue.h @@ -69,7 +69,7 @@ rt_err_t rt_workqueue_critical_work(struct rt_workqueue *queue, struct rt_work * #ifdef RT_USING_SYSTEM_WORKQUEUE rt_err_t rt_work_submit(struct rt_work *work, rt_tick_t time); rt_err_t rt_work_cancel(struct rt_work *work); -#endif +#endif /* RT_USING_SYSTEM_WORKQUEUE */ rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data) @@ -85,7 +85,6 @@ rt_inline void rt_work_init(struct rt_work *work, void (*work_func)(struct rt_wo void rt_delayed_work_init(struct rt_delayed_work *work, void (*work_func)(struct rt_work *work, void *work_data), void *work_data); -int rt_work_sys_workqueue_init(void); -#endif +#endif /* RT_USING_HEAP */ #endif diff --git a/components/drivers/src/workqueue.c b/components/drivers/src/workqueue.c index f195dad927..065c505015 100644 --- a/components/drivers/src/workqueue.c +++ b/components/drivers/src/workqueue.c @@ -358,7 +358,7 @@ rt_err_t rt_work_cancel(struct rt_work *work) return rt_workqueue_cancel_work(sys_workq, work); } -int rt_work_sys_workqueue_init(void) +static int rt_work_sys_workqueue_init(void) { if (sys_workq != RT_NULL) return RT_EOK; @@ -370,5 +370,5 @@ int rt_work_sys_workqueue_init(void) return RT_EOK; } INIT_PREV_EXPORT(rt_work_sys_workqueue_init); -#endif -#endif +#endif /* RT_USING_SYSTEM_WORKQUEUE */ +#endif /* RT_USING_HEAP */ diff --git a/components/libc/aio/posix_aio.c b/components/libc/aio/posix_aio.c index 66f15e4c57..66cced8687 100644 --- a/components/libc/aio/posix_aio.c +++ b/components/libc/aio/posix_aio.c @@ -9,14 +9,8 @@ */ #include <stdint.h> -#include <stdio.h> - #include <rthw.h> -#include <rtdevice.h> -#include <rtthread.h> - #include <dfs_posix.h> - #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 de11738515..4e25e1d15b 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 <stdio.h> +#include <sys/signal.h> +#include <rtdevice.h> + 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 ad3614024d..ff1abca387 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 c4b42083c4..c8f65df435 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 7222326a2a..e9f44f7762 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 <stdint.h> diff --git a/components/libc/compilers/common/none-gcc/sys/unistd.h b/components/libc/compilers/common/none-gcc/sys/unistd.h index 2f01f660b3..ea2d674b0f 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 <rtconfig.h> #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 0000000000..db42b6ebcc --- /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 <rtconfig.h> +#include <sys/types.h> + +#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/components/libc/compilers/common/sys/signal.h b/components/libc/compilers/common/sys/signal.h new file mode 100644 index 0000000000..9787958a37 --- /dev/null +++ b/components/libc/compilers/common/sys/signal.h @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2017-09-12 Bernard The first version + * 2021-07-21 Meco Man move to libc/common + */ + +#ifndef __SYS_SIGNAL_H__ +#define __SYS_SIGNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +#include <stdint.h> + +/* 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 */ +}; + +struct sigevent +{ + int sigev_notify; /* Notification type */ + int sigev_signo; /* Signal number */ + union sigval sigev_value; /* Signal value */ + void (*sigev_notify_function)( union sigval ); + /* Notification function */ + void *sigev_notify_attributes; /* Notification Attributes, really pthread_attr_t */ +}; + +struct siginfo +{ + uint16_t si_signo; + uint16_t si_code; + + union sigval si_value; +}; +typedef struct siginfo siginfo_t; + +#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. */ + +typedef void (*_sig_func_ptr)(int); +typedef unsigned long sigset_t; + +struct sigaction +{ + _sig_func_ptr sa_handler; + sigset_t sa_mask; + int sa_flags; +}; + +#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 +/* #define SIGILL 4 */ +#define SIGTRAP 5 +/* #define SIGABRT 6 */ +#define SIGEMT 7 +/* #define SIGFPE 8 */ +#define SIGKILL 9 +#define SIGBUS 10 +/* #define SIGSEGV 11 */ +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 +/* #define SIGTERM 15 */ +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGPOLL 23 +#define SIGWINCH 24 +/* #define SIGUSR1 25 */ +/* #define SIGUSR2 26 */ +#define SIGRTMIN 27 +#define SIGRTMAX 31 +#define NSIG 32 + +#include <signal.h> + +#elif defined(__IAR_SYSTEMS_ICC__) +#define SIGHUP 1 +#define SIGINT 2 +#define SIGQUIT 3 +#define SIGILL 4 +#define SIGTRAP 5 +/* #define SIGABRT 6 */ +#define SIGEMT 7 +#define SIGFPE 8 +#define SIGKILL 9 +#define SIGBUS 10 +#define SIGSEGV 11 +#define SIGSYS 12 +#define SIGPIPE 13 +#define SIGALRM 14 +#define SIGTERM 15 +#define SIGURG 16 +#define SIGSTOP 17 +#define SIGTSTP 18 +#define SIGCONT 19 +#define SIGCHLD 20 +#define SIGTTIN 21 +#define SIGTTOU 22 +#define SIGPOLL 23 +#define SIGWINCH 24 +#define SIGUSR1 25 +#define SIGUSR2 26 +#define SIGRTMIN 27 +#define SIGRTMAX 31 +#define NSIG 32 + +#include <signal.h> + +#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 <sys/signal.h> + * and <signal.h> are equivalent in glibc. Allow for that here. */ +#include <signal.h> +#endif + +#endif + +#ifdef __cplusplus +} +#endif + +#endif + diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c index ce2ff43e23..6840164a68 100644 --- a/components/libc/pthreads/mqueue.c +++ b/components/libc/pthreads/mqueue.c @@ -8,6 +8,7 @@ */ #include <string.h> +#include <sys/signal.h> #include "mqueue.h" #include "pthread_internal.h" diff --git a/components/libc/signal/posix_signal.c b/components/libc/signal/posix_signal.c index d664feb24d..ac8d2b1eef 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 <rthw.h> #include <rtthread.h> @@ -14,6 +15,7 @@ #include <sys/errno.h> #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 = rt_timespec_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 fa8ad38fa6..f04b54c5f8 100644 --- a/components/libc/signal/posix_signal.h +++ b/components/libc/signal/posix_signal.h @@ -15,7 +15,6 @@ extern "C" { #endif -#include <rtthread.h> #include <sys/signal.h> enum rt_signal_value{ diff --git a/components/net/at/at_socket/at_socket.c b/components/net/at/at_socket/at_socket.c index 973be0acf4..8215dd4417 100644 --- a/components/net/at/at_socket/at_socket.c +++ b/components/net/at/at_socket/at_socket.c @@ -13,6 +13,7 @@ #include <string.h> #include <ctype.h> #include <sys/time.h> +#include <sys/errno.h> #include <at_socket.h> #include <at_device.h> @@ -78,7 +79,7 @@ struct at_socket *at_get_socket(int socket) } /* get a block to the AT socket receive list*/ -static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) +static rt_err_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) { at_recv_pkt_t pkt = RT_NULL; @@ -86,7 +87,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) if (pkt == RT_NULL) { LOG_E("No memory for receive packet table!"); - return 0; + return -RT_ENOMEM; } pkt->bfsz_totle = length; @@ -95,7 +96,7 @@ static size_t at_recvpkt_put(rt_slist_t *rlist, const char *ptr, size_t length) rt_slist_append(rlist, &pkt->list); - return length; + return RT_EOK; } /* delete and free all receive buffer list */ @@ -651,14 +652,20 @@ static void at_recv_notice_cb(struct at_socket *sock, at_socket_evt_t event, con RT_ASSERT(event == AT_SOCKET_EVT_RECV); /* check the socket object status */ - if (sock->magic != AT_SOCKET_MAGIC) + if (sock->magic != AT_SOCKET_MAGIC || sock->state == AT_SOCKET_CLOSED) { + rt_free((void *)buff); return; } /* put receive buffer to receiver packet list */ rt_mutex_take(sock->recv_lock, RT_WAITING_FOREVER); - at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz); + if (at_recvpkt_put(&(sock->recvpkt_list), buff, bfsz) != RT_EOK) + { + rt_free((void *)buff); + rt_mutex_release(sock->recv_lock); + return; + } rt_mutex_release(sock->recv_lock); rt_sem_release(sock->recv_notice); diff --git a/components/net/at/src/at_client.c b/components/net/at/src/at_client.c index 7904c24d92..948020f4cf 100644 --- a/components/net/at/src/at_client.c +++ b/components/net/at/src/at_client.c @@ -9,6 +9,7 @@ * 2018-04-12 chenyong add client implement * 2018-08-17 chenyong multiple client support * 2021-03-17 Meco Man fix a buf of leaking memory + * 2021-07-14 Sszl fix a buf of leaking memory */ #include <at.h> @@ -571,30 +572,19 @@ int at_obj_set_urc_table(at_client_t client, const struct at_urc *urc_table, rt_ } else { - struct at_urc_table *old_urc_table = RT_NULL; - size_t old_table_size = client->urc_table_size * sizeof(struct at_urc_table); - - old_urc_table = (struct at_urc_table *) rt_malloc(old_table_size); - if (old_urc_table == RT_NULL) - { - return -RT_ENOMEM; - } - rt_memcpy(old_urc_table, client->urc_table, old_table_size); + struct at_urc_table *new_urc_table = RT_NULL; /* realloc urc table space */ - client->urc_table = (struct at_urc_table *) rt_realloc(client->urc_table, - old_table_size + sizeof(struct at_urc_table)); - if (client->urc_table == RT_NULL) + new_urc_table = (struct at_urc_table *) rt_realloc(client->urc_table,client->urc_table_size * sizeof(struct at_urc_table) + sizeof(struct at_urc_table)); + if (new_urc_table == RT_NULL) { - rt_free(old_urc_table); return -RT_ENOMEM; } - rt_memcpy(client->urc_table, old_urc_table, old_table_size); + client->urc_table = new_urc_table; client->urc_table[client->urc_table_size].urc = urc_table; client->urc_table[client->urc_table_size].urc_size = table_sz; client->urc_table_size++; - rt_free(old_urc_table); } return RT_EOK; diff --git a/components/net/sal_socket/include/socket/netdb.h b/components/net/sal_socket/include/socket/netdb.h index 4783405022..9d54953681 100644 --- a/components/net/sal_socket/include/socket/netdb.h +++ b/components/net/sal_socket/include/socket/netdb.h @@ -6,7 +6,7 @@ * Change Logs: * Date Author Notes * 2015-02-17 Bernard First version - * 2108-05-24 ChenYong Add socket abstraction layer + * 2018-05-24 ChenYong Add socket abstraction layer */ #ifndef NETDB_H__ |
