Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions libc-test/build/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ fn test_apple(t: &Target) {
"os/lock.h",
"os/signpost.h",
"os/os_sync_wait_on_address.h",
"paths.h",
"poll.h",
"pthread.h",
"pthread_spis.h",
Expand Down Expand Up @@ -473,6 +474,7 @@ fn test_openbsd(t: &Target) {
"sys/shm.h",
"sys/param.h",
"sys/auxv.h",
"paths.h",
);

cfg.rename_type(|ty| match ty {
Expand Down Expand Up @@ -574,6 +576,7 @@ fn test_cygwin(t: &Target) {
"net/if.h",
"netdb.h",
"netinet/tcp.h",
"paths.h",
"poll.h",
"pthread.h",
"pty.h",
Expand Down Expand Up @@ -875,6 +878,7 @@ fn test_redox(t: &Target) {
"netinet/in.h",
"netinet/ip.h",
"netinet/tcp.h",
"paths.h",
"poll.h",
"pwd.h",
"semaphore.h",
Expand Down Expand Up @@ -1303,6 +1307,7 @@ fn test_netbsd(t: &Target) {
"iconv.h",
"utmp.h",
"utmpx.h",
"paths.h",
);

cfg.rename_type(move |ty| {
Expand Down Expand Up @@ -1546,6 +1551,7 @@ fn test_dragonflybsd(t: &Target) {
"netinet/ip.h",
"netinet/tcp.h",
"netinet/udp.h",
"paths.h",
"poll.h",
"pthread.h",
"pthread_np.h",
Expand Down Expand Up @@ -2077,6 +2083,7 @@ fn test_android(t: &Target) {
// generate the error 'Your time_t is already 64-bit'
(t.p32(), "time64.h"),
(x86, "sys/reg.h"),
"paths.h",
);

// Include linux headers at the end:
Expand Down Expand Up @@ -2560,6 +2567,7 @@ fn test_freebsd(t: &Target) {
"netinet/tcp.h",
"netinet/udp.h",
"netinet6/in6_var.h",
"paths.h",
"poll.h",
"pthread.h",
"pthread_np.h",
Expand Down Expand Up @@ -3247,6 +3255,7 @@ fn test_emscripten(t: &Target) {
"utmp.h",
"utmpx.h",
"wchar.h",
"paths.h",
);

cfg.rename_struct_ty(move |ty| {
Expand Down Expand Up @@ -4106,6 +4115,7 @@ fn test_linux(t: &Target) {
// https://www.openwall.com/lists/musl/2015/04/09/3
// <execinfo.h> is not present on uclibc.
(!(musl || uclibc), "execinfo.h"),
"paths.h",
);

// Include linux headers at the end:
Expand Down Expand Up @@ -5494,6 +5504,7 @@ fn test_haiku(t: &Target) {
"netinet6/in6.h",
"nl_types.h",
"null.h",
"paths.h",
"poll.h",
"pthread.h",
"pwd.h",
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/android.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3175,6 +3175,8 @@ X_OK
_IOFBF
_IOLBF
_IONBF
_PATH_BSHELL
_PATH_DEFPATH
_PC_2_SYMLINKS
_PC_ALLOC_SIZE_MIN
_PC_ASYNC_IO
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/apple.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1627,6 +1627,8 @@ _NSGetArgc
_NSGetArgv
_NSGetEnviron
_NSGetProgname
_PATH_BSHELL
_PATH_DEFPATH
_PC_2_SYMLINKS
_PC_ALLOC_SIZE_MIN
_PC_ASYNC_IO
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/cygwin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,8 @@ WINDOWS_SEND
XTABS
_CS_PATH
_IONBF
_PATH_BSHELL
_PATH_DEFPATH
_PC_2_SYMLINKS
_PC_ALLOC_SIZE_MIN
_PC_ASYNC_IO
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/dragonfly.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,8 @@ _CS_PATH
_IOFBF
_IOLBF
_IONBF
_PATH_BSHELL
_PATH_DEFPATH
_PC_2_SYMLINKS
_PC_ACL_EXTENDED
_PC_ACL_PATH_MAX
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/espidf.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SIGSEGV
SIGTERM
SOL_SOCKET
SOMAXCONN
_PATH_BSHELL
__errno
cmsghdr
dirent
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/freebsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1766,6 +1766,8 @@ _IOR
_IOW
_IOWINT
_IOWR
_PATH_BSHELL
_PATH_DEFPATH
_PC_ACL_EXTENDED
_PC_ACL_NFS4
_PC_ACL_PATH_MAX
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/linux.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3873,6 +3873,8 @@ _IONBF
_IOR
_IOW
_IOWR
_PATH_BSHELL
_PATH_DEFPATH
_PC_2_SYMLINKS
_PC_ALLOC_SIZE_MIN
_PC_ASYNC_IO
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/netbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,8 @@ _IONBF
_IOR
_IOW
_IOWR
_PATH_BSHELL
_PATH_DEFPATH
_PC_2_SYMLINKS
_PC_ACL_EXTENDED
_PC_FILESIZEBITS
Expand Down
2 changes: 2 additions & 0 deletions libc-test/semver/openbsd.txt
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ _IOR
_IOW
_IOWR
_MAX_PAGE_SHIFT
_PATH_BSHELL
_PATH_DEFPATH
_PC_2_SYMLINKS
_PC_ALLOC_SIZE_MIN
_PC_ASYNC_IO
Expand Down
1 change: 1 addition & 0 deletions libc-test/semver/redox.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS
_IOFBF
_IOLBF
_IONBF
_PATH_BSHELL
_PC_2_SYMLINKS
_PC_ALLOC_SIZE_MIN
_PC_ASYNC_IO
Expand Down
1 change: 1 addition & 0 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ macro_rules! prelude {
pub(crate) use crate::types::u32_cast_ioctl;
#[allow(unused_imports)]
pub(crate) use crate::types::{
cstr,
replace_array_items,
u16_cast_short,
u32_cast_int,
Expand Down
8 changes: 8 additions & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,11 @@ pub const fn replace_array_items<T: Copy, const N: usize>(
}
dst
}

/// Constructs a compile time cstring literal from a byte array
// FIXME(msrv): we can opt to use C-string literals directly in 1.77
#[allow(dead_code)]
pub(crate) const fn cstr(bytes: &[u8]) -> *const c_char {
assert!(!bytes.is_empty() && bytes[bytes.len() - 1] == 0);
bytes.as_ptr().cast::<c_char>()
}
Comment thread
asder8215 marked this conversation as resolved.
4 changes: 4 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4111,6 +4111,10 @@ pub const VMADDR_CID_RESERVED: c_uint = 1;
pub const VMADDR_CID_HOST: c_uint = 2;
pub const VMADDR_PORT_ANY: c_uint = 0xFFFFFFFF;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

const fn __DARWIN_ALIGN32(p: usize) -> usize {
const __DARWIN_ALIGNBYTES32: usize = size_of::<u32>() - 1;
(p + __DARWIN_ALIGNBYTES32) & !__DARWIN_ALIGNBYTES32
Expand Down
6 changes: 6 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,12 @@ pub const RTAX_MPLS3: c_int = 10;
/// for details.
pub const RTAX_MAX: c_int = 11;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(
b"/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:/usr/pkg/bin:/usr/pkg/sbin\0",
);
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

const fn _CMSG_ALIGN(n: usize) -> usize {
(n + (size_of::<c_long>() - 1)) & !(size_of::<c_long>() - 1)
}
Expand Down
5 changes: 5 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4318,6 +4318,11 @@ const fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}

// include/paths.h
pub const _PATH_DEFPATH: *const c_char =
cstr(b"/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

f! {
pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).add(_ALIGN(size_of::<cmsghdr>()))
Expand Down
4 changes: 4 additions & 0 deletions src/unix/bsd/netbsdlike/netbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1813,6 +1813,10 @@ const fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

f! {
pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).add(_ALIGN(size_of::<cmsghdr>()))
Expand Down
5 changes: 5 additions & 0 deletions src/unix/bsd/netbsdlike/openbsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,6 +1831,11 @@ const fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}

// include/paths.h
pub const _PATH_DEFPATH: *const c_char =
cstr(b"/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

f! {
pub unsafe fn CMSG_DATA(cmsg: *const cmsghdr) -> *mut c_uchar {
(cmsg as *mut c_uchar).offset(_ALIGN(size_of::<cmsghdr>()) as isize)
Expand Down
4 changes: 4 additions & 0 deletions src/unix/cygwin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1678,6 +1678,10 @@ pub const FALLOC_FL_COLLAPSE_RANGE: c_int = 0x0008;
pub const FALLOC_FL_INSERT_RANGE: c_int = 0x0010;
pub const FALLOC_FL_KEEP_SIZE: c_int = 0x1000;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");
Comment thread
asder8215 marked this conversation as resolved.

f! {
pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
Expand Down
4 changes: 4 additions & 0 deletions src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1386,6 +1386,10 @@ pub const POSIX_SPAWN_SETSIGDEF: c_short = 0x10;
pub const POSIX_SPAWN_SETSIGMASK: c_short = 0x20;
pub const POSIX_SPAWN_SETSID: c_short = 0x40;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

const fn CMSG_ALIGN(len: usize) -> usize {
len + size_of::<usize>() - 1 & !(size_of::<usize>() - 1)
}
Expand Down
8 changes: 8 additions & 0 deletions src/unix/linux_like/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3410,6 +3410,14 @@ pub const RWF_NOAPPEND: c_int = 0x00000020;
pub const RWF_ATOMIC: c_int = 0x00000040;
pub const RWF_DONTCACHE: c_int = 0x00000080;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(
b"/product/bin:/apex/com.android.runtime/bin:\
/apex/com.android.art/bin:/system_ext/bin:/system/bin:\
/system/xbin:/odm/bin:/vendor/bin:/vendor/xbin\0",
);
pub const _PATH_BSHELL: *const c_char = cstr(b"/system/bin/sh\0");

// 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.
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/emscripten/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1279,6 +1279,10 @@ pub const PRIO_USER: c_int = 2;

pub const SOMAXCONN: c_int = 128;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/local/bin:/bin:/usr/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

f! {
pub unsafe fn CMSG_NXTHDR(mhdr: *const msghdr, cmsg: *const cmsghdr) -> *mut cmsghdr {
if ((*cmsg).cmsg_len as usize) < size_of::<cmsghdr>() {
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/l4re/uclibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ pub const PTHREAD_MUTEX_ADAPTIVE_NP: c_int = 3;

pub const __LT_SPINLOCK_INIT: c_int = 0;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

pub const __LOCK_INITIALIZER: _pthread_fastlock = _pthread_fastlock {
__status: 0,
__spinlock: __LT_SPINLOCK_INIT,
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/gnu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,10 @@ pub const GLOB_TILDE_CHECK: c_int = 1 << 14;

pub const MADV_COLLAPSE: c_int = 25;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

cfg_if! {
if #[cfg(any(
target_arch = "arm",
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -790,6 +790,10 @@ pub const UT_HOSTSIZE: usize = 256;
pub const UT_LINESIZE: usize = 32;
pub const UT_NAMESIZE: usize = 32;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/local/bin:/bin:/usr/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

cfg_if! {
if #[cfg(target_arch = "s390x")] {
pub const POSIX_FADV_DONTNEED: c_int = 6;
Expand Down
4 changes: 4 additions & 0 deletions src/unix/linux_like/linux/uclibc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,10 @@ pub const TCP_COOKIE_TRANSACTIONS: c_int = 15;
pub const UDP_GRO: c_int = 104;
pub const UDP_SEGMENT: c_int = 103;

// include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\0");
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

extern "C" {
pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut crate::timezone) -> c_int;

Expand Down
3 changes: 3 additions & 0 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -842,6 +842,9 @@ pub const PRIO_PROCESS: c_int = 0;
pub const PRIO_PGRP: c_int = 1;
pub const PRIO_USER: c_int = 2;

// include/paths.h from newlib's libc
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");
Comment thread
asder8215 marked this conversation as resolved.

f! {
pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
let bits = size_of_val(&(*set).fds_bits[0]) * 8;
Expand Down
3 changes: 3 additions & 0 deletions src/unix/redox/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@ pub const PRIO_USER: c_int = 2;

pub const RENAME_NOREPLACE: c_uint = 1;

// include/paths.h from relibc
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");

f! {
//sys/socket.h
pub const unsafe fn CMSG_ALIGN(len: size_t) -> size_t {
Expand Down
Loading