Skip to content

Commit be1d79d

Browse files
committed
xous: add initial C definitions
This adds initial C definitions to Xous. There is no C library, so this mostly serves to add C-compatible exports to the `libc` crate. Signed-off-by: Sean Cross <[email protected]>
1 parent 44542e9 commit be1d79d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

src/lib.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,12 @@ cfg_if! {
151151

152152
mod wasi;
153153
pub use wasi::*;
154+
} else if #[cfg(target_os = "xous")] {
155+
mod fixed_width_ints;
156+
pub use fixed_width_ints::*;
157+
158+
mod xous;
159+
pub use xous::*;
154160
} else {
155161
// non-supported targets: empty...
156162
}

src/xous.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//! Xous C type definitions
2+
3+
pub type c_schar = i8;
4+
pub type c_uchar = u8;
5+
pub type c_short = i16;
6+
pub type c_ushort = u16;
7+
pub type c_int = i32;
8+
pub type c_uint = u32;
9+
pub type c_float = f32;
10+
pub type c_double = f64;
11+
pub type c_longlong = i64;
12+
pub type c_ulonglong = u64;
13+
pub type intmax_t = i64;
14+
pub type uintmax_t = u64;
15+
16+
pub type size_t = usize;
17+
pub type ptrdiff_t = isize;
18+
pub type intptr_t = isize;
19+
pub type uintptr_t = usize;
20+
pub type ssize_t = isize;
21+
22+
pub type off_t = i64;
23+
pub type c_char = u8;
24+
pub type c_long = i64;
25+
pub type c_ulong = u64;
26+
pub type wchar_t = u32;
27+
28+
pub const INT_MIN: c_int = -2147483648;
29+
pub const INT_MAX: c_int = 2147483647;
30+
31+
cfg_if! {
32+
if #[cfg(libc_core_cvoid)] {
33+
pub use ::ffi::c_void;
34+
} else {
35+
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
36+
// enable more optimization opportunities around it recognizing things
37+
// like malloc/free.
38+
#[repr(u8)]
39+
#[allow(missing_copy_implementations)]
40+
#[allow(missing_debug_implementations)]
41+
pub enum c_void {
42+
// Two dummy variants so the #[repr] attribute can be used.
43+
#[doc(hidden)]
44+
__variant1,
45+
#[doc(hidden)]
46+
__variant2,
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)