Skip to content

Commit

Permalink
Sync more files with libc-0.2 to reduce the diff
Browse files Browse the repository at this point in the history
  • Loading branch information
tgross35 committed Nov 18, 2024
1 parent 86b04cb commit 504f88a
Show file tree
Hide file tree
Showing 15 changed files with 121 additions and 66 deletions.
35 changes: 18 additions & 17 deletions src/fixed_width_ints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,28 +59,29 @@ cfg_if! {
/// C __uint128_t (alternate name for [__uint128][])
pub type __uint128_t = u128;

macro_rules! static_assert_eq {
($a:expr, $b:expr) => {
const _: [(); $a] = [(); $b];
};
}

// NOTE: if you add more platforms to here, you may need to cfg
// these consts. They should always match the platform's values
// for `sizeof(__int128)` and `_Alignof(__int128)`.
const _SIZE_128: usize = 16;
const _ALIGN_128: usize = 16;

// Since Rust doesn't officially guarantee that these types
// have compatible ABIs, we const assert that these values have the
// known size/align of the target platform's libc. If rustc ever
// tries to regress things, it will cause a compilation error.
// FIXME(ctest): ctest doesn't handle `_` as an identifier so these tests are temporarily
// disabled.
// macro_rules! static_assert_eq {
// ($a:expr, $b:expr) => {
// const _: [(); $a] = [(); $b];
// };
// }
//
// This isn't a bullet-proof solution because e.g. it doesn't
// catch the fact that llvm and gcc disagree on how x64 __int128
// is actually *passed* on the stack (clang underaligns it for
// the same reason that rustc *never* properly aligns it).
// FIXME: temporarily disabled because of a ctest2 bug.
// // Since Rust doesn't officially guarantee that these types
// // have compatible ABIs, we const assert that these values have the
// // known size/align of the target platform's libc. If rustc ever
// // tries to regress things, it will cause a compilation error.
// //
// // This isn't a bullet-proof solution because e.g. it doesn't
// // catch the fact that llvm and gcc disagree on how x64 __int128
// // is actually *passed* on the stack (clang underaligns it for
// // the same reason that rustc *never* properly aligns it).
// static_assert_eq!(core::mem::size_of::<__int128>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__int128>(), _ALIGN_128);

Expand All @@ -93,9 +94,9 @@ cfg_if! {
// static_assert_eq!(core::mem::size_of::<__uint128_t>(), _SIZE_128);
// static_assert_eq!(core::mem::align_of::<__uint128_t>(), _ALIGN_128);
} else if #[cfg(all(target_arch = "aarch64", any(target_os = "macos", target_os = "ios", target_os = "tvos", target_os = "watchos")))] {
/// /// C `__int128_t`
/// C `__int128_t`
pub type __int128_t = i128;
/// /// C `__uint128_t`
/// C `__uint128_t`
pub type __uint128_t = u128;
}
}
33 changes: 31 additions & 2 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,36 @@ macro_rules! e {
)*);
}

// This is a pretty horrible hack to allow us to conditionally mark
// some functions as 'const', without requiring users of this macro
// to care about the "const-extern-fn" feature.
//
// When 'const-extern-fn' is enabled, we emit the captured 'const' keyword
// in the expanded function.
//
// When 'const-extern-fn' is disabled, we always emit a plain 'pub unsafe extern fn'.
// Note that the expression matched by the macro is exactly the same - this allows
// users of this macro to work whether or not 'const-extern-fn' is enabled
//
// Unfortunately, we need to duplicate most of this macro between the 'cfg_if' blocks.
// This is because 'const unsafe extern fn' won't even parse on older compilers,
// so we need to avoid emitting it at all of 'const-extern-fn'.
//
// Specifically, moving the 'cfg_if' into the macro body will *not* work.
// Doing so would cause the '#[cfg(feature = "const-extern-fn")]' to be emitted
// into user code. The 'cfg' gate will not stop Rust from trying to parse the
// 'pub const unsafe extern fn', so users would get a compiler error even when
// the 'const-extern-fn' feature is disabled
//
// Note that users of this macro need to place 'const' in a weird position
// (after the closing ')' for the arguments, but before the return type).
// This was the only way I could satisfy the following two requirements:
// 1. Avoid ambiguity errors from 'macro_rules!' (which happen when writing '$foo:ident fn'
// 2. Allow users of this macro to mix 'pub fn foo' and 'pub const fn bar' within the same
// 'f!' block

// FIXME(ctest): ctest can't handle `const extern` functions, we should be able to remove this
// cfg completely.
cfg_if! {
if #[cfg(feature = "const-extern-fn")] {
/// Define an `unsafe` function that is const as long as `const-extern-fn` is enabled.
Expand Down Expand Up @@ -243,8 +273,7 @@ cfg_if! {
)*) => ($(
#[inline]
$(#[$attr])*
pub extern fn $i($($arg: $argty),*
) -> $ret {
pub extern fn $i($($arg: $argty),*) -> $ret {
$($body);*
}
)*)
Expand Down
2 changes: 1 addition & 1 deletion src/unix/bsd/apple/b64/aarch64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ s! {
__private: [::uintptr_t; 18], // FIXME: needs arm64 auth pointers support
}

pub struct ucontext_t {
pub struct ucontext_t {
pub uc_onstack: ::c_int,
pub uc_sigmask: ::sigset_t,
pub uc_stack: ::stack_t,
Expand Down
1 change: 1 addition & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,7 @@ s! {
pub ifs6_pfx_expiry_cnt: ::u_quad_t,
pub ifs6_defrtr_expiry_cnt: ::u_quad_t,
}

pub struct icmp6_ifstat {
pub ifs6_in_msg: ::u_quad_t,
pub ifs6_in_error: ::u_quad_t,
Expand Down
2 changes: 2 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ cfg_if! {
}

pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1;

pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;

pub const MAP_32BIT: ::c_int = 0x00080000;
pub const MINSIGSTKSZ: ::size_t = 4096; // 1024 * 4
pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459;
25 changes: 12 additions & 13 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1723,13 +1723,12 @@ cfg_if! {
&& self.cr_uid == other.cr_uid
&& self.cr_ngroups == other.cr_ngroups
&& self.cr_groups == other.cr_groups
&& self.cr_pid__c_anonymous_union
== other.cr_pid__c_anonymous_union
&& self.cr_pid__c_anonymous_union == other.cr_pid__c_anonymous_union
}
}
impl Eq for xucred {}
impl ::fmt::Debug for xucred {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
fn fmt(&self, f: &mut ::fmt::Formatter<'_>) -> ::fmt::Result {
f.debug_struct("xucred")
.field("cr_version", &self.cr_version)
.field("cr_uid", &self.cr_uid)
Expand Down Expand Up @@ -4904,16 +4903,16 @@ pub const TFD_CLOEXEC: ::c_int = O_CLOEXEC;
pub const TFD_TIMER_ABSTIME: ::c_int = 0x01;
pub const TFD_TIMER_CANCEL_ON_SET: ::c_int = 0x02;

// sys/unistd.h

pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;

pub const KCMP_FILE: ::c_int = 100;
pub const KCMP_FILEOBJ: ::c_int = 101;
pub const KCMP_FILES: ::c_int = 102;
pub const KCMP_SIGHAND: ::c_int = 103;
pub const KCMP_VM: ::c_int = 104;

// sys/unistd.h

pub const CLOSE_RANGE_CLOEXEC: ::c_uint = 1 << 2;

pub const fn MAP_ALIGNED(a: ::c_int) -> ::c_int {
a << 24
}
Expand Down Expand Up @@ -5632,19 +5631,19 @@ extern "C" {
pub fn closefrom(lowfd: ::c_int);
pub fn close_range(lowfd: ::c_uint, highfd: ::c_uint, flags: ::c_int) -> ::c_int;

pub fn execvpe(
file: *const ::c_char,
argv: *const *const ::c_char,
envp: *const *const ::c_char,
) -> ::c_int;

pub fn kcmp(
pid1: ::pid_t,
pid2: ::pid_t,
type_: ::c_int,
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")]
Expand Down
1 change: 1 addition & 0 deletions src/unix/bsd/freebsdlike/freebsd/powerpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ cfg_if! {
}

pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_int>() - 1;

pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
pub const MAP_32BIT: ::c_int = 0x00080000;
Expand Down
2 changes: 2 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/powerpc64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ cfg_if! {
}

pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_long>() - 1;

pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;

pub const MAP_32BIT: ::c_int = 0x00080000;
pub const MINSIGSTKSZ: ::size_t = 2048; // 512 * 4
pub const TIOCTIMESTAMP: ::c_ulong = 0x40107459;
4 changes: 2 additions & 2 deletions src/unix/bsd/freebsdlike/freebsd/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ s_no_extra_traits! {
}
}

pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1;

cfg_if! {
if #[cfg(feature = "extra_traits")] {
impl PartialEq for gpregs {
Expand Down Expand Up @@ -142,6 +140,8 @@ cfg_if! {
}
}

pub(crate) const _ALIGNBYTES: usize = ::mem::size_of::<::c_longlong>() - 1;

pub const BIOCSRTIMEOUT: ::c_ulong = 0x8010426d;
pub const BIOCGRTIMEOUT: ::c_ulong = 0x4010426e;
pub const MAP_32BIT: ::c_int = 0x00080000;
Expand Down
5 changes: 2 additions & 3 deletions src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1045,11 +1045,10 @@ cfg_if! {
}
}

impl Eq for statfs { }
impl Eq for statfs {}

impl ::fmt::Debug for statfs {
fn fmt(&self, f: &mut ::fmt::Formatter)
-> ::fmt::Result {
fn fmt(&self, f: &mut ::fmt::Formatter) -> ::fmt::Result {
f.debug_struct("statfs")
.field("f_flags", &self.f_flags)
.field("f_bsize", &self.f_bsize)
Expand Down
1 change: 1 addition & 0 deletions src/unix/haiku/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1328,6 +1328,7 @@ extern "C" {
pathString: *mut ::c_char,
length: i32,
) -> status_t;

pub fn get_cpuid(info: *mut cpuid_info, eaxRegister: u32, cpuNum: u32) -> status_t;
}

Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/android/b32/arm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ s_no_extra_traits! {
pub uc_mcontext: mcontext_t,
pub uc_sigmask__c_anonymous_union: __c_anonymous_uc_sigmask,
/* The kernel adds extra padding after uc_sigmask to match
* glibc sigset_t on ARM. */
* glibc sigset_t on ARM. */
__padding: [c_char; 120],
__align: [::c_longlong; 0],
uc_regspace: [::c_ulong; 128],
Expand Down
4 changes: 2 additions & 2 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4153,6 +4153,8 @@ extern "C" {
pub fn fflush_unlocked(stream: *mut ::FILE) -> ::c_int;
pub fn fgets_unlocked(buf: *mut ::c_char, size: ::c_int, stream: *mut ::FILE) -> *mut ::c_char;

pub fn klogctl(syslog_type: ::c_int, bufp: *mut ::c_char, len: ::c_int) -> ::c_int;

pub fn memfd_create(name: *const ::c_char, flags: ::c_uint) -> ::c_int;
pub fn renameat2(
olddirfd: ::c_int,
Expand All @@ -4168,8 +4170,6 @@ 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! {
Expand Down
Loading

0 comments on commit 504f88a

Please sign in to comment.