Skip to content

Commit

Permalink
Polyfill the missing memchr impl in latest esp-hal
Browse files Browse the repository at this point in the history
  • Loading branch information
ivmarkov committed Jan 5, 2025
1 parent 773dba3 commit 446a01a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 2 additions & 1 deletion esp-mbedtls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down
10 changes: 10 additions & 0 deletions esp-mbedtls/src/esp_hal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 446a01a

Please sign in to comment.