nuttx/libs/libc/pthread
Marco Casaroli 43694933ce libc, sched: Resolve FDPIC descriptors at module callback entry points.
The base firmware and an FDPIC module disagree about what a function
pointer is.  Firmware is not built FDPIC, so to it a pointer is a code
address and it branches there.  A module passes the address of a two word
descriptor instead, because its code and data are placed independently and
a bare code address would leave the callee unable to find its own data.  A
firmware routine that takes a callback therefore branches into the
module's data segment and faults.

So the ten entry points that can be handed a callback by a module resolve
the descriptor before storing or branching to it: qsort, bsearch,
pthread_create, signal, sigaction, task_create and task_create_with_stack,
task_spawn, pthread_once, scandir, and mq_notify and timer_create with
SIGEV_THREAD.

Which one resolves matters as much as that one does.  Resolving twice would
take an already resolved code address for a descriptor and read two words
from the instruction stream, so each pointer is resolved exactly once, at
the outermost point that sees it.  signal() passes its argument through
untouched because sigaction() and then nxsig_action() will resolve it,
which covers a module calling sigaction() directly as well.  qsort() is
split so that the public entry resolves and the recursive implementation
does not.  scandir() resolves its filter but not its comparison function,
which it hands to qsort().

Whether a caller is a module at all is asked of the PIC base register,
which up_initial_state() sets only for a task that has a D-Space.  A plain
kernel task therefore reads zero and is left alone.

SIGEV_THREAD is the case the register cannot answer, because the callback
runs later on a work queue worker that carries no module's base at all.
The base is captured instead when the notification is registered, in the
module's own context, and installed around the call.

All of it is behind CONFIG_FDPIC, which defaults off.  Built for
mps3-an547:picostest both ways; with it off the entry points compile to
what they were.

Assisted-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
2026-09-25 10:46:48 -03:00
..
CMakeLists.txt arch, sched/signal: Fix compilation with ENABLE_PARTIAL_SIGNALS=y 2026-06-16 17:07:32 +08:00
Kconfig boardcrtl: change BOARDCTL_TESTSET to BOARDIOC_SPINLOCK 2024-09-06 16:10:09 +08:00
Make.defs arch, sched/signal: Fix compilation with ENABLE_PARTIAL_SIGNALS=y 2026-06-16 17:07:32 +08:00
pthread.h pthread: move pthread_cond to userspace 2026-01-26 16:26:39 +08:00
pthread_atfork.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_destroy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_getaffinity.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_getdetachstate.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_getguardsize.c pthread: add pthread_attr_{get|set}guardsize support 2025-08-22 20:50:13 +08:00
pthread_attr_getinheritsched.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_getschedparam.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_getschedpolicy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_getscope.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_getstack.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_getstackaddr.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_getstacksize.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_init.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_setaffinity.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_setdetachstate.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_setguardsize.c pthread: add pthread_attr_{get|set}guardsize support 2025-08-22 20:50:13 +08:00
pthread_attr_setinheritsched.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_setschedparam.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_setschedpolicy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_attr_setscope.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_setstack.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_setstackaddr.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_attr_setstacksize.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_barrierattr_destroy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_barrierattr_getpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_barrierattr_init.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_barrierattr_setpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_barrierdestroy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_barrierinit.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_barrierwait.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_cleanup.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_concurrency.c pthread: add pthread_{get|set}concurrency support 2025-08-22 20:50:13 +08:00
pthread_condattr_destroy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condattr_getclock.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_condattr_getpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condattr_init.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condattr_setclock.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_condattr_setpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condbroadcast.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condclockwait.c nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr 2026-08-24 13:20:45 +08:00
pthread_conddestroy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condinit.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condsignal.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_condtimedwait.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_condwait.c nuttx/atomic: replace atomic_fetch_xxx with atomic_xxx just like zephyr 2026-08-24 13:20:45 +08:00
pthread_create.c libc, sched: Resolve FDPIC descriptors at module callback entry points. 2026-09-25 10:46:48 -03:00
pthread_equal.c pthead: change the pthread_equal implementation from macro to function 2026-01-16 01:37:38 +08:00
pthread_exit.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_get_stackaddr_np.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_get_stacksize_np.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_getcpuclockid.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_getname_np.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_getspecific.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_gettid_np.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_keycreate.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_keydelete.c libc/pthread/pthread_keydelete.c: reset key value 2025-10-01 12:00:43 +08:00
pthread_kill.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutex.c pthread: make PTHREAD_MUTEX_DEFAULT_UNSAFE default true 2026-01-26 20:56:12 +08:00
pthread_mutex_consistent.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutex_destroy.c arch, sched/signal: Fix compilation with ENABLE_PARTIAL_SIGNALS=y 2026-06-16 17:07:32 +08:00
pthread_mutex_getprioceiling.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutex_inconsistent.c pthread: remove tl_lock 2026-01-26 20:56:12 +08:00
pthread_mutex_init.c libs/libc/pthread/pthread_mutex: Fix robust mutex initialization 2026-06-12 08:04:09 +08:00
pthread_mutex_lock.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutex_setprioceiling.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutex_timedlock.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutex_trylock.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutex_unlock.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutexattr_destroy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutexattr_getprioceiling.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutexattr_getprotocol.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutexattr_getpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutexattr_getrobust.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutexattr_gettype.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutexattr_init.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutexattr_setprioceiling.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutexattr_setprotocol.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutexattr_setpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_mutexattr_setrobust.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_mutexattr_settype.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_once.c libc, sched: Resolve FDPIC descriptors at module callback entry points. 2026-09-25 10:46:48 -03:00
pthread_rwlock.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_rwlock_rdlock.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_rwlock_wrlock.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_rwlockattr_destroy.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_rwlockattr_getpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_rwlockattr_init.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_rwlockattr_setpshared.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_self.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_setcancelstate.c style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
pthread_setcanceltype.c style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
pthread_setname_np.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_setspecific.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00
pthread_spinlock.c include/debug.h: Move to include/nuttx/debug.h 2026-04-07 07:50:06 -03:00
pthread_testcancel.c style: fix spelling in code comments and strings 2025-05-23 10:48:41 +08:00
pthread_yield.c libs/libc: migrate to SPDX identifier 2024-10-01 12:25:52 +08:00