Skip to content

Commit

Permalink
Merge pull request #3827 from tgross35/backport-beetroot
Browse files Browse the repository at this point in the history
Backport beetroot
  • Loading branch information
tgross35 authored Aug 15, 2024
2 parents 07559cf + 66cdb6b commit ee3c3df
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 22 deletions.
11 changes: 7 additions & 4 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -2093,19 +2096,19 @@ 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
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
Expand Down
5 changes: 5 additions & 0 deletions libc-test/semver/wasi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
fd_set
FD_SET
FD_ZERO
FD_ISSET
select
4 changes: 4 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 11 additions & 0 deletions src/unix/bsd/netbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
9 changes: 0 additions & 9 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 0 additions & 9 deletions src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
35 changes: 35 additions & 0 deletions src/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ee3c3df

Please sign in to comment.