drivers/misc/optee: Add mmap shm op + remove memfd

The previous approach with memfd has 3 problems:
1) The close operation on the memfd isn't tied with optee_shm_close,
   therefore close(fd) doesn't free the optee_shm struct allocated
   by the kernel.

2) The kernel unnecessarily maps the file descriptor to its memory,
   however only userspace should need to do that.

3) Since the kernel doesn't need to map the file descriptor we
   don't need to unmap it.

To use anonymous mapping, the prototype of map_anonymous() was
moved from fs/mmap/fs_anonmap.h to include/nuttx/fs/fs.h. Since
fs_anonmap.h didn't contain any other information it is deleted.

A type from fs/mmap/fs_rammap.h was moved to the public :
include/nuttx/fs/fs.h as well.

Signed-off-by: Theodore Karatapanis <tkaratapanis@census-labs.com>
This commit is contained in:
Theodore Karatapanis
2025-08-06 02:29:33 +08:00
committed by Xiang Xiao
parent cbdd3ac39b
commit 95ca3e7ca5
7 changed files with 111 additions and 119 deletions
+25
View File
@@ -1938,6 +1938,31 @@ int file_pipe(FAR struct file *filep[2], size_t bufsize, int flags);
int nx_mkfifo(FAR const char *pathname, mode_t mode, size_t bufsize);
#endif
/****************************************************************************
* Name: map_anonymous
*
* Description:
* Support simulation of private anonymous mapping by allocating memory
* from heap
*
* Input Parameters:
* map Input struct containing user request
* kernel fs_heap_zalloc or kumm_zalloc
*
* Returned Value:
* On success returns 0. Otherwise negated errno is returned appropriately.
*
* ENOMEM
* Insufficient memory is available to simulate mapping
*
****************************************************************************/
#ifdef CONFIG_FS_ANONMAP
int map_anonymous(FAR struct mm_map_entry_s *entry, bool kernel);
#else
# define map_anonymous(entry, kernel) (-ENOSYS)
#endif /* CONFIG_FS_ANONMAP */
#undef EXTERN
#if defined(__cplusplus)
}
+1
View File
@@ -382,6 +382,7 @@ struct tee_iocl_supp_send_arg
#define TEE_SHM_ALLOC (1 << 0) /* Kernel-malloced and must freed */
#define TEE_SHM_REGISTER (1 << 1) /* Registered with TEE OS */
#define TEE_SHM_USER_MAP (1 << 2) /* Will be used by userspace after mmap */
/* struct tee_ioctl_shm_register_data - Shared memory register argument
* addr: [in] Start address of shared memory to register