binfmt/loadable: move binary_s to stack to avoid access allocator

Improve performance by reducing allocator accesses

Signed-off-by: chao an <anchao@lixiang.com>
This commit is contained in:
chao an 2024-12-11 08:57:54 +08:00 committed by Xiang Xiao
parent 5abcc49789
commit c6dfdbad41

View file

@ -84,16 +84,22 @@ static int exec_internal(FAR const char *filename,
irqstate_t flags; irqstate_t flags;
int pid; int pid;
int ret; int ret;
#ifndef CONFIG_BINFMT_LOADABLE
struct binary_s sbin;
bin = &sbin;
#else
/* Allocate the load information */ /* Allocate the load information */
bin = kmm_zalloc(sizeof(struct binary_s)); bin = kmm_zalloc(sizeof(struct binary_s));
if (!bin) if (bin == NULL)
{ {
berr("ERROR: Failed to allocate binary_s\n"); berr("ERROR: Failed to allocate binary_s\n");
ret = -ENOMEM; ret = -ENOMEM;
goto errout; goto errout;
} }
#endif
/* Load the module into memory */ /* Load the module into memory */
@ -154,15 +160,9 @@ static int exec_internal(FAR const char *filename,
if (ret < 0) if (ret < 0)
{ {
berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret); berr("ERROR: Failed to schedule unload '%s': %d\n", filename, ret);
goto errout_with_lock;
} }
#else
/* Free the binary_s structure here */
kmm_free(bin);
/* TODO: How does the module get unloaded in this case? */
#endif #endif
sched_unlock(); sched_unlock();
@ -174,8 +174,10 @@ errout_with_lock:
leave_critical_section(flags); leave_critical_section(flags);
unload_module(bin); unload_module(bin);
errout_with_bin: errout_with_bin:
#ifdef CONFIG_BINFMT_LOADABLE
kmm_free(bin); kmm_free(bin);
errout: errout:
#endif
return ret; return ret;
} }