diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index c8320056f15fc..d4ca406ffe918 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -240,6 +240,11 @@ jobs: # FIXME(ppc): SIGILL running tests, see # https://github.com/rust-lang/libc/pull/4254#issuecomment-2636288713 # - target: powerpc-unknown-linux-gnu + - target: aarch64-apple-ios-sim + os: macos-26 + cargo-apple-runner: true + simulator: "iPhone 17" + env: { CARGO_TARGET_AARCH64_APPLE_IOS_SIM_RUNNER: cargo-apple-runner } runs-on: ${{ matrix.os && matrix.os || 'ubuntu-26.04' }} timeout-minutes: 25 env: @@ -261,6 +266,16 @@ jobs: jq -r 'to_entries | map("\(.key)=\(.value|tostring)") | .[]' >>$GITHUB_ENV shell: bash + - name: Install `cargo-apple-runner` + if: matrix.cargo-apple-runner + uses: taiki-e/install-action@0631aa6515c7d545823c67cfae7ef4fc7f490154 # v2.81.8 + with: + tool: cargo-apple-runner + + - name: Start simulator + if: matrix.simulator + run: xcrun simctl boot "${{ matrix.simulator }}" + - name: Run natively if: runner.os != 'Linux' run: ./ci/run.sh ${{ matrix.target }} diff --git a/ci/README.md b/ci/README.md index 4e5b552d58892..7093b6fe7c8a4 100644 --- a/ci/README.md +++ b/ci/README.md @@ -37,13 +37,13 @@ The remaining architectures look like: the generated binary to actually verify the tests pass. * The MUSL build just has to download a MUSL compiler and target libraries and then otherwise runs tests normally. -* iOS builds need an extra linker flag currently, but beyond that they're built - as standard as everything else. +* iOS is tested using [`cargo-apple-runner`][cargo-apple-runner]. * The BSD builds, currently OpenBSD and FreeBSD, use QEMU to boot up a system and compile/run tests. More information on that below. [Actions config]: https://github.com/rust-lang/libc/tree/HEAD/.github/workflows [android-docker]: https://github.com/rust-lang/libc/blob/HEAD/ci/docker/x86_64-linux-android/Dockerfile +[cargo-apple-runner]: https://github.com/madsmtm/cargo-apple-runner ## QEMU diff --git a/ci/ios/deploy_and_run_on_ios_simulator.rs b/ci/ios/deploy_and_run_on_ios_simulator.rs deleted file mode 100644 index 5c2d2fbad328d..0000000000000 --- a/ci/ios/deploy_and_run_on_ios_simulator.rs +++ /dev/null @@ -1,187 +0,0 @@ -// This is a script to deploy and execute a binary on an iOS simulator. -// The primary use of this is to be able to run unit tests on the simulator and -// retrieve the results. -// -// To do this through Cargo instead, use Dinghy -// (https://github.com/snipsco/dinghy): cargo dinghy install, then cargo dinghy -// test. - -use std::fs::{ - self, - File, -}; -use std::io::Write; -use std::path::Path; -use std::process::Command; -use std::{ - env, - process, -}; - -macro_rules! t { - ($e:expr) => { - match $e { - Ok(e) => e, - Err(e) => panic!("{} failed with: {e}", stringify!($e)), - } - }; -} - -// Step one: Wrap as an app -fn package_as_simulator_app(crate_name: &str, test_binary_path: &Path) { - println!("Packaging simulator app"); - drop(fs::remove_dir_all("ios_simulator_app")); - t!(fs::create_dir("ios_simulator_app")); - t!(fs::copy( - test_binary_path, - Path::new("ios_simulator_app").join(crate_name) - )); - - let mut f = t!(File::create("ios_simulator_app/Info.plist")); - t!(f.write_all( - format!( - r#" - - - - - CFBundleExecutable - {} - CFBundleIdentifier - com.rust.unittests - - - "#, - crate_name - ) - .as_bytes() - )); -} - -// Step two: Start the iOS simulator -fn start_simulator() { - println!("Looking for iOS simulator"); - let output = t!(Command::new("xcrun").arg("simctl").arg("list").output()); - assert!(output.status.success()); - let mut simulator_exists = false; - let mut simulator_booted = false; - let mut found_rust_sim = false; - let stdout = t!(String::from_utf8(output.stdout)); - for line in stdout.lines() { - if line.contains("rust_ios") { - if found_rust_sim { - panic!( - "Duplicate rust_ios simulators found. Please \ - double-check xcrun simctl list." - ); - } - simulator_exists = true; - simulator_booted = line.contains("(Booted)"); - found_rust_sim = true; - } - } - - if simulator_exists == false { - println!("Creating iOS simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("create") - .arg("rust_ios") - .arg("com.apple.CoreSimulator.SimDeviceType.iPhone-SE") - .arg("com.apple.CoreSimulator.SimRuntime.iOS-10-2") - .check_status(); - } else if simulator_booted == true { - println!("Shutting down already-booted simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("shutdown") - .arg("rust_ios") - .check_status(); - } - - println!("Starting iOS simulator"); - // We can't uninstall the app (if present) as that will hang if the - // simulator isn't completely booted; just erase the simulator instead. - Command::new("xcrun") - .arg("simctl") - .arg("erase") - .arg("rust_ios") - .check_status(); - Command::new("xcrun") - .arg("simctl") - .arg("boot") - .arg("rust_ios") - .check_status(); -} - -// Step three: Install the app -fn install_app_to_simulator() { - println!("Installing app to simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("install") - .arg("booted") - .arg("ios_simulator_app/") - .check_status(); -} - -// Step four: Run the app -fn run_app_on_simulator() { - println!("Running app"); - let output = t!(Command::new("xcrun") - .arg("simctl") - .arg("launch") - .arg("--console") - .arg("booted") - .arg("com.rust.unittests") - .output()); - - println!("status: {}", output.status); - println!("stdout --\n{}\n", String::from_utf8_lossy(&output.stdout)); - println!("stderr --\n{}\n", String::from_utf8_lossy(&output.stderr)); - - let stdout = String::from_utf8_lossy(&output.stdout); - let passed = stdout - .lines() - .find(|l| (l.contains("PASSED") && l.contains("tests")) || l.contains("test result: ok")) - .unwrap_or(false); - - println!("Shutting down simulator"); - Command::new("xcrun") - .arg("simctl") - .arg("shutdown") - .arg("rust_ios") - .check_status(); - if !passed { - panic!("tests didn't pass"); - } -} - -trait CheckStatus { - fn check_status(&mut self); -} - -impl CheckStatus for Command { - fn check_status(&mut self) { - println!("\trunning: {self:?}"); - assert!(t!(self.status()).success()); - } -} - -fn main() { - let args: Vec = env::args().collect(); - if args.len() != 2 { - println!("Usage: {} ", args[0]); - process::exit(-1); - } - - let test_binary_path = Path::new(&args[1]); - let crate_name = test_binary_path.file_name().unwrap(); - - package_as_simulator_app(crate_name.to_str().unwrap(), test_binary_path); - start_simulator(); - install_app_to_simulator(); - run_app_on_simulator(); -} diff --git a/ci/run.sh b/ci/run.sh index c3a726b4c88b6..955b1f92d7cbf 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -26,6 +26,9 @@ case "$target" in # FIXME(android): unit tests fail to start on Android *android*) cmd="$cmd --manifest-path libc-test/Cargo.toml" ;; *s390x*) cmd="$cmd --manifest-path libc-test/Cargo.toml" ;; + # ctest's own tests don't work on Apple devices, since these don't have + # host tooling such as `rustc` or a C compiler. + *ios*|*tvos*|*watchos*|*visionos*) cmd="$cmd --workspace --exclude ctest" ;; # For all other platforms, test everything in the workspace *) cmd="$cmd --workspace" ;; esac diff --git a/libc-test/build.rs b/libc-test/build.rs index 6e171b6f4808f..f259faa277bd4 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -209,6 +209,9 @@ fn test_apple(target: &str) { assert!(target.contains("apple")); let x86_64 = target.contains("x86_64"); let i686 = target.contains("i686"); + let macos = target.contains("darwin") || target.contains("macos"); + let tvos = target.contains("tvos"); + let watchos = target.contains("watchos"); let mut cfg = ctest_cfg(); @@ -236,27 +239,29 @@ fn test_apple(target: &str) { "ifaddrs.h", "langinfo.h", "libgen.h", - "libproc.h", + (macos, "libproc.h"), "limits.h", "locale.h", + "mach/mach.h", "malloc/malloc.h", - "net/bpf.h", - "net/dlil.h", + (macos, "net/bpf.h"), + (macos, "net/dlil.h"), "net/if.h", - "net/if_arp.h", + (macos, "net/if_arp.h"), "net/if_dl.h", - "net/if_mib.h", - "net/if_utun.h", + (macos, "net/if_mib.h"), + (macos, "net/if_utun.h"), "net/if_var.h", - "net/ndrv.h", - "net/route.h", + (macos, "net/ndrv.h"), + (macos, "net/route.h"), "netdb.h", - "netinet/if_ether.h", + (macos, "netinet/if_ether.h"), "netinet/in.h", "netinet/ip.h", "netinet/tcp.h", "netinet/udp.h", - "netinet6/in6_var.h", + "netinet6/scope6_var.h", + (macos, "netinet6/in6_var.h"), "os/clock.h", "os/lock.h", "os/signpost.h", @@ -287,20 +292,20 @@ fn test_apple(target: &str) { "sys/file.h", "sys/ioctl.h", "sys/ipc.h", - "sys/kern_control.h", + (macos, "sys/kern_control.h"), "sys/mman.h", "sys/mount.h", - "sys/proc_info.h", - "sys/ptrace.h", + (macos, "sys/proc_info.h"), + (macos, "sys/ptrace.h"), "sys/quota.h", - "sys/random.h", + (macos, "sys/random.h"), "sys/resource.h", "sys/sem.h", "sys/shm.h", "sys/socket.h", "sys/stat.h", "sys/statvfs.h", - "sys/sys_domain.h", + (macos, "sys/sys_domain.h"), "sys/sysctl.h", "sys/time.h", "sys/times.h", @@ -321,7 +326,7 @@ fn test_apple(target: &str) { "utmpx.h", "wchar.h", "xlocale.h", - (x86_64, "crt_externs.h"), + "crt_externs.h", ); cfg.skip_struct(move |s| { @@ -377,6 +382,26 @@ fn test_apple(target: &str) { "close" if x86_64 => true, // FIXME(1.0): std removed libresolv support: https://github.com/rust-lang/rust/pull/102766 "res_init" => true, + // Marked available everywhere, but the `sys/random.h` header only + // exists on the macOS SDK. + // FIXME(madsmtm): Filed as FB23000895. + "getentropy" => !macos, + // Prohibited on iOS, tvOS, watchOS and visionOS. + // FIXME(madsmtm): Perhaps we should just not expose this symbol? + "system" => !macos, + // Marked unavailable on iOS, tvOS, watchOS and visionOS. + // FIXME(madsmtm): Perhaps we should just not expose these symbols? + "pthread_jit_write_protect_np" + | "pthread_jit_write_protect_supported_np" + | "pthread_jit_write_with_callback_np" + | "pthread_jit_write_freeze_callbacks_np" + | "gethostuuid" => !macos, + // Marked as unavailable on tvOS and watchOS. + // FIXME(madsmtm): Perhaps we should just not expose this symbol? + "execl" | "execle" | "execlp" | "execv" | "execve" | "execvp" | "execvP" | "fork" + | "sigaltstack" | "syscall" | "daemon" | "brk" | "sbrk" | "task_set_info" + | "exchangedata" => tvos || watchos, + ident if ident.starts_with("posix_spawn") => tvos || watchos, _ => false, } }); diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index cf1d92de132dc..3340063832a29 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -46,7 +46,6 @@ AF_ROUTE AF_SIP AF_SNA AF_SYSTEM -AF_SYS_CONTROL AIO_ALLDONE AIO_CANCELED AIO_LISTIO_MAX @@ -65,12 +64,6 @@ AI_V4MAPPED_CFG ALTWERASE ALT_DIGITS AM_STR -ARPOP_REPLY -ARPOP_REQUEST -ATF_COM -ATF_PERM -ATF_PUBL -ATF_USETRAILERS ATTR_BIT_MAP_COUNT ATTR_CMNEXT_CLONEID ATTR_CMNEXT_EXT_FLAGS @@ -162,30 +155,7 @@ B14400 B28800 B7200 B76800 -BIOCFLUSH -BIOCGBLEN -BIOCGDLT -BIOCGDLTLIST -BIOCGETIF -BIOCGHDRCMPLT -BIOCGRSIG -BIOCGRTIMEOUT -BIOCGSEESENT -BIOCGSTATS -BIOCIMMEDIATE -BIOCPROMISC -BIOCSBLEN -BIOCSDLT -BIOCSETF -BIOCSETFNR -BIOCSETIF -BIOCSHDRCMPLT -BIOCSRSIG -BIOCSRTIMEOUT -BIOCSSEESENT -BIOCVERSION BOOT_TIME -BPF_ALIGNMENT BS0 BS1 BSDLY @@ -279,7 +249,6 @@ CTLFLAG_RD CTLFLAG_RW CTLFLAG_SECURE CTLFLAG_WR -CTLIOCGINFO CTLTYPE CTLTYPE_INT CTLTYPE_NODE @@ -309,20 +278,6 @@ DAY_6 DAY_7 DEAD_PROCESS DIR_MNTSTATUS_MNTPOINT -DLT_ARCNET -DLT_ATM_RFC1483 -DLT_AX25 -DLT_CHAOS -DLT_EN10MB -DLT_EN3MB -DLT_FDDI -DLT_IEEE802 -DLT_LOOP -DLT_NULL -DLT_PPP -DLT_PRONET -DLT_RAW -DLT_SLIP DT_UNKNOWN D_FMT D_MD_ORDER @@ -1125,12 +1080,6 @@ PRIO_DARWIN_BG PRIO_DARWIN_NONUI PRIO_DARWIN_PROCESS PRIO_DARWIN_THREAD -PROC_CSM_ALL -PROC_CSM_NOSMT -PROC_CSM_TECS -PROC_PIDTASKALLINFO -PROC_PIDTASKINFO -PROC_PIDTHREADINFO PTHREAD_CANCELED PTHREAD_CANCEL_ASYNCHRONOUS PTHREAD_CANCEL_DEFERRED @@ -1155,24 +1104,6 @@ PTHREAD_PROCESS_SHARED PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_SYSTEM PTHREAD_STACK_MIN -PT_ATTACH -PT_ATTACHEXC -PT_CONTINUE -PT_DENY_ATTACH -PT_DETACH -PT_FIRSTMACH -PT_FORCEQUOTA -PT_KILL -PT_READ_D -PT_READ_I -PT_READ_U -PT_SIGEXC -PT_STEP -PT_THUPDATE -PT_TRACE_ME -PT_WRITE_D -PT_WRITE_I -PT_WRITE_U P_ALL P_PGID P_PID @@ -1230,86 +1161,11 @@ RLIMIT_RSS RLIMIT_STACK RLIM_INFINITY RLIM_NLIMITS -RTAX_AUTHOR -RTAX_BRD -RTAX_DST -RTAX_GATEWAY -RTAX_GENMASK -RTAX_IFA -RTAX_IFP -RTAX_MAX -RTAX_NETMASK -RTA_AUTHOR -RTA_BRD -RTA_DST -RTA_GATEWAY -RTA_GENMASK -RTA_IFA -RTA_IFP -RTA_NETMASK -RTF_BLACKHOLE -RTF_BROADCAST -RTF_CLONING -RTF_CONDEMNED -RTF_DEAD -RTF_DELCLONE -RTF_DONE -RTF_DYNAMIC -RTF_GATEWAY -RTF_GLOBAL -RTF_HOST -RTF_IFREF -RTF_IFSCOPE -RTF_LLINFO -RTF_LOCAL -RTF_MODIFIED -RTF_MULTICAST -RTF_NOIFREF -RTF_PINNED -RTF_PRCLONING -RTF_PROTO1 -RTF_PROTO2 -RTF_PROTO3 -RTF_PROXY -RTF_REJECT -RTF_ROUTER -RTF_STATIC -RTF_UP -RTF_WASCLONED -RTF_XRESOLVE RTLD_FIRST RTLD_NEXT RTLD_NODELETE RTLD_NOLOAD RTLD_SELF -RTM_ADD -RTM_CHANGE -RTM_DELADDR -RTM_DELETE -RTM_DELMADDR -RTM_GET -RTM_GET2 -RTM_IFINFO -RTM_IFINFO2 -RTM_LOCK -RTM_LOSING -RTM_MISS -RTM_NEWADDR -RTM_NEWMADDR -RTM_NEWMADDR2 -RTM_OLDADD -RTM_OLDDEL -RTM_REDIRECT -RTM_RESOLVE -RTM_VERSION -RTV_EXPIRE -RTV_HOPCOUNT -RTV_MTU -RTV_RPIPE -RTV_RTT -RTV_RTTVAR -RTV_SPIPE -RTV_SSTHRESH RUN_LVL RUSAGE_CHILDREN RUSAGE_SELF @@ -1348,7 +1204,6 @@ SIGINFO SIGIO SIGNATURE SIGSTKSZ -SIOCGIFADDR SOCK_MAXADDRLEN SOCK_RAW SOCK_RDM @@ -1394,8 +1249,6 @@ STA_RONLY STA_UNSYNC ST_NOSUID ST_RDONLY -SYSPROTO_CONTROL -SYSPROTO_EVENT S_IEXEC S_IREAD S_IWRITE @@ -1553,8 +1406,6 @@ USER_STREAM_MAX USER_TZNAME_MAX UTIME_NOW UTIME_OMIT -UTUN_OPT_FLAGS -UTUN_OPT_IFNAME VDISCARD VDSUSP VLNEXT @@ -1811,7 +1662,6 @@ aiocb arc4random arc4random_buf arc4random_uniform -arphdr asctime asctime_r attrgroup_t @@ -1825,7 +1675,6 @@ backtrace_symbols backtrace_symbols_fd basename boolean_t -bpf_hdr brk bsearch chflags @@ -1847,7 +1696,6 @@ cpu_subtype_t cpu_type_t ctime ctime_r -ctl_info devname difftime dirfd @@ -1928,7 +1776,6 @@ globfree host_cpu_load_info host_cpu_load_info_data_t host_cpu_load_info_t -icmp6_ifstat iconv_t id_t idtype_t @@ -1941,9 +1788,6 @@ ifconf ifkpi ifreq image_offset -in6_addrlifetime -in6_ifreq -in6_ifstat in6_pktinfo in_pktinfo initgroups @@ -2070,27 +1914,6 @@ posix_spawnattr_setsigmask posix_spawnattr_t posix_spawnp preadv -proc_bsdinfo -proc_bsdshortinfo -proc_kmsgbuf -proc_libversion -proc_listallpids -proc_listchildpids -proc_listpgrppids -proc_listpids -proc_name -proc_pidfdinfo -proc_pidfileportinfo -proc_pidinfo -proc_pidpath -proc_regionfilename -proc_set_csm -proc_set_no_smt -proc_setthread_csm -proc_setthread_no_smt -proc_taskallinfo -proc_taskinfo -proc_threadinfo pseudo_AF_HDRCMPLT pseudo_AF_KEY pseudo_AF_PIP @@ -2142,7 +1965,6 @@ pthread_set_qos_class_self_np pthread_setname_np pthread_setschedparam pthread_stack_frame_decode_np -ptrace pututxline pwritev qsort @@ -2213,9 +2035,7 @@ sigevent siginfo_t sigsuspend sigwait -sockaddr_ctl sockaddr_dl -sockaddr_inarp srand stack_t statfs diff --git a/libc-test/semver/macos.txt b/libc-test/semver/macos.txt index 048c8a120329b..b2489021c9ed4 100644 --- a/libc-test/semver/macos.txt +++ b/libc-test/semver/macos.txt @@ -1,7 +1,187 @@ +AF_SYS_CONTROL +ARPOP_REPLY +ARPOP_REQUEST +ATF_COM +ATF_PERM +ATF_PUBL +ATF_USETRAILERS +BIOCFLUSH +BIOCGBLEN +BIOCGDLT +BIOCGDLTLIST +BIOCGETIF +BIOCGHDRCMPLT +BIOCGRSIG +BIOCGRTIMEOUT +BIOCGSEESENT +BIOCGSTATS +BIOCIMMEDIATE +BIOCPROMISC +BIOCSBLEN +BIOCSDLT +BIOCSETF +BIOCSETFNR +BIOCSETIF +BIOCSHDRCMPLT +BIOCSRSIG +BIOCSRTIMEOUT +BIOCSSEESENT +BIOCVERSION +BPF_ALIGNMENT CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC_RAW_APPROX CLOCK_UPTIME_RAW CLOCK_UPTIME_RAW_APPROX +CTLIOCGINFO +DLT_ARCNET +DLT_ATM_RFC1483 +DLT_AX25 +DLT_CHAOS +DLT_EN10MB +DLT_EN3MB +DLT_FDDI +DLT_IEEE802 +DLT_LOOP +DLT_NULL +DLT_PPP +DLT_PRONET +DLT_RAW +DLT_SLIP +PROC_CSM_ALL +PROC_CSM_NOSMT +PROC_CSM_TECS +PROC_PIDTASKALLINFO +PROC_PIDTASKINFO +PROC_PIDTHREADINFO +PT_ATTACH +PT_ATTACHEXC +PT_CONTINUE +PT_DENY_ATTACH +PT_DETACH +PT_FIRSTMACH +PT_FORCEQUOTA +PT_KILL +PT_READ_D +PT_READ_I +PT_READ_U +PT_SIGEXC +PT_STEP +PT_THUPDATE +PT_TRACE_ME +PT_WRITE_D +PT_WRITE_I +PT_WRITE_U +RTAX_AUTHOR +RTAX_BRD +RTAX_DST +RTAX_GATEWAY +RTAX_GENMASK +RTAX_IFA +RTAX_IFP +RTAX_MAX +RTAX_NETMASK +RTA_AUTHOR +RTA_BRD +RTA_DST +RTA_GATEWAY +RTA_GENMASK +RTA_IFA +RTA_IFP +RTA_NETMASK +RTF_BLACKHOLE +RTF_BROADCAST +RTF_CLONING +RTF_CONDEMNED +RTF_DEAD +RTF_DELCLONE +RTF_DONE +RTF_DYNAMIC +RTF_GATEWAY +RTF_GLOBAL +RTF_HOST +RTF_IFREF +RTF_IFSCOPE +RTF_LLINFO +RTF_LOCAL +RTF_MODIFIED +RTF_MULTICAST +RTF_NOIFREF +RTF_PINNED +RTF_PRCLONING +RTF_PROTO1 +RTF_PROTO2 +RTF_PROTO3 +RTF_PROXY +RTF_REJECT +RTF_ROUTER +RTF_STATIC +RTF_UP +RTF_WASCLONED +RTF_XRESOLVE +RTM_ADD +RTM_CHANGE +RTM_DELADDR +RTM_DELETE +RTM_DELMADDR +RTM_GET +RTM_GET2 +RTM_IFINFO +RTM_IFINFO2 +RTM_LOCK +RTM_LOSING +RTM_MISS +RTM_NEWADDR +RTM_NEWMADDR +RTM_NEWMADDR2 +RTM_OLDADD +RTM_OLDDEL +RTM_REDIRECT +RTM_RESOLVE +RTM_VERSION +RTV_EXPIRE +RTV_HOPCOUNT +RTV_MTU +RTV_RPIPE +RTV_RTT +RTV_RTTVAR +RTV_SPIPE +RTV_SSTHRESH +SIOCGIFADDR +SYSPROTO_CONTROL +SYSPROTO_EVENT +UTUN_OPT_FLAGS +UTUN_OPT_IFNAME +arphdr +bpf_hdr clock_settime +ctl_info +icmp6_ifstat +in6_addrlifetime +in6_ifreq +in6_ifstat memmem +proc_bsdinfo +proc_bsdshortinfo +proc_kmsgbuf +proc_libversion +proc_listallpids +proc_listchildpids +proc_listpgrppids +proc_listpids +proc_name +proc_pidfdinfo +proc_pidfileportinfo +proc_pidinfo +proc_pidpath +proc_regionfilename +proc_set_csm +proc_set_no_smt +proc_setthread_csm +proc_setthread_no_smt +proc_taskallinfo +proc_taskinfo +proc_threadinfo +ptrace +sockaddr_ctl +sockaddr_inarp task_set_info diff --git a/libc-test/tests/style.rs b/libc-test/tests/style.rs index 3cc70586d15e8..be734f2a1184a 100644 --- a/libc-test/tests/style.rs +++ b/libc-test/tests/style.rs @@ -29,6 +29,15 @@ const SKIP_PREFIXES: &[&str] = &[ ]; #[test] +#[cfg_attr( + any( + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + ), + ignore = "source code is not available for cross-compiled tests" +)] fn check_style() { let src_root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../src"); walk(&src_root).unwrap(); diff --git a/src/unix/bsd/apple/b32/mod.rs b/src/unix/bsd/apple/b32/mod.rs index ab0c94ef4c2c2..2b89825479155 100644 --- a/src/unix/bsd/apple/b32/mod.rs +++ b/src/unix/bsd/apple/b32/mod.rs @@ -37,6 +37,7 @@ s! { pub ifi_reserved2: u32, } + #[cfg(target_os = "macos")] pub struct bpf_hdr { pub bh_tstamp: crate::timeval, pub bh_caplen: u32, @@ -63,10 +64,14 @@ pub const NET_RT_MAXID: c_int = 10; pub const TIOCTIMESTAMP: c_ulong = 0x40087459; pub const TIOCDCDTIMESTAMP: c_ulong = 0x40087458; -pub const BIOCSETF: c_ulong = 0x80084267; -pub const BIOCSRTIMEOUT: c_ulong = 0x8008426d; -pub const BIOCGRTIMEOUT: c_ulong = 0x4008426e; -pub const BIOCSETFNR: c_ulong = 0x8008427e; +cfg_if! { + if #[cfg(target_os = "macos")] { + pub const BIOCSETF: c_ulong = 0x80084267; + pub const BIOCSRTIMEOUT: c_ulong = 0x8008426d; + pub const BIOCGRTIMEOUT: c_ulong = 0x4008426e; + pub const BIOCSETFNR: c_ulong = 0x8008427e; + } +} extern "C" { pub fn exchangedata(path1: *const c_char, path2: *const c_char, options: c_ulong) -> c_int; diff --git a/src/unix/bsd/apple/b64/mod.rs b/src/unix/bsd/apple/b64/mod.rs index 5ccf65abb840e..cf112059b953c 100644 --- a/src/unix/bsd/apple/b64/mod.rs +++ b/src/unix/bsd/apple/b64/mod.rs @@ -41,6 +41,7 @@ s! { pub ifi_reserved2: u32, } + #[cfg(target_os = "macos")] pub struct bpf_hdr { pub bh_tstamp: crate::timeval32, pub bh_caplen: u32, @@ -56,10 +57,14 @@ pub const NET_RT_MAXID: c_int = 11; pub const TIOCTIMESTAMP: c_ulong = 0x40107459; pub const TIOCDCDTIMESTAMP: c_ulong = 0x40107458; -pub const BIOCSETF: c_ulong = 0x80104267; -pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; -pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; -pub const BIOCSETFNR: c_ulong = 0x8010427e; +cfg_if! { + if #[cfg(target_os = "macos")] { + pub const BIOCSETF: c_ulong = 0x80104267; + pub const BIOCSRTIMEOUT: c_ulong = 0x8010426d; + pub const BIOCGRTIMEOUT: c_ulong = 0x4010426e; + pub const BIOCSETFNR: c_ulong = 0x8010427e; + } +} extern "C" { pub fn exchangedata(path1: *const c_char, path2: *const c_char, options: c_uint) -> c_int; diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index f0bd543bf6df8..a9b429ae7bc41 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -461,6 +461,7 @@ s! { pub ifmam_refcount: i32, } + #[cfg(target_os = "macos")] pub struct rt_metrics { pub rmx_locks: u32, pub rmx_mtu: u32, @@ -475,6 +476,7 @@ s! { pub rmx_filler: [u32; 4], } + #[cfg(target_os = "macos")] pub struct rt_msghdr { pub rtm_msglen: c_ushort, pub rtm_version: c_uchar, @@ -490,6 +492,7 @@ s! { pub rtm_rmx: rt_metrics, } + #[cfg(target_os = "macos")] pub struct rt_msghdr2 { pub rtm_msglen: c_ushort, pub rtm_version: c_uchar, @@ -557,6 +560,7 @@ s! { pub int_n_sign_posn: c_char, } + #[cfg(target_os = "macos")] pub struct proc_taskinfo { pub pti_virtual_size: u64, pub pti_resident_size: u64, @@ -578,6 +582,7 @@ s! { pub pti_priority: i32, } + #[cfg(target_os = "macos")] pub struct proc_bsdinfo { pub pbi_flags: u32, pub pbi_status: u32, @@ -603,6 +608,7 @@ s! { pub pbi_start_tvusec: u64, } + #[cfg(target_os = "macos")] pub struct proc_bsdshortinfo { /// Process ID. pub pbsi_pid: u32, @@ -632,6 +638,7 @@ s! { pbsi_rfu: u32, } + #[cfg(target_os = "macos")] pub struct proc_taskallinfo { pub pbsd: proc_bsdinfo, pub ptinfo: proc_taskinfo, @@ -696,6 +703,7 @@ s! { pub sdl_data: [c_char; 12], } + #[cfg(target_os = "macos")] pub struct sockaddr_inarp { pub sin_len: c_uchar, pub sin_family: c_uchar, @@ -706,6 +714,7 @@ s! { pub sin_other: c_ushort, } + #[cfg(target_os = "macos")] pub struct sockaddr_ctl { pub sc_len: c_uchar, pub sc_family: c_uchar, @@ -739,15 +748,14 @@ s! { } // sys/sem.h - pub struct sembuf { pub sem_num: c_ushort, pub sem_op: c_short, pub sem_flg: c_short, } - // sys/shm.h - + // sys/if_arp.h + #[cfg(target_os = "macos")] pub struct arphdr { pub ar_hrd: u16, pub ar_pro: u16, @@ -761,6 +769,7 @@ s! { } // net/ndrv.h + #[cfg(target_os = "macos")] pub struct sockaddr_ndrv { pub snd_len: c_uchar, pub snd_family: c_uchar, @@ -861,6 +870,7 @@ s! { pub size: crate::vm_size_t, } + #[cfg(target_os = "macos")] pub struct vinfo_stat { pub vst_dev: u32, pub vst_mode: u16, @@ -885,6 +895,7 @@ s! { pub vst_qspare: [i64; 2], } + #[cfg(target_os = "macos")] pub struct vnode_info { pub vi_stat: vinfo_stat, pub vi_type: c_int, @@ -892,11 +903,13 @@ s! { pub vi_fsid: crate::fsid_t, } + #[cfg(target_os = "macos")] pub struct vnode_info_path { pub vip_vi: vnode_info, pub vip_path: [c_char; crate::MAXPATHLEN as usize], } + #[cfg(target_os = "macos")] pub struct proc_vnodepathinfo { pub pvi_cdir: vnode_info_path, pub pvi_rdir: vnode_info_path, @@ -1132,6 +1145,7 @@ s! { pub tcpi_rxretransmitpackets: u64, } + #[cfg(target_os = "macos")] pub struct in6_addrlifetime { pub ia6t_expire: time_t, pub ia6t_preferred: time_t, @@ -1139,6 +1153,7 @@ s! { pub ia6t_pltime: u32, } + #[cfg(target_os = "macos")] pub struct in6_ifstat { pub ifs6_in_receive: crate::u_quad_t, pub ifs6_in_hdrerr: crate::u_quad_t, @@ -1167,6 +1182,7 @@ s! { pub ifs6_defrtr_expiry_cnt: crate::u_quad_t, } + #[cfg(target_os = "macos")] pub struct icmp6_ifstat { pub ifs6_in_msg: crate::u_quad_t, pub ifs6_in_error: crate::u_quad_t, @@ -1210,6 +1226,7 @@ s! { } // net/if_mib.h + #[cfg(target_os = "macos")] pub struct ifmibdata { /// Name of interface pub ifmd_name: [c_char; crate::IFNAMSIZ], @@ -1229,6 +1246,7 @@ s! { pub ifmd_data: if_data64, } + #[cfg(target_os = "macos")] pub struct ifs_iso_8802_3 { pub dot3StatsAlignmentErrors: u32, pub dot3StatsFCSErrors: u32, @@ -1249,12 +1267,14 @@ s! { } // kern_control.h + #[cfg(target_os = "macos")] pub struct ctl_info { pub ctl_id: u32, pub ctl_name: [c_char; MAX_KCTL_NAME], } // sys/proc_info.h + #[cfg(target_os = "macos")] pub struct proc_fdinfo { pub proc_fd: i32, pub proc_fdtype: u32, @@ -1297,6 +1317,7 @@ s! { pub shm_internal: *mut c_void, } + #[cfg(target_os = "macos")] pub struct proc_threadinfo { pub pth_user_time: u64, pub pth_system_time: u64, @@ -1551,6 +1572,7 @@ s! { pub ifr_ifru: __c_anonymous_ifr_ifru, } + #[cfg(target_os = "macos")] pub struct in6_ifreq { pub ifr_name: [c_char; crate::IFNAMSIZ], pub ifr_ifru: __c_anonymous_ifr_ifru6, @@ -1591,19 +1613,25 @@ s_no_extra_traits! { pub ifcu_buf: *mut c_char, pub ifcu_req: *mut ifreq, } +} - pub union __c_anonymous_ifr_ifru6 { - pub ifru_addr: crate::sockaddr_in6, - pub ifru_dstaddr: crate::sockaddr_in6, - pub ifru_flags: c_int, - pub ifru_flags6: c_int, - pub ifru_metrics: c_int, - pub ifru_intval: c_int, - pub ifru_data: *mut c_char, - pub ifru_lifetime: in6_addrlifetime, - pub ifru_stat: in6_ifstat, - pub ifru_icmp6stat: icmp6_ifstat, - pub ifru_scope_id: [u32; SCOPE6_ID_MAX], +cfg_if! { + if #[cfg(target_os = "macos")] { + s_no_extra_traits! { + pub union __c_anonymous_ifr_ifru6 { + pub ifru_addr: crate::sockaddr_in6, + pub ifru_dstaddr: crate::sockaddr_in6, + pub ifru_flags: c_int, + pub ifru_flags6: c_int, + pub ifru_metrics: c_int, + pub ifru_intval: c_int, + pub ifru_data: *mut c_char, + pub ifru_lifetime: in6_addrlifetime, + pub ifru_stat: in6_ifstat, + pub ifru_icmp6stat: icmp6_ifstat, + pub ifru_scope_id: [u32; SCOPE6_ID_MAX], + } + } } } @@ -1731,6 +1759,7 @@ cfg_if! { } } + #[cfg(target_os = "macos")] impl PartialEq for __c_anonymous_ifr_ifru6 { fn eq(&self, other: &__c_anonymous_ifr_ifru6) -> bool { unsafe { @@ -1750,8 +1779,10 @@ cfg_if! { } } + #[cfg(target_os = "macos")] impl Eq for __c_anonymous_ifr_ifru6 {} + #[cfg(target_os = "macos")] impl hash::Hash for __c_anonymous_ifr_ifru6 { fn hash(&self, state: &mut H) { unsafe { @@ -1983,25 +2014,30 @@ pub const PROT_READ: c_int = 1; pub const PROT_WRITE: c_int = 2; pub const PROT_EXEC: c_int = 4; -pub const PT_TRACE_ME: c_int = 0; -pub const PT_READ_I: c_int = 1; -pub const PT_READ_D: c_int = 2; -pub const PT_READ_U: c_int = 3; -pub const PT_WRITE_I: c_int = 4; -pub const PT_WRITE_D: c_int = 5; -pub const PT_WRITE_U: c_int = 6; -pub const PT_CONTINUE: c_int = 7; -pub const PT_KILL: c_int = 8; -pub const PT_STEP: c_int = 9; -pub const PT_ATTACH: c_int = 10; -pub const PT_DETACH: c_int = 11; -pub const PT_SIGEXC: c_int = 12; -pub const PT_THUPDATE: c_int = 13; -pub const PT_ATTACHEXC: c_int = 14; - -pub const PT_FORCEQUOTA: c_int = 30; -pub const PT_DENY_ATTACH: c_int = 31; -pub const PT_FIRSTMACH: c_int = 32; +cfg_if! { + if #[cfg(target_os = "macos")] { + // ptrace.h + pub const PT_TRACE_ME: c_int = 0; + pub const PT_READ_I: c_int = 1; + pub const PT_READ_D: c_int = 2; + pub const PT_READ_U: c_int = 3; + pub const PT_WRITE_I: c_int = 4; + pub const PT_WRITE_D: c_int = 5; + pub const PT_WRITE_U: c_int = 6; + pub const PT_CONTINUE: c_int = 7; + pub const PT_KILL: c_int = 8; + pub const PT_STEP: c_int = 9; + pub const PT_ATTACH: c_int = 10; + pub const PT_DETACH: c_int = 11; + pub const PT_SIGEXC: c_int = 12; + pub const PT_THUPDATE: c_int = 13; + pub const PT_ATTACHEXC: c_int = 14; + + pub const PT_FORCEQUOTA: c_int = 30; + pub const PT_DENY_ATTACH: c_int = 31; + pub const PT_FIRSTMACH: c_int = 32; + } +} pub const MAP_FILE: c_int = 0x0000; pub const MAP_SHARED: c_int = 0x0001; @@ -2266,12 +2302,17 @@ pub const TIOCSETA: c_ulong = 0x80487414; pub const TIOCSETAW: c_ulong = 0x80487415; pub const TIOCSETAF: c_ulong = 0x80487416; -pub const BIOCGRSIG: c_ulong = 0x40044272; -pub const BIOCSRSIG: c_ulong = 0x80044273; -pub const BIOCSDLT: c_ulong = 0x80044278; -pub const BIOCGSEESENT: c_ulong = 0x40044276; -pub const BIOCSSEESENT: c_ulong = 0x80044277; -pub const BIOCGDLTLIST: c_ulong = 0xc00c4279; +cfg_if! { + if #[cfg(target_os = "macos")] { + // net/bpf.h + pub const BIOCGRSIG: c_ulong = 0x40044272; + pub const BIOCSRSIG: c_ulong = 0x80044273; + pub const BIOCSDLT: c_ulong = 0x80044278; + pub const BIOCGSEESENT: c_ulong = 0x40044276; + pub const BIOCSSEESENT: c_ulong = 0x80044277; + pub const BIOCGDLTLIST: c_ulong = 0xc00c4279; + } +} pub const FIODTYPE: c_ulong = 0x4004667a; @@ -2393,7 +2434,11 @@ pub const MINCORE_MODIFIED: c_int = 0x4; pub const MINCORE_REFERENCED_OTHER: c_int = 0x8; pub const MINCORE_MODIFIED_OTHER: c_int = 0x10; -pub const CTLIOCGINFO: c_ulong = 0xc0644e03; +cfg_if! { + if #[cfg(target_os = "macos")] { + pub const CTLIOCGINFO: c_ulong = 0xc0644e03; + } +} // // sys/netinet/in.h @@ -2653,10 +2698,15 @@ pub const pseudo_AF_HDRCMPLT: c_int = 35; pub const AF_IEEE80211: c_int = 37; pub const AF_UTUN: c_int = 38; pub const AF_VSOCK: c_int = 40; -pub const AF_SYS_CONTROL: u16 = 2; -pub const SYSPROTO_EVENT: c_int = 1; -pub const SYSPROTO_CONTROL: c_int = 2; +cfg_if! { + if #[cfg(target_os = "macos")] { + // sys/sys_domain.h + pub const AF_SYS_CONTROL: u16 = 2; + pub const SYSPROTO_EVENT: c_int = 1; + pub const SYSPROTO_CONTROL: c_int = 2; + } +} pub const PF_UNSPEC: c_int = AF_UNSPEC; pub const PF_LOCAL: c_int = AF_LOCAL; @@ -3479,82 +3529,93 @@ pub const XATTR_SHOWCOMPRESSION: c_int = 0x0020; pub const NET_RT_IFLIST2: c_int = 0x0006; -// net/route.h -pub const RTF_DELCLONE: c_int = 0x80; -pub const RTF_CLONING: c_int = 0x100; -pub const RTF_XRESOLVE: c_int = 0x200; -pub const RTF_LLINFO: c_int = 0x400; -pub const RTF_NOIFREF: c_int = 0x2000; -pub const RTF_PRCLONING: c_int = 0x10000; -pub const RTF_WASCLONED: c_int = 0x20000; -pub const RTF_PROTO3: c_int = 0x40000; -pub const RTF_PINNED: c_int = 0x100000; -pub const RTF_LOCAL: c_int = 0x200000; -pub const RTF_BROADCAST: c_int = 0x400000; -pub const RTF_MULTICAST: c_int = 0x800000; -pub const RTF_IFSCOPE: c_int = 0x1000000; -pub const RTF_CONDEMNED: c_int = 0x2000000; -pub const RTF_IFREF: c_int = 0x4000000; -pub const RTF_PROXY: c_int = 0x8000000; -pub const RTF_ROUTER: c_int = 0x10000000; -pub const RTF_DEAD: c_int = 0x20000000; -pub const RTF_GLOBAL: c_int = 0x40000000; - -pub const RTM_VERSION: c_int = 5; - -// Message types -pub const RTM_LOCK: c_int = 0x8; -pub const RTM_OLDADD: c_int = 0x9; -pub const RTM_OLDDEL: c_int = 0xa; -pub const RTM_RESOLVE: c_int = 0xb; -pub const RTM_NEWADDR: c_int = 0xc; -pub const RTM_DELADDR: c_int = 0xd; -pub const RTM_IFINFO: c_int = 0xe; -pub const RTM_NEWMADDR: c_int = 0xf; -pub const RTM_DELMADDR: c_int = 0x10; -pub const RTM_IFINFO2: c_int = 0x12; -pub const RTM_NEWMADDR2: c_int = 0x13; -pub const RTM_GET2: c_int = 0x14; - -// Bitmask values for rtm_inits and rmx_locks. -pub const RTV_MTU: c_int = 0x1; -pub const RTV_HOPCOUNT: c_int = 0x2; -pub const RTV_EXPIRE: c_int = 0x4; -pub const RTV_RPIPE: c_int = 0x8; -pub const RTV_SPIPE: c_int = 0x10; -pub const RTV_SSTHRESH: c_int = 0x20; -pub const RTV_RTT: c_int = 0x40; -pub const RTV_RTTVAR: c_int = 0x80; - -pub const RTAX_MAX: c_int = 8; +cfg_if! { + if #[cfg(target_os = "macos")] { + // net/route.h + pub const RTF_DELCLONE: c_int = 0x80; + pub const RTF_CLONING: c_int = 0x100; + pub const RTF_XRESOLVE: c_int = 0x200; + pub const RTF_LLINFO: c_int = 0x400; + pub const RTF_NOIFREF: c_int = 0x2000; + pub const RTF_PRCLONING: c_int = 0x10000; + pub const RTF_WASCLONED: c_int = 0x20000; + pub const RTF_PROTO3: c_int = 0x40000; + pub const RTF_PINNED: c_int = 0x100000; + pub const RTF_LOCAL: c_int = 0x200000; + pub const RTF_BROADCAST: c_int = 0x400000; + pub const RTF_MULTICAST: c_int = 0x800000; + pub const RTF_IFSCOPE: c_int = 0x1000000; + pub const RTF_CONDEMNED: c_int = 0x2000000; + pub const RTF_IFREF: c_int = 0x4000000; + pub const RTF_PROXY: c_int = 0x8000000; + pub const RTF_ROUTER: c_int = 0x10000000; + pub const RTF_DEAD: c_int = 0x20000000; + pub const RTF_GLOBAL: c_int = 0x40000000; + + pub const RTM_VERSION: c_int = 5; + + // Message types + pub const RTM_LOCK: c_int = 0x8; + pub const RTM_OLDADD: c_int = 0x9; + pub const RTM_OLDDEL: c_int = 0xa; + pub const RTM_RESOLVE: c_int = 0xb; + pub const RTM_NEWADDR: c_int = 0xc; + pub const RTM_DELADDR: c_int = 0xd; + pub const RTM_IFINFO: c_int = 0xe; + pub const RTM_NEWMADDR: c_int = 0xf; + pub const RTM_DELMADDR: c_int = 0x10; + pub const RTM_IFINFO2: c_int = 0x12; + pub const RTM_NEWMADDR2: c_int = 0x13; + pub const RTM_GET2: c_int = 0x14; + + // Bitmask values for rtm_inits and rmx_locks. + pub const RTV_MTU: c_int = 0x1; + pub const RTV_HOPCOUNT: c_int = 0x2; + pub const RTV_EXPIRE: c_int = 0x4; + pub const RTV_RPIPE: c_int = 0x8; + pub const RTV_SPIPE: c_int = 0x10; + pub const RTV_SSTHRESH: c_int = 0x20; + pub const RTV_RTT: c_int = 0x40; + pub const RTV_RTTVAR: c_int = 0x80; + + pub const RTAX_MAX: c_int = 8; + } +} pub const KERN_PROCARGS2: c_int = 49; -pub const PROC_PIDTASKALLINFO: c_int = 2; -pub const PROC_PIDTBSDINFO: c_int = 3; -pub const PROC_PIDTASKINFO: c_int = 4; -pub const PROC_PIDTHREADINFO: c_int = 5; -pub const PROC_PIDVNODEPATHINFO: c_int = 9; -pub const PROC_PIDT_SHORTBSDINFO: c_int = 13; -pub const PROC_PIDPATHINFO_MAXSIZE: c_int = 4096; - -pub const PROC_PIDLISTFDS: c_int = 1; -pub const PROC_PIDLISTFD_SIZE: c_int = size_of::() as c_int; -pub const PROX_FDTYPE_ATALK: c_int = 0; -pub const PROX_FDTYPE_VNODE: c_int = 1; -pub const PROX_FDTYPE_SOCKET: c_int = 2; -pub const PROX_FDTYPE_PSHM: c_int = 3; -pub const PROX_FDTYPE_PSEM: c_int = 4; -pub const PROX_FDTYPE_KQUEUE: c_int = 5; -pub const PROX_FDTYPE_PIPE: c_int = 6; -pub const PROX_FDTYPE_FSEVENTS: c_int = 7; -pub const PROX_FDTYPE_NETPOLICY: c_int = 9; -pub const PROX_FDTYPE_CHANNEL: c_int = 10; -pub const PROX_FDTYPE_NEXUS: c_int = 11; - -pub const PROC_CSM_ALL: c_uint = 0x0001; -pub const PROC_CSM_NOSMT: c_uint = 0x0002; -pub const PROC_CSM_TECS: c_uint = 0x0004; +cfg_if! { + if #[cfg(target_os = "macos")] { + // sys/proc_info.h + pub const PROC_PIDTASKALLINFO: c_int = 2; + pub const PROC_PIDTBSDINFO: c_int = 3; + pub const PROC_PIDTASKINFO: c_int = 4; + pub const PROC_PIDTHREADINFO: c_int = 5; + pub const PROC_PIDVNODEPATHINFO: c_int = 9; + pub const PROC_PIDT_SHORTBSDINFO: c_int = 13; + pub const PROC_PIDPATHINFO_MAXSIZE: c_int = 4096; + + pub const PROC_PIDLISTFDS: c_int = 1; + pub const PROC_PIDLISTFD_SIZE: c_int = size_of::() as c_int; + pub const PROX_FDTYPE_ATALK: c_int = 0; + pub const PROX_FDTYPE_VNODE: c_int = 1; + pub const PROX_FDTYPE_SOCKET: c_int = 2; + pub const PROX_FDTYPE_PSHM: c_int = 3; + pub const PROX_FDTYPE_PSEM: c_int = 4; + pub const PROX_FDTYPE_KQUEUE: c_int = 5; + pub const PROX_FDTYPE_PIPE: c_int = 6; + pub const PROX_FDTYPE_FSEVENTS: c_int = 7; + pub const PROX_FDTYPE_NETPOLICY: c_int = 9; + pub const PROX_FDTYPE_CHANNEL: c_int = 10; + pub const PROX_FDTYPE_NEXUS: c_int = 11; + + // libproc.h + pub const PROC_CSM_ALL: c_uint = 0x0001; + pub const PROC_CSM_NOSMT: c_uint = 0x0002; + pub const PROC_CSM_TECS: c_uint = 0x0004; + } +} + pub const MAXCOMLEN: usize = 16; pub const MAXTHREADNAMESIZE: usize = 64; @@ -3566,29 +3627,33 @@ pub const LC_SEGMENT_64: u32 = 0x19; pub const MH_MAGIC: u32 = 0xfeedface; pub const MH_MAGIC_64: u32 = 0xfeedfacf; -// net/if_utun.h -pub const UTUN_OPT_FLAGS: c_int = 1; -pub const UTUN_OPT_IFNAME: c_int = 2; - -// net/bpf.h -pub const DLT_NULL: c_uint = 0; // no link-layer encapsulation -pub const DLT_EN10MB: c_uint = 1; // Ethernet (10Mb) -pub const DLT_EN3MB: c_uint = 2; // Experimental Ethernet (3Mb) -pub const DLT_AX25: c_uint = 3; // Amateur Radio AX.25 -pub const DLT_PRONET: c_uint = 4; // Proteon ProNET Token Ring -pub const DLT_CHAOS: c_uint = 5; // Chaos -pub const DLT_IEEE802: c_uint = 6; // IEEE 802 Networks -pub const DLT_ARCNET: c_uint = 7; // ARCNET -pub const DLT_SLIP: c_uint = 8; // Serial Line IP -pub const DLT_PPP: c_uint = 9; // Point-to-point Protocol -pub const DLT_FDDI: c_uint = 10; // FDDI -pub const DLT_ATM_RFC1483: c_uint = 11; // LLC/SNAP encapsulated atm -pub const DLT_RAW: c_uint = 12; // raw IP -pub const DLT_LOOP: c_uint = 108; - -// https://github.com/apple/darwin-xnu/blob/HEAD/bsd/net/bpf.h#L100 -// sizeof(i32) -pub const BPF_ALIGNMENT: c_int = 4; +cfg_if! { + if #[cfg(target_os = "macos")] { + // net/if_utun.h + pub const UTUN_OPT_FLAGS: c_int = 1; + pub const UTUN_OPT_IFNAME: c_int = 2; + + // net/bpf.h + pub const DLT_NULL: c_uint = 0; // no link-layer encapsulation + pub const DLT_EN10MB: c_uint = 1; // Ethernet (10Mb) + pub const DLT_EN3MB: c_uint = 2; // Experimental Ethernet (3Mb) + pub const DLT_AX25: c_uint = 3; // Amateur Radio AX.25 + pub const DLT_PRONET: c_uint = 4; // Proteon ProNET Token Ring + pub const DLT_CHAOS: c_uint = 5; // Chaos + pub const DLT_IEEE802: c_uint = 6; // IEEE 802 Networks + pub const DLT_ARCNET: c_uint = 7; // ARCNET + pub const DLT_SLIP: c_uint = 8; // Serial Line IP + pub const DLT_PPP: c_uint = 9; // Point-to-point Protocol + pub const DLT_FDDI: c_uint = 10; // FDDI + pub const DLT_ATM_RFC1483: c_uint = 11; // LLC/SNAP encapsulated atm + pub const DLT_RAW: c_uint = 12; // raw IP + pub const DLT_LOOP: c_uint = 108; + + // https://github.com/apple/darwin-xnu/blob/HEAD/bsd/net/bpf.h#L100 + // sizeof(i32) + pub const BPF_ALIGNMENT: c_int = 4; + } +} // sys/mount.h pub const MNT_NODEV: c_int = 0x00000010; @@ -4062,34 +4127,38 @@ pub const MACH_TASK_BASIC_INFO_COUNT: u32 = pub const HOST_VM_INFO64_COUNT: mach_msg_type_number_t = (size_of::() / size_of::()) as mach_msg_type_number_t; -// bsd/net/if_mib.h -/// Non-interface-specific -pub const IFMIB_SYSTEM: c_int = 1; -/// Per-interface data table -pub const IFMIB_IFDATA: c_int = 2; -/// All interfaces data at once -pub const IFMIB_IFALLDATA: c_int = 3; - -/// Generic stats for all kinds of ifaces -pub const IFDATA_GENERAL: c_int = 1; -/// Specific to the type of interface -pub const IFDATA_LINKSPECIFIC: c_int = 2; -/// Addresses assigned to interface -pub const IFDATA_ADDRS: c_int = 3; -/// Multicast addresses assigned to interface -pub const IFDATA_MULTIADDRS: c_int = 4; - -/// Number of interfaces configured -pub const IFMIB_IFCOUNT: c_int = 1; - -/// Functions not specific to a type of iface -pub const NETLINK_GENERIC: c_int = 0; - -pub const DOT3COMPLIANCE_STATS: c_int = 1; -pub const DOT3COMPLIANCE_COLLS: c_int = 2; - -// kern_control.h -pub const MAX_KCTL_NAME: usize = 96; +cfg_if! { + if #[cfg(target_os = "macos")] { + // bsd/net/if_mib.h + /// Non-interface-specific + pub const IFMIB_SYSTEM: c_int = 1; + /// Per-interface data table + pub const IFMIB_IFDATA: c_int = 2; + /// All interfaces data at once + pub const IFMIB_IFALLDATA: c_int = 3; + + /// Generic stats for all kinds of ifaces + pub const IFDATA_GENERAL: c_int = 1; + /// Specific to the type of interface + pub const IFDATA_LINKSPECIFIC: c_int = 2; + /// Addresses assigned to interface + pub const IFDATA_ADDRS: c_int = 3; + /// Multicast addresses assigned to interface + pub const IFDATA_MULTIADDRS: c_int = 4; + + /// Number of interfaces configured + pub const IFMIB_IFCOUNT: c_int = 1; + + /// Functions not specific to a type of iface + pub const NETLINK_GENERIC: c_int = 0; + + pub const DOT3COMPLIANCE_STATS: c_int = 1; + pub const DOT3COMPLIANCE_COLLS: c_int = 2; + + // kern_control.h + pub const MAX_KCTL_NAME: usize = 96; + } +} f! { pub fn CMSG_NXTHDR(mhdr: *const crate::msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr { @@ -4429,6 +4498,7 @@ extern "C" { data: *mut c_void, ) -> c_int; pub fn fmount(src: *const c_char, fd: c_int, flags: c_int, data: *mut c_void) -> c_int; + #[cfg(target_os = "macos")] pub fn ptrace(request: c_int, pid: crate::pid_t, addr: *mut c_char, data: c_int) -> c_int; pub fn quotactl(special: *const c_char, cmd: c_int, id: c_int, data: *mut c_char) -> c_int; pub fn sethostname(name: *const c_char, len: c_int) -> c_int; @@ -4726,49 +4796,6 @@ extern "C" { ) -> *mut c_void; pub fn malloc_zone_free(zone: *mut crate::malloc_zone_t, ptr: *mut c_void); - pub fn proc_listpids(t: u32, typeinfo: u32, buffer: *mut c_void, buffersize: c_int) -> c_int; - pub fn proc_listallpids(buffer: *mut c_void, buffersize: c_int) -> c_int; - pub fn proc_listpgrppids(pgrpid: crate::pid_t, buffer: *mut c_void, buffersize: c_int) - -> c_int; - pub fn proc_listchildpids(ppid: crate::pid_t, buffer: *mut c_void, buffersize: c_int) -> c_int; - pub fn proc_pidinfo( - pid: c_int, - flavor: c_int, - arg: u64, - buffer: *mut c_void, - buffersize: c_int, - ) -> c_int; - pub fn proc_pidfdinfo( - pid: c_int, - fd: c_int, - flavor: c_int, - buffer: *mut c_void, - buffersize: c_int, - ) -> c_int; - pub fn proc_pidfileportinfo( - pid: c_int, - fileport: u32, - flavor: c_int, - buffer: *mut c_void, - buffersize: c_int, - ) -> c_int; - pub fn proc_pidpath(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int; - pub fn proc_name(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int; - pub fn proc_regionfilename( - pid: c_int, - address: u64, - buffer: *mut c_void, - buffersize: u32, - ) -> c_int; - pub fn proc_kmsgbuf(buffer: *mut c_void, buffersize: u32) -> c_int; - pub fn proc_libversion(major: *mut c_int, minor: *mut c_int) -> c_int; - pub fn proc_pid_rusage(pid: c_int, flavor: c_int, buffer: *mut rusage_info_t) -> c_int; - - // Available from Big Sur - pub fn proc_set_no_smt() -> c_int; - pub fn proc_setthread_no_smt() -> c_int; - pub fn proc_set_csm(flags: u32) -> c_int; - pub fn proc_setthread_csm(flags: u32) -> c_int; /// # Notes /// /// `id` is of type [`uuid_t`]. @@ -4936,6 +4963,62 @@ cfg_if! { if #[cfg(target_os = "macos")] { extern "C" { pub fn clock_settime(clock_id: crate::clockid_t, tp: *const crate::timespec) -> c_int; + + // libproc.h + pub fn proc_listpids( + t: u32, + typeinfo: u32, + buffer: *mut c_void, + buffersize: c_int, + ) -> c_int; + pub fn proc_listallpids(buffer: *mut c_void, buffersize: c_int) -> c_int; + pub fn proc_listpgrppids( + pgrpid: crate::pid_t, + buffer: *mut c_void, + buffersize: c_int, + ) -> c_int; + pub fn proc_listchildpids( + ppid: crate::pid_t, + buffer: *mut c_void, + buffersize: c_int, + ) -> c_int; + pub fn proc_pidinfo( + pid: c_int, + flavor: c_int, + arg: u64, + buffer: *mut c_void, + buffersize: c_int, + ) -> c_int; + pub fn proc_pidfdinfo( + pid: c_int, + fd: c_int, + flavor: c_int, + buffer: *mut c_void, + buffersize: c_int, + ) -> c_int; + pub fn proc_pidfileportinfo( + pid: c_int, + fileport: u32, + flavor: c_int, + buffer: *mut c_void, + buffersize: c_int, + ) -> c_int; + pub fn proc_pidpath(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int; + pub fn proc_name(pid: c_int, buffer: *mut c_void, buffersize: u32) -> c_int; + pub fn proc_regionfilename( + pid: c_int, + address: u64, + buffer: *mut c_void, + buffersize: u32, + ) -> c_int; + pub fn proc_kmsgbuf(buffer: *mut c_void, buffersize: u32) -> c_int; + pub fn proc_libversion(major: *mut c_int, minor: *mut c_int) -> c_int; + pub fn proc_pid_rusage(pid: c_int, flavor: c_int, buffer: *mut rusage_info_t) -> c_int; + // Available from Big Sur + pub fn proc_set_no_smt() -> c_int; + pub fn proc_setthread_no_smt() -> c_int; + pub fn proc_set_csm(flags: u32) -> c_int; + pub fn proc_setthread_csm(flags: u32) -> c_int; } } } diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 47fd27321609f..d7a712e045111 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -37,15 +37,7 @@ s! { pub pw_shell: *mut c_char, pub pw_expire: crate::time_t, - #[cfg(not(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos", - target_os = "netbsd", - target_os = "openbsd" - )))] + #[cfg(not(any(target_vendor = "apple", target_os = "netbsd", target_os = "openbsd")))] pub pw_fields: c_int, } @@ -385,8 +377,14 @@ pub const POLLRDBAND: c_short = 0x080; pub const POLLWRBAND: c_short = 0x100; cfg_if! { - // Not yet implemented on NetBSD - if #[cfg(not(any(target_os = "netbsd")))] { + // Not yet implemented on NetBSD, and not present on iOS/tvOS/watchOS/visionOS + if #[cfg(not(any( + target_os = "netbsd", + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + )))] { pub const BIOCGBLEN: c_ulong = 0x40044266; pub const BIOCSBLEN: c_ulong = 0xc0044266; pub const BIOCFLUSH: c_uint = 0x20004268; @@ -449,48 +447,58 @@ pub const ITIMER_REAL: c_int = 0; pub const ITIMER_VIRTUAL: c_int = 1; pub const ITIMER_PROF: c_int = 2; -// net/route.h - -pub const RTF_UP: c_int = 0x1; -pub const RTF_GATEWAY: c_int = 0x2; -pub const RTF_HOST: c_int = 0x4; -pub const RTF_REJECT: c_int = 0x8; -pub const RTF_DYNAMIC: c_int = 0x10; -pub const RTF_MODIFIED: c_int = 0x20; -pub const RTF_DONE: c_int = 0x40; -pub const RTF_STATIC: c_int = 0x800; -pub const RTF_BLACKHOLE: c_int = 0x1000; -pub const RTF_PROTO2: c_int = 0x4000; -pub const RTF_PROTO1: c_int = 0x8000; - -// Message types -pub const RTM_ADD: c_int = 0x1; -pub const RTM_DELETE: c_int = 0x2; -pub const RTM_CHANGE: c_int = 0x3; -pub const RTM_GET: c_int = 0x4; -pub const RTM_LOSING: c_int = 0x5; -pub const RTM_REDIRECT: c_int = 0x6; -pub const RTM_MISS: c_int = 0x7; - -// Bitmask values for rtm_addrs. -pub const RTA_DST: c_int = 0x1; -pub const RTA_GATEWAY: c_int = 0x2; -pub const RTA_NETMASK: c_int = 0x4; -pub const RTA_GENMASK: c_int = 0x8; -pub const RTA_IFP: c_int = 0x10; -pub const RTA_IFA: c_int = 0x20; -pub const RTA_AUTHOR: c_int = 0x40; -pub const RTA_BRD: c_int = 0x80; - -// Index offsets for sockaddr array for alternate internal encoding. -pub const RTAX_DST: c_int = 0; -pub const RTAX_GATEWAY: c_int = 1; -pub const RTAX_NETMASK: c_int = 2; -pub const RTAX_GENMASK: c_int = 3; -pub const RTAX_IFP: c_int = 4; -pub const RTAX_IFA: c_int = 5; -pub const RTAX_AUTHOR: c_int = 6; -pub const RTAX_BRD: c_int = 7; +cfg_if! { + // Not present on iOS/tvOS/watchOS/visionOS + if #[cfg(not(any( + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + )))] { + // net/route.h + + pub const RTF_UP: c_int = 0x1; + pub const RTF_GATEWAY: c_int = 0x2; + pub const RTF_HOST: c_int = 0x4; + pub const RTF_REJECT: c_int = 0x8; + pub const RTF_DYNAMIC: c_int = 0x10; + pub const RTF_MODIFIED: c_int = 0x20; + pub const RTF_DONE: c_int = 0x40; + pub const RTF_STATIC: c_int = 0x800; + pub const RTF_BLACKHOLE: c_int = 0x1000; + pub const RTF_PROTO2: c_int = 0x4000; + pub const RTF_PROTO1: c_int = 0x8000; + + // Message types + pub const RTM_ADD: c_int = 0x1; + pub const RTM_DELETE: c_int = 0x2; + pub const RTM_CHANGE: c_int = 0x3; + pub const RTM_GET: c_int = 0x4; + pub const RTM_LOSING: c_int = 0x5; + pub const RTM_REDIRECT: c_int = 0x6; + pub const RTM_MISS: c_int = 0x7; + + // Bitmask values for rtm_addrs. + pub const RTA_DST: c_int = 0x1; + pub const RTA_GATEWAY: c_int = 0x2; + pub const RTA_NETMASK: c_int = 0x4; + pub const RTA_GENMASK: c_int = 0x8; + pub const RTA_IFP: c_int = 0x10; + pub const RTA_IFA: c_int = 0x20; + pub const RTA_AUTHOR: c_int = 0x40; + pub const RTA_BRD: c_int = 0x80; + + // Index offsets for sockaddr array for alternate internal encoding. + pub const RTAX_DST: c_int = 0; + pub const RTAX_GATEWAY: c_int = 1; + pub const RTAX_NETMASK: c_int = 2; + pub const RTAX_GENMASK: c_int = 3; + pub const RTAX_IFP: c_int = 4; + pub const RTAX_IFA: c_int = 5; + pub const RTAX_AUTHOR: c_int = 6; + pub const RTAX_BRD: c_int = 7; + } +} f! { pub fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr { @@ -881,13 +889,7 @@ cfg_if! { } cfg_if! { - if #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos" - ))] { + if #[cfg(target_vendor = "apple")] { mod apple; pub use self::apple::*; } else if #[cfg(any(target_os = "openbsd", target_os = "netbsd"))] { diff --git a/src/unix/mod.rs b/src/unix/mod.rs index ff440d5a13f1c..623ef02dbae77 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -362,13 +362,23 @@ pub const IN6ADDR_ANY_INIT: in6_addr = in6_addr { s6_addr: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], }; -pub const ARPOP_REQUEST: u16 = 1; -pub const ARPOP_REPLY: u16 = 2; +cfg_if! { + // Not present on iOS/tvOS/watchOS/visionOS + if #[cfg(not(any( + target_os = "ios", + target_os = "tvos", + target_os = "watchos", + target_os = "visionos", + )))] { + pub const ARPOP_REQUEST: u16 = 1; + pub const ARPOP_REPLY: u16 = 2; -pub const ATF_COM: c_int = 0x02; -pub const ATF_PERM: c_int = 0x04; -pub const ATF_PUBL: c_int = 0x08; -pub const ATF_USETRAILERS: c_int = 0x10; + pub const ATF_COM: c_int = 0x02; + pub const ATF_PERM: c_int = 0x04; + pub const ATF_PUBL: c_int = 0x08; + pub const ATF_USETRAILERS: c_int = 0x10; + } +} cfg_if! { if #[cfg(any(target_os = "nto", target_os = "aix"))] { @@ -393,7 +403,7 @@ cfg_if! { cfg_if! { if #[cfg(any( - target_os = "macos", + target_vendor = "apple", target_os = "freebsd", target_os = "android", target_os = "openbsd", @@ -408,7 +418,7 @@ cfg_if! { cfg_if! { if #[cfg(any( - target_os = "macos", + target_vendor = "apple", target_os = "freebsd", target_os = "android", target_os = "openbsd", @@ -549,11 +559,7 @@ cfg_if! { #[link(name = "c", cfg(not(target_feature = "crt-static")))] extern "C" {} } else if #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos", + target_vendor = "apple", target_os = "android", target_os = "openbsd", target_os = "nto", @@ -1279,16 +1285,7 @@ extern "C" { #[cfg_attr(musl_redir_time64, link_name = "__getrusage_time64")] pub fn getrusage(resource: c_int, usage: *mut rusage) -> c_int; - #[cfg_attr( - any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos" - ), - link_name = "realpath$DARWIN_EXTSN" - )] + #[cfg_attr(target_vendor = "apple", link_name = "realpath$DARWIN_EXTSN")] pub fn realpath(pathname: *const c_char, resolved: *mut c_char) -> *mut c_char; #[cfg_attr(target_os = "netbsd", link_name = "__times13")] @@ -1466,16 +1463,7 @@ extern "C" { ), link_name = "__res_init" )] - #[cfg_attr( - any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos" - ), - link_name = "res_9_init" - )] + #[cfg_attr(target_vendor = "apple", link_name = "res_9_init")] #[cfg_attr(target_os = "aix", link_name = "_res_init")] #[cfg(not(target_os = "l4re"))] pub fn res_init() -> c_int; @@ -2171,7 +2159,7 @@ cfg_if! { target_os = "dragonfly", target_os = "emscripten", target_os = "hurd", - target_os = "macos", + target_vendor = "apple", target_os = "openbsd", target_os = "l4re", )))] { @@ -2468,11 +2456,7 @@ cfg_if! { mod linux_like; pub use self::linux_like::*; } else if #[cfg(any( - target_os = "macos", - target_os = "ios", - target_os = "tvos", - target_os = "watchos", - target_os = "visionos", + target_vendor = "apple", target_os = "freebsd", target_os = "dragonfly", target_os = "openbsd",