From f0422d50255641c0caec48556e65e1e9b82994b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafael=20=C3=81vila=20de=20Esp=C3=ADndola?= Date: Fri, 24 May 2024 15:17:34 +0000 Subject: [PATCH 1/6] Add iopl/ioperm to musl x86_64 Note that I think this is available on more than x86_64, but that is all that I have to test. This also matches what was done for glibc systems. (backport ) (cherry picked from commit 083499ae1ea8e9a8cc91515ec08f9e5746378a9f) --- libc-test/semver/linux-i686.txt | 2 ++ libc-test/semver/linux-x86_64.txt | 2 ++ src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs | 2 -- src/unix/linux_like/linux/mod.rs | 10 ++++++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libc-test/semver/linux-i686.txt b/libc-test/semver/linux-i686.txt index 2f40472dcfaeb..73d4ca3554321 100644 --- a/libc-test/semver/linux-i686.txt +++ b/libc-test/semver/linux-i686.txt @@ -214,6 +214,8 @@ fsblkcnt64_t fsfilcnt64_t getcontext greg_t +ioperm +iopl makecontext max_align_t mcontext_t diff --git a/libc-test/semver/linux-x86_64.txt b/libc-test/semver/linux-x86_64.txt index c8a509c215085..a26f63d6d5a6c 100644 --- a/libc-test/semver/linux-x86_64.txt +++ b/libc-test/semver/linux-x86_64.txt @@ -139,6 +139,8 @@ TIOCGRS485 TIOCSBRK TIOCSRS485 greg_t +ioperm +iopl max_align_t mcontext_t ucontext_t diff --git a/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs b/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs index 609c74429c5bc..f66eb0409c596 100644 --- a/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs +++ b/src/unix/linux_like/linux/gnu/b64/x86_64/mod.rs @@ -802,8 +802,6 @@ extern "C" { pub fn setcontext(ucp: *const ucontext_t) -> ::c_int; pub fn makecontext(ucp: *mut ucontext_t, func: extern "C" fn(), argc: ::c_int, ...); pub fn swapcontext(uocp: *mut ucontext_t, ucp: *const ucontext_t) -> ::c_int; - pub fn iopl(level: ::c_int) -> ::c_int; - pub fn ioperm(from: ::c_ulong, num: ::c_ulong, turn_on: ::c_int) -> ::c_int; } cfg_if! { diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 3ca4446e66ef1..7df3a953c293b 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -1556,6 +1556,16 @@ cfg_if! { } } +cfg_if! { + if #[cfg(all(any(target_env = "gnu", target_env = "musl", target_env = "ohos"), + any(target_arch = "x86_64", target_arch = "x86")))] { + extern "C" { + pub fn iopl(level: ::c_int) -> ::c_int; + pub fn ioperm(from: ::c_ulong, num: ::c_ulong, turn_on: ::c_int) -> ::c_int; + } + } +} + cfg_if! { if #[cfg(any(target_env = "gnu", target_env = "musl", target_env = "ohos"))] { pub const ABDAY_1: ::nl_item = 0x20000; From a3cbf5f08bccefbe1a04bc79e45dd30a24cd175c Mon Sep 17 00:00:00 2001 From: Nathaniel Date: Fri, 6 Sep 2024 16:11:20 -0400 Subject: [PATCH 2/6] Apple: Add additional `pthread` APIs (backport ) (cherry picked from commit 7b0b1a821c494e310c3027394341a286a1fb4831) --- libc-test/semver/apple.txt | 26 +++++++++++++++++++ src/unix/bsd/apple/b32/mod.rs | 35 ++++++++++++++++++++++++++ src/unix/bsd/apple/b64/mod.rs | 35 ++++++++++++++++++++++++++ src/unix/bsd/apple/mod.rs | 47 +++++++++++++++++++++++++++++++++++ 4 files changed, 143 insertions(+) diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 89b5cca443395..b528a1c64350c 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1116,16 +1116,29 @@ PROC_CSM_TECS PROC_PIDTASKALLINFO PROC_PIDTASKINFO PROC_PIDTHREADINFO +PTHREAD_CANCEL_ASYNCHRONOUS +PTHREAD_CANCEL_DEFERRED +PTHREAD_CANCEL_DISABLE +PTHREAD_CANCEL_ENABLE +PTHREAD_CANCELED PTHREAD_CREATE_DETACHED PTHREAD_CREATE_JOINABLE +PTHREAD_EXPLICIT_SCHED +PTHREAD_INHERIT_SCHED PTHREAD_INTROSPECTION_THREAD_CREATE PTHREAD_INTROSPECTION_THREAD_DESTROY PTHREAD_INTROSPECTION_THREAD_START PTHREAD_INTROSPECTION_THREAD_TERMINATE PTHREAD_MUTEX_DEFAULT PTHREAD_MUTEX_ERRORCHECK +PTHREAD_ONCE_INIT +PTHREAD_PRIO_INHERIT +PTHREAD_PRIO_NONE +PTHREAD_PRIO_PROTECT PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_SHARED +PTHREAD_SCOPE_PROCESS +PTHREAD_SCOPE_SYSTEM PTHREAD_STACK_MIN PT_ATTACH PT_ATTACHEXC @@ -1832,6 +1845,7 @@ _WSTOPPED __PTHREAD_CONDATTR_SIZE__ __PTHREAD_COND_SIZE__ __PTHREAD_MUTEX_SIZE__ +__PTHREAD_ONCE_SIZE__ __PTHREAD_RWLOCKATTR_SIZE__ __PTHREAD_RWLOCK_SIZE__ __darwin_mcontext64 @@ -2142,8 +2156,18 @@ pseudo_AF_KEY pseudo_AF_PIP pseudo_AF_RTIP pseudo_AF_XTP +pthread_atfork +pthread_attr_getdetachstate +pthread_attr_getinheritsched pthread_attr_getschedparam +pthread_attr_getschedpolicy +pthread_attr_getscope +pthread_attr_getstackaddr +pthread_attr_setinheritsched pthread_attr_setschedparam +pthread_attr_setschedpolicy +pthread_attr_setscope +pthread_attr_setstackaddr pthread_cancel pthread_condattr_getpshared pthread_condattr_setpshared @@ -2167,6 +2191,8 @@ pthread_kill pthread_main_np pthread_mutexattr_getpshared pthread_mutexattr_setpshared +pthread_once +pthread_once_t pthread_rwlockattr_getpshared pthread_rwlockattr_setpshared pthread_setname_np diff --git a/src/unix/bsd/apple/b32/mod.rs b/src/unix/bsd/apple/b32/mod.rs index 0f1722f975744..4e45459c18101 100644 --- a/src/unix/bsd/apple/b32/mod.rs +++ b/src/unix/bsd/apple/b32/mod.rs @@ -54,6 +54,11 @@ s_no_extra_traits! { __sig: c_long, __opaque: [::c_char; 36] } + + pub struct pthread_once_t { + __sig: c_long, + __opaque: [::c_char; ::__PTHREAD_ONCE_SIZE__], + } } cfg_if! { @@ -82,6 +87,29 @@ cfg_if! { self.__opaque.hash(state); } } + impl PartialEq for pthread_once_t { + fn eq(&self, other: &pthread_once_t) -> bool { + self.__sig == other.__sig + && self.__opaque + .iter() + .zip(other.__opaque.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_once_t {} + impl ::fmt::Debug for pthread_once_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_once_t") + .field("__sig", &self.__sig) + .finish() + } + } + impl ::hash::Hash for pthread_once_t { + fn hash(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } + } } } @@ -92,6 +120,7 @@ pub const NET_RT_MAXID: ::c_int = 10; pub const __PTHREAD_MUTEX_SIZE__: usize = 40; pub const __PTHREAD_COND_SIZE__: usize = 24; pub const __PTHREAD_CONDATTR_SIZE__: usize = 4; +pub const __PTHREAD_ONCE_SIZE__: usize = 4; pub const __PTHREAD_RWLOCK_SIZE__: usize = 124; pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 12; @@ -103,6 +132,12 @@ pub const BIOCSRTIMEOUT: ::c_ulong = 0x8008426d; pub const BIOCGRTIMEOUT: ::c_ulong = 0x4008426e; pub const BIOCSETFNR: ::c_ulong = 0x8008427e; +const _PTHREAD_ONCE_SIG_INIT: c_long = 0x30B1BCBA; +pub const PTHREAD_ONCE_INIT: ::pthread_once_t = ::pthread_once_t { + __sig: _PTHREAD_ONCE_SIG_INIT, + __opaque: [0; 4], +}; + extern "C" { pub fn exchangedata( path1: *const ::c_char, diff --git a/src/unix/bsd/apple/b64/mod.rs b/src/unix/bsd/apple/b64/mod.rs index 48d94bcd6bfdc..2206210da5575 100644 --- a/src/unix/bsd/apple/b64/mod.rs +++ b/src/unix/bsd/apple/b64/mod.rs @@ -54,6 +54,11 @@ s_no_extra_traits! { __sig: c_long, __opaque: [::c_char; 56] } + + pub struct pthread_once_t { + __sig: c_long, + __opaque: [::c_char; __PTHREAD_ONCE_SIZE__], + } } cfg_if! { @@ -82,6 +87,29 @@ cfg_if! { self.__opaque.hash(state); } } + impl PartialEq for pthread_once_t { + fn eq(&self, other: &pthread_once_t) -> bool { + self.__sig == other.__sig + && self.__opaque + .iter() + .zip(other.__opaque.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for pthread_once_t {} + impl ::fmt::Debug for pthread_once_t { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("pthread_once_t") + .field("__sig", &self.__sig) + .finish() + } + } + impl ::hash::Hash for pthread_once_t { + fn hash(&self, state: &mut H) { + self.__sig.hash(state); + self.__opaque.hash(state); + } + } } } @@ -92,6 +120,7 @@ pub const NET_RT_MAXID: ::c_int = 11; pub const __PTHREAD_MUTEX_SIZE__: usize = 56; pub const __PTHREAD_COND_SIZE__: usize = 40; pub const __PTHREAD_CONDATTR_SIZE__: usize = 8; +pub const __PTHREAD_ONCE_SIZE__: usize = 8; pub const __PTHREAD_RWLOCK_SIZE__: usize = 192; pub const __PTHREAD_RWLOCKATTR_SIZE__: usize = 16; @@ -103,6 +132,12 @@ pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d; pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e; pub const BIOCSETFNR: ::c_ulong = 0x8010427e; +const _PTHREAD_ONCE_SIG_INIT: c_long = 0x30B1BCBA; +pub const PTHREAD_ONCE_INIT: ::pthread_once_t = ::pthread_once_t { + __sig: _PTHREAD_ONCE_SIG_INIT, + __opaque: [0; 8], +}; + extern "C" { pub fn exchangedata( path1: *const ::c_char, diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 92d724071a3d4..3e150feee6afa 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -3787,6 +3787,19 @@ pub const PTHREAD_PROCESS_PRIVATE: ::c_int = 2; pub const PTHREAD_PROCESS_SHARED: ::c_int = 1; pub const PTHREAD_CREATE_JOINABLE: ::c_int = 1; pub const PTHREAD_CREATE_DETACHED: ::c_int = 2; +pub const PTHREAD_INHERIT_SCHED: ::c_int = 1; +pub const PTHREAD_EXPLICIT_SCHED: ::c_int = 2; +pub const PTHREAD_CANCEL_ENABLE: ::c_int = 0x01; +pub const PTHREAD_CANCEL_DISABLE: ::c_int = 0x00; +pub const PTHREAD_CANCEL_DEFERRED: ::c_int = 0x02; +pub const PTHREAD_CANCEL_ASYNCHRONOUS: ::c_int = 0x00; +pub const PTHREAD_CANCELED: *mut ::c_void = 1 as *mut ::c_void; +pub const PTHREAD_SCOPE_SYSTEM: ::c_int = 1; +pub const PTHREAD_SCOPE_PROCESS: ::c_int = 2; +pub const PTHREAD_PRIO_NONE: ::c_int = 0; +pub const PTHREAD_PRIO_INHERIT: ::c_int = 1; +pub const PTHREAD_PRIO_PROTECT: ::c_int = 2; + #[cfg(target_arch = "aarch64")] pub const PTHREAD_STACK_MIN: ::size_t = 16384; #[cfg(not(target_arch = "aarch64"))] @@ -5757,6 +5770,40 @@ extern "C" { pub fn mach_timebase_info(info: *mut ::mach_timebase_info) -> ::c_int; pub fn mach_host_self() -> mach_port_t; pub fn mach_thread_self() -> mach_port_t; + pub fn pthread_once( + once_control: *mut ::pthread_once_t, + init_routine: ::Option, + ) -> ::c_int; + pub fn pthread_attr_getinheritsched( + attr: *const ::pthread_attr_t, + inheritsched: *mut ::c_int, + ) -> ::c_int; + pub fn pthread_attr_getschedpolicy( + attr: *const ::pthread_attr_t, + policy: *mut ::c_int, + ) -> ::c_int; + pub fn pthread_attr_getscope( + attr: *const ::pthread_attr_t, + contentionscope: *mut ::c_int, + ) -> ::c_int; + pub fn pthread_attr_getstackaddr( + attr: *const ::pthread_attr_t, + stackaddr: *mut *mut ::c_void, + ) -> ::c_int; + pub fn pthread_attr_getdetachstate( + attr: *const ::pthread_attr_t, + detachstate: *mut ::c_int, + ) -> ::c_int; + pub fn pthread_attr_setinheritsched( + attr: *mut ::pthread_attr_t, + inheritsched: ::c_int, + ) -> ::c_int; + pub fn pthread_attr_setschedpolicy(attr: *mut ::pthread_attr_t, policy: ::c_int) -> ::c_int; + pub fn pthread_attr_setscope(attr: *mut ::pthread_attr_t, contentionscope: ::c_int) -> ::c_int; + pub fn pthread_attr_setstackaddr( + attr: *mut ::pthread_attr_t, + stackaddr: *mut ::c_void, + ) -> ::c_int; pub fn pthread_setname_np(name: *const ::c_char) -> ::c_int; pub fn pthread_getname_np(thread: ::pthread_t, name: *mut ::c_char, len: ::size_t) -> ::c_int; pub fn pthread_mach_thread_np(thread: ::pthread_t) -> ::mach_port_t; From 9de4a5cfd65c356cd684ee72f71153579b51656d Mon Sep 17 00:00:00 2001 From: Jan Sommer Date: Sun, 20 Aug 2023 23:00:31 +0200 Subject: [PATCH 3/6] Add port for RTEMS (backport ) (cherry picked from commit 6a78b021c099d5ef41760eafcf4f32132aaa46fd) --- build.rs | 5 +- src/unix/newlib/mod.rs | 17 +++++ src/unix/newlib/rtems/mod.rs | 141 +++++++++++++++++++++++++++++++++++ 3 files changed, 162 insertions(+), 1 deletion(-) create mode 100644 src/unix/newlib/rtems/mod.rs diff --git a/build.rs b/build.rs index ce4541e62955c..895dd59abb4ba 100644 --- a/build.rs +++ b/build.rs @@ -35,7 +35,10 @@ const ALLOWED_CFGS: &'static [&'static str] = &[ // Extra values to allow for check-cfg. const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[ - ("target_os", &["switch", "aix", "ohos", "hurd", "visionos"]), + ( + "target_os", + &["switch", "aix", "ohos", "hurd", "rtems", "visionos"], + ), ("target_env", &["illumos", "wasi", "aix", "ohos"]), ( "target_arch", diff --git a/src/unix/newlib/mod.rs b/src/unix/newlib/mod.rs index 29693f6ec2402..91380db247b05 100644 --- a/src/unix/newlib/mod.rs +++ b/src/unix/newlib/mod.rs @@ -267,6 +267,16 @@ cfg_if! { pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 4; pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 4; pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 4; + } else if #[cfg(target_os = "rtems")] { + const __PTHREAD_INITIALIZER_BYTE: u8 = 0x00; + pub const __SIZEOF_PTHREAD_ATTR_T: usize = 96; + pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 64; + pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 24; + pub const __SIZEOF_PTHREAD_COND_T: usize = 28; + pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 24; + pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; + pub const __SIZEOF_PTHREAD_RWLOCKATTR_T: usize = 8; + pub const __SIZEOF_PTHREAD_BARRIER_T: usize = 32; } else { const __PTHREAD_INITIALIZER_BYTE: u8 = 0; pub const __SIZEOF_PTHREAD_ATTR_T: usize = 56; @@ -792,6 +802,13 @@ cfg_if! { } } +cfg_if! { + if #[cfg(target_os = "rtems")] { + mod rtems; + pub use self::rtems::*; + } +} + cfg_if! { if #[cfg(libc_align)] { #[macro_use] diff --git a/src/unix/newlib/rtems/mod.rs b/src/unix/newlib/rtems/mod.rs new file mode 100644 index 0000000000000..36f4820c92f4f --- /dev/null +++ b/src/unix/newlib/rtems/mod.rs @@ -0,0 +1,141 @@ +// defined in architecture specific module +use c_long; + +s! { + pub struct sockaddr_un { + pub sun_family: ::sa_family_t, + pub sun_path: [::c_char; 108usize], + } +} + +pub const AF_UNIX: ::c_int = 1; + +pub const RTLD_DEFAULT: *mut ::c_void = -2isize as *mut ::c_void; + +pub const UTIME_OMIT: c_long = -1; +pub const AT_FDCWD: ::c_int = -2; + +pub const O_DIRECTORY: ::c_int = 0x200000; +pub const O_NOFOLLOW: ::c_int = 0x100000; + +pub const AT_EACCESS: ::c_int = 1; +pub const AT_SYMLINK_NOFOLLOW: ::c_int = 2; +pub const AT_SYMLINK_FOLLOW: ::c_int = 4; +pub const AT_REMOVEDIR: ::c_int = 8; + +// signal.h +pub const SIG_BLOCK: ::c_int = 1; +pub const SIG_UNBLOCK: ::c_int = 2; +pub const SIG_SETMASK: ::c_int = 0; +pub const SIGHUP: ::c_int = 1; +pub const SIGINT: ::c_int = 2; +pub const SIGQUIT: ::c_int = 3; +pub const SIGILL: ::c_int = 4; +pub const SIGTRAP: ::c_int = 5; +pub const SIGABRT: ::c_int = 6; +pub const SIGEMT: ::c_int = 7; +pub const SIGFPE: ::c_int = 8; +pub const SIGKILL: ::c_int = 9; +pub const SIGBUS: ::c_int = 10; +pub const SIGSEGV: ::c_int = 11; +pub const SIGSYS: ::c_int = 12; +pub const SIGPIPE: ::c_int = 13; +pub const SIGALRM: ::c_int = 14; +pub const SIGTERM: ::c_int = 15; +pub const SIGURG: ::c_int = 16; +pub const SIGSTOP: ::c_int = 17; +pub const SIGTSTP: ::c_int = 18; +pub const SIGCONT: ::c_int = 19; +pub const SIGCHLD: ::c_int = 20; +pub const SIGCLD: ::c_int = 20; +pub const SIGTTIN: ::c_int = 21; +pub const SIGTTOU: ::c_int = 22; +pub const SIGIO: ::c_int = 23; +pub const SIGWINCH: ::c_int = 24; +pub const SIGUSR1: ::c_int = 25; +pub const SIGUSR2: ::c_int = 26; +pub const SIGRTMIN: ::c_int = 27; +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; + +pub const EAI_AGAIN: ::c_int = 2; +pub const EAI_BADFLAGS: ::c_int = 3; +pub const EAI_FAIL: ::c_int = 4; +pub const EAI_SERVICE: ::c_int = 9; +pub const EAI_SYSTEM: ::c_int = 11; +pub const EAI_OVERFLOW: ::c_int = 14; + +pub const _SC_PAGESIZE: ::c_int = 8; +pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 51; +pub const PTHREAD_STACK_MIN: ::size_t = 0; + +// sys/wait.h +pub const WNOHANG: ::c_int = 1; +pub const WUNTRACED: ::c_int = 2; + +// sys/socket.h +pub const SOMAXCONN: ::c_int = 128; + +safe_f! { + pub {const} fn WIFSTOPPED(status: ::c_int) -> bool { + (status & 0xff) == 0x7f + } + + pub {const} fn WSTOPSIG(status: ::c_int) -> ::c_int { + // (status >> 8) & 0xff + WEXITSTATUS(status) + } + + pub {const} fn WIFSIGNALED(status: ::c_int) -> bool { + ((status & 0x7f) > 0) && ((status & 0x7f) < 0x7f) + } + + pub {const} fn WTERMSIG(status: ::c_int) -> ::c_int { + status & 0x7f + } + + pub {const} fn WIFEXITED(status: ::c_int) -> bool { + (status & 0xff) == 0 + } + + pub {const} fn WEXITSTATUS(status: ::c_int) -> ::c_int { + (status >> 8) & 0xff + } + + // RTEMS doesn't have native WIFCONTINUED. + pub {const} fn WIFCONTINUED(_status: ::c_int) -> bool { + true + } + + // RTEMS doesn't have native WCOREDUMP. + pub {const} fn WCOREDUMP(_status: ::c_int) -> bool { + false + } +} + +extern "C" { + pub fn futimens(fd: ::c_int, times: *const ::timespec) -> ::c_int; + pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; + pub fn readv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; + + 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 pthread_condattr_setclock( + attr: *mut ::pthread_condattr_t, + clock_id: ::clockid_t, + ) -> ::c_int; + + pub fn setgroups(ngroups: ::c_int, grouplist: *const ::gid_t) -> ::c_int; +} From 0567d118b1a4030cf5e46c9ba8a588db000dc695 Mon Sep 17 00:00:00 2001 From: Andrew Liebenow Date: Tue, 1 Oct 2024 02:21:44 -0500 Subject: [PATCH 4/6] Add missing musl utmpx.h constants (backport ) (cherry picked from commit 6cd88a49e7ead33237eed71152ed72e196b95077) --- libc-test/semver/linux-musl.txt | 9 +++++++++ src/unix/linux_like/linux/musl/mod.rs | 12 ++++++++++++ 2 files changed, 21 insertions(+) diff --git a/libc-test/semver/linux-musl.txt b/libc-test/semver/linux-musl.txt index bb8dbb2f9834e..e873cb21d0491 100644 --- a/libc-test/semver/linux-musl.txt +++ b/libc-test/semver/linux-musl.txt @@ -10,25 +10,34 @@ MPOL_DEFAULT MPOL_INTERLEAVE MPOL_LOCAL MPOL_PREFERRED +BOOT_TIME +DEAD_PROCESS Elf32_Chdr Elf64_Chdr +EMPTY +INIT_PROCESS LIO_NOP LIO_NOWAIT LIO_READ LIO_WAIT LIO_WRITE +LOGIN_PROCESS +NEW_TIME +OLD_TIME PF_IB PF_MPLS PF_XDP PIDFD_NONBLOCK PR_SET_VMA PR_SET_VMA_ANON_NAME +RUN_LVL RWF_APPEND RWF_DSYNC RWF_HIPRI RWF_NOWAIT RWF_SYNC SOL_XDP +USER_PROCESS XDP_SHARED_UMEM XDP_COPY XDP_ZEROCOPY diff --git a/src/unix/linux_like/linux/musl/mod.rs b/src/unix/linux_like/linux/musl/mod.rs index d102d5de2cfed..72bd335360b8e 100644 --- a/src/unix/linux_like/linux/musl/mod.rs +++ b/src/unix/linux_like/linux/musl/mod.rs @@ -632,6 +632,18 @@ pub const MAP_HUGE_16GB: ::c_int = 34 << MAP_HUGE_SHIFT; pub const MS_RMT_MASK: ::c_ulong = 0x02800051; +// include/utmpx.h +pub const EMPTY: ::c_short = 0; +pub const RUN_LVL: ::c_short = 1; +pub const BOOT_TIME: ::c_short = 2; +pub const NEW_TIME: ::c_short = 3; +pub const OLD_TIME: ::c_short = 4; +pub const INIT_PROCESS: ::c_short = 5; +pub const LOGIN_PROCESS: ::c_short = 6; +pub const USER_PROCESS: ::c_short = 7; +pub const DEAD_PROCESS: ::c_short = 8; +// musl does not define ACCOUNTING + pub const SFD_CLOEXEC: ::c_int = 0x080000; pub const NCCS: usize = 32; From c2e03d56aef34249bfb5010a366c26b0173f04e4 Mon Sep 17 00:00:00 2001 From: Huang Qi Date: Wed, 25 Sep 2024 08:16:29 +0800 Subject: [PATCH 5/6] Initial support for NuttX (#3909) Define the essential types that for NuttX OS. Signed-off-by: Huang Qi (backport ) (cherry picked from commit c31dfc1595a06fa28e2da66a262c7a64b5fc1923) --- build.rs | 4 +- src/unix/mod.rs | 10 +- src/unix/nuttx/mod.rs | 555 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 566 insertions(+), 3 deletions(-) create mode 100644 src/unix/nuttx/mod.rs diff --git a/build.rs b/build.rs index 895dd59abb4ba..ea55185d77023 100644 --- a/build.rs +++ b/build.rs @@ -37,7 +37,9 @@ const ALLOWED_CFGS: &'static [&'static str] = &[ const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[ ( "target_os", - &["switch", "aix", "ohos", "hurd", "rtems", "visionos"], + &[ + "switch", "aix", "ohos", "hurd", "rtems", "visionos", "nuttx", + ], ), ("target_env", &["illumos", "wasi", "aix", "ohos"]), ( diff --git a/src/unix/mod.rs b/src/unix/mod.rs index 6bab825b0449b..3f1148043f532 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -319,8 +319,11 @@ extern "C" { } cfg_if! { - if #[cfg(any(target_os = "l4re", target_os = "espidf"))] { - // required libraries for L4Re and the ESP-IDF framework are linked externally, ATM + if #[cfg(any(target_os = "l4re", target_os = "espidf", target_os = "nuttx"))] { + // required libraries are linked externally for these platforms: + // * L4Re + // * ESP-IDF + // * NuttX } else if #[cfg(feature = "std")] { // cargo build, don't pull in anything extra as the std dep // already pulls in all libs. @@ -1617,6 +1620,9 @@ cfg_if! { } else if #[cfg(target_os = "hurd")] { mod hurd; pub use self::hurd::*; + } else if #[cfg(target_os = "nuttx")] { + mod nuttx; + pub use self::nuttx::*; } else { // Unknown target_os } diff --git a/src/unix/nuttx/mod.rs b/src/unix/nuttx/mod.rs new file mode 100644 index 0000000000000..e3a3c15b338cc --- /dev/null +++ b/src/unix/nuttx/mod.rs @@ -0,0 +1,555 @@ +use c_void; +use in6_addr; +use in_addr_t; +use timespec; +use DIR; + +pub type nlink_t = u16; +pub type ino_t = u16; +pub type blkcnt_t = u64; +pub type blksize_t = i16; +pub type c_char = i8; +pub type c_long = isize; +pub type c_ulong = usize; +pub type cc_t = u8; +pub type clock_t = i64; +pub type dev_t = i32; +pub type fsblkcnt_t = u64; +pub type locale_t = *mut i8; +pub type mode_t = u32; +pub type nfds_t = u32; +pub type off_t = i64; +pub type pthread_key_t = i32; +pub type pthread_mutexattr_t = u8; +pub type pthread_rwlockattr_t = i32; +pub type pthread_t = i32; +pub type rlim_t = i64; +pub type sa_family_t = u16; +pub type socklen_t = u32; +pub type speed_t = usize; +pub type suseconds_t = i32; +pub type tcflag_t = u32; +pub type clockid_t = i32; +pub type time_t = i64; +pub type wchar_t = i32; + +s! { + pub struct stat { + pub st_dev: dev_t, + pub st_ino: ino_t, + pub st_mode: mode_t, + pub st_nlink: u64, + pub st_uid: u32, + pub st_gid: u32, + pub st_rdev: dev_t, + pub st_size: off_t, + pub st_atim: timespec, + pub st_mtim: timespec, + pub st_ctim: timespec, + pub st_blksize: blksize_t, + pub st_blocks: i64, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__], + } + + pub struct sockaddr { + pub sa_family: sa_family_t, + pub sa_data: [u8; 14], + } + + pub struct passwd { + pub pw_name: *const c_char, + pub pw_uid: u32, + pub pw_gid: u32, + pub pw_gecos: *const c_char, + pub pw_dir: *const c_char, + pub pw_shell: *const c_char, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__] + } + + pub struct sem_t { __val: [usize; __SEM_SIZE__] } + + pub struct pthread_attr_t { __val: [usize; __PTHREAD_ATTR_SIZE__] } + + pub struct pthread_mutex_t { __val: [usize; __PTHREAD_MUTEX_SIZE__] } + + pub struct pthread_cond_t { __val: [usize; __PTHREAD_COND_SIZE__] } + + pub struct pthread_condattr_t { __val: [usize; __PTHREAD_CONDATTR_SIZE__] } + + pub struct Dl_info { + pub dli_fname: *const c_char, + pub dli_fbase: *mut c_void, + pub dli_sname: *const c_char, + pub dli_saddr: *mut c_void, + } + + pub struct lconv { + pub decimal_point: *const c_char, + pub thousands_sep: *const c_char, + pub grouping: *const c_char, + pub int_curr_symbol: *const c_char, + pub currency_symbol: *const c_char, + pub mon_decimal_point: *const c_char, + pub mon_thousands_sep: *const c_char, + pub mon_grouping: *const c_char, + pub positive_sign: *const c_char, + pub negative_sign: *const c_char, + pub int_frac_digits: i8, + pub frac_digits: i8, + pub p_cs_precedes: i8, + pub p_sep_by_space: i8, + pub n_cs_precedes: i8, + pub n_sep_by_space: i8, + pub p_sign_posn: i8, + pub n_sign_posn: i8, + pub int_n_cs_precedes: i8, + pub int_n_sep_by_space: i8, + pub int_n_sign_posn: i8, + pub int_p_cs_precedes: i8, + pub int_p_sep_by_space: i8, + pub int_p_sign_posn: i8, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__], + } + + pub struct tm { + pub tm_sec: i32, + pub tm_min: i32, + pub tm_hour: i32, + pub tm_mday: i32, + pub tm_mon: i32, + pub tm_year: i32, + pub tm_wday: i32, + pub tm_yday: i32, + pub tm_isdst: i32, + pub tm_gmtoff: isize, + pub tm_zone: *const i8, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__], + } + + pub struct addrinfo { + pub ai_flags: i32, + pub ai_family: i32, + pub ai_socktype: i32, + pub ai_protocol: i32, + pub ai_addrlen: socklen_t, + pub ai_addr: *mut sockaddr, + pub ai_canonname: *mut c_char, + pub ai_next: *mut addrinfo, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__], + } + + pub struct pthread_rwlock_t { + __val: [usize; __PTHREAD_RWLOCK_SIZE__], + } + + pub struct statvfs { + pub f_bsize: usize, + pub f_frsize: usize, + pub f_blocks: fsblkcnt_t, + pub f_bfree: fsblkcnt_t, + pub f_bavail: fsblkcnt_t, + pub f_files: fsblkcnt_t, + pub f_ffree: fsblkcnt_t, + pub f_favail: fsblkcnt_t, + pub f_fsid: usize, + pub f_flag: usize, + pub f_namemax: usize, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__], + } + + pub struct dirent { + pub d_type: u8, + pub d_name: [i8; __NAME_MAX__ + 1], + } + + pub struct fd_set { + __val: [u32; __FDSET_SIZE__], + } + + pub struct sigset_t { + __val: [u32; __SIGSET_SIZE__], + } + + pub struct sigaction { + pub sa_handler: usize, + pub sa_mask: sigset_t, + pub sa_flags: i32, + pub sa_user: usize, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__], + } + + pub struct termios { + pub c_iflag: tcflag_t, + pub c_oflag: tcflag_t, + pub c_cflag: tcflag_t, + pub c_lflag: tcflag_t, + pub c_cc: [cc_t; 12], + pub c_speed: speed_t, + __reserved: [usize; __DEFAULT_RESERVED_SIZE__], + } + + pub struct in_addr { + pub s_addr: in_addr_t, + } + + pub struct sockaddr_in { + pub sin_family: sa_family_t, + pub sin_port: ::in_port_t, + pub sin_addr: ::in_addr, + pub sin_zero: [u8; 8], + } + + pub struct sockaddr_in6 { + pub sin6_family: sa_family_t, + pub sin6_port: ::in_port_t, + pub sin6_flowinfo: u32, + pub sin6_addr: ::in6_addr, + pub sin6_scope_id: u32, + } + + pub struct sockaddr_un { + pub sun_family: sa_family_t, + pub sun_path: [c_char; 108], + } + + pub struct sockaddr_storage { + pub ss_family: sa_family_t, + ss_data: [u32; __SOCKADDR_STORAGE_SIZE__], + } + + pub struct ip_mreq { + pub imr_multiaddr: in_addr, + pub imr_interface: in_addr, + } + + pub struct ipv6_mreq { + pub ipv6mr_multiaddr: in6_addr, + pub ipv6mr_interface: u32, + } + + pub struct timeval { + pub tv_sec: time_t, + pub tv_usec: suseconds_t, + } +} + +// Reserved two pointer size for reserved area for some structures. +// This ensures that the size of these structures is large enough +// if more fields are added in the NuttX side. +// +// These structures are that defined by POSIX but only necessary fields are included, +// for example, struct passwd, https://pubs.opengroup.org/onlinepubs/009695399/basedefs/pwd.h.html, +// POSIX only defines following fields in struct passwd: +// char *pw_name User's login name. +// uid_t pw_uid Numerical user ID. +// gid_t pw_gid Numerical group ID. +// char *pw_dir Initial working directory. +// char *pw_shell Program to use as shell. +// Other fields can be different depending on the implementation. + +const __DEFAULT_RESERVED_SIZE__: usize = 2; + +const __SOCKADDR_STORAGE_SIZE__: usize = 36; +const __PTHREAD_ATTR_SIZE__: usize = 5; +const __PTHREAD_MUTEX_SIZE__: usize = 9; +const __PTHREAD_COND_SIZE__: usize = 7; +const __PTHREAD_CONDATTR_SIZE__: usize = 5; +const __PTHREAD_RWLOCK_SIZE__: usize = 17; +const __SEM_SIZE__: usize = 6; +const __NAME_MAX__: usize = 64; +const __FDSET_SIZE__: usize = 10; +const __SIGSET_SIZE__: usize = 8; + +pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + __val: [0; __PTHREAD_COND_SIZE__], +}; +pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + __val: [0; __PTHREAD_MUTEX_SIZE__], +}; + +// dlfcn.h +pub const RTLD_DEFAULT: *mut c_void = 0 as *mut c_void; + +// stdlib.h +pub const EXIT_SUCCESS: i32 = 0; +pub const EXIT_FAILURE: i32 = 1; + +// time.h +pub const CLOCK_REALTIME: i32 = 0; +pub const CLOCK_MONOTONIC: i32 = 1; + +// errno.h +pub const EPERM: i32 = 1; +pub const ENOENT: i32 = 2; +pub const ESRCH: i32 = 3; +pub const EINTR: i32 = 4; +pub const EIO: i32 = 5; +pub const ENXIO: i32 = 6; +pub const E2BIG: i32 = 7; +pub const ENOEXEC: i32 = 8; +pub const EBADF: i32 = 9; +pub const ECHILD: i32 = 10; +pub const EAGAIN: i32 = 11; +pub const ENOMEM: i32 = 12; +pub const EACCES: i32 = 13; +pub const EFAULT: i32 = 14; +pub const ENOTBLK: i32 = 15; +pub const EBUSY: i32 = 16; +pub const EEXIST: i32 = 17; +pub const EXDEV: i32 = 18; +pub const ENODEV: i32 = 19; +pub const ENOTDIR: i32 = 20; +pub const EISDIR: i32 = 21; +pub const EINVAL: i32 = 22; +pub const ENFILE: i32 = 23; +pub const EMFILE: i32 = 24; +pub const ENOTTY: i32 = 25; +pub const ETXTBSY: i32 = 26; +pub const EFBIG: i32 = 27; +pub const ENOSPC: i32 = 28; +pub const ESPIPE: i32 = 29; +pub const EROFS: i32 = 30; +pub const EMLINK: i32 = 31; +pub const EPIPE: i32 = 32; +pub const EDOM: i32 = 33; +pub const ERANGE: i32 = 34; +pub const EDEADLK: i32 = 35; +pub const ENAMETOOLONG: i32 = 36; +pub const ENOLCK: i32 = 37; +pub const ENOSYS: i32 = 38; +pub const ENOTEMPTY: i32 = 39; +pub const ELOOP: i32 = 40; +pub const EWOULDBLOCK: i32 = EAGAIN; +pub const ENOMSG: i32 = 42; +pub const EIDRM: i32 = 43; +pub const ECHRNG: i32 = 44; +pub const EL2NSYNC: i32 = 45; +pub const EL3HLT: i32 = 46; +pub const EL3RST: i32 = 47; +pub const ELNRNG: i32 = 48; +pub const EUNATCH: i32 = 49; +pub const ENOCSI: i32 = 50; +pub const EL2HLT: i32 = 51; +pub const EBADE: i32 = 52; +pub const EBADR: i32 = 53; +pub const EXFULL: i32 = 54; +pub const ENOANO: i32 = 55; +pub const EBADRQC: i32 = 56; +pub const EBADSLT: i32 = 57; +pub const EDEADLOCK: i32 = EDEADLK; +pub const EBFONT: i32 = 59; +pub const ENOSTR: i32 = 60; +pub const ENODATA: i32 = 61; +pub const ETIME: i32 = 62; +pub const ENOSR: i32 = 63; +pub const ENONET: i32 = 64; +pub const ENOPKG: i32 = 65; +pub const EREMOTE: i32 = 66; +pub const ENOLINK: i32 = 67; +pub const EADV: i32 = 68; +pub const ESRMNT: i32 = 69; +pub const ECOMM: i32 = 70; +pub const EPROTO: i32 = 71; +pub const EMULTIHOP: i32 = 72; +pub const EDOTDOT: i32 = 73; +pub const EBADMSG: i32 = 74; +pub const EOVERFLOW: i32 = 75; +pub const ENOTUNIQ: i32 = 76; +pub const EBADFD: i32 = 77; +pub const EREMCHG: i32 = 78; +pub const ELIBACC: i32 = 79; +pub const ELIBBAD: i32 = 80; +pub const ELIBSCN: i32 = 81; +pub const ELIBMAX: i32 = 82; +pub const ELIBEXEC: i32 = 83; +pub const EILSEQ: i32 = 84; +pub const ERESTART: i32 = 85; +pub const ESTRPIPE: i32 = 86; +pub const EUSERS: i32 = 87; +pub const ENOTSOCK: i32 = 88; +pub const EDESTADDRREQ: i32 = 89; +pub const EMSGSIZE: i32 = 90; +pub const EPROTOTYPE: i32 = 91; +pub const ENOPROTOOPT: i32 = 92; +pub const EPROTONOSUPPORT: i32 = 93; +pub const ESOCKTNOSUPPORT: i32 = 94; +pub const EOPNOTSUPP: i32 = 95; +pub const EPFNOSUPPORT: i32 = 96; +pub const EAFNOSUPPORT: i32 = 97; +pub const EADDRINUSE: i32 = 98; +pub const EADDRNOTAVAIL: i32 = 99; +pub const ENETDOWN: i32 = 100; +pub const ENETUNREACH: i32 = 101; +pub const ENETRESET: i32 = 102; +pub const ECONNABORTED: i32 = 103; +pub const ECONNRESET: i32 = 104; +pub const ENOBUFS: i32 = 105; +pub const EISCONN: i32 = 106; +pub const ENOTCONN: i32 = 107; +pub const ESHUTDOWN: i32 = 108; +pub const ETOOMANYREFS: i32 = 109; +pub const ETIMEDOUT: i32 = 110; +pub const ECONNREFUSED: i32 = 111; +pub const EHOSTDOWN: i32 = 112; +pub const EHOSTUNREACH: i32 = 113; +pub const EALREADY: i32 = 114; +pub const EINPROGRESS: i32 = 115; +pub const ESTALE: i32 = 116; +pub const EUCLEAN: i32 = 117; +pub const ENOTNAM: i32 = 118; +pub const ENAVAIL: i32 = 119; +pub const EISNAM: i32 = 120; +pub const EREMOTEIO: i32 = 121; +pub const EDQUOT: i32 = 122; +pub const ENOMEDIUM: i32 = 123; +pub const EMEDIUMTYPE: i32 = 124; +pub const ECANCELED: i32 = 125; +pub const ENOKEY: i32 = 126; +pub const EKEYEXPIRED: i32 = 127; +pub const EKEYREVOKED: i32 = 128; +pub const EKEYREJECTED: i32 = 129; +pub const EOWNERDEAD: i32 = 130; +pub const ENOTRECOVERABLE: i32 = 131; +pub const ERFKILL: i32 = 132; +pub const EHWPOISON: i32 = 133; +pub const ELBIN: i32 = 134; +pub const EFTYPE: i32 = 135; +pub const ENMFILE: i32 = 136; +pub const EPROCLIM: i32 = 137; +pub const ENOTSUP: i32 = 138; +pub const ENOSHARE: i32 = 139; +pub const ECASECLASH: i32 = 140; + +// fcntl.h +pub const FIOCLEX: i32 = 0x30b; +pub const F_SETFL: i32 = 0x9; +pub const F_DUPFD_CLOEXEC: i32 = 0x12; +pub const F_GETFD: i32 = 0x1; +pub const F_GETFL: i32 = 0x2; +pub const O_RDONLY: i32 = 0x1; +pub const O_WRONLY: i32 = 0x2; +pub const O_RDWR: i32 = 0x3; +pub const O_CREAT: i32 = 0x4; +pub const O_EXCL: i32 = 0x8; +pub const O_NOCTTY: i32 = 0x0; +pub const O_TRUNC: i32 = 0x20; +pub const O_APPEND: i32 = 0x10; +pub const O_NONBLOCK: i32 = 0x40; +pub const O_DSYNC: i32 = 0x80; +pub const O_DIRECT: i32 = 0x200; +pub const O_LARGEFILE: i32 = 0x2000; +pub const O_DIRECTORY: i32 = 0x800; +pub const O_NOFOLLOW: i32 = 0x1000; +pub const O_NOATIME: i32 = 0x40000; +pub const O_CLOEXEC: i32 = 0x400; +pub const O_ACCMODE: i32 = 0x0003; +pub const AT_FDCWD: i32 = -100; +pub const AT_REMOVEDIR: i32 = 0x200; + +// sys/types.h +pub const SEEK_SET: i32 = 0; +pub const SEEK_CUR: i32 = 1; +pub const SEEK_END: i32 = 2; + +// sys/stat.h +pub const S_IFDIR: u32 = 0x4000; +pub const S_IFLNK: u32 = 0xA000; +pub const S_IFREG: u32 = 0x8000; +pub const S_IFMT: u32 = 0xF000; +pub const S_IFIFO: u32 = 0x1000; +pub const S_IFSOCK: u32 = 0xc000; +pub const S_IFBLK: u32 = 0x6000; +pub const S_IFCHR: u32 = 0x2000; +pub const S_IRUSR: u32 = 0x100; +pub const S_IWUSR: u32 = 0x80; +pub const S_IXUSR: u32 = 0x40; +pub const S_IRGRP: u32 = 0x20; +pub const S_IWGRP: u32 = 0x10; +pub const S_IXGRP: u32 = 0x8; +pub const S_IROTH: u32 = 0x004; +pub const S_IWOTH: u32 = 0x002; +pub const S_IXOTH: u32 = 0x001; + +// sys/poll.h +pub const POLLIN: i16 = 0x01; +pub const POLLOUT: i16 = 0x04; +pub const POLLHUP: i16 = 0x10; +pub const POLLERR: i16 = 0x08; +pub const POLLNVAL: i16 = 0x20; + +// sys/socket.h +pub const AF_UNIX: i32 = 1; +pub const SOCK_DGRAM: i32 = 2; +pub const SOCK_STREAM: i32 = 1; +pub const AF_INET: i32 = 2; +pub const AF_INET6: i32 = 10; +pub const MSG_PEEK: i32 = 0x02; +pub const SOL_SOCKET: i32 = 1; +pub const SHUT_WR: i32 = 2; +pub const SHUT_RD: i32 = 1; +pub const SHUT_RDWR: i32 = 3; +pub const SO_ERROR: i32 = 4; +pub const SO_REUSEADDR: i32 = 11; +pub const SOMAXCONN: i32 = 8; +pub const SO_LINGER: i32 = 6; +pub const SO_RCVTIMEO: i32 = 0xa; +pub const SO_SNDTIMEO: i32 = 0xe; +pub const SO_BROADCAST: i32 = 1; + +// netinet/tcp.h +pub const TCP_NODELAY: i32 = 0x10; + +// nuttx/fs/ioctl.h +pub const FIONBIO: i32 = 0x30a; + +// unistd.h +pub const STDIN_FILENO: i32 = 0; +pub const STDOUT_FILENO: i32 = 1; +pub const STDERR_FILENO: i32 = 2; +pub const _SC_PAGESIZE: i32 = 0x36; +pub const _SC_THREAD_STACK_MIN: i32 = 0x58; +pub const _SC_GETPW_R_SIZE_MAX: i32 = 0x25; + +// signal.h +pub const SIGPIPE: i32 = 13; + +// pthread.h +pub const PTHREAD_MUTEX_NORMAL: i32 = 0; + +// netinet/in.h +pub const IP_TTL: i32 = 0x1e; +pub const IPV6_V6ONLY: i32 = 0x17; +pub const IPV6_JOIN_GROUP: i32 = 0x11; +pub const IPV6_LEAVE_GROUP: i32 = 0x12; +pub const IP_MULTICAST_LOOP: i32 = 0x13; +pub const IPV6_MULTICAST_LOOP: i32 = 0x15; +pub const IP_MULTICAST_TTL: i32 = 0x12; +pub const IP_ADD_MEMBERSHIP: i32 = 0x14; +pub const IP_DROP_MEMBERSHIP: i32 = 0x15; + +extern "C" { + pub fn bind(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32; + pub fn ioctl(fd: i32, request: i32, ...) -> i32; + pub fn dirfd(dirp: *mut DIR) -> i32; + pub fn recvfrom( + sockfd: i32, + buf: *mut c_void, + len: usize, + flags: i32, + src_addr: *mut sockaddr, + addrlen: *mut socklen_t, + ) -> i32; + + pub fn pthread_create( + thread: *mut pthread_t, + attr: *const pthread_attr_t, + start_routine: extern "C" fn(*mut c_void) -> *mut c_void, + arg: *mut c_void, + ) -> i32; + + pub fn clock_gettime(clockid: clockid_t, tp: *mut timespec) -> i32; + pub fn futimens(fd: i32, times: *const timespec) -> i32; + pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> i32; + pub fn pthread_set_name_np(thread: pthread_t, name: *const c_char) -> i32; + pub fn getrandom(buf: *mut c_void, buflen: usize, flags: u32) -> isize; +} From d607b77d316413915f340b7b6617902bc19efdd0 Mon Sep 17 00:00:00 2001 From: ChanTsune <41658782+ChanTsune@users.noreply.github.com> Date: Wed, 25 Sep 2024 07:31:46 -0700 Subject: [PATCH 6/6] Add `AT_EACCESS` to emscripten (#3911) https://github.com/emscripten-core/emscripten/blob/3073806d3fde4320c81cb2dc7cf0e00378f52df1/system/lib/libc/musl/include/fcntl.h#L68 (backport ) (cherry picked from commit b23f5176536c4ed3a1a28dcb377db32692166fae) --- libc-test/semver/emscripten.txt | 1 + src/unix/linux_like/emscripten/mod.rs | 2 ++ 2 files changed, 3 insertions(+) diff --git a/libc-test/semver/emscripten.txt b/libc-test/semver/emscripten.txt index d14abae402367..d61541c4f2baf 100644 --- a/libc-test/semver/emscripten.txt +++ b/libc-test/semver/emscripten.txt @@ -1,3 +1,4 @@ +AT_EACCESS getentropy posix_fallocate64 getpwnam_r diff --git a/src/unix/linux_like/emscripten/mod.rs b/src/unix/linux_like/emscripten/mod.rs index 11a16aa7afa41..5a598f5503850 100644 --- a/src/unix/linux_like/emscripten/mod.rs +++ b/src/unix/linux_like/emscripten/mod.rs @@ -775,6 +775,8 @@ pub const POSIX_MADV_RANDOM: ::c_int = 1; pub const POSIX_MADV_SEQUENTIAL: ::c_int = 2; pub const POSIX_MADV_WILLNEED: ::c_int = 3; +pub const AT_EACCESS: ::c_int = 0x200; + pub const S_IEXEC: mode_t = 64; pub const S_IWRITE: mode_t = 128; pub const S_IREAD: mode_t = 256;