2015-12-10 16:53:31 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/modlib/modlib_unload.c
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
2020-04-13 17:03:46 +02: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
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
2020-04-13 17:03:46 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
2020-04-13 17:03:46 +02:00
|
|
|
* 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.
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
2017-01-29 15:24:42 +01:00
|
|
|
#include <nuttx/lib/modlib.h>
|
2015-12-10 16:53:31 +01:00
|
|
|
|
2017-01-29 18:54:54 +01:00
|
|
|
#include "libc.h"
|
2017-01-29 19:23:24 +01:00
|
|
|
#include "modlib/modlib.h"
|
2017-01-29 18:54:54 +01:00
|
|
|
|
2015-12-10 16:53:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-01-29 18:54:54 +01:00
|
|
|
* Name: modlib_unload
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function unloads the object from memory. This essentially undoes
|
2017-01-29 18:17:29 +01:00
|
|
|
* the actions of modlib_load(). It is called only under certain error
|
2015-12-10 16:53:31 +01:00
|
|
|
* conditions after the module has been loaded but not yet started.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 (OK) is returned on success and a negated errno is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2023-07-02 18:11:02 +02:00
|
|
|
int modlib_unload(FAR struct mod_loadinfo_s *loadinfo)
|
2015-12-10 16:53:31 +01:00
|
|
|
{
|
|
|
|
/* Free all working buffers */
|
|
|
|
|
2017-01-29 18:54:54 +01:00
|
|
|
modlib_freebuffers(loadinfo);
|
2015-12-10 16:53:31 +01:00
|
|
|
|
|
|
|
/* Release memory holding the relocated ELF image */
|
|
|
|
|
2023-09-04 02:37:48 +02:00
|
|
|
/* ET_DYN has a single allocation so we only free textalloc */
|
|
|
|
|
|
|
|
if (loadinfo->ehdr.e_type != ET_DYN)
|
2020-03-06 09:05:25 +01:00
|
|
|
{
|
2023-09-04 02:37:48 +02:00
|
|
|
if (loadinfo->textalloc != 0)
|
|
|
|
{
|
2021-06-18 01:47:45 +02:00
|
|
|
#if defined(CONFIG_ARCH_USE_TEXT_HEAP)
|
2023-09-04 02:37:48 +02:00
|
|
|
up_textheap_free((FAR void *)loadinfo->textalloc);
|
2021-04-15 04:33:48 +02:00
|
|
|
#else
|
2023-09-04 02:37:48 +02:00
|
|
|
lib_free((FAR void *)loadinfo->textalloc);
|
2021-04-15 04:33:48 +02:00
|
|
|
#endif
|
2023-09-04 02:37:48 +02:00
|
|
|
}
|
2020-03-06 09:05:25 +01:00
|
|
|
|
2023-09-04 02:37:48 +02:00
|
|
|
if (loadinfo->datastart != 0)
|
|
|
|
{
|
|
|
|
lib_free((FAR void *)loadinfo->datastart);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2020-03-06 09:05:25 +01:00
|
|
|
{
|
2023-09-04 02:37:48 +02:00
|
|
|
lib_free((FAR void *)loadinfo->textalloc);
|
2020-03-06 09:05:25 +01:00
|
|
|
}
|
2015-12-10 16:53:31 +01:00
|
|
|
|
|
|
|
/* Clear out all indications of the allocated address environment */
|
|
|
|
|
|
|
|
loadinfo->textalloc = 0;
|
2015-12-11 17:55:21 +01:00
|
|
|
loadinfo->datastart = 0;
|
2015-12-10 16:53:31 +01:00
|
|
|
loadinfo->textsize = 0;
|
|
|
|
loadinfo->datasize = 0;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|