From 9105f6a4ee14c90506983113e1a2c15562c170f6 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 19 Jul 2024 09:03:31 +1000 Subject: [PATCH 1/4] Add fcntl OFD commands for macOS Obey shellcheck ci/style.sh should be executable Require macos-14 (backport ) (cherry picked from commit 00163d2019049a703cfb2b09b3f3fc3a25647af0) --- libc-test/semver/apple.txt | 11 +++++++---- src/unix/bsd/apple/mod.rs | 4 ++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index 4ca721005f139..dc9d7b4426022 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -256,10 +256,10 @@ COPYFILE_STATE_SRC_FD COPYFILE_STATE_SRC_FILENAME COPYFILE_STATE_STATUS_CB COPYFILE_STATE_STATUS_CTX -COPYFILE_STATE_XATTRNAME COPYFILE_STATE_WAS_CLONED -COPYFILE_VERBOSE +COPYFILE_STATE_XATTRNAME COPYFILE_UNLINK +COPYFILE_VERBOSE COPYFILE_XATTR CR0 CR1 @@ -441,6 +441,9 @@ F_LOG2PHYS F_LOG2PHYS_EXT F_NOCACHE F_NODIRECT +F_OFD_GETLK +F_OFD_SETLK +F_OFD_SETLKW F_PEOFPOSMODE F_PREALLOCATE F_PUNCHHOLE @@ -2093,6 +2096,7 @@ posix_spawn_file_actions_t posix_spawnattr_destroy posix_spawnattr_get_qos_class_np posix_spawnattr_getarchpref_np +posix_spawnattr_getbinpref_np posix_spawnattr_getflags posix_spawnattr_getpgroup posix_spawnattr_getsigdefault @@ -2100,12 +2104,11 @@ posix_spawnattr_getsigmask posix_spawnattr_init posix_spawnattr_set_qos_class_np posix_spawnattr_setarchpref_np +posix_spawnattr_setbinpref_np posix_spawnattr_setflags posix_spawnattr_setpgroup posix_spawnattr_setsigdefault posix_spawnattr_setsigmask -posix_spawnattr_getbinpref_np -posix_spawnattr_setbinpref_np posix_spawnattr_t posix_spawnp preadv diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index f21c0ae6e54aa..32f0f4eac779b 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -3609,6 +3609,10 @@ pub const F_GLOBAL_NOCACHE: ::c_int = 55; pub const F_NODIRECT: ::c_int = 62; pub const F_LOG2PHYS_EXT: ::c_int = 65; pub const F_BARRIERFSYNC: ::c_int = 85; +// See https://github.com/apple/darwin-xnu/blob/main/bsd/sys/fcntl.h +pub const F_OFD_SETLK: ::c_int = 90; /* Acquire or release open file description lock */ +pub const F_OFD_SETLKW: ::c_int = 91; /* (as F_OFD_SETLK but blocking if conflicting lock) */ +pub const F_OFD_GETLK: ::c_int = 92; /* Examine OFD lock */ pub const F_PUNCHHOLE: ::c_int = 99; pub const F_TRIM_ACTIVE_FILE: ::c_int = 100; pub const F_SPECULATIVE_READ: ::c_int = 101; From 191c59f84dd8a3870bd8de02a5fb7879f8c87351 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Sun, 5 May 2024 15:47:13 +0900 Subject: [PATCH 2/4] Add wasi select, FD_SET, FD_ZERO, FD_ISSET (backport ) (cherry picked from commit 1edaad1b20a2c9396947ff1d811f4d082ec16830) --- src/wasi.rs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/wasi.rs b/src/wasi.rs index 8b32405b9fbfe..0f6cace8becb6 100644 --- a/src/wasi.rs +++ b/src/wasi.rs @@ -175,6 +175,11 @@ s! { pub st_ctim: timespec, __reserved: [c_longlong; 3], } + + pub struct fd_set { + __nfds: usize, + __fds: [c_int; FD_SETSIZE as usize], + } } // Declare dirent outside of s! so that it doesn't implement Copy, Eq, Hash, @@ -442,6 +447,28 @@ pub const NOEXPR: ::nl_item = 0x50001; pub const YESSTR: ::nl_item = 0x50002; pub const NOSTR: ::nl_item = 0x50003; +f! { + pub fn FD_ISSET(fd: ::c_int, set: *const fd_set) -> bool { + let set = &*set; + let n = set.__nfds; + return set.__fds[..n].iter().any(|p| *p == fd) + } + + pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { + let set = &mut *set; + let n = set.__nfds; + if !set.__fds[..n].iter().any(|p| *p == fd) { + set.__nfds = n + 1; + set.__fds[n] = fd; + } + } + + pub fn FD_ZERO(set: *mut fd_set) -> () { + (*set).__nfds = 0; + return + } +} + #[cfg_attr( feature = "rustc-dep-of-std", link( @@ -737,6 +764,14 @@ extern "C" { pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; pub fn nl_langinfo_l(item: ::nl_item, loc: ::locale_t) -> *mut ::c_char; + pub fn select( + nfds: c_int, + readfds: *mut fd_set, + writefds: *mut fd_set, + errorfds: *mut fd_set, + timeout: *const timeval, + ) -> c_int; + pub fn __wasilibc_register_preopened_fd(fd: c_int, path: *const c_char) -> c_int; pub fn __wasilibc_fd_renumber(fd: c_int, newfd: c_int) -> c_int; pub fn __wasilibc_unlinkat(fd: c_int, path: *const c_char) -> c_int; From d3910e7b5cf96c00b679b40e553a19262b62bec2 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Tue, 13 Aug 2024 09:52:36 +0900 Subject: [PATCH 3/4] Add semver/wasi.txt (backport ) (cherry picked from commit e9da8a01a9c2c2d24797cb24c25f8ef18d55a712) --- libc-test/semver/wasi.txt | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 libc-test/semver/wasi.txt diff --git a/libc-test/semver/wasi.txt b/libc-test/semver/wasi.txt new file mode 100644 index 0000000000000..975c8155a58cb --- /dev/null +++ b/libc-test/semver/wasi.txt @@ -0,0 +1,5 @@ +fd_set +FD_SET +FD_ZERO +FD_ISSET +select From 66cdb6bd9612387d2926709058619afd4e47b7a5 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Wed, 14 Aug 2024 19:00:03 +0100 Subject: [PATCH 4/4] openbsd/netbsd factorise getnameinfo. (backport ) (cherry picked from commit 5df9fa0db73fea938c3837c811a9ab4d27aadd96) --- src/unix/bsd/netbsdlike/mod.rs | 11 +++++++++++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 9 --------- src/unix/bsd/netbsdlike/openbsd/mod.rs | 9 --------- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/src/unix/bsd/netbsdlike/mod.rs b/src/unix/bsd/netbsdlike/mod.rs index e92cf65940141..eec8f39b5c858 100644 --- a/src/unix/bsd/netbsdlike/mod.rs +++ b/src/unix/bsd/netbsdlike/mod.rs @@ -706,6 +706,17 @@ extern "C" { dev: dev_t, ) -> ::c_int; pub fn mkfifoat(dirfd: ::c_int, pathname: *const ::c_char, mode: ::mode_t) -> ::c_int; + + pub fn getnameinfo( + sa: *const ::sockaddr, + salen: ::socklen_t, + host: *mut ::c_char, + hostlen: ::socklen_t, + serv: *mut ::c_char, + servlen: ::socklen_t, + flags: ::c_int, + ) -> ::c_int; + pub fn sem_timedwait(sem: *mut sem_t, abstime: *const ::timespec) -> ::c_int; pub fn sem_getvalue(sem: *mut sem_t, sval: *mut ::c_int) -> ::c_int; pub fn pthread_condattr_setclock( diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 7c63db8e0e205..28456d68bebd8 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -2648,15 +2648,6 @@ extern "C" { pub fn lutimes(file: *const ::c_char, times: *const ::timeval) -> ::c_int; #[link_name = "__gettimeofday50"] pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::socklen_t, - serv: *mut ::c_char, - servlen: ::socklen_t, - flags: ::c_int, - ) -> ::c_int; pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; pub fn sysctl( name: *const ::c_int, diff --git a/src/unix/bsd/netbsdlike/openbsd/mod.rs b/src/unix/bsd/netbsdlike/openbsd/mod.rs index 8f470aff9a357..1809384e4b6a3 100644 --- a/src/unix/bsd/netbsdlike/openbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/openbsd/mod.rs @@ -2018,15 +2018,6 @@ extern "C" { atflag: ::c_int, ) -> ::c_int; pub fn dirfd(dirp: *mut ::DIR) -> ::c_int; - pub fn getnameinfo( - sa: *const ::sockaddr, - salen: ::socklen_t, - host: *mut ::c_char, - hostlen: ::size_t, - serv: *mut ::c_char, - servlen: ::size_t, - flags: ::c_int, - ) -> ::c_int; pub fn getresgid(rgid: *mut ::gid_t, egid: *mut ::gid_t, sgid: *mut ::gid_t) -> ::c_int; pub fn getresuid(ruid: *mut ::uid_t, euid: *mut ::uid_t, suid: *mut ::uid_t) -> ::c_int; pub fn kevent(