From 23b49bbbc2bdc6ec200aae8b022f5295c49b5794 Mon Sep 17 00:00:00 2001 From: arctic-alpaca <67190338+arctic-alpaca@users.noreply.github.com> Date: Tue, 19 Dec 2023 11:12:53 +0100 Subject: [PATCH 1/3] Add missing symbols to semver/linux.txt --- libc-test/semver/linux.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 37aab57f23ee3..ff186a7d830ba 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -2475,6 +2475,7 @@ SIOCSIFMAP SIOCSIFMEM SIOCSIFMETRIC SIOCSIFMTU +SIOCSIFNAME SIOCSIFNETMASK SIOCSIFPFLAGS SIOCSIFSLAVE @@ -3860,3 +3861,6 @@ wait4 waitid eventfd_read eventfd_write +__c_anonymous_ifru_map +__c_anonymous_ifr_ifru +__c_anonymous_ifc_ifcu From c0b1ccf49cc761e75fe124090375ea8977693514 Mon Sep 17 00:00:00 2001 From: arctic-alpaca <67190338+arctic-alpaca@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:02:18 +0100 Subject: [PATCH 2/3] Add `ifreq`, `ifconf` and related constants to Android --- libc-test/build.rs | 2 + libc-test/semver/android.txt | 44 +++++++++ src/unix/linux_like/android/mod.rs | 145 +++++++++++++++++++++++++++++ 3 files changed, 191 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index a9d04ca81cc15..7319c65352958 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1996,6 +1996,8 @@ fn test_android(target: &str) { // this is actually a union on linux, so we can't represent it well and // just insert some padding. ("siginfo_t", "_pad") => true, + ("ifreq", "ifr_ifru") => true, + ("ifconf", "ifc_ifcu") => true, _ => false, } diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index a7c235eefb3ed..f0e4358d37c62 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -2241,7 +2241,44 @@ SIOCADDMULTI SIOCADDRT SIOCDARP SIOCDELMULTI +SIOCGIFINDEX +SIOGIFINDEX +SIOCSIFPFLAGS +SIOCGIFPFLAGS +SIOCDIFADDR +SIOCSIFHWBROADCAST +SIOCGIFCOUNT +SIOCGIFBR +SIOCSIFBR +SIOCGIFTXQLEN +SIOCSIFTXQLEN +SIOCETHTOOL +SIOCGMIIPHY +SIOCGMIIREG +SIOCSMIIREG +SIOCWANDEV +SIOCOUTQNSD +SIOCGSKNS +SIOCADDDLCI +SIOCDELDLCI +SIOCGIFVLAN +SIOCSIFVLAN +SIOCBONDENSLAVE +SIOCBONDRELEASE +SIOCBONDSETHWADDR +SIOCBONDSLAVEINFOQUERY +SIOCBONDINFOQUERY +SIOCBONDCHANGEACTIVE +SIOCBRADDBR +SIOCBRDELBR +SIOCBRADDIF +SIOCBRDELIF +SIOCSHWTSTAMP +SIOCGHWTSTAMP +SIOCDEVPRIVATE +SIOCPROTOPRIVATE SIOCDELRT +SIOCRTMSG SIOCDRARP SIOCGARP SIOCGIFADDR @@ -2250,6 +2287,7 @@ SIOCGIFCONF SIOCGIFDSTADDR SIOCGIFENCAP SIOCGIFFLAGS +SIOCSIFNAME SIOCGIFHWADDR SIOCGIFMAP SIOCGIFMEM @@ -3223,10 +3261,16 @@ group hostent id_t idtype_t +ifconf +ifreq +__c_anonymous_ifc_ifcu +__c_anonymous_ifr_ifru +__c_anonymous_ifru_map if_indextoname if_nametoindex ifaddrs in6_addr +in6_ifreq in6_pktinfo in6_rtmsg in_addr diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 999a15440d12c..94c4eace85539 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -496,6 +496,22 @@ s! { pub flag: *mut ::c_int, pub val: ::c_int, } + + pub struct __c_anonymous_ifru_map { + pub mem_start: ::c_ulong, + pub mem_end: ::c_ulong, + pub base_addr: ::c_ushort, + pub irq: ::c_uchar, + pub dma: ::c_uchar, + pub port: ::c_uchar, + } + + pub struct in6_ifreq { + pub ifr6_addr: ::in6_addr, + pub ifr6_prefixlen: u32, + pub ifr6_ifindex: ::c_int, + } + } s_no_extra_traits! { @@ -591,6 +607,50 @@ s_no_extra_traits! { __serial: ::c_uint, __value: [[::c_char; 4]; 23], } + + #[cfg(libc_union)] + pub union __c_anonymous_ifr_ifru { + pub ifru_addr: ::sockaddr, + pub ifru_dstaddr: ::sockaddr, + pub ifru_broadaddr: ::sockaddr, + pub ifru_netmask: ::sockaddr, + pub ifru_hwaddr: ::sockaddr, + pub ifru_flags: ::c_short, + pub ifru_ifindex: ::c_int, + pub ifru_metric: ::c_int, + pub ifru_mtu: ::c_int, + pub ifru_map: __c_anonymous_ifru_map, + pub ifru_slave: [::c_char; ::IFNAMSIZ], + pub ifru_newname: [::c_char; ::IFNAMSIZ], + pub ifru_data: *mut ::c_char, + } + + pub struct ifreq { + /// interface name, e.g. "en0" + pub ifr_name: [::c_char; ::IFNAMSIZ], + #[cfg(libc_union)] + pub ifr_ifru: __c_anonymous_ifr_ifru, + #[cfg(not(libc_union))] + pub ifr_ifru: ::sockaddr, + } + + #[cfg(libc_union)] + pub union __c_anonymous_ifc_ifcu { + pub ifcu_buf: *mut ::c_char, + pub ifcu_req: *mut ::ifreq, + } + + /* Structure used in SIOCGIFCONF request. Used to retrieve interface + configuration for machine (useful for programs which must know all + networks accessible). */ + pub struct ifconf { + pub ifc_len: ::c_int, /* Size of buffer. */ + #[cfg(libc_union)] + pub ifc_ifcu: __c_anonymous_ifc_ifcu, + #[cfg(not(libc_union))] + pub ifc_ifcu: *mut ::ifreq, + } + } cfg_if! { @@ -938,6 +998,53 @@ cfg_if! { } } + #[cfg(libc_union)] + impl ::fmt::Debug for __c_anonymous_ifr_ifru { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ifr_ifru") + .field("ifru_addr", unsafe { &self.ifru_addr }) + .field("ifru_dstaddr", unsafe { &self.ifru_dstaddr }) + .field("ifru_broadaddr", unsafe { &self.ifru_broadaddr }) + .field("ifru_netmask", unsafe { &self.ifru_netmask }) + .field("ifru_hwaddr", unsafe { &self.ifru_hwaddr }) + .field("ifru_flags", unsafe { &self.ifru_flags }) + .field("ifru_ifindex", unsafe { &self.ifru_ifindex }) + .field("ifru_metric", unsafe { &self.ifru_metric }) + .field("ifru_mtu", unsafe { &self.ifru_mtu }) + .field("ifru_map", unsafe { &self.ifru_map }) + .field("ifru_slave", unsafe { &self.ifru_slave }) + .field("ifru_newname", unsafe { &self.ifru_newname }) + .field("ifru_data", unsafe { &self.ifru_data }) + .finish() + } + } + impl ::fmt::Debug for ifreq { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ifreq") + .field("ifr_name", &self.ifr_name) + .field("ifr_ifru", &self.ifr_ifru) + .finish() + } + } + + #[cfg(libc_union)] + impl ::fmt::Debug for __c_anonymous_ifc_ifcu { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ifr_ifru") + .field("ifcu_buf", unsafe { &self.ifcu_buf }) + .field("ifcu_req", unsafe { &self.ifcu_req }) + .finish() + } + } + impl ::fmt::Debug for ifconf { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("ifconf") + .field("ifc_len", &self.ifc_len) + .field("ifc_ifcu", &self.ifc_ifcu) + .finish() + } + } + #[allow(deprecated)] impl af_alg_iv { fn as_slice(&self) -> &[u8] { @@ -2715,6 +2822,7 @@ pub const NFEA_DONT_REFRESH: ::c_ushort = 2; pub const SIOCADDRT: ::c_ulong = 0x0000890B; pub const SIOCDELRT: ::c_ulong = 0x0000890C; +pub const SIOCRTMSG: ::c_ulong = 0x0000890D; pub const SIOCGIFNAME: ::c_ulong = 0x00008910; pub const SIOCSIFLINK: ::c_ulong = 0x00008911; pub const SIOCGIFCONF: ::c_ulong = 0x00008912; @@ -2734,6 +2842,7 @@ pub const SIOCGIFMEM: ::c_ulong = 0x0000891F; pub const SIOCSIFMEM: ::c_ulong = 0x00008920; pub const SIOCGIFMTU: ::c_ulong = 0x00008921; pub const SIOCSIFMTU: ::c_ulong = 0x00008922; +pub const SIOCSIFNAME: ::c_ulong = 0x00008923; pub const SIOCSIFHWADDR: ::c_ulong = 0x00008924; pub const SIOCGIFENCAP: ::c_ulong = 0x00008925; pub const SIOCSIFENCAP: ::c_ulong = 0x00008926; @@ -2742,6 +2851,24 @@ pub const SIOCGIFSLAVE: ::c_ulong = 0x00008929; pub const SIOCSIFSLAVE: ::c_ulong = 0x00008930; pub const SIOCADDMULTI: ::c_ulong = 0x00008931; pub const SIOCDELMULTI: ::c_ulong = 0x00008932; +pub const SIOCGIFINDEX: ::c_ulong = 0x00008933; +pub const SIOGIFINDEX: ::c_ulong = SIOCGIFINDEX; +pub const SIOCSIFPFLAGS: ::c_ulong = 0x00008934; +pub const SIOCGIFPFLAGS: ::c_ulong = 0x00008935; +pub const SIOCDIFADDR: ::c_ulong = 0x00008936; +pub const SIOCSIFHWBROADCAST: ::c_ulong = 0x00008937; +pub const SIOCGIFCOUNT: ::c_ulong = 0x00008938; +pub const SIOCGIFBR: ::c_ulong = 0x00008940; +pub const SIOCSIFBR: ::c_ulong = 0x00008941; +pub const SIOCGIFTXQLEN: ::c_ulong = 0x00008942; +pub const SIOCSIFTXQLEN: ::c_ulong = 0x00008943; +pub const SIOCETHTOOL: ::c_ulong = 0x00008946; +pub const SIOCGMIIPHY: ::c_ulong = 0x00008947; +pub const SIOCGMIIREG: ::c_ulong = 0x00008948; +pub const SIOCSMIIREG: ::c_ulong = 0x00008949; +pub const SIOCWANDEV: ::c_ulong = 0x0000894A; +pub const SIOCOUTQNSD: ::c_ulong = 0x0000894B; +pub const SIOCGSKNS: ::c_ulong = 0x0000894C; pub const SIOCDARP: ::c_ulong = 0x00008953; pub const SIOCGARP: ::c_ulong = 0x00008954; pub const SIOCSARP: ::c_ulong = 0x00008955; @@ -2750,6 +2877,24 @@ pub const SIOCGRARP: ::c_ulong = 0x00008961; pub const SIOCSRARP: ::c_ulong = 0x00008962; pub const SIOCGIFMAP: ::c_ulong = 0x00008970; pub const SIOCSIFMAP: ::c_ulong = 0x00008971; +pub const SIOCADDDLCI: ::c_ulong = 0x00008980; +pub const SIOCDELDLCI: ::c_ulong = 0x00008981; +pub const SIOCGIFVLAN: ::c_ulong = 0x00008982; +pub const SIOCSIFVLAN: ::c_ulong = 0x00008983; +pub const SIOCBONDENSLAVE: ::c_ulong = 0x00008990; +pub const SIOCBONDRELEASE: ::c_ulong = 0x00008991; +pub const SIOCBONDSETHWADDR: ::c_ulong = 0x00008992; +pub const SIOCBONDSLAVEINFOQUERY: ::c_ulong = 0x00008993; +pub const SIOCBONDINFOQUERY: ::c_ulong = 0x00008994; +pub const SIOCBONDCHANGEACTIVE: ::c_ulong = 0x00008995; +pub const SIOCBRADDBR: ::c_ulong = 0x000089a0; +pub const SIOCBRDELBR: ::c_ulong = 0x000089a1; +pub const SIOCBRADDIF: ::c_ulong = 0x000089a2; +pub const SIOCBRDELIF: ::c_ulong = 0x000089a3; +pub const SIOCSHWTSTAMP: ::c_ulong = 0x000089b0; +pub const SIOCGHWTSTAMP: ::c_ulong = 0x000089b1; +pub const SIOCDEVPRIVATE: ::c_ulong = 0x000089F0; +pub const SIOCPROTOPRIVATE: ::c_ulong = 0x000089E0; // linux/module.h pub const MODULE_INIT_IGNORE_MODVERSIONS: ::c_uint = 0x0001; From ba4dd05e027960c980237d286310dc8cbd33ab28 Mon Sep 17 00:00:00 2001 From: arctic-alpaca <67190338+arctic-alpaca@users.noreply.github.com> Date: Tue, 19 Dec 2023 15:05:29 +0100 Subject: [PATCH 3/3] Remove overwritten `cfg.skip_field()` call in `test_android()` --- libc-test/build.rs | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 7319c65352958..f8decdb8a692a 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1972,21 +1972,6 @@ fn test_android(target: &str) { (struct_ == "flock64" && (field == "l_start" || field == "l_len")) }); - cfg.skip_field(move |struct_, field| { - // this is actually a union on linux, so we can't represent it well and - // just insert some padding. - (struct_ == "siginfo_t" && field == "_pad") || - // FIXME: `sa_sigaction` has type `sighandler_t` but that type is - // incorrect, see: https://github.com/rust-lang/libc/issues/1359 - (struct_ == "sigaction" && field == "sa_sigaction") || - // sigev_notify_thread_id is actually part of a sigev_un union - (struct_ == "sigevent" && field == "sigev_notify_thread_id") || - // signalfd had SIGSYS fields added in Android 4.19, but CI does not have that version yet. - (struct_ == "signalfd_siginfo" && (field == "ssi_syscall" || - field == "ssi_call_addr" || - field == "ssi_arch")) - }); - cfg.skip_field(|struct_, field| { match (struct_, field) { // conflicting with `p_type` macro from .