Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[0.2] Backports #4206

Merged
merged 9 commits into from
Dec 18, 2024
Merged
5 changes: 2 additions & 3 deletions ci/style.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@
//! * alignment
//! * leading colons on paths

use std::env;
use std::fs;
use std::io::prelude::*;
use std::path::Path;
use std::{env, fs};

macro_rules! t {
($e:expr) => {
Expand Down Expand Up @@ -130,7 +129,7 @@ fn check_style(file: &str, path: &Path, err: &mut Errors) {
let line = if is_pub { &line[4..] } else { line };

let line_state = if line.starts_with("use ") {
if line.contains("c_void") {
if line.contains("c_void") || line.contains("c_char") {
continue;
}
if is_pub {
Expand Down
35 changes: 34 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,9 @@ fn test_apple(target: &str) {
// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -758,6 +761,8 @@ fn test_windows(target: &str) {
"ssize_t" if !gnu => true,
// FIXME: The size and alignment of this type are incorrect
"time_t" if gnu && i686 => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
});

Expand Down Expand Up @@ -975,6 +980,8 @@ fn test_solarish(target: &str) {

cfg.skip_type(move |ty| match ty {
"sighandler_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
});

Expand Down Expand Up @@ -1278,6 +1285,8 @@ fn test_netbsd(target: &str) {
match ty {
// FIXME: sighandler_t is crazy across platforms
"sighandler_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
}
});
Expand Down Expand Up @@ -1497,7 +1506,8 @@ fn test_dragonflybsd(target: &str) {
match ty {
// sighandler_t is crazy across platforms
"sighandler_t" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
}
});
Expand Down Expand Up @@ -1659,6 +1669,8 @@ fn test_wasi(target: &str) {
}
});

cfg.skip_type(|ty| ty == "c_char_def");

// These have a different and internal type in header files and are only
// used here to generate a pointer to them in bindings so skip these tests.
cfg.skip_static(|c| c.starts_with("_CLOCK_"));
Expand Down Expand Up @@ -1907,6 +1919,9 @@ fn test_android(target: &str) {
// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -2669,6 +2684,9 @@ fn test_freebsd(target: &str) {
// `eventfd(2)` and things come with it are added in FreeBSD 13
"eventfd_t" if Some(13) > freebsd_ver => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -2989,6 +3007,9 @@ fn test_emscripten(target: &str) {
// https://github.com/emscripten-core/emscripten/issues/5033
ty if ty.starts_with("epoll") => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

// LFS64 types have been removed in Emscripten 3.1.44
// https://github.com/emscripten-core/emscripten/pull/19812
t => t.ends_with("64") || t.ends_with("64_t"),
Expand Down Expand Up @@ -3260,6 +3281,9 @@ fn test_neutrino(target: &str) {
// Does not exist in Neutrino
"locale_t" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

_ => false,
}
});
Expand Down Expand Up @@ -3426,6 +3450,8 @@ fn test_vxworks(target: &str) {
// FIXME
cfg.skip_type(move |ty| match ty {
"stat64" | "sighandler_t" | "off64_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
});

Expand Down Expand Up @@ -3773,6 +3799,9 @@ fn test_linux(target: &str) {
// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

// `c_char_def` is always public but not always reexported.
"c_char_def" => true,

t => {
if musl {
// LFS64 types have been removed in musl 1.2.4+
Expand Down Expand Up @@ -4725,6 +4754,8 @@ fn test_linux_like_apis(target: &str) {
})
.skip_type(move |ty| match ty {
"Elf64_Phdr" | "Elf32_Phdr" => false,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => true,
});
cfg.generate(src_hotfix_dir().join("lib.rs"), "linux_elf.rs");
Expand Down Expand Up @@ -4960,6 +4991,8 @@ fn test_haiku(target: &str) {
"pthread_condattr_t" => true,
"pthread_mutexattr_t" => true,
"pthread_rwlockattr_t" => true,
// `c_char_def` is always public but not always reexported.
"c_char_def" => true,
_ => false,
}
});
Expand Down
22 changes: 22 additions & 0 deletions libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1504,6 +1504,17 @@ S_IWRITE
TAB0
TAB3
TABDLY
TCP_BBR_ALGORITHM
TCP_BBR_DRAIN_PG
TCP_BBR_IWINTSO
TCP_BBR_MAX_RTO
TCP_BBR_MIN_RTO
TCP_BBR_PACE_OH
TCP_BBR_PROBE_RTT_INT
TCP_BBR_STARTUP_LOSS_EXIT
TCP_BBR_STARTUP_PG
TCP_BBR_TSLIMITS
TCP_BBR_USEDEL_RATE
TCP_CCALGOOPT
TCP_CONGESTION
TCP_DELACK
Expand All @@ -1530,7 +1541,18 @@ TCP_PCAP_IN
TCP_PCAP_OUT
TCP_PERF_INFO
TCP_PROC_ACCOUNTING
TCP_RACK_EARLY_SEG
TCP_RACK_MBUF_QUEUE
TCP_RACK_MIN_TO
TCP_RACK_PACE_ALWAYS
TCP_RACK_PACE_MAX_SEG
TCP_RACK_PKT_DELAY
TCP_RACK_PRR_SENDALOT
TCP_RACK_REORD_FADE
TCP_RACK_REORD_THRESH
TCP_RACK_TLP_REDUCE
TCP_REMOTE_UDP_ENCAPS_PORT
TCP_REUSPORT_LB_NUMA
TCP_SHARED_CWND_ALLOWED
TCP_USE_CMP_ACKS
THOUSEP
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/fuchsia.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1446,6 +1446,7 @@ sigwait
sigwaitinfo
sockaddr_ll
sockaddr_nl
sockaddr_vm
splice
spwd
srand
Expand Down
8 changes: 8 additions & 0 deletions src/fuchsia/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,14 @@ s! {
pub sin6_scope_id: u32,
}

pub struct sockaddr_vm {
pub svm_family: sa_family_t,
pub svm_reserved1: c_ushort,
pub svm_port: crate::in_port_t,
pub svm_cid: c_uint,
pub svm_zero: [u8; 4],
}

pub struct addrinfo {
pub ai_flags: c_int,
pub ai_family: c_int,
Expand Down
9 changes: 1 addition & 8 deletions src/hermit.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
//! Hermit C type definitions

pub use crate::arch::c_char_def as c_char;
use crate::prelude::*;

cfg_if! {
if #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))] {
pub type c_char = u8;
} else {
pub type c_char = i8;
}
}

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
Expand Down
38 changes: 38 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,44 @@ cfg_if! {

pub use core::ffi::c_void;

/// Type definitions that are coupled tighter to architecture than OS.
mod arch {
cfg_if! {
// This configuration comes from `rust-lang/rust` in `library/core/src/ffi/mod.rs`.
if #[cfg(all(
not(windows),
// FIXME(ctest): just use `target_vendor` = "apple"` once `ctest` supports it
not(any(
target_os = "macos",
target_os = "ios",
target_os = "tvos",
target_os = "watchos",
target_os = "visionos",
)),
any(
target_arch = "aarch64",
target_arch = "arm",
target_arch = "csky",
target_arch = "hexagon",
target_arch = "msp430",
target_arch = "powerpc",
target_arch = "powerpc64",
target_arch = "riscv64",
target_arch = "riscv32",
target_arch = "s390x",
target_arch = "xtensa",
)
))] {
// To be reexported as `c_char`
// FIXME(ctest): just name these `c_char` once `ctest` learns that these don't get
// exported.
pub type c_char_def = u8;
} else {
pub type c_char_def = i8;
}
}
}

cfg_if! {
if #[cfg(windows)] {
mod fixed_width_ints;
Expand Down
2 changes: 1 addition & 1 deletion src/solid/aarch64.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub type c_char = i8;
pub type c_char = u8;
pub type wchar_t = u32;
pub type c_long = i64;
pub type c_ulong = u64;
2 changes: 1 addition & 1 deletion src/solid/arm.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub type c_char = i8;
pub type c_char = u8;
pub type wchar_t = u32;
pub type c_long = i32;
pub type c_ulong = u32;
3 changes: 0 additions & 3 deletions src/teeos/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]

// only supported on Rust > 1.59, so we can directly reexport c_void from core.
pub use core::ffi::c_void;

use crate::prelude::*;

pub type c_schar = i8;
Expand Down
12 changes: 2 additions & 10 deletions src/trusty.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
pub use core::ffi::c_void;

pub use crate::arch::c_char_def as c_char;
use crate::prelude::*;
pub type size_t = usize;
pub type ssize_t = isize;

pub type off_t = i64;

cfg_if! {
if #[cfg(any(target_arch = "aarch64", target_arch = "arm"))] {
pub type c_char = u8;
} else if #[cfg(target_arch = "x86_64")] {
pub type c_char = i8;
}
}

pub type c_schar = i8;
pub type c_uchar = u8;
pub type c_short = i16;
Expand Down
24 changes: 24 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3764,6 +3764,30 @@ pub const TCP_FUNCTION_ALIAS: c_int = 8193;
pub const TCP_FASTOPEN_PSK_LEN: c_int = 16;
pub const TCP_FUNCTION_NAME_LEN_MAX: c_int = 32;

pub const TCP_REUSPORT_LB_NUMA: c_int = 1026;
pub const TCP_RACK_MBUF_QUEUE: c_int = 1050;
pub const TCP_RACK_TLP_REDUCE: c_int = 1052;
pub const TCP_RACK_PACE_MAX_SEG: c_int = 1054;
pub const TCP_RACK_PACE_ALWAYS: c_int = 1055;
pub const TCP_RACK_PRR_SENDALOT: c_int = 1057;
pub const TCP_RACK_MIN_TO: c_int = 1058;
pub const TCP_RACK_EARLY_SEG: c_int = 1060;
pub const TCP_RACK_REORD_THRESH: c_int = 1061;
pub const TCP_RACK_REORD_FADE: c_int = 1062;
pub const TCP_RACK_TLP_THRESH: c_int = 1063;
pub const TCP_RACK_PKT_DELAY: c_int = 1064;
pub const TCP_BBR_IWINTSO: c_int = 1067;
pub const TCP_BBR_STARTUP_PG: c_int = 1069;
pub const TCP_BBR_DRAIN_PG: c_int = 1070;
pub const TCP_BBR_PROBE_RTT_INT: c_int = 1072;
pub const TCP_BBR_STARTUP_LOSS_EXIT: c_int = 1074;
pub const TCP_BBR_TSLIMITS: c_int = 1076;
pub const TCP_BBR_PACE_OH: c_int = 1077;
pub const TCP_BBR_USEDEL_RATE: c_int = 1079;
pub const TCP_BBR_MIN_RTO: c_int = 1080;
pub const TCP_BBR_MAX_RTO: c_int = 1081;
pub const TCP_BBR_ALGORITHM: c_int = 1083;

pub const IP_BINDANY: c_int = 24;
pub const IP_BINDMULTI: c_int = 25;
pub const IP_RSS_LISTEN_BUCKET: c_int = 26;
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/android/b64/riscv64/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::off64_t;
use crate::prelude::*;

pub type c_char = i8;
pub type c_char = u8;
pub type wchar_t = u32;
pub type greg_t = i64;
pub type __u64 = c_ulonglong;
Expand Down
2 changes: 1 addition & 1 deletion src/unix/linux_like/linux/uclibc/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::prelude::*;
pub type blkcnt_t = i64;
pub type blksize_t = i64;
pub type clock_t = i64;
pub type c_char = u8;
pub type c_char = i8;
pub type c_long = i64;
pub type c_ulong = u64;
pub type fsblkcnt_t = c_ulong;
Expand Down
2 changes: 1 addition & 1 deletion src/unix/newlib/espidf/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::prelude::*;

pub type clock_t = c_ulong;
pub type c_char = i8;
pub type c_char = u8;
pub type wchar_t = u32;

pub type c_long = i32;
Expand Down
2 changes: 1 addition & 1 deletion src/unix/newlib/vita/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::prelude::*;

pub type clock_t = c_long;

pub type c_char = i8;
pub type c_char = u8;
pub type wchar_t = u32;

pub type c_long = i32;
Expand Down
2 changes: 1 addition & 1 deletion src/unix/nuttx/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
pub use crate::arch::c_char_def as c_char;
use crate::prelude::*;
use crate::{in6_addr, in_addr_t, timespec, DIR};

pub type nlink_t = u16;
pub type ino_t = u16;
pub type blkcnt_t = u64;
pub type blksize_t = i16;
pub type c_char = i8;
pub type c_long = isize;
pub type c_ulong = usize;
pub type cc_t = u8;
Expand Down
Loading
Loading