binfmt: Replace all nx_ API with file_ API

since binfmt is a kernel component

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2021-02-16 01:15:08 +08:00 committed by Masayuki Ishikawa
parent 8612af4ae5
commit 841a4922aa
15 changed files with 34 additions and 41 deletions

View File

@ -156,7 +156,7 @@ int unload_module(FAR struct binary_s *binp)
{
binfo("Unmapping address space: %p\n", binp->mapped);
munmap(binp->mapped, binp->mapsize);
file_munmap(binp->mapped, binp->mapsize);
}
/* Free allocated address spaces */

View File

@ -78,7 +78,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
int nexports)
{
FAR const struct builtin_s *builtin;
int fd;
struct file file;
int index;
int ret;
@ -86,22 +86,23 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
/* Open the binary file for reading (only) */
fd = nx_open(filename, O_RDONLY);
if (fd < 0)
ret = file_open(&file, filename, O_RDONLY);
if (ret < 0)
{
berr("ERROR: Failed to open binary %s: %d\n", filename, fd);
return fd;
berr("ERROR: Failed to open binary %s: %d\n", filename, ret);
return ret;
}
/* If this file is a BINFS file system, then we can recover the name of
* the file using the FIOC_FILENAME ioctl() call.
*/
ret = nx_ioctl(fd, FIOC_FILENAME, (unsigned long)((uintptr_t)&filename));
ret = file_ioctl(&file, FIOC_FILENAME,
(unsigned long)((uintptr_t)&filename));
if (ret < 0)
{
berr("ERROR: FIOC_FILENAME ioctl failed: %d\n", ret);
nx_close(fd);
file_close(&file);
return ret;
}
@ -113,7 +114,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
if (index < 0)
{
berr("ERROR: %s is not a builtin application\n", filename);
nx_close(fd);
file_close(&file);
return index;
}
@ -125,7 +126,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
binp->entrypt = builtin->main;
binp->stacksize = builtin->stacksize;
binp->priority = builtin->priority;
nx_close(fd);
file_close(&file);
return OK;
}

View File

@ -114,7 +114,6 @@ static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo)
binfo(" dtors: %08lx\n", (long)loadinfo->dtors);
binfo(" ndtors: %d\n", loadinfo->ndtors);
#endif
binfo(" filfd: %d\n", loadinfo->filfd);
binfo(" symtabidx: %d\n", loadinfo->symtabidx);
binfo(" strtabidx: %d\n", loadinfo->strtabidx);

View File

@ -134,7 +134,6 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
/* Clear the load info structure */
memset(loadinfo, 0, sizeof(struct elf_loadinfo_s));
loadinfo->filfd = -1;
/* Get the length of the file. */
@ -147,10 +146,9 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo)
/* Open the binary file for reading (only) */
loadinfo->filfd = nx_open(filename, O_RDONLY);
if (loadinfo->filfd < 0)
ret = file_open(&loadinfo->file, filename, O_RDONLY);
if (ret < 0)
{
ret = loadinfo->filfd;
berr("Failed to open ELF binary %s: %d\n", filename, ret);
return ret;
}

View File

@ -239,7 +239,7 @@ int elf_load(FAR struct elf_loadinfo_s *loadinfo)
int ret;
binfo("loadinfo: %p\n", loadinfo);
DEBUGASSERT(loadinfo && loadinfo->filfd >= 0);
DEBUGASSERT(loadinfo && loadinfo->file.f_inode);
/* Load section headers into memory */

View File

@ -108,7 +108,7 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
{
/* Seek to the next read position */
rpos = nx_seek(loadinfo->filfd, offset, SEEK_SET);
rpos = file_seek(&loadinfo->file, offset, SEEK_SET);
if (rpos != offset)
{
berr("Failed to seek to position %lu: %d\n",
@ -118,7 +118,7 @@ int elf_read(FAR struct elf_loadinfo_s *loadinfo, FAR uint8_t *buffer,
/* Read the file data at offset into the user buffer */
nbytes = nx_read(loadinfo->filfd, buffer, readsize);
nbytes = file_read(&loadinfo->file, buffer, readsize);
if (nbytes < 0)
{
/* EINTR just means that we received a signal */

View File

@ -70,9 +70,9 @@ int elf_uninit(struct elf_loadinfo_s *loadinfo)
/* Close the ELF file */
if (loadinfo->filfd >= 0)
if (loadinfo->file.f_inode)
{
nx_close(loadinfo->filfd);
file_close(&loadinfo->file);
}
return OK;

View File

@ -94,10 +94,9 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
/* Open the binary file */
loadinfo->filfd = nx_open(filename, O_RDONLY);
if (loadinfo->filfd < 0)
ret = file_open(&loadinfo->file, filename, O_RDONLY);
if (ret < 0)
{
ret = loadinfo->filfd;
berr("ERROR: Failed to open NXFLAT binary %s: %d\n", filename, ret);
return ret;
}
@ -109,7 +108,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
if (ret < 0)
{
berr("ERROR: Failed to read NXFLAT header: %d\n", ret);
nx_close(loadinfo->filfd);
file_close(&loadinfo->file);
return ret;
}
@ -128,7 +127,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
*/
berr("ERROR: Bad NXFLAT header\n");
nx_close(loadinfo->filfd);
file_close(&loadinfo->file);
return -ENOEXEC;
}

View File

@ -132,13 +132,12 @@ int nxflat_load(struct nxflat_loadinfo_s *loadinfo)
* memory resides as long as it is fully initialized and ready to execute.
*/
loadinfo->ispace = (uint32_t)mmap(NULL, loadinfo->isize, PROT_READ,
MAP_SHARED | MAP_FILE, loadinfo->filfd,
0);
if (loadinfo->ispace == (uint32_t)MAP_FAILED)
ret = file_mmap(&loadinfo->file, NULL, loadinfo->isize, PROT_READ,
MAP_SHARED | MAP_FILE, 0, (FAR void **)&loadinfo->ispace);
if (ret < 0)
{
berr("Failed to map NXFLAT ISpace: %d\n", errno);
return -errno;
berr("Failed to map NXFLAT ISpace: %d\n", ret);
return ret;
}
binfo("Mapped ISpace (%" PRId32 " bytes) at %08x\n",

View File

@ -113,7 +113,7 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
bytesleft = readsize;
do
{
rpos = nx_seek(loadinfo->filfd, offset, SEEK_SET);
rpos = file_seek(&loadinfo->file, offset, SEEK_SET);
if (rpos != offset)
{
berr("Failed to seek to position %d: %d\n", offset, (int)rpos);
@ -122,7 +122,7 @@ int nxflat_read(struct nxflat_loadinfo_s *loadinfo, char *buffer,
/* Read the file data at offset into the user buffer */
nbytes = nx_read(loadinfo->filfd, bufptr, bytesleft);
nbytes = file_read(&loadinfo->file, bufptr, bytesleft);
if (nbytes < 0)
{
if (nbytes != -EINTR)

View File

@ -61,9 +61,9 @@
int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo)
{
if (loadinfo->filfd >= 0)
if (loadinfo->file.f_inode)
{
nx_close(loadinfo->filfd);
file_close(&loadinfo->file);
}
return OK;

View File

@ -72,7 +72,7 @@ int nxflat_unload(FAR struct nxflat_loadinfo_s *loadinfo)
if (loadinfo->ispace)
{
munmap((FAR void *)loadinfo->ispace, loadinfo->isize);
file_munmap((FAR void *)loadinfo->ispace, loadinfo->isize);
loadinfo->ispace = 0;
}

View File

@ -123,9 +123,6 @@ static void nxflat_dumploadinfo(FAR struct nxflat_loadinfo_s *loadinfo)
binfo(" RELOCS:\n");
binfo(" relocstart: %08lx\n", loadinfo->relocstart);
binfo(" reloccount: %d\n", loadinfo->reloccount);
binfo(" HANDLES:\n");
binfo(" filfd: %d\n", loadinfo->filfd);
}
#else
# define nxflat_dumploadinfo(i)

View File

@ -132,7 +132,7 @@ struct elf_loadinfo_s
uint16_t symtabidx; /* Symbol table section index */
uint16_t strtabidx; /* String table section index */
uint16_t buflen; /* size of iobuffer[] */
int filfd; /* Descriptor for the file being loaded */
struct file file; /* Descriptor for the file being loaded */
};
/****************************************************************************

View File

@ -95,7 +95,7 @@ struct nxflat_loadinfo_s
/* File descriptors */
int filfd; /* Descriptor for the file being loaded */
struct file file; /* Descriptor for the file being loaded */
/* This is a copy of the NXFLAT header (still in network order) */