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

   ## Summary
   
   Fix TriCore vfork by restoring the lower context only after no saved-context 
temporaries remain live.
   
   ## Impact
   
   Fixes vfork on TriCore without changing the CSA and stack copying logic or 
affecting other architectures.
   
   ## Problem
   
   `up_fork()` used `rslcx` with only a `memory` clobber, although the 
instruction restores the complete TriCore lower context (D0-D7 and A2-A7).
   
   With `tricore_fork()` inlined into `up_fork()`, GCC kept the CSA address 
mask `0x003fffc0` in D3 before `rslcx` and reused D3 afterwards while walking 
the parent CSA chain. Since `rslcx` had restored D3 to its earlier value, 
`tricore_csa2addr()` calculated an invalid CSA address. The resulting 
parent-chain traversal and child-context corruption caused vfork to fail with a 
TriCore class 3, TIN 5 call stack underflow.
   
   ## Solution
   
   Defer `rslcx` until after `tricore_fork()` returns. No lower-context 
temporaries or call arguments remain live across the restore at that point.
   
   Store the return value in a volatile local so GCC writes it to memory before 
`rslcx` and reloads D2 afterwards. The CSA counting, copying, relinking and 
stack-relocation logic is unchanged; only the lifetime of the parent's entry 
lower CSA changes. This does not require an assembly helper, a register clobber 
list or an additional upper-context call frame.
   
   ## Testing
   
   Build: GCC/CMake build for `a2g-tc397-5v-tft:nsh`: passed.
   
   Test: Infineon AURIX TC397 V2.0, noncached HEX image: full `ostest` passed.
   
   - `tools/checkpatch.sh -f arch/tricore/src/common/tricore_fork.c`: passed.
   - A unique hello-world marker confirmed that the board ran this image.
   - The test completed with:
   
   ```text
   vfork_test: Child 7 ran and exited before the parent resumed
   ostest_main: Exiting with status 0
   ```
   
   No assertion, panic or TriCore trap occurred in the completed run.


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