diff options
author | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-17 14:43:55 +0000 |
---|---|---|
committer | patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3> | 2013-01-17 14:43:55 +0000 |
commit | e9d0885500d437cc6c89370d8131913bd1e7310b (patch) | |
tree | d9cf39f88361f174a2350d354ffb5584d43e2fc4 /nuttx/include | |
parent | caeef71797019505fd450b1a0ae573ac5e490c6e (diff) | |
download | px4-firmware-e9d0885500d437cc6c89370d8131913bd1e7310b.tar.gz px4-firmware-e9d0885500d437cc6c89370d8131913bd1e7310b.tar.bz2 px4-firmware-e9d0885500d437cc6c89370d8131913bd1e7310b.zip |
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
Diffstat (limited to 'nuttx/include')
-rw-r--r-- | nuttx/include/nuttx/binfmt/binfmt.h | 47 | ||||
-rw-r--r-- | nuttx/include/nuttx/binfmt/builtin.h | 26 |
2 files changed, 53 insertions, 20 deletions
diff --git a/nuttx/include/nuttx/binfmt/binfmt.h b/nuttx/include/nuttx/binfmt/binfmt.h index c6c7c874a..472ba0fc4 100644 --- a/nuttx/include/nuttx/binfmt/binfmt.h +++ b/nuttx/include/nuttx/binfmt/binfmt.h @@ -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,7 +234,7 @@ 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. * ****************************************************************************/ @@ -230,11 +242,40 @@ int unload_module(FAR const struct binary_s *bin); 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. * ****************************************************************************/ diff --git a/nuttx/include/nuttx/binfmt/builtin.h b/nuttx/include/nuttx/binfmt/builtin.h index 632f8944d..5921cc518 100644 --- a/nuttx/include/nuttx/binfmt/builtin.h +++ b/nuttx/include/nuttx/binfmt/builtin.h @@ -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) |