2015-12-10 16:53:31 +01:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/modlib/modlib_uninit.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
|
|
|
|
*
|
|
|
|
* 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.
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.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 17:05:15 +01:00
|
|
|
#include "libc.h"
|
2017-01-29 18:54:54 +01:00
|
|
|
#include "modlib/modlib.h"
|
2017-01-29 17:05:15 +01:00
|
|
|
|
2015-12-10 16:53:31 +01:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-01-29 17:05:15 +01:00
|
|
|
* Name: modlib_uninitialize
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
|
|
|
* Description:
|
2017-01-29 17:05:15 +01:00
|
|
|
* Releases any resources committed by modlib_initialize(). This
|
|
|
|
* essentially undoes the actions of modlib_initialize.
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
|
|
|
* 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_uninitialize(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
|
|
|
|
|
|
|
/* Close the ELF file */
|
|
|
|
|
|
|
|
if (loadinfo->filfd >= 0)
|
|
|
|
{
|
2021-02-15 09:08:51 +01:00
|
|
|
_NX_CLOSE(loadinfo->filfd);
|
2015-12-10 16:53:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-01-29 18:54:54 +01:00
|
|
|
* Name: modlib_freebuffers
|
2015-12-10 16:53:31 +01:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release all working buffers.
|
|
|
|
*
|
|
|
|
* 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_freebuffers(FAR struct mod_loadinfo_s *loadinfo)
|
2015-12-10 16:53:31 +01:00
|
|
|
{
|
|
|
|
/* Release all working allocations */
|
|
|
|
|
2017-01-29 17:05:15 +01:00
|
|
|
if (loadinfo->shdr != NULL)
|
2015-12-10 16:53:31 +01:00
|
|
|
{
|
2023-07-02 18:11:02 +02:00
|
|
|
lib_free(loadinfo->shdr);
|
|
|
|
loadinfo->shdr = NULL;
|
2015-12-10 16:53:31 +01:00
|
|
|
}
|
|
|
|
|
2022-09-26 08:22:03 +02:00
|
|
|
if (loadinfo->phdr != NULL)
|
|
|
|
{
|
2023-07-02 18:11:02 +02:00
|
|
|
lib_free(loadinfo->phdr);
|
|
|
|
loadinfo->phdr = NULL;
|
2022-09-26 08:22:03 +02:00
|
|
|
}
|
|
|
|
|
2017-01-29 17:05:15 +01:00
|
|
|
if (loadinfo->iobuffer != NULL)
|
2015-12-10 16:53:31 +01:00
|
|
|
{
|
2023-07-02 18:11:02 +02:00
|
|
|
lib_free(loadinfo->iobuffer);
|
|
|
|
loadinfo->iobuffer = NULL;
|
|
|
|
loadinfo->buflen = 0;
|
2015-12-10 16:53:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|