Add logic to automatically unload module on exit; Several patches from Mike Smith

git-svn-id: http://svn.code.sf.net/p/nuttx/code/trunk@5528 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
patacongo
2013-01-17 14:43:55 +00:00
parent caeef71797
commit e9d0885500
15 changed files with 214 additions and 96 deletions
+44 -3
View File
@@ -82,6 +82,18 @@ typedef FAR void (*binfmt_dtor_t)(void);
struct symtab_s;
struct binary_s
{
/* If CONFIG_SCHED_HAVE_PARENT is defined then schedul_unload() will
* manage instances of struct binary_s allocated with kmalloc. It
* will keep the binary data in a link list and when SIGCHLD is received
* (meaning that the task has exit'ed, schedul_unload() will find the
* data, unload the module, and free the structure.
*/
#ifdef CONFIG_SCHED_HAVE_PARENT
FAR struct binary_s *flink; /* Supports a singly linked list */
pid_t pid; /* Task ID of the child task */
#endif
/* Information provided to the loader to load and bind a module */
FAR const char *filename; /* Full path to the binary to be loaded (See NOTE 1 above) */
@@ -222,19 +234,48 @@ int unload_module(FAR const struct binary_s *bin);
*
* Returned Value:
* This is an end-user function, so it follows the normal convention:
* Returns the PID of the exec'ed module. On failure, it.returns
* Returns the PID of the exec'ed module. On failure, it returns
* -1 (ERROR) and sets errno appropriately.
*
****************************************************************************/
int exec_module(FAR const struct binary_s *bin);
/****************************************************************************
* Name: schedule_unload
*
* Description:
* If CONFIG_SCHED_HAVE_PARENT is defined, this function may be called by
* the parent of the the newly created task to automatically unload the
* module when the task exits. This assumes that (1) the caller is the
* parent of the created task, (2) that bin was allocated with kmalloc()
* or friends. It will also automatically free the structure with kfree()
* after unloading the module.
*
* Input Parameter:
* pid - The task ID of the child task
* bin - This structure must have been allocated with kmalloc() and must
* persist until the task unloads
*
* Returned Value:
* This is an end-user function, so it follows the normal convention:
* It returns 0 (OK) if the callback was successfully scheduled. On
* failure, it returns -1 (ERROR) and sets errno appropriately.
*
****************************************************************************/
#ifdef CONFIG_SCHED_HAVE_PARENT
int schedule_unload(pid_t pid, FAR const struct binary_s *bin);
#endif
/****************************************************************************
* Name: exec
*
* Description:
* This is a convenience function that wraps load_ and exec_module into
* one call.
* one call. If CONFIG_SCHED_ONEXIT is also defined, this function will
* automatically call schedule_unload() to unload the module when task
* exits.
*
* Input Parameter:
* filename - Fulll path to the binary to be loaded
@@ -244,7 +285,7 @@ int exec_module(FAR const struct binary_s *bin);
*
* Returned Value:
* This is an end-user function, so it follows the normal convention:
* Returns the PID of the exec'ed module. On failure, it.returns
* It returns the PID of the exec'ed module. On failure, it returns
* -1 (ERROR) and sets errno appropriately.
*
****************************************************************************/
+9 -17
View File
@@ -73,14 +73,6 @@ extern "C" {
#define EXTERN extern
#endif
/* The g_builtins[] array holds information about each builtin function. If
* support for builtin functions is enabled in the NuttX configuration, then
* this arrary (along with the number_builtins() function) must be provided
* by the application code.
*/
EXTERN const struct builtin_s g_builtins[];
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -128,24 +120,24 @@ FAR const char *builtin_getname(int index);
* Data Set Access Functions Provided to Applications by binfmt/libbuiltin
****************************************************************************/
/****************************************************************************
* Name: number_builtins
* Name: builtin_for_index
*
* Description:
* Returns the number of builtin functions in the g_builtins[] array. If
* support for builtin functions is enabled in the NuttX configuration,
* then this function (along with g_builtins[]) must be provided by the
* application code.
* Returns the builtin_s structure for the selected builtin.
* If support for builtin functions is enabled in the NuttX configuration,
* then this function must be provided by the application code.
*
* Input Parameter:
* None
* index, from 0 and on...
*
* Returned Value:
* The number of entries in the g_builtins[] array. This function does
* not return failures.
* Returns valid pointer pointing to the builtin_s structure if index is
* valid.
* Otherwise, NULL is returned.
*
****************************************************************************/
int number_builtins(void);
EXTERN FAR const struct builtin_s *builtin_for_index(int index);
#undef EXTERN
#if defined(__cplusplus)