From 70004713b855d4fe1328d4faa33bca037cd17be3 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Wed, 5 Jun 2024 17:14:58 +1000 Subject: [PATCH 01/27] feat: add missing netfilter consts --- libc-test/build.rs | 14 +++++++++-- libc-test/semver/android.txt | 24 +++++++++++++++++++ libc-test/semver/linux.txt | 24 +++++++++++++++++++ src/unix/linux_like/android/mod.rs | 31 ++++++++++++++++++++++++- src/unix/linux_like/linux/mod.rs | 37 ++++++++++++++++++++++++++---- 5 files changed, 123 insertions(+), 7 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 2da148caa61ba..794f503540cf8 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1631,6 +1631,8 @@ fn test_android(target: &str) { "linux/netfilter/nfnetlink_log.h", "linux/netfilter/nfnetlink_queue.h", "linux/netfilter/nf_tables.h", + "linux/netfilter_arp.h", + "linux/netfilter_bridge.h", "linux/netfilter_ipv4.h", "linux/netfilter_ipv6.h", "linux/netfilter_ipv6/ip6_tables.h", @@ -3419,6 +3421,8 @@ fn test_linux(target: &str) { "linux/netfilter/nfnetlink_log.h", "linux/netfilter/nfnetlink_queue.h", "linux/netfilter/nf_tables.h", + "linux/netfilter_arp.h", + "linux/netfilter_bridge.h", "linux/netfilter_ipv4.h", "linux/netfilter_ipv6.h", "linux/netfilter_ipv6/ip6_tables.h", @@ -3935,9 +3939,15 @@ fn test_linux(target: &str) { | "MINSIGSTKSZ" if gnu => true, - // FIXME: Linux >= 5.16 changed its value: + // FIXME: Linux >= 5.10: + // https://github.com/torvalds/linux/commit/d25e2e9388eda61b6e298585024ee3355f50c493 + "NF_INET_INGRESS" if musl => true, + + // FIXME: Linux >= 5.16: // https://github.com/torvalds/linux/commit/42df6e1d221dddc0f2acf2be37e68d553ad65f96 - "NF_NETDEV_NUMHOOKS" => true, + "NF_NETDEV_EGRESS" if musl || sparc64 => true, + // value changed + "NF_NETDEV_NUMHOOKS" if musl || sparc64 => true, // FIXME: requires Linux >= 5.6: | "RESOLVE_BENEATH" diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 5210a8a643287..8bca8a5245948 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -1644,8 +1644,29 @@ NFULNL_COPY_PACKET NFULNL_MSG_CONFIG NFULNL_MSG_PACKET NF_ACCEPT +NF_ARP +NF_ARP_FORWARD +NF_ARP_IN +NF_ARP_NUMHOOKS +NF_ARP_OUT +NF_BR_BROUTING +NF_BR_FORWARD +NF_BR_LOCAL_IN +NF_BR_LOCAL_OUT +NF_BR_NUMHOOKS +NF_BR_POST_ROUTING +NF_BR_PRE_ROUTING +NF_BR_PRI_BRNF +NF_BR_PRI_FILTER_BRIDGED +NF_BR_PRI_FILTER_OTHER +NF_BR_PRI_FIRST +NF_BR_PRI_LAST +NF_BR_PRI_NAT_DST_BRIDGED +NF_BR_PRI_NAT_DST_OTHER +NF_BR_PRI_NAT_SRC NF_DROP NF_INET_FORWARD +NF_INET_INGRESS NF_INET_LOCAL_IN NF_INET_LOCAL_OUT NF_INET_NUMHOOKS @@ -1667,6 +1688,7 @@ NF_IP6_PRI_MANGLE NF_IP6_PRI_NAT_DST NF_IP6_PRI_NAT_SRC NF_IP6_PRI_RAW +NF_IP6_PRI_RAW_BEFORE_DEFRAG NF_IP6_PRI_SECURITY NF_IP6_PRI_SELINUX_FIRST NF_IP6_PRI_SELINUX_LAST @@ -1687,10 +1709,12 @@ NF_IP_PRI_MANGLE NF_IP_PRI_NAT_DST NF_IP_PRI_NAT_SRC NF_IP_PRI_RAW +NF_IP_PRI_RAW_BEFORE_DEFRAG NF_IP_PRI_SECURITY NF_IP_PRI_SELINUX_FIRST NF_IP_PRI_SELINUX_LAST NF_MAX_VERDICT +NF_NETDEV_EGRESS NF_NETDEV_INGRESS NF_NETDEV_NUMHOOKS NF_QUEUE diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 715af2dc0fadf..5691855371f66 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -1692,8 +1692,29 @@ NFULNL_COPY_PACKET NFULNL_MSG_CONFIG NFULNL_MSG_PACKET NF_ACCEPT +NF_ARP +NF_ARP_FORWARD +NF_ARP_IN +NF_ARP_NUMHOOKS +NF_ARP_OUT +NF_BR_BROUTING +NF_BR_FORWARD +NF_BR_LOCAL_IN +NF_BR_LOCAL_OUT +NF_BR_NUMHOOKS +NF_BR_POST_ROUTING +NF_BR_PRE_ROUTING +NF_BR_PRI_BRNF +NF_BR_PRI_FILTER_BRIDGED +NF_BR_PRI_FILTER_OTHER +NF_BR_PRI_FIRST +NF_BR_PRI_LAST +NF_BR_PRI_NAT_DST_BRIDGED +NF_BR_PRI_NAT_DST_OTHER +NF_BR_PRI_NAT_SRC NF_DROP NF_INET_FORWARD +NF_INET_INGRESS NF_INET_LOCAL_IN NF_INET_LOCAL_OUT NF_INET_NUMHOOKS @@ -1715,6 +1736,7 @@ NF_IP6_PRI_MANGLE NF_IP6_PRI_NAT_DST NF_IP6_PRI_NAT_SRC NF_IP6_PRI_RAW +NF_IP6_PRI_RAW_BEFORE_DEFRAG NF_IP6_PRI_SECURITY NF_IP6_PRI_SELINUX_FIRST NF_IP6_PRI_SELINUX_LAST @@ -1735,10 +1757,12 @@ NF_IP_PRI_MANGLE NF_IP_PRI_NAT_DST NF_IP_PRI_NAT_SRC NF_IP_PRI_RAW +NF_IP_PRI_RAW_BEFORE_DEFRAG NF_IP_PRI_SECURITY NF_IP_PRI_SELINUX_FIRST NF_IP_PRI_SELINUX_LAST NF_MAX_VERDICT +NF_NETDEV_EGRESS NF_QUEUE NF_REPEAT NF_STOLEN diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index ef8c2ccaa4fde..4a920f2d172b7 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -2311,9 +2311,11 @@ pub const NF_INET_FORWARD: ::c_int = 2; pub const NF_INET_LOCAL_OUT: ::c_int = 3; pub const NF_INET_POST_ROUTING: ::c_int = 4; pub const NF_INET_NUMHOOKS: ::c_int = 5; +pub const NF_INET_INGRESS: ::c_int = NF_INET_NUMHOOKS; pub const NF_NETDEV_INGRESS: ::c_int = 0; -pub const NF_NETDEV_NUMHOOKS: ::c_int = 1; +pub const NF_NETDEV_EGRESS: ::c_int = 1; +pub const NF_NETDEV_NUMHOOKS: ::c_int = 2; pub const NFPROTO_UNSPEC: ::c_int = 0; pub const NFPROTO_INET: ::c_int = 1; @@ -2325,6 +2327,31 @@ pub const NFPROTO_IPV6: ::c_int = 10; pub const NFPROTO_DECNET: ::c_int = 12; pub const NFPROTO_NUMPROTO: ::c_int = 13; +// linux/netfilter_arp.h +pub const NF_ARP: ::c_int = 0; +pub const NF_ARP_IN: ::c_int = 0; +pub const NF_ARP_OUT: ::c_int = 1; +pub const NF_ARP_FORWARD: ::c_int = 2; +pub const NF_ARP_NUMHOOKS: ::c_int = 3; + +// linux/netfilter_bridge.h +pub const NF_BR_PRE_ROUTING: ::c_int = 0; +pub const NF_BR_LOCAL_IN: ::c_int = 1; +pub const NF_BR_FORWARD: ::c_int = 2; +pub const NF_BR_LOCAL_OUT: ::c_int = 3; +pub const NF_BR_POST_ROUTING: ::c_int = 4; +pub const NF_BR_BROUTING: ::c_int = 5; +pub const NF_BR_NUMHOOKS: ::c_int = 6; + +pub const NF_BR_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_BR_PRI_NAT_DST_BRIDGED: ::c_int = -300; +pub const NF_BR_PRI_FILTER_BRIDGED: ::c_int = -200; +pub const NF_BR_PRI_BRNF: ::c_int = 0; +pub const NF_BR_PRI_NAT_DST_OTHER: ::c_int = 100; +pub const NF_BR_PRI_FILTER_OTHER: ::c_int = 200; +pub const NF_BR_PRI_NAT_SRC: ::c_int = 300; +pub const NF_BR_PRI_LAST: ::c_int = ::INT_MAX; + // linux/netfilter_ipv4.h pub const NF_IP_PRE_ROUTING: ::c_int = 0; pub const NF_IP_LOCAL_IN: ::c_int = 1; @@ -2334,6 +2361,7 @@ pub const NF_IP_POST_ROUTING: ::c_int = 4; pub const NF_IP_NUMHOOKS: ::c_int = 5; pub const NF_IP_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP_PRI_RAW: ::c_int = -300; pub const NF_IP_PRI_SELINUX_FIRST: ::c_int = -225; @@ -2357,6 +2385,7 @@ pub const NF_IP6_POST_ROUTING: ::c_int = 4; pub const NF_IP6_NUMHOOKS: ::c_int = 5; pub const NF_IP6_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP6_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP6_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP6_PRI_RAW: ::c_int = -300; pub const NF_IP6_PRI_SELINUX_FIRST: ::c_int = -225; diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index ac0bb87b2ced4..d660face6d04a 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -3288,20 +3288,47 @@ pub const NF_INET_FORWARD: ::c_int = 2; pub const NF_INET_LOCAL_OUT: ::c_int = 3; pub const NF_INET_POST_ROUTING: ::c_int = 4; pub const NF_INET_NUMHOOKS: ::c_int = 5; +pub const NF_INET_INGRESS: ::c_int = NF_INET_NUMHOOKS; + +pub const NF_NETDEV_INGRESS: ::c_int = 0; +pub const NF_NETDEV_EGRESS: ::c_int = 1; +pub const NF_NETDEV_NUMHOOKS: ::c_int = 2; // Some NFPROTO are not compatible with musl and are defined in submodules. pub const NFPROTO_UNSPEC: ::c_int = 0; +pub const NFPROTO_INET: ::c_int = 1; pub const NFPROTO_IPV4: ::c_int = 2; pub const NFPROTO_ARP: ::c_int = 3; +pub const NFPROTO_NETDEV: ::c_int = 5; pub const NFPROTO_BRIDGE: ::c_int = 7; pub const NFPROTO_IPV6: ::c_int = 10; pub const NFPROTO_DECNET: ::c_int = 12; pub const NFPROTO_NUMPROTO: ::c_int = 13; -pub const NFPROTO_INET: ::c_int = 1; -pub const NFPROTO_NETDEV: ::c_int = 5; -pub const NF_NETDEV_INGRESS: ::c_int = 0; -pub const NF_NETDEV_NUMHOOKS: ::c_int = 1; +// linux/netfilter_arp.h +pub const NF_ARP: ::c_int = 0; +pub const NF_ARP_IN: ::c_int = 0; +pub const NF_ARP_OUT: ::c_int = 1; +pub const NF_ARP_FORWARD: ::c_int = 2; +pub const NF_ARP_NUMHOOKS: ::c_int = 3; + +// linux/netfilter_bridge.h +pub const NF_BR_PRE_ROUTING: ::c_int = 0; +pub const NF_BR_LOCAL_IN: ::c_int = 1; +pub const NF_BR_FORWARD: ::c_int = 2; +pub const NF_BR_LOCAL_OUT: ::c_int = 3; +pub const NF_BR_POST_ROUTING: ::c_int = 4; +pub const NF_BR_BROUTING: ::c_int = 5; +pub const NF_BR_NUMHOOKS: ::c_int = 6; + +pub const NF_BR_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_BR_PRI_NAT_DST_BRIDGED: ::c_int = -300; +pub const NF_BR_PRI_FILTER_BRIDGED: ::c_int = -200; +pub const NF_BR_PRI_BRNF: ::c_int = 0; +pub const NF_BR_PRI_NAT_DST_OTHER: ::c_int = 100; +pub const NF_BR_PRI_FILTER_OTHER: ::c_int = 200; +pub const NF_BR_PRI_NAT_SRC: ::c_int = 300; +pub const NF_BR_PRI_LAST: ::c_int = ::INT_MAX; // linux/netfilter_ipv4.h pub const NF_IP_PRE_ROUTING: ::c_int = 0; @@ -3312,6 +3339,7 @@ pub const NF_IP_POST_ROUTING: ::c_int = 4; pub const NF_IP_NUMHOOKS: ::c_int = 5; pub const NF_IP_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP_PRI_RAW: ::c_int = -300; pub const NF_IP_PRI_SELINUX_FIRST: ::c_int = -225; @@ -3335,6 +3363,7 @@ pub const NF_IP6_POST_ROUTING: ::c_int = 4; pub const NF_IP6_NUMHOOKS: ::c_int = 5; pub const NF_IP6_PRI_FIRST: ::c_int = ::INT_MIN; +pub const NF_IP6_PRI_RAW_BEFORE_DEFRAG: ::c_int = -450; pub const NF_IP6_PRI_CONNTRACK_DEFRAG: ::c_int = -400; pub const NF_IP6_PRI_RAW: ::c_int = -300; pub const NF_IP6_PRI_SELINUX_FIRST: ::c_int = -225; From d4da6c866a9b25cc37f73d2a27cb9f2d61397298 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Sat, 9 Mar 2024 02:27:20 +0000 Subject: [PATCH 02/27] Move testing of primitive types from std --- libc-test/Cargo.toml | 5 +++++ libc-test/test/primitive_types.rs | 15 +++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 libc-test/test/primitive_types.rs diff --git a/libc-test/Cargo.toml b/libc-test/Cargo.toml index 20543d69bcb0f..8d85ad794ed53 100644 --- a/libc-test/Cargo.toml +++ b/libc-test/Cargo.toml @@ -85,3 +85,8 @@ harness = true name = "semver" path = "test/semver.rs" harness = false + +[[test]] +name = "primitive_types" +path = "test/primitive_types.rs" +harness = true diff --git a/libc-test/test/primitive_types.rs b/libc-test/test/primitive_types.rs new file mode 100644 index 0000000000000..c125a92a58110 --- /dev/null +++ b/libc-test/test/primitive_types.rs @@ -0,0 +1,15 @@ +use std::any::TypeId; + +macro_rules! ok { + ($($t:ident)*) => {$( + assert!(TypeId::of::() == TypeId::of::(), + "{} is wrong", stringify!($t)); + )*} +} + +#[test] +fn same() { + use std::ffi; + ok!(c_char c_schar c_uchar c_short c_ushort c_int c_uint c_long c_ulong + c_longlong c_ulonglong c_float c_double); +} From 73a6a03e81c3727703c28207dc539589cc77e267 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sun, 21 Jul 2024 16:45:03 +0100 Subject: [PATCH 03/27] vxWorks adding few errnoLib related constants. --- src/vxworks/mod.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/vxworks/mod.rs b/src/vxworks/mod.rs index 7da4ec05bd828..def1cccfa58ce 100644 --- a/src/vxworks/mod.rs +++ b/src/vxworks/mod.rs @@ -91,6 +91,7 @@ pub type SEM_ID_KERNEL = ::OBJ_HANDLE; pub type RTP_ID = ::OBJ_HANDLE; pub type SD_ID = ::OBJ_HANDLE; pub type CONDVAR_ID = ::OBJ_HANDLE; +pub type STATUS = ::OBJ_HANDLE; // From vxTypes.h pub type _Vx_usr_arg_t = isize; @@ -613,6 +614,7 @@ pub const PTHREAD_STACK_MIN: usize = 4096; pub const _PTHREAD_SHARED_SEM_NAME_MAX: usize = 30; // ERRNO STUFF +pub const ERROR: ::c_int = -1; pub const OK: ::c_int = 0; pub const EPERM: ::c_int = 1; /* Not owner */ pub const ENOENT: ::c_int = 2; /* No such file or directory */ @@ -720,6 +722,33 @@ pub const S_nfsLib_NFSERR_SERVERFAULT: ::c_int = EIO; pub const S_nfsLib_NFSERR_BADTYPE: ::c_int = M_nfsStat | nfsstat::NFSERR_BADTYPE as ::c_int; pub const S_nfsLib_NFSERR_JUKEBOX: ::c_int = M_nfsStat | nfsstat::NFSERR_JUKEBOX as ::c_int; +// internal offset values for below constants +const taskErrorBase: ::c_int = 0x00030000; +const semErrorBase: ::c_int = 0x00160000; +const objErrorBase: ::c_int = 0x003d0000; + +// taskLibCommon.h +pub const S_taskLib_NAME_NOT_FOUND: ::c_int = taskErrorBase + 0x0065; +pub const S_taskLib_TASK_HOOK_TABLE_FULL: ::c_int = taskErrorBase + 0x0066; +pub const S_taskLib_TASK_HOOK_NOT_FOUND: ::c_int = taskErrorBase + 0x0067; +pub const S_taskLib_ILLEGAL_PRIORITY: ::c_int = taskErrorBase + 0x0068; + +// FIXME: could also be useful for TASK_DESC type +pub const VX_TASK_NAME_LENGTH: ::c_int = 31; + +// semLibCommon.h +pub const S_semLib_INVALID_STATE: ::c_int = semErrorBase + 0x0065; +pub const S_semLib_INVALID_OPTION: ::c_int = semErrorBase + 0x0066; +pub const S_semLib_INVALID_QUEUE_TYPE: ::c_int = semErrorBase + 0x0067; +pub const S_semLib_INVALID_OPERATION: ::c_int = semErrorBase + 0x0068; + +// objLibCommon.h +pub const S_objLib_OBJ_ID_ERROR: ::c_int = objErrorBase + 0x0001; +pub const S_objLib_OBJ_UNAVAILABLE: ::c_int = objErrorBase + 0x0002; +pub const S_objLib_OBJ_DELETED: ::c_int = objErrorBase + 0x0003; +pub const S_objLib_OBJ_TIMEOUT: ::c_int = objErrorBase + 0x0004; +pub const S_objLib_OBJ_NO_METHOD: ::c_int = objErrorBase + 0x0005; + // in.h pub const IPPROTO_IP: ::c_int = 0; pub const IPPROTO_IPV6: ::c_int = 41; From 6e018a3b2fb41f782d935c800d0b6cffc4e70c19 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 12 Aug 2024 05:15:18 -0500 Subject: [PATCH 04/27] Allow setting `stable-nominated` via rustbot --- triagebot.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/triagebot.toml b/triagebot.toml index 8b989c8db5058..1fa350bf74cdd 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1,6 +1,6 @@ [relabel] allow-unauthenticated = [ - "C-*", "O-*", "S-*" + "C-*", "O-*", "S-*", "stable-nominated" ] [autolabel."S-waiting-on-review"] From 460fb7424f08380539f44caffbbd5b25ade91d33 Mon Sep 17 00:00:00 2001 From: mekosko Date: Mon, 12 Aug 2024 23:01:42 +0500 Subject: [PATCH 05/27] fix: use c_char from crate root --- src/unix/bsd/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index e2b5121b03911..83e675ca3474d 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -128,7 +128,7 @@ s_no_extra_traits! { pub struct sockaddr_un { pub sun_len: u8, pub sun_family: sa_family_t, - pub sun_path: [c_char; 104] + pub sun_path: [::c_char; 104] } pub struct utsname { From d5019f0d860bfc41bce8390447528dd2d0ca3438 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 12 Aug 2024 13:29:24 -0500 Subject: [PATCH 06/27] Update macro docs and formatting Add documentation to `src/macros.rs` and adjust some formatting. --- src/macros.rs | 163 +++++++++++++++++++++++++++++++------------------- 1 file changed, 103 insertions(+), 60 deletions(-) diff --git a/src/macros.rs b/src/macros.rs index aa08505239c58..7090e6d1d1538 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -61,13 +61,23 @@ macro_rules! cfg_if { }; } +/// Implement `Clone` and `Copy` for a struct, as well as `Debug`, `Eq`, `Hash`, and +/// `PartialEq` if the `extra_traits` feature is enabled. +/// +/// Use [`s_no_extra_traits`] for structs where the `extra_traits` feature does not +/// make sense, and for unions. macro_rules! s { - ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($( + ($( + $(#[$attr:meta])* + pub $t:ident $i:ident { $($field:tt)* } + )*) => ($( s!(it: $(#[$attr])* pub $t $i { $($field)* }); )*); + (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => ( compile_error!("unions cannot derive extra traits, use s_no_extra_traits instead"); ); + (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] @@ -85,10 +95,38 @@ macro_rules! s { ); } +/// Implement `Clone` and `Copy` for a tuple struct, as well as `Debug`, `Eq`, `Hash`, +/// and `PartialEq` if the `extra_traits` feature is enabled. +/// +/// This is the same as [`s`] but works for tuple structs. +macro_rules! s_paren { + ($( + $(#[$attr:meta])* + pub struct $i:ident ( $($field:tt)* ); + )*) => ($( + __item! { + #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] + $(#[$attr])* + pub struct $i ( $($field)* ); + } + impl ::Copy for $i {} + impl ::Clone for $i { + fn clone(&self) -> $i { *self } + } + )*); +} + +/// Implement `Clone` and `Copy` for a struct with no `extra_traits` feature. +/// +/// Most items will prefer to use [`s`]. macro_rules! s_no_extra_traits { - ($($(#[$attr:meta])* pub $t:ident $i:ident { $($field:tt)* })*) => ($( + ($( + $(#[$attr:meta])* + pub $t:ident $i:ident { $($field:tt)* } + )*) => ($( s_no_extra_traits!(it: $(#[$attr])* pub $t $i { $($field)* }); )*); + (it: $(#[$attr:meta])* pub union $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] @@ -101,6 +139,7 @@ macro_rules! s_no_extra_traits { fn clone(&self) -> $i { *self } } ); + (it: $(#[$attr:meta])* pub struct $i:ident { $($field:tt)* }) => ( __item! { #[repr(C)] @@ -116,14 +155,26 @@ macro_rules! s_no_extra_traits { ); } +/// Specify that an enum should have no traits that aren't specified in the macro +/// invocation, i.e. no `Clone` or `Copy`. macro_rules! missing { - ($($(#[$attr:meta])* pub enum $i:ident {})*) => ($( - $(#[$attr])* #[allow(missing_copy_implementations)] pub enum $i { } + ($( + $(#[$attr:meta])* + pub enum $i:ident {} + )*) => ($( + $(#[$attr])* + #[allow(missing_copy_implementations)] + pub enum $i { } )*); } +/// Implement `Clone` and `Copy` for an enum, as well as `Debug`, `Eq`, `Hash`, and +/// `PartialEq` if the `extra_traits` feature is enabled. macro_rules! e { - ($($(#[$attr:meta])* pub enum $i:ident { $($field:tt)* })*) => ($( + ($( + $(#[$attr:meta])* + pub enum $i:ident { $($field:tt)* } + )*) => ($( __item! { #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] $(#[$attr])* @@ -136,89 +187,80 @@ macro_rules! e { )*); } -macro_rules! s_paren { - ($($(#[$attr:meta])* pub struct $i:ident ( $($field:tt)* ); )* ) => ($( - __item! { - #[cfg_attr(feature = "extra_traits", derive(Debug, Eq, Hash, PartialEq))] - $(#[$attr])* - pub struct $i ( $($field)* ); - } - impl ::Copy for $i {} - impl ::Clone for $i { - fn clone(&self) -> $i { *self } - } - )*); -} - cfg_if! { if #[cfg(feature = "const-extern-fn")] { + /// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled. macro_rules! f { - ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( + ($( + $(#[$attr:meta])* + pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty { + $($body:stmt);* + } + )*) => ($( #[inline] $(#[$attr])* - pub $($constness)* unsafe extern fn $i($($arg: $argty),* - ) -> $ret { + pub $($constness)* unsafe extern fn $i($($arg: $argty),*) -> $ret { $($body);* } )*) } + /// Define a safe function that is const as long as `const-extern-fn` is enabled. macro_rules! safe_f { - ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( + ($( + $(#[$attr:meta])* + pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty { + $($body:stmt);* + } + )*) => ($( #[inline] $(#[$attr])* - pub $($constness)* extern fn $i($($arg: $argty),* - ) -> $ret { + pub $($constness)* extern fn $i($($arg: $argty),*) -> $ret { $($body);* } )*) } + /// A nonpublic function that is const as long as `const-extern-fn` is enabled. macro_rules! const_fn { - ($($(#[$attr:meta])* $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( + ($( + $(#[$attr:meta])* + $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty { + $($body:stmt);* + } + )*) => ($( #[inline] $(#[$attr])* - $($constness)* fn $i($($arg: $argty),* - ) -> $ret { + $($constness)* fn $i($($arg: $argty),*) -> $ret { $($body);* } )*) } - } else { + /// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled. macro_rules! f { - ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( + ($( + $(#[$attr:meta])* + pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty { + $($body:stmt);* + } + )*) => ($( #[inline] $(#[$attr])* - pub unsafe extern fn $i($($arg: $argty),* - ) -> $ret { + pub unsafe extern fn $i($($arg: $argty),*) -> $ret { $($body);* } )*) } + /// Define a safe function that is const as long as `const-extern-fn` is enabled. macro_rules! safe_f { - ($($(#[$attr:meta])* pub $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( + ($( + $(#[$attr:meta])* + pub $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty { + $($body:stmt);* + } + )*) => ($( #[inline] $(#[$attr])* pub extern fn $i($($arg: $argty),* @@ -228,16 +270,17 @@ cfg_if! { )*) } + /// A nonpublic function that is const as long as `const-extern-fn` is enabled. macro_rules! const_fn { - ($($(#[$attr:meta])* $({$constness:ident})* fn $i:ident( - $($arg:ident: $argty:ty),* - ) -> $ret:ty { - $($body:stmt);* - })*) => ($( + ($( + $(#[$attr:meta])* + $({$constness:ident})* fn $i:ident($($arg:ident: $argty:ty),*) -> $ret:ty { + $($body:stmt);* + } + )*) => ($( #[inline] $(#[$attr])* - fn $i($($arg: $argty),* - ) -> $ret { + fn $i($($arg: $argty),*) -> $ret { $($body);* } )*) From 09b8a4f0af7d2cb88fe5eafb35449bd43bf84242 Mon Sep 17 00:00:00 2001 From: Evan Wildenhain Date: Mon, 22 Jul 2024 10:45:25 -0400 Subject: [PATCH 07/27] Define SO_BINDTOIFINDEX on Fuchsia Fuchsia supports SO_BINDTOIFINDEX as of API level 20: https://cs.opensource.google/fuchsia/fuchsia/+/main:sdk/lib/zxio/socket.cc;l=755;drc=b03121152bf13fb8898a95b58d952c95ee73cd0c --- libc-test/semver/fuchsia.txt | 1 + src/fuchsia/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/libc-test/semver/fuchsia.txt b/libc-test/semver/fuchsia.txt index 525b26bd62940..164916ccd554f 100644 --- a/libc-test/semver/fuchsia.txt +++ b/libc-test/semver/fuchsia.txt @@ -951,6 +951,7 @@ SOL_UDP SOL_X25 SOMAXCONN SO_BINDTODEVICE +SO_BINDTOIFINDEX SO_BSDCOMPAT SO_BUSY_POLL SO_DOMAIN diff --git a/src/fuchsia/mod.rs b/src/fuchsia/mod.rs index 65d7e9005ddfe..bf4250c974106 100644 --- a/src/fuchsia/mod.rs +++ b/src/fuchsia/mod.rs @@ -2979,6 +2979,7 @@ pub const SO_MARK: ::c_int = 36; pub const SO_RXQ_OVFL: ::c_int = 40; pub const SO_PEEK_OFF: ::c_int = 42; pub const SO_BUSY_POLL: ::c_int = 46; +pub const SO_BINDTOIFINDEX: ::c_int = 62; pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; From 80d43bf020792098497a94d0ff1c9ef30e8bdf05 Mon Sep 17 00:00:00 2001 From: Rain Date: Wed, 31 Jul 2024 15:25:40 -0700 Subject: [PATCH 08/27] [illumos] add pthread stack functions --- libc-test/semver/illumos.txt | 3 +++ src/unix/solarish/illumos.rs | 15 +++++++++++++++ 2 files changed, 18 insertions(+) create mode 100644 libc-test/semver/illumos.txt diff --git a/libc-test/semver/illumos.txt b/libc-test/semver/illumos.txt new file mode 100644 index 0000000000000..d0ef608456d54 --- /dev/null +++ b/libc-test/semver/illumos.txt @@ -0,0 +1,3 @@ +pthread_attr_get_np +pthread_attr_getstackaddr +pthread_attr_setstack diff --git a/src/unix/solarish/illumos.rs b/src/unix/solarish/illumos.rs index 404f013da2f98..ef3862ee41b34 100644 --- a/src/unix/solarish/illumos.rs +++ b/src/unix/solarish/illumos.rs @@ -81,6 +81,21 @@ extern "C" { ) -> ::c_int; pub fn pset_getloadavg(pset: ::psetid_t, load: *mut ::c_double, num: ::c_int) -> ::c_int; + pub fn pthread_attr_get_np(thread: ::pthread_t, attr: *mut ::pthread_attr_t) -> ::c_int; + pub fn pthread_attr_getstackaddr( + attr: *const ::pthread_attr_t, + stackaddr: *mut *mut ::c_void, + ) -> ::c_int; + pub fn pthread_attr_setstack( + attr: *mut ::pthread_attr_t, + stackaddr: *mut ::c_void, + stacksize: ::size_t, + ) -> ::c_int; + pub fn pthread_attr_setstackaddr( + attr: *mut ::pthread_attr_t, + stackaddr: *mut ::c_void, + ) -> ::c_int; + pub fn preadv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, offset: ::off_t) -> ::ssize_t; pub fn pwritev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int, offset: ::off_t) -> ::ssize_t; From 9fda1f68219ed0d740ea38f967d50efef063219f Mon Sep 17 00:00:00 2001 From: kxxt Date: Sat, 22 Jun 2024 13:24:18 +0800 Subject: [PATCH 09/27] Add clone_args for riscv64 linux gnu/musl --- .../linux_like/linux/gnu/b64/riscv64/align.rs | 17 +++++++++++++++++ .../linux_like/linux/musl/b64/riscv64/align.rs | 17 +++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/src/unix/linux_like/linux/gnu/b64/riscv64/align.rs b/src/unix/linux_like/linux/gnu/b64/riscv64/align.rs index 48d152a5721ec..5b33f2375d39c 100644 --- a/src/unix/linux_like/linux/gnu/b64/riscv64/align.rs +++ b/src/unix/linux_like/linux/gnu/b64/riscv64/align.rs @@ -42,3 +42,20 @@ s_no_extra_traits! { pub __glibc_reserved: [::c_uint; 3], } } + +s! { + #[repr(align(8))] + pub struct clone_args { + pub flags: ::c_ulonglong, + pub pidfd: ::c_ulonglong, + pub child_tid: ::c_ulonglong, + pub parent_tid: ::c_ulonglong, + pub exit_signal: ::c_ulonglong, + pub stack: ::c_ulonglong, + pub stack_size: ::c_ulonglong, + pub tls: ::c_ulonglong, + pub set_tid: ::c_ulonglong, + pub set_tid_size: ::c_ulonglong, + pub cgroup: ::c_ulonglong, + } +} diff --git a/src/unix/linux_like/linux/musl/b64/riscv64/align.rs b/src/unix/linux_like/linux/musl/b64/riscv64/align.rs index 48d152a5721ec..5b33f2375d39c 100644 --- a/src/unix/linux_like/linux/musl/b64/riscv64/align.rs +++ b/src/unix/linux_like/linux/musl/b64/riscv64/align.rs @@ -42,3 +42,20 @@ s_no_extra_traits! { pub __glibc_reserved: [::c_uint; 3], } } + +s! { + #[repr(align(8))] + pub struct clone_args { + pub flags: ::c_ulonglong, + pub pidfd: ::c_ulonglong, + pub child_tid: ::c_ulonglong, + pub parent_tid: ::c_ulonglong, + pub exit_signal: ::c_ulonglong, + pub stack: ::c_ulonglong, + pub stack_size: ::c_ulonglong, + pub tls: ::c_ulonglong, + pub set_tid: ::c_ulonglong, + pub set_tid_size: ::c_ulonglong, + pub cgroup: ::c_ulonglong, + } +} From 67d062f97ad8f517242a4cc101d3beda5e5dfeb9 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 12 Aug 2024 21:09:45 +0100 Subject: [PATCH 10/27] freebsd adding execvpe support from 14.1 release --- libc-test/build.rs | 2 ++ libc-test/semver/freebsd.txt | 1 + src/unix/bsd/freebsdlike/freebsd/mod.rs | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index f2c6c3ccddf5a..09dc440400590 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -2489,6 +2489,8 @@ fn test_freebsd(target: &str) { cfg.skip_fn(move |name| { // skip those that are manually verified match name { + // This is introduced in FreeBSD 14.1 + "execvpe" => true, // The `uname` function in the `utsname.h` FreeBSD header is a C // inline function (has no symbol) that calls the `__xuname` symbol. // Therefore the function pointer comparison does not make sense for it. diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 5a049d102114e..bb6d67c6d0079 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -1873,6 +1873,7 @@ eui64_hostton eui64_ntoa eui64_ntohost exect +execvpe execvP explicit_bzero extattr_delete_fd diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index a2942913b95d1..53f1f7adcaffd 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -5534,6 +5534,12 @@ extern "C" { idx1: ::c_ulong, idx2: ::c_ulong, ) -> ::c_int; + + pub fn execvpe( + file: *const ::c_char, + argv: *const *const ::c_char, + envp: *const *const ::c_char, + ) -> ::c_int; } #[link(name = "memstat")] From 6b1ae22e6719ee30bd44d2f34f03d155bf554192 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 12 Aug 2024 15:39:35 -0500 Subject: [PATCH 11/27] Update documentation with the 0.2/1.0 workflow Clarify that PRs should be to `main` then cherry picked to 0.2 after review, in order to keep things from getting too out of sync or needing to conduct the same review in multiple places. --- .github/PULL_REQUEST_TEMPLATE.md | 2 +- CONTRIBUTING.md | 41 +++++++++++++++++++++++++++----- README.md | 13 ++++++---- 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 70ed1ca355300..978a5e578549a 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -10,6 +10,6 @@ Here's a checklist for things that will be checked during review or continuous i - \[ ] If your PR increments version number, it must NOT contain any other changes (otherwise a release could be delayed) - \[ ] Make sure `ci/style.sh` passes - \[ ] `cd libc-test && cargo test` - - (this might fail on your env due to environment difference between your env and CI. Ignore failures if you are not sure) + - (this might fail on your env due to environment difference between your env and CI. Ignore local failures if you are not sure) Delete this line and everything above before opening your PR. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b6f41cc6de85e..beebff7ac4c08 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -3,12 +3,41 @@ Welcome! If you are reading this document, it means you are interested in contributing to the `libc` crate. -## v0.2 changes +## v1.0 Roadmap -If you want to add your changes to v0.2, please submit them to the `libc-0.2` branch. -If you want to add any breaking changes, it should be submitted to the main branch, -which has changes for v0.3. -We will support and make a new release for v0.2 until we make the first release of v0.3. +`libc` has two active branches: `main` and `libc-0.2`. `main` is for active +development of the upcoming v1.0 release, and should be the target of all pull +requests. `libc-0.2` is for updates to the currently released version. + +If a pull request to `main` is a good candidate for inclusion in an `0.2.x` +release, include `@rustbot label stable-nominated` in a comment to propose this. +Good candidates will usually meet the following: + +1. The included changes are non-breaking. +2. The change applies cleanly to both branches. +3. There is a usecase that justifies inclusion in a stable release (all + additions should always have a usecase, hopefully). + +Once a `stable-nominated` PR targeting `main` has merged, it can be cherry +picked to the `libc-0.2` branch. A maintainer will likely do these cherry +picks in a batch. + +Alternatively, you can start this process yourself by creating a new branch +based on `libc-0.2` and running `git cherry-pick -xe commit-sha-on-main` (`git +cherry-pick -xe start-sha^..end-sha` if a range of commits is needed). `git` +will automatically add the "cherry picked from commit" note, but try to add a +backport note so the original PR gets crosslinked: + +``` +# ... original commit message ... + +(backport ) # add manually +(cherry picked from commit 104b6a4ae31c726814c36318dc718470cc96e167) # added by git +``` + +Once the cherry-pick is complete, open a PR targeting `libc-0.2`. + +See the [tracking issue](https://github.com/rust-lang/libc/issues/3248) for details. ## Adding an API @@ -51,7 +80,7 @@ With that in mind, the steps for adding a new API are: 5. Wait for a merge! 1: Note that this list has nothing to do with any Unix or Posix -standard, it's just a list shared between all OSs that declare `#[cfg(unix)]`. +standard, it's just a list shared among all OSs that declare `#[cfg(unix)]`. ## Test before you commit diff --git a/README.md b/README.md index 4b72be03179aa..2ba6b9ced923d 100644 --- a/README.md +++ b/README.md @@ -16,14 +16,17 @@ More detailed information about the design of this library can be found in its [rfc]: https://github.com/rust-lang/rfcs/blob/HEAD/text/1291-promote-libc.md -## v0.3 Roadmap +## v1.0 Roadmap -The main branch is now for v0.3 which has some breaking changes. +Currently, `libc` has two active branches: `main` for the upcoming v1.0 release, +and `libc-0.2` for the currently published version. By default all pull requests +should target `main`; once reviewed, they can be cherry picked to the `libc-0.2` +branch if needed. -For v0.2, please submit PRs to the `libc-0.2` branch instead. -We will stop making new v0.2 releases once we release v0.3 on crates.io. +We will stop making new v0.2 releases once v1.0 is released. -See the [tracking issue](https://github.com/rust-lang/libc/issues/3248) for details. +See the section in [CONTRIBUTING.md](CONTRIBUTING.md#v10-roadmap) for more +details. ## Usage From 8c5c7ce860a5e0cee5add2d4f33b36364d3fdb18 Mon Sep 17 00:00:00 2001 From: Daniel Schemmel Date: Sat, 27 Jul 2024 05:19:17 +0100 Subject: [PATCH 12/27] add FUTEX_WAITERS, FUTEX_OWNER_DIED and FUTEX_TID_MASK to linux --- libc-test/semver/linux.txt | 3 +++ src/unix/linux_like/linux/mod.rs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index b09fd745357fd..89331caf8d344 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -837,13 +837,16 @@ FUTEX_OP_OPARG_SHIFT FUTEX_OP_OR FUTEX_OP_SET FUTEX_OP_XOR +FUTEX_OWNER_DIED FUTEX_PRIVATE_FLAG FUTEX_REQUEUE +FUTEX_TID_MASK FUTEX_TRYLOCK_PI FUTEX_UNLOCK_PI FUTEX_WAIT FUTEX_WAIT_BITSET FUTEX_WAIT_REQUEUE_PI +FUTEX_WAITERS FUTEX_WAKE FUTEX_WAKE_BITSET FUTEX_WAKE_OP diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index d526bcb1d2243..5e2042fede677 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -4607,6 +4607,7 @@ pub const FAN_NOFD: ::c_int = -1; pub const FAN_NOPIDFD: ::c_int = FAN_NOFD; pub const FAN_EPIDFD: ::c_int = -2; +// linux/futex.h pub const FUTEX_WAIT: ::c_int = 0; pub const FUTEX_WAKE: ::c_int = 1; pub const FUTEX_FD: ::c_int = 2; @@ -4626,6 +4627,10 @@ pub const FUTEX_PRIVATE_FLAG: ::c_int = 128; pub const FUTEX_CLOCK_REALTIME: ::c_int = 256; pub const FUTEX_CMD_MASK: ::c_int = !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME); +pub const FUTEX_WAITERS: u32 = 0x80000000; +pub const FUTEX_OWNER_DIED: u32 = 0x40000000; +pub const FUTEX_TID_MASK: u32 = 0x3fffffff; + pub const FUTEX_BITSET_MATCH_ANY: ::c_int = 0xffffffff; pub const FUTEX_OP_SET: ::c_int = 0; From 966c359357797cfd73ebe8de162a76fb4248178e Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 12 Aug 2024 17:53:04 -0500 Subject: [PATCH 13/27] Add a note asking for headers or documentation in PRs Having a link to relevant source makes PRs much easier to review, especially on less common platforms. Request that as part of the PR template. --- .github/PULL_REQUEST_TEMPLATE.md | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 978a5e578549a..3bfd0807ce11b 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -1,15 +1,25 @@ Thanks for considering submitting a PR! -We have the [contribution guide](https://github.com/rust-lang/libc/blob/main/CONTRIBUTING.md). Please read it if you're new here! +We have the +[contribution guide](https://github.com/rust-lang/libc/blob/main/CONTRIBUTING.md). +Please read it if you're new here! -Here's a checklist for things that will be checked during review or continuous integration. +Here is a checklist for things that will be checked during review or continuous +integration: -- \[ ] Edit corresponding file(s) under `libc-test/semver` when you add/remove item(s), e.g. edit `linux.txt` if you add an item to `src/unix/linux_like/linux/mod.rs` -- \[ ] Your PR doesn't contain any private or *unstable* values like `*LAST` or `*MAX` (see [#3131](https://github.com/rust-lang/libc/issues/3131)) +- \[ ] Edit corresponding file(s) under `libc-test/semver` when you add/remove + item(s), e.g. edit `linux.txt` if you add an item to + `src/unix/linux_like/linux/mod.rs` +- \[ ] Your PR doesn't contain any private or _unstable_ values like `*LAST` or + `*MAX` (see [#3131](https://github.com/rust-lang/libc/issues/3131)) +- \[ ] Provide a link to relevant source (headers or documentation) if your PR + adds or changes API. - \[ ] If your PR has a breaking change, please clarify it -- \[ ] If your PR increments version number, it must NOT contain any other changes (otherwise a release could be delayed) +- \[ ] If your PR increments version number, it must NOT contain any other + changes (otherwise a release could be delayed) - \[ ] Make sure `ci/style.sh` passes - \[ ] `cd libc-test && cargo test` - - (this might fail on your env due to environment difference between your env and CI. Ignore local failures if you are not sure) + - (this might fail on your env due to environment difference between your env + and CI. Ignore local failures if you are not sure) Delete this line and everything above before opening your PR. From 34942a570715b4f6afc507dc2bd9ae9e02b437d8 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Mon, 12 Aug 2024 19:27:48 +0100 Subject: [PATCH 14/27] freebsd moving the kinfo_file type to general use. but keeping the constant KINFO_FILE_SIZE for intel archs only. --- libc-test/semver/freebsd-x86_64.txt | 1 + libc-test/semver/freebsd.txt | 1 + src/unix/bsd/freebsdlike/freebsd/mod.rs | 63 ++++++++++++++++++ src/unix/bsd/freebsdlike/freebsd/x86.rs | 2 + .../bsd/freebsdlike/freebsd/x86_64/mod.rs | 65 +------------------ 5 files changed, 69 insertions(+), 63 deletions(-) diff --git a/libc-test/semver/freebsd-x86_64.txt b/libc-test/semver/freebsd-x86_64.txt index 8edfb525633db..be73d1f7290fe 100644 --- a/libc-test/semver/freebsd-x86_64.txt +++ b/libc-test/semver/freebsd-x86_64.txt @@ -1,4 +1,5 @@ Elf64_Auxinfo +KINFO_FILE_SIZE MAP_32BIT _MC_FLAG_MASK _MC_FPFMT_NODEV diff --git a/libc-test/semver/freebsd.txt b/libc-test/semver/freebsd.txt index 5a049d102114e..d427bedab574a 100644 --- a/libc-test/semver/freebsd.txt +++ b/libc-test/semver/freebsd.txt @@ -1981,6 +1981,7 @@ kcmp kevent key_t killpg +kinfo_file kinfo_getvmmap kinfo_proc kinfo_vmentry diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index a2942913b95d1..995381ce12975 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -1621,6 +1621,23 @@ s_no_extra_traits! { pub cause: sctp_error_cause, pub hmac_id: u16, } + + pub struct kinfo_file { + pub kf_structsize: ::c_int, + pub kf_type: ::c_int, + pub kf_fd: ::c_int, + pub kf_ref_count: ::c_int, + pub kf_flags: ::c_int, + _kf_pad0: ::c_int, + pub kf_offset: i64, + _priv: [::uintptr_t; 38], // FIXME if needed + pub kf_status: u16, + _kf_pad1: u16, + _kf_ispare0: ::c_int, + pub kf_cap_rights: ::cap_rights_t, + _kf_cap_spare: u64, + pub kf_path: [::c_char; ::PATH_MAX as usize], + } } cfg_if! { @@ -2529,6 +2546,52 @@ cfg_if! { {self.hmac_id}.hash(state); } } + + impl PartialEq for kinfo_file { + fn eq(&self, other: &kinfo_file) -> bool { + self.kf_structsize == other.kf_structsize && + self.kf_type == other.kf_type && + self.kf_fd == other.kf_fd && + self.kf_ref_count == other.kf_ref_count && + self.kf_flags == other.kf_flags && + self.kf_offset == other.kf_offset && + self.kf_status == other.kf_status && + self.kf_cap_rights == other.kf_cap_rights && + self.kf_path + .iter() + .zip(other.kf_path.iter()) + .all(|(a,b)| a == b) + } + } + impl Eq for kinfo_file {} + impl ::fmt::Debug for kinfo_file { + fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + f.debug_struct("kinfo_file") + .field("kf_structsize", &self.kf_structsize) + .field("kf_type", &self.kf_type) + .field("kf_fd", &self.kf_fd) + .field("kf_ref_count", &self.kf_ref_count) + .field("kf_flags", &self.kf_flags) + .field("kf_offset", &self.kf_offset) + .field("kf_status", &self.kf_status) + .field("kf_cap_rights", &self.kf_cap_rights) + .field("kf_path", &&self.kf_path[..]) + .finish() + } + } + impl ::hash::Hash for kinfo_file { + fn hash(&self, state: &mut H) { + self.kf_structsize.hash(state); + self.kf_type.hash(state); + self.kf_fd.hash(state); + self.kf_ref_count.hash(state); + self.kf_flags.hash(state); + self.kf_offset.hash(state); + self.kf_status.hash(state); + self.kf_cap_rights.hash(state); + self.kf_path.hash(state); + } + } } } diff --git a/src/unix/bsd/freebsdlike/freebsd/x86.rs b/src/unix/bsd/freebsdlike/freebsd/x86.rs index 29689c910689f..3e3e5cc9f34fb 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86.rs @@ -190,3 +190,5 @@ cfg_if! { } pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4 + +pub const KINFO_FILE_SIZE: ::c_int = 1392; diff --git a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs index c94695ed06cfb..aa33345f3113f 100644 --- a/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/x86_64/mod.rs @@ -91,23 +91,6 @@ s_no_extra_traits! { pub a_type: ::c_long, pub a_un: __c_anonymous_elf64_auxv_union, } - - pub struct kinfo_file { - pub kf_structsize: ::c_int, - pub kf_type: ::c_int, - pub kf_fd: ::c_int, - pub kf_ref_count: ::c_int, - pub kf_flags: ::c_int, - _kf_pad0: ::c_int, - pub kf_offset: i64, - _priv: [::uintptr_t; 38], // FIXME if needed - pub kf_status: u16, - _kf_pad1: u16, - _kf_ispare0: ::c_int, - pub kf_cap_rights: ::cap_rights_t, - _kf_cap_spare: u64, - pub kf_path: [::c_char; ::PATH_MAX as usize], - } } cfg_if! { @@ -232,52 +215,6 @@ cfg_if! { .finish() } } - - impl PartialEq for kinfo_file { - fn eq(&self, other: &kinfo_file) -> bool { - self.kf_structsize == other.kf_structsize && - self.kf_type == other.kf_type && - self.kf_fd == other.kf_fd && - self.kf_ref_count == other.kf_ref_count && - self.kf_flags == other.kf_flags && - self.kf_offset == other.kf_offset && - self.kf_status == other.kf_status && - self.kf_cap_rights == other.kf_cap_rights && - self.kf_path - .iter() - .zip(other.kf_path.iter()) - .all(|(a,b)| a == b) - } - } - impl Eq for kinfo_file {} - impl ::fmt::Debug for kinfo_file { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { - f.debug_struct("kinfo_file") - .field("kf_structsize", &self.kf_structsize) - .field("kf_type", &self.kf_type) - .field("kf_fd", &self.kf_fd) - .field("kf_ref_count", &self.kf_ref_count) - .field("kf_flags", &self.kf_flags) - .field("kf_offset", &self.kf_offset) - .field("kf_status", &self.kf_status) - .field("kf_cap_rights", &self.kf_cap_rights) - .field("kf_path", &&self.kf_path[..]) - .finish() - } - } - impl ::hash::Hash for kinfo_file { - fn hash(&self, state: &mut H) { - self.kf_structsize.hash(state); - self.kf_type.hash(state); - self.kf_fd.hash(state); - self.kf_ref_count.hash(state); - self.kf_flags.hash(state); - self.kf_offset.hash(state); - self.kf_status.hash(state); - self.kf_cap_rights.hash(state); - self.kf_path.hash(state); - } - } } } @@ -297,5 +234,7 @@ pub const _MC_FPOWNED_NONE: c_long = 0x20000; pub const _MC_FPOWNED_FPU: c_long = 0x20001; pub const _MC_FPOWNED_PCB: c_long = 0x20002; +pub const KINFO_FILE_SIZE: ::c_int = 1392; + mod align; pub use self::align::*; From 7f42793075fd1d18f02d1072202d2515b0e3567f Mon Sep 17 00:00:00 2001 From: Lzu Tao Date: Tue, 7 May 2024 00:34:46 +0700 Subject: [PATCH 15/27] Readd posix_spawn{_file_actions_t,attr_t} on Android Fixes: https://github.com/rust-lang/libc/issues/3709 Fixes: https://github.com/rust-lang/libc/issues/3608 Fixes: https://github.com/rust-lang/libc/issues/3677 Co-authored-by: Jorge Aparicio [resolved conflict, update commit message - Trevor] (apply to `main`) (cherry picked from commit b2b2fd71f4cb866c2d3e4579a50a70aa460aab8e) Signed-off-by: Trevor Gross --- libc-test/build.rs | 5 +++++ src/unix/linux_like/android/mod.rs | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index f2c6c3ccddf5a..010f42fbf9904 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1550,6 +1550,7 @@ fn test_android(target: &str) { "sched.h", "semaphore.h", "signal.h", + "spawn.h", "stddef.h", "stdint.h", "stdio.h", @@ -1709,6 +1710,10 @@ fn test_android(target: &str) { // FIXME: Somehow fails to test after removing cfg hacks: "__uint128" => true, + + // These are intended to be opaque + "posix_spawn_file_actions_t" => true, + "posix_spawnattr_t" => true, _ => false, } }); diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index cf8b98d7e62c1..79f06fdf1a33b 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -48,6 +48,10 @@ pub type Elf64_Xword = u64; pub type eventfd_t = u64; +// these structs sit behind a heap allocation on Android +pub type posix_spawn_file_actions_t = *mut ::c_void; +pub type posix_spawnattr_t = *mut ::c_void; + s! { pub struct stack_t { pub ss_sp: *mut ::c_void, From f6cd046d1338492b158d731da41e2f50f5bb9ac0 Mon Sep 17 00:00:00 2001 From: Kai Luo Date: Tue, 2 Apr 2024 04:38:40 -0400 Subject: [PATCH 16/27] Fix hidden lifetime --- src/unix/aix/mod.rs | 8 ++++---- src/unix/aix/powerpc64.rs | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/unix/aix/mod.rs b/src/unix/aix/mod.rs index 1e2dedee9bffb..bcd3f242d802a 100644 --- a/src/unix/aix/mod.rs +++ b/src/unix/aix/mod.rs @@ -574,7 +574,7 @@ cfg_if! { } impl Eq for __sigaction_sa_union {} impl ::fmt::Debug for __sigaction_sa_union { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__sigaction_sa_union") .field("__su_handler", unsafe { &self.__su_handler }) .field("__su_sigaction", unsafe { &self.__su_sigaction }) @@ -600,7 +600,7 @@ cfg_if! { } impl Eq for sigaction {} impl ::fmt::Debug for sigaction { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { let mut struct_formatter = f.debug_struct("sigaction"); struct_formatter.field("sa_union", &self.sa_union); struct_formatter.field("sa_mask", &self.sa_mask); @@ -627,7 +627,7 @@ cfg_if! { } impl Eq for __poll_ctl_ext_u {} impl ::fmt::Debug for __poll_ctl_ext_u { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__poll_ctl_ext_u") .field("addr", unsafe { &self.addr }) .field("data32", unsafe { &self.data32 }) @@ -658,7 +658,7 @@ cfg_if! { } impl Eq for poll_ctl_ext {} impl ::fmt::Debug for poll_ctl_ext { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { let mut struct_formatter = f.debug_struct("poll_ctl_ext"); struct_formatter.field("version", &self.version); struct_formatter.field("command", &self.command); diff --git a/src/unix/aix/powerpc64.rs b/src/unix/aix/powerpc64.rs index deec291b28dca..ff5f77a74a2f6 100644 --- a/src/unix/aix/powerpc64.rs +++ b/src/unix/aix/powerpc64.rs @@ -307,7 +307,7 @@ cfg_if! { } impl Eq for siginfo_t {} impl ::fmt::Debug for siginfo_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { let mut struct_formatter = f.debug_struct("siginfo_t"); struct_formatter.field("si_signo", &self.si_signo); struct_formatter.field("si_errno", &self.si_errno); @@ -347,7 +347,7 @@ cfg_if! { } impl Eq for _kernel_simple_lock {} impl ::fmt::Debug for _kernel_simple_lock { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("_kernel_simple_lock") .field("_slock", unsafe { &self._slock }) .field("_slockp", unsafe { &self._slockp }) @@ -374,7 +374,7 @@ cfg_if! { } impl Eq for fileops_t {} impl ::fmt::Debug for fileops_t { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { let mut struct_formatter = f.debug_struct("fileops_t"); struct_formatter.field("fo_rw", &self.fo_rw); struct_formatter.field("fo_ioctl", &self.fo_ioctl); @@ -415,7 +415,7 @@ cfg_if! { } impl Eq for file {} impl ::fmt::Debug for file { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { let mut struct_formatter = f.debug_struct("file"); struct_formatter.field("f_flag", &self.f_flag); struct_formatter.field("f_count", &self.f_count); @@ -466,7 +466,7 @@ cfg_if! { } impl Eq for __ld_info_file {} impl ::fmt::Debug for __ld_info_file { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__ld_info_file") .field("_ldinfo_fd", unsafe { &self._ldinfo_fd }) .field("_ldinfo_fp", unsafe { &self._ldinfo_fp }) @@ -498,7 +498,7 @@ cfg_if! { } impl Eq for ld_info {} impl ::fmt::Debug for ld_info { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { let mut struct_formatter = f.debug_struct("ld_info"); struct_formatter.field("ldinfo_next", &self.ldinfo_next); struct_formatter.field("ldinfo_flags", &self.ldinfo_flags); @@ -535,7 +535,7 @@ cfg_if! { } impl Eq for __pollfd_ext_u {} impl ::fmt::Debug for __pollfd_ext_u { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { f.debug_struct("__pollfd_ext_u") .field("addr", unsafe { &self.addr }) .field("data32", unsafe { &self.data32 }) @@ -563,7 +563,7 @@ cfg_if! { } impl Eq for pollfd_ext {} impl ::fmt::Debug for pollfd_ext { - fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result { + fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result { let mut struct_formatter = f.debug_struct("pollfd_ext"); struct_formatter.field("fd", &self.fd); struct_formatter.field("events", &self.events); From 4edd2660c451dbef87b7b6b5f2f555bc84553882 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Mon, 5 Aug 2024 18:32:01 -0400 Subject: [PATCH 17/27] Modify QNX NTO platform support Modify QNX NTO `dl_iterate_phdr` to toke `* mut` All other platforms use `* mut`, and while this is technically a breaking change, most likely noone is using it directly. NTO does not define last four fields of the `dl_phdr_info`, so might as well exclude them for cleanliness. v7.0: [link](https://www.qnx.com/developers/docs/7.0.0/index.html#com.qnx.doc.neutrino.lib_ref/topic/d/dl_iterate_phdr.html) v7.1: [link](https://www.qnx.com/developers/docs/7.1/#com.qnx.doc.neutrino.lib_ref/topic/d/dl_iterate_phdr.html) v8.0: [link](https://www.qnx.com/developers/docs/8.0/com.qnx.doc.neutrino.lib_ref/topic/d/dl_iterate_phdr.html?hl=dl_phdr_info) See also https://github.com/rust-lang/backtrace-rs/pull/648 --- src/unix/linux_like/linux/mod.rs | 9 +++++---- src/unix/nto/mod.rs | 5 ++++- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index 5e2042fede677..c719df6fdf815 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -469,13 +469,14 @@ s! { // to false. So I'm just removing these, and if uClibc changes // the #if block in the future to include the following fields, these // will probably need including here. tsidea, skrap - #[cfg(not(target_env = "uclibc"))] + // QNX (NTO) platform does not define these fields + #[cfg(not(any(target_env = "uclibc", target_os = "nto")))] pub dlpi_adds: ::c_ulonglong, - #[cfg(not(target_env = "uclibc"))] + #[cfg(not(any(target_env = "uclibc", target_os = "nto")))] pub dlpi_subs: ::c_ulonglong, - #[cfg(not(target_env = "uclibc"))] + #[cfg(not(any(target_env = "uclibc", target_os = "nto")))] pub dlpi_tls_modid: ::size_t, - #[cfg(not(target_env = "uclibc"))] + #[cfg(not(any(target_env = "uclibc", target_os = "nto")))] pub dlpi_tls_data: *mut ::c_void, } diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index f00d710bbac02..a0ab11b515631 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -3339,7 +3339,10 @@ extern "C" { pub fn dl_iterate_phdr( callback: ::Option< unsafe extern "C" fn( - info: *const dl_phdr_info, + // The original .h file declares this as *const, but for consistency with other platforms, + // changing this to *mut to make it easier to use. + // Maybe in v0.3 all platforms should use this as a *const. + info: *mut dl_phdr_info, size: ::size_t, data: *mut ::c_void, ) -> ::c_int, From 4333c2f1de640379ec5ecbbc79219bef799b5bd0 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Wed, 15 May 2024 11:58:30 +0200 Subject: [PATCH 18/27] Add _NSGetArgv, _NSGetArgc and _NSGetProgname from crt_externs.h Available in the headers on all Apple platforms. --- libc-test/semver/apple.txt | 3 +++ src/unix/bsd/apple/mod.rs | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/libc-test/semver/apple.txt b/libc-test/semver/apple.txt index b4e91dd083463..dfa3ede1eb2de 100644 --- a/libc-test/semver/apple.txt +++ b/libc-test/semver/apple.txt @@ -1599,7 +1599,10 @@ _CS_PATH _IOFBF _IOLBF _IONBF +_NSGetArgc +_NSGetArgv _NSGetEnviron +_NSGetProgname _POSIX_VDISABLE _PTHREAD_COND_SIG_init _PTHREAD_MUTEX_SIG_init diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index ff3326475970d..a44b43fd16610 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -6266,7 +6266,11 @@ extern "C" { pub fn CCRandomGenerateBytes(bytes: *mut ::c_void, size: ::size_t) -> ::CCRNGStatus; pub fn getentropy(buf: *mut ::c_void, buflen: ::size_t) -> ::c_int; + // crt_externs.h + pub fn _NSGetArgv() -> *mut *mut *mut ::c_char; + pub fn _NSGetArgc() -> *mut ::c_int; pub fn _NSGetEnviron() -> *mut *mut *mut ::c_char; + pub fn _NSGetProgname() -> *mut *mut ::c_char; pub fn vm_allocate( target_task: vm_map_t, From bf8cfdfaa5ae937b8a2811fb2d28207ae4c19ed4 Mon Sep 17 00:00:00 2001 From: Trevor Gross Date: Mon, 12 Aug 2024 21:07:22 -0500 Subject: [PATCH 19/27] Add myself to the review rotation --- triagebot.toml | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/triagebot.toml b/triagebot.toml index 1fa350bf74cdd..f11f0ae9c2316 100644 --- a/triagebot.toml +++ b/triagebot.toml @@ -1,6 +1,9 @@ [relabel] allow-unauthenticated = [ - "C-*", "O-*", "S-*", "stable-nominated" + "C-*", + "O-*", + "S-*", + "stable-nominated", ] [autolabel."S-waiting-on-review"] @@ -10,7 +13,10 @@ new_pr = true contributing_url = "https://github.com/rust-lang/libc/blob/HEAD/CONTRIBUTING.md" [assign.owners] -"*" = ["@JohnTitor"] +"*" = [ + "@JohnTitor", + "@tgross35", +] [mentions."src/unix/bsd/netbsdlike/openbsd"] message = "Some changes occurred in OpenBSD module" From 6778a43c8e618d9d4e361b100e3e91f066fdf72a Mon Sep 17 00:00:00 2001 From: tevzi2 Date: Sun, 14 Apr 2024 19:43:25 +0200 Subject: [PATCH 20/27] added missing signal constants for espidf (apply to `main`) (cherry picked from commit 539ec751f337c784ff09ca17f7cf2be953d0ad3e) --- src/unix/newlib/espidf/mod.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/unix/newlib/espidf/mod.rs b/src/unix/newlib/espidf/mod.rs index 409d7ad9bd784..e2e98ee9c394a 100644 --- a/src/unix/newlib/espidf/mod.rs +++ b/src/unix/newlib/espidf/mod.rs @@ -89,6 +89,16 @@ pub const MSG_EOR: ::c_int = 0x08; pub const PTHREAD_STACK_MIN: ::size_t = 768; +pub const SIGABRT: ::size_t = 1; +pub const SIGFPE: ::size_t = 1; +pub const SIGILL: ::size_t = 1; +pub const SIGINT: ::size_t = 1; +pub const SIGSEGV: ::size_t = 1; +pub const SIGTERM: ::size_t = 1; +pub const SIGHUP: ::size_t = 1; +pub const SIGQUIT: ::size_t = 1; +pub const NSIG: ::size_t = 2; + extern "C" { pub fn pthread_create( native: *mut ::pthread_t, From 62bd84a2d85543af422b5f5ab7a760fcf2e287d7 Mon Sep 17 00:00:00 2001 From: Yuri Astrakhan Date: Thu, 18 Jul 2024 12:43:01 -0400 Subject: [PATCH 21/27] Disable `libregex` for QNX 7.0 `libregex` did not exist until QNX 7.1. Before that, the regex functions were part of the libc. (apply to `main`) (cherry picked from commit 0f4d2f702d31a20fff8800d05ff9b549ddf33bf1) --- src/unix/nto/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index f00d710bbac02..96229ce564c21 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -2864,9 +2864,9 @@ safe_f! { // Network related functions are provided by libsocket and regex // functions are provided by libregex. +// Note that in QNX <=7.0, libregex functions were included it in libc itself. #[link(name = "socket")] -#[link(name = "regex")] - +#[cfg_attr(not(target_env = "nto70"), link(name = "regex"))] extern "C" { pub fn sem_destroy(sem: *mut sem_t) -> ::c_int; pub fn sem_init(sem: *mut sem_t, pshared: ::c_int, value: ::c_uint) -> ::c_int; From 78b639cef27b5c4319a5eb89d7426c74b9bd1caf Mon Sep 17 00:00:00 2001 From: Josh Triplett Date: Thu, 18 Jul 2024 10:13:49 -0700 Subject: [PATCH 22/27] Tweak comment (apply to `main`) (cherry picked from commit aea287e5178a87dd2db071f311074fcb9663e518) --- src/unix/nto/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/nto/mod.rs b/src/unix/nto/mod.rs index 96229ce564c21..a13390afe9574 100644 --- a/src/unix/nto/mod.rs +++ b/src/unix/nto/mod.rs @@ -2864,7 +2864,7 @@ safe_f! { // Network related functions are provided by libsocket and regex // functions are provided by libregex. -// Note that in QNX <=7.0, libregex functions were included it in libc itself. +// In QNX <=7.0, libregex functions were included in libc itself. #[link(name = "socket")] #[cfg_attr(not(target_env = "nto70"), link(name = "regex"))] extern "C" { From 00163d2019049a703cfb2b09b3f3fc3a25647af0 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Fri, 19 Jul 2024 09:03:31 +1000 Subject: [PATCH 23/27] Add fcntl OFD commands for macOS Obey shellcheck ci/style.sh should be executable Require macos-14 --- 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 b4e91dd083463..fc01dd675a6e4 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 @@ -1976,6 +1979,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 @@ -1983,12 +1987,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 ff3326475970d..fab7610554d6c 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -3592,6 +3592,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 83b3393ebbb6fe5671181da76fdbc7e5474ce395 Mon Sep 17 00:00:00 2001 From: joboet Date: Thu, 18 Jul 2024 14:21:12 +0200 Subject: [PATCH 24/27] add `pthread_equal` --- libc-test/semver/unix.txt | 1 + src/unix/mod.rs | 1 + 2 files changed, 2 insertions(+) diff --git a/libc-test/semver/unix.txt b/libc-test/semver/unix.txt index 5e84434b46bf4..03248dfec58c7 100644 --- a/libc-test/semver/unix.txt +++ b/libc-test/semver/unix.txt @@ -687,6 +687,7 @@ pthread_condattr_init pthread_condattr_t pthread_create pthread_detach +pthread_equal pthread_exit pthread_getspecific pthread_join diff --git a/src/unix/mod.rs b/src/unix/mod.rs index b67b5a93e3541..487a15dde90c5 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -1030,6 +1030,7 @@ extern "C" { pub fn times(buf: *mut ::tms) -> ::clock_t; pub fn pthread_self() -> ::pthread_t; + pub fn pthread_equal(t1: ::pthread_t, t2: ::pthread_t) -> ::c_int; #[cfg_attr( all(target_os = "macos", target_arch = "x86"), link_name = "pthread_join$UNIX2003" From 4769aaad8ca6e2d005b3354a2c5a724b46639e79 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Sat, 25 May 2024 09:27:41 +0000 Subject: [PATCH 25/27] netbsd adding _lwp_park api. --- libc-test/semver/netbsd.txt | 3 +++ src/unix/bsd/netbsdlike/netbsd/mod.rs | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libc-test/semver/netbsd.txt b/libc-test/semver/netbsd.txt index 353b1e7356ff5..b82d9cbeca065 100644 --- a/libc-test/semver/netbsd.txt +++ b/libc-test/semver/netbsd.txt @@ -1189,6 +1189,9 @@ _cpuset_destroy _cpuset_isset _cpuset_set _cpuset_zero +_lwp_park +_lwp_unpark +_lwp_unpark_all _lwp_self abs accept4 diff --git a/src/unix/bsd/netbsdlike/netbsd/mod.rs b/src/unix/bsd/netbsdlike/netbsd/mod.rs index 47ade8c087fd2..7c58e85c4434c 100644 --- a/src/unix/bsd/netbsdlike/netbsd/mod.rs +++ b/src/unix/bsd/netbsdlike/netbsd/mod.rs @@ -2862,6 +2862,22 @@ extern "C" { pub fn getrandom(buf: *mut ::c_void, buflen: ::size_t, flags: ::c_uint) -> ::ssize_t; pub fn reboot(mode: ::c_int, bootstr: *mut ::c_char) -> ::c_int; + + #[link_name = "___lwp_park60"] + pub fn _lwp_park( + clock: ::clockid_t, + flags: ::c_int, + ts: *const ::timespec, + unpark: ::lwpid_t, + hint: *const ::c_void, + unparkhint: *mut ::c_void, + ) -> ::c_int; + pub fn _lwp_unpark(lwp: ::lwpid_t, hint: *const ::c_void) -> ::c_int; + pub fn _lwp_unpark_all( + targets: *const ::lwpid_t, + ntargets: ::size_t, + hint: *const ::c_void, + ) -> ::c_int; } #[link(name = "rt")] From 7d2eb94259a945f60f88cf0613b9b2ac46bc3170 Mon Sep 17 00:00:00 2001 From: Petr Sumbera Date: Wed, 22 May 2024 17:38:11 +0200 Subject: [PATCH 26/27] Add missing networking support for Solaris --- libc-test/semver/solarish.txt | 13 +++++++++++++ src/unix/mod.rs | 30 ++++++++++++++++++++++++------ src/unix/solarish/mod.rs | 26 ++++++++++++++++++++++---- 3 files changed, 59 insertions(+), 10 deletions(-) diff --git a/libc-test/semver/solarish.txt b/libc-test/semver/solarish.txt index 069508925c8ef..8f51b3ceca6fa 100644 --- a/libc-test/semver/solarish.txt +++ b/libc-test/semver/solarish.txt @@ -1 +1,14 @@ +IPV6_DONTFRAG +IPV6_PKTINFO +IPV6_RECVTCLASS +IPV6_TCLASS +IP_DONTFRAG +IP_PKTINFO +IP_TOS +IP_TTL PIPE_BUF +bind +in6_pktinfo +in_pktinfo +recvmsg +sendmsg diff --git a/src/unix/mod.rs b/src/unix/mod.rs index b67b5a93e3541..bc65d21615a92 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -590,7 +590,10 @@ extern "C" { #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))] #[cfg_attr(target_os = "netbsd", link_name = "__socket30")] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_socket")] + #[cfg_attr( + any(target_os = "illumos", target_os = "solaris"), + link_name = "__xnet_socket" + )] #[cfg_attr(target_os = "espidf", link_name = "lwip_socket")] pub fn socket(domain: ::c_int, ty: ::c_int, protocol: ::c_int) -> ::c_int; #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))] @@ -598,7 +601,10 @@ extern "C" { all(target_os = "macos", target_arch = "x86"), link_name = "connect$UNIX2003" )] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_connect")] + #[cfg_attr( + any(target_os = "illumos", target_os = "solaris"), + link_name = "__xnet_connect" + )] #[cfg_attr(target_os = "espidf", link_name = "lwip_connect")] pub fn connect(socket: ::c_int, address: *const sockaddr, len: socklen_t) -> ::c_int; #[cfg_attr( @@ -648,7 +654,10 @@ extern "C" { all(target_os = "macos", target_arch = "x86"), link_name = "socketpair$UNIX2003" )] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_socketpair")] + #[cfg_attr( + any(target_os = "illumos", target_os = "solaris"), + link_name = "__xnet_socketpair" + )] pub fn socketpair( domain: ::c_int, type_: ::c_int, @@ -660,7 +669,10 @@ extern "C" { all(target_os = "macos", target_arch = "x86"), link_name = "sendto$UNIX2003" )] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_sendto")] + #[cfg_attr( + any(target_os = "illumos", target_os = "solaris"), + link_name = "__xnet_sendto" + )] #[cfg_attr(target_os = "espidf", link_name = "lwip_sendto")] pub fn sendto( socket: ::c_int, @@ -1137,7 +1149,10 @@ extern "C" { pub fn pthread_rwlockattr_init(attr: *mut pthread_rwlockattr_t) -> ::c_int; pub fn pthread_rwlockattr_destroy(attr: *mut pthread_rwlockattr_t) -> ::c_int; - #[cfg_attr(target_os = "illumos", link_name = "__xnet_getsockopt")] + #[cfg_attr( + any(target_os = "illumos", target_os = "solaris"), + link_name = "__xnet_getsockopt" + )] #[cfg_attr(target_os = "espidf", link_name = "lwip_getsockopt")] pub fn getsockopt( sockfd: ::c_int, @@ -1156,7 +1171,10 @@ extern "C" { pub fn dlclose(handle: *mut ::c_void) -> ::c_int; #[cfg(not(all(target_arch = "powerpc", target_vendor = "nintendo")))] - #[cfg_attr(target_os = "illumos", link_name = "__xnet_getaddrinfo")] + #[cfg_attr( + any(target_os = "illumos", target_os = "solaris"), + link_name = "__xnet_getaddrinfo" + )] #[cfg_attr(target_os = "espidf", link_name = "lwip_getaddrinfo")] pub fn getaddrinfo( node: *const c_char, diff --git a/src/unix/solarish/mod.rs b/src/unix/solarish/mod.rs index ab8070dd3f077..27f3bf920c116 100644 --- a/src/unix/solarish/mod.rs +++ b/src/unix/solarish/mod.rs @@ -120,6 +120,17 @@ s! { pub __sin6_src_id: u32 } + pub struct in_pktinfo { + pub ipi_ifindex: ::c_uint, + pub ipi_spec_dst: ::in_addr, + pub ipi_addr: ::in_addr, + } + + pub struct in6_pktinfo { + pub ipi6_addr: ::in6_addr, + pub ipi6_ifindex: ::c_uint, + } + pub struct passwd { pub pw_name: *mut ::c_char, pub pw_passwd: *mut ::c_char, @@ -1224,14 +1235,20 @@ pub const CLD_STOPPED: ::c_int = 5; pub const CLD_CONTINUED: ::c_int = 6; pub const IP_RECVDSTADDR: ::c_int = 0x7; +pub const IP_PKTINFO: ::c_int = 0x1a; +pub const IP_DONTFRAG: ::c_int = 0x1b; pub const IP_SEC_OPT: ::c_int = 0x22; pub const IPV6_UNICAST_HOPS: ::c_int = 0x5; pub const IPV6_MULTICAST_IF: ::c_int = 0x6; pub const IPV6_MULTICAST_HOPS: ::c_int = 0x7; pub const IPV6_MULTICAST_LOOP: ::c_int = 0x8; +pub const IPV6_PKTINFO: ::c_int = 0xb; pub const IPV6_RECVPKTINFO: ::c_int = 0x12; +pub const IPV6_RECVTCLASS: ::c_int = 0x19; +pub const IPV6_DONTFRAG: ::c_int = 0x21; pub const IPV6_SEC_OPT: ::c_int = 0x22; +pub const IPV6_TCLASS: ::c_int = 0x26; pub const IPV6_V6ONLY: ::c_int = 0x27; cfg_if! { @@ -1761,8 +1778,9 @@ pub const SOCK_SEQPACKET: ::c_int = 6; pub const IP_MULTICAST_IF: ::c_int = 16; pub const IP_MULTICAST_TTL: ::c_int = 17; pub const IP_MULTICAST_LOOP: ::c_int = 18; -pub const IP_TTL: ::c_int = 4; pub const IP_HDRINCL: ::c_int = 2; +pub const IP_TOS: ::c_int = 3; +pub const IP_TTL: ::c_int = 4; pub const IP_ADD_MEMBERSHIP: ::c_int = 19; pub const IP_DROP_MEMBERSHIP: ::c_int = 20; pub const IPV6_JOIN_GROUP: ::c_int = 9; @@ -2855,15 +2873,15 @@ extern "C" { ) -> ::c_int; pub fn nl_langinfo(item: ::nl_item) -> *mut ::c_char; - #[cfg_attr(target_os = "illumos", link_name = "__xnet_bind")] + #[link_name = "__xnet_bind"] pub fn bind(socket: ::c_int, address: *const ::sockaddr, address_len: ::socklen_t) -> ::c_int; pub fn writev(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; pub fn readv(fd: ::c_int, iov: *const ::iovec, iovcnt: ::c_int) -> ::ssize_t; - #[cfg_attr(target_os = "illumos", link_name = "__xnet_sendmsg")] + #[link_name = "__xnet_sendmsg"] pub fn sendmsg(fd: ::c_int, msg: *const ::msghdr, flags: ::c_int) -> ::ssize_t; - #[cfg_attr(target_os = "illumos", link_name = "__xnet_recvmsg")] + #[link_name = "__xnet_recvmsg"] pub fn recvmsg(fd: ::c_int, msg: *mut ::msghdr, flags: ::c_int) -> ::ssize_t; pub fn accept4( fd: ::c_int, From ece907b48871ccbfa6cca666f31dff7a888dea54 Mon Sep 17 00:00:00 2001 From: "Simon B. Gasse" Date: Fri, 19 Jul 2024 17:21:08 +0200 Subject: [PATCH 27/27] Add `klogctl` to linux and android For android, we also add the `KLOG_*` constants. For linux, they are defined in source but not exported to user space. --- libc-test/build.rs | 2 ++ libc-test/semver/android.txt | 12 ++++++++++++ libc-test/semver/linux.txt | 1 + src/unix/linux_like/android/mod.rs | 14 ++++++++++++++ src/unix/linux_like/linux/mod.rs | 2 ++ 5 files changed, 31 insertions(+) diff --git a/libc-test/build.rs b/libc-test/build.rs index 3ad203e27bc79..2f45523187a51 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -1563,6 +1563,7 @@ fn test_android(target: &str) { "sys/fsuid.h", "sys/inotify.h", "sys/ioctl.h", + "sys/klog.h", "sys/mman.h", "sys/mount.h", "sys/personality.h", @@ -3351,6 +3352,7 @@ fn test_linux(target: &str) { "sys/eventfd.h", "sys/file.h", "sys/fsuid.h", + "sys/klog.h", "sys/inotify.h", "sys/ioctl.h", "sys/ipc.h", diff --git a/libc-test/semver/android.txt b/libc-test/semver/android.txt index 5375b80d8a186..3f379a70451a2 100644 --- a/libc-test/semver/android.txt +++ b/libc-test/semver/android.txt @@ -1072,6 +1072,17 @@ KEXEC_ON_CRASH KEXEC_PRESERVE_CONTEXT KEY_CNT KEY_MAX +KLOG_CLOSE +KLOG_OPEN +KLOG_READ +KLOG_READ_ALL +KLOG_READ_CLEAR +KLOG_CLEAR +KLOG_CONSOLE_OFF +KLOG_CONSOLE_ON +KLOG_CONSOLE_LEVEL +KLOG_SIZE_UNREAD +KLOG_SIZE_BUFFER LC_ADDRESS LC_ADDRESS_MASK LC_ALL @@ -3361,6 +3372,7 @@ itimerval key_t kill killpg +klogctl lastlog lchown lconv diff --git a/libc-test/semver/linux.txt b/libc-test/semver/linux.txt index 89331caf8d344..c93940b82e485 100644 --- a/libc-test/semver/linux.txt +++ b/libc-test/semver/linux.txt @@ -3663,6 +3663,7 @@ j1939_filter jrand48 key_t killpg +klogctl labs lcong48 lgetxattr diff --git a/src/unix/linux_like/android/mod.rs b/src/unix/linux_like/android/mod.rs index 79f06fdf1a33b..b3780f28405db 100644 --- a/src/unix/linux_like/android/mod.rs +++ b/src/unix/linux_like/android/mod.rs @@ -3508,6 +3508,18 @@ pub const PF_MEMALLOC_PIN: ::c_int = 0x10000000; pub const PF_SUSPEND_TASK: ::c_int = 0x80000000; +pub const KLOG_CLOSE: ::c_int = 0; +pub const KLOG_OPEN: ::c_int = 1; +pub const KLOG_READ: ::c_int = 2; +pub const KLOG_READ_ALL: ::c_int = 3; +pub const KLOG_READ_CLEAR: ::c_int = 4; +pub const KLOG_CLEAR: ::c_int = 5; +pub const KLOG_CONSOLE_OFF: ::c_int = 6; +pub const KLOG_CONSOLE_ON: ::c_int = 7; +pub const KLOG_CONSOLE_LEVEL: ::c_int = 8; +pub const KLOG_SIZE_UNREAD: ::c_int = 9; +pub const KLOG_SIZE_BUFFER: ::c_int = 10; + // Most `*_SUPER_MAGIC` constants are defined at the `linux_like` level; the // following are only available on newer Linux versions than the versions // currently used in CI in some configurations, so we define them here. @@ -4096,6 +4108,8 @@ extern "C" { mask: ::c_uint, statxbuf: *mut statx, ) -> ::c_int; + + pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int; } cfg_if! { diff --git a/src/unix/linux_like/linux/mod.rs b/src/unix/linux_like/linux/mod.rs index c719df6fdf815..ba68965174c09 100644 --- a/src/unix/linux_like/linux/mod.rs +++ b/src/unix/linux_like/linux/mod.rs @@ -6123,6 +6123,8 @@ extern "C" { len: ::size_t, flags: ::c_uint, ) -> ::ssize_t; + + pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int; } // LFS64 extensions