JianyuWang0623 opened a new pull request, #3821:
URL: https://github.com/apache/nuttx-apps/pull/3821

   ## Summary
   
   Under `CONFIG_BUILD_PROTECTED`, `nxinit`'s `init_main()` runs in user space 
while the binfmt builtin loader and BINFS run in kernel space. The builtin 
application table (`g_builtins`/`g_builtin_count`) is linked only into the user 
blob (`nuttx_user`) and is never present in the kernel image. As a result, any 
kernel-space lookup against that table — such as the `posix_spawnp()` call that 
starts the `console sh` service from `init.rc` — fails with `ENOENT`, because 
the kernel-side `g_builtins[]` was never populated.
   
   NuttX already ships the fix for this gap: `include/nuttx/lib/builtin.h` 
documents that `boardctl(BOARDIOC_BUILTINS)` must be called by the application 
layer to register the table with the kernel. This change wires that call up in 
`init_main()`, before any service is started. The block is guarded by `#if 
defined(CONFIG_BUILD_PROTECTED) && defined(CONFIG_BUILTIN)` and compiled out 
entirely for FLAT and KERNEL builds, which are unaffected (in FLAT, there is no 
separate address space; in KERNEL, user-space addresses cannot meaningfully be 
passed across the boundary in this way).
   
   `nsh` is not affected by this problem: `exec_builtin()` has a `task_spawn()` 
fallback path that does not require a populated kernel-side table.
   
   ## Impact
   
   Only affects `CONFIG_BUILD_PROTECTED && CONFIG_BUILTIN` builds. FLAT and 
KERNEL builds are not changed. The apache/nuttx `rv-virt:pnsh` configuration 
(already switched to nxinit on master) currently fails to start its console 
service with `Error Starting service 'console': 2`; this PR fixes that. A 
pending nuttx PR that switches `qemu-armv7r` to nxinit also depends on this 
change.
   
   ## Testing
   
   **Host**: Linux x86_64, `arm-none-eabi-gcc 10.3.1`
   
   **Target**: `qemu-armv7r:pnsh` (PROTECTED build)
   
   **QEMU**: 10.2.1, `-M virt -cpu cortex-r5f`
   
   **Before this change**: boot log prints `Error Starting service 'console': 
2` and the console service never starts.
   
   **After this change**, three consecutive runs:
   
   ```
   nsh> ps
     TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK        
    STACK    USED FILLED COMMAND
       0     0     0   0 FIFO     Kthread   - Ready    ...                      
                          Idle_Task
       1     0     0 192 RR       Kthread   - Waiting  Semaphore ...            
                          hpwork
       3     3     0 100 RR       Task      - Waiting  Semaphore ...            
                          init_main
       4     4     3 100 RR       Task      - Running  ...                      
                          sh
   ```
   
   `init_main` (PID 3, PPID 0) and `sh` (PID 4, PPID 3) confirm the expected 
parent-child relationship.
   
   `qemu-armv7r:nsh` (flat build): compiles cleanly with this change; the `#if` 
guard excludes the new code entirely.
   
   `rv-virt:pnsh`: not built or run on this branch; it is known to exhibit the 
same failure on apache/nuttx master without this fix.
   


-- 
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