Skip to content

Conversation

@hujun260
Copy link
Contributor

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

@github-actions github-actions bot added Area: OS Components OS Components issues Area: BINFMT Size: S The size of the change in this PR is small labels Jan 16, 2026

#ifdef CONFIG_BINFMT_LOADABLE
struct binary_s; /* Forward reference */
int group_exitinfo(pid_t pid, FAR struct binary_s *bininfo);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where we remove group_exitinfo code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Remove deprecated group_exitinfo() function and related critical section locking
from binfmt_exec.c, moving module unload setup directly into exec_module() where
it integrates naturally with task activation, simplifying code flow and reducing
unnecessary synchronization overhead.

Signed-off-by: hujun5 <[email protected]>
@hujun260 hujun260 force-pushed the apache_remove_group_exitinfo branch from 5d4c2be to f7df317 Compare January 16, 2026 07:40
@hujun260 hujun260 requested a review from jerpelea as a code owner January 16, 2026 07:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: BINFMT Area: OS Components OS Components issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants