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

thread: adapt to API change of thread_measure_stack_free() and accept either version #97

Merged
merged 2 commits into from
May 31, 2024
Merged
Changes from all 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
25 changes: 23 additions & 2 deletions src/thread/riot_c.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,36 @@ impl KernelPID {
pub fn stack_stats(&self) -> Result<StackStats, StackStatsError> {
#[cfg(riot_develhelp)]
{
/// Out of a thread pointer, build whatever thread_measure_stack_free happens to need
/// right now
struct ThreadOrItsStart(*const riot_sys::thread_t);

// Before https://github.com/RIOT-OS/RIOT/pull/18942 (up and including 2024.04)
impl Into<*const riot_sys::libc::c_char> for ThreadOrItsStart {
fn into(self) -> *const riot_sys::libc::c_char {
unsafe { (*self.0).stack_start }
}
}
// After https://github.com/RIOT-OS/RIOT/pull/18942 (presumably 2024.07 and later)
impl Into<*const riot_sys::inline::thread_t> for ThreadOrItsStart {
fn into(self) -> *const riot_sys::inline::thread_t {
crate::inline_cast(self.0)
}
}

let thread = self.thread()?;
return Ok(StackStats {
// This cast is relevant because different platforms (eg. native and arm) disagree on
// whether that's an i8 or u8 pointer. Could have made it c_char, but a) don't want to
// alter the signatures and b) it's easier to use on the Rust side with a clear type.
start: unsafe { (*thread).stack_start as _ },
size: unsafe { (*thread).stack_size as _ },
free: unsafe { riot_sys::thread_measure_stack_free((*thread).stack_start) }
as usize,
#[allow(unused_imports)]
free: unsafe {
use riot_sys::inline::*;
use riot_sys::*;
thread_measure_stack_free(ThreadOrItsStart(thread).into())
} as usize,
});
}
#[cfg(not(riot_develhelp))]
Expand Down
Loading