Skip to content

[0.2] Backports #4396

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

Merged
merged 8 commits into from
Apr 11, 2025
5 changes: 4 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ const CHECK_CFG_EXTRA: &'static [(&'static str, &'static [&'static str])] = &[
"switch", "aix", "ohos", "hurd", "rtems", "visionos", "nuttx", "cygwin",
],
),
("target_env", &["illumos", "wasi", "aix", "ohos"]),
(
"target_env",
&["illumos", "wasi", "aix", "ohos", "nto71_iosock", "nto80"],
),
(
"target_arch",
&["loongarch64", "mips32r6", "mips64r6", "csky"],
Expand Down
25 changes: 25 additions & 0 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,20 @@ fn test_neutrino(target: &str) {
assert!(target.contains("nto-qnx"));

let mut cfg = ctest_cfg();
if target.ends_with("_iosock") {
let qnx_target_val = std::env::var("QNX_TARGET")
.unwrap_or_else(|_| "QNX_TARGET_not_set_please_source_qnxsdp".into());

cfg.include(qnx_target_val + "/usr/include/io-sock");
headers! { cfg:
"io-sock.h",
"sys/types.h",
"sys/socket.h",
"sys/sysctl.h",
"net/if.h",
"net/if_arp.h"
}
}

headers! { cfg:
"ctype.h",
Expand Down Expand Up @@ -3464,6 +3478,9 @@ fn test_neutrino(target: &str) {
// Does not exist in Neutrino
"locale_t" => true,

// FIXME: "'__uint128' undeclared" in C
"__uint128" => true,

_ => false,
}
});
Expand Down Expand Up @@ -3527,6 +3544,9 @@ fn test_neutrino(target: &str) {
// stack unwinding bug.
"__my_thread_exit" => true,

// Wrong const-ness
"dl_iterate_phdr" => true,

_ => false,
}
});
Expand Down Expand Up @@ -4178,6 +4198,9 @@ fn test_linux(target: &str) {
// FIXME(linux): Requires >= 6.12 kernel headers.
"dmabuf_cmsg" | "dmabuf_token" => true,

// FIXME(linux): Requires >= 6.4 kernel headers.
"ptrace_sud_config" => true,

_ => false,
}
});
Expand Down Expand Up @@ -4602,6 +4625,8 @@ fn test_linux(target: &str) {
| "SO_DEVMEM_DONTNEED"
| "SCM_DEVMEM_LINEAR"
| "SCM_DEVMEM_DMABUF" => true,
// FIXME(linux): Requires >= 6.4 kernel headers.
"PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG" | "PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG" => true,

_ => false,
}
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/android.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2446,6 +2446,7 @@ SOL_X25
SOMAXCONN
SO_ACCEPTCONN
SO_BINDTODEVICE
SO_BINDTOIFINDEX
SO_BROADCAST
SO_BSDCOMPAT
SO_BUSY_POLL
Expand Down
4 changes: 4 additions & 0 deletions libc-test/semver/cygwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -734,8 +734,12 @@ posix_fadvise
posix_fallocate
posix_madvise
posix_spawn
posix_spawn_file_actions_addchdir
posix_spawn_file_actions_addchdir_np
posix_spawn_file_actions_addclose
posix_spawn_file_actions_adddup2
posix_spawn_file_actions_addfchdir
posix_spawn_file_actions_addfchdir_np
posix_spawn_file_actions_addopen
posix_spawn_file_actions_destroy
posix_spawn_file_actions_init
Expand Down
3 changes: 3 additions & 0 deletions libc-test/semver/linux-gnu.txt
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,8 @@ PR_SET_VMA
PR_SET_VMA_ANON_NAME
PTHREAD_MUTEX_ADAPTIVE_NP
PTRACE_GET_SYSCALL_INFO
PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG
PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG
PTRACE_SYSCALL_INFO_ENTRY
PTRACE_SYSCALL_INFO_EXIT
PTRACE_SYSCALL_INFO_NONE
Expand Down Expand Up @@ -652,6 +654,7 @@ pthread_rwlockattr_getkind_np
pthread_rwlockattr_getpshared
pthread_rwlockattr_setkind_np
ptrace_peeksiginfo_args
ptrace_sud_config
ptrace_syscall_info
putgrent
putpwent
Expand Down
5 changes: 5 additions & 0 deletions libc-test/semver/linux-musl.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
ACCOUNTING
AF_IB
AF_MPLS
AF_XDP
Expand Down Expand Up @@ -37,6 +38,9 @@ RWF_HIPRI
RWF_NOWAIT
RWF_SYNC
USER_PROCESS
UT_HOSTSIZE
UT_LINESIZE
UT_NAMESIZE
_CS_V6_ENV
_CS_V7_ENV
adjtimex
Expand Down Expand Up @@ -82,3 +86,4 @@ reallocarray
setutxent
tcp_info
timex
utmpxname
3 changes: 1 addition & 2 deletions src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ s! {
// This is normally "struct vnode".
/// Pointer to executable file.
pub ki_textvp: *mut c_void,
// This is normally "struct filedesc".
/// Pointer to open file info.
pub ki_fd: *mut c_void,
pub ki_fd: *mut crate::filedesc,
// This is normally "struct vmspace".
/// Pointer to kernel vmspace struct.
pub ki_vmspace: *mut c_void,
Expand Down
3 changes: 1 addition & 2 deletions src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ s! {
// This is normally "struct vnode".
/// Pointer to executable file.
pub ki_textvp: *mut c_void,
// This is normally "struct filedesc".
/// Pointer to open file info.
pub ki_fd: *mut c_void,
pub ki_fd: *mut crate::filedesc,
// This is normally "struct vmspace".
/// Pointer to kernel vmspace struct.
pub ki_vmspace: *mut c_void,
Expand Down
3 changes: 1 addition & 2 deletions src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ s! {
// This is normally "struct vnode".
/// Pointer to executable file.
pub ki_textvp: *mut c_void,
// This is normally "struct filedesc".
/// Pointer to open file info.
pub ki_fd: *mut c_void,
pub ki_fd: *mut crate::filedesc,
// This is normally "struct vmspace".
/// Pointer to kernel vmspace struct.
pub ki_vmspace: *mut c_void,
Expand Down
3 changes: 1 addition & 2 deletions src/unix/bsd/freebsdlike/freebsd/freebsd14/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ s! {
// This is normally "struct vnode".
/// Pointer to executable file.
pub ki_textvp: *mut c_void,
// This is normally "struct filedesc".
/// Pointer to open file info.
pub ki_fd: *mut c_void,
pub ki_fd: *mut crate::filedesc,
// This is normally "struct vmspace".
/// Pointer to kernel vmspace struct.
pub ki_vmspace: *mut c_void,
Expand Down
3 changes: 1 addition & 2 deletions src/unix/bsd/freebsdlike/freebsd/freebsd15/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ s! {
// This is normally "struct vnode".
/// Pointer to executable file.
pub ki_textvp: *mut c_void,
// This is normally "struct filedesc".
/// Pointer to open file info.
pub ki_fd: *mut c_void,
pub ki_fd: *mut crate::filedesc,
// This is normally "struct vmspace".
/// Pointer to kernel vmspace struct.
pub ki_vmspace: *mut c_void,
Expand Down
41 changes: 41 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1357,6 +1357,47 @@ s! {
pub strchange_instrms: u16,
pub strchange_outstrms: u16,
}

pub struct filedesc {
pub fd_files: *mut fdescenttbl,
pub fd_map: *mut c_ulong,
pub fd_freefile: c_int,
pub fd_refcnt: c_int,
pub fd_holdcnt: c_int,
fd_sx: sx,
fd_kqlist: kqlist,
pub fd_holdleaderscount: c_int,
pub fd_holdleaderswakeup: c_int,
}

pub struct fdescenttbl {
pub fdt_nfiles: c_int,
fdt_ofiles: [*mut c_void; 0],
}

// FIXME: Should be private.
#[doc(hidden)]
pub struct sx {
lock_object: lock_object,
sx_lock: crate::uintptr_t,
}

// FIXME: Should be private.
#[doc(hidden)]
pub struct lock_object {
lo_name: *const c_char,
lo_flags: c_uint,
lo_data: c_uint,
// This is normally `struct witness`.
lo_witness: *mut c_void,
}

// FIXME: Should be private.
#[doc(hidden)]
pub struct kqlist {
tqh_first: *mut c_void,
tqh_last: *mut *mut c_void,
}
}

s_no_extra_traits! {
Expand Down
16 changes: 16 additions & 0 deletions src/unix/cygwin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,22 @@ extern "C" {
fd: c_int,
newfd: c_int,
) -> c_int;
pub fn posix_spawn_file_actions_addchdir(
actions: *mut crate::posix_spawn_file_actions_t,
path: *const c_char,
) -> c_int;
pub fn posix_spawn_file_actions_addfchdir(
actions: *mut crate::posix_spawn_file_actions_t,
fd: c_int,
) -> c_int;
pub fn posix_spawn_file_actions_addchdir_np(
actions: *mut crate::posix_spawn_file_actions_t,
path: *const c_char,
) -> c_int;
pub fn posix_spawn_file_actions_addfchdir_np(
actions: *mut crate::posix_spawn_file_actions_t,
fd: c_int,
) -> c_int;

pub fn forkpty(
amaster: *mut c_int,
Expand Down
1 change: 1 addition & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1555,6 +1555,7 @@ pub const SO_PEEK_OFF: c_int = 42;
pub const SO_BUSY_POLL: c_int = 46;
pub const SCM_TIMESTAMPING_OPT_STATS: c_int = 54;
pub const SCM_TIMESTAMPING_PKTINFO: c_int = 58;
pub const SO_BINDTOIFINDEX: c_int = 62;
pub const SO_TIMESTAMP_NEW: c_int = 63;
pub const SO_TIMESTAMPNS_NEW: c_int = 64;
pub const SO_TIMESTAMPING_NEW: c_int = 65;
Expand Down
9 changes: 9 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ s! {
pub u: __c_anonymous_ptrace_syscall_info_data,
}

pub struct ptrace_sud_config {
pub mode: crate::__u64,
pub selector: crate::__u64,
pub offset: crate::__u64,
pub len: crate::__u64,
}

pub struct iocb {
pub aio_data: crate::__u64,
#[cfg(target_endian = "little")]
Expand Down Expand Up @@ -933,6 +940,8 @@ pub const PTRACE_SYSCALL_INFO_NONE: crate::__u8 = 0;
pub const PTRACE_SYSCALL_INFO_ENTRY: crate::__u8 = 1;
pub const PTRACE_SYSCALL_INFO_EXIT: crate::__u8 = 2;
pub const PTRACE_SYSCALL_INFO_SECCOMP: crate::__u8 = 3;
pub const PTRACE_SET_SYSCALL_USER_DISPATCH_CONFIG: crate::__u8 = 0x4210;
pub const PTRACE_GET_SYSCALL_USER_DISPATCH_CONFIG: crate::__u8 = 0x4211;

// linux/fs.h

Expand Down
35 changes: 34 additions & 1 deletion src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ pub const INIT_PROCESS: c_short = 5;
pub const LOGIN_PROCESS: c_short = 6;
pub const USER_PROCESS: c_short = 7;
pub const DEAD_PROCESS: c_short = 8;
// musl does not define ACCOUNTING
pub const ACCOUNTING: c_short = 9;

pub const SFD_CLOEXEC: c_int = 0x080000;

Expand Down Expand Up @@ -886,6 +886,10 @@ pub const _CS_V7_ENV: c_int = 1149;

pub const CLONE_NEWTIME: c_int = 0x80;

pub const UT_HOSTSIZE: usize = 256;
pub const UT_LINESIZE: usize = 32;
pub const UT_NAMESIZE: usize = 32;

cfg_if! {
if #[cfg(target_arch = "s390x")] {
pub const POSIX_FADV_DONTNEED: c_int = 6;
Expand Down Expand Up @@ -985,12 +989,41 @@ extern "C" {
fd: c_int,
) -> c_int;

#[deprecated(
since = "0.2.172",
note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
)]
pub fn getutxent() -> *mut utmpx;
#[deprecated(
since = "0.2.172",
note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
)]
pub fn getutxid(ut: *const utmpx) -> *mut utmpx;
#[deprecated(
since = "0.2.172",
note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
)]
pub fn getutxline(ut: *const utmpx) -> *mut utmpx;
#[deprecated(
since = "0.2.172",
note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
)]
pub fn pututxline(ut: *const utmpx) -> *mut utmpx;
#[deprecated(
since = "0.2.172",
note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
)]
pub fn setutxent();
#[deprecated(
since = "0.2.172",
note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
)]
pub fn endutxent();
#[deprecated(
since = "0.2.172",
note = "musl provides `utmp` as stubs and an alternative should be preferred; see https://wiki.musl-libc.org/faq.html"
)]
pub fn utmpxname(file: *const c_char) -> c_int;
}

// Alias <foo> to <foo>64 to mimic glibc's LFS64 support
Expand Down
23 changes: 21 additions & 2 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,13 @@ pub const ATF_PERM: c_int = 0x04;
pub const ATF_PUBL: c_int = 0x08;
pub const ATF_USETRAILERS: c_int = 0x10;

pub const FNM_PERIOD: c_int = 1 << 2;
cfg_if! {
if #[cfg(target_os = "nto")] {
pub const FNM_PERIOD: c_int = 1 << 1;
} else {
pub const FNM_PERIOD: c_int = 1 << 2;
}
}
pub const FNM_NOMATCH: c_int = 1;

cfg_if! {
Expand All @@ -354,9 +360,22 @@ cfg_if! {
target_os = "cygwin",
))] {
pub const FNM_PATHNAME: c_int = 1 << 1;
pub const FNM_NOESCAPE: c_int = 1 << 0;
} else {
pub const FNM_PATHNAME: c_int = 1 << 0;
}
}

cfg_if! {
if #[cfg(any(
target_os = "macos",
target_os = "freebsd",
target_os = "android",
target_os = "openbsd",
))] {
pub const FNM_NOESCAPE: c_int = 1 << 0;
} else if #[cfg(target_os = "nto")] {
pub const FNM_NOESCAPE: c_int = 1 << 2;
} else {
pub const FNM_NOESCAPE: c_int = 1 << 1;
}
}
Expand Down
Loading