From 446a01a5215e05e34356d1544adc4494d8ae2733 Mon Sep 17 00:00:00 2001 From: ivmarkov Date: Sun, 5 Jan 2025 09:27:15 +0000 Subject: [PATCH] Polyfill the missing memchr impl in latest esp-hal --- esp-mbedtls/Cargo.toml | 3 ++- esp-mbedtls/src/esp_hal.rs | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/esp-mbedtls/Cargo.toml b/esp-mbedtls/Cargo.toml index 2e52d47..ed20ee5 100644 --- a/esp-mbedtls/Cargo.toml +++ b/esp-mbedtls/Cargo.toml @@ -23,12 +23,13 @@ cfg-if = "1.0.0" edge-nal = { version = "0.4.0", optional = true } critical-section = "1.1.3" crypto-bigint = { version = "0.5.3", optional = true, default-features = false, features = ["extra-sizes"] } +tinyrlibc = { version = "0.5", optional = true, default-features = false } [features] default = ["edge-nal"] async = ["dep:embedded-io-async"] esp32 = ["esp-hal/esp32", "esp-wifi/esp32", "esp-mbedtls-sys/esp32", "crypto-bigint"] -esp32c3 = ["esp-hal/esp32c3", "esp-wifi/esp32c3", "esp-mbedtls-sys/esp32c3", "crypto-bigint"] +esp32c3 = ["esp-hal/esp32c3", "esp-wifi/esp32c3", "esp-mbedtls-sys/esp32c3", "crypto-bigint", "tinyrlibc/memchr"] esp32s2 = ["esp-hal/esp32s2", "esp-wifi/esp32s2", "esp-mbedtls-sys/esp32s2", "crypto-bigint"] esp32s3 = ["esp-hal/esp32s3", "esp-wifi/esp32s3", "esp-mbedtls-sys/esp32s3", "crypto-bigint"] diff --git a/esp-mbedtls/src/esp_hal.rs b/esp-mbedtls/src/esp_hal.rs index c688fa5..8839b04 100644 --- a/esp-mbedtls/src/esp_hal.rs +++ b/esp-mbedtls/src/esp_hal.rs @@ -66,3 +66,13 @@ impl Drop for Tls<'_> { critical_section::with(|cs| SHARED_SHA.borrow_ref_mut(cs).take()); } } + +// See https://github.com/esp-rs/esp-mbedtls/pull/62#issuecomment-2560830139 +// TODO: In future - and for all baremetal platforms - we should be having a definition like the one below +// for **all** libc functions used by `mbedtls` +// +// And then each baremetal platform can decide to opt-in and use the definition(s) +// from `tinyrlibc` or opt-out and provide their own implementation(s) +#[cfg(feature = "esp32c3")] +#[used] +static _MEMCHR: unsafe extern "C" fn(*const core::ffi::c_void, core::ffi::c_int, usize) -> *const core::ffi::c_void = tinyrlibc::memchr;