Skip to content

Commit

Permalink
Change type of seL4_DebugPutChar to take unsigned byte
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Spinale <[email protected]>
  • Loading branch information
nspin committed Jan 18, 2024
1 parent aa06e2f commit b9588b5
Show file tree
Hide file tree
Showing 9 changed files with 13 additions and 25 deletions.
7 changes: 1 addition & 6 deletions crates/private/support/sel4-simple-task/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#[cfg(feature = "alloc")]
extern crate alloc;

use core::ffi::c_char;
use core::ptr;
use core::slice;

Expand Down Expand Up @@ -122,11 +121,7 @@ fn abort_hook(info: Option<&AbortInfo>) {

sel4_panicking_env::register_abort_hook!(abort_hook);

fn debug_put_char(c: u8) {
sel4::debug_put_char(c as c_char)
}

sel4_panicking_env::register_debug_put_char!(debug_put_char);
sel4_panicking_env::register_debug_put_char!(sel4::debug_put_char);

fn panic_hook(info: &ExternalPanicInfo<'_>) {
debug_println!("{}", info);
Expand Down
2 changes: 1 addition & 1 deletion crates/sel4-microkit/src/panicking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) fn init_panicking() {
fn debug_put_char(c: u8) {
sel4::sel4_cfg_if! {
if #[cfg(PRINTING)] {
sel4::debug_put_char(c as core::ffi::c_char)
sel4::debug_put_char(c)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sel4-newlib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ mod impl_write {
1 | 2 => {
let bytes =
unsafe { slice::from_raw_parts(ptr.cast::<u8>(), len.try_into().unwrap()) };
for b in bytes {
debug_put_char(*b);
for &b in bytes {
debug_put_char(b);
}
len
}
Expand Down
7 changes: 1 addition & 6 deletions crates/sel4-root-task/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#![feature(cfg_target_thread_local)]
#![feature(never_type)]

use core::ffi::c_char;
use core::fmt;

pub use sel4_panicking_env::{abort, debug_print, debug_println};
Expand Down Expand Up @@ -83,11 +82,7 @@ where
}
}

fn debug_put_char(c: u8) {
sel4::debug_put_char(c as c_char)
}

sel4_panicking_env::register_debug_put_char!(debug_put_char);
sel4_panicking_env::register_debug_put_char!(sel4::debug_put_char);

#[macro_export]
macro_rules! declare_root_task {
Expand Down
4 changes: 1 addition & 3 deletions crates/sel4/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,10 @@
// SPDX-License-Identifier: MIT
//

use core::ffi::c_char;

use crate::{sys, InvocationContext, CapType, TCB, LocalCPtr};

/// Corresponds to `seL4_DebugPutChar`.
pub fn debug_put_char(c: c_char) {
pub fn debug_put_char(c: u8) {
sys::seL4_DebugPutChar(c)
}

Expand Down
3 changes: 1 addition & 2 deletions crates/sel4/src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
// SPDX-License-Identifier: MIT
//

use core::ffi::c_char;
use core::fmt;

use crate::debug_put_char;
Expand All @@ -21,7 +20,7 @@ pub struct DebugWrite;
impl fmt::Write for DebugWrite {
fn write_str(&mut self, s: &str) -> fmt::Result {
for &c in s.as_bytes() {
debug_put_char(c as c_char)
debug_put_char(c)
}
Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions crates/sel4/sys/src/syscalls/calls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// SPDX-License-Identifier: BSD-2-Clause
//

use core::ffi::{c_char, c_int};
use core::ffi::c_int;
use core::sync::atomic::{compiler_fence, Ordering};

use sel4_config::{sel4_cfg, sel4_cfg_if};
Expand Down Expand Up @@ -631,7 +631,7 @@ pub fn seL4_Yield() {

sel4_cfg_if! {
if #[cfg(DEBUG_BUILD)] {
pub fn seL4_DebugPutChar(c: c_char) {
pub fn seL4_DebugPutChar(c: u8) {
sys_send_recv_simple(syscall_id::DebugPutChar, c as seL4_Word);
}

Expand Down
4 changes: 3 additions & 1 deletion crates/sel4/sys/src/wrappers/syscalls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,9 +385,11 @@ pub unsafe extern "C" fn seL4_Poll(src: seL4_CPtr, sender: *mut seL4_Word) -> se

sel4_cfg_if! {
if #[cfg(DEBUG_BUILD)] {
// Doesn't actually matter, but libsel4 uses char, which may be signed. Use c_char here and
// cast to u8 for the sake of principles.
#[no_mangle]
pub unsafe extern "C" fn seL4_DebugPutChar(c: c_char) {
crate::seL4_DebugPutChar(c)
crate::seL4_DebugPutChar(c as u8)
}

#[no_mangle]
Expand Down
3 changes: 1 addition & 2 deletions crates/sel4/sys/wrappers/src/panic_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// SPDX-License-Identifier: BSD-2-Clause
//

use core::ffi::c_char;
use core::fmt::{self, Write};
use core::panic::PanicInfo;

Expand All @@ -21,7 +20,7 @@ struct Debug;
impl Write for Debug {
fn write_str(&mut self, s: &str) -> fmt::Result {
for &c in s.as_bytes() {
seL4_DebugPutChar(c as c_char)
seL4_DebugPutChar(c)
}
Ok(())
}
Expand Down

0 comments on commit b9588b5

Please sign in to comment.