2012-10-25 00:46:12 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* binfmt/libelf/libelf_uninit.c
|
|
|
|
*
|
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
|
2012-10-25 00:46:12 +08:00
|
|
|
*
|
2021-02-03 21:47:23 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-10-25 00:46:12 +08:00
|
|
|
*
|
2021-02-03 21:47:23 +08: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.
|
2012-10-25 00:46:12 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
2012-10-29 08:52:23 +08:00
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
2012-10-25 04:19:44 +08:00
|
|
|
#include <nuttx/binfmt/elf.h>
|
2012-10-25 00:46:12 +08:00
|
|
|
|
2012-10-29 08:52:23 +08:00
|
|
|
#include "libelf.h"
|
|
|
|
|
2012-10-25 00:46:12 +08:00
|
|
|
/****************************************************************************
|
2015-04-08 22:29:03 +08:00
|
|
|
* Pre-processor Definitions
|
2012-10-25 00:46:12 +08:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Constant Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: elf_uninit
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Releases any resources committed by elf_init(). This essentially
|
|
|
|
* undoes the actions of elf_init.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 (OK) is returned on success and a negated errno is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int elf_uninit(struct elf_loadinfo_s *loadinfo)
|
|
|
|
{
|
2012-10-29 08:52:23 +08:00
|
|
|
/* Free all working buffers */
|
|
|
|
|
|
|
|
elf_freebuffers(loadinfo);
|
|
|
|
|
|
|
|
/* Close the ELF file */
|
|
|
|
|
2021-02-16 01:15:08 +08:00
|
|
|
if (loadinfo->file.f_inode)
|
2012-10-25 00:46:12 +08:00
|
|
|
{
|
2021-02-16 01:15:08 +08:00
|
|
|
file_close(&loadinfo->file);
|
2012-10-25 00:46:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-10-29 08:52:23 +08:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: elf_freebuffers
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Release all working buffers.
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* 0 (OK) is returned on success and a negated errno is returned on
|
|
|
|
* failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
int elf_freebuffers(struct elf_loadinfo_s *loadinfo)
|
|
|
|
{
|
|
|
|
/* Release all working allocations */
|
|
|
|
|
|
|
|
if (loadinfo->shdr)
|
|
|
|
{
|
2014-09-01 07:04:02 +08:00
|
|
|
kmm_free((FAR void *)loadinfo->shdr);
|
2012-10-29 08:52:23 +08:00
|
|
|
loadinfo->shdr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loadinfo->iobuffer)
|
|
|
|
{
|
2014-09-01 07:04:02 +08:00
|
|
|
kmm_free((FAR void *)loadinfo->iobuffer);
|
2012-10-29 08:52:23 +08:00
|
|
|
loadinfo->iobuffer = NULL;
|
|
|
|
loadinfo->buflen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|