casaroli commented on code in PR #20784:
URL: https://github.com/apache/nuttx/pull/20784#discussion_r4308373987


##########
libs/libc/unistd/Make.defs:
##########
@@ -30,7 +30,7 @@ CSRCS += lib_getopterrp.c lib_getoptindp.c lib_getoptoptp.c 
lib_times.c
 CSRCS += lib_alarm.c lib_fstatvfs.c lib_statvfs.c lib_sleep.c lib_nice.c
 CSRCS += lib_getrusage.c lib_utime.c lib_utimes.c lib_getdtablesize.c
 CSRCS += lib_getpagesize.c
-CSRCS += lib_setrlimit.c lib_getrlimit.c lib_setpriority.c lib_getpriority.c
+CSRCS += lib_setpriority.c lib_getpriority.c

Review Comment:
   Done.



##########
fs/inode/fs_files.c:
##########
@@ -58,6 +59,24 @@
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: fdlist_limit
+ *
+ * Description:
+ *   Return the RLIMIT_NOFILE soft limit of the task group that owns the
+ *   list: a new file descriptor must be below it.
+ *
+ ****************************************************************************/
+
+static int fdlist_limit(FAR struct fdlist *list)
+{
+  FAR struct task_group_s *group =
+    container_of(list, struct task_group_s, tg_fdlist);
+
+  return group->tg_rlimit_nofile.rlim_cur < OPEN_MAX ?
+         (int)group->tg_rlimit_nofile.rlim_cur : OPEN_MAX;

Review Comment:
   Done.



##########
fs/inode/fs_files.c:
##########
@@ -58,6 +59,24 @@
  * Private Functions
  ****************************************************************************/
 
+/****************************************************************************
+ * Name: fdlist_limit
+ *
+ * Description:
+ *   Return the RLIMIT_NOFILE soft limit of the task group that owns the
+ *   list: a new file descriptor must be below it.
+ *
+ ****************************************************************************/
+
+static int fdlist_limit(FAR struct fdlist *list)

Review Comment:
   Done.



##########
sched/group/group_rlimit.c:
##########
@@ -96,6 +98,43 @@ void group_init_rlimit(FAR struct task_group_s *group,
     }
 }
 
+/****************************************************************************
+ * Name: nxsched_get_stacksize
+ *
+ * Description:
+ *   Return the default stack size of a new thread or program of the
+ *   calling task group: its RLIMIT_STACK soft limit, kept between
+ *   PTHREAD_STACK_MIN and the largest stack that a task can have, or the
+ *   given size if there is no limit.
+ *
+ ****************************************************************************/
+
+size_t nxsched_get_stacksize(size_t size)
+{
+  FAR struct task_group_s *group = nxsched_self()->group;
+  rlim_t limit;
+
+  if (group == NULL || group->tg_rlimit_stack.rlim_cur == RLIM_INFINITY)
+    {
+      return size;
+    }
+
+  limit = group->tg_rlimit_stack.rlim_cur;
+  if (limit < PTHREAD_STACK_MIN)
+    {
+      limit = PTHREAD_STACK_MIN;
+    }
+
+#ifdef CONFIG_TLS_ALIGNED
+  if (limit > TLS_MAXSTACK)
+    {
+      limit = TLS_MAXSTACK;
+    }
+#endif
+
+  return (size_t)limit;

Review Comment:
   The RLIMIT_STACK soft limit is the default stack size: for a new thread 
without a stack size attribute, and for the main stack of a new program, as on 
Linux. The size argument is used only when there is no limit.



##########
libs/libc/pthread/pthread_attr_init.c:
##########
@@ -86,6 +89,28 @@ int pthread_attr_init(FAR pthread_attr_t *attr)
        */
 
       memcpy(attr, &g_default_pthread_attr, sizeof(pthread_attr_t));
+
+      /* The RLIMIT_STACK soft limit gives the default stack size, kept
+       * between PTHREAD_STACK_MIN and the largest stack a task can have.
+       */
+
+      if (getrlimit(RLIMIT_STACK, &rlim) == 0 &&

Review Comment:
   Done: pthread_attr_init() calls lib_get_stacksize() now.



##########
sched/group/group_rlimit.c:
##########
@@ -96,6 +98,43 @@ void group_init_rlimit(FAR struct task_group_s *group,
     }
 }
 
+/****************************************************************************
+ * Name: nxsched_get_stacksize
+ *
+ * Description:
+ *   Return the default stack size of a new thread or program of the
+ *   calling task group: its RLIMIT_STACK soft limit, kept between
+ *   PTHREAD_STACK_MIN and the largest stack that a task can have, or the
+ *   given size if there is no limit.
+ *
+ ****************************************************************************/
+
+size_t nxsched_get_stacksize(size_t size)

Review Comment:
   Done: lib_get_stacksize() is in libs/libc/misc/lib_getstacksize.c and reads 
the limit with getrlimit(). pthread_attr_init(), nx_pthread_create() and the 
ELF loader call it.



-- 
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]

Reply via email to