summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-02-05 08:43:45 +0000
committerbors <bors@rust-lang.org>2023-02-05 08:43:45 +0000
commit7349741e84fd409930bd3498e636e5c094dd249f (patch)
treedb1692dbb7f49a81b609a03653b95df2c94024c0
parent3190d469e1817b330ec0c7f6b2c2bac72d6d5f72 (diff)
parentbe1d79de6008f137199f34a57621a0dea3a1ab29 (diff)
downloadrust-libc-7349741e84fd409930bd3498e636e5c094dd249f.tar.gz
Auto merge of #3084 - betrusted-io:initial-xous-support, r=JohnTitor
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.
-rw-r--r--src/lib.rs6
-rw-r--r--src/xous.rs49
2 files changed, 55 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index acda091592..d9bd318d1d 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -151,6 +151,12 @@ cfg_if! {
mod wasi;
pub use wasi::*;
+ } else if #[cfg(target_os = "xous")] {
+ mod fixed_width_ints;
+ pub use fixed_width_ints::*;
+
+ mod xous;
+ pub use xous::*;
} else {
// non-supported targets: empty...
}
diff --git a/src/xous.rs b/src/xous.rs
new file mode 100644
index 0000000000..e6c0c2573d
--- /dev/null
+++ b/src/xous.rs
@@ -0,0 +1,49 @@
+//! Xous C type definitions
+
+pub type c_schar = i8;
+pub type c_uchar = u8;
+pub type c_short = i16;
+pub type c_ushort = u16;
+pub type c_int = i32;
+pub type c_uint = u32;
+pub type c_float = f32;
+pub type c_double = f64;
+pub type c_longlong = i64;
+pub type c_ulonglong = u64;
+pub type intmax_t = i64;
+pub type uintmax_t = u64;
+
+pub type size_t = usize;
+pub type ptrdiff_t = isize;
+pub type intptr_t = isize;
+pub type uintptr_t = usize;
+pub type ssize_t = isize;
+
+pub type off_t = i64;
+pub type c_char = u8;
+pub type c_long = i64;
+pub type c_ulong = u64;
+pub type wchar_t = u32;
+
+pub const INT_MIN: c_int = -2147483648;
+pub const INT_MAX: c_int = 2147483647;
+
+cfg_if! {
+ if #[cfg(libc_core_cvoid)] {
+ pub use ::ffi::c_void;
+ } else {
+ // Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help
+ // enable more optimization opportunities around it recognizing things
+ // like malloc/free.
+ #[repr(u8)]
+ #[allow(missing_copy_implementations)]
+ #[allow(missing_debug_implementations)]
+ pub enum c_void {
+ // Two dummy variants so the #[repr] attribute can be used.
+ #[doc(hidden)]
+ __variant1,
+ #[doc(hidden)]
+ __variant2,
+ }
+ }
+}