pussuw opened a new pull request, #7966: URL: https://github.com/apache/nuttx/pull/7966
## Summary Highlights are in commit messages, but as a summary this fixes several issues with group and address environment handling when a process exits or is being killed: - Group becomes NULL, when nxtask_exithook is called the first time. This is not done in a critical section and a context change or IRQ can happen afterwards -> the address environment selector does not know what to do any more when restoring the (new?) context - Address environment is released before the system is done using it. The kernel mappings exist inside each process's address environment, and if these are destroyed, the kernel is left without mappings. This might not cause an immediate crash as the physical memory might not be re-used, but _if it is, the system crashes at once because of a corrupt page directory_ This commit fixes both issues by: - Adding a safe copy reference to the group into TCB, which is used to determine the group structure whose mappings are in use. - Adding a reference counter to protect the mappings from removal, if someone is using them Kernel processes continue to "lend" the address environment from the user processes, but this time they inform the user process (group) that the address environment is in use (via the ref. counter) which ensures that the address environment (nor the group) are NOT freed when the kernel still needs them. Also added a work queue to do the heavy lifting when an address environment is destroyed, otherwise this work would be done during a context switch which is IMO a very bad idea. ## Impact Significant, but only affects builds with CONFIG_ARCH_ADDRENV=y (i.e. kernel build) ## Testing icicle:knsh -- 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-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org