You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/07/31 14:50:16 UTC

[nuttx] branch master updated (c126ee8468 -> f40eee50d6)

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


    from c126ee8468 sched/assert.c: Fix style check error
     new f2844a2e3c vfs: return OK when fsync dir
     new a551be4ee2 malloc: set errno to ENOMEM when malloc fail
     new 9a60d7bb49 signal: add SIGWINCH define
     new fde8affe71 singal: add stack_t define
     new b2a9c6a3e5 sched: inherit parent priority by default
     new c33e6528b1 getrlimit: add RLIMIT_MEMLOCK define
     new ed705f9cb3 sysconf: add _SC_THREAD_THREADS_MAX response
     new 700cc5ab90 single: add SS_ONSTACK and SS_DISABLE define
     new 3721af647a Add _POSIX_THREAD_PRIORITY_SCHEDULING define
     new 30367fd4cd sched: inherit parent priority by default, except idle
     new 4ecff53e2c sigaltstack: Add initial implementation of sigaltstack
     new f40eee50d6 pwd: Add initial implementation of getpwent

The 12 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 arch/arm/include/cxd56xx/crashdump.h               |   4 +-
 fs/vfs/fs_dir.c                                    |   7 +-
 include/pwd.h                                      |   6 +
 include/signal.h                                   |  21 +++
 include/sys/resource.h                             |   1 +
 include/unistd.h                                   |   1 +
 libs/libc/pwd/Make.defs                            |   4 +-
 libs/libc/pwd/lib_find_pwdfile.c                   |  69 ++++++++-
 libs/libc/pwd/lib_getpwent.c                       | 165 +++++++++++++++++++++
 libs/libc/pwd/lib_pwd.h                            |   3 +
 libs/libc/pwd/lib_pwd_globals.c                    |   1 +
 libs/libc/signal/Make.defs                         |   3 +-
 .../lib_getrlimit.c => signal/sig_altstack.c}      |  54 +++----
 libs/libc/unistd/lib_sysconf.c                     |   5 +
 mm/umm_heap/umm_malloc.c                           |  12 +-
 mm/umm_heap/umm_memalign.c                         |  12 +-
 mm/umm_heap/umm_realloc.c                          |  12 +-
 mm/umm_heap/umm_zalloc.c                           |  12 +-
 sched/pthread/pthread_create.c                     |  16 +-
 19 files changed, 357 insertions(+), 51 deletions(-)
 create mode 100644 libs/libc/pwd/lib_getpwent.c
 copy libs/libc/{unistd/lib_getrlimit.c => signal/sig_altstack.c} (70%)


[nuttx] 04/12: singal: add stack_t define

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit fde8affe71f72990c298a9ef0784cca682b7ee76
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Tue Jun 20 11:31:50 2023 +0800

    singal: add stack_t define
    
    stack_t used by sigaltstack, make it compile sucess in sim.
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
    
    ltp: fix compile errors
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 arch/arm/include/cxd56xx/crashdump.h |  4 ++--
 include/signal.h                     | 14 ++++++++++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/arch/arm/include/cxd56xx/crashdump.h b/arch/arm/include/cxd56xx/crashdump.h
index e7b3b5d8fa..72dd29644b 100644
--- a/arch/arm/include/cxd56xx/crashdump.h
+++ b/arch/arm/include/cxd56xx/crashdump.h
@@ -85,7 +85,7 @@ typedef struct
 #if CONFIG_ARCH_INTERRUPTSTACK > 3
   _stack_t interrupt;
 #endif
-} stack_t;
+} crash_stack_t;
 
 /* Flags to identify what is in the dump */
 
@@ -106,7 +106,7 @@ typedef struct
   int           lineno;                 /* __LINE__ to up_assert */
   pid_t         pid;                    /* Process ID */
   uint32_t      regs[XCPTCONTEXT_REGS]; /* Interrupt register save area */
-  stack_t       stacks;                 /* Stack info */
+  crash_stack_t stacks;                 /* Stack info */
 #if CONFIG_TASK_NAME_SIZE > 0
   char          name[CONFIG_TASK_NAME_SIZE + 1]; /* Task name (with NULL
                                                   * terminator) */
diff --git a/include/signal.h b/include/signal.h
index f60e11ead0..ccaa198805 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -220,6 +220,11 @@
 #  define SIGEV_THREAD  3 /* A notification function is called */
 #endif
 
+/* sigaltstack stack size */
+
+#define MINSIGSTKSZ     CONFIG_PTHREAD_STACK_MIN     /* Smallest signal stack size */
+#define SIGSTKSZ        CONFIG_PTHREAD_STACK_DEFAULT /* Default signal stack size */
+
 /* Special values of sa_handler used by sigaction and sigset.  They are all
  * treated like NULL for now.  This is okay for SIG_DFL and SIG_IGN because
  * in NuttX, the default action for all signals is to ignore them.
@@ -341,6 +346,15 @@ struct sigaction
 #define sa_handler   sa_u._sa_handler
 #define sa_sigaction sa_u._sa_sigaction
 
+/* Structure describing a signal stack.  */
+
+typedef struct
+{
+  FAR void *ss_sp;
+  int ss_flags;
+  size_t ss_size;
+} stack_t;
+
 /****************************************************************************
  * Public Function Prototypes
  ****************************************************************************/


[nuttx] 12/12: pwd: Add initial implementation of getpwent

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f40eee50d63b5ff94867b870a4c351244c574c0e
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Sun Jun 25 16:53:44 2023 +0800

    pwd: Add initial implementation of getpwent
    
    fix ltp sigqueue testcase crash in getpwent:
    nsh> ltp_sigqueue_3_1
    core dumped
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 include/pwd.h                    |   6 ++
 libs/libc/pwd/Make.defs          |   4 +-
 libs/libc/pwd/lib_find_pwdfile.c |  69 +++++++++++++++-
 libs/libc/pwd/lib_getpwent.c     | 165 +++++++++++++++++++++++++++++++++++++++
 libs/libc/pwd/lib_pwd.h          |   3 +
 libs/libc/pwd/lib_pwd_globals.c  |   1 +
 6 files changed, 242 insertions(+), 6 deletions(-)

diff --git a/include/pwd.h b/include/pwd.h
index aff3613749..205bd2f209 100644
--- a/include/pwd.h
+++ b/include/pwd.h
@@ -67,6 +67,12 @@ extern "C"
 #define EXTERN extern
 #endif
 
+void setpwent(void);
+void endpwent(void);
+FAR struct passwd *getpwent(void);
+int getpwent_r(FAR struct passwd *pwd,
+               FAR char *buf, size_t buflen,
+               FAR struct passwd **result);
 FAR struct passwd *getpwnam(FAR const char *name);
 FAR struct passwd *getpwuid(uid_t uid);
 int getpwnam_r(FAR const char *name, FAR struct passwd *pwd, FAR char *buf,
diff --git a/libs/libc/pwd/Make.defs b/libs/libc/pwd/Make.defs
index 73b7cb5130..6d6333ebb9 100644
--- a/libs/libc/pwd/Make.defs
+++ b/libs/libc/pwd/Make.defs
@@ -21,10 +21,10 @@
 # Add the pwd C files to the build
 
 CSRCS += lib_getpwnam.c lib_getpwnamr.c lib_getpwuid.c lib_getpwuidr.c
-CSRCS += lib_pwd_globals.c
+CSRCS += lib_getpwent.c lib_pwd_globals.c
 
 ifeq ($(CONFIG_LIBC_PASSWD_FILE),y)
-CSRCS += lib_find_pwdfile.c lib_pwd_globals.c
+CSRCS += lib_find_pwdfile.c
 else
 CSRCS += lib_getpwbuf.c lib_getpwbufr.c
 endif
diff --git a/libs/libc/pwd/lib_find_pwdfile.c b/libs/libc/pwd/lib_find_pwdfile.c
index a7781631be..5cfa14da9d 100644
--- a/libs/libc/pwd/lib_find_pwdfile.c
+++ b/libs/libc/pwd/lib_find_pwdfile.c
@@ -37,7 +37,7 @@
  ****************************************************************************/
 
 typedef CODE int (pwd_foreach_match_t)(FAR const struct passwd *entry,
-                                       uintptr_t arg);
+                                       uintptr_t index, uintptr_t arg);
 
 /****************************************************************************
  * Private Functions
@@ -52,6 +52,7 @@ typedef CODE int (pwd_foreach_match_t)(FAR const struct passwd *entry,
  *
  * Input Parameters:
  *   entry  - The parsed passwd file record
+ *   index  - The index of record in passwd file
  *   arg    - A pointer to the user name to match
  *
  * Returned Value:
@@ -61,8 +62,11 @@ typedef CODE int (pwd_foreach_match_t)(FAR const struct passwd *entry,
  *
  ****************************************************************************/
 
-static int pwd_match_name(FAR const struct passwd *entry, uintptr_t arg)
+static int pwd_match_name(FAR const struct passwd *entry,
+                          uintptr_t index, uintptr_t arg)
 {
+  UNUSED(index);
+
   FAR const char *uname = (FAR const char *)arg;
   return strcmp(entry->pw_name, uname) == 0 ? 1 : 0;
 }
@@ -76,6 +80,7 @@ static int pwd_match_name(FAR const struct passwd *entry, uintptr_t arg)
  *
  * Input Parameters:
  *   entry  - The parsed passwd file record
+ *   index  - The index of record in passwd file
  *   arg    - The user ID to match
  *
  * Returned Value:
@@ -85,12 +90,41 @@ static int pwd_match_name(FAR const struct passwd *entry, uintptr_t arg)
  *
  ****************************************************************************/
 
-static int pwd_match_uid(FAR const struct passwd *entry, uintptr_t arg)
+static int pwd_match_uid(FAR const struct passwd *entry,
+                         uintptr_t index, uintptr_t arg)
 {
+  UNUSED(index);
+
   int match_uid = (int)arg;
   return match_uid == entry->pw_uid ? 1 : 0;
 }
 
+/****************************************************************************
+ * Name: pwd_match_index
+ *
+ * Description:
+ *   Called for each record in the passwd file.  Returns "1" if the record
+ *   matches the index (passed as arg)
+ *
+ * Input Parameters:
+ *   entry  - The parsed passwd file record
+ *   index  - The index of record in passwd file
+ *   arg    - The index to match
+ *
+ * Returned Value:
+ *   = 0 :  No entry name does not match.
+ *   = 1 :  The entry name matches
+ *
+ ****************************************************************************/
+
+static int pwd_match_index(FAR const struct passwd *entry,
+                           uintptr_t index, uintptr_t arg)
+{
+  UNUSED(entry);
+
+  return index == arg;
+}
+
 /****************************************************************************
  * Name: pwd_foreach
  *
@@ -118,6 +152,7 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg,
   FAR FILE *stream;
   FAR char *ptr;
   FAR char *save;
+  int index = 0;
   int ret;
 
   stream = fopen(CONFIG_LIBC_PASSWD_FILEPATH, "r");
@@ -255,7 +290,7 @@ static int pwd_foreach(pwd_foreach_match_t match, uintptr_t arg,
 
       /* Check for a match */
 
-      ret = match(entry, arg);
+      ret = match(entry, (uintptr_t)index++, arg);
       if (ret != 0)
         {
           /* We either have the match or an error occurred. */
@@ -333,3 +368,29 @@ int pwd_findby_uid(uid_t uid, FAR struct passwd *entry, FAR char *buffer,
 
   return pwd_foreach(pwd_match_uid, (uintptr_t)uid, entry, buffer, buflen);
 }
+
+/****************************************************************************
+ * Name: pwd_findby_index
+ *
+ * Description:
+ *   Find passwd file entry using the index.
+ *
+ * Input Parameters:
+ *   index  - The index of entry
+ *   entry  - Location to return the parsed passwd file entry
+ *   buffer - I/O buffer used to access the passwd file
+ *   buflen - The size of the I/O buffer in bytes
+ *
+ * Returned Value:
+ *   < 0 :  An error has occurred.
+ *   = 0 :  No entry with this name was found.
+ *   = 1 :  The entry with this name was found.
+ *
+ ****************************************************************************/
+
+int pwd_findby_index(int index, FAR struct passwd *entry,
+                     FAR char *buffer, size_t buflen)
+{
+  return pwd_foreach(pwd_match_index, (uintptr_t)index,
+                     entry, buffer, buflen);
+}
diff --git a/libs/libc/pwd/lib_getpwent.c b/libs/libc/pwd/lib_getpwent.c
new file mode 100644
index 0000000000..53ac0808fe
--- /dev/null
+++ b/libs/libc/pwd/lib_getpwent.c
@@ -0,0 +1,165 @@
+/****************************************************************************
+ * libs/libc/pwd/lib_getpwent.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <string.h>
+#include <pwd.h>
+#include <errno.h>
+
+#include "pwd/lib_pwd.h"
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: setpwent
+ *
+ * Description:
+ *   The setpwent() function rewinds to the beginning of the password
+ *   database.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void setpwent(void)
+{
+  g_passwd_index = 0;
+}
+
+/****************************************************************************
+ * Name: endpwent
+ *
+ * Description:
+ *   The endpwent() function is used to close the password database after
+ *   all processing has been performed.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   None
+ *
+ ****************************************************************************/
+
+void endpwent(void)
+{
+  g_passwd_index = 0;
+}
+
+/****************************************************************************
+ * Name: getpwent
+ *
+ * Description:
+ *   The getpwent() function returns a pointer to a structure
+ *   containing the broken-out fields of a record from the password
+ *   database.
+ *
+ * Input Parameters:
+ *   None.
+ *
+ * Returned Value:
+ *   The getpwent() function returns a pointer to a passwd structure,
+ *   or NULL if there are no more entries or an error occurred.  If an
+ *   error occurs, errno is set to indicate the error.  If one wants
+ *   to check errno after the call, it should be set to zero before
+ *   the call.
+ *
+ ****************************************************************************/
+
+FAR struct passwd *getpwent(void)
+{
+  FAR struct passwd *pwd;
+  getpwent_r(&g_passwd, g_passwd_buffer,
+             CONFIG_LIBC_PASSWD_LINESIZE, &pwd);
+  return pwd;
+}
+
+/****************************************************************************
+ * Name: getpwent_r
+ *
+ * Description:
+ *   The functions getpwent_r() are the reentrant versions of getpwent().
+ *   The former reads the next passwd entry from the stream
+ *   initialized by setpwent().
+ *
+ * Input Parameters:
+ *   pwd     - contains the struct passwd that was read from the stream,
+ *             if any.
+ *   buf     - contains additional strings, if any.
+ *   buflen  - specifies the size of buf.
+ *   *result - returns a pointer to the struct passwd in *pwd.
+ *
+ * Returned Value:
+ *   On success, return 0, and *pwbufp shall contain a pointer to the result.
+ *   On failure, *pwbufp shall contain NULL. return an error an follows:
+ *     ENOENT: No more password entries.
+ *     ERANGE: Not enough buffer space. Specify a larger buffer and
+ *             try again.
+ *
+ ****************************************************************************/
+
+int getpwent_r(FAR struct passwd *pwd,
+               FAR char *buf, size_t buflen,
+               FAR struct passwd **result)
+{
+  int ret;
+#ifdef CONFIG_LIBC_PASSWD_FILE
+  ret = pwd_findby_index(g_passwd_index, pwd, buf, buflen);
+  if (ret != 1)
+    {
+      *result = NULL;
+      return ret < 0 ? ret : ENOENT;
+    }
+
+  *result = pwd;
+  g_passwd_index++;
+  return OK;
+#else
+  if (g_passwd_index != 0)
+    {
+      /* The only known user is 'root', if index in not 0. Thus, report
+       * back that no match was found.
+       */
+
+      *result = NULL;
+      return ENOENT;
+    }
+
+  ret = getpwbuf_r(ROOT_UID, ROOT_GID, ROOT_NAME, ROOT_NAME, ROOT_DIR,
+                    ROOT_SHELL, pwd, buf, buflen, result);
+  if (ret == 0)
+    {
+      g_passwd_index++;
+    }
+
+  return ret;
+#endif
+}
diff --git a/libs/libc/pwd/lib_pwd.h b/libs/libc/pwd/lib_pwd.h
index 582616c3ee..5b73a2e14b 100644
--- a/libs/libc/pwd/lib_pwd.h
+++ b/libs/libc/pwd/lib_pwd.h
@@ -58,6 +58,7 @@ extern "C"
 
 /* Data for non-reentrant group functions */
 
+EXTERN int g_passwd_index;
 EXTERN struct passwd g_passwd;
 EXTERN char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE];
 
@@ -78,6 +79,8 @@ int pwd_findby_name(FAR const char *uname, FAR struct passwd *entry,
                     FAR char *buffer, size_t buflen);
 int pwd_findby_uid(uid_t uid, FAR struct passwd *entry, FAR char *buffer,
                    size_t buflen);
+int pwd_findby_index(int index, FAR struct passwd *entry,
+                     FAR char *buffer, size_t buflen)
 #endif
 
 #undef EXTERN
diff --git a/libs/libc/pwd/lib_pwd_globals.c b/libs/libc/pwd/lib_pwd_globals.c
index 12deca175a..f6488d60e7 100644
--- a/libs/libc/pwd/lib_pwd_globals.c
+++ b/libs/libc/pwd/lib_pwd_globals.c
@@ -32,6 +32,7 @@
 
 /* Data for non-reentrant group functions */
 
+int g_passwd_index;
 struct passwd g_passwd;
 char g_passwd_buffer[CONFIG_LIBC_PASSWD_LINESIZE];
 


[nuttx] 07/12: sysconf: add _SC_THREAD_THREADS_MAX response

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit ed705f9cb371caba68ff8f4e0d127ab0dc3916c7
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Mon Jun 26 10:39:32 2023 +0800

    sysconf: add _SC_THREAD_THREADS_MAX response
    
    fix ltp_pthread_create_s_c1 test get wrong PTHREAD_THREADS_MAX.
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 libs/libc/unistd/lib_sysconf.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/libs/libc/unistd/lib_sysconf.c b/libs/libc/unistd/lib_sysconf.c
index aab4950ef8..f0fde4bfe2 100644
--- a/libs/libc/unistd/lib_sysconf.c
+++ b/libs/libc/unistd/lib_sysconf.c
@@ -249,6 +249,11 @@ long sysconf(int name)
       case _SC_THREAD_STACK_MIN:
         return CONFIG_PTHREAD_STACK_MIN;
 
+      /* threads limit to tcb_s->group->tg_nmembers(unint_8) */
+
+      case _SC_THREAD_THREADS_MAX:
+        return UINT8_MAX;
+
       default:
 #if 0 /* Assume valid but not implemented for the time being */
         errcode = EINVAL;


[nuttx] 05/12: sched: inherit parent priority by default

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit b2a9c6a3e563ad4f57b0539b6f99dad3ec2a8c3c
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Sun Jun 25 14:37:31 2023 +0800

    sched: inherit parent priority by default
    
    fix ltp pthread_cond_wait_1 test question, child should inherit parent
    priority by default.
    nsh> ltp_pthread_cond_wait_1
    Error: the policy or priority not correct
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 sched/pthread/pthread_create.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c
index a158af4518..df054c9cd2 100644
--- a/sched/pthread/pthread_create.c
+++ b/sched/pthread/pthread_create.c
@@ -185,14 +185,21 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
   pid_t pid;
   int ret;
   bool group_joined = false;
+  pthread_attr_t default_attr = g_default_pthread_attr;
 
   DEBUGASSERT(trampoline != NULL);
 
+  parent = this_task();
+  DEBUGASSERT(parent != NULL);
+
   /* If attributes were not supplied, use the default attributes */
 
   if (!attr)
     {
-      attr = &g_default_pthread_attr;
+      /* Inherit parent priority by default */
+
+      default_attr.priority = parent->sched_priority;
+      attr = &default_attr;
     }
 
   /* Allocate a TCB for the new task. */
@@ -395,9 +402,6 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
     }
 #endif
 
-  parent = this_task();
-  DEBUGASSERT(parent != NULL);
-
   /* Configure the TCB for a pthread receiving on parameter
    * passed by value
    */


[nuttx] 01/12: vfs: return OK when fsync dir

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit f2844a2e3cb9fbeb20b5bb1fa66c12ec2690adc2
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Tue Jun 13 11:11:08 2023 +0800

    vfs: return OK when fsync dir
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 fs/vfs/fs_dir.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/fs/vfs/fs_dir.c b/fs/vfs/fs_dir.c
index 8568628457..d2cb4c5c3c 100644
--- a/fs/vfs/fs_dir.c
+++ b/fs/vfs/fs_dir.c
@@ -546,12 +546,15 @@ static off_t dir_seek(FAR struct file *filep, off_t offset, int whence)
 static int dir_ioctl(FAR struct file *filep, int cmd, unsigned long arg)
 {
   FAR struct fs_dirent_s *dir = filep->f_priv;
-  int ret = -ENOTTY;
+  int ret = OK;
 
   if (cmd == FIOC_FILEPATH)
     {
       strlcpy((FAR char *)(uintptr_t)arg, dir->fd_path, PATH_MAX);
-      ret = OK;
+    }
+  else if (cmd != BIOC_FLUSH)
+    {
+      ret = -ENOTTY;
     }
 
   return ret;


[nuttx] 02/12: malloc: set errno to ENOMEM when malloc fail

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a551be4ee2686735f9b8f7490c0c882c902cbf6d
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Thu Jun 15 10:38:38 2023 +0800

    malloc: set errno to ENOMEM when malloc fail
    
    fix LTP case ltp_threads_pthread_cond_init_s_c error:
    "Test ltp_threads_pthread_cond_init_s_c unresolved: got 38
    (Invalid system call number) on line 236 (Memory not full)"
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
    
    ltp: fix review questions
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 mm/umm_heap/umm_malloc.c   | 12 ++++++++++--
 mm/umm_heap/umm_memalign.c | 12 ++++++++++--
 mm/umm_heap/umm_realloc.c  | 12 ++++++++++--
 mm/umm_heap/umm_zalloc.c   | 12 ++++++++++--
 4 files changed, 40 insertions(+), 8 deletions(-)

diff --git a/mm/umm_heap/umm_malloc.c b/mm/umm_heap/umm_malloc.c
index 261f0d8460..97a12c2204 100644
--- a/mm/umm_heap/umm_malloc.c
+++ b/mm/umm_heap/umm_malloc.c
@@ -26,7 +26,7 @@
 
 #include <stdlib.h>
 #include <unistd.h>
-
+#include <errno.h>
 #include <nuttx/mm/mm.h>
 
 #include "umm_heap/umm_heap.h"
@@ -57,8 +57,16 @@ FAR void *malloc(size_t size)
 
   return memalign(sizeof(FAR void *), size);
 #else
+  FAR void *ret;
+
   /* Use mm_malloc() because it implements the clear */
 
-  return mm_malloc(USR_HEAP, size);
+  ret = mm_malloc(USR_HEAP, size);
+  if (!ret)
+    {
+      set_errno(ENOMEM);
+    }
+
+  return ret;
 #endif
 }
diff --git a/mm/umm_heap/umm_memalign.c b/mm/umm_heap/umm_memalign.c
index 378ce6e428..f67cfc0cff 100644
--- a/mm/umm_heap/umm_memalign.c
+++ b/mm/umm_heap/umm_memalign.c
@@ -26,7 +26,7 @@
 
 #include <stdlib.h>
 #include <unistd.h>
-
+#include <errno.h>
 #include <nuttx/mm/mm.h>
 
 #include "umm_heap/umm_heap.h"
@@ -86,6 +86,14 @@ FAR void *memalign(size_t alignment, size_t size)
 
   return mem;
 #else
-  return mm_memalign(USR_HEAP, alignment, size);
+  FAR void *ret;
+
+  ret = mm_memalign(USR_HEAP, alignment, size);
+  if (!ret)
+    {
+      set_errno(ENOMEM);
+    }
+
+  return ret;
 #endif
 }
diff --git a/mm/umm_heap/umm_realloc.c b/mm/umm_heap/umm_realloc.c
index 2db289db14..f3c221b528 100644
--- a/mm/umm_heap/umm_realloc.c
+++ b/mm/umm_heap/umm_realloc.c
@@ -26,7 +26,7 @@
 
 #include <stdlib.h>
 #include <unistd.h>
-
+#include <errno.h>
 #include <nuttx/mm/mm.h>
 
 #include "umm_heap/umm_heap.h"
@@ -88,6 +88,14 @@ FAR void *realloc(FAR void *oldmem, size_t size)
 
   return mem;
 #else
-  return mm_realloc(USR_HEAP, oldmem, size);
+  FAR void *ret;
+
+  ret = mm_realloc(USR_HEAP, oldmem, size);
+  if (!ret)
+    {
+      set_errno(ENOMEM);
+    }
+
+  return ret;
 #endif
 }
diff --git a/mm/umm_heap/umm_zalloc.c b/mm/umm_heap/umm_zalloc.c
index 82d0906ae4..0ff400d7fb 100644
--- a/mm/umm_heap/umm_zalloc.c
+++ b/mm/umm_heap/umm_zalloc.c
@@ -26,7 +26,7 @@
 
 #include <stdlib.h>
 #include <string.h>
-
+#include <errno.h>
 #include <nuttx/mm/mm.h>
 
 #include "umm_heap/umm_heap.h"
@@ -63,8 +63,16 @@ FAR void *zalloc(size_t size)
 
   return mem;
 #else
+  FAR void *ret;
+
   /* Use mm_zalloc() because it implements the clear */
 
-  return mm_zalloc(USR_HEAP, size);
+  ret = mm_zalloc(USR_HEAP, size);
+  if (!ret)
+    {
+      set_errno(ENOMEM);
+    }
+
+  return ret;
 #endif
 }


[nuttx] 10/12: sched: inherit parent priority by default, except idle

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 30367fd4cdc86d5ff48e87f2ba3bdc06ff5f18f3
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Thu Jun 29 17:08:26 2023 +0800

    sched: inherit parent priority by default, except idle
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
    
    asdfas
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 sched/pthread/pthread_create.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/sched/pthread/pthread_create.c b/sched/pthread/pthread_create.c
index df054c9cd2..ae05ea17c3 100644
--- a/sched/pthread/pthread_create.c
+++ b/sched/pthread/pthread_create.c
@@ -196,9 +196,13 @@ int nx_pthread_create(pthread_trampoline_t trampoline, FAR pthread_t *thread,
 
   if (!attr)
     {
-      /* Inherit parent priority by default */
+      /* Inherit parent priority by default. except idle */
+
+      if (!is_idle_task(parent))
+        {
+          default_attr.priority = parent->sched_priority;
+        }
 
-      default_attr.priority = parent->sched_priority;
       attr = &default_attr;
     }
 


[nuttx] 03/12: signal: add SIGWINCH define

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 9a60d7bb49112a33fef89e0531b5893031106a01
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Tue Jun 20 14:40:29 2023 +0800

    signal: add SIGWINCH define
    
    SIGWINCH used in ltp sigaction/16-1.c testcase.
    ltp/testcases/open_posix_testsuite/conformance/interfaces/sigaction/16-1.c:79:3:
    error: ‘SIGWINCH’ undeclared here (not in a function); did you mean ‘SIGINT’?
       79 |  {SIGWINCH, "SIGWINCH", 0},
          |   ^~~~~~~~
          |   SIGINT
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 include/signal.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/signal.h b/include/signal.h
index 7318a334d3..f60e11ead0 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -163,6 +163,7 @@
 #define SIGXFSZ         25
 #define SIGVTALRM       26
 #define SIGPROF         27
+#define SIGWINCH        28
 #define SIGPOLL         29
 
 #define SIGIO           SIGPOLL


[nuttx] 09/12: Add _POSIX_THREAD_PRIORITY_SCHEDULING define

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 3721af647a94f98dd3174b8e79d79712e8d6ab27
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Mon Jun 26 16:35:09 2023 +0800

    Add _POSIX_THREAD_PRIORITY_SCHEDULING define
    
    fix ltp_pthread_rwlock_rdlock_2_2 testcase error:
    nsh> ltp_pthread_rwlock_rdlock_2_2
    Posix Thread Execution Scheduling not supported
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 include/unistd.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/unistd.h b/include/unistd.h
index a3c6ace08d..4b2666a10e 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -65,6 +65,7 @@
 #define _POSIX_PRIORITIZED_IO _POSIX_VERSION
 #define _POSIX_CPUTIME _POSIX_VERSION
 #define _POSIX_THREAD_CPUTIME _POSIX_VERSION
+#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION
 
 #ifdef CONFIG_FS_AIO
 #  define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION


[nuttx] 11/12: sigaltstack: Add initial implementation of sigaltstack

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 4ecff53e2c55325e93eee581678bf27087097afd
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Mon Jun 26 14:42:21 2023 +0800

    sigaltstack: Add initial implementation of sigaltstack
    
    fix ltp testcase compile error:
    ltp/testcases/open_posix_testsuite/conformance/definitions/signal_h/31-1-buildonly.c:16:13: \
    error: ‘sigaltstack’ undeclared (first use in this function)
       16 |  dummyvar = sigaltstack;
          |             ^~~~~~~~~~~
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 include/signal.h                |  1 +
 libs/libc/signal/Make.defs      |  3 +-
 libs/libc/signal/sig_altstack.c | 73 +++++++++++++++++++++++++++++++++++++++++
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/include/signal.h b/include/signal.h
index 5f8421aef3..f60a834201 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -404,6 +404,7 @@ int  sigtimedwait(FAR const sigset_t *set, FAR struct siginfo *value,
                   FAR const struct timespec *timeout);
 int  sigsuspend(FAR const sigset_t *sigmask);
 int  sigwaitinfo(FAR const sigset_t *set, FAR struct siginfo *value);
+int  sigaltstack(FAR const stack_t *ss, FAR stack_t *oss);
 
 #undef EXTERN
 #ifdef __cplusplus
diff --git a/libs/libc/signal/Make.defs b/libs/libc/signal/Make.defs
index 8e7df2c69b..9c9d81f7ba 100644
--- a/libs/libc/signal/Make.defs
+++ b/libs/libc/signal/Make.defs
@@ -22,10 +22,9 @@
 
 CSRCS += sig_addset.c sig_delset.c sig_emptyset.c sig_fillset.c
 CSRCS += sig_nandset.c sig_andset.c sig_orset.c sig_xorset.c
-CSRCS += sig_isemptyset.c
+CSRCS += sig_isemptyset.c sig_killpg.c sig_altstack.c
 CSRCS += sig_hold.c sig_ignore.c sig_ismember.c sig_pause.c sig_psignal.c
 CSRCS += sig_raise.c sig_relse.c sig_set.c sig_signal.c sig_wait.c
-CSRCS += sig_killpg.c
 
 # Add the signal directory to the build
 
diff --git a/libs/libc/signal/sig_altstack.c b/libs/libc/signal/sig_altstack.c
new file mode 100644
index 0000000000..9d7ded47de
--- /dev/null
+++ b/libs/libc/signal/sig_altstack.c
@@ -0,0 +1,73 @@
+/****************************************************************************
+ * libs/libc/signal/sig_altstack.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <signal.h>
+#include <errno.h>
+#include <string.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: sigaltstack
+ *
+ * Description:
+ * The sigaltstack() function allows a process to define and examine the
+ * state of an alternate stack for signal handlers for the current thread.
+ * Signals that have been explicitly declared to execute on the alternate
+ * stack shall be delivered on the alternate stack.
+ *
+ ****************************************************************************/
+
+int sigaltstack(const stack_t *ss, stack_t *oss)
+{
+  if (ss)
+    {
+      if (ss->ss_flags & SS_DISABLE)
+        {
+          goto out;
+        }
+
+      if (ss->ss_size < MINSIGSTKSZ)
+        {
+          set_errno(ENOMEM);
+          return ERROR;
+        }
+
+      /* not support SS_ONSTACK now */
+
+      set_errno(EINVAL);
+      return ERROR;
+    }
+
+out:
+  if (oss)
+    {
+      memset(oss, 0, sizeof(*oss));
+      oss->ss_flags = SS_DISABLE;
+    }
+
+  return OK;
+}


[nuttx] 08/12: single: add SS_ONSTACK and SS_DISABLE define

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit 700cc5ab9004a562c4541a32c42ba78ac3643de6
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Mon Jun 26 11:12:05 2023 +0800

    single: add SS_ONSTACK and SS_DISABLE define
    
    fix ltp_sigaltstack_6_1 testcase comile error:
    iltp/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/6-1.c:41:28: \
    error: ‘SS_ONSTACK’ undeclared (first use in this function); did you mean ‘SA_ONSTACK’?
    ltp/testcases/open_posix_testsuite/conformance/interfaces/sigaltstack/8-1.c:41:28: \
    error: ‘SS_DISABLE’ undeclared (first use in this function
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 include/signal.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/include/signal.h b/include/signal.h
index ccaa198805..5f8421aef3 100644
--- a/include/signal.h
+++ b/include/signal.h
@@ -225,6 +225,11 @@
 #define MINSIGSTKSZ     CONFIG_PTHREAD_STACK_MIN     /* Smallest signal stack size */
 #define SIGSTKSZ        CONFIG_PTHREAD_STACK_DEFAULT /* Default signal stack size */
 
+/* define signal handlers stack on an alternate stack or the current thread */
+
+#define SS_ONSTACK      1
+#define SS_DISABLE      2
+
 /* Special values of sa_handler used by sigaction and sigset.  They are all
  * treated like NULL for now.  This is okay for SIG_DFL and SIG_IGN because
  * in NuttX, the default action for all signals is to ignore them.


[nuttx] 06/12: getrlimit: add RLIMIT_MEMLOCK define

Posted by xi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit c33e6528b15ee79e39e0829100e238e4d07e7a54
Author: yangyalei <ya...@xiaomi.com>
AuthorDate: Sun Jun 25 16:00:42 2023 +0800

    getrlimit: add RLIMIT_MEMLOCK define
    
    add RLIMIT_MEMLOCK define, enable compile mmap/18-1.c.
    ltp/testcases/open_posix_testsuite/conformance/interfaces/mmap/18-1.c:95:16: \
    error: ‘RLIMIT_MEMLOCK’ undeclared (first use in this function); did you mean ‘RLIMIT_STACK’?
    
    Signed-off-by: yangyalei <ya...@xiaomi.com>
---
 include/sys/resource.h | 1 +
 1 file changed, 1 insertion(+)

diff --git a/include/sys/resource.h b/include/sys/resource.h
index 0ce13783c4..494e9a1d28 100644
--- a/include/sys/resource.h
+++ b/include/sys/resource.h
@@ -57,6 +57,7 @@
 #define RLIMIT_NOFILE   5           /* Limit on number of open files */
 #define RLIMIT_STACK    6           /* Limit on stack size */
 #define RLIMIT_AS       7           /* Limit on address space size */
+#define RLIMIT_MEMLOCK  8           /* Limit on memory use */
 
 #if defined(CONFIG_FS_LARGEFILE)
 #  define RLIM_INFINITY    UINT64_MAX /* No limit */