2012-10-24 18:46:12 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* binfmt/libelf/libelf_uninit.c
|
|
|
|
*
|
2021-02-03 14:47:23 +01: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-24 18:46:12 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-10-24 18:46:12 +02:00
|
|
|
*
|
2021-02-03 14:47:23 +01: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-24 18:46:12 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <errno.h>
|
2012-10-29 01:52:23 +01:00
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
2012-10-24 22:19:44 +02:00
|
|
|
#include <nuttx/binfmt/elf.h>
|
2012-10-24 18:46:12 +02:00
|
|
|
|
2012-10-29 01:52:23 +01:00
|
|
|
#include "libelf.h"
|
|
|
|
|
2012-10-24 18:46:12 +02:00
|
|
|
/****************************************************************************
|
2015-04-08 16:29:03 +02:00
|
|
|
* Pre-processor Definitions
|
2012-10-24 18:46:12 +02: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 01:52:23 +01:00
|
|
|
/* Free all working buffers */
|
|
|
|
|
|
|
|
elf_freebuffers(loadinfo);
|
|
|
|
|
|
|
|
/* Close the ELF file */
|
|
|
|
|
2012-10-24 18:46:12 +02:00
|
|
|
if (loadinfo->filfd >= 0)
|
|
|
|
{
|
2020-05-02 16:30:58 +02:00
|
|
|
nx_close(loadinfo->filfd);
|
2012-10-24 18:46:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-10-29 01:52:23 +01: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 01:04:02 +02:00
|
|
|
kmm_free((FAR void *)loadinfo->shdr);
|
2012-10-29 01:52:23 +01:00
|
|
|
loadinfo->shdr = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (loadinfo->iobuffer)
|
|
|
|
{
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free((FAR void *)loadinfo->iobuffer);
|
2012-10-29 01:52:23 +01:00
|
|
|
loadinfo->iobuffer = NULL;
|
|
|
|
loadinfo->buflen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|