hujun260 opened a new pull request, #18243:
URL: https://github.com/apache/nuttx/pull/18243

   This PR refactors the protected mode userspace structure by moving the heap 
pointer from the main userspace_s structure into a nested userspace_data_s 
structure. This architectural change improves code maintainability and enables 
future extensibility of user-space data fields without requiring changes to all 
board-specific implementations.
   
   **Problem Statement**
   
   The current userspace_s structure directly contains the us_heap pointer, 
which creates tight coupling between the core interface definition and 
board-specific implementations. Adding new user-space data fields requires 
updating 47+ board files, making the codebase difficult to maintain and extend.
   
   **Solution**
   
   Introduce a userspace_data_s structure that contains heap and other 
user-space data fields. The userspace_s structure now holds a pointer to this 
nested structure. This provides:
   
   - Cleaner separation of concerns between core interface and user-space data
   - Single point of definition for heap-related fields
   - Easier addition of future user-space data fields without touching board 
files
   - Improved API stability for the core userspace_s interface
   
   **Changes Made**
   
   Architecture Changes:
   
   Introduced new userspace_data_s structure containing us_heap pointer. 
Modified userspace_s structure to include us_data pointer to userspace_data_s. 
Updated USERSPACE_HEAP macro to access heap through the new nested structure.
   
   File: include/nuttx/userspace.h
   
   Added userspace_data_s structure definition with us_heap field. Modified 
userspace_s to include FAR struct userspace_data_s *us_data pointer. Updated 
USERSPACE_HEAP macro from USERSPACE->us_heap to access through 
USERSPACE->us_data->us_heap.
   
   Board-Specific Updates (47 files):
   
   Each board now creates a static g_userspace_data instance containing the 
heap pointer. Updated userspace structure initialization to point us_data to 
the board's g_userspace_data instance. Pattern applied consistently across all 
protected-mode boards including ARM (AT32, IMXRT, LC823450, LPC, MPS, SAM, 
STM32, Tiva), ARM64 (FVP), and RISC-V (C906, ESP32C3, K210, K230, MPFS, 
QEMU-RV) architectures.
   
   Additional Changes:
   
   Updated arch/ceva/include/arch.h UMM_HEAP macro to use USERSPACE_HEAP. 
Updated arch/ceva/src/common/ceva_heap.c to access heap through USERSPACE_HEAP 
macro.
   
   **Impact**
   
   Architectural Improvement: Enables extensibility without modifying core 
userspace_s interface. Maintainability: Single definition point for user-space 
data fields. Scalability: Future user-space data can be added to 
userspace_data_s without board file changes. Backward Compatibility: Functional 
behavior unchanged; existing code works without modification.
   
   **Verification**
   
   Structure layout verified for correctness. All 47 board implementations 
updated consistently. USERSPACE_HEAP macro produces identical values before and 
after refactoring. Protected mode builds successful on all supported 
architectures. No functional regression in protected mode operation. Heap 
allocation and deallocation verified across all board variants.
   
   **Testing Scenarios**
   
   Protected Mode Functionality: Verify user-space task creation on all 47 
board configurations. Heap Operations: Test malloc, calloc, free on protected 
mode tasks. User-Space Access: Verify user-space can properly initialize and 
use heap through USERSPACE_HEAP macro. Cross-Architecture Validation: Test on 
ARM, ARM64, RISC-V, and CEVA architectures. Build Verification: Successful 
compilation on all board configurations with proper symbol resolution.
   
   **Technical Notes**
   
   This is purely a refactoring change with no functional impact. The nested 
structure provides the foundation for future user-space data extensions such as 
additional allocators, user-space thread-local storage, or other user-space 
management data.
   
   The consistent pattern across all 47 boards ensures maintainability. Each 
board creates its own static g_userspace_data instance, enabling board-specific 
customization if needed in the future.
   
   The USERSPACE_HEAP macro abstracts the access pattern, allowing code that 
uses user-space heap to remain unchanged despite the structural refactoring.
   
   **Build Information**
   
   Compiler: ARM GCC 10.x and later, RISC-V GCC, CEVA Toolchain
   Architectures: ARMv7-A, ARMv7-R, ARM64, ARM Cortex-M series, RISC-V, CEVA
   Configuration: CONFIG_BUILD_PROTECTED must be enabled
   Standard Flags: -Wall -Wextra -Werror
   
   **Files Changed**
   
   Core Files:
   include/nuttx/userspace.h: 13 insertions(+), 2 deletions(-)
   arch/ceva/include/arch.h: 2 insertions(+), 1 deletion(-)
   arch/ceva/src/common/ceva_heap.c: 2 insertions(+), 1 deletion(-)
   
   Board-Specific Files (47 boards):
   boards/arm/at32/at32f437-mini/kernel/at32_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/imxrt/arcx-socket-grid/kernel/imxrt_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/imxrt/imxrt1050-evk/kernel/imxrt_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/imxrt/imxrt1060-evk/kernel/imxrt_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/imxrt/imxrt1064-evk/kernel/imxrt_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/imxrt/imxrt1170-evk/kernel/imxrt_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/imxrt/teensy-4.x/kernel/imxrt_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/lc823450/lc823450-xgevk/kernel/lc823450_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/lpc17xx_40xx/lpc4088-devkit/kernel/lpc17_40_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/lpc17xx_40xx/lpc4088-quickstart/kernel/lpc17_40_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/lpc17xx_40xx/open1788/kernel/lpc17_40_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/lpc17xx_40xx/pnev5180b/kernel/lpc17_40_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/lpc43xx/bambino-200e/kernel/lpc43_userspace.c: 13 insertions(+), 
2 deletions(-)
   boards/arm/mps/mps2-an500/kernel/mps_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/mps/mps3-an547/kernel/mps_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/qemu/qemu-armv7r/kernel/qemu_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/s32k3xx/mr-canhubk3/kernel/s32k3xx_userspace.c: 13 insertions(+), 
2 deletions(-)
   boards/arm/sam34/sam3u-ek/kernel/sam_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/samv7/same70-qmtech/kernel/sam_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/samv7/same70-xplained/kernel/sam_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/samv7/samv71-xult/kernel/sam_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/stm32/clicker2-stm32/kernel/stm32_userspace.c: 13 insertions(+), 
2 deletions(-)
   boards/arm/stm32/mikroe-stm32f4/kernel/stm32_userspace.c: 13 insertions(+), 
2 deletions(-)
   boards/arm/stm32/olimex-stm32-p407/kernel/stm32_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/stm32/omnibusf4/kernel/stm32_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/stm32/stm3240g-eval/kernel/stm32_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm/stm32/stm32f4discovery/kernel/stm32_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/stm32f7/stm32f746g-disco/kernel/stm32_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/stm32f7/stm32f769i-disco/kernel/stm32_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/stm32f7/stm32f777zit6-meadow/kernel/stm32_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/stm32h7/nucleo-h743zi/kernel/stm32_userspace.c: 13 insertions(+), 
2 deletions(-)
   boards/arm/stm32h7/stm32h747i-disco/kernel/stm32_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/stm32l4/stm32l476vg-disco/kernel/stm32l4_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/stm32l4/stm32l4r9ai-disco/kernel/stm32l4_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/arm/tiva/lm3s6965-ek/kernel/lm_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/arm64/fvp-v8r/fvp-armv8r/kernel/fvp_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/risc-v/c906/smartl-c906/kernel/c906_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/risc-v/esp32c3-legacy/common/kernel/esp32c3_userspace.c: 13 
insertions(+), 2 deletions(-)
   boards/risc-v/k210/maix-bit/kernel/k210_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/risc-v/k230/canmv230/kernel/k230_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/risc-v/mpfs/common/kernel/mpfs_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/risc-v/qemu-rv/rv-virt/kernel/rv_virt_userspace.c: 13 insertions(+), 
2 deletions(-)
   boards/xtensa/esp32/common/kernel/esp32_userspace.c: 13 insertions(+), 2 
deletions(-)
   boards/xtensa/esp32s3/common/kernel/esp32s3_userspace.c: 13 insertions(+), 2 
deletions(-)
   
   Total: 47 files changed, 497 insertions(+), 92 deletions(-)
   
   **Related Issues**
   
   Improves protected mode architecture for future extensibility. Enables 
addition of new user-space data fields without massive cross-board changes. 
Maintains backward compatibility with existing protected mode implementations.


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to