pico_cyw43_arch FreeRTOS+lwIP: route errno through newlib (LWIP_ERRNO_STDINCLUDE) #2974
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!2974
Loading…
Reference in a new issue
No description provided.
Delete branch "skycmoon/fix/freertos-lwip-errno"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #2973.
What
Swap
LWIP_PROVIDE_ERRNO=1forLWIP_ERRNO_STDINCLUDE=1on thepico_cyw43_arch_lwip_sys_freertosvariant. Single hunk insrc/rp2_common/pico_cyw43_arch/CMakeLists.txt.Why
LWIP_PROVIDE_ERRNO=1is correct for bare-metal builds (no libc ownserrno), but the FreeRTOS+lwIP variant always ships with newlib, which already provides a thread-localerrnovia<errno.h>. The unconditionalLWIP_PROVIDE_ERRNO=1makes lwIP declare its ownextern int errnoglobal, diverging from newlib's storage. Any code readingerrnovia<errno.h>— including the standard mbedTLSlibrary/net_sockets.cBIO — misses theEWOULDBLOCKlwIP wrote, treats every non-blockingrecv()poll as fatal, and tears the TLS session down right after handshake.LWIP_ERRNO_STDINCLUDE=1keeps lwIP'sE*constants available but routes them via<errno.h>, so lwIP and the rest of the program share newlib's thread-local storage. Issue #2973 has the full diagnosis and an observable symptom description (TLS handshake completes → application sends e.g. MQTTCONNECT→ server queuesCONNACK→ client immediately FINs without reading the response → loop forever at the application's backoff cadence).Scope
pico_cyw43_arch_lwip_sys_freertos_headersis touched.pico_cyw43_arch_lwip_threadsafe_background(bare-metal) does not currently setLWIP_PROVIDE_ERRNO=1, so no change needed there.Compatibility
Behaviour-preserving for users who don't touch
errnodirectly — lwIP'sE*constants still resolve, just through<errno.h>. Correcting for users on the stock mbedTLS BIO pattern (or any equivalent POSIX-style errno shim).Test
I verified the equivalent fix locally as a project-side override in
lwipopts.h: cancelling the SDK's-D LWIP_PROVIDE_ERRNO=1and settingLWIP_ERRNO_STDINCLUDE=1resolved a persistent MQTTCONNECT/CONNACK/closestorm on Pico 2W (FreeRTOS + lwIP + mbedTLS + coreMQTT). This PR moves that fix from a per-project workaround to the SDK default for the variant.@ -69,2 +69,3 @@CYW43_LWIP=1LWIP_PROVIDE_ERRNO=1# FreeRTOS+lwIP uses newlib, which provides a thread-local errno# via <errno.h>. LWIP_PROVIDE_ERRNO=1 would declare lwIP's ownum, who says it uses newlib? surely it is dependent on the compiler/toolchain?
i'm not convinced by this yet - as i say, who says that newlib is used? and this is non-overridable now as implemented
Yes. I think it was a mistake to add this to the library. It should have been left to be defined in lwipopts.h
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.