zephyr/lib/libc/picolibc
Keith Packard f075022bec libc/picolibc: Make lock typing match between Zephyr and picolibc
Picolibc's retargetable locking is based upon having the user own the lock
type (struct __lock, along with typedef struct __lock *_LOCK_T), and then
having the picolibc internal code only refer to this type via the _LOCK_T
pointer typedef, leaving the actual struct undeclared there.

Zephyr wants to use 'struct k_mutex' for this type; the initial picolibc
port handled this by trying to redefine the picolibc locking to use 'void
*' instead of 'struct __lock *' by including '#define _LOCK_T void
*'. Which 'works' as long as the Zephyr code doesn't actually include
picolibc's sys/lock.h.

A recent picolibc change to support POSIX stdio locking has picolibc's
stdio.h including sys/lock.h, which breaks Zephyr's hack.

To fix this, create a real 'struct __lock' type as

	struct __lock { struct k_mutex m; };

Define all of the required picolibc locking API with this real type,
referring to the mutex inside without needing any casts.

This required switching the definition of the C library global lock from
K_MUTEX_DEFINE to the open-coded version, STRUCT_SECTION_ITERABLE_ALTERNATE
so that it has the correct type and still lands in the same elf section.

The only mildly inappropriate code left is that lock are allocated using
k_object_alloc(K_OBJ_MUTEX), which "works" because the size of 'struct
__lock` will exactly match the size of 'struct k_mutex' because of C's
struct allocation rules.

Signed-off-by: Keith Packard <keithp@keithp.com>
2025-05-01 07:15:16 +02:00
..
assert.c picolibc: Use common abort(), call from assert when !__ASSERT_ON 2025-02-14 10:42:16 +01:00
cbprintf.c libc/picolibc: Split hooks into separate files 2024-11-16 13:50:16 -05:00
chk_fail.c libc/picolibc: Split hooks into separate files 2024-11-16 13:50:16 -05:00
CMakeLists.txt picolibc: Replace hard coded -fno-lto flag 2025-01-27 13:24:52 +01:00
errno_wrap.c libc/picolibc: Split hooks into separate files 2024-11-16 13:50:16 -05:00
exit.c libc/picolibc: Split hooks into separate files 2024-11-16 13:50:16 -05:00
Kconfig lib/libc: picolibc: select its source with Kconfig choice 2024-07-09 17:29:12 -04:00
locks.c libc/picolibc: Make lock typing match between Zephyr and picolibc 2025-05-01 07:15:16 +02:00
picolibc-hooks.h libc/picolibc: Split hooks into separate files 2024-11-16 13:50:16 -05:00
stdio.c libc/picolibc: Split hooks into separate files 2024-11-16 13:50:16 -05:00