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/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 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; 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( 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;