libc: Prefer to implement memfd on top of shm
since shm can work in protected and kernel mode too Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
f930b4f6f5
commit
43f9abf84f
@ -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.
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user