This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 835c9c0f777 binfmt: refactor loadable module cleanup mechanism
835c9c0f777 is described below
commit 835c9c0f77792f788ef7c6ae7b89633986c3c0f0
Author: hujun5 <[email protected]>
AuthorDate: Fri Mar 7 21:40:25 2025 +0800
binfmt: refactor loadable module cleanup mechanism
Remove deprecated group_exitinfo() function and related critical section
locking
from binfmt_exec.c, moving module unload setup directly into exec_module()
where
it integrates naturally with task activation, simplifying code flow and
reducing
unnecessary synchronization overhead.
Signed-off-by: hujun5 <[email protected]>
---
binfmt/binfmt_exec.c | 27 ------------
binfmt/binfmt_execmodule.c | 4 ++
include/nuttx/sched.h | 25 ------------
sched/group/CMakeLists.txt | 4 --
sched/group/Make.defs | 4 --
sched/group/group_exitinfo.c | 97 --------------------------------------------
6 files changed, 4 insertions(+), 157 deletions(-)
diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c
index e58d0ad8913..f97adfcb8a3 100644
--- a/binfmt/binfmt_exec.c
+++ b/binfmt/binfmt_exec.c
@@ -81,7 +81,6 @@ static int exec_internal(FAR const char *filename,
FAR const posix_spawnattr_t *attr, bool spawn)
{
FAR struct binary_s *bin;
- irqstate_t flags;
int pid;
int ret;
#ifndef CONFIG_BINFMT_LOADABLE
@@ -133,14 +132,6 @@ static int exec_internal(FAR const char *filename,
#endif
}
- /* Disable pre-emption so that the executed module does
- * not return until we get a chance to connect the on_exit
- * handler.
- */
-
- flags = enter_critical_section();
- sched_lock();
-
/* Then start the module */
pid = exec_module(bin, filename, argv, envp, actions, attr, spawn);
@@ -152,27 +143,9 @@ static int exec_internal(FAR const char *filename,
goto errout_with_lock;
}
-#ifdef CONFIG_BINFMT_LOADABLE
- /* Set up to unload the module (and free the binary_s structure)
- * when the task exists.
- */
-
- ret = group_exitinfo(pid, bin);
- if (ret < 0)
- {
- berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret);
- goto errout_with_lock;
- }
-
-#endif
-
- sched_unlock();
- leave_critical_section(flags);
return pid;
errout_with_lock:
- sched_unlock();
- leave_critical_section(flags);
unload_module(bin);
errout_with_bin:
#ifdef CONFIG_BINFMT_LOADABLE
diff --git a/binfmt/binfmt_execmodule.c b/binfmt/binfmt_execmodule.c
index 424678a1ec4..c8cd9f7b753 100644
--- a/binfmt/binfmt_execmodule.c
+++ b/binfmt/binfmt_execmodule.c
@@ -354,6 +354,10 @@ int exec_module(FAR struct binary_s *binp,
}
}
+#ifdef CONFIG_BINFMT_LOADABLE
+ tcb->group->tg_bininfo = binp;
+#endif
+
/* Then activate the task at the provided priority */
nxtask_activate(tcb);
diff --git a/include/nuttx/sched.h b/include/nuttx/sched.h
index 8a83aefc435..dc438899d17 100644
--- a/include/nuttx/sched.h
+++ b/include/nuttx/sched.h
@@ -1170,31 +1170,6 @@ void nxtask_abort_fork(FAR struct tcb_s *child, int
errcode);
size_t nxtask_argvstr(FAR struct tcb_s *tcb, FAR char *args, size_t size);
-/****************************************************************************
- * Name: group_exitinfo
- *
- * Description:
- * This function may be called to when a task is loaded into memory. It
- * will setup the to automatically unload the module when the task exits.
- *
- * Input Parameters:
- * pid - The task ID of the newly loaded task
- * bininfo - This structure allocated with kmm_malloc(). This memory
- * persists until the task exits and will be used unloads
- * the module from memory.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_BINFMT_LOADABLE
-struct binary_s; /* Forward reference */
-int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo);
-#endif
-
/****************************************************************************
* Name: nxsched_get_param
*
diff --git a/sched/group/CMakeLists.txt b/sched/group/CMakeLists.txt
index 6211a2c7c66..dcb96d6952d 100644
--- a/sched/group/CMakeLists.txt
+++ b/sched/group/CMakeLists.txt
@@ -59,10 +59,6 @@ if(CONFIG_SIG_SIGSTOP_ACTION)
list(APPEND SRCS group_suspendchildren.c group_continue.c)
endif()
-if(CONFIG_BINFMT_LOADABLE)
- list(APPEND SRCS group_exitinfo.c)
-endif()
-
if(CONFIG_MM_KERNEL_HEAP)
list(APPEND SRCS group_malloc.c group_realloc.c group_zalloc.c group_free.c)
endif()
diff --git a/sched/group/Make.defs b/sched/group/Make.defs
index 336beda8f21..98ea6d09c6f 100644
--- a/sched/group/Make.defs
+++ b/sched/group/Make.defs
@@ -47,10 +47,6 @@ ifeq ($(CONFIG_SIG_SIGSTOP_ACTION),y)
CSRCS += group_suspendchildren.c group_continue.c
endif
-ifeq ($(CONFIG_BINFMT_LOADABLE),y)
-CSRCS += group_exitinfo.c
-endif
-
ifeq ($(CONFIG_MM_KERNEL_HEAP),y)
CSRCS += group_malloc.c group_realloc.c group_zalloc.c group_free.c
endif
diff --git a/sched/group/group_exitinfo.c b/sched/group/group_exitinfo.c
deleted file mode 100644
index e82a72e420c..00000000000
--- a/sched/group/group_exitinfo.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/****************************************************************************
- * sched/group/group_exitinfo.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 <sys/types.h>
-#include <assert.h>
-#include <errno.h>
-
-#include <nuttx/sched.h>
-#include <nuttx/spinlock.h>
-#include <nuttx/binfmt/binfmt.h>
-
-#include "sched/sched.h"
-#include "group/group.h"
-
-#ifdef CONFIG_BINFMT_LOADABLE
-
-/****************************************************************************
- * Public Functions
- ****************************************************************************/
-
-/****************************************************************************
- * Name: group_exitinfo
- *
- * Description:
- * This function may be called to when a task is loaded into memory. It
- * will setup the to automatically unload the module when the task exits.
- *
- * Input Parameters:
- * pid - The task ID of the newly loaded task
- * bininfo - This structure allocated with kmm_malloc(). This memory
- * persists until the task exits and will be used unloads
- * the module from memory.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo)
-{
- FAR struct tcb_s *tcb;
- FAR struct task_group_s *group;
- irqstate_t flags;
-
- DEBUGASSERT(bininfo != NULL);
- flags = enter_critical_section();
-
- /* Get the TCB associated with the PID */
-
- tcb = nxsched_get_tcb(pid);
- if (tcb == NULL)
- {
- leave_critical_section(flags);
- return -ESRCH;
- }
-
- /* Get the group that this task belongs to */
-
- group = tcb->group;
- DEBUGASSERT(group != NULL && group->tg_bininfo == NULL);
-
- /* Save the binary info for use when the task exits */
-
- group->tg_bininfo = bininfo;
-
- leave_critical_section(flags);
- return OK;
-}
-
-#endif /* CONFIG_BINFMT_LOADABLE */