From 6509a0c0caafb906c077a64cf424b9196ef56bc0 Mon Sep 17 00:00:00 2001
From: nchao
Date: Thu, 8 Nov 2018 07:27:14 -0600
Subject: [PATCH] binfmt/ and libs/libc: Make exepath_*() more common:
1. Move exepath_*() related code to libc/misc
1. Rename exepath_ to envpath_
2. Rename BINFMT_EXEPATH to LIB_ENVPATH
libs/libc/modlib: Add pre module library symbol table support
---
Documentation/NuttXBinfmt.html | 54 +++---
Documentation/NuttxUserGuide.html | 12 +-
binfmt/Kconfig | 10 +-
binfmt/Makefile | 4 -
binfmt/binfmt_exec.c | 2 +-
binfmt/binfmt_loadmodule.c | 11 +-
binfmt/libpcode/README.txt | 2 +-
binfmt/pcode.c | 2 +-
configs/lc823450-xgevk/elf/defconfig | 2 +-
configs/lc823450-xgevk/krndis/defconfig | 2 +-
configs/lc823450-xgevk/posix_spawn/defconfig | 2 +-
configs/lc823450-xgevk/rndis/defconfig | 2 +-
configs/olimex-stm32-p407/kelf/defconfig | 2 +-
configs/sim/bas/defconfig | 2 +-
configs/sim/bluetooth/defconfig | 2 +-
configs/sim/ipforward/defconfig | 2 +-
configs/sim/loadable/defconfig | 2 +-
configs/sim/minibasic/defconfig | 2 +-
configs/sim/nsh/defconfig | 2 +-
configs/sim/udgram/defconfig | 2 +-
configs/sim/unionfs/defconfig | 2 +-
configs/sim/userfs/defconfig | 2 +-
configs/sim/ustream/defconfig | 2 +-
configs/stm32f4discovery/elf/defconfig | 2 +-
.../stm32f4discovery/posix_spawn/defconfig | 2 +-
include/nuttx/binfmt/binfmt.h | 95 +----------
include/nuttx/envpath.h | 159 ++++++++++++++++++
include/nuttx/lib/modlib.h | 2 -
include/spawn.h | 2 +-
include/sys/syscall.h | 2 +-
libs/libc/misc/Kconfig | 8 +
libs/libc/misc/Make.defs | 6 +
.../libc/misc/lib_envpath.c | 100 +++++------
libs/libc/modlib/Kconfig | 20 +++
libs/libc/modlib/modlib_symbols.c | 10 +-
libs/libc/modlib/modlib_symtab.c | 44 ++++-
libs/libc/unistd/lib_execl.c | 2 +-
sched/task/task_execv.c | 2 +-
sched/task/task_posixspawn.c | 10 +-
sched/task/task_spawn.c | 2 +-
syscall/syscall.csv | 4 +-
syscall/syscall_lookup.h | 2 +-
tools/cfgdefine.c | 2 +
43 files changed, 368 insertions(+), 235 deletions(-)
create mode 100644 include/nuttx/envpath.h
rename binfmt/binfmt_exepath.c => libs/libc/misc/lib_envpath.c (76%)
diff --git a/Documentation/NuttXBinfmt.html b/Documentation/NuttXBinfmt.html
index b6c19e9cdc..653d1ea198 100644
--- a/Documentation/NuttXBinfmt.html
+++ b/Documentation/NuttXBinfmt.html
@@ -186,7 +186,7 @@ struct binary_s
- 1The filename
must be the full, absolute path to the file to be executed unless CONFIG_BINFMT_EXEPATH
is defined.
+ 1The filename
must be the full, absolute path to the file to be executed unless CONFIG_LIB_ENVPATH
is defined.
In that case, filename
may be a relative path;
a set of candidate absolute paths will be generated using the PATH
environment variable and load_module()
will attempt to load each file that is found at those absolute paths.
@@ -224,9 +224,9 @@ typedef FAR void (*binfmt_dtor_t)(void);
PATH
traversal logic:
@@ -273,7 +273,7 @@ int load_module(FAR struct binary_s *bin);
load_module()
will use the filename
field in the struct binary_s
in order to locate the module to be loaded from the file system.
- The filename
must be the full, absolute path to the file to be executed unless CONFIG_BINFMT_EXEPATH
is defined.
+ The filename
must be the full, absolute path to the file to be executed unless CONFIG_LIB_ENVPATH
is defined.
In that case, filename
may be a relative path;
a set of candidate absolute paths will be generated using the PATH
environment variable and load_module()
will attempt to load each file that is found at those absolute paths.
@@ -345,12 +345,12 @@ int exec(FAR const char *filename, FAR const char **argv,
On failure, it returns -1 (ERROR
) with errno
set appropriately.
-
+
Function Prototype:
-#include <:nuttx/binfmt/binfmt.h>
-#ifdef CONFIG_BINFMT_EXEPATH
-EXEPATH_HANDLE exepath_init(void);
+#include <:nuttx/envpath.h>
+#ifdef CONFIG_LIB_ENVPATH
+ENVPATH_HANDLE envpath_init(void);
#endif
Description:
@@ -361,31 +361,31 @@ EXEPATH_HANDLE exepath_init(void);
-
- Call
exepath_init()
to initialize for the traversal.
- exepath_init()
will return an opaque handle that can then be provided to exepath_next()
and exepath_release()
.
+ Call envpath_init()
to initialize for the traversal.
+ envpath_init()
will return an opaque handle that can then be provided to envpath_next()
and envpath_release()
.
-
- Call
exepath_next()
repeatedly to examine every file that lies in the directories of the PATH
variable.
+ Call envpath_next()
repeatedly to examine every file that lies in the directories of the PATH
variable.
-
- Call
exepath_release()
to free resources set aside by exepath_init()
.
+ Call envpath_release()
to free resources set aside by envpath_init()
.
Input Parameters: None
Returned Value:
- On success, exepath_init()
return a non-NULL
, opaque handle that may subsequently be used in calls to exepath_next()
and exepath_release()
.
+ On success, envpath_init()
return a non-NULL
, opaque handle that may subsequently be used in calls to envpath_next()
and envpath_release()
.
On error, a NULL
handle value will be returned.
The most likely cause of an error would be that there is no value associated with the PATH
variable.
-
+
Function Prototype:
-#include <:nuttx/binfmt/binfmt.h>
-#ifdef CONFIG_BINFMT_EXEPATH
-FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
+#include <:nuttx/envpath.h>
+#ifdef CONFIG_LIB_ENVPATH
+FAR char *envpath_next(ENVPATH_HANDLE handle, FAR const char *relpath);
#endif
Description:
@@ -394,7 +394,7 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
Input Parameters:
- handle
: The handle value returned by exepath_init()
.
+ handle
: The handle value returned by envpath_init()
.
relpath
: The relative path to the file to be found.
Returned Value:
@@ -410,27 +410,27 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
NULL
relpath from any absolute path in the PATH
variable.
- In this case, there is no point in calling exepath_next()
further; exepath_release()
must be called to release resources set aside by expath_init()
.
+ In this case, there is no point in calling envpath_next()
further; envpath_release()
must be called to release resources set aside by expath_init()
.
-
+
Function Prototype:
-#include <:nuttx/binfmt/binfmt.h>
-#ifdef CONFIG_BINFMT_EXEPATH
-void exepath_release(EXEPATH_HANDLE handle);
+#include <:nuttx/envpath.h>
+#ifdef CONFIG_LIB_ENVPATH
+void envpath_release(ENVPATH_HANDLE handle);
#endif
Description:
- Release all resources set aside by exepath_init
when the handle value was created.
+ Release all resources set aside by envpath_init
when the handle value was created.
The handle value is invalid on return from this function.
- Attempts to all exepath_next()
or exepath_release()
with such a stale handle will result in undefined (i.e., not good) behavior.
+ Attempts to all envpath_next()
or envpath_release()
with such a stale handle will result in undefined (i.e., not good) behavior.
Input Parameters:
- handle
: The handle value returned by exepath_init()
.
+ handle
: The handle value returned by envpath_init()
.
Returned Value: None
diff --git a/Documentation/NuttxUserGuide.html b/Documentation/NuttxUserGuide.html
index b2328be4fa..fea8cf2840 100644
--- a/Documentation/NuttxUserGuide.html
+++ b/Documentation/NuttxUserGuide.html
@@ -875,7 +875,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
filename
:
The path to the program to be executed.
- If CONFIG_BINFMT_EXEPATH
is defined in the configuration, then this may be a relative path from the current working directory.
+ If CONFIG_LIB_ENVPATH
is defined in the configuration, then this may be a relative path from the current working directory.
Otherwise, path
must be the absolute path to the program.
@@ -969,7 +969,7 @@ int execv(FAR const char *path, FAR char *const argv[]);
path
:
The path to the program to be executed.
- If CONFIG_BINFMT_EXEPATH
is defined in the configuration, then this may be a relative path from the current working directory.
+ If CONFIG_LIB_ENVPATH
is defined in the configuration, then this may be a relative path from the current working directory.
Otherwise, path
must be the absolute path to the program.
@@ -1013,7 +1013,7 @@ int execl(FAR const char *path, ...);
path
:
The path to the program to be executed.
- If CONFIG_BINFMT_EXEPATH
is defined in the configuration, then this may be a relative path from the current working directory.
+ If CONFIG_LIB_ENVPATH
is defined in the configuration, then this may be a relative path from the current working directory.
Otherwise, path
must be the absolute path to the program.
@@ -1074,7 +1074,7 @@ int posix_spawnp(FAR pid_t *pid, FAR const char *file,
NOTE: NuttX provides only one implementation:
- If CONFIG_BINFMT_EXEPATH
is defined, then only posix_spawnp()
behavior is supported; otherwise, only posix_spawn
behavior is supported.
+ If CONFIG_LIB_ENVPATH
is defined, then only posix_spawnp()
behavior is supported; otherwise, only posix_spawn
behavior is supported.
@@ -1156,8 +1156,8 @@ int posix_spawnp(FAR pid_t *pid, FAR const char *file,
-
- NuttX provides only
posix_spawn()
or posix_spawnp()
behavior depending upon the setting of CONFIG_BINFMT_EXEPATH
:
- If CONFIG_BINFMT_EXEPATH
is defined, then only posix_spawnp()
behavior is supported; otherwise, only posix_spawn()
behavior is supported.
+ NuttX provides only posix_spawn()
or posix_spawnp()
behavior depending upon the setting of CONFIG_LIB_ENVPATH
:
+ If CONFIG_LIB_ENVPATH
is defined, then only posix_spawnp()
behavior is supported; otherwise, only posix_spawn()
behavior is supported.
-
The
envp
argument is not used and the environ
variable is not altered (NuttX does not support the environ
variable).
diff --git a/binfmt/Kconfig b/binfmt/Kconfig
index 58638a9d0c..7885eb6f74 100644
--- a/binfmt/Kconfig
+++ b/binfmt/Kconfig
@@ -12,18 +12,10 @@ config BINFMT_DISABLE
if !BINFMT_DISABLE
-config BINFMT_EXEPATH
- bool "Support PATH variable"
- default n
- depends on !DISABLE_ENVIRON
- ---help---
- Use the contents of the PATH environment variable to locate executable
- files. Default: n
-
config PATH_INITIAL
string "Initial PATH Value"
default ""
- depends on BINFMT_EXEPATH
+ depends on LIB_ENVPATH
---help---
The initial value of the PATH variable. This is the colon-separated
list of absolute paths. E.g., "/bin:/usr/bin:/sbin"
diff --git a/binfmt/Makefile b/binfmt/Makefile
index 6dcf3642a9..e0d6d49776 100644
--- a/binfmt/Makefile
+++ b/binfmt/Makefile
@@ -49,10 +49,6 @@ BINFMT_CSRCS = binfmt_globals.c binfmt_initialize.c binfmt_register.c binfmt_un
BINFMT_CSRCS += binfmt_loadmodule.c binfmt_unloadmodule.c binfmt_execmodule.c
BINFMT_CSRCS += binfmt_exec.c binfmt_copyargv.c binfmt_dumpmodule.c
-ifeq ($(CONFIG_BINFMT_EXEPATH),y)
-BINFMT_CSRCS += binfmt_exepath.c
-endif
-
ifeq ($(CONFIG_BINFMT_LOADABLE),y)
BINFMT_CSRCS += binfmt_exit.c
endif
diff --git a/binfmt/binfmt_exec.c b/binfmt/binfmt_exec.c
index 6aed5ebf65..b150ead72d 100644
--- a/binfmt/binfmt_exec.c
+++ b/binfmt/binfmt_exec.c
@@ -98,7 +98,7 @@
*
* Input Parameters:
* filename - The path to the program to be executed. If
- * CONFIG_BINFMT_EXEPATH is defined in the configuration, then
+ * CONFIG_LIB_ENVPATH is defined in the configuration, then
* this may be a relative path from the current working
* directory. Otherwise, path must be the absolute path to the
* program.
diff --git a/binfmt/binfmt_loadmodule.c b/binfmt/binfmt_loadmodule.c
index 6040c3fdee..617d33924c 100644
--- a/binfmt/binfmt_loadmodule.c
+++ b/binfmt/binfmt_loadmodule.c
@@ -43,6 +43,7 @@
#include
#include
+#include
#include
#include
#include
@@ -190,12 +191,12 @@ int load_module(FAR struct binary_s *bin)
* be loaded? Absolute paths start with '/'.
*/
-#ifdef CONFIG_BINFMT_EXEPATH
+#ifdef CONFIG_LIB_ENVPATH
if (bin->filename[0] != '/')
{
FAR const char *relpath;
FAR char *fullpath;
- EXEPATH_HANDLE handle;
+ ENVPATH_HANDLE handle;
/* Set aside the relative path */
@@ -204,12 +205,12 @@ int load_module(FAR struct binary_s *bin)
/* Initialize to traverse the PATH variable */
- handle = exepath_init();
+ handle = envpath_init("PATH");
if (handle)
{
/* Get the next absolute file path */
- while ((fullpath = exepath_next(handle, relpath)) != NULL)
+ while ((fullpath = envpath_next(handle, relpath)) != NULL)
{
/* Try to load the file at this path */
@@ -230,7 +231,7 @@ int load_module(FAR struct binary_s *bin)
/* Release the traversal handle */
- exepath_release(handle);
+ envpath_release(handle);
}
/* Restore the relative path. This is not needed for anything
diff --git a/binfmt/libpcode/README.txt b/binfmt/libpcode/README.txt
index 5e536693c8..debbb95931 100644
--- a/binfmt/libpcode/README.txt
+++ b/binfmt/libpcode/README.txt
@@ -71,7 +71,7 @@ Here is a simple test configuration using the NuttX simulator:
This enables general BINFMT support:
CONFIG_DEBUG_BINFMT=y
- CONFIG_BINFMT_EXEPATH=y
+ CONFIG_LIB_ENVPATH=y
This enables building of the P-Code virtual machine:
diff --git a/binfmt/pcode.c b/binfmt/pcode.c
index e6b40b3f91..db8caf175f 100644
--- a/binfmt/pcode.c
+++ b/binfmt/pcode.c
@@ -276,7 +276,7 @@ static int pcode_mount_testfs(void)
* the ROMFS mountpoint.
*/
-#if defined(CONFIG_BINFMT_EXEPATH) && !defined(CONFIG_PATH_INITIAL)
+#if defined(CONFIG_LIB_ENVPATH) && !defined(CONFIG_PATH_INITIAL)
(void)setenv("PATH", CONFIG_BINFMT_PCODE_TEST_MOUNTPOINT, 1);
#endif
diff --git a/configs/lc823450-xgevk/elf/defconfig b/configs/lc823450-xgevk/elf/defconfig
index 3a4268ea6c..6183c328b4 100644
--- a/configs/lc823450-xgevk/elf/defconfig
+++ b/configs/lc823450-xgevk/elf/defconfig
@@ -7,7 +7,6 @@ CONFIG_ARCH_FLOAT_H=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STDARG_H=y
CONFIG_BINFMT_CONSTRUCTORS=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARD_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=12061
CONFIG_C99_BOOL8=y
@@ -26,6 +25,7 @@ CONFIG_INTELHEX_BINARY=y
CONFIG_LC823450_UART0=y
CONFIG_LIBM=y
CONFIG_LIB_BOARDCTL=y
+CONFIG_LIB_ENVPATH=y
CONFIG_LIB_KBDCODEC=y
CONFIG_MAX_TASKS=64
CONFIG_MAX_WDOGPARMS=2
diff --git a/configs/lc823450-xgevk/krndis/defconfig b/configs/lc823450-xgevk/krndis/defconfig
index 4cabfb379b..2f0ea98c2f 100644
--- a/configs/lc823450-xgevk/krndis/defconfig
+++ b/configs/lc823450-xgevk/krndis/defconfig
@@ -18,7 +18,6 @@ CONFIG_AUDIO_EXCLUDE_FFORWARD=y
CONFIG_AUDIO_EXCLUDE_TONE=y
CONFIG_AUDIO_I2SCHAR=y
CONFIG_AUDIO_WM8776=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARDCTL_USBDEVCTRL=y
CONFIG_BOARD_LOOPSPERMSEC=12061
@@ -71,6 +70,7 @@ CONFIG_LCD=y
CONFIG_LCD_ST7565=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBM=y
+CONFIG_LIB_ENVPATH=y
CONFIG_LIB_KBDCODEC=y
CONFIG_MAX_TASKS=64
CONFIG_MAX_WDOGPARMS=2
diff --git a/configs/lc823450-xgevk/posix_spawn/defconfig b/configs/lc823450-xgevk/posix_spawn/defconfig
index bd011e4e5e..892875dceb 100644
--- a/configs/lc823450-xgevk/posix_spawn/defconfig
+++ b/configs/lc823450-xgevk/posix_spawn/defconfig
@@ -6,7 +6,6 @@ CONFIG_ARCH_CHIP_LC823450=y
CONFIG_ARCH_FLOAT_H=y
CONFIG_ARCH_INTERRUPTSTACK=2048
CONFIG_ARCH_STDARG_H=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_APP_SYMTAB=y
CONFIG_BOARD_LOOPSPERMSEC=12061
CONFIG_C99_BOOL8=y
@@ -25,6 +24,7 @@ CONFIG_LC823450_UART0=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBM=y
CONFIG_LIB_BOARDCTL=y
+CONFIG_LIB_ENVPATH=y
CONFIG_LIB_KBDCODEC=y
CONFIG_MAX_TASKS=64
CONFIG_MAX_WDOGPARMS=2
diff --git a/configs/lc823450-xgevk/rndis/defconfig b/configs/lc823450-xgevk/rndis/defconfig
index e2646c13b4..50b9847750 100644
--- a/configs/lc823450-xgevk/rndis/defconfig
+++ b/configs/lc823450-xgevk/rndis/defconfig
@@ -17,7 +17,6 @@ CONFIG_AUDIO_EXCLUDE_FFORWARD=y
CONFIG_AUDIO_EXCLUDE_TONE=y
CONFIG_AUDIO_I2SCHAR=y
CONFIG_AUDIO_WM8776=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_RESET=y
CONFIG_BOARDCTL_USBDEVCTRL=y
CONFIG_BOARD_LOOPSPERMSEC=12061
@@ -69,6 +68,7 @@ CONFIG_LCD=y
CONFIG_LCD_ST7565=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBM=y
+CONFIG_LIB_ENVPATH=y
CONFIG_LIB_KBDCODEC=y
CONFIG_MAX_TASKS=64
CONFIG_MAX_WDOGPARMS=2
diff --git a/configs/olimex-stm32-p407/kelf/defconfig b/configs/olimex-stm32-p407/kelf/defconfig
index baf47b7175..2c32a624fd 100644
--- a/configs/olimex-stm32-p407/kelf/defconfig
+++ b/configs/olimex-stm32-p407/kelf/defconfig
@@ -8,7 +8,6 @@ CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_ARM_MPU=y
CONFIG_BINFMT_CONSTRUCTORS=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARD_INITIALIZE=y
CONFIG_BOARD_INITTHREAD=y
CONFIG_BOARD_LOOPSPERMSEC=16717
@@ -24,6 +23,7 @@ CONFIG_FAT_LFN=y
CONFIG_FS_FAT=y
CONFIG_HAVE_CXX=y
CONFIG_INTELHEX_BINARY=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MM_KERNEL_HEAPSIZE=16384
diff --git a/configs/sim/bas/defconfig b/configs/sim/bas/defconfig
index 92f1b279f2..5b06e240d3 100644
--- a/configs/sim/bas/defconfig
+++ b/configs/sim/bas/defconfig
@@ -3,7 +3,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
CONFIG_BUILTIN=y
@@ -18,6 +17,7 @@ CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_INTERPRETERS_BAS=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBM=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NFILE_DESCRIPTORS=32
CONFIG_NSH_ARCHINIT=y
diff --git a/configs/sim/bluetooth/defconfig b/configs/sim/bluetooth/defconfig
index 69ece9dbb5..83d687b46a 100644
--- a/configs/sim/bluetooth/defconfig
+++ b/configs/sim/bluetooth/defconfig
@@ -7,7 +7,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BLUETOOTH_MAX_CONN=2
CONFIG_BLUETOOTH_MAX_PAIRED=2
CONFIG_BLUETOOTH_NULL=y
@@ -34,6 +33,7 @@ CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NET=y
CONFIG_NETDEVICES=y
diff --git a/configs/sim/ipforward/defconfig b/configs/sim/ipforward/defconfig
index 7dd092dc7d..e096bb3f35 100644
--- a/configs/sim/ipforward/defconfig
+++ b/configs/sim/ipforward/defconfig
@@ -8,7 +8,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
@@ -28,6 +27,7 @@ CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NET=y
CONFIG_NETDEVICES=y
diff --git a/configs/sim/loadable/defconfig b/configs/sim/loadable/defconfig
index f52c89328f..0c4dddac48 100644
--- a/configs/sim/loadable/defconfig
+++ b/configs/sim/loadable/defconfig
@@ -2,7 +2,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_APP_SYMTAB=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_INITIALIZE=y
@@ -26,6 +25,7 @@ CONFIG_INIT_MOUNT_FSTYPE="hostfs"
CONFIG_INIT_MOUNT_SOURCE=""
CONFIG_INIT_MOUNT_TARGET="/system"
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MEMSET_OPTSPEED=y
CONFIG_NSH_ARCHINIT=y
CONFIG_NSH_BUILTIN_APPS=y
diff --git a/configs/sim/minibasic/defconfig b/configs/sim/minibasic/defconfig
index bd273f4046..223ccf4f34 100644
--- a/configs/sim/minibasic/defconfig
+++ b/configs/sim/minibasic/defconfig
@@ -4,7 +4,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
@@ -27,6 +26,7 @@ CONFIG_INTERPRETERS_MINIBASIC=y
CONFIG_INTERPRETER_MINIBASIC_TESTSCRIPT=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIBM=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NFILE_DESCRIPTORS=32
CONFIG_NSH_ARCHINIT=y
diff --git a/configs/sim/nsh/defconfig b/configs/sim/nsh/defconfig
index 8efa9fa0d6..209c7ce8d2 100644
--- a/configs/sim/nsh/defconfig
+++ b/configs/sim/nsh/defconfig
@@ -4,7 +4,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_APP_SYMTAB=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=0
@@ -26,6 +25,7 @@ CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NFILE_DESCRIPTORS=32
CONFIG_NSH_ARCHINIT=y
diff --git a/configs/sim/udgram/defconfig b/configs/sim/udgram/defconfig
index b646677835..85329a2e03 100644
--- a/configs/sim/udgram/defconfig
+++ b/configs/sim/udgram/defconfig
@@ -6,7 +6,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
CONFIG_BUILTIN=y
@@ -23,6 +22,7 @@ CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_IDLETHREAD_STACKSIZE=8192
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NET=y
CONFIG_NET_LOCAL=y
diff --git a/configs/sim/unionfs/defconfig b/configs/sim/unionfs/defconfig
index 4d8d6cfced..b0d82b8208 100644
--- a/configs/sim/unionfs/defconfig
+++ b/configs/sim/unionfs/defconfig
@@ -3,7 +3,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
CONFIG_BUILTIN=y
@@ -20,6 +19,7 @@ CONFIG_FS_ROMFS=y
CONFIG_FS_UNIONFS=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NFILE_DESCRIPTORS=32
CONFIG_NSH_ARCHINIT=y
diff --git a/configs/sim/userfs/defconfig b/configs/sim/userfs/defconfig
index 564df31d46..65b2aa20e1 100644
--- a/configs/sim/userfs/defconfig
+++ b/configs/sim/userfs/defconfig
@@ -6,7 +6,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_POWEROFF=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
@@ -28,6 +27,7 @@ CONFIG_FS_ROMFS=y
CONFIG_FS_USERFS=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NET=y
CONFIG_NETDEVICES=y
diff --git a/configs/sim/ustream/defconfig b/configs/sim/ustream/defconfig
index 168fe796a4..f8bcdd204f 100644
--- a/configs/sim/ustream/defconfig
+++ b/configs/sim/ustream/defconfig
@@ -6,7 +6,6 @@ CONFIG_ARCH="sim"
CONFIG_ARCH_BOARD="sim"
CONFIG_ARCH_BOARD_SIM=y
CONFIG_ARCH_SIM=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_APP_SYMTAB=y
CONFIG_BOARD_LOOPSPERMSEC=0
CONFIG_BOOT_RUNFROMEXTSRAM=y
@@ -23,6 +22,7 @@ CONFIG_FS_PROCFS=y
CONFIG_FS_ROMFS=y
CONFIG_IDLETHREAD_STACKSIZE=4096
CONFIG_LIBC_EXECFUNCS=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=64
CONFIG_NET=y
CONFIG_NET_LOCAL=y
diff --git a/configs/stm32f4discovery/elf/defconfig b/configs/stm32f4discovery/elf/defconfig
index 926d0a7029..f212f89524 100644
--- a/configs/stm32f4discovery/elf/defconfig
+++ b/configs/stm32f4discovery/elf/defconfig
@@ -7,7 +7,6 @@ CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_ARMV7M_USEBASEPRI=y
CONFIG_BINFMT_CONSTRUCTORS=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARD_INITIALIZE=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_DEV_LOWCONSOLE=y
@@ -18,6 +17,7 @@ CONFIG_FS_ROMFS=y
CONFIG_HAVE_CXX=y
CONFIG_HOST_WINDOWS=y
CONFIG_INTELHEX_BINARY=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MM_REGIONS=2
diff --git a/configs/stm32f4discovery/posix_spawn/defconfig b/configs/stm32f4discovery/posix_spawn/defconfig
index e29d347410..0d8d8aced0 100644
--- a/configs/stm32f4discovery/posix_spawn/defconfig
+++ b/configs/stm32f4discovery/posix_spawn/defconfig
@@ -6,7 +6,6 @@ CONFIG_ARCH_CHIP_STM32=y
CONFIG_ARCH_CHIP_STM32F407VG=y
CONFIG_ARCH_STACKDUMP=y
CONFIG_BINFMT_CONSTRUCTORS=y
-CONFIG_BINFMT_EXEPATH=y
CONFIG_BOARDCTL_APP_SYMTAB=y
CONFIG_BOARD_LOOPSPERMSEC=16717
CONFIG_DEV_LOWCONSOLE=y
@@ -21,6 +20,7 @@ CONFIG_HOST_WINDOWS=y
CONFIG_INTELHEX_BINARY=y
CONFIG_LIBC_EXECFUNCS=y
CONFIG_LIB_BOARDCTL=y
+CONFIG_LIB_ENVPATH=y
CONFIG_MAX_TASKS=16
CONFIG_MAX_WDOGPARMS=2
CONFIG_MM_REGIONS=2
diff --git a/include/nuttx/binfmt/binfmt.h b/include/nuttx/binfmt/binfmt.h
index ee50bfea80..4be3b22b15 100644
--- a/include/nuttx/binfmt/binfmt.h
+++ b/include/nuttx/binfmt/binfmt.h
@@ -58,14 +58,6 @@
* Public Types
****************************************************************************/
-/* EXEPATH_HANDLE is an opaque handle used to traverse the absolute paths
- * assigned to the PATH environment variable.
- */
-
-#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
-typedef FAR void *EXEPATH_HANDLE;
-#endif
-
/* The type of one C++ constructor or destructor */
typedef FAR void (*binfmt_ctor_t)(void);
@@ -74,7 +66,7 @@ typedef FAR void (*binfmt_dtor_t)(void);
/* This describes the file to be loaded.
*
* NOTE 1: The 'filename' must be the full, absolute path to the file to be
- * executed unless CONFIG_BINFMT_EXEPATH is defined. In that case,
+ * executed unless CONFIG_LIB_ENVPATH is defined. In that case,
* 'filename' may be a relative path; a set of candidate absolute paths
* will be generated using the PATH environment variable and load_module()
* will attempt to load each file that is found at those absolute paths.
@@ -300,7 +292,7 @@ int exec_module(FAR const struct binary_s *bin);
*
* Input Parameters:
* filename - The path to the program to be executed. If
- * CONFIG_BINFMT_EXEPATH is defined in the configuration, then
+ * CONFIG_LIB_ENVPATH is defined in the configuration, then
* this may be a relative path from the current working
* directory. Otherwise, path must be the absolute path to the
* program.
@@ -345,89 +337,6 @@ int exec(FAR const char *filename, FAR char * const *argv,
int binfmt_exit(FAR struct binary_s *bin);
#endif
-/****************************************************************************
- * Name: exepath_init
- *
- * Description:
- * Initialize for the traversal of each value in the PATH variable. The
- * usage is sequence is as follows:
- *
- * 1) Call exepath_init() to initialize for the traversal. exepath_init()
- * will return an opaque handle that can then be provided to
- * exepath_next() and exepath_release().
- * 2) Call exepath_next() repeatedly to examine every file that lies
- * in the directories of the PATH variable
- * 3) Call exepath_release() to free resources set aside by exepath_init().
- *
- * Input Parameters:
- * None
- *
- * Returned Value:
- * On success, exepath_init() return a non-NULL, opaque handle that may
- * subsequently be used in calls to exepath_next() and exepath_release().
- * On error, a NULL handle value will be returned. The most likely cause
- * of an error would be that there is no value associated with the PATH
- * variable.
- *
- ****************************************************************************/
-
-#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
-EXEPATH_HANDLE exepath_init(void);
-#endif
-
-/****************************************************************************
- * Name: exepath_next
- *
- * Description:
- * Traverse all possible values in the PATH variable in attempt to find
- * the full path to an executable file when only a relative path is
- * provided.
- *
- * Input Parameters:
- * handle - The handle value returned by exepath_init
- * relpath - The relative path to the file to be found.
- *
- * Returned Value:
- * On success, a non-NULL pointer to a null-terminated string is provided.
- * This is the full path to a file that exists in the file system. This
- * function will verify that the file exists (but will not verify that it
- * is marked executable).
- *
- * NOTE: The string pointer return in the success case points to allocated
- * memory. This memory must be freed by the called by calling kmm_free().
- *
- * NULL is returned if no path is found to any file with the provided
- * 'relpath' from any absolute path in the PATH variable. In this case,
- * there is no point in calling exepath_next() further; exepath_release()
- * must be called to release resources set aside by expath_init().
- *
- ****************************************************************************/
-
-#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
-FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
-#endif
-
-/****************************************************************************
- * Name: exepath_release
- *
- * Description:
- * Release all resources set aside by exepath_init() when the handle value
- * was created. The handle value is invalid on return from this function.
- * Attempts to all exepath_next() or exepath_release() with such a 'stale'
- * handle will result in undefined (i.e., not good) behavior.
- *
- * Input Parameters:
- * handle - The handle value returned by exepath_init
- *
- * Returned Value:
- * None
- *
- ****************************************************************************/
-
-#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
-void exepath_release(EXEPATH_HANDLE handle);
-#endif
-
#undef EXTERN
#if defined(__cplusplus)
}
diff --git a/include/nuttx/envpath.h b/include/nuttx/envpath.h
new file mode 100644
index 0000000000..8f75ff809b
--- /dev/null
+++ b/include/nuttx/envpath.h
@@ -0,0 +1,159 @@
+/****************************************************************************
+ * include/nuttx/envpath.h
+ *
+ * Copyright (C) 2018 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_NUTTX_ENVPATH_H
+#define __INCLUDE_NUTTX_ENVPATH_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include
+
+#ifdef CONFIG_LIB_ENVPATH
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Public Types
+ ****************************************************************************/
+
+/* ENVPATH_HANDLE is an opaque handle used to traverse the absolute paths
+ * assigned to the PATH environment variable.
+ */
+
+typedef FAR void *ENVPATH_HANDLE;
+
+/****************************************************************************
+ * Public Function Prototypes
+ ****************************************************************************/
+
+#ifdef __cplusplus
+#define EXTERN extern "C"
+extern "C"
+{
+#else
+#define EXTERN extern
+#endif
+
+/****************************************************************************
+ * Name: envpath_init
+ *
+ * Description:
+ * Initialize for the traversal of each value in the PATH variable. The
+ * usage is sequence is as follows:
+ *
+ * Input Parameters:
+ * name - The variable name of environment to searches path list.
+ *
+ * 1) Call envpath_init() to initialize for the traversal. envpath_init()
+ * will return an opaque handle that can then be provided to
+ * envpath_next() and envpath_release().
+ * 2) Call envpath_next() repeatedly to examine every file that lies
+ * in the directories of the PATH variable
+ * 3) Call envpath_release() to free resources set aside by envpath_init().
+ *
+ * Input Parameters:
+ * None
+ *
+ * Returned Value:
+ * On success, envpath_init() return a non-NULL, opaque handle that may
+ * subsequently be used in calls to envpath_next() and envpath_release().
+ * On error, a NULL handle value will be returned. The most likely cause
+ * of an error would be that there is no value associated with the PATH
+ * variable.
+ *
+ ****************************************************************************/
+
+ENVPATH_HANDLE envpath_init(FAR const char *name);
+
+/****************************************************************************
+ * Name: envpath_next
+ *
+ * Description:
+ * Traverse all possible values in the PATH variable in attempt to find
+ * the full path to an executable file when only a relative path is
+ * provided.
+ *
+ * Input Parameters:
+ * handle - The handle value returned by envpath_init
+ * relpath - The relative path to the file to be found.
+ *
+ * Returned Value:
+ * On success, a non-NULL pointer to a null-terminated string is provided.
+ * This is the full path to a file that exists in the file system. This
+ * function will verify that the file exists (but will not verify that it
+ * is marked executable).
+ *
+ * NOTE: The string pointer return in the success case points to allocated
+ * memory. This memory must be freed by the called by calling kmm_free().
+ *
+ * NULL is returned if no path is found to any file with the provided
+ * 'relpath' from any absolute path in the PATH variable. In this case,
+ * there is no point in calling envpath_next() further; envpath_release()
+ * must be called to release resources set aside by expath_init().
+ *
+ ****************************************************************************/
+
+FAR char *envpath_next(ENVPATH_HANDLE handle, FAR const char *relpath);
+
+/****************************************************************************
+ * Name: envpath_release
+ *
+ * Description:
+ * Release all resources set aside by envpath_init() when the handle value
+ * was created. The handle value is invalid on return from this function.
+ * Attempts to all envpath_next() or envpath_release() with such a 'stale'
+ * handle will result in undefined (i.e., not good) behavior.
+ *
+ * Input Parameters:
+ * handle - The handle value returned by envpath_init
+ *
+ * Returned Value:
+ * None
+ *
+ ****************************************************************************/
+
+void envpath_release(ENVPATH_HANDLE handle);
+
+#undef EXTERN
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CONFIG_LIB_ENVPATH */
+#endif /* INCLUDE_NUTTX_ENVPATH_H */
diff --git a/include/nuttx/lib/modlib.h b/include/nuttx/lib/modlib.h
index d76c0120c3..e2c1feb057 100644
--- a/include/nuttx/lib/modlib.h
+++ b/include/nuttx/lib/modlib.h
@@ -222,8 +222,6 @@ struct mod_loadinfo_s
****************************************************************************/
struct symtab_s;
-FAR const struct symtab_s *g_modlib_symtab;
-FAR int g_modlib_nsymbols;
/****************************************************************************
* Public Function Prototypes
diff --git a/include/spawn.h b/include/spawn.h
index 5ffbd03199..46a848173a 100644
--- a/include/spawn.h
+++ b/include/spawn.h
@@ -137,7 +137,7 @@ extern "C"
* file system at 'path'
*/
-#ifdef CONFIG_BINFMT_EXEPATH
+#ifdef CONFIG_LIB_ENVPATH
int posix_spawnp(FAR pid_t *pid, FAR const char *path,
FAR const posix_spawn_file_actions_t *file_actions,
FAR const posix_spawnattr_t *attr,
diff --git a/include/sys/syscall.h b/include/sys/syscall.h
index 88d0473f0d..3beacfa62b 100644
--- a/include/sys/syscall.h
+++ b/include/sys/syscall.h
@@ -200,7 +200,7 @@
# define __SYS_posix_spawn __SYS_exec
# endif
# ifdef CONFIG_LIBC_EXECFUNCS
-# ifdef CONFIG_BINFMT_EXEPATH
+# ifdef CONFIG_LIB_ENVPATH
# define SYS_posix_spawnp __SYS_posix_spawn
# else
# define SYS_posix_spawn __SYS_posix_spawn
diff --git a/libs/libc/misc/Kconfig b/libs/libc/misc/Kconfig
index b0dc66b601..fce6ab36f1 100644
--- a/libs/libc/misc/Kconfig
+++ b/libs/libc/misc/Kconfig
@@ -102,3 +102,11 @@ config LIB_SLCDCODEC
include/nuttx/lcd/slcd_codec.h. While not correctly a part of the C
library, it is included here because the encoding side of this
interface must be accessible by end user programs.
+
+config LIB_ENVPATH
+ bool "Support PATH Environment Variable"
+ default n
+ depends on !DISABLE_ENVIRON
+ ---help---
+ Use the contents of the common environment variable to locate executable
+ or library files. Default: n
diff --git a/libs/libc/misc/Make.defs b/libs/libc/misc/Make.defs
index a72ef15a81..31a06aa4a9 100644
--- a/libs/libc/misc/Make.defs
+++ b/libs/libc/misc/Make.defs
@@ -103,6 +103,12 @@ ifeq ($(CONFIG_LIB_SLCDCODEC),y)
CSRCS += lib_slcdencode.c lib_slcddecode.c
endif
+# Environment search path support
+
+ifeq ($(CONFIG_LIB_ENVPATH),y)
+CSRCS += lib_envpath.c
+endif
+
# Add the misc directory to the build
DEPPATH += --dep-path misc
diff --git a/binfmt/binfmt_exepath.c b/libs/libc/misc/lib_envpath.c
similarity index 76%
rename from binfmt/binfmt_exepath.c
rename to libs/libc/misc/lib_envpath.c
index 18af9643ca..7660bfc913 100644
--- a/binfmt/binfmt_exepath.c
+++ b/libs/libc/misc/lib_envpath.c
@@ -1,7 +1,7 @@
/****************************************************************************
- * binfmt/binfmt_exepath.c
+ * libs/libc/misc/lib_envpath.c
*
- * Copyright (C) 2012 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2012, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
*
* Redistribution and use in source and binary forms, with or without
@@ -47,120 +47,124 @@
#include
#include
-#include
-#include
+#include
-#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
+#include "libc.h"
+
+#if defined(CONFIG_LIB_ENVPATH)
/****************************************************************************
* Private Types
****************************************************************************/
-struct exepath_s
+struct envpath_s
{
FAR char *next; /* Pointer to the next (unterminated) value in the PATH variable */
char path[1];
};
-#define SIZEOF_EXEPATH_S(n) (sizeof(struct exepath_s) + (n) - 1)
+
+#define SIZEOF_ENVPATH_S(n) (sizeof(struct envpath_s) + (n) - 1)
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
- * Name: exepath_init
+ * Name: envpath_init
*
* Description:
* Initialize for the traversal of each value in the PATH variable. The
* usage is sequence is as follows:
*
- * 1) Call exepath_init() to initialize for the traversal. exepath_init()
+ * 1) Call envpath_init() to initialize for the traversal. envpath_init()
* will return an opaque handle that can then be provided to
- * exepath_next() and exepath_release().
- * 2) Call exepath_next() repeatedly to examine every file that lies
+ * envpath_next() and envpath_release().
+ * 2) Call envpath_next() repeatedly to examine every file that lies
* in the directories of the PATH variable
- * 3) Call exepath_release() to free resources set aside by exepath_init().
+ * 3) Call envpath_release() to free resources set aside by envpath_init().
*
* Input Parameters:
* None
*
* Returned Value:
- * On success, exepath_init() return a non-NULL, opaque handle that may
- * subsequently be used in calls to exepath_next() and exepath_release().
+ * On success, envpath_init() return a non-NULL, opaque handle that may
+ * subsequently be used in calls to envpath_next() and envpath_release().
* On error, a NULL handle value will be returned. The most likely cause
* of an error would be that there is no value associated with the PATH
* variable.
*
****************************************************************************/
-EXEPATH_HANDLE exepath_init(void)
+ENVPATH_HANDLE envpath_init(FAR const char *name)
{
- FAR struct exepath_s *exepath;
+ FAR struct envpath_s *envpath;
FAR char *path;
/* Get the value of the PATH variable */
- path = getenv("PATH");
+ path = getenv(name);
if (!path)
{
/* getenv() will return a NULL value if the PATH variable does not
* exist in the environment.
*/
- return (EXEPATH_HANDLE)NULL;
+ return (ENVPATH_HANDLE)NULL;
}
/* Allocate a container for the PATH variable contents */
- exepath = (FAR struct exepath_s *)kmm_malloc(SIZEOF_EXEPATH_S(strlen(path) + 1));
- if (!exepath)
+ envpath = (FAR struct envpath_s *)
+ lib_malloc(SIZEOF_ENVPATH_S(strlen(path) + 1));
+
+ if (!envpath)
{
/* Ooops.. we are out of memory */
- return (EXEPATH_HANDLE)NULL;
+ return (ENVPATH_HANDLE)NULL;
}
/* Populate the container */
- strcpy(exepath->path, path);
- exepath->next = exepath->path;
+ strcpy(envpath->path, path);
+ envpath->next = envpath->path;
/* And return the containing cast to an opaque handle */
- return (EXEPATH_HANDLE)exepath;
+ return (ENVPATH_HANDLE)envpath;
}
/****************************************************************************
- * Name: exepath_next
+ * Name: envpath_next
*
* Description:
* Traverse all possible values in the PATH variable in attempt to find
- * the full path to an executable file when only a relative path is
+ * the full path to an envcutable file when only a relative path is
* provided.
*
* Input Parameters:
- * handle - The handle value returned by exepath_init
+ * handle - The handle value returned by envpath_init
* relpath - The relative path to the file to be found.
*
* Returned Value:
* On success, a non-NULL pointer to a null-terminated string is provided.
* This is the full path to a file that exists in the file system. This
* function will verify that the file exists (but will not verify that it
- * is marked executable).
+ * is marked envcutable).
*
* NOTE: The string pointer return in the success case points to allocated
- * memory. This memory must be freed by the called by calling kmm_free().
+ * memory. This memory must be freed by the called by calling lib_free().
*
* NULL is returned if no path is found to any file with the provided
* 'relpath' from any absolute path in the PATH variable. In this case,
- * there is no point in calling exepath_next() further; exepath_release()
+ * there is no point in calling envpath_next() further; envpath_release()
* must be called to release resources set aside by expath_init().
*
****************************************************************************/
-FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
+FAR char *envpath_next(ENVPATH_HANDLE handle, FAR const char *relpath)
{
- FAR struct exepath_s *exepath = (FAR struct exepath_s *)handle;
+ FAR struct envpath_s *envpath = (FAR struct envpath_s *)handle;
struct stat buf;
FAR char *endptr;
FAR char *path;
@@ -170,7 +174,7 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
/* Verify that a value handle and relative path were provided */
- DEBUGASSERT(exepath && relpath);
+ DEBUGASSERT(envpath && relpath);
DEBUGASSERT(relpath[0] != '\0' && relpath[0] != '/');
/* Loop until (1) we find a file with this relative path from one of the
@@ -180,9 +184,9 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
for (; ; )
{
- /* Make sure that exepath->next points to the beginning of a string */
+ /* Make sure that envpath->next points to the beginning of a string */
- path = exepath->next;
+ path = envpath->next;
if (*path == '\0')
{
/* If it points to a NULL it means that either (1) the PATH varialbe
@@ -199,7 +203,7 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
*/
endptr = strchr(path, ':');
- if (!endptr)
+ if (endptr == NULL)
{
/* If strchr returns NUL it means that ':' does not appear in the
* string. Therefore, this must be the final path in the PATH
@@ -207,19 +211,19 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
*/
endptr = &path[strlen(path)];
- exepath->next = endptr;
+ envpath->next = endptr;
DEBUGASSERT(*endptr == '\0');
}
else
{
DEBUGASSERT(*endptr == ':');
- exepath->next = endptr + 1;
+ envpath->next = endptr + 1;
*endptr = '\0';
}
pathlen = strlen(path) + strlen(relpath) + 2;
- fullpath = (FAR char *)kmm_malloc(pathlen);
- if (!fullpath)
+ fullpath = (FAR char *)lib_malloc(pathlen);
+ if (fullpathi == NULL)
{
/* Failed to allocate memory */
@@ -242,33 +246,33 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath)
* continue to try the next path.
*/
- kmm_free(fullpath);
+ lib_free(fullpath);
}
/* We will not get here */
}
/****************************************************************************
- * Name: exepath_release
+ * Name: envpath_release
*
* Description:
- * Release all resources set aside by exepath_init() when the handle value
+ * Release all resources set aside by envpath_init() when the handle value
* was created. The handle value is invalid on return from this function.
- * Attempts to all exepath_next() or exepath_release() with such a 'stale'
+ * Attempts to all envpath_next() or envpath_release() with such a 'stale'
* handle will result in undefined (i.e., not good) behavior.
*
* Input Parameters:
- * handle - The handle value returned by exepath_init
+ * handle - The handle value returned by envpath_init
*
* Returned Value:
* None
*
****************************************************************************/
-void exepath_release(EXEPATH_HANDLE handle)
+void envpath_release(ENVPATH_HANDLE handle)
{
- kmm_free(handle);
+ lib_free(handle);
}
-#endif /* !CONFIG_BINFMT_DISABLE && CONFIG_BINFMT_EXEPATH */
+#endif /* CONFIG_LIBC_ENVPATH */
diff --git a/libs/libc/modlib/Kconfig b/libs/libc/modlib/Kconfig
index eeb5d05dcc..56e52b98f7 100644
--- a/libs/libc/modlib/Kconfig
+++ b/libs/libc/modlib/Kconfig
@@ -56,4 +56,24 @@ config MODLIB_DUMPBUFFER
---help---
Dump various module buffers for debug purposes
+config MODLIB_HAVE_SYMTAB
+ bool "Have symbol table"
+ default n if BUILD_KERNEL
+ ---help---
+ If you have a module library symbol table, then you may select this
+ option in order to use it. Symbol tables are required in most
+ cases in order to link executable programs to the base code.
+
+if MODLIB_HAVE_SYMTAB
+
+config MODLIB_SYMTAB_ARRAY
+ string "Symbol table name used by dlsym"
+ default "g_mod_symtab"
+
+config MODLIB_NSYMBOLS_VAR
+ string "Name of variable holding the number of symbols"
+ default "g_mod_nsymbols"
+
+endif # MODLIB_HAVE_SYMTAB
+
endmenu # Module library configuration
diff --git a/libs/libc/modlib/modlib_symbols.c b/libs/libc/modlib/modlib_symbols.c
index 090a85ba60..8ef575e212 100644
--- a/libs/libc/modlib/modlib_symbols.c
+++ b/libs/libc/modlib/modlib_symbols.c
@@ -337,6 +337,7 @@ int modlib_symvalue(FAR struct module_s *modp,
FAR const struct symtab_s *symbol;
struct mod_exportinfo_s exportinfo;
uintptr_t secbase;
+ int nsymbols;
int ret;
switch (sym->st_shndx)
@@ -399,12 +400,13 @@ int modlib_symvalue(FAR struct module_s *modp,
if (symbol == NULL)
{
+ modlib_getsymtab(&symbol, &nsymbols);
#ifdef CONFIG_SYMTAB_ORDEREDBYNAME
- symbol = symtab_findorderedbyname(g_modlib_symtab, exportinfo.name,
- g_modlib_nsymbols);
+ symbol = symtab_findorderedbyname(symbol, exportinfo.name,
+ nsymbols);
#else
- symbol = symtab_findbyname(g_modlib_symtab, exportinfo.name,
- g_modlib_nsymbols);
+ symbol = symtab_findbyname(symbol, exportinfo.name,
+ nsymbols);
#endif
}
diff --git a/libs/libc/modlib/modlib_symtab.c b/libs/libc/modlib/modlib_symtab.c
index 575428e886..f69c0a2895 100644
--- a/libs/libc/modlib/modlib_symtab.c
+++ b/libs/libc/modlib/modlib_symtab.c
@@ -1,7 +1,7 @@
/****************************************************************************
* libs/libc/modlib/modlib_symtab.c
*
- * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
+ * Copyright (C) 2015, 2017-2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt
*
* Redistribution and use in source and binary forms, with or without
@@ -45,12 +45,39 @@
#include
#include
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#ifdef CONFIG_MODLIB_HAVE_SYMTAB
+ /* Symbol table used by dlsym */
+
+# ifndef CONFIG_MODLIB_SYMTAB_ARRAY
+# error "CONFIG_MODLIB_SYMTAB_ARRAY must be defined"
+# endif
+
+ /* Number of Symbols in the Table */
+
+# ifndef CONFIG_MODLIB_NSYMBOLS_VAR
+# error "CONFIG_MODLIB_NSYMBOLS_VAR must be defined"
+# endif
+#endif
+
/****************************************************************************
* Public Data
****************************************************************************/
-FAR const struct symtab_s *g_modlib_symtab;
-FAR int g_modlib_nsymbols;
+#ifdef CONFIG_MODLIB_HAVE_SYMTAB
+extern const struct symtab_s CONFIG_MODLIB_SYMTAB_ARRAY[];
+extern int CONFIG_MODLIB_NSYMBOLS_VAR;
+#endif
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static FAR const struct symtab_s *g_modlib_symtab;
+static FAR int g_modlib_nsymbols;
/****************************************************************************
* Public Functions
@@ -64,7 +91,8 @@ FAR int g_modlib_nsymbols;
*
* Input Parameters:
* symtab - The location to store the symbol table.
- * nsymbols - The location to store the number of symbols in the symbol table.
+ * nsymbols - The location to store the number of symbols in the symbol
+ * table.
*
* Returned Value:
* None
@@ -78,6 +106,14 @@ void modlib_getsymtab(FAR const struct symtab_s **symtab, FAR int *nsymbols)
/* Borrow the registry lock to assure atomic access */
modlib_registry_lock();
+#ifdef CONFIG_MODLIB_HAVE_SYMTAB
+ if (g_modlib_symtab == NULL)
+ {
+ g_modlib_symtab = CONFIG_MODLIB_SYMTAB_ARRAY;
+ g_modlib_nsymbols = CONFIG_MODLIB_NSYMBOLS_VAR;
+ }
+#endif
+
*symtab = g_modlib_symtab;
*nsymbols = g_modlib_nsymbols;
modlib_registry_unlock();
diff --git a/libs/libc/unistd/lib_execl.c b/libs/libc/unistd/lib_execl.c
index ec02a110d4..e9af31a33a 100644
--- a/libs/libc/unistd/lib_execl.c
+++ b/libs/libc/unistd/lib_execl.c
@@ -111,7 +111,7 @@
* task.
*
* Input Parameters:
- * path - The path to the program to be executed. If CONFIG_BINFMT_EXEPATH
+ * path - The path to the program to be executed. If CONFIG_LIB_ENVPATH
* is defined in the configuration, then this may be a relative path
* from the current working directory. Otherwise, path must be the
* absolute path to the program.
diff --git a/sched/task/task_execv.c b/sched/task/task_execv.c
index 61674fc1c7..bb947223f7 100644
--- a/sched/task/task_execv.c
+++ b/sched/task/task_execv.c
@@ -106,7 +106,7 @@
* task.
*
* Input Parameters:
- * path - The path to the program to be executed. If CONFIG_BINFMT_EXEPATH
+ * path - The path to the program to be executed. If CONFIG_LIB_ENVPATH
* is defined in the configuration, then this may be a relative path
* from the current working directory. Otherwise, path must be the
* absolute path to the program.
diff --git a/sched/task/task_posixspawn.c b/sched/task/task_posixspawn.c
index e3f11a8b99..9c75ab47e5 100644
--- a/sched/task/task_posixspawn.c
+++ b/sched/task/task_posixspawn.c
@@ -69,7 +69,7 @@
* child task in the variable pointed to by a non-NULL 'pid' argument.|
*
* path - The 'path' argument identifies the file to execute. If
- * CONFIG_BINFMT_EXEPATH is defined, this may be either a relative or
+ * CONFIG_LIB_ENVPATH is defined, this may be either a relative or
* or an absolute path. Otherwise, it must be an absolute path.
*
* attr - If the value of the 'attr' parameter is NULL, the all default
@@ -257,7 +257,7 @@ static int posix_spawn_proxy(int argc, FAR char *argv[])
* directories passed as the environment variable PATH.
*
* NOTE: NuttX provides only one implementation: If
- * CONFIG_BINFMT_EXEPATH is defined, then only posix_spawnp() behavior
+ * CONFIG_LIB_ENVPATH is defined, then only posix_spawnp() behavior
* is supported; otherwise, only posix_spawn behavior is supported.
*
* file_actions - If 'file_actions' is a null pointer, then file
@@ -309,8 +309,8 @@ static int posix_spawn_proxy(int argc, FAR char *argv[])
*
* Assumptions/Limitations:
* - NuttX provides only posix_spawn() or posix_spawnp() behavior
- * depending upon the setting of CONFIG_BINFMT_EXEPATH: If
- * CONFIG_BINFMT_EXEPATH is defined, then only posix_spawnp() behavior
+ * depending upon the setting of CONFIG_LIB_ENVPATH: If
+ * CONFIG_LIB_ENVPATH is defined, then only posix_spawnp() behavior
* is supported; otherwise, only posix_spawn behavior is supported.
* - The 'envp' argument is not used and the 'environ' variable is not
* altered (NuttX does not support the 'environ' variable).
@@ -327,7 +327,7 @@ static int posix_spawn_proxy(int argc, FAR char *argv[])
*
****************************************************************************/
-#ifdef CONFIG_BINFMT_EXEPATH
+#ifdef CONFIG_LIB_ENVPATH
int posix_spawnp(FAR pid_t *pid, FAR const char *path,
FAR const posix_spawn_file_actions_t *file_actions,
FAR const posix_spawnattr_t *attr,
diff --git a/sched/task/task_spawn.c b/sched/task/task_spawn.c
index 8f2ee750ec..08b4ce4a14 100644
--- a/sched/task/task_spawn.c
+++ b/sched/task/task_spawn.c
@@ -70,7 +70,7 @@
* child task in the variable pointed to by a non-NULL 'pid' argument.|
*
* path - The 'path' argument identifies the file to execute. If
- * CONFIG_BINFMT_EXEPATH is defined, this may be either a relative or
+ * CONFIG_LIB_ENVPATH is defined, this may be either a relative or
* or an absolute path. Otherwise, it must be an absolute path.
*
* attr - If the value of the 'attr' parameter is NULL, the all default
diff --git a/syscall/syscall.csv b/syscall/syscall.csv
index 4a87854310..13c365e9a0 100644
--- a/syscall/syscall.csv
+++ b/syscall/syscall.csv
@@ -70,8 +70,8 @@
"prctl","sys/prctl.h", "CONFIG_TASK_NAME_SIZE > 0","int","int","..."
"pread","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","FAR void*","size_t","off_t"
"pwrite","unistd.h","CONFIG_NSOCKET_DESCRIPTORS > 0 || CONFIG_NFILE_DESCRIPTORS > 0","ssize_t","int","FAR const void*","size_t","off_t"
-"posix_spawnp","spawn.h","!defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_BINFMT_EXEPATH)","int","FAR pid_t *","FAR const char *","FAR const posix_spawn_file_actions_t *","FAR const posix_spawnattr_t *","FAR char *const []|FAR char *const *","FAR char *const []|FAR char *const *"
-"posix_spawn","spawn.h","!defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS) && !defined(CONFIG_BINFMT_EXEPATH)","int","FAR pid_t *","FAR const char *","FAR const posix_spawn_file_actions_t *","FAR const posix_spawnattr_t *","FAR char *const []|FAR char *const *","FAR char *const []|FAR char *const *"
+"posix_spawnp","spawn.h","!defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS) && defined(CONFIG_LIB_ENVPATH)","int","FAR pid_t *","FAR const char *","FAR const posix_spawn_file_actions_t *","FAR const posix_spawnattr_t *","FAR char *const []|FAR char *const *","FAR char *const []|FAR char *const *"
+"posix_spawn","spawn.h","!defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_LIBC_EXECFUNCS) && !defined(CONFIG_LIB_ENVPATH)","int","FAR pid_t *","FAR const char *","FAR const posix_spawn_file_actions_t *","FAR const posix_spawnattr_t *","FAR char *const []|FAR char *const *","FAR char *const []|FAR char *const *"
"pthread_cancel","pthread.h","!defined(CONFIG_DISABLE_PTHREAD)","int","pthread_t"
"pthread_cleanup_pop","pthread.h","defined(CONFIG_PTHREAD_CLEANUP)","void","int"
"pthread_cleanup_push","pthread.h","defined(CONFIG_PTHREAD_CLEANUP)","void","pthread_cleanup_t","FAR void*"
diff --git a/syscall/syscall_lookup.h b/syscall/syscall_lookup.h
index 4ec8b1dded..2ec407c024 100644
--- a/syscall/syscall_lookup.h
+++ b/syscall/syscall_lookup.h
@@ -135,7 +135,7 @@ SYSCALL_LOOKUP(up_assert, 2, STUB_up_assert)
SYSCALL_LOOKUP(exec, 4, STUB_exec)
#endif
#ifdef CONFIG_LIBC_EXECFUNCS
-#ifdef CONFIG_BINFMT_EXEPATH
+#ifdef CONFIG_LIB_ENVPATH
SYSCALL_LOOKUP(posix_spawnp, 6, STUB_posix_spawnp)
#else
SYSCALL_LOOKUP(posix_spawn, 6, STUB_posix_spawn)
diff --git a/tools/cfgdefine.c b/tools/cfgdefine.c
index 27670f6bd4..4349ef0cd1 100644
--- a/tools/cfgdefine.c
+++ b/tools/cfgdefine.c
@@ -66,6 +66,8 @@ static const char *dequote_list[] =
"CONFIG_USER_ENTRYPOINT", /* Name of entry point function */
"CONFIG_EXECFUNCS_SYMTAB_ARRAY", /* Symbol table array used by exec[l|v] */
"CONFIG_EXECFUNCS_NSYMBOLS_VAR", /* Variable holding number of symbols in the table */
+ "CONFIG_MODLIB_SYMTAB_ARRAY", /* Symbol table array used by dllfcn[l|v] */
+ "CONFIG_MODLIB_NSYMBOLS_VAR", /* Variable holding number of symbols in the table */
"CONFIG_PASS1_BUILDIR", /* Pass1 build directory */
"CONFIG_PASS1_TARGET", /* Pass1 build target */
"CONFIG_PASS1_OBJECT", /* Pass1 build object */