You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by pk...@apache.org on 2023/06/20 17:14:26 UTC

[nuttx] branch master updated (f930b4f6f5 -> 1a06f7a2c9)

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

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


    from f930b4f6f5 Fix Kconfig style
     new 43f9abf84f libc: Prefer to implement memfd on top of shm
     new 1a06f7a2c9 libc: memfd_create should create /tmp/memfd/ before creating file

The 2 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:
 libs/libc/misc/Kconfig     | 18 +++++++++++++++++-
 libs/libc/misc/lib_memfd.c | 27 +++++++++++++++++++--------
 2 files changed, 36 insertions(+), 9 deletions(-)


[nuttx] 02/02: libc: memfd_create should create /tmp/memfd/ before creating file

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

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

commit 1a06f7a2c9d738a146f2f5f28d91e2229707df7d
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 11 23:55:51 2023 +0800

    libc: memfd_create should create /tmp/memfd/ before creating file
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/misc/lib_memfd.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/libs/libc/misc/lib_memfd.c b/libs/libc/misc/lib_memfd.c
index 828874d7fc..98db24fa43 100644
--- a/libs/libc/misc/lib_memfd.c
+++ b/libs/libc/misc/lib_memfd.c
@@ -23,6 +23,7 @@
  ****************************************************************************/
 
 #include <sys/mman.h>
+#include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
@@ -56,6 +57,7 @@ int memfd_create(FAR const char *name, unsigned int flags)
 #  ifdef CONFIG_LIBC_MEMFD_SHMFS
   return shm_open(path, O_RDWR | flags, 0660);
 #  else
+  mkdir(LIBC_MEM_FD_VFS_PATH, 0666);
   return open(path, O_RDWR | flags, 0660);
 #  endif
 #endif


[nuttx] 01/02: libc: Prefer to implement memfd on top of shm

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

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

commit 43f9abf84f7c2b19b74fd0a37b2b5855f1c31136
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Mon Jun 12 00:03:55 2023 +0800

    libc: Prefer to implement memfd on top of shm
    
    since shm can work in protected and kernel mode too
    
    Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
 libs/libc/misc/Kconfig     | 18 +++++++++++++++++-
 libs/libc/misc/lib_memfd.c | 25 +++++++++++++++++--------
 2 files changed, 34 insertions(+), 9 deletions(-)

diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig
index ba8d50a0ee..f94e97f776 100644
--- a/libs/libc/misc/Kconfig
+++ b/libs/libc/misc/Kconfig
@@ -81,9 +81,25 @@ config LIBC_FTOK_VFS_PATH
 	---help---
 		The relative path to where ftok will exist in the root namespace.
 
+choice
+	prompt "Select memfd implementation"
+
+config LIBC_MEMFD_SHMFS
+	bool "memfd base on shmfs"
+	depends on FS_SHMFS
+
+config LIBC_MEMFD_TMPFS
+	bool "memfd base on tmpfs"
+	depends on FS_TMPFS
+
+config LIBC_MEMFD_ERROR
+	bool "memfd return error"
+
+endchoice
+
 config LIBC_MEM_FD_VFS_PATH
 	string "Relative path to memfd storage"
 	default "memfd"
-	depends on FS_TMPFS
+	depends on !LIBC_MEMFD_ERROR
 	---help---
 		The relative path to where memfd will exist in the tmpfs namespace.
diff --git a/libs/libc/misc/lib_memfd.c b/libs/libc/misc/lib_memfd.c
index d3cc8c6b8f..828874d7fc 100644
--- a/libs/libc/misc/lib_memfd.c
+++ b/libs/libc/misc/lib_memfd.c
@@ -32,8 +32,13 @@
  * Pre-processor Definitions
  ****************************************************************************/
 
-#define LIBC_MEM_FD_VFS_PATH \
-          CONFIG_LIBC_TMPDIR "/" CONFIG_LIBC_MEM_FD_VFS_PATH "/%s"
+#ifdef CONFIG_LIBC_MEMFD_TMPFS
+#  define LIBC_MEM_FD_VFS_PATH CONFIG_LIBC_TMPDIR "/" CONFIG_LIBC_MEM_FD_VFS_PATH
+#else
+#  define LIBC_MEM_FD_VFS_PATH CONFIG_LIBC_MEM_FD_VFS_PATH
+#endif
+
+#define LIBC_MEM_FD_VFS_PATH_FMT LIBC_MEM_FD_VFS_PATH "/%s"
 
 /****************************************************************************
  * Public Functions
@@ -41,13 +46,17 @@
 
 int memfd_create(FAR const char *name, unsigned int flags)
 {
-#ifdef CONFIG_FS_TMPFS
-  char path[PATH_MAX];
-
-  snprintf(path, sizeof(path), LIBC_MEM_FD_VFS_PATH, name);
-  return open(path, O_RDWR | flags);
-#else
+#ifdef CONFIG_LIBC_MEMFD_ERROR
   set_errno(ENOSYS);
   return -1;
+#else
+  char path[PATH_MAX];
+
+  snprintf(path, sizeof(path), LIBC_MEM_FD_VFS_PATH_FMT, name);
+#  ifdef CONFIG_LIBC_MEMFD_SHMFS
+  return shm_open(path, O_RDWR | flags, 0660);
+#  else
+  return open(path, O_RDWR | flags, 0660);
+#  endif
 #endif
 }