pussuw commented on code in PR #12320:
URL: https://github.com/apache/nuttx/pull/12320#discussion_r1795044227
##########
libs/libc/stdlib/lib_getprogname.c:
##########
@@ -25,20 +25,26 @@
#include <nuttx/config.h>
#include <stdlib.h>
-#include <nuttx/tls.h>
+#include <nuttx/sched.h>
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: getprogname
+ *
+ * Note that previous impl returns address in the stack of main thread when
+ * used from a pthread, that is dangerous as main thread may end earlier.
****************************************************************************/
FAR const char *getprogname(void)
{
- FAR struct task_info_s *info;
+ struct stackinfo_s si;
+ FAR struct tls_info_s *ti = tls_get_info();
+ uintptr_t ret = ti ? (uintptr_t)ti + ti->tl_size : 0;
+ int rc = nxsched_get_stackinfo(0, &si);
- info = task_get_info();
- return info->ta_argv[0];
+ return (rc >= 0 && ret && ((uintptr_t)si.stack_base_ptr) > ret) ?
Review Comment:
Ok, so should we have implemented a reference counter for the parent stack /
TLS so this does not happen until all threads / the process itself exits ?
Now pthreads do not see the argument vector at all
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]