未验证 提交 e61d05ca 编写于 作者: X xiangxistu 提交者: GitHub

[fix] the risk for function exit() when open pthread support. (#6229)

* [fix] the risk for function exit() when open pthread support.
* [update] modify annotation from "user data" to "pthread_data".
上级 79934777
...@@ -21,8 +21,11 @@ void __rt_libc_exit(int status) ...@@ -21,8 +21,11 @@ void __rt_libc_exit(int status)
if (self != RT_NULL) if (self != RT_NULL)
{ {
#ifdef RT_USING_PTHREADS #ifdef RT_USING_PTHREADS
extern void pthread_exit(void *value); if(self->pthread_data != RT_NULL)
pthread_exit((void *)status); {
extern void pthread_exit(void *value);
pthread_exit((void *)status);
}
#else #else
LOG_E("thread:%s exit:%d!", self->name, status); LOG_E("thread:%s exit:%d!", self->name, status);
rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL); rt_thread_control(self, RT_THREAD_CTRL_CLOSE, RT_NULL);
......
...@@ -135,8 +135,8 @@ void _pthread_data_destroy(_pthread_data_t *ptd) ...@@ -135,8 +135,8 @@ void _pthread_data_destroy(_pthread_data_t *ptd)
/* clean magic */ /* clean magic */
ptd->magic = 0x0; ptd->magic = 0x0;
/* clear the "ptd->tid->user_data" */ /* clear the "ptd->tid->pthread_data" */
ptd->tid->user_data = RT_NULL; ptd->tid->pthread_data = RT_NULL;
/* free ptd */ /* free ptd */
rt_free(ptd); rt_free(ptd);
...@@ -281,7 +281,7 @@ int pthread_create(pthread_t *pid, ...@@ -281,7 +281,7 @@ int pthread_create(pthread_t *pid,
/* set pthread cleanup function and ptd data */ /* set pthread cleanup function and ptd data */
ptd->tid->cleanup = _pthread_cleanup; ptd->tid->cleanup = _pthread_cleanup;
ptd->tid->user_data = (rt_ubase_t)ptd; ptd->tid->pthread_data = (void *)ptd;
/* start thread */ /* start thread */
if (rt_thread_startup(ptd->tid) == RT_EOK) if (rt_thread_startup(ptd->tid) == RT_EOK)
...@@ -394,8 +394,8 @@ pthread_t pthread_self (void) ...@@ -394,8 +394,8 @@ pthread_t pthread_self (void)
tid = rt_thread_self(); tid = rt_thread_self();
if (tid == NULL) return PTHREAD_NUM_MAX; if (tid == NULL) return PTHREAD_NUM_MAX;
/* get pthread data from user data of thread */ /* get pthread data from pthread_data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data; ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
RT_ASSERT(ptd != RT_NULL); RT_ASSERT(ptd != RT_NULL);
return _pthread_data_get_pth(ptd); return _pthread_data_get_pth(ptd);
...@@ -477,8 +477,8 @@ void pthread_exit(void *value) ...@@ -477,8 +477,8 @@ void pthread_exit(void *value)
return; return;
} }
/* get pthread data from user data of thread */ /* get pthread data from pthread_data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data; ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
rt_enter_critical(); rt_enter_critical();
/* disable cancel */ /* disable cancel */
...@@ -595,8 +595,8 @@ void pthread_cleanup_pop(int execute) ...@@ -595,8 +595,8 @@ void pthread_cleanup_pop(int execute)
if (rt_thread_self() == NULL) return; if (rt_thread_self() == NULL) return;
/* get pthread data from user data of thread */ /* get pthread data from pthread_data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data; ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
RT_ASSERT(ptd != RT_NULL); RT_ASSERT(ptd != RT_NULL);
if (execute) if (execute)
...@@ -624,8 +624,8 @@ void pthread_cleanup_push(void (*routine)(void *), void *arg) ...@@ -624,8 +624,8 @@ void pthread_cleanup_push(void (*routine)(void *), void *arg)
if (rt_thread_self() == NULL) return; if (rt_thread_self() == NULL) return;
/* get pthread data from user data of thread */ /* get pthread data from pthread_data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data; ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
RT_ASSERT(ptd != RT_NULL); RT_ASSERT(ptd != RT_NULL);
cleanup = (_pthread_cleanup_t *)rt_malloc(sizeof(_pthread_cleanup_t)); cleanup = (_pthread_cleanup_t *)rt_malloc(sizeof(_pthread_cleanup_t));
...@@ -676,8 +676,8 @@ int pthread_setcancelstate(int state, int *oldstate) ...@@ -676,8 +676,8 @@ int pthread_setcancelstate(int state, int *oldstate)
if (rt_thread_self() == NULL) return EINVAL; if (rt_thread_self() == NULL) return EINVAL;
/* get pthread data from user data of thread */ /* get pthread data from pthread_data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data; ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
RT_ASSERT(ptd != RT_NULL); RT_ASSERT(ptd != RT_NULL);
if ((state == PTHREAD_CANCEL_ENABLE) || (state == PTHREAD_CANCEL_DISABLE)) if ((state == PTHREAD_CANCEL_ENABLE) || (state == PTHREAD_CANCEL_DISABLE))
...@@ -699,8 +699,8 @@ int pthread_setcanceltype(int type, int *oldtype) ...@@ -699,8 +699,8 @@ int pthread_setcanceltype(int type, int *oldtype)
if (rt_thread_self() == NULL) return EINVAL; if (rt_thread_self() == NULL) return EINVAL;
/* get pthread data from user data of thread */ /* get pthread data from pthread_data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data; ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
RT_ASSERT(ptd != RT_NULL); RT_ASSERT(ptd != RT_NULL);
if ((type != PTHREAD_CANCEL_DEFERRED) && (type != PTHREAD_CANCEL_ASYNCHRONOUS)) if ((type != PTHREAD_CANCEL_DEFERRED) && (type != PTHREAD_CANCEL_ASYNCHRONOUS))
...@@ -721,8 +721,8 @@ void pthread_testcancel(void) ...@@ -721,8 +721,8 @@ void pthread_testcancel(void)
if (rt_thread_self() == NULL) return; if (rt_thread_self() == NULL) return;
/* get pthread data from user data of thread */ /* get pthread data from pthread_data of thread */
ptd = (_pthread_data_t *)rt_thread_self()->user_data; ptd = (_pthread_data_t *)rt_thread_self()->pthread_data;
RT_ASSERT(ptd != RT_NULL); RT_ASSERT(ptd != RT_NULL);
if (ptd->cancelstate == PTHREAD_CANCEL_ENABLE) if (ptd->cancelstate == PTHREAD_CANCEL_ENABLE)
......
...@@ -690,9 +690,13 @@ struct rt_thread ...@@ -690,9 +690,13 @@ struct rt_thread
rt_ubase_t remaining_tick; /**< remaining tick */ rt_ubase_t remaining_tick; /**< remaining tick */
#ifdef RT_USING_CPU_USAGE #ifdef RT_USING_CPU_USAGE
rt_uint64_t duration_tick; /**< cpu usage tick */ rt_uint64_t duration_tick; /**< cpu usage tick */
#endif /* RT_USING_CPU_USAGE */ #endif /* RT_USING_CPU_USAGE */
#ifdef RT_USING_PTHREADS
void *pthread_data; /**< the handle of pthread data, adapt 32/64bit */
#endif /* RT_USING_PTHREADS */
struct rt_timer thread_timer; /**< built-in thread timer */ struct rt_timer thread_timer; /**< built-in thread timer */
void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */ void (*cleanup)(struct rt_thread *tid); /**< cleanup function when thread exit */
......
...@@ -252,6 +252,10 @@ static rt_err_t _thread_init(struct rt_thread *thread, ...@@ -252,6 +252,10 @@ static rt_err_t _thread_init(struct rt_thread *thread,
thread->duration_tick = 0; thread->duration_tick = 0;
#endif /* RT_USING_CPU_USAGE */ #endif /* RT_USING_CPU_USAGE */
#ifdef RT_USING_PTHREADS
thread->pthread_data = RT_NULL;
#endif /* RT_USING_PTHREADS */
#ifdef RT_USING_MODULE #ifdef RT_USING_MODULE
thread->module_id = 0; thread->module_id = 0;
#endif /* RT_USING_MODULE */ #endif /* RT_USING_MODULE */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册