binfmt: Remove filename/exports/nexports from binary_s
to simplify the life cycle management Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
parent
cf78a5b6cf
commit
bebdbc5c87
@ -57,7 +57,6 @@ int binfmt_dumpmodule(FAR const struct binary_s *bin)
|
||||
if (bin)
|
||||
{
|
||||
binfo("Module:\n");
|
||||
binfo(" filename: %s\n", bin->filename);
|
||||
binfo(" entrypt: %p\n", bin->entrypt);
|
||||
binfo(" mapped: %p size=%zd\n", bin->mapped, bin->mapsize);
|
||||
binfo(" alloc: %p %p %p\n", bin->alloc[0],
|
||||
|
@ -86,15 +86,9 @@ int exec_spawn(FAR const char *filename, FAR char * const *argv,
|
||||
goto errout;
|
||||
}
|
||||
|
||||
/* Initialize the binary structure */
|
||||
|
||||
bin->filename = filename;
|
||||
bin->exports = exports;
|
||||
bin->nexports = nexports;
|
||||
|
||||
/* Load the module into memory */
|
||||
|
||||
ret = load_module(bin);
|
||||
ret = load_module(bin, filename, exports, nexports);
|
||||
if (ret < 0)
|
||||
{
|
||||
berr("ERROR: Failed to load program '%s': %d\n", filename, ret);
|
||||
@ -127,7 +121,7 @@ int exec_spawn(FAR const char *filename, FAR char * const *argv,
|
||||
|
||||
/* Then start the module */
|
||||
|
||||
pid = exec_module(bin, argv);
|
||||
pid = exec_module(bin, filename, argv);
|
||||
if (pid < 0)
|
||||
{
|
||||
ret = pid;
|
||||
|
@ -111,7 +111,8 @@ static void exec_ctors(FAR void *arg)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int exec_module(FAR const struct binary_s *binp, FAR char * const *argv)
|
||||
int exec_module(FAR const struct binary_s *binp,
|
||||
FAR const char *filename, FAR char * const *argv)
|
||||
{
|
||||
FAR struct task_tcb_s *tcb;
|
||||
#if defined(CONFIG_ARCH_ADDRENV) && defined(CONFIG_BUILD_KERNEL)
|
||||
@ -129,7 +130,7 @@ int exec_module(FAR const struct binary_s *binp, FAR char * const *argv)
|
||||
}
|
||||
#endif
|
||||
|
||||
binfo("Executing %s\n", binp->filename);
|
||||
binfo("Executing %s\n", filename);
|
||||
|
||||
/* Allocate a TCB for the new task. */
|
||||
|
||||
@ -167,7 +168,7 @@ int exec_module(FAR const struct binary_s *binp, FAR char * const *argv)
|
||||
|
||||
/* Initialize the task */
|
||||
|
||||
ret = nxtask_init(tcb, binp->filename, binp->priority,
|
||||
ret = nxtask_init(tcb, filename, binp->priority,
|
||||
NULL, binp->stacksize, binp->entrypt, argv);
|
||||
binfmt_freeargv(argv);
|
||||
if (ret < 0)
|
||||
|
@ -86,7 +86,7 @@ static int load_default_priority(FAR struct binary_s *bin)
|
||||
*
|
||||
* Description:
|
||||
* Load a module into memory, bind it to an exported symbol take, and
|
||||
* prep the module for execution. bin->filename is known to be an absolute
|
||||
* prep the module for execution. filename is known to be an absolute
|
||||
* path to the file to be loaded.
|
||||
*
|
||||
* Returned Value:
|
||||
@ -95,12 +95,13 @@ static int load_default_priority(FAR struct binary_s *bin)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int load_absmodule(FAR struct binary_s *bin)
|
||||
static int load_absmodule(FAR struct binary_s *bin, FAR const char *filename,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
{
|
||||
FAR struct binfmt_s *binfmt;
|
||||
int ret = -ENOENT;
|
||||
|
||||
binfo("Loading %s\n", bin->filename);
|
||||
binfo("Loading %s\n", filename);
|
||||
|
||||
/* Disabling pre-emption should be sufficient protection while accessing
|
||||
* the list of registered binary format handlers.
|
||||
@ -117,12 +118,12 @@ static int load_absmodule(FAR struct binary_s *bin)
|
||||
{
|
||||
/* Use this handler to try to load the format */
|
||||
|
||||
ret = binfmt->load(bin);
|
||||
ret = binfmt->load(bin, filename, exports, nexports);
|
||||
if (ret == OK)
|
||||
{
|
||||
/* Successfully loaded -- break out with ret == 0 */
|
||||
|
||||
binfo("Successfully loaded module %s\n", bin->filename);
|
||||
binfo("Successfully loaded module %s\n", filename);
|
||||
|
||||
/* Save the unload method for use by unload_module */
|
||||
|
||||
@ -154,14 +155,15 @@ static int load_absmodule(FAR struct binary_s *bin)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int load_module(FAR struct binary_s *bin)
|
||||
int load_module(FAR struct binary_s *bin, FAR const char *filename,
|
||||
FAR const struct symtab_s *exports, int nexports)
|
||||
{
|
||||
int ret = -EINVAL;
|
||||
|
||||
/* Verify that we were provided something to work with */
|
||||
|
||||
#ifdef CONFIG_DEBUG_FEATURES
|
||||
if (bin && bin->filename)
|
||||
if (bin && filename)
|
||||
#endif
|
||||
{
|
||||
/* Set the default priority of the new program. */
|
||||
@ -177,16 +179,12 @@ int load_module(FAR struct binary_s *bin)
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_LIB_ENVPATH
|
||||
if (bin->filename[0] != '/')
|
||||
if (filename[0] != '/')
|
||||
{
|
||||
FAR const char *relpath;
|
||||
FAR char *fullpath;
|
||||
ENVPATH_HANDLE handle;
|
||||
|
||||
/* Set aside the relative path */
|
||||
|
||||
relpath = bin->filename;
|
||||
ret = -ENOENT;
|
||||
ret = -ENOENT;
|
||||
|
||||
/* Initialize to traverse the PATH variable */
|
||||
|
||||
@ -195,12 +193,11 @@ int load_module(FAR struct binary_s *bin)
|
||||
{
|
||||
/* Get the next absolute file path */
|
||||
|
||||
while ((fullpath = envpath_next(handle, relpath)) != NULL)
|
||||
while ((fullpath = envpath_next(handle, filename)) != NULL)
|
||||
{
|
||||
/* Try to load the file at this path */
|
||||
|
||||
bin->filename = fullpath;
|
||||
ret = load_absmodule(bin);
|
||||
ret = load_absmodule(bin, fullpath, exports, nexports);
|
||||
|
||||
/* Free the allocated fullpath */
|
||||
|
||||
@ -218,12 +215,6 @@ int load_module(FAR struct binary_s *bin)
|
||||
|
||||
envpath_release(handle);
|
||||
}
|
||||
|
||||
/* Restore the relative path. This is not needed for anything
|
||||
* but debug output after the file has been loaded.
|
||||
*/
|
||||
|
||||
bin->filename = relpath;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
@ -232,7 +223,7 @@ int load_module(FAR struct binary_s *bin)
|
||||
* be loaded.
|
||||
*/
|
||||
|
||||
ret = load_absmodule(bin);
|
||||
ret = load_absmodule(bin, filename, exports, nexports);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,10 @@
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int builtin_loadbinary(FAR struct binary_s *binp);
|
||||
static int builtin_loadbinary(FAR struct binary_s *binp,
|
||||
FAR const char *filename,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@ -69,22 +72,24 @@ static struct binfmt_s g_builtin_binfmt =
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int builtin_loadbinary(struct binary_s *binp)
|
||||
static int builtin_loadbinary(FAR struct binary_s *binp,
|
||||
FAR const char *filename,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports)
|
||||
{
|
||||
FAR const char *filename;
|
||||
FAR const struct builtin_s *builtin;
|
||||
int fd;
|
||||
int index;
|
||||
int ret;
|
||||
|
||||
binfo("Loading file: %s\n", binp->filename);
|
||||
binfo("Loading file: %s\n", filename);
|
||||
|
||||
/* Open the binary file for reading (only) */
|
||||
|
||||
fd = nx_open(binp->filename, O_RDONLY);
|
||||
fd = nx_open(filename, O_RDONLY);
|
||||
if (fd < 0)
|
||||
{
|
||||
berr("ERROR: Failed to open binary %s: %d\n", binp->filename, fd);
|
||||
berr("ERROR: Failed to open binary %s: %d\n", filename, fd);
|
||||
return fd;
|
||||
}
|
||||
|
||||
|
16
binfmt/elf.c
16
binfmt/elf.c
@ -68,7 +68,10 @@
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_loadbinary(FAR struct binary_s *binp);
|
||||
static int elf_loadbinary(FAR struct binary_s *binp,
|
||||
FAR const char *filename,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports);
|
||||
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_DEBUG_BINFMT)
|
||||
static void elf_dumploadinfo(FAR struct elf_loadinfo_s *loadinfo);
|
||||
#endif
|
||||
@ -206,16 +209,19 @@ static void elf_dumpentrypt(FAR struct binary_s *binp,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int elf_loadbinary(FAR struct binary_s *binp)
|
||||
static int elf_loadbinary(FAR struct binary_s *binp,
|
||||
FAR const char *filename,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports)
|
||||
{
|
||||
struct elf_loadinfo_s loadinfo; /* Contains globals for libelf */
|
||||
int ret;
|
||||
|
||||
binfo("Loading file: %s\n", binp->filename);
|
||||
binfo("Loading file: %s\n", filename);
|
||||
|
||||
/* Initialize the ELF library to load the program binary. */
|
||||
|
||||
ret = elf_init(binp->filename, &loadinfo);
|
||||
ret = elf_init(filename, &loadinfo);
|
||||
elf_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
@ -235,7 +241,7 @@ static int elf_loadbinary(FAR struct binary_s *binp)
|
||||
|
||||
/* Bind the program to the exported symbol table */
|
||||
|
||||
ret = elf_bind(&loadinfo, binp->exports, binp->nexports);
|
||||
ret = elf_bind(&loadinfo, exports, nexports);
|
||||
if (ret != 0)
|
||||
{
|
||||
berr("Failed to bind symbols program binary: %d\n", ret);
|
||||
|
@ -65,7 +65,10 @@
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static int nxflat_loadbinary(FAR struct binary_s *binp);
|
||||
static int nxflat_loadbinary(FAR struct binary_s *binp,
|
||||
FAR const char *filename,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports);
|
||||
static int nxflat_unloadbinary(FAR struct binary_s *binp);
|
||||
|
||||
#if defined(CONFIG_DEBUG_FEATURES) && defined(CONFIG_DEBUG_BINFMT)
|
||||
@ -137,16 +140,19 @@ static void nxflat_dumploadinfo(FAR struct nxflat_loadinfo_s *loadinfo)
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int nxflat_loadbinary(FAR struct binary_s *binp)
|
||||
static int nxflat_loadbinary(FAR struct binary_s *binp,
|
||||
FAR const char *filename,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports)
|
||||
{
|
||||
struct nxflat_loadinfo_s loadinfo; /* Contains globals for libnxflat */
|
||||
int ret;
|
||||
|
||||
binfo("Loading file: %s\n", binp->filename);
|
||||
binfo("Loading file: %s\n", filename);
|
||||
|
||||
/* Initialize the xflat library to load the program binary. */
|
||||
|
||||
ret = nxflat_init(binp->filename, &loadinfo);
|
||||
ret = nxflat_init(filename, &loadinfo);
|
||||
nxflat_dumploadinfo(&loadinfo);
|
||||
if (ret != 0)
|
||||
{
|
||||
@ -166,7 +172,7 @@ static int nxflat_loadbinary(FAR struct binary_s *binp)
|
||||
|
||||
/* Bind the program to the exported symbol table */
|
||||
|
||||
ret = nxflat_bind(&loadinfo, binp->exports, binp->nexports);
|
||||
ret = nxflat_bind(&loadinfo, exports, nexports);
|
||||
if (ret != 0)
|
||||
{
|
||||
berr("Failed to bind symbols program binary: %d\n", ret);
|
||||
|
@ -61,12 +61,6 @@ typedef FAR void (*binfmt_dtor_t)(void);
|
||||
struct symtab_s;
|
||||
struct binary_s
|
||||
{
|
||||
/* Information provided to the loader to load and bind a module */
|
||||
|
||||
FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */
|
||||
FAR const struct symtab_s *exports; /* Table of exported symbols */
|
||||
int nexports; /* The number of symbols in exports[] */
|
||||
|
||||
/* Information provided from the loader (if successful) describing the
|
||||
* resources used by the loaded module.
|
||||
*/
|
||||
@ -118,7 +112,10 @@ struct binfmt_s
|
||||
|
||||
/* Verify and load binary into memory */
|
||||
|
||||
CODE int (*load)(FAR struct binary_s *bin);
|
||||
CODE int (*load)(FAR struct binary_s *bin,
|
||||
FAR const char *filename,
|
||||
FAR const struct symtab_s *exports,
|
||||
int nexports);
|
||||
|
||||
/* Unload module callback */
|
||||
|
||||
@ -192,7 +189,8 @@ int unregister_binfmt(FAR struct binfmt_s *binfmt);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int load_module(FAR struct binary_s *bin);
|
||||
int load_module(FAR struct binary_s *bin, FAR const char *filename,
|
||||
FAR const struct symtab_s *exports, int nexports);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: unload_module
|
||||
@ -228,7 +226,8 @@ int unload_module(FAR struct binary_s *bin);
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int exec_module(FAR const struct binary_s *binp, FAR char * const *argv);
|
||||
int exec_module(FAR const struct binary_s *binp,
|
||||
FAR const char *filename, FAR char * const *argv);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exec
|
||||
|
Loading…
x
Reference in New Issue
Block a user