You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "hujun260 (via GitHub)" <gi...@apache.org> on 2026/01/16 05:40:11 UTC
[PR] binfmt: refactor loadable module cleanup mechanism [nuttx]
hujun260 opened a new pull request, #17954:
URL: https://github.com/apache/nuttx/pull/17954
## Summary
This PR refactors the loadable binary module cleanup mechanism to remove the
deprecated `group_exitinfo()` function and simplify the module unload process.
The changes eliminate unnecessary critical section locking in the exec path and
integrate module unload setup directly into the task initialization sequence.
## Changes
The refactoring involves several related changes across the binary format and
group management subsystems:
1. **binfmt/binfmt_exec.c** - Simplify exec_internal():
- Remove `irqstate_t flags` variable and related critical section management
- Remove `enter_critical_section()` and `sched_lock()` calls
- Remove deprecated `group_exitinfo()` call and associated error handling
- Simplify error handling paths by eliminating unnecessary cleanup code
- Result: Cleaner, more straightforward module execution flow
2. **binfmt/binfmt_execmodule.c** - Move unload setup to exec_module():
- Add direct assignment: `tcb->group->tg_bininfo = binp` under CONFIG_BINFMT_LOADABLE
- Integrates naturally with task activation
- Eliminates need for separate group_exitinfo() function call
- Module information is now directly accessible when task exits
3. **include/nuttx/sched.h** - Remove deprecated interface:
- Remove `group_exitinfo()` function declaration
- Remove associated documentation and comments
4. **sched/group/CMakeLists.txt** and **Make.defs**:
- Remove `group_exitinfo.c` source file from build
- Clean up build configuration
## Benefits
- **Code Simplification**: Eliminates unnecessary critical section overhead
- **Performance**: Removes redundant locking/unlocking operations
- **Maintainability**: Consolidates module initialization logic into single place
- **Architecture**: Direct assignment pattern is clearer than indirect registration
- **Robustness**: Reduces complexity reduces potential race conditions
## Testing
Tested on:
- **Platform**: NuttX with loadable module support (CONFIG_BINFMT_LOADABLE=y)
- **Configuration**: ELF and other binary format drivers
- **Test scenarios**:
- Load and execute tasks with loadable modules
- Verify module cleanup occurs at task exit
- Test error paths during module loading/execution
- Concurrent task creation with different module types
- Memory allocation/deallocation for module structures
- **Result**:
- All loadable modules work correctly with simplified mechanism
- No memory leaks during module cleanup
- Performance improved due to reduced critical section overhead
- No functional regressions observed
## Impact
- **Stability**: Maintains module loading/unloading functionality
- **Performance**: Improves performance by eliminating critical section overhead
- **Compatibility**: No breaking changes to public APIs
- **Code Quality**: Improves code organization and maintainability
- **Architecture**: Aligns module setup with natural task initialization flow
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] binfmt: refactor loadable module cleanup mechanism [nuttx]
Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #17954:
URL: https://github.com/apache/nuttx/pull/17954#discussion_r2697297665
##########
include/nuttx/sched.h:
##########
@@ -1168,31 +1168,6 @@ void nxtask_abort_fork(FAR struct tcb_s *child, int errcode);
size_t nxtask_argvstr(FAR struct tcb_s *tcb, FAR char *args, size_t size);
-/****************************************************************************
- * Name: group_exitinfo
- *
- * Description:
- * This function may be called to when a task is loaded into memory. It
- * will setup the to automatically unload the module when the task exits.
- *
- * Input Parameters:
- * pid - The task ID of the newly loaded task
- * bininfo - This structure allocated with kmm_malloc(). This memory
- * persists until the task exits and will be used unloads
- * the module from memory.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_BINFMT_LOADABLE
-struct binary_s; /* Forward reference */
-int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo);
Review Comment:
where we remove group_exitinfo code
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] binfmt: refactor loadable module cleanup mechanism [nuttx]
Posted by "hujun260 (via GitHub)" <gi...@apache.org>.
hujun260 commented on code in PR #17954:
URL: https://github.com/apache/nuttx/pull/17954#discussion_r2697344180
##########
include/nuttx/sched.h:
##########
@@ -1168,31 +1168,6 @@ void nxtask_abort_fork(FAR struct tcb_s *child, int errcode);
size_t nxtask_argvstr(FAR struct tcb_s *tcb, FAR char *args, size_t size);
-/****************************************************************************
- * Name: group_exitinfo
- *
- * Description:
- * This function may be called to when a task is loaded into memory. It
- * will setup the to automatically unload the module when the task exits.
- *
- * Input Parameters:
- * pid - The task ID of the newly loaded task
- * bininfo - This structure allocated with kmm_malloc(). This memory
- * persists until the task exits and will be used unloads
- * the module from memory.
- *
- * Returned Value:
- * This is a NuttX internal function so it follows the convention that
- * 0 (OK) is returned on success and a negated errno is returned on
- * failure.
- *
- ****************************************************************************/
-
-#ifdef CONFIG_BINFMT_LOADABLE
-struct binary_s; /* Forward reference */
-int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo);
Review Comment:
done
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] binfmt: refactor loadable module cleanup mechanism [nuttx]
Posted by "acassis (via GitHub)" <gi...@apache.org>.
acassis merged PR #17954:
URL: https://github.com/apache/nuttx/pull/17954
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org