Skip to content

libc(picolibc): fix locks.c K_MUTEX and _LOCK_T incompatibilities (clean)#53

Closed
bhoot1234567890 wants to merge 10000 commits intozmkfirmware:mainfrom
bhoot1234567890:clean/fix-picolibc-locks
Closed

libc(picolibc): fix locks.c K_MUTEX and _LOCK_T incompatibilities (clean)#53
bhoot1234567890 wants to merge 10000 commits intozmkfirmware:mainfrom
bhoot1234567890:clean/fix-picolibc-locks

Conversation

@bhoot1234567890
Copy link

Summary:

This patch fixes several issues in zephyr/lib/libc/picolibc/locks.c discovered when building ZMK with picolibc enabled. The changes make the file compatible with newlib/newlib-style expectations and Zephyr userspace handling.

Problems found:

  • K_MUTEX_DEFINE(__lock___libc_recursive_mutex) conflicts with newlib's struct __lock and Zephyr iterable section macros, causing "conflicting types" compilation errors.
  • _LOCK_T previously defined as void * mismatched newlib expectations (newlib expects _LOCK_T to be a pointer to struct __lock). This caused conflicting function signatures for __retarget_lock_*.
  • Static lock initialization and userspace access granting were not aligned with CONFIG_USERSPACE; static initialization used K_MUTEX_DEFINE, which cannot be granted properly as an object pointer in userspace contexts.
  • Dynamic allocation path allocated raw struct k_mutex pointers (or returned raw k_mutex pointers), which didn’t match newlib's _LOCK_T usage.

What this patch does:

  • Introduces struct __lock wrapper matching newlib expectations and typedefs _LOCK_T as struct __lock * so signatures match newlib.
  • Replaces the K_MUTEX_DEFINE static declaration with a struct __lock __lock___libc_recursive_mutex wrapper and initializes the embedded mutex in a SYS_INIT handler.
  • Ensures userspace support: when CONFIG_USERSPACE is enabled, the static wrapper allocates a kernel mutex object, initializes it, and grants access with k_object_access_all_grant.
  • Updates dynamic allocation routines to allocate struct __lock wrappers and to allocate/initialize the underlying k_mutex appropriately for both kernel and userspace builds.
  • Adjusts __retarget_lock_acquire/_release/_try_acquire to operate on the wrapper correctly in both userspace and non-userspace builds.

Testing performed:

  • Built the ZMK application (nrf52832_mdk with tkl_nrf52832 shield) locally with picolibc enabled; the build completes and zephyr/zmk.elf is generated.
  • Verified that enabling CONFIG_NEWLIB_LIBC switches the build to newlib (no longer uses this file), and observed expected size differences.

Notes:

  • The change keeps compatibility with CONFIG_USERSPACE and non-userspace builds.
  • If maintainers prefer the static K_MUTEX_DEFINE approach, an alternate patch could expose the object properly to userspace; this patch prefers an explicit wrapper to match newlib ABI expectations.

Files changed:

  • zephyr/lib/libc/picolibc/locks.c

Please review for style and userspace semantics; happy to adjust to match upstream conventions.

Thalley and others added 30 commits January 6, 2026 19:14
Use the host defined roles, rather than the HCI defined ones.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
Since the entire cid checking function is conditionally included based
on KConfig, the usage site also needs to use #if instead of IS_ENABLED,
otherwise you get the following warning during compilation when the
option is disabled:

`error: implicit declaration of function
‘bt_mesh_vnd_mod_msg_cid_check’`

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
This deprecates CONFIG_BT_MESH_MODEL_VND_MSG_CID_FORCE. This option was
added to allow an optimization that a) only can apply in edge case
networks that use multiple vendor models with different CIDs, b) doesn't
really have much potential gains even in this case unless there is a
large number of opcodes in these vendor models, and c) makes it
impractical to implement support for vendor models handling SIG opcodes.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
This fixes a limitation where the stack assumed that vendor models could
not specify handlers for SIG-defined (1- or 2-byte) opcodes. This
assumption does not exist in the specification. In fact, the
specification expects this very use-case to be possible, in MeshPRT 1.1,
section 3.8.3:

> To exchange messages with a Bluetooth SIG adopted model, a Vendor Model
> shall use the Access message defined for the Bluetooth SIG model.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
This adds a test case to the access BSIM tests to check that vendor
models can specify a handler for and receive messages using a
SIG-defined 1-byte opcode.

Signed-off-by: Ludvig Jordet <ludvig.jordet@nordicsemi.no>
Since the STM32MP2 I3C controller uses a combined interrupt line for I3C
events and errors, add the support for handling this type of interrupt
in the I3C driver.

Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
Add clock bindings for I3C peripherals for the STM32MP2 series.

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
Add reset bindings for I3C peripherals for the STM32MP2 series.

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
Add I3C clocks rate reading to the STM32MP2 clock driver.

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
Add the node I3C4 in non-secure context to dtsi. Others I3C nodes cannot
be added as they rely on EXTI1 interrupt lines that is not supported yet
for the STM32MP2.

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
The I3C is now supported on the STM32MP257F-DK and STM32MP257F-EV1
boards.

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
The I2C and SPI features have been added to the supported features for
the stm32mp257f_ev1 but were missing from the stm32mp257f_dk board file.

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
This commit adds the i2c8 node to the device tree for the
STM32MP257F-DK board. This node corresponds to the i2c exposed by the
GPIO expansion connector [1] and not used by the cortex A35.

[1]: https://www.st.com/resource/en/user_manual/um3385-discovery-kit-with-stm32mp257f-mpu-stmicroelectronics.pdf
    Table 24. GPIO connector pinout

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
This commit adds the i3c4 node to the device tree for the
STM32MP257F-EV1 and the STM32MP257F-DK boards. This node corresponds to
the i3c exposed by the GPIO expansion connector [1], [2] and not used by
the cortex A35.

According to the STM32MP257F-EV1 and STM32MP257F-DK schematics, the I3C4
are connected to the same pins as the I2C8. Therefore, both nodes cannot
be enabled together.

[1]: https://wiki.st.com/stm32mpu/wiki/STM32MP257x-EV1_-_hardware_description

[1]: https://www.st.com/resource/en/user_manual/um3385-discovery-kit-with-stm32mp257f-mpu-stmicroelectronics.pdf
    Table 24. GPIO connector pinout

Co-authored-by: Charles Wenger <charles.wenger@savoirfairelinux.com>
Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
This driver uses math functions that require the math.h header. If not
included a lot of implicit declaration warnings are generated during
build.

Signed-off-by: Tanguy Raufflet <tanguy.raufflet@savoirfairelinux.com>
Previously, eventfd file descriptors were not being counted against the
required size for the global file descriptor table, which would result
in the function `eventfd()` (and `zvfs_eventfd()`) failing due to
insufficient resources.

Signed-off-by: Chris Friedt <chris@fr4.co>
This patch adds support for the QSPI memory controller (for the
SiWG917 SoC) in order to enable PSRAM testing. It also adds board
overlays for this family that include PSRAM.

Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
Enable the adc node to prevent undefined node reference error in adc_api
test.

Signed-off-by: Fabian Blatz <fabianblatz@gmail.com>
Product photo from https://learn.adafruit.com/assets/121788,
with the license CC BY-SA 3.0

Tested with the commands mentioned in index.rst

Signed-off-by: Jonas Berg <jonas.s.t.berg@gmail.com>
Add corresponding overlay file

Signed-off-by: Jonas Berg <jonas.s.t.berg@gmail.com>
set_iir_config() dereferences the device pointer before checking it
against NULL, making the defensive check ineffective.

Remove the redundant check.

Signed-off-by: Gaetan Perrot <gaetan.perrot@spacecubics.com>
This patch enables the output sample for the board siwx917_rb4342a
by adding an overlay.

Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
Raspberry pi based boards are now using binary info by default
(96b9b0f), and that limits pinctrl groups to 4 or 6 nodes. Split
this node in multiple groups.

Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
This commit adds the main DTS configurations required
to enable MSPI/OSPI/QSPI support on STM32.

Signed-off-by: Sara Touqan <zephyr@exalt.ps>
Signed-off-by: Sarah Younis <zephyr@exalt.ps>
Signed-off-by: Mohammad Odeh <zephyr@exalt.ps>
This commit introduces support for the mspi and ospi drivers on STM32,
enabling functionality APIs for MSPI/OSPI/QSPI host controllers..

Signed-off-by: Sara Touqan <zephyr@exalt.ps>
Signed-off-by: Sarah Younis <zephyr@exalt.ps>
Signed-off-by: Mohammad Odeh <zephyr@exalt.ps>
this commit enables building and running the sample on
stm32h573i_dk board,stm32h735g_disco board, arduino_giga_r1
board, and  b_u585i_iot02a board by providing the required overlay
and configuration updates.

Signed-off-by: Sara Touqan <zephyr@exalt.ps>
Signed-off-by: Sarah Younis <zephyr@exalt.ps>
Signed-off-by: Mohammad Odeh <zephyr@exalt.ps>
- Moves nxp,imx-gpt.yaml from the timer to the counter folder,
  as this is the binding for the counter driver
  drivers/counter/counter_mcux_gpt.c
- Fixes: zephyrproject-rtos#100947

Signed-off-by: Andrej Butok <andrey.butok@nxp.com>
UART0 is not currently used by Zephyr running on RPU. Remove it.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
Use the convenient DT_FREQ_M() macro from freq.h to improve readability.

Signed-off-by: Yasushi SHOJI <yashi@spacecubics.com>
1. Add power state nodes for mcxa156, including
sleep, deepsleep and powerdown.

2. Add power management related peripheral nodes
for mcxa156, including spc, cmc, vbat and wuu.

3. Add 'zephyr,cortex-m-idle-timer' node in frdm_mcxa156.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
julek-wolfssl and others added 25 commits January 8, 2026 08:33
The device is not able to place the entropy into stack or heap allocated
buffers. This uses a bounce buffer to be able to use any buffer with
virtio entropy.

Signed-off-by: Juliusz Sosinowicz <juliusz@wolfssl.com>
Add Renode simulation support for `mpfs_icicle`.

Signed-off-by: Marek Slowinski <mslowinski@antmicro.com>
Tune quantum parameter for selected kernel tests
targeting mpfs_icicle platform.

Those tests require higher fidelity of the virtual
time flow which is achievable on multi-core platforms
in Renode by reducing the quantum.

Increase time resolution to 10us (default is 100us).
It is a maximum drift of the virtual time between
simulated processors in SMP configuration.

Signed-off-by: Marek Slowinski <mslowinski@antmicro.com>
Tested with the commands in index.rst

Product photo from
https://github.com/CytronTechnologies/MAKER-NANO-RP2040/
blob/main/MAKER-NANO-RP2040-Image.PNG

Signed-off-by: Jonas Berg <jonas.s.t.berg@gmail.com>
Run clang-format on drivers/i2c/i2c_cdns.c.

Signed-off-by: Simon Maurer <mail@maurer.systems>
Switch the Cadence I2C device driver over to the use of the
DEVICE_MMIO_... macros instead of just using the physical base
address from the device tree.

Signed-off-by: Simon Maurer <mail@maurer.systems>
Clear the hold flag during the final data interrupt; otherwise the
Transfer Complete interrupt is never asserted.

Signed-off-by: Simon Maurer <mail@maurer.systems>
…unter

Add support for configuring and enabling the internal timestamp counter of
the Bosch M_CAN IP core.

Frontend drivers can overwrite this configuration for using a SoC-specific,
external timestamp counter.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
Enable support for configuring and enabling the external timestamp counter
of the NXP LPC MCAN.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
Add initial support for the Allwinner H3 SoC, commonly
found in development boards like the Orange Pi series.

This commit introduces the intial SoC support files:
 - Basic Kconfig configuration and SoC definition
 - MMU region setup for memory management
 - SoC-specific headers and device tree source include

Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
Add initial board support for the Xunlong Orange Pi Zero,
single-board computer based on the Allwinner H2+/H3 SoC.

Signed-off-by: Muhammad Waleed Badar <walid.badar@gmail.com>
The MCXN236 can use ostimer as the kernel timer.
We enable it in the dts, and which specific timer
to use as the system timer can be controlled through
Kconfig option based on application requirements.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
MCUX_LPTMR_TIMER is default to n, no need to set it again.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Add MCUX_OS_TIMER configuration with CPU_FREQ-based default selection.
Update CORTEX_M_SYSTICK to be disabled when either LPTMR or OSTIMER
is selected as the system timer, ensuring only one timer is active.

Signed-off-by: Zhaoxiang Jin <Zhaoxiang.Jin_1@nxp.com>
Cmake complains about this.

Signed-off-by: Wilfried Chauveau <wilfried.chauveau@arm.com>
Fix macro parameter typo (##inst → ##index) in CAN_RENESAS_RA_INIT
to ensure unique IRQ configure function names per instance.

Signed-off-by: Khai Cao <khai.cao.xk@renesas.com>
BIT_MASK(32) cannot do (1 << 32) - 1 without causing integer overflow.
Hence, for these macros BIT64_MASK(32) is required.

Additionally, remove the unnecessary (and presently unused) macros for the
register space. All of these can be reliably derived from the present
register masks.

Signed-off-by: Amneesh Singh <amneesh@ti.com>
Disable all interrupts when the VIM interrupt controller is initialized so
that it doesn't encounter any stray interrupts that were not enabled on
Zephyr.

Signed-off-by: Amneesh Singh <amneesh@ti.com>
List USB device controller as a supported feature in order to increase test
coverage.

Signed-off-by: Henrik Brix Andersen <henrik@brixandersen.dk>
Reneamed photograph of Renesas US159 DA14531EVZ board to match
convention documented in the Board Porting Guide (resolving issue
with old image not appearing in list of supported boards on Zephyr
website).

Signed-off-by: Ian Morris <ian.d.morris@outlook.com>
In z_vrfy_k_poll, there is a memory access check
K_SYSCALL_MEMORY_WRITE which is wrapped in a spinlock, the same
spinlock used in z_handle_obj_poll_events which is called from
k_sem_give() for example.

The K_SYSCALL_MEMORY_WRITE() macro conditionally calls LOG_ERR()
which may call the UART console, which may call an API like
k_sem_give(). This will cause a deadlock since the locked spinlock
will be relocked, and a recursive lock if SPINLOCK_VALIDATE and
ASSERTS are enabled as the validation will fail, causing a LOG_ERR,
causing a k_sem_give() causing a relock... until stack overflows.

To solve the issue, only protect the copy of events to events_copy
with the spinlock, the content of events is not actually checked, and
bound is not shared, so there is no need to do this validation in a
critical section. The contents of events is shared so that must be
copied in atomically.

Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
The current implementation of k_sleep(), when multi-threading
is disabled, busy waits using k_busy_wait() until the sleep timeout
has expired.

This patch aims to improve power efficiency of k_sleep() for
single-threaded applications by starting a timer (k_timer) and idling
the CPU until the timer interrupt wakes it up, thus avoiding
busy-looping.

Signed-off-by: Emanuele Di Santo <emdi@nordicsemi.no>
Instead of performing a linear search to determine if a given
thread is running on another CPU, or if it is marked as being
preempted by a metaIRQ on any CPU do this in O(1) time.

On SMP systems, Zephyr already tracks the CPU on which a thread
executes (or lasted executed). This information is leveraged to
do the search in O(1) time.

Signed-off-by: Peter Mitsis <peter.mitsis@intel.com>
Add support for clause 45 MDIO transactions to the GPIO MDIO driver.

Signed-off-by: Tim Pambor <tim.pambor@codewrights.de>
This problem didn't surface earlier, as different sizes weren't permitted.

Signed-off-by: Benedek Kupper <kupper.benedek@gmail.com>
@bhoot1234567890 bhoot1234567890 force-pushed the clean/fix-picolibc-locks branch from 40c0617 to 0fdd5de Compare January 9, 2026 06:33
@bhoot1234567890
Copy link
Author

Closing this duplicate PR — the clean single-commit fix is at zephyrproject-rtos#101988.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.