From 0d3a2bbae84f537627a2f52a9b7a50ce5fc10960 Mon Sep 17 00:00:00 2001 From: baggio63446333 Date: Tue, 16 Aug 2022 11:54:53 +0900 Subject: [PATCH] nshlib: Change ELF priority and stack size based on builtin list When an application is used as a loadable ELF module, the priority and stack size of the application task is always fixed at the default values. This commit changes to get the priority and stack size of the application from the bulitin list. If it is not on the list, it still works as before. --- nshlib/nsh_fileapps.c | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/nshlib/nsh_fileapps.c b/nshlib/nsh_fileapps.c index 98c50dffa..d64b37b11 100644 --- a/nshlib/nsh_fileapps.c +++ b/nshlib/nsh_fileapps.c @@ -34,6 +34,8 @@ #include #include #include +#include +#include #include "nsh.h" #include "nsh_console.h" @@ -73,6 +75,10 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, pid_t pid; int rc = 0; int ret; +#ifdef CONFIG_BUILTIN + FAR char *appname; + int index; +#endif /* Initialize the attributes file actions structure */ @@ -117,6 +123,42 @@ int nsh_fileapp(FAR struct nsh_vtbl_s *vtbl, FAR const char *cmd, } } +#ifdef CONFIG_BUILTIN + /* Check if a builtin application with this name exists */ + + appname = basename((FAR char *)cmd); + index = builtin_isavail(appname); + if (index >= 0) + { + FAR const struct builtin_s *builtin; + struct sched_param param; + + /* Get information about the builtin */ + + builtin = builtin_for_index(index); + if (builtin == NULL) + { + ret = ENOENT; + goto errout_with_actions; + } + + /* Set the correct task size and priority */ + + param.sched_priority = builtin->priority; + ret = posix_spawnattr_setschedparam(&attr, ¶m); + if (ret != 0) + { + goto errout_with_actions; + } + + ret = task_spawnattr_setstacksize(&attr, builtin->stacksize); + if (ret != 0) + { + goto errout_with_actions; + } + } +#endif + /* Lock the scheduler in an attempt to prevent the application from * running until waitpid() has been called. */