zephyr/lib
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
..
acpi lib: fix typo in multiple directories 2025-01-28 00:06:18 +01:00
cpp cpp: Add c++ version number 2025-02-10 15:57:26 +00:00
crc lib: crc: add CRC-32K/4.2 2025-04-14 09:49:02 +02:00
hash lib: hash: murmur3: Account for unaligned 32-bit access 2025-04-29 17:54:51 +02:00
heap kernel: sys_heap: decouple realloc from aligned_realloc 2025-04-01 22:13:04 +02:00
libc libc/picolibc: Make lock typing match between Zephyr and picolibc 2025-05-01 07:15:16 +02:00
mem_blocks lib: mem_block: move to own folder 2023-12-13 17:27:54 -05:00
net_buf lib: net_buf: remove deprecated net_buf_put() and net_buf_get() functions 2025-03-12 19:04:19 +01:00
open-amp lib: open-amp: fix OPENAMP_COPY_RSC_TABLE dependancy 2025-04-25 15:55:43 +02:00
os lib/os/fdtable: Remove ifdef on NATIVE_POSIX 2025-03-12 02:27:36 +01:00
posix posix: fix typo in pthread_cond_init 2025-04-25 19:03:28 +02:00
runtime llvm: Add support for selecting runtime library 2023-08-03 19:35:11 +02:00
smf lib: smf: Fix handled bug causing events to not propagate. 2025-01-23 19:24:08 +01:00
utils json: improve parsing and serializing of integers 2025-04-11 06:32:50 +02:00
uuid uuid: Add UUID utilities 2025-04-14 09:47:26 +02:00
CMakeLists.txt uuid: Add UUID utilities 2025-04-14 09:47:26 +02:00
Kconfig uuid: Add UUID utilities 2025-04-14 09:47:26 +02:00