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

   
   ## Summary
   
     * Allows an application's configured stack size and priority to be carried
       as absolute ELF symbols (`nx_stacksize`, `nx_priority`, and
       `nx_uid`/`nx_gid`/`nx_mode` under `CONFIG_SCHED_USER_IDENTITY`) and read
       back by the binary loader at exec time, instead of always falling back
       to `CONFIG_ELF_STACKSIZE` / `SCHED_PRIORITY_DEFAULT`.
     * Adds `libelf_findsymbol()` (a name-based symbol lookup over the ELF
       symbol table) in `libs/libc/elf/elf_symbols.c` and declares it in
       `include/nuttx/lib/elf.h`; `binfmt/elf.c` uses it to populate
       `struct binary_s` (`binp->stacksize`/`priority`/`uid`/`gid`/`mode`),
       falling back to the existing defaults when a symbol is absent.
     * `cmake/nuttx_add_application.cmake` emits the `--defsym nx_*` flags at
       link time.
     * `posix_spawnattr_init()` no longer pre-fills `attr->stacksize` and
       `attr->priority` (left at 0); `nxtask_spawn_exec()` fills the parent
       priority and `CONFIG_POSIX_SPAWN_DEFAULT_STACKSIZE` when a caller does
       not set them. This stops the spawnattr defaults from overriding the
       values parsed from the ELF, so the embedded symbols actually drive the
       spawned task.
     * Related NuttX Apps PR: <apps PR link>
   
   ## Impact
   
     * Is new feature added? Is existing feature changed? YES — new feature:
       application attributes are parsed from ELF symbols and used by the
       binary loader.
     * Impact on user (will user need to adapt to change)? NO — the symbols
       are optional; when absent the loader keeps using the existing defaults
       (`CONFIG_ELF_STACKSIZE`, `SCHED_PRIORITY_DEFAULT`).
     * Impact on build (will build process change)? YES (minor) — the ELF app
       link now emits `--defsym nx_stacksize`/`nx_priority` (and `nx_uid`/
       `nx_gid`/`nx_mode` under `CONFIG_SCHED_USER_IDENTITY`); handled in the
       companion apps PR via `Application.mk`.
     * Impact on hardware (will arch(s) / board(s) / driver(s) change)? NO.
     * Impact on documentation (is update required / provided)? NO (not yet).
     * Impact on security (any sort of implications)? NO.
     * Impact on compatibility (backward/forward/interoperability)? NO —
       `posix_spawnattr_init()` callers that relied on the old stacksize/
       priority defaults still get them filled in by `nxtask_spawn_exec()` /
       the binary loader, so observable defaults are unchanged; only apps that
       embed the `nx_*` symbols change behavior (they now honor their own
       configured values).
     * Anything else to consider or add? The `heapsize` attribute from the
       original implementation is intentionally not included (it depends on
       the separate task-heap feature).
   
   ## Testing
   
     I confirm that changes are verified on local setup and works as intended:
     * Build Host(s): Ubuntu, arm-none-eabi-gcc 12.2.1
     * Target(s): `qemu-armv7a:knsh` (CONFIG_BUILD_KERNEL, CONFIG_ELF=y)
     * Build: `./tools/configure.sh qemu-armv7a:knsh && make && make export`
       (apps built separately and mounted via hostfs as `/system`).
     * Run command: `qemu-system-arm -semihosting -M virt -m 1024 -nographic 
-kernel ./nuttx`
   
     Testing logs before change (stock upstream/master nuttx; the `getprime`
     app was built with `--defsym nx_stacksize=8192 --defsym nx_priority=50`,
     but the symbol is not consulted, so the task uses the defaults — stack
     4096, priority 100):
   
     ```
     nsh> getprime 4 &
       TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK      
      STACK    USED FILLED COMMAND
         4     4     3 100 RR       Task      - Waiting  Semaphore 
0000000000000000 0004048 0000776  19.1%  getprime 4
     ```
   
     Testing logs after change (this PR; same `getprime` app — the ELF symbols
     now drive the task: stack ≈ 8192, priority 50):
   
     ```
     nsh> getprime 4 &
       TID   PID  PPID PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK      
      STACK    USED FILLED COMMAND
         4     4     3  50 RR       Task      - Waiting  Semaphore 
0000000000000000 0008144 0000792   9.7%  getprime 4
     ```
   
     `hello`, `ostest`, and NSH itself continue to load and run; no regression
     observed on `knsh`.
   
   ## PR verification Self-Check
   
     * [X] This PR introduces only one functional change.
     * [X] I have updated all required description fields above.
     * [X] My PR adheres to Contributing Guidelines and Documentation (git 
commit title and message, coding standard, etc).
     * [ ] My PR is still work in progress (not ready for review).
     * [X] My PR is ready for review and can be safely merged into a codebase.
   


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