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
This commit is contained in:
nchao 2018-11-08 07:27:14 -06:00 committed by Gregory Nutt
parent da737f3167
commit 6509a0c0ca
43 changed files with 368 additions and 235 deletions

View File

@ -186,7 +186,7 @@ struct binary_s
<ul>
<p><small>
<sup>1</sup>The <code>filename</code> must be the full, absolute path to the file to be executed unless <code>CONFIG_BINFMT_EXEPATH</code> is defined.
<sup>1</sup>The <code>filename</code> must be the full, absolute path to the file to be executed unless <code>CONFIG_LIB_ENVPATH</code> is defined.
In that case, <code>filename</code> may be a relative path;
a set of candidate absolute paths will be generated using the <code>PATH</code> environment variable and <a href="#load_module"><code>load_module()</code></a> will attempt to load each file that is found at those absolute paths.
</small></p>
@ -224,9 +224,9 @@ typedef FAR void (*binfmt_dtor_t)(void);
<code>PATH</code> traversal logic:
</h3>
<ul>
<a href="#exepath_init">2.3.8 <code>exepath_init()</code></a><br>
<a href="#exepath_next">2.3.9 <code>exepath_next()</code></a><br>
<a href="#exepath_release">2.3.10 <code>exepath_release()</code></a>
<a href="#envpath_init">2.3.8 <code>envpath_init()</code></a><br>
<a href="#envpath_next">2.3.9 <code>envpath_next()</code></a><br>
<a href="#envpath_release">2.3.10 <code>envpath_release()</code></a>
</ul>
<h3>2.3.1 <a name="register_binfmt"><code>register_binfmt()</code></a></h3>
@ -273,7 +273,7 @@ int load_module(FAR struct binary_s *bin);
</p>
<p>
<code>load_module()</code> will use the <code>filename</code> field in the <a href="#binfmtdata"><code>struct binary_s</code></a> in order to locate the module to be loaded from the file system.
The <code>filename</code> must be the full, absolute path to the file to be executed unless <code>CONFIG_BINFMT_EXEPATH</code> is defined.
The <code>filename</code> must be the full, absolute path to the file to be executed unless <code>CONFIG_LIB_ENVPATH</code> is defined.
In that case, <code>filename</code> may be a relative path;
a set of candidate absolute paths will be generated using the <code>PATH</code> environment variable and <code>load_module()</code> will attempt to load each file that is found at those absolute paths.
</p>
@ -345,12 +345,12 @@ int exec(FAR const char *filename, FAR const char **argv,
On failure, it returns -1 (<code>ERROR</code>) with <code>errno</code> set appropriately.
</ul>
<h3>2.3.8 <a name="exepath_init"><code>exepath_init()</code></a></h3>
<h3>2.3.8 <a name="envpath_init"><code>envpath_init()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt:nuttx/binfmt/binfmt.h&gt;
#ifdef CONFIG_BINFMT_EXEPATH
EXEPATH_HANDLE exepath_init(void);
#include &lt:nuttx/envpath.h&gt;
#ifdef CONFIG_LIB_ENVPATH
ENVPATH_HANDLE envpath_init(void);
#endif
</pre></ul>
<p><b>Description:</b></p>
@ -361,31 +361,31 @@ EXEPATH_HANDLE exepath_init(void);
</p>
<ol>
<li>
Call <code>exepath_init()</code> to initialize for the traversal.
<code>exepath_init()</code> will return an opaque handle that can then be provided to <code>exepath_next()</code> and <code>exepath_release()</code>.
Call <code>envpath_init()</code> to initialize for the traversal.
<code>envpath_init()</code> will return an opaque handle that can then be provided to <code>envpath_next()</code> and <code>envpath_release()</code>.
</li>
<li>
Call <code>exepath_next()</code> repeatedly to examine every file that lies in the directories of the <code>PATH</code> variable.
Call <code>envpath_next()</code> repeatedly to examine every file that lies in the directories of the <code>PATH</code> variable.
</li>
<li>
Call <code>exepath_release()</code> to free resources set aside by <code>exepath_init()</code>.
Call <code>envpath_release()</code> to free resources set aside by <code>envpath_init()</code>.
</li>
</ol>
</ul>
<p><b>Input Parameters:</b> <i>None</i></p>
<p><b>Returned Value:</b></p>
<ul>
On success, <code>exepath_init()</code> return a non-<code>NULL</code>, opaque handle that may subsequently be used in calls to <code>exepath_next()</code> and <code>exepath_release()</code>.
On success, <code>envpath_init()</code> return a non-<code>NULL</code>, opaque handle that may subsequently be used in calls to <code>envpath_next()</code> and <code>envpath_release()</code>.
On error, a <code>NULL</code> handle value will be returned.
The most likely cause of an error would be that there is no value associated with the <code>PATH</code> variable.
</ul>
<h3>2.3.9 <a name="exepath_next"><code>exepath_next()</code></a></h3>
<h3>2.3.9 <a name="envpath_next"><code>envpath_next()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt:nuttx/binfmt/binfmt.h&gt;
#ifdef CONFIG_BINFMT_EXEPATH
FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
#include &lt:nuttx/envpath.h&gt;
#ifdef CONFIG_LIB_ENVPATH
FAR char *envpath_next(ENVPATH_HANDLE handle, FAR const char *relpath);
#endif
</pre></ul>
<p><b>Description:</b></p>
@ -394,7 +394,7 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
</ul>
<p><b>Input Parameters:</b></p>
<ul>
<li><code>handle</code>: The handle value returned by <code>exepath_init()</code>.</li>
<li><code>handle</code>: The handle value returned by <code>envpath_init()</code>.</li>
<li><code>relpath</code>: The relative path to the file to be found.</li>
</ul>
<p><b>Returned Value:</b></p>
@ -410,27 +410,27 @@ FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
</p>
<p>
<code>NULL</code is returned if no path is found to any file with the provided <code>relpath</colde> from any absolute path in the <code>PATH</code> variable.
In this case, there is no point in calling <code>exepath_next()</code> further; <code>exepath_release()</code> must be called to release resources set aside by <code>expath_init()</code>.
In this case, there is no point in calling <code>envpath_next()</code> further; <code>envpath_release()</code> must be called to release resources set aside by <code>expath_init()</code>.
</p>
</ul>
<h3>2.3.10- <a name="exepath_release"><code>exepath_release()</code></a></h3>
<h3>2.3.10- <a name="envpath_release"><code>envpath_release()</code></a></h3>
<p><b>Function Prototype:</b></p>
<ul><pre>
#include &lt:nuttx/binfmt/binfmt.h&gt;
#ifdef CONFIG_BINFMT_EXEPATH
void exepath_release(EXEPATH_HANDLE handle);
#include &lt:nuttx/envpath.h&gt;
#ifdef CONFIG_LIB_ENVPATH
void envpath_release(ENVPATH_HANDLE handle);
#endif
</pre></ul>
<p><b>Description:</b></p>
<ul>
Release all resources set aside by <code>exepath_init</code> when the handle value was created.
Release all resources set aside by <code>envpath_init</code> when the handle value was created.
The handle value is invalid on return from this function.
Attempts to all <code>exepath_next()</code> or <code>exepath_release()</code> with such a <i>stale</i> handle will result in undefined (i.e., not good) behavior.
Attempts to all <code>envpath_next()</code> or <code>envpath_release()</code> with such a <i>stale</i> handle will result in undefined (i.e., not good) behavior.
</ul>
<p><b>Input Parameters:</b></p>
<ul>
<li><code>handle</code>: The handle value returned by <code>exepath_init()</code>.</li>
<li><code>handle</code>: The handle value returned by <code>envpath_init()</code>.</li>
</ul>
<p><b>Returned Value:</b> <i>None</i></p>

View File

@ -875,7 +875,7 @@ int exec(FAR const char *filename, FAR char * const *argv,
<li>
<code>filename</code>:
The path to the program to be executed.
If <code>CONFIG_BINFMT_EXEPATH</code> is defined in the configuration, then this may be a relative path from the current working directory.
If <code>CONFIG_LIB_ENVPATH</code> is defined in the configuration, then this may be a relative path from the current working directory.
Otherwise, <code>path</code> must be the absolute path to the program.
</li>
<li>
@ -969,7 +969,7 @@ int execv(FAR const char *path, FAR char *const argv[]);
<li>
<code>path</code>:
The path to the program to be executed.
If <code>CONFIG_BINFMT_EXEPATH</code> is defined in the configuration, then this may be a relative path from the current working directory.
If <code>CONFIG_LIB_ENVPATH</code> is defined in the configuration, then this may be a relative path from the current working directory.
Otherwise, <code>path</code> must be the absolute path to the program.
<li>
</li>
@ -1013,7 +1013,7 @@ int execl(FAR const char *path, ...);
<li>
<code>path</code>:
The path to the program to be executed.
If <code>CONFIG_BINFMT_EXEPATH</code> is defined in the configuration, then this may be a relative path from the current working directory.
If <code>CONFIG_LIB_ENVPATH</code> is defined in the configuration, then this may be a relative path from the current working directory.
Otherwise, <code>path</code> must be the absolute path to the program.
<li>
</li>
@ -1074,7 +1074,7 @@ int posix_spawnp(FAR pid_t *pid, FAR const char *file,
</p>
<p>
NOTE: NuttX provides only one implementation:
If <code>CONFIG_BINFMT_EXEPATH</code> is defined, then only <code>posix_spawnp()</code> behavior is supported; otherwise, only <code>posix_spawn</code> behavior is supported.
If <code>CONFIG_LIB_ENVPATH</code> is defined, then only <code>posix_spawnp()</code> behavior is supported; otherwise, only <code>posix_spawn</code> behavior is supported.
</li>
<li>
<p>
@ -1156,8 +1156,8 @@ int posix_spawnp(FAR pid_t *pid, FAR const char *file,
</p>
<ul>
<li>
NuttX provides only <code>posix_spawn()</code> or <code>posix_spawnp()</code> behavior depending upon the setting of <code>CONFIG_BINFMT_EXEPATH</code>:
If <code>CONFIG_BINFMT_EXEPATH</code> is defined, then only <code>posix_spawnp()</code> behavior is supported; otherwise, only <code>posix_spawn()</code> behavior is supported.
NuttX provides only <code>posix_spawn()</code> or <code>posix_spawnp()</code> behavior depending upon the setting of <code>CONFIG_LIB_ENVPATH</code>:
If <code>CONFIG_LIB_ENVPATH</code> is defined, then only <code>posix_spawnp()</code> behavior is supported; otherwise, only <code>posix_spawn()</code> behavior is supported.
</li>
<li>
The <code>envp</code> argument is not used and the <code>environ</code> variable is not altered (NuttX does not support the <code>environ</code> variable).

View File

@ -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"

View File

@ -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

View File

@ -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.

View File

@ -43,6 +43,7 @@
#include <debug.h>
#include <errno.h>
#include <nuttx/envpath.h>
#include <nuttx/sched.h>
#include <nuttx/kmalloc.h>
#include <nuttx/binfmt/binfmt.h>
@ -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

View File

@ -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:

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
}

159
include/nuttx/envpath.h Normal file
View File

@ -0,0 +1,159 @@
/****************************************************************************
* include/nuttx/envpath.h
*
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* 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 <nuttx/config.h>
#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 */

View File

@ -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

View File

@ -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,

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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 <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -47,120 +47,124 @@
#include <string.h>
#include <assert.h>
#include <nuttx/kmalloc.h>
#include <nuttx/binfmt/binfmt.h>
#include <nuttx/envpath.h>
#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 */

View File

@ -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

View File

@ -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
}

View File

@ -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 <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
@ -45,12 +45,39 @@
#include <nuttx/module.h>
#include <nuttx/lib/modlib.h>
/****************************************************************************
* 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();

View File

@ -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.

View File

@ -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.

View File

@ -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,

View File

@ -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

View File

@ -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*"

Can't render this file because it has a wrong number of fields in line 2.

View File

@ -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)

View File

@ -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 */