casaroli opened a new pull request, #20982: URL: https://github.com/apache/nuttx/pull/20982
## Summary Two problems in the system call path of xtensa protected builds: - `xtensa_dispatch_syscall()` stored the fifth parameter at `SP` and called the stub with that `SP`. Without `CONFIG_ARCH_KERNEL_STACK` the dispatch runs on the stack of the caller, so each system call overwrote the word at `SP` of the function that made the call. Also, the register frame of the system call is just below `SP`, and `fork()` reads it (`xcp.sregs`) while the stub runs, so the stub frames overwrote part of it. The dispatch now moves `SP` below the register frame and the parameter word first, and back before the return. - The `sys_call` functions in `arch/xtensa/include/syscall.h` gave the parameter registers to the compiler as inputs only and clobbered no register. The kernel returns with `A2` and `A3` set to the return value, `A4`-`A11` changed by the dispatch, and `A12`-`A15` maybe changed by the stub. The compiler kept values in these registers across `SYSCALL`. The parameter registers are now in and out operands, and `A3`-`A15` are clobbered. On `esp32s3-devkit:knsh`, `sched_getparam(pid, NULL)` followed by `sched_getscheduler(pid)` gave `-1` as the pid to the second call. ## Impact xtensa protected builds (`CONFIG_LIB_SYSCALL`). Flat builds do not use these macros or the dispatch. The ABI of the system calls does not change. ## Testing Test program `sysclobber.c`: each case makes two system calls in one function with the `sys_call` macros and passes the same pid to both. Case 2 makes the first call fail. Hardware, protected build, `knsh` with `INIT_ENTRYPOINT=nsh_main`: | Board | master | this PR | |---|---|---| | ESP32-S3-DevKitC (`esp32s3-devkit:knsh`) | `sysclobber` case 2 FAIL (getscheduler -1) | PASS | | ESP32-DevKitC (`esp32-devkitc:knsh`) | `sysclobber` case 2 FAIL | PASS | | `ostest` (both boards, `vfork()` included) | status 0 | status 0 | With only the `syscall.h` change, case 2 still failed on the ESP32-S3: the dispatch overwrote the word that held the pid. `tools/checkpatch.sh -c -u -m -g` passes. -- 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]
