From d2deccda70ee2a89c3a4eb15ce1e0c3259b01d72 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Tue, 13 Dec 2022 20:01:04 +0000 Subject: [PATCH 01/10] Add preliminary support for zephyr embedded OS to libc and std. --- Cargo.toml | 4 +- src/unix/mod.rs | 2 +- src/unix/newlib/mod.rs | 5 +- src/unix/newlib/zephyr/mod.rs | 211 ++++++++++++++++++++++++++++++++++ 4 files changed, 218 insertions(+), 4 deletions(-) create mode 100644 src/unix/newlib/zephyr/mod.rs diff --git a/Cargo.toml b/Cargo.toml index dd7c11a1102e4..1b48ef406225a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,5 +31,5 @@ const-extern-fn = [] # use_std is deprecated, use `std` instead use_std = ['std'] -[workspace] -members = ["libc-test"] +#[workspace] +#members = ["libc-test"] diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 75d511e3909ea..2a364cdf6a190 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -29,7 +29,7 @@ pub type sighandler_t = ::size_t; pub type cc_t = ::c_uchar; cfg_if! { - if #[cfg(any(target_os = "espidf", target_os = "horizon"))] { + if #[cfg(any(target_os = "espidf", target_os = "horizon", target_os = "zephyr"))] { pub type uid_t = ::c_ushort; pub type gid_t = ::c_ushort; } else if #[cfg(target_os = "nto")] { diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index d46844268f60c..189991ba7a799 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -27,7 +27,7 @@ pub type pthread_key_t = ::c_uint; pub type rlim_t = u32; cfg_if! { - if #[cfg(target_os = "horizon")] { + if #[cfg(any(target_os = "horizon", target_os = "zephyr"))] { pub type sa_family_t = u16; } else { pub type sa_family_t = u8; @@ -730,6 +730,9 @@ cfg_if! { } else if #[cfg(target_os = "horizon")] { mod horizon; pub use self::horizon::*; + } else if #[cfg(target_os = "zephyr")] { + mod zephyr; + pub use self::zephyr::*; } else if #[cfg(target_os = "vita")] { mod vita; pub use self::vita::*; diff --git a/src/unix/newlib/zephyr/mod.rs b/src/unix/newlib/zephyr/mod.rs new file mode 100644 index 0000000000000..68f5fd9fd2f69 --- /dev/null +++ b/src/unix/newlib/zephyr/mod.rs @@ -0,0 +1,211 @@ +pub type c_char = i8; +pub type c_long = i32; +pub type c_ulong = u32; + +pub type wchar_t = ::c_uint; + +// pub type u_char = ::c_uchar; +// pub type u_short = ::c_ushort; +// pub type u_int = ::c_uint; +// pub type u_long = c_ulong; +// pub type ushort = ::c_ushort; +// pub type uint = ::c_uint; +// pub type ulong = c_ulong; +pub type clock_t = c_ulong; +// pub type daddr_t = c_long; +// pub type caddr_t = *mut c_char; +// pub type sbintime_t = ::c_longlong; +// pub type sigset_t = ::c_ulong; + +s! { + pub struct cmsghdr { + pub cmsg_len: ::socklen_t, + pub cmsg_level: ::c_int, + pub cmsg_type: ::c_int, + } + + pub struct msghdr { + pub msg_name: *mut ::c_void, + pub msg_namelen: ::socklen_t, + pub msg_iov: *mut ::iovec, + pub msg_iovlen: ::c_int, + pub msg_control: *mut ::c_void, + pub msg_controllen: ::size_t, + pub msg_flags: ::c_int, + } + + pub struct sockaddr { + pub sa_family: ::sa_family_t, + pub data: [::c_char; NET_SOCKADDR_MAX_SIZE], // previously [:14] + } + + pub struct sockaddr_in6 { + pub sin6_family: ::sa_family_t, + pub sin6_port: ::in_port_t, + pub sin6_addr: ::in6_addr, + pub sin6_scope_id: u8, + } + + pub struct sockaddr_in { + pub sin_family: ::sa_family_t, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, + } + + pub struct sockaddr_storage { + pub ss_family: ::sa_family_t, + pub data: [::c_char; NET_SOCKADDR_MAX_SIZE] + } + + pub struct sockaddr_un { + pub sun_family: ::sa_family_t, + pub sun_path: [::c_char; NET_SOCKADDR_MAX_SIZE] + } +} + +pub const NET_SOCKADDR_MAX_SIZE: size_t = crate::mem::size_of::(); + +pub const PF_UNSPEC: ::c_long = 0; +/**< Unspecified protocol family. */ +pub const PF_INET: ::c_long = 1; +/**< IP protocol family version 4. */ +pub const PF_INET6: ::c_long = 2; +/**< IP protocol family version 6. */ +pub const PF_PACKET: ::c_long = 3; +/**< Packet family. */ +pub const PF_CAN: ::c_long = 4; +/**< Controller Area Network. */ +pub const PF_NET_MGMT: ::c_long = 5; +/**< Network management info. */ +pub const PF_LOCAL: ::c_long = 6; +/**< Inter-process communication */ +pub const PF_UNIX: ::c_long = PF_LOCAL; +/**< Inter-process communication */ + +pub const AF_UNSPEC: ::c_long = PF_UNSPEC; +/**< Unspecified address family. */ +pub const AF_INET: ::c_long = PF_INET; +/**< IP protocol family version 4. */ +pub const AF_INET6: ::c_long = PF_INET6; +/**< IP protocol family version 6. */ +pub const AF_PACKET: ::c_long = PF_PACKET; +/**< Packet family. */ +pub const AF_CAN: ::c_long = PF_CAN; +/**< Controller Area Network. */ +pub const AF_NET_MGMT: ::c_long = PF_NET_MGMT; +/**< Network management info. */ +pub const AF_LOCAL: ::c_long = PF_LOCAL; +/**< Inter-process communication */ +pub const AF_UNIX: ::c_long = PF_UNIX; +/**< Inter-process communication */ + +pub const FIONBIO: ::c_ulong = 2147772030; + +pub const ZSOCK_POLLIN: ::c_short = 0x1; +pub const ZSOCK_POLLPRI: ::c_short = 0x2; +pub const ZSOCK_POLLHUP: ::c_short = 0x4; +pub const ZSOCK_POLLERR: ::c_short = 0x8; +pub const ZSOCK_POLLOUT: ::c_short = 0x10; +pub const ZSOCK_POLLNVAL: ::c_short = 0x20; + +pub const POLLIN: ::c_short = ZSOCK_POLLIN; +pub const POLLPRI: ::c_short = ZSOCK_POLLPRI; +pub const POLLHUP: ::c_short = ZSOCK_POLLHUP; +pub const POLLERR: ::c_short = ZSOCK_POLLERR; +pub const POLLOUT: ::c_short = ZSOCK_POLLOUT; +pub const POLLNVAL: ::c_short = ZSOCK_POLLNVAL; + +pub const _SC_PAGESIZE: ::c_int = 8; +pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51; + +pub const SIGHUP: ::c_int = 1; /* hangup */ +pub const SIGINT: ::c_int = 2; /* interrupt */ +pub const SIGQUIT: ::c_int = 3; /* quit */ +pub const SIGILL: ::c_int = 4; /* illegal instruction (not reset when caught) */ +pub const SIGTRAP: ::c_int = 5; /* trace trap (not reset when caught) */ +pub const SIGIOT: ::c_int = 6; /* IOT instruction */ +pub const SIGABRT: ::c_int = 6; /* used by abort, replace SIGIOT in the future */ +pub const SIGEMT: ::c_int = 7; /* EMT instruction */ +pub const SIGFPE: ::c_int = 8; /* floating point exception */ +pub const SIGKILL: ::c_int = 9; /* kill (cannot be caught or ignored) */ +pub const SIGBUS: ::c_int = 10; /* bus error */ +pub const SIGSEGV: ::c_int = 11; /* segmentation violation */ +pub const SIGSYS: ::c_int = 12; /* bad argument to system call */ +pub const SIGPIPE: ::c_int = 13; /* write on a pipe with no one to read it */ +pub const SIGALRM: ::c_int = 14; /* alarm clock */ +pub const SIGTERM: ::c_int = 15; /* software termination signal from kill */ +pub const SOL_SOCKET: ::c_int = 0xfff; + +pub const ZSOCK_MSG_PEEK: ::c_long = 0x02; +pub const ZSOCK_MSG_TRUNC: ::c_long = 0x20; +pub const ZSOCK_MSG_DONTWAIT: ::c_long = 0x40; +pub const ZSOCK_MSG_WAITALL: ::c_long = 0x100; + +pub const MSG_PEEK: ::c_long = ZSOCK_MSG_PEEK; +pub const MSG_TRUNC: ::c_long = ZSOCK_MSG_TRUNC; +pub const MSG_DONTWAIT: ::c_long = ZSOCK_MSG_DONTWAIT; +pub const MSG_WAITALL: ::c_long = ZSOCK_MSG_WAITALL; + +pub const DNS_EAI_BADFLAGS: ::c_int = -1; +pub const DNS_EAI_NONAME: ::c_int = -2; +pub const DNS_EAI_AGAIN: ::c_int = -3; +pub const DNS_EAI_FAIL: ::c_int = -4; +pub const DNS_EAI_NODATA: ::c_int = -5; +pub const DNS_EAI_FAMILY: ::c_int = -6; +pub const DNS_EAI_SOCKTYPE: ::c_int = -7; +pub const DNS_EAI_SERVICE: ::c_int = -8; +pub const DNS_EAI_ADDRFAMILY: ::c_int = -9; +pub const DNS_EAI_MEMORY: ::c_int = -10; +pub const DNS_EAI_SYSTEM: ::c_int = -11; +pub const DNS_EAI_OVERFLOW: ::c_int = -12; +pub const DNS_EAI_INPROGRESS: ::c_int = -100; +pub const DNS_EAI_CANCELED: ::c_int = -101; +pub const DNS_EAI_NOTCANCELED: ::c_int = -102; +pub const DNS_EAI_ALLDONE: ::c_int = -103; +pub const DNS_EAI_IDN_ENCODE: ::c_int = -105; + +/** POSIX wrapper for @ref DNS_EAI_BADFLAGS */ +pub const EAI_BADFLAGS: ::c_int = DNS_EAI_BADFLAGS; +/** POSIX wrapper for @ref DNS_EAI_NONAME */ +pub const EAI_NONAME: ::c_int = DNS_EAI_NONAME; +/** POSIX wrapper for @ref DNS_EAI_AGAIN */ +pub const EAI_AGAIN: ::c_int = DNS_EAI_AGAIN; +/** POSIX wrapper for @ref DNS_EAI_FAIL */ +pub const EAI_FAIL: ::c_int = DNS_EAI_FAIL; +/** POSIX wrapper for @ref DNS_EAI_NODATA */ +pub const EAI_NODATA: ::c_int = DNS_EAI_NODATA; +/** POSIX wrapper for @ref DNS_EAI_MEMORY */ +pub const EAI_MEMORY: ::c_int = DNS_EAI_MEMORY; +/** POSIX wrapper for @ref DNS_EAI_SYSTEM */ +pub const EAI_SYSTEM: ::c_int = DNS_EAI_SYSTEM; +/** POSIX wrapper for @ref DNS_EAI_SERVICE */ +pub const EAI_SERVICE: ::c_int = DNS_EAI_SERVICE; +/** POSIX wrapper for @ref DNS_EAI_SOCKTYPE */ +pub const EAI_SOCKTYPE: ::c_int = DNS_EAI_SOCKTYPE; +/** POSIX wrapper for @ref DNS_EAI_FAMILY */ +pub const EAI_FAMILY: ::c_int = DNS_EAI_FAMILY; + +pub const PTHREAD_STACK_MIN: ::size_t = 768; + +pub const RTLD_DEFAULT: *mut ::c_void = 0 as *mut ::c_void; + +extern "C" { + pub fn pthread_create( + native: *mut ::pthread_t, + attr: *const ::pthread_attr_t, + f: extern "C" fn(_: *mut ::c_void) -> *mut ::c_void, + value: *mut ::c_void, + ) -> ::c_int; + + // pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t; + // + // #[link_name = "lwip_sendmsg"] + // pub fn sendmsg(s: ::c_int, msg: *const ::msghdr, flags: ::c_int) -> ::ssize_t; + // #[link_name = "lwip_recvmsg"] + // pub fn recvmsg(s: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t; + // + // pub fn eventfd(initval: ::c_uint, flags: ::c_int) -> ::c_int; +} + +pub use crate::unix::newlib::generic::{sigset_t, stat}; +use size_t; From 9fe7b4ed09d96d60612e3df8188b649dca423b17 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Fri, 16 Dec 2022 18:51:55 +0000 Subject: [PATCH 02/10] Tidy up a few type usages to be internally consistent --- src/unix/newlib/zephyr/mod.rs | 51 +++++++++++++++++------------------ 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/src/unix/newlib/zephyr/mod.rs b/src/unix/newlib/zephyr/mod.rs index 68f5fd9fd2f69..2e50b161265b7 100644 --- a/src/unix/newlib/zephyr/mod.rs +++ b/src/unix/newlib/zephyr/mod.rs @@ -63,40 +63,40 @@ s! { } } -pub const NET_SOCKADDR_MAX_SIZE: size_t = crate::mem::size_of::(); +pub const NET_SOCKADDR_MAX_SIZE: ::size_t = crate::mem::size_of::(); -pub const PF_UNSPEC: ::c_long = 0; +pub const PF_UNSPEC: c_long = 0; /**< Unspecified protocol family. */ -pub const PF_INET: ::c_long = 1; +pub const PF_INET: c_long = 1; /**< IP protocol family version 4. */ -pub const PF_INET6: ::c_long = 2; +pub const PF_INET6: c_long = 2; /**< IP protocol family version 6. */ -pub const PF_PACKET: ::c_long = 3; +pub const PF_PACKET: c_long = 3; /**< Packet family. */ -pub const PF_CAN: ::c_long = 4; +pub const PF_CAN: c_long = 4; /**< Controller Area Network. */ -pub const PF_NET_MGMT: ::c_long = 5; +pub const PF_NET_MGMT: c_long = 5; /**< Network management info. */ -pub const PF_LOCAL: ::c_long = 6; +pub const PF_LOCAL: c_long = 6; /**< Inter-process communication */ -pub const PF_UNIX: ::c_long = PF_LOCAL; +pub const PF_UNIX: c_long = PF_LOCAL; /**< Inter-process communication */ -pub const AF_UNSPEC: ::c_long = PF_UNSPEC; +pub const AF_UNSPEC: c_long = PF_UNSPEC; /**< Unspecified address family. */ -pub const AF_INET: ::c_long = PF_INET; +pub const AF_INET: c_long = PF_INET; /**< IP protocol family version 4. */ -pub const AF_INET6: ::c_long = PF_INET6; +pub const AF_INET6: c_long = PF_INET6; /**< IP protocol family version 6. */ -pub const AF_PACKET: ::c_long = PF_PACKET; +pub const AF_PACKET: c_long = PF_PACKET; /**< Packet family. */ -pub const AF_CAN: ::c_long = PF_CAN; +pub const AF_CAN: c_long = PF_CAN; /**< Controller Area Network. */ -pub const AF_NET_MGMT: ::c_long = PF_NET_MGMT; +pub const AF_NET_MGMT: c_long = PF_NET_MGMT; /**< Network management info. */ -pub const AF_LOCAL: ::c_long = PF_LOCAL; +pub const AF_LOCAL: c_long = PF_LOCAL; /**< Inter-process communication */ -pub const AF_UNIX: ::c_long = PF_UNIX; +pub const AF_UNIX: c_long = PF_UNIX; /**< Inter-process communication */ pub const FIONBIO: ::c_ulong = 2147772030; @@ -136,15 +136,15 @@ pub const SIGALRM: ::c_int = 14; /* alarm clock */ pub const SIGTERM: ::c_int = 15; /* software termination signal from kill */ pub const SOL_SOCKET: ::c_int = 0xfff; -pub const ZSOCK_MSG_PEEK: ::c_long = 0x02; -pub const ZSOCK_MSG_TRUNC: ::c_long = 0x20; -pub const ZSOCK_MSG_DONTWAIT: ::c_long = 0x40; -pub const ZSOCK_MSG_WAITALL: ::c_long = 0x100; +pub const ZSOCK_MSG_PEEK: c_long = 0x02; +pub const ZSOCK_MSG_TRUNC: c_long = 0x20; +pub const ZSOCK_MSG_DONTWAIT: c_long = 0x40; +pub const ZSOCK_MSG_WAITALL: c_long = 0x100; -pub const MSG_PEEK: ::c_long = ZSOCK_MSG_PEEK; -pub const MSG_TRUNC: ::c_long = ZSOCK_MSG_TRUNC; -pub const MSG_DONTWAIT: ::c_long = ZSOCK_MSG_DONTWAIT; -pub const MSG_WAITALL: ::c_long = ZSOCK_MSG_WAITALL; +pub const MSG_PEEK: c_long = ZSOCK_MSG_PEEK; +pub const MSG_TRUNC: c_long = ZSOCK_MSG_TRUNC; +pub const MSG_DONTWAIT: c_long = ZSOCK_MSG_DONTWAIT; +pub const MSG_WAITALL: c_long = ZSOCK_MSG_WAITALL; pub const DNS_EAI_BADFLAGS: ::c_int = -1; pub const DNS_EAI_NONAME: ::c_int = -2; @@ -208,4 +208,3 @@ extern "C" { } pub use crate::unix::newlib::generic::{sigset_t, stat}; -use size_t; From 3cc7a9c837e16b956741e770f848be2c12814ae2 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Thu, 23 May 2019 18:13:08 -0400 Subject: [PATCH 03/10] Zephyr OS support --- src/lib.rs | 3 +++ src/zephyr/mod.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 src/zephyr/mod.rs diff --git a/src/lib.rs b/src/lib.rs index d9bd318d1dfb6..7da000ec89b8f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -157,6 +157,9 @@ cfg_if! { mod xous; pub use xous::*; + } else if #[cfg(target_os = "zephyr")] { + mod zephyr; + pub use zephyr::*; } else { // non-supported targets: empty... } diff --git a/src/zephyr/mod.rs b/src/zephyr/mod.rs new file mode 100644 index 0000000000000..8dc8c677cc0bf --- /dev/null +++ b/src/zephyr/mod.rs @@ -0,0 +1,52 @@ +//! Definitions found commonly among almost all Unix derivatives +//! +//! More functions and definitions can be found in the more specific modules +//! according to the platform in question. + +pub type int8_t = i8; +pub type int16_t = i16; +pub type int32_t = i32; +pub type int64_t = i64; +pub type uint8_t = u8; +pub type uint16_t = u16; +pub type uint32_t = u32; +pub type uint64_t = u64; + +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; + +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, + } + } +} From ef7c089fc63bf816dc44558d3f22d7f1c0d0ecc4 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Fri, 24 May 2019 15:34:56 -0400 Subject: [PATCH 04/10] zephyr: add c_char --- src/zephyr/mod.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/zephyr/mod.rs b/src/zephyr/mod.rs index 8dc8c677cc0bf..70b6b38c77114 100644 --- a/src/zephyr/mod.rs +++ b/src/zephyr/mod.rs @@ -12,6 +12,10 @@ pub type uint16_t = u16; pub type uint32_t = u32; pub type uint64_t = u64; +#[cfg(target_arch = "aarch64")] +pub type c_char = u8; +#[cfg(not(target_arch = "aarch64"))] +pub type c_char = i8; pub type c_schar = i8; pub type c_uchar = u8; pub type c_short = i16; From 2cc492517659a8cfab2870a936b06f2fc04509ce Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Fri, 24 May 2019 15:34:59 -0400 Subject: [PATCH 05/10] zephyr: add basic string/mem functions --- src/zephyr/mod.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/zephyr/mod.rs b/src/zephyr/mod.rs index 70b6b38c77114..40da4180cc8db 100644 --- a/src/zephyr/mod.rs +++ b/src/zephyr/mod.rs @@ -54,3 +54,15 @@ cfg_if! { } } } + +extern { + pub fn strlen(cs: *const c_char) -> size_t; + + pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; + pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; + pub fn memcpy(dest: *mut c_void, src: *const c_void, + n: size_t) -> *mut c_void; + pub fn memmove(dest: *mut c_void, src: *const c_void, + n: size_t) -> *mut c_void; + pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; +} From a3701d9cce1e05b4e3d672bf53c5cf679bb0b9c7 Mon Sep 17 00:00:00 2001 From: Tyler Hall Date: Tue, 28 May 2019 23:37:02 -0400 Subject: [PATCH 06/10] zephyr: add long and ulong --- src/zephyr/mod.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/zephyr/mod.rs b/src/zephyr/mod.rs index 40da4180cc8db..ab3c1733c1a38 100644 --- a/src/zephyr/mod.rs +++ b/src/zephyr/mod.rs @@ -22,12 +22,20 @@ 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; +#[cfg(target_pointer_width = "32")] +pub type c_long = i32; +#[cfg(target_pointer_width = "32")] +pub type c_ulong = u32; +#[cfg(target_pointer_width = "64")] +pub type c_long = i64; +#[cfg(target_pointer_width = "64")] +pub type c_ulong = u64; pub type c_longlong = i64; pub type c_ulonglong = u64; pub type intmax_t = i64; pub type uintmax_t = u64; +pub type c_float = f32; +pub type c_double = f64; pub type size_t = usize; pub type ptrdiff_t = isize; From ddeab6d4b72686cc2cc5be0fd9b256e275f73032 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Thu, 16 Mar 2023 23:10:16 +0000 Subject: [PATCH 07/10] Fix a compilation warning with zephyr due to unused consts (may be used at application level) --- src/unix/newlib/zephyr/mod.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/unix/newlib/zephyr/mod.rs b/src/unix/newlib/zephyr/mod.rs index 2e50b161265b7..04eba27291f98 100644 --- a/src/unix/newlib/zephyr/mod.rs +++ b/src/unix/newlib/zephyr/mod.rs @@ -1,3 +1,5 @@ +#![allow(dead_code)] + pub type c_char = i8; pub type c_long = i32; pub type c_ulong = u32; From 81d20cd8c02427c19f7dadfeb3f979f11a6a6dfb Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sun, 2 Apr 2023 16:33:43 +0100 Subject: [PATCH 08/10] Revert accidentally disabling workspace members in 170ea221 --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b48ef406225a..dd7c11a1102e4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,5 +31,5 @@ const-extern-fn = [] # use_std is deprecated, use `std` instead use_std = ['std'] -#[workspace] -#members = ["libc-test"] +[workspace] +members = ["libc-test"] From c4d6eab5727d4fcbec18080233f29939a7800ffd Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sun, 2 Apr 2023 18:22:35 +0100 Subject: [PATCH 09/10] Fix a few ci/style.rs issues. --- src/zephyr/mod.rs | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/src/zephyr/mod.rs b/src/zephyr/mod.rs index ab3c1733c1a38..8ca21fdceb848 100644 --- a/src/zephyr/mod.rs +++ b/src/zephyr/mod.rs @@ -12,24 +12,28 @@ pub type uint16_t = u16; pub type uint32_t = u32; pub type uint64_t = u64; -#[cfg(target_arch = "aarch64")] -pub type c_char = u8; -#[cfg(not(target_arch = "aarch64"))] -pub type c_char = i8; +cfg_if::cfg_if! { + if #[cfg(target_arch = "aarch64")] { + pub type c_char = u8; + } else { + pub type c_char = i8; + } +} 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; -#[cfg(target_pointer_width = "32")] -pub type c_long = i32; -#[cfg(target_pointer_width = "32")] -pub type c_ulong = u32; -#[cfg(target_pointer_width = "64")] -pub type c_long = i64; -#[cfg(target_pointer_width = "64")] -pub type c_ulong = u64; +cfg_if::cfg_if! { + if #[cfg(target_pointer_width = "32")] { + pub type c_long = i32; + pub type c_ulong = u32; + } else if #[cfg(target_pointer_width = "64")] { + pub type c_long = i64; + pub type c_ulong = u64; + } +} pub type c_longlong = i64; pub type c_ulonglong = u64; pub type intmax_t = i64; @@ -63,14 +67,12 @@ cfg_if! { } } -extern { +extern "C" { pub fn strlen(cs: *const c_char) -> size_t; pub fn memchr(cx: *const c_void, c: c_int, n: size_t) -> *mut c_void; pub fn memcmp(cx: *const c_void, ct: *const c_void, n: size_t) -> c_int; - pub fn memcpy(dest: *mut c_void, src: *const c_void, - n: size_t) -> *mut c_void; - pub fn memmove(dest: *mut c_void, src: *const c_void, - n: size_t) -> *mut c_void; + pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; + pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void; pub fn memset(dest: *mut c_void, c: c_int, n: size_t) -> *mut c_void; } From e370d84c9c06be2d90537dd8213f19caca335699 Mon Sep 17 00:00:00 2001 From: Tom Price Date: Sat, 6 May 2023 18:30:44 +0100 Subject: [PATCH 10/10] Fix cfg_if! macro usage --- src/zephyr/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/zephyr/mod.rs b/src/zephyr/mod.rs index 8ca21fdceb848..71eded2fbd48e 100644 --- a/src/zephyr/mod.rs +++ b/src/zephyr/mod.rs @@ -12,7 +12,7 @@ pub type uint16_t = u16; pub type uint32_t = u32; pub type uint64_t = u64; -cfg_if::cfg_if! { +cfg_if! { if #[cfg(target_arch = "aarch64")] { pub type c_char = u8; } else { @@ -25,7 +25,7 @@ pub type c_short = i16; pub type c_ushort = u16; pub type c_int = i32; pub type c_uint = u32; -cfg_if::cfg_if! { +cfg_if! { if #[cfg(target_pointer_width = "32")] { pub type c_long = i32; pub type c_ulong = u32;