mirror of
https://github.com/apache/nuttx.git
synced 2026-10-03 20:27:53 +00:00
modlib:add new api to uninitialize modp
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
parent
91c7e8e44b
commit
e9550783d3
2 changed files with 68 additions and 37 deletions
|
|
@ -691,6 +691,16 @@ FAR void *modlib_insert(FAR const char *filename, FAR const char *modname);
|
||||||
|
|
||||||
FAR const void *modlib_getsymbol(FAR void *handle, FAR const char *name);
|
FAR const void *modlib_getsymbol(FAR void *handle, FAR const char *name);
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: modlib_uninit
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Uninitialize module resources.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int modlib_uninit(FAR struct module_s *modp);
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: modlib_remove
|
* Name: modlib_remove
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -36,50 +36,26 @@
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: modlib_remove
|
* Name: modlib_uninit
|
||||||
*
|
*
|
||||||
* Description:
|
* Description:
|
||||||
* Remove a previously installed module from memory.
|
* Uninitialize module resources.
|
||||||
*
|
|
||||||
* Input Parameters:
|
|
||||||
* handle - The module handler previously returned by modlib_insert().
|
|
||||||
*
|
|
||||||
* Returned Value:
|
|
||||||
* Zero (OK) on success. On any failure, -1 (ERROR) is returned the
|
|
||||||
* errno value is set appropriately.
|
|
||||||
*
|
*
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
int modlib_remove(FAR void *handle)
|
int modlib_uninit(FAR struct module_s *modp)
|
||||||
{
|
{
|
||||||
FAR struct module_s *modp = (FAR struct module_s *)handle;
|
|
||||||
FAR void (**array)(void);
|
FAR void (**array)(void);
|
||||||
int ret;
|
int ret = OK;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
DEBUGASSERT(modp != NULL);
|
|
||||||
|
|
||||||
/* Get exclusive access to the module registry */
|
|
||||||
|
|
||||||
modlib_registry_lock();
|
|
||||||
|
|
||||||
/* Verify that the module is in the registry */
|
|
||||||
|
|
||||||
ret = modlib_registry_verify(modp);
|
|
||||||
if (ret < 0)
|
|
||||||
{
|
|
||||||
berr("ERROR: Failed to verify module: %d\n", ret);
|
|
||||||
goto errout_with_lock;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if CONFIG_MODLIB_MAXDEPEND > 0
|
#if CONFIG_MODLIB_MAXDEPEND > 0
|
||||||
/* Refuse to remove any module that other modules may depend upon. */
|
/* Refuse to remove any module that other modules may depend upon. */
|
||||||
|
|
||||||
if (modp->dependents > 0)
|
if (modp->dependents > 0)
|
||||||
{
|
{
|
||||||
berr("ERROR: Module has dependents: %d\n", modp->dependents);
|
berr("ERROR: Module has dependents: %d\n", modp->dependents);
|
||||||
ret = -EBUSY;
|
return -EBUSY;
|
||||||
goto errout_with_lock;
|
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -102,7 +78,7 @@ int modlib_remove(FAR void *handle)
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
berr("ERROR: Failed to uninitialize the module: %d\n", ret);
|
berr("ERROR: Failed to uninitialize the module: %d\n", ret);
|
||||||
goto errout_with_lock;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
modlib_freesymtab(modp);
|
modlib_freesymtab(modp);
|
||||||
|
|
@ -183,6 +159,57 @@ int modlib_remove(FAR void *handle)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if CONFIG_MODLIB_MAXDEPEND > 0
|
||||||
|
/* Eliminate any dependencies that this module has on other modules */
|
||||||
|
|
||||||
|
modlib_undepend(modp);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name: modlib_remove
|
||||||
|
*
|
||||||
|
* Description:
|
||||||
|
* Remove a previously installed module from memory.
|
||||||
|
*
|
||||||
|
* Input Parameters:
|
||||||
|
* handle - The module handler previously returned by modlib_insert().
|
||||||
|
*
|
||||||
|
* Returned Value:
|
||||||
|
* Zero (OK) on success. On any failure, -1 (ERROR) is returned the
|
||||||
|
* errno value is set appropriately.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int modlib_remove(FAR void *handle)
|
||||||
|
{
|
||||||
|
FAR struct module_s *modp = (FAR struct module_s *)handle;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
DEBUGASSERT(modp != NULL);
|
||||||
|
|
||||||
|
/* Get exclusive access to the module registry */
|
||||||
|
|
||||||
|
modlib_registry_lock();
|
||||||
|
|
||||||
|
/* Verify that the module is in the registry */
|
||||||
|
|
||||||
|
ret = modlib_registry_verify(modp);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
berr("ERROR: Failed to verify module: %d\n", ret);
|
||||||
|
goto errout_with_lock;
|
||||||
|
}
|
||||||
|
|
||||||
|
ret = modlib_uninit(modp);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
berr("ERROR: Failed to uninitialize module %d\n", ret);
|
||||||
|
goto errout_with_lock;
|
||||||
|
}
|
||||||
|
|
||||||
/* Remove the module from the registry */
|
/* Remove the module from the registry */
|
||||||
|
|
||||||
ret = modlib_registry_del(modp);
|
ret = modlib_registry_del(modp);
|
||||||
|
|
@ -193,17 +220,11 @@ int modlib_remove(FAR void *handle)
|
||||||
goto errout_with_lock;
|
goto errout_with_lock;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG_MODLIB_MAXDEPEND > 0
|
|
||||||
/* Eliminate any dependencies that this module has on other modules */
|
|
||||||
|
|
||||||
modlib_undepend(modp);
|
|
||||||
#endif
|
|
||||||
modlib_registry_unlock();
|
modlib_registry_unlock();
|
||||||
|
|
||||||
/* And free the registry entry */
|
/* And free the registry entry */
|
||||||
|
|
||||||
lib_free(modp);
|
return ret;
|
||||||
return OK;
|
|
||||||
|
|
||||||
errout_with_lock:
|
errout_with_lock:
|
||||||
modlib_registry_unlock();
|
modlib_registry_unlock();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue