This is an automated email from the ASF dual-hosted git repository. GUIDINGLI pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/nuttx.git
commit ed99c1ced93a39a24efe7d990bf357bb61bade79 Author: yintao <[email protected]> AuthorDate: Wed Sep 17 20:34:44 2025 +0800 net: add psock_mmap() Move the dispatch to si_mmap out of fs/socket into net/socket as psock_mmap(), alongside the other psock_*() operations, so that kernel code holding a struct socket can map it too. Signed-off-by: yintao <[email protected]> Signed-off-by: Bowen Wang <[email protected]> --- fs/socket/socket.c | 14 +-------- include/nuttx/net/net.h | 14 +++++++++ net/socket/CMakeLists.txt | 3 +- net/socket/Make.defs | 2 +- net/socket/net_mmap.c | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 90 insertions(+), 15 deletions(-) diff --git a/fs/socket/socket.c b/fs/socket/socket.c index a9474886821..32f6c0255df 100644 --- a/fs/socket/socket.c +++ b/fs/socket/socket.c @@ -156,19 +156,7 @@ static int sock_file_ioctl(FAR struct file *filep, int cmd, static int sock_file_mmap(FAR struct file *filep, FAR struct mm_map_entry_s *map) { - struct socket *psock = filep->f_priv; - - DEBUGASSERT(psock != NULL && map != NULL); - - /* Let the address family's mmap() method handle the operation */ - - DEBUGASSERT(psock->s_sockif != NULL); - if (psock->s_sockif->si_mmap == NULL) - { - return -EOPNOTSUPP; - } - - return psock->s_sockif->si_mmap(psock, map); + return psock_mmap(filep->f_priv, map); } static int sock_file_poll(FAR struct file *filep, FAR struct pollfd_s *fds, diff --git a/include/nuttx/net/net.h b/include/nuttx/net/net.h index 4872b1c2dcd..bdd12131bba 100644 --- a/include/nuttx/net/net.h +++ b/include/nuttx/net/net.h @@ -1374,6 +1374,20 @@ int psock_dup2(FAR struct socket *psock1, FAR struct socket *psock2); int psock_fstat(FAR struct socket *psock, FAR struct stat *buf); +/**************************************************************************** + * Name: psock_mmap + * + * Description: + * Perform mmap operations on socket. + * + * Returned Value: + * On success, returns the number of new socket. On any error, + * a negated errno value is returned. + * + ****************************************************************************/ + +int psock_mmap(FAR struct socket *psock, FAR struct mm_map_entry_s *map); + /**************************************************************************** * Name: psock_sendfile * diff --git a/net/socket/CMakeLists.txt b/net/socket/CMakeLists.txt index 776b190c725..2e6591e62c6 100644 --- a/net/socket/CMakeLists.txt +++ b/net/socket/CMakeLists.txt @@ -42,7 +42,8 @@ set(SRCS net_dup2.c net_sockif.c net_poll.c - net_fstat.c) + net_fstat.c + net_mmap.c) # Socket options diff --git a/net/socket/Make.defs b/net/socket/Make.defs index 84f9527633f..2f414abb3aa 100644 --- a/net/socket/Make.defs +++ b/net/socket/Make.defs @@ -25,7 +25,7 @@ SOCK_CSRCS += accept.c bind.c connect.c getsockname.c getpeername.c SOCK_CSRCS += listen.c recv.c recvfrom.c send.c sendto.c socket.c SOCK_CSRCS += socketpair.c net_close.c recvmsg.c sendmsg.c shutdown.c -SOCK_CSRCS += net_dup2.c net_sockif.c net_poll.c net_fstat.c +SOCK_CSRCS += net_dup2.c net_sockif.c net_poll.c net_fstat.c net_mmap.c # Socket options diff --git a/net/socket/net_mmap.c b/net/socket/net_mmap.c new file mode 100644 index 00000000000..978cc5161dd --- /dev/null +++ b/net/socket/net_mmap.c @@ -0,0 +1,72 @@ +/**************************************************************************** + * net/socket/net_mmap.c + * + * SPDX-License-Identifier: Apache-2.0 + * + * 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 <assert.h> +#include <errno.h> + +#include <nuttx/net/net.h> + +#include "socket/socket.h" + +/**************************************************************************** + * Public Functions + ****************************************************************************/ + +/**************************************************************************** + * Name: psock_mmap + * + * Description: + * Redirect the mmap operation on socket descriptors to the address family- + * specific mmap implementation. This function serves as a dispatcher that + * invokes the socket interface's mmap method if it exists. + * + * Input Parameters: + * psock - An instance of the internal socket structure. + * map - Pointer to the memory mapping entry containing mapping + * details such as address, length, protection flags, + * and file offset. + * + * Returned Value: + * 0: Success; Negated errno on failure + * + ****************************************************************************/ + +int psock_mmap(FAR struct socket *psock, FAR struct mm_map_entry_s *map) +{ + DEBUGASSERT(psock != NULL && map != NULL); + + /* Let the address family's mmap() method handle the operation */ + + DEBUGASSERT(psock->s_sockif != NULL); + if (psock->s_sockif->si_mmap == NULL) + { + return -EOPNOTSUPP; + } + + return psock->s_sockif->si_mmap(psock, map); +}
