mirror of
https://github.com/apache/nuttx.git
synced 2026-08-01 20:28:58 +00:00
A SIGEV_THREAD notification -- from mq_notify() or timer_create() -- runs its callback on a shared signal-notification work queue, not in the registering task. That worker carries no FDPIC data base, so a module's callback reaches it with the wrong base and cannot touch its own globals. This is unlike every other callback entry point, where the callback runs in a task that inherited the module's data space and resolving the code address is enough. The base is knowable exactly once, at registration, when the call is still in the module's own context: capture it there with fdpic_base() into the persisted work structure (mq's ntwork, the timer's pt_work). At send or expiry the descriptor is resolved to its code address -- a plain memory read that needs no base -- and stored in work->func. The worker, seeing a non-zero base, installs it in the FDPIC register around the call and restores it after; a zero base, which is every non-module callback, takes the direct path unchanged. fdpic_base() exposes the test fdpic_callback() already makes internally -- whether the caller is a module -- for a site that has to decide before it stores a pointer somewhere the register will no longer be correct. fdpic_invoke() is the install-call-restore, in the same ARM-thumb inline asm as the rest of fdpic.h. It saves the register on the stack and keeps the push 8-byte aligned, and pins the argument in r0, so it asks the allocator for only two free registers -- enough on builds that also reserve a frame pointer. It is safe against preemption: the FDPIC register is REG_PIC in the saved context, preserved across a context switch, and base firmware reserves it so no interrupt handler disturbs it. A context switch or interrupt while the callback runs therefore keeps the module's base. Verified with CONFIG_SIG_EVTHREAD on two ARM cores: an RP2350 (Cortex-M33, armv8-m) on hardware and mps2-an500 (Cortex-M7, armv7e-m) under QEMU. On each a module's mq_notify and timer_create SIGEV_THREAD callbacks run on the worker and write a distinctive value into a module global, proving the base was installed. Removing just the register install makes the same callback HardFault the board, confirming it is load-bearing. Assisted-by: Claude Code:claude-opus-5 Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com> |
||
|---|---|---|
| .. | ||
| android | ||
| arpa | ||
| crypto | ||
| cxx | ||
| net | ||
| netinet | ||
| netpacket | ||
| nuttx | ||
| ssp | ||
| sys | ||
| .gitignore | ||
| aio.h | ||
| alloca.h | ||
| assert.h | ||
| byteswap.h | ||
| ctype.h | ||
| debug.h | ||
| dirent.h | ||
| dlfcn.h | ||
| dsp.h | ||
| dspb16.h | ||
| elf.h | ||
| elf32.h | ||
| elf64.h | ||
| endian.h | ||
| err.h | ||
| errno.h | ||
| execinfo.h | ||
| fcntl.h | ||
| fixedmath.h | ||
| fnmatch.h | ||
| ftw.h | ||
| gcov.h | ||
| getopt.h | ||
| glob.h | ||
| grp.h | ||
| hex2bin.h | ||
| iconv.h | ||
| ifaddrs.h | ||
| imx_container.h | ||
| inttypes.h | ||
| iso646.h | ||
| langinfo.h | ||
| libgen.h | ||
| libintl.h | ||
| limits.h | ||
| locale.h | ||
| lzf.h | ||
| malloc.h | ||
| mqueue.h | ||
| netdb.h | ||
| nl_types.h | ||
| nxflat.h | ||
| obstack.h | ||
| poll.h | ||
| pthread.h | ||
| pty.h | ||
| pwd.h | ||
| regex.h | ||
| resolv.h | ||
| sched.h | ||
| search.h | ||
| semaphore.h | ||
| shadow.h | ||
| signal.h | ||
| spawn.h | ||
| stdbool.h | ||
| stddef.h | ||
| stdint.h | ||
| stdio.h | ||
| stdlib.h | ||
| stdnoreturn.h | ||
| string.h | ||
| strings.h | ||
| syscall.h | ||
| syslog.h | ||
| termios.h | ||
| threads.h | ||
| time.h | ||
| ulimit.h | ||
| unistd.h | ||
| utime.h | ||
| uuid.h | ||
| wait.h | ||
| wchar.h | ||
| wctype.h | ||