Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use own implementation instead of ROM functions, re-add memchr #2896

Merged
merged 4 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions esp-hal/ld/esp32/rom/additional.ld
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ PROVIDE ( strchr = 0x4000c53c );
PROVIDE ( strlcpy = 0x4000c584 );
PROVIDE ( strstr = 0x4000c674 );
PROVIDE ( strcasecmp = 0x400011cc );
PROVIDE ( strdup = 0x4000143c );
PROVIDE ( atoi = 0x400566c4 );

PROVIDE ( memchr = 0x4000c244 );
2 changes: 0 additions & 2 deletions esp-hal/ld/esp32c2/rom/additional.ld
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,3 @@ PROVIDE ( strchr = 0x40000514 );
PROVIDE ( strlcpy = 0x40000524 );
PROVIDE ( strstr = 0x400004ac );
PROVIDE ( strcasecmp = 0x40000504 );
PROVIDE ( strdup = 0x40000510 );
PROVIDE ( atoi = 0x40000580 );
4 changes: 2 additions & 2 deletions esp-hal/ld/esp32c3/rom/additional.ld
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ PROVIDE( strchr = 0x400003e0 );
PROVIDE( strlcpy = 0x400003f0 );
PROVIDE( strstr = 0x40000378 );
PROVIDE( strcasecmp = 0x400003d0 );
PROVIDE( strdup = 0x400003dc );
PROVIDE( atoi = 0x4000044c );

PROVIDE( memchr = 0x400003c8 );
2 changes: 0 additions & 2 deletions esp-hal/ld/esp32c6/rom/additional.ld
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,3 @@ PROVIDE(strchr = 0x40000534);
PROVIDE(strlcpy = 0x40000544);
PROVIDE(strstr = 0x400004cc);
PROVIDE(strcasecmp = 0x40000524);
PROVIDE(strdup = 0x40000530);
PROVIDE(atoi = 0x400005a0);
4 changes: 2 additions & 2 deletions esp-hal/ld/esp32h2/rom/additional.ld
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ PROVIDE( strchr = 0x4000052c );
PROVIDE( strlcpy = 0x4000053c );
PROVIDE( strstr = 0x400004c4 );
PROVIDE( strcasecmp = 0x4000051c );
PROVIDE( strdup = 0x40000528 );
PROVIDE( atoi = 0x40000598 );

PROVIDE( memchr = 0x40000514 );
1 change: 0 additions & 1 deletion esp-hal/ld/esp32s2/rom/additional.ld
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@ PROVIDE ( strchr = 0x4001adb0 );
PROVIDE ( strlcpy = 0x4001adf8 );
PROVIDE ( strstr = 0x4001aee8 );
PROVIDE ( strcasecmp = 0x40007b38 );
PROVIDE ( strdup = 0x40007d84 );
2 changes: 0 additions & 2 deletions esp-hal/ld/esp32s3/rom/additional.ld
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,3 @@ PROVIDE( strchr = 0x4000138c );
PROVIDE( strlcpy = 0x400013bc );
PROVIDE( strstr = 0x40001254 );
PROVIDE( strcasecmp = 0x4000135c );
PROVIDE( strdup = 0x40001380 );
PROVIDE( atoi = 0x400014d0 );
1 change: 1 addition & 0 deletions esp-wifi/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed

- Fixed triggering a debug-assertion during scan (#2612)
- Fix WPA2-ENTERPRISE functionality (#2896)

### Removed

Expand Down
26 changes: 23 additions & 3 deletions esp-wifi/src/compat/misc.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// these are not called but needed for linking
use crate::compat::malloc::malloc;

// these are not called but needed for linking
#[no_mangle]
unsafe extern "C" fn fwrite(ptr: *const (), size: usize, count: usize, stream: *const ()) -> usize {
todo!("fwrite {:?} {} {} {:?}", ptr, size, count, stream)
Expand All @@ -20,8 +21,27 @@ unsafe extern "C" fn fclose(stream: *const ()) -> i32 {
todo!("fclose {:?}", stream);
}

// not available in ROM on ESP32-S2
#[cfg(feature = "esp32s2")]
// We cannot just use the ROM function since it needs to allocate memory
#[no_mangle]
unsafe extern "C" fn strdup(str: *const core::ffi::c_char) -> *const core::ffi::c_char {
trace!("strdup {:?}", str);

unsafe {
let s = core::ffi::CStr::from_ptr(str);
let len = s.count_bytes() + 1;
let p = malloc(len);
if !p.is_null() {
core::ptr::copy_nonoverlapping(str, p as *mut i8, len);
}
Dominaezzz marked this conversation as resolved.
Show resolved Hide resolved
p.cast()
}
}

// We cannot just use the ROM function since it calls `__getreent`
//
// From docs: The __getreent() function returns a per-task pointer to struct
// _reent in newlib libc. This structure is allocated on the TCB of each task.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was looking into why on earth atoi needed to be reentrant, it seems it can set errno and therefore needs a thread local errno to set to avoid race conditions - annoying.

// i.e. it assumes a FreeRTOS task calling it.
#[no_mangle]
unsafe extern "C" fn atoi(str: *const i8) -> i32 {
trace!("atoi {:?}", str);
Expand Down
Loading