diff options
| author | Man, Jianting (Meco) <[email protected]> | 2021-08-17 16:56:10 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-08-17 16:56:10 -0500 |
| commit | 3e6578916f892e4456d9dff4bbd44590a0cb4bc8 (patch) | |
| tree | b98d9fe601ce62e17b37f5b971f0cc9f965fa0e3 /components/libc/pthreads | |
| parent | 37a9231e6219b94f7cde8bdea9251e260c4bed18 (diff) | |
| parent | 196f340e5d845efd005b57a2089e0642266a79be (diff) | |
Merge branch 'master' into security
Diffstat (limited to 'components/libc/pthreads')
| -rw-r--r-- | components/libc/pthreads/mqueue.c | 3 | ||||
| -rw-r--r-- | components/libc/pthreads/posix_types.h | 9 | ||||
| -rw-r--r-- | components/libc/pthreads/pthread.c | 21 | ||||
| -rw-r--r-- | components/libc/pthreads/pthread_cond.c | 2 | ||||
| -rw-r--r-- | components/libc/pthreads/semaphore.c | 4 |
5 files changed, 26 insertions, 13 deletions
diff --git a/components/libc/pthreads/mqueue.c b/components/libc/pthreads/mqueue.c index 1af0ab2919..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" @@ -243,7 +244,7 @@ ssize_t mq_timedreceive(mqd_t mqdes, return -1; } - tick = clock_time_to_tick(abs_timeout); + tick = rt_timespec_to_tick(abs_timeout); result = rt_mq_recv(mqdes->mq, msg_ptr, msg_len, tick); if (result == RT_EOK) diff --git a/components/libc/pthreads/posix_types.h b/components/libc/pthreads/posix_types.h index f2d806cc9a..5838e8b370 100644 --- a/components/libc/pthreads/posix_types.h +++ b/components/libc/pthreads/posix_types.h @@ -19,16 +19,9 @@ #include <sys/types.h> #include <sys/time.h> - -/* errno for Keil MDK */ -#if defined(__CC_ARM) || defined(__IAR_SYSTEMS_ICC__) -#include <sys/errno.h> -#include <sys/unistd.h> -#else #include <unistd.h> -#include <errno.h> +#include <sys/errno.h> #include <fcntl.h> -#endif #endif diff --git a/components/libc/pthreads/pthread.c b/components/libc/pthreads/pthread.c index 8a728c4e99..79104d1fd5 100644 --- a/components/libc/pthreads/pthread.c +++ b/components/libc/pthreads/pthread.c @@ -209,6 +209,8 @@ int pthread_create(pthread_t *pid, /* get pthread data */ ptd = _pthread_get_data(pth_id); + RT_ASSERT(ptd != RT_NULL); + if (attr != RT_NULL) { ptd->attr = *attr; @@ -299,6 +301,12 @@ int pthread_detach(pthread_t thread) { int ret = 0; _pthread_data_t *ptd = _pthread_get_data(thread); + if (ptd == RT_NULL) + { + /* invalid pthread id */ + ret = EINVAL; + goto __exit; + } rt_enter_critical(); if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED) @@ -360,6 +368,12 @@ int pthread_join(pthread_t thread, void **value_ptr) rt_err_t result; ptd = _pthread_get_data(thread); + + if (ptd == RT_NULL) + { + return EINVAL; /* invalid pthread id */ + } + if (ptd && ptd->tid == rt_thread_self()) { /* join self */ @@ -367,7 +381,9 @@ int pthread_join(pthread_t thread, void **value_ptr) } if (ptd->attr.detachstate == PTHREAD_CREATE_DETACHED) + { return EINVAL; /* join on a detached pthread */ + } result = rt_sem_take(ptd->joinable_sem, RT_WAITING_FOREVER); if (result == RT_EOK) @@ -662,7 +678,10 @@ int pthread_cancel(pthread_t thread) /* get posix thread data */ ptd = _pthread_get_data(thread); - RT_ASSERT(ptd != RT_NULL); + if (ptd == RT_NULL) + { + return EINVAL; + } /* cancel self */ if (ptd->tid == rt_thread_self()) diff --git a/components/libc/pthreads/pthread_cond.c b/components/libc/pthreads/pthread_cond.c index 59c271bf6e..9bf49704ed 100644 --- a/components/libc/pthreads/pthread_cond.c +++ b/components/libc/pthreads/pthread_cond.c @@ -222,7 +222,7 @@ int pthread_cond_timedwait(pthread_cond_t *cond, int timeout; rt_err_t result; - timeout = clock_time_to_tick(abstime); + timeout = rt_timespec_to_tick(abstime); result = _pthread_cond_timedwait(cond, mutex, timeout); if (result == RT_EOK) return 0; diff --git a/components/libc/pthreads/semaphore.c b/components/libc/pthreads/semaphore.c index 398cdf1f49..5e59ae850f 100644 --- a/components/libc/pthreads/semaphore.c +++ b/components/libc/pthreads/semaphore.c @@ -186,7 +186,7 @@ int sem_init(sem_t *sem, int pshared, unsigned int value) rt_snprintf(name, sizeof(name), "psem%02d", psem_number++); sem->sem = rt_sem_create(name, value, RT_IPC_FLAG_FIFO); - if (sem == RT_NULL) + if (sem->sem == RT_NULL) { rt_set_errno(ENOMEM); @@ -319,7 +319,7 @@ int sem_timedwait(sem_t *sem, const struct timespec *abs_timeout) return EINVAL; /* calculate os tick */ - tick = clock_time_to_tick(abs_timeout); + tick = rt_timespec_to_tick(abs_timeout); result = rt_sem_take(sem->sem, tick); if (result == -RT_ETIMEOUT) |
