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); binfo("Unmapping address space: %p\n", binp->mapped);
munmap(binp->mapped, binp->mapsize); file_munmap(binp->mapped, binp->mapsize);
} }
/* Free allocated address spaces */ /* Free allocated address spaces */

View File

@ -78,7 +78,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
int nexports) int nexports)
{ {
FAR const struct builtin_s *builtin; FAR const struct builtin_s *builtin;
int fd; struct file file;
int index; int index;
int ret; int ret;
@ -86,22 +86,23 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
/* Open the binary file for reading (only) */ /* Open the binary file for reading (only) */
fd = nx_open(filename, O_RDONLY); ret = file_open(&file, filename, O_RDONLY);
if (fd < 0) if (ret < 0)
{ {
berr("ERROR: Failed to open binary %s: %d\n", filename, fd); berr("ERROR: Failed to open binary %s: %d\n", filename, ret);
return fd; return ret;
} }
/* If this file is a BINFS file system, then we can recover the name of /* If this file is a BINFS file system, then we can recover the name of
* the file using the FIOC_FILENAME ioctl() call. * 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) if (ret < 0)
{ {
berr("ERROR: FIOC_FILENAME ioctl failed: %d\n", ret); berr("ERROR: FIOC_FILENAME ioctl failed: %d\n", ret);
nx_close(fd); file_close(&file);
return ret; return ret;
} }
@ -113,7 +114,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
if (index < 0) if (index < 0)
{ {
berr("ERROR: %s is not a builtin application\n", filename); berr("ERROR: %s is not a builtin application\n", filename);
nx_close(fd); file_close(&file);
return index; return index;
} }
@ -125,7 +126,7 @@ static int builtin_loadbinary(FAR struct binary_s *binp,
binp->entrypt = builtin->main; binp->entrypt = builtin->main;
binp->stacksize = builtin->stacksize; binp->stacksize = builtin->stacksize;
binp->priority = builtin->priority; binp->priority = builtin->priority;
nx_close(fd); file_close(&file);
return OK; 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(" dtors: %08lx\n", (long)loadinfo->dtors);
binfo(" ndtors: %d\n", loadinfo->ndtors); binfo(" ndtors: %d\n", loadinfo->ndtors);
#endif #endif
binfo(" filfd: %d\n", loadinfo->filfd);
binfo(" symtabidx: %d\n", loadinfo->symtabidx); binfo(" symtabidx: %d\n", loadinfo->symtabidx);
binfo(" strtabidx: %d\n", loadinfo->strtabidx); 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 */ /* Clear the load info structure */
memset(loadinfo, 0, sizeof(struct elf_loadinfo_s)); memset(loadinfo, 0, sizeof(struct elf_loadinfo_s));
loadinfo->filfd = -1;
/* Get the length of the file. */ /* 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) */ /* Open the binary file for reading (only) */
loadinfo->filfd = nx_open(filename, O_RDONLY); ret = file_open(&loadinfo->file, filename, O_RDONLY);
if (loadinfo->filfd < 0) if (ret < 0)
{ {
ret = loadinfo->filfd;
berr("Failed to open ELF binary %s: %d\n", filename, ret); berr("Failed to open ELF binary %s: %d\n", filename, ret);
return ret; return ret;
} }

View File

@ -239,7 +239,7 @@ int elf_load(FAR struct elf_loadinfo_s *loadinfo)
int ret; int ret;
binfo("loadinfo: %p\n", loadinfo); binfo("loadinfo: %p\n", loadinfo);
DEBUGASSERT(loadinfo && loadinfo->filfd >= 0); DEBUGASSERT(loadinfo && loadinfo->file.f_inode);
/* Load section headers into memory */ /* 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 */ /* 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) if (rpos != offset)
{ {
berr("Failed to seek to position %lu: %d\n", 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 */ /* 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) if (nbytes < 0)
{ {
/* EINTR just means that we received a signal */ /* 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 */ /* Close the ELF file */
if (loadinfo->filfd >= 0) if (loadinfo->file.f_inode)
{ {
nx_close(loadinfo->filfd); file_close(&loadinfo->file);
} }
return OK; return OK;

View File

@ -94,10 +94,9 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
/* Open the binary file */ /* Open the binary file */
loadinfo->filfd = nx_open(filename, O_RDONLY); ret = file_open(&loadinfo->file, filename, O_RDONLY);
if (loadinfo->filfd < 0) if (ret < 0)
{ {
ret = loadinfo->filfd;
berr("ERROR: Failed to open NXFLAT binary %s: %d\n", filename, ret); berr("ERROR: Failed to open NXFLAT binary %s: %d\n", filename, ret);
return ret; return ret;
} }
@ -109,7 +108,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
if (ret < 0) if (ret < 0)
{ {
berr("ERROR: Failed to read NXFLAT header: %d\n", ret); berr("ERROR: Failed to read NXFLAT header: %d\n", ret);
nx_close(loadinfo->filfd); file_close(&loadinfo->file);
return ret; return ret;
} }
@ -128,7 +127,7 @@ int nxflat_init(const char *filename, struct nxflat_loadinfo_s *loadinfo)
*/ */
berr("ERROR: Bad NXFLAT header\n"); berr("ERROR: Bad NXFLAT header\n");
nx_close(loadinfo->filfd); file_close(&loadinfo->file);
return -ENOEXEC; 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. * memory resides as long as it is fully initialized and ready to execute.
*/ */
loadinfo->ispace = (uint32_t)mmap(NULL, loadinfo->isize, PROT_READ, ret = file_mmap(&loadinfo->file, NULL, loadinfo->isize, PROT_READ,
MAP_SHARED | MAP_FILE, loadinfo->filfd, MAP_SHARED | MAP_FILE, 0, (FAR void **)&loadinfo->ispace);
0); if (ret < 0)
if (loadinfo->ispace == (uint32_t)MAP_FAILED)
{ {
berr("Failed to map NXFLAT ISpace: %d\n", errno); berr("Failed to map NXFLAT ISpace: %d\n", ret);
return -errno; return ret;
} }
binfo("Mapped ISpace (%" PRId32 " bytes) at %08x\n", 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; bytesleft = readsize;
do do
{ {
rpos = nx_seek(loadinfo->filfd, offset, SEEK_SET); rpos = file_seek(&loadinfo->file, offset, SEEK_SET);
if (rpos != offset) if (rpos != offset)
{ {
berr("Failed to seek to position %d: %d\n", offset, (int)rpos); 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 */ /* 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 < 0)
{ {
if (nbytes != -EINTR) if (nbytes != -EINTR)

View File

@ -61,9 +61,9 @@
int nxflat_uninit(struct nxflat_loadinfo_s *loadinfo) 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; return OK;

View File

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

View File

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

View File

@ -132,7 +132,7 @@ struct elf_loadinfo_s
uint16_t symtabidx; /* Symbol table section index */ uint16_t symtabidx; /* Symbol table section index */
uint16_t strtabidx; /* String table section index */ uint16_t strtabidx; /* String table section index */
uint16_t buflen; /* size of iobuffer[] */ 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 */ /* 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) */ /* This is a copy of the NXFLAT header (still in network order) */