mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
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 <hujun5@xiaomi.com>
This commit is contained in:
parent
35537cb1a7
commit
835c9c0f77
6 changed files with 4 additions and 157 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue