diff --git a/binfmt/elf.c b/binfmt/elf.c index cfe146cb26e..fc896300538 100644 --- a/binfmt/elf.c +++ b/binfmt/elf.c @@ -98,6 +98,7 @@ static int elf_loadbinary(FAR struct binary_s *binp, int nexports) { struct mod_loadinfo_s loadinfo; + Elf_Sym sym; int ret; binfo("Loading file: %s\n", filename); @@ -173,7 +174,57 @@ static int elf_loadbinary(FAR struct binary_s *binp, /* Return the load information */ - binp->stacksize = CONFIG_ELF_STACKSIZE; + ret = libelf_findsymbol(&loadinfo, "nx_stacksize", &sym); + if (ret == 0) + { + binp->stacksize = sym.st_value; + } + else + { + binp->stacksize = CONFIG_ELF_STACKSIZE; + } + + ret = libelf_findsymbol(&loadinfo, "nx_priority", &sym); + if (ret == 0) + { + binp->priority = sym.st_value; + } + else + { + binp->priority = SCHED_PRIORITY_DEFAULT; + } + +#ifdef CONFIG_SCHED_USER_IDENTITY + ret = libelf_findsymbol(&loadinfo, "nx_uid", &sym); + if (ret == 0) + { + binp->uid = sym.st_value; + } + else + { + binp->uid = 0; + } + + ret = libelf_findsymbol(&loadinfo, "nx_gid", &sym); + if (ret == 0) + { + binp->gid = sym.st_value; + } + else + { + binp->gid = 0; + } + + ret = libelf_findsymbol(&loadinfo, "nx_mode", &sym); + if (ret == 0) + { + binp->mode = sym.st_value; + } + else + { + binp->mode = 0; + } +#endif /* Add the ELF allocation to the alloc[] only if there is no address * environment. If there is an address environment, it will automatically diff --git a/cmake/nuttx_add_application.cmake b/cmake/nuttx_add_application.cmake index c0b147452a3..7e26894ed18 100644 --- a/cmake/nuttx_add_application.cmake +++ b/cmake/nuttx_add_application.cmake @@ -147,6 +147,31 @@ function(nuttx_add_application) if(NOT "${CMAKE_LD}" MATCHES "gcc$") set(USE_LINKER True) endif() + if(STACKSIZE) + set(SYMBOL_STACKSIZE $<$>:-Wl,>--defsym + nx_stacksize=${STACKSIZE}) + endif() + if(PRIORITY) + if(PRIORITY STREQUAL "SCHED_PRIORITY_DEFAULT") + set(PRIORITY "0") + endif() + set(SYMBOL_PRIORITY $<$>:-Wl,>--defsym + nx_priority=${PRIORITY}) + endif() + if(CONFIG_SCHED_USER_IDENTITY) + if(UID) + set(SYMBOL_UID $<$>:-Wl,>--defsym + nx_uid=${UID}) + endif() + if(GID) + set(SYMBOL_GID $<$>:-Wl,>--defsym + nx_gid=${GID}) + endif() + if(MODE) + set(SYMBOL_MODE $<$>:-Wl,>--defsym + nx_mode=${MODE}) + endif() + endif() add_custom_command( TARGET ${TARGET} POST_BUILD @@ -158,7 +183,8 @@ function(nuttx_add_application) # add global ELF link option if m&kernel link $<$,$>:$> # add local link option last - ${LINK_FLAGS} + ${LINK_FLAGS} ${SYMBOL_STACKSIZE} ${SYMBOL_PRIORITY} ${SYMBOL_UID} + ${SYMBOL_GID} ${SYMBOL_MODE} # link startup obj if m&kernel link $<$,$>>:$> $<$>:-Wl,>--start-group