2009-06-18 02:45:48 +08:00
|
|
|
/****************************************************************************
|
2019-01-27 01:18:45 +08:00
|
|
|
* binfmt/binfmt_unloadmodule.c
|
2009-06-18 02:45:48 +08:00
|
|
|
*
|
2024-09-09 15:12:59 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* 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.
|
2009-06-18 02:45:48 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2009-12-16 01:06:59 +08:00
|
|
|
#include <sys/mman.h>
|
2009-06-18 02:45:48 +08:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sched.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2023-01-27 19:45:03 +08:00
|
|
|
#include <nuttx/addrenv.h>
|
2013-03-10 05:12:20 +08:00
|
|
|
#include <nuttx/kmalloc.h>
|
2012-10-25 04:19:44 +08:00
|
|
|
#include <nuttx/binfmt/binfmt.h>
|
2009-06-18 02:45:48 +08:00
|
|
|
|
2015-11-14 21:29:47 +08:00
|
|
|
#include "binfmt.h"
|
2009-06-18 02:45:48 +08:00
|
|
|
|
2009-06-18 05:15:31 +08:00
|
|
|
#ifndef CONFIG_BINFMT_DISABLE
|
|
|
|
|
2009-06-18 02:45:48 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
2009-06-18 04:25:27 +08:00
|
|
|
/****************************************************************************
|
2009-06-18 02:45:48 +08:00
|
|
|
* Public Functions
|
2009-06-18 04:25:27 +08:00
|
|
|
****************************************************************************/
|
2009-06-18 02:45:48 +08:00
|
|
|
|
2009-06-18 04:25:27 +08:00
|
|
|
/****************************************************************************
|
2009-06-18 02:45:48 +08:00
|
|
|
* Name: unload_module
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Unload a (non-executing) module from memory. If the module has
|
2012-10-30 03:32:05 +08:00
|
|
|
* been started (via exec_module) and has not exited, calling this will
|
|
|
|
* be fatal.
|
|
|
|
*
|
2014-05-09 06:58:10 +08:00
|
|
|
* However, this function must be called after the module exits. How
|
2012-10-30 03:32:05 +08:00
|
|
|
* this is done is up to your logic. Perhaps you register it to be
|
|
|
|
* called by on_exit()?
|
2009-06-18 02:45:48 +08:00
|
|
|
*
|
2009-06-18 04:25:27 +08:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2009-06-18 02:45:48 +08:00
|
|
|
|
2014-05-09 06:58:10 +08:00
|
|
|
int unload_module(FAR struct binary_s *binp)
|
2009-06-18 02:45:48 +08:00
|
|
|
{
|
2012-12-20 01:54:26 +08:00
|
|
|
int ret;
|
2014-04-14 06:22:22 +08:00
|
|
|
|
2012-10-30 03:32:05 +08:00
|
|
|
if (binp)
|
2009-06-18 02:45:48 +08:00
|
|
|
{
|
2014-05-09 06:58:10 +08:00
|
|
|
/* Perform any format-specific unload operations */
|
|
|
|
|
|
|
|
if (binp->unload)
|
|
|
|
{
|
|
|
|
ret = binp->unload(binp);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
2016-06-12 05:50:49 +08:00
|
|
|
berr("binp->unload() failed: %d\n", ret);
|
2017-10-03 05:30:55 +08:00
|
|
|
return ret;
|
2014-05-09 06:58:10 +08:00
|
|
|
}
|
|
|
|
}
|
2012-10-30 03:32:05 +08:00
|
|
|
|
|
|
|
/* Unmap mapped address spaces */
|
|
|
|
|
|
|
|
if (binp->mapped)
|
2009-06-18 02:45:48 +08:00
|
|
|
{
|
2016-06-12 01:59:51 +08:00
|
|
|
binfo("Unmapping address space: %p\n", binp->mapped);
|
2012-10-30 03:32:05 +08:00
|
|
|
|
2021-02-16 01:15:08 +08:00
|
|
|
file_munmap(binp->mapped, binp->mapsize);
|
2009-06-18 02:45:48 +08:00
|
|
|
}
|
|
|
|
|
2012-12-20 01:54:26 +08:00
|
|
|
/* Notice that the address environment is not destroyed. This should
|
|
|
|
* happen automatically when the task exits.
|
|
|
|
*/
|
2009-06-18 02:45:48 +08:00
|
|
|
}
|
2012-10-30 03:32:05 +08:00
|
|
|
|
2009-06-18 02:45:48 +08:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2009-06-18 05:15:31 +08:00
|
|
|
#endif /* CONFIG_BINFMT_DISABLE */
|