no1wudi edited a comment on pull request #3626: URL: https://github.com/apache/incubator-nuttx/pull/3626#issuecomment-829783428
> pthread_exit() must only be called from user space, especially after this change. However, I still see several calls to pthread_exit() from within the OS in supervisor mode. This is a problem. > > In the original code before your change there are these: > > ``` > sched/pthread/pthread_create.c: pthread_exit(exit_status); > sched/signal/sig_default.c: pthread_exit(NULL); > sched/task/task_cancelpt.c: pthread_exit(PTHREAD_CANCELED); > sched/task/task_cancelpt.c: pthread_exit(PTHREAD_CANCELED); > sched/task/task_setcancelstate.c: pthread_exit(PTHREAD_CANCELED); > sched/task/task_setcanceltype.c: pthread_exit(PTHREAD_CANCELED); > ``` > > We must not call pthread_exit() from within the OS without first dropping the privileges to user. Otherwise, the problem that we are trying to solve with this PR is not solved. See full comments for a suggested solution. > > In my point of view, we could probably just open another PR for these remaining issues and merge as is. We are still making a positive step forward. If replace all pthread_exit() with nx_pthread_exit(), there would be a memory leak that cleanup function (include future ptherad_key_create destructors) not executed correctly. I'll try this solution: > Possible solution: > Add a pointer to pthread_exit to nx_pthread_create(). We have to do this because the address of pthread_exit() will not be > >known in the PROTECTED and KERNEL builds. I think you were not seeing the build failure in the PROTECTED/KERNEL builds > because cancellation points and default signal actions were not enabled. > Save the pthread_exit() pointer in the TCB > Replace calls to pthread_exit() in the OS to up_pthread_exit(). > up_pthread_exit should issue a trap that drops to user mode and calls to the saved pthread_exit() entry point. or another possible solution: Replace these pthread_exit with by send SIG_ABRT, dorp to user space with sig action and call pthread_exit in signal handler ? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
