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
+27 -27
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>
+6 -6
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).