From da0accb72d050cf42782bd4cebeb4fa6616a138b Mon Sep 17 00:00:00 2001 From: Sky Date: Wed, 27 May 2026 19:01:46 -0700 Subject: [PATCH] pico_cyw43_arch: route lwIP errno through newlib on FreeRTOS+lwIP MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The freertos+lwIP variant unconditionally sets LWIP_PROVIDE_ERRNO=1, which makes lwIP declare its own `extern int errno` global. Under FreeRTOS+newlib (the only libc shipped with the SDK's FreeRTOS port) newlib already provides a thread-local errno via , so any POSIX-style code that reads errno via diverges from the storage lwIP writes to. The standard mbedTLS BIO pattern (stock net_sockets.c) is exactly this — `recv()` returns -1, the shim reads errno and never sees the EWOULDBLOCK lwIP set, so it treats every non-blocking poll as a fatal error and tears the session down. LWIP_ERRNO_STDINCLUDE=1 keeps lwIP's errno-constants behaviour but routes through , so lwIP and the rest of the program share newlib's thread-local storage. Behaviour for users not exercising the BIO-shim pattern is unchanged. --- src/rp2_common/pico_cyw43_arch/CMakeLists.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rp2_common/pico_cyw43_arch/CMakeLists.txt b/src/rp2_common/pico_cyw43_arch/CMakeLists.txt index ae81bccd5..1a6c4d28d 100644 --- a/src/rp2_common/pico_cyw43_arch/CMakeLists.txt +++ b/src/rp2_common/pico_cyw43_arch/CMakeLists.txt @@ -67,7 +67,13 @@ if (PICO_CYW43_SUPPORTED) # set by BOARD=pico-w pico_cyw43_arch_sys_freertos) target_compile_definitions(pico_cyw43_arch_lwip_sys_freertos_headers INTERFACE CYW43_LWIP=1 - LWIP_PROVIDE_ERRNO=1 + # FreeRTOS+lwIP uses newlib, which provides a thread-local errno + # via . LWIP_PROVIDE_ERRNO=1 would declare lwIP's own + # `extern int errno` global, diverging from newlib's storage and + # silently breaking mbedTLS BIO shims (and any code reading errno + # via ) that miss the EWOULDBLOCK lwIP wrote. + # LWIP_ERRNO_STDINCLUDE=1 routes lwIP through instead. + LWIP_ERRNO_STDINCLUDE=1 # now the default #PICO_LWIP_CUSTOM_LOCK_TCPIP_CORE=1 # we want to override the lwip locking mechanism to use our mutex )