diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 13a27f8cb01f..46df3bf74891 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -25,6 +25,7 @@ cfg_if! { if #[cfg(any( target_os = "espidf", target_os = "horizon", + target_os = "rtems", target_os = "vita" ))] { pub type uid_t = c_ushort; @@ -90,12 +91,14 @@ s2! { __pad0: Padding, } + #[cfg(not(target_os = "rtems"))] #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rlimit { pub rlim_cur: rlim_t, pub rlim_max: rlim_t, } + #[cfg(not(target_os = "rtems"))] #[exhaustive] // FIXME(exhaustive): review for 1.0 pub struct rusage { pub ru_utime: timeval, @@ -314,7 +317,8 @@ cfg_if! { target_os = "nto", target_os = "qnx", target_os = "l4re", - target_os = "hurd" + target_os = "hurd", + target_os = "rtems" )))] { pub const USRQUOTA: c_int = 0; pub const GRPQUOTA: c_int = 1; @@ -379,7 +383,11 @@ pub const LOG_PRIMASK: c_int = 7; pub const LOG_FACMASK: c_int = 0x3f8; cfg_if! { - if #[cfg(not(any(target_os = "nto", target_os = "qnx")))] { + if #[cfg(not(any( + target_os = "nto", + target_os = "qnx", + target_os = "rtems" + )))] { pub const PRIO_MIN: c_int = -20; pub const PRIO_MAX: c_int = 20; } @@ -452,6 +460,7 @@ cfg_if! { target_os = "openbsd", target_os = "cygwin", target_os = "netbsd", + target_os = "rtems", ))] { pub const FNM_PATHNAME: c_int = 1 << 1; } else { @@ -468,6 +477,7 @@ cfg_if! { target_os = "openbsd", target_os = "netbsd", target_os = "cygwin", + target_os = "rtems", ))] { pub const FNM_NOESCAPE: c_int = 1 << 0; } else if #[cfg(any(target_os = "nto", target_os = "qnx"))] { @@ -646,6 +656,9 @@ cfg_if! { #[link(name = "root")] #[link(name = "network")] extern "C" {} + } else if #[cfg(target_os = "rtems")] { + #[link(name = "m")] + extern "C" {} } else if #[cfg(target_env = "newlib")] { #[link(name = "c")] #[link(name = "m")] @@ -1025,6 +1038,7 @@ extern "C" { #[cfg_attr(musl_redir_time64, link_name = "__stat_time64")] pub fn stat(path: *const c_char, buf: *mut stat) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn pclose(stream: *mut crate::FILE) -> c_int; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), @@ -1102,9 +1116,10 @@ extern "C" { )] pub fn rewinddir(dirp: *mut crate::DIR); + #[cfg(not(target_os = "rtems"))] pub fn fchmodat(dirfd: c_int, pathname: *const c_char, mode: mode_t, flags: c_int) -> c_int; pub fn fchown(fd: c_int, owner: crate::uid_t, group: crate::gid_t) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn fchownat( dirfd: c_int, pathname: *const c_char, @@ -1112,6 +1127,7 @@ extern "C" { group: crate::gid_t, flags: c_int, ) -> c_int; + #[cfg(not(target_os = "rtems"))] #[cfg_attr(gnu_file_offset_bits64, link_name = "openat64")] pub fn openat(dirfd: c_int, pathname: *const c_char, flags: c_int, ...) -> c_int; #[cfg_attr( @@ -1127,10 +1143,10 @@ extern "C" { all(not(gnu_time_bits64), gnu_file_offset_bits64), link_name = "fstatat64" )] - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] #[cfg_attr(musl_redir_time64, link_name = "__fstatat_time64")] pub fn fstatat(dirfd: c_int, pathname: *const c_char, buf: *mut stat, flags: c_int) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn linkat( olddirfd: c_int, oldpath: *const c_char, @@ -1138,18 +1154,18 @@ extern "C" { newpath: *const c_char, flags: c_int, ) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn mkdirat(dirfd: c_int, pathname: *const c_char, mode: mode_t) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn renameat( olddirfd: c_int, oldpath: *const c_char, newdirfd: c_int, newpath: *const c_char, ) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn symlinkat(target: *const c_char, newdirfd: c_int, linkpath: *const c_char) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn unlinkat(dirfd: c_int, pathname: *const c_char, flags: c_int) -> c_int; pub fn access(path: *const c_char, amode: c_int) -> c_int; @@ -1204,6 +1220,7 @@ extern "C" { link_name = "getopt$UNIX2003" )] pub fn getopt(argc: c_int, argv: *const *mut c_char, optstr: *const c_char) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn getpgid(pid: pid_t) -> pid_t; pub fn getpgrp() -> pid_t; pub fn getpid() -> pid_t; @@ -1235,7 +1252,9 @@ extern "C" { pub fn setpgid(pid: pid_t, pgid: pid_t) -> c_int; pub fn setsid() -> pid_t; pub fn setuid(uid: uid_t) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn setreuid(ruid: uid_t, euid: uid_t) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn setregid(rgid: gid_t, egid: gid_t) -> c_int; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), @@ -1301,6 +1320,7 @@ extern "C" { link_name = "kill$UNIX2003" )] pub fn kill(pid: pid_t, sig: c_int) -> c_int; + #[cfg(not(target_os = "rtems"))] #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "killpg$UNIX2003" @@ -1617,7 +1637,7 @@ extern "C" { #[cfg_attr(any(gnu_time_bits64, musl_redir_time64), link_name = "__difftime64")] #[cfg_attr(not(musl32_time64), allow(deprecated))] pub fn difftime(time1: time_t, time0: time_t) -> c_double; - #[cfg(not(target_os = "aix"))] + #[cfg(not(any(target_os = "aix", target_os = "rtems")))] #[cfg_attr(target_os = "netbsd", link_name = "__timegm50")] #[cfg_attr(gnu_time_bits64, link_name = "__timegm64")] #[cfg_attr(not(musl32_time64), allow(deprecated))] @@ -1703,6 +1723,7 @@ extern "C" { #[cfg(not(all(target_os = "linux", target_env = "gnu")))] // defined in new/glibc #[cfg_attr(gnu_file_offset_bits64, link_name = "statvfs64")] pub fn statvfs(path: *const c_char, buf: *mut crate::statvfs) -> c_int; + #[cfg(not(target_os = "rtems"))] #[cfg(not(all(target_os = "linux", target_env = "gnu")))] // defined in new/glibc #[cfg_attr(gnu_file_offset_bits64, link_name = "fstatvfs64")] pub fn fstatvfs(fd: c_int, buf: *mut crate::statvfs) -> c_int; @@ -2185,6 +2206,7 @@ extern "C" { pub fn tcsetattr(fd: c_int, optional_actions: c_int, termios: *const crate::termios) -> c_int; pub fn tcflow(fd: c_int, action: c_int) -> c_int; pub fn tcflush(fd: c_int, action: c_int) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn tcgetsid(fd: c_int) -> crate::pid_t; pub fn tcsendbreak(fd: c_int, duration: c_int) -> c_int; #[cfg_attr(gnu_file_offset_bits64, link_name = "mkstemp64")] @@ -2202,25 +2224,28 @@ extern "C" { pub fn setlogmask(maskpri: c_int) -> c_int; #[cfg_attr(target_os = "macos", link_name = "syslog$DARWIN_EXTSN")] pub fn syslog(priority: c_int, message: *const c_char, ...); + #[cfg(not(target_os = "rtems"))] #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "nice$UNIX2003" )] pub fn nice(incr: c_int) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn grantpt(fd: c_int) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn posix_openpt(flags: c_int) -> c_int; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn ptsname(fd: c_int) -> *mut c_char; - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn unlockpt(fd: c_int) -> c_int; #[cfg(not(target_os = "aix"))] pub fn strcasestr(cs: *const c_char, ct: *const c_char) -> *mut c_char; + #[cfg(not(target_os = "rtems"))] pub fn getline(lineptr: *mut *mut c_char, n: *mut size_t, stream: *mut FILE) -> ssize_t; + #[cfg(not(target_os = "rtems"))] #[cfg_attr(gnu_file_offset_bits64, link_name = "lockf64")] pub fn lockf(fd: c_int, cmd: c_int, len: off_t) -> c_int; @@ -2291,7 +2316,7 @@ cfg_if! { } cfg_if! { - if #[cfg(not(target_os = "aix"))] { + if #[cfg(not(any(target_os = "aix", target_os = "rtems")))] { extern "C" { pub fn dladdr(addr: *const c_void, info: *mut Dl_info) -> c_int; } @@ -2299,7 +2324,11 @@ cfg_if! { } cfg_if! { - if #[cfg(not(any(target_os = "solaris", target_os = "espidf")))] { + if #[cfg(not(any( + target_os = "solaris", + target_os = "espidf", + target_os = "rtems" + )))] { extern "C" { pub fn flock(fd: c_int, operation: c_int) -> c_int; } @@ -2317,6 +2346,7 @@ cfg_if! { cfg_if! { if #[cfg(not(target_os = "redox"))] { extern "C" { + #[cfg(not(target_os = "rtems"))] pub fn getsid(pid: pid_t) -> pid_t; #[cfg_attr( all(target_os = "macos", any(target_arch = "x86", target_arch = "x86_64")), @@ -2371,7 +2401,7 @@ cfg_if! { } } else { extern "C" { - #[cfg(not(target_os = "l4re"))] + #[cfg(not(any(target_os = "l4re", target_os = "rtems")))] pub fn readlinkat( dirfd: c_int, pathname: *const c_char, diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index b0cdf3609ef5..3781b7491bc8 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -33,6 +33,7 @@ pub type fsblkcnt_t = u64; pub type fsfilcnt_t = u32; pub type id_t = u32; pub type key_t = c_int; +#[cfg(not(target_os = "rtems"))] pub type loff_t = c_longlong; pub type mode_t = c_uint; pub type nfds_t = u32; @@ -166,6 +167,7 @@ s! { // FIXME(1.0): This should not implement `PartialEq` #[allow(unpredictable_function_pointer_comparisons)] + #[cfg(not(target_os = "rtems"))] pub struct sigaction { pub sa_handler: extern "C" fn(arg1: c_int), pub sa_mask: sigset_t, @@ -189,11 +191,14 @@ s! { pub pw_passwd: *mut c_char, pub pw_uid: crate::uid_t, pub pw_gid: crate::gid_t, + #[cfg(target_os = "rtems")] + pub pw_comment: *mut c_char, pub pw_gecos: *mut c_char, pub pw_dir: *mut c_char, pub pw_shell: *mut c_char, } + #[cfg(not(target_os = "rtems"))] pub struct termios { // Unverified pub c_iflag: crate::tcflag_t, @@ -209,11 +214,16 @@ s! { pub c_ospeed: u32, } + #[cfg_attr(target_os = "rtems", repr(align(4)))] pub struct sem_t { // Unverified + #[cfg(not(target_os = "rtems"))] __size: [c_char; 16], + #[cfg(target_os = "rtems")] + __size: [c_char; 28], } + #[cfg(not(target_os = "rtems"))] pub struct Dl_info { // Unverified pub dli_fname: *const c_char, @@ -222,6 +232,7 @@ s! { pub dli_saddr: *mut c_void, } + #[cfg(not(target_os = "rtems"))] pub struct utsname { // Unverified pub sysname: [c_char; 65], @@ -234,9 +245,13 @@ s! { pub struct cpu_set_t { // Unverified + #[cfg(not(target_os = "rtems"))] bits: [u32; 32], + #[cfg(target_os = "rtems")] + bits: [c_long; 1], } + #[cfg_attr(target_os = "rtems", repr(align(8)))] pub struct pthread_attr_t { // Unverified #[cfg(not(target_os = "espidf"))] @@ -259,7 +274,7 @@ s! { pub detachstate: i32, } - #[cfg_attr(target_os = "espidf", repr(align(4)))] + #[cfg_attr(any(target_os = "espidf", target_os = "rtems"), repr(align(4)))] pub struct pthread_rwlockattr_t { // Unverified __size: [u8; __SIZEOF_PTHREAD_RWLOCKATTR_T], @@ -270,7 +285,8 @@ s! { target_os = "espidf", all( target_pointer_width = "32", - any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc") + any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc"), + not(target_os = "rtems") ) ), repr(align(4)) @@ -280,7 +296,8 @@ s! { not(target_os = "espidf"), any( target_pointer_width = "64", - not(any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc")) + not(any(target_arch = "mips", target_arch = "arm", target_arch = "powerpc")), + target_os = "rtems" ) ), repr(align(8)) @@ -342,14 +359,15 @@ s! { size: [u8; crate::__SIZEOF_PTHREAD_MUTEXATTR_T], } - #[cfg_attr(target_os = "espidf", repr(align(4)))] - #[cfg_attr(not(target_os = "espidf"), repr(align(8)))] + #[cfg_attr(any(target_os = "espidf", target_os = "rtems"), repr(align(4)))] + #[cfg_attr(not(any(target_os = "espidf", target_os = "rtems")), repr(align(8)))] pub struct pthread_cond_t { // Unverified size: [u8; crate::__SIZEOF_PTHREAD_COND_T], } - #[repr(align(4))] + #[cfg_attr(target_os = "rtems", repr(align(8)))] + #[cfg_attr(not(target_os = "rtems"), repr(align(4)))] pub struct pthread_condattr_t { // Unverified size: [u8; crate::__SIZEOF_PTHREAD_CONDATTR_T], @@ -375,10 +393,11 @@ s! { pub st_ctim: crate::timespec, pub st_blksize: crate::blksize_t, pub st_blocks: crate::blkcnt_t, + #[cfg(not(target_os = "rtems"))] st_spare4: Padding<[c_long; 2usize]>, } - #[cfg(not(target_os = "vita"))] + #[cfg(not(any(target_os = "rtems", target_os = "vita")))] pub struct dirent { pub d_ino: crate::ino_t, pub d_type: c_uchar, @@ -631,6 +650,7 @@ pub const S_IROTH: mode_t = 0o0004; pub const S_IWOTH: mode_t = 0o0002; pub const S_IXOTH: mode_t = 0o0001; +#[cfg(not(target_os = "rtems"))] pub const SOL_TCP: c_int = 6; pub const PF_UNSPEC: c_int = 0; @@ -650,6 +670,7 @@ pub const AF_INET: c_int = 2; pub const CLOCK_REALTIME: crate::clockid_t = 1; pub const CLOCK_MONOTONIC: crate::clockid_t = 4; +#[cfg(not(target_os = "rtems"))] pub const CLOCK_BOOTTIME: crate::clockid_t = 4; pub const SOCK_STREAM: c_int = 1; @@ -717,6 +738,7 @@ pub const IFF_BROADCAST: c_int = 0x2; // broadcast address valid pub const IFF_DEBUG: c_int = 0x4; // turn on debugging pub const IFF_LOOPBACK: c_int = 0x8; // is a loopback net pub const IFF_POINTOPOINT: c_int = 0x10; // interface is point-to-point link +#[cfg(not(target_os = "rtems"))] pub const IFF_NOTRAILERS: c_int = 0x20; // avoid use of trailers pub const IFF_RUNNING: c_int = 0x40; // resources allocated pub const IFF_NOARP: c_int = 0x80; // no address resolution protocol @@ -815,7 +837,9 @@ cfg_if! { pub const IPV6_V6ONLY: c_int = 27; pub const IPV6_JOIN_GROUP: c_int = 12; pub const IPV6_LEAVE_GROUP: c_int = 13; +#[cfg(not(target_os = "rtems"))] pub const IPV6_ADD_MEMBERSHIP: c_int = 12; +#[cfg(not(target_os = "rtems"))] pub const IPV6_DROP_MEMBERSHIP: c_int = 13; cfg_if! { @@ -898,8 +922,11 @@ cfg_if! { pub const EXIT_SUCCESS: c_int = 0; pub const EXIT_FAILURE: c_int = 1; +#[cfg(not(target_os = "rtems"))] pub const PRIO_PROCESS: c_int = 0; +#[cfg(not(target_os = "rtems"))] pub const PRIO_PGRP: c_int = 1; +#[cfg(not(target_os = "rtems"))] pub const PRIO_USER: c_int = 2; // include/paths.h from newlib's libc @@ -939,8 +966,11 @@ f! { } extern "C" { + #[cfg(not(target_os = "rtems"))] pub fn __errno() -> *mut c_int; + #[cfg(not(target_os = "rtems"))] pub fn getrlimit(resource: c_int, rlim: *mut crate::rlimit) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn setrlimit(resource: c_int, rlim: *const crate::rlimit) -> c_int; #[cfg_attr( @@ -963,6 +993,7 @@ extern "C" { pub fn clock_settime(clock_id: crate::clockid_t, tp: *const crate::timespec) -> c_int; pub fn clock_gettime(clock_id: crate::clockid_t, tp: *mut crate::timespec) -> c_int; pub fn clock_getres(clock_id: crate::clockid_t, res: *mut crate::timespec) -> c_int; + #[cfg(not(target_os = "rtems"))] #[cfg_attr(target_os = "espidf", link_name = "lwip_close")] pub fn closesocket(sockfd: c_int) -> c_int; pub fn ioctl(fd: c_int, request: c_ulong, ...) -> c_int; @@ -987,6 +1018,7 @@ extern "C" { flags: c_int, ) -> c_int; pub fn memalign(align: size_t, size: size_t) -> *mut c_void; + #[cfg(not(target_os = "rtems"))] pub fn fexecve(fd: c_int, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int; pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut c_void) -> c_int; pub fn getgrgid_r( @@ -996,8 +1028,10 @@ extern "C" { buflen: size_t, result: *mut *mut crate::group, ) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn sigaltstack(ss: *const stack_t, oss: *mut stack_t) -> c_int; pub fn sem_close(sem: *mut sem_t) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn getdtablesize() -> c_int; pub fn getgrnam_r( name: *const c_char, @@ -1011,6 +1045,7 @@ extern "C" { pub fn getgrnam(name: *const c_char) -> *mut crate::group; pub fn pthread_kill(thread: crate::pthread_t, sig: c_int) -> c_int; pub fn sem_unlink(name: *const c_char) -> c_int; + #[cfg(not(target_os = "rtems"))] pub fn daemon(nochdir: c_int, noclose: c_int) -> c_int; pub fn getpwnam_r( name: *const c_char, @@ -1033,6 +1068,7 @@ extern "C" { child: Option, ) -> c_int; pub fn getgrgid(gid: crate::gid_t) -> *mut crate::group; + #[cfg(not(target_os = "rtems"))] pub fn popen(command: *const c_char, mode: *const c_char) -> *mut crate::FILE; pub fn uname(buf: *mut crate::utsname) -> c_int; } diff --git a/src/unix/newlib/rtems/mod.rs b/src/unix/newlib/rtems/mod.rs index 71405e2c3a94..b6c1537ac4d1 100644 --- a/src/unix/newlib/rtems/mod.rs +++ b/src/unix/newlib/rtems/mod.rs @@ -42,6 +42,49 @@ s! { __ss_align: i64, __ss_pad2: Padding<[u8; 112]>, } + + // FIXME(1.0): This should not implement `PartialEq` + #[allow(unpredictable_function_pointer_comparisons)] + pub struct sigaction { + pub sa_flags: c_int, + pub sa_mask: crate::sigset_t, + pub sa_handler: extern "C" fn(arg1: c_int), + } + + pub struct termios { + pub c_iflag: crate::tcflag_t, + pub c_oflag: crate::tcflag_t, + pub c_cflag: crate::tcflag_t, + pub c_lflag: crate::tcflag_t, + pub c_cc: [crate::cc_t; crate::NCCS], + pub c_ispeed: crate::speed_t, + pub c_ospeed: crate::speed_t, + } + + pub struct dirent { + pub d_ino: crate::ino_t, + pub d_off: crate::off_t, + pub d_reclen: u16, + pub d_type: u8, + pub d_namlen: u16, + pub d_name: [c_char; 256], + } + + pub struct utsname { + pub sysname: [c_char; 48], + pub nodename: [c_char; 48], + pub release: [c_char; 48], + pub version: [c_char; 48], + pub machine: [c_char; 48], + } +} + +s2! { + #[exhaustive] // FIXME(exhaustive): review for 1.0 + pub struct rusage { + pub ru_utime: crate::timeval, + pub ru_stime: crate::timeval, + } } pub const AF_UNIX: c_int = 1; @@ -64,7 +107,6 @@ pub const MSG_DONTROUTE: c_int = 0x4; pub const MSG_WAITALL: c_int = 0x40; pub const MSG_DONTWAIT: c_int = 0x80; pub const MSG_NOSIGNAL: c_int = 0x20000; -pub const MSG_MORE: c_int = 0; pub const RTLD_DEFAULT: *mut c_void = -2isize as *mut c_void; @@ -79,6 +121,8 @@ pub const AT_SYMLINK_NOFOLLOW: c_int = 2; pub const AT_SYMLINK_FOLLOW: c_int = 4; pub const AT_REMOVEDIR: c_int = 8; +pub const CLOCK_BOOTTIME: crate::clockid_t = 7; + // signal.h pub const SIG_BLOCK: c_int = 1; pub const SIG_UNBLOCK: c_int = 2; @@ -116,11 +160,6 @@ pub const SIGRTMIN: c_int = 27; /// for details. pub const SIGRTMAX: c_int = 31; -pub const SIGXCPU: c_int = 24; -pub const SIGXFSZ: c_int = 25; -pub const SIGVTALRM: c_int = 26; -pub const SIGPROF: c_int = 27; - pub const SA_NOCLDSTOP: c_ulong = 0x00000001; pub const SA_SIGINFO: c_ulong = 0x00000002; pub const SA_ONSTACK: c_ulong = 0x00000004;