From 1b2f37259a7dd6b8e2a3033e83a6ff758b70dbc9 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Wed, 28 Jun 2023 16:58:09 +0800 Subject: [PATCH] binfmt/elf: Replace nx_stat with file_stat since kernel code prefer to use file_ API Signed-off-by: Xiang Xiao --- binfmt/libelf/libelf_init.c | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/binfmt/libelf/libelf_init.c b/binfmt/libelf/libelf_init.c index 640124888d..6a2600a4e1 100644 --- a/binfmt/libelf/libelf_init.c +++ b/binfmt/libelf/libelf_init.c @@ -75,15 +75,14 @@ * ****************************************************************************/ -static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo, - FAR const char *filename) +static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo) { struct stat buf; int ret; /* Get the file stats */ - ret = nx_stat(filename, &buf, 1); + ret = file_fstat(&loadinfo->file, &buf); if (ret < 0) { berr("Failed to stat file: %d\n", ret); @@ -98,10 +97,6 @@ static inline int elf_filelen(FAR struct elf_loadinfo_s *loadinfo, return -ENOENT; } - /* TODO: Verify that the file is readable. Not really important because - * we will detect this when we try to open the file read-only. - */ - /* Return the size of the file in the loadinfo structure */ loadinfo->filelen = buf.st_size; @@ -135,15 +130,6 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) memset(loadinfo, 0, sizeof(struct elf_loadinfo_s)); - /* Get the length of the file. */ - - ret = elf_filelen(loadinfo, filename); - if (ret < 0) - { - berr("elf_filelen failed: %d\n", ret); - return ret; - } - /* Open the binary file for reading (only) */ ret = file_open(&loadinfo->file, filename, O_RDONLY); @@ -153,6 +139,15 @@ int elf_init(FAR const char *filename, FAR struct elf_loadinfo_s *loadinfo) return ret; } + /* Get the length of the file. */ + + ret = elf_filelen(loadinfo); + if (ret < 0) + { + berr("elf_filelen failed: %d\n", ret); + return ret; + } + /* Read the ELF ehdr from offset 0 */ ret = elf_read(loadinfo, (FAR uint8_t *)&loadinfo->ehdr,