Skip to content
Snippets Groups Projects
Commit fdfe5882 authored by tamaf96's avatar tamaf96
Browse files

unsafe fix for missing syscalls::yieldk_for()

parent ffc7fd52
No related branches found
No related tags found
No related merge requests found
...@@ -44,7 +44,6 @@ use libtock::buttons::ButtonState; ...@@ -44,7 +44,6 @@ use libtock::buttons::ButtonState;
use libtock::console::Console; use libtock::console::Console;
use libtock::leds::LedsDriver; use libtock::leds::LedsDriver;
use libtock::result::TockResult; use libtock::result::TockResult;
use libtock::syscalls;
use libtock::timer; use libtock::timer;
#[cfg(feature = "debug_ctap")] #[cfg(feature = "debug_ctap")]
use libtock::timer::Timer; use libtock::timer::Timer;
...@@ -363,7 +362,7 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> { ...@@ -363,7 +362,7 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> {
let keepalive_alarm = keepalive.set_alarm(KEEPALIVE_DELAY).unwrap(); let keepalive_alarm = keepalive.set_alarm(KEEPALIVE_DELAY).unwrap();
// Wait for a button touch or an alarm. // Wait for a button touch or an alarm.
syscalls::yieldk_for(|| button_touched.get() || keepalive_expired.get()); usb_ctap_hid::yieldk_for(|| button_touched.get() || keepalive_expired.get());
// Cleanup alarm callback. // Cleanup alarm callback.
match keepalive.stop_alarm(keepalive_alarm) { match keepalive.stop_alarm(keepalive_alarm) {
...@@ -403,4 +402,4 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> { ...@@ -403,4 +402,4 @@ fn check_user_presence(cid: ChannelID) -> Result<(), Ctap2StatusCode> {
} else { } else {
Err(Ctap2StatusCode::CTAP2_ERR_USER_ACTION_TIMEOUT) Err(Ctap2StatusCode::CTAP2_ERR_USER_ACTION_TIMEOUT)
} }
} }
\ No newline at end of file
...@@ -81,7 +81,7 @@ pub fn recv(buf: &mut [u8; 64]) -> bool { ...@@ -81,7 +81,7 @@ pub fn recv(buf: &mut [u8; 64]) -> bool {
return false; return false;
} }
syscalls::yieldk_for(|| done.get()); yieldk_for(|| done.get());
true true
} }
...@@ -104,7 +104,7 @@ pub fn send(buf: &mut [u8; 64]) -> bool { ...@@ -104,7 +104,7 @@ pub fn send(buf: &mut [u8; 64]) -> bool {
return false; return false;
} }
syscalls::yieldk_for(|| done.get()); yieldk_for(|| done.get());
true true
} }
...@@ -154,7 +154,7 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus { ...@@ -154,7 +154,7 @@ pub fn send_or_recv(buf: &mut [u8; 64]) -> SendOrRecvStatus {
return SendOrRecvStatus::Error; return SendOrRecvStatus::Error;
} }
syscalls::yieldk_for(|| status.get().is_some()); yieldk_for(|| status.get().is_some());
status.get().unwrap() status.get().unwrap()
} }
...@@ -261,7 +261,7 @@ fn recv_with_timeout_detail( ...@@ -261,7 +261,7 @@ fn recv_with_timeout_detail(
return Some(SendOrRecvStatus::Error); return Some(SendOrRecvStatus::Error);
} }
syscalls::yieldk_for(|| status.get().is_some() || timeout_expired.get()); yieldk_for(|| status.get().is_some() || timeout_expired.get());
// Cleanup alarm callback. // Cleanup alarm callback.
match timeout.stop_alarm(timeout_alarm) { match timeout.stop_alarm(timeout_alarm) {
...@@ -362,7 +362,7 @@ fn send_or_recv_with_timeout_detail( ...@@ -362,7 +362,7 @@ fn send_or_recv_with_timeout_detail(
return Some(SendOrRecvStatus::Error); return Some(SendOrRecvStatus::Error);
} }
syscalls::yieldk_for(|| status.get().is_some() || timeout_expired.get()); yieldk_for(|| status.get().is_some() || timeout_expired.get());
// Cleanup alarm callback. // Cleanup alarm callback.
match timeout.stop_alarm(timeout_alarm) { match timeout.stop_alarm(timeout_alarm) {
...@@ -411,3 +411,11 @@ fn send_or_recv_with_timeout_detail( ...@@ -411,3 +411,11 @@ fn send_or_recv_with_timeout_detail(
status.get() status.get()
} }
pub(crate) fn yieldk_for<F: Fn() -> bool>(cond: F) {
while !cond() {
unsafe {
syscalls::raw::yieldk();
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment