Skip to content
Open
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
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(unused)]
pub(crate) const fn cstr(bytes: &[u8]) -> *const c_char {
assert!(!bytes.is_empty() && bytes[bytes.len() - 1] == 0);
bytes.as_ptr().cast::<i8>()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c_char, not i8 (on some platforms this is u8)

}
Comment on lines +142 to +148

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dead_code rather than unused. Also add this to the prelude (via macro_rules! prelude in macros.rs) so you don't need to import it everywhere.

4 changes: 4 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//! This covers *-apple-* triples currently

use crate::prelude::*;
use crate::types::cstr;
use crate::{
cmsghdr,
off_t,
Expand Down Expand Up @@ -4111,6 +4112,9 @@ 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
const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\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
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;
use crate::{
cmsghdr,
off_t,
Expand Down Expand Up @@ -1232,6 +1233,11 @@ pub const RTAX_MPLS3: c_int = 10;
/// for details.
pub const RTAX_MAX: c_int = 11;

// include/paths.h
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",
);

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
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;
use crate::{
cmsghdr,
off_t,
Expand Down Expand Up @@ -4318,6 +4319,10 @@ const fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}

// include/paths.h
const _PATH_DEFPATH: *const c_char =
cstr(b"/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin\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/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;

pub type off_t = i64;
pub type useconds_t = u32;
Expand Down Expand Up @@ -480,6 +481,9 @@ cfg_if! {
}
}

// include/paths.h
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");
Comment on lines +484 to +485

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy this to each of the modules so it's next to _PATH_DEFPATH rather than just being in bsd, may as well keep these and future _PATH values together


f! {
pub unsafe fn CMSG_FIRSTHDR(mhdr: *const crate::msghdr) -> *mut cmsghdr {
if (*mhdr).msg_controllen as usize >= 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
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;
use crate::{
cmsghdr,
cpuid_t,
Expand Down Expand Up @@ -1813,6 +1814,9 @@ const fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}

// include/paths.h
const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin:/usr/pkg/bin:/usr/local/bin\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
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;
use crate::unix::bsd::O_SYNC;
use crate::{
cmsghdr,
Expand Down Expand Up @@ -1831,6 +1832,10 @@ const fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
}

// include/paths.h
const _PATH_DEFPATH: *const c_char =
cstr(b"/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11R6/bin:/usr/local/bin:/usr/local/sbin\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
7 changes: 7 additions & 0 deletions src/unix/cygwin/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;
use crate::*;

pub type wchar_t = c_ushort;
Expand Down Expand Up @@ -1678,6 +1679,12 @@ 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
// Only defined in winsup/cygwin/include/paths.h
pub const _PATH_DEFPATH: *const c_char = cstr(b"/bin\0");
// This is defined in both winsup/cygwin/include/paths.h and newlib/libc/include/paths.h
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");
Comment on lines +1682 to +1686

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the newlib/ source in cygwin is actually the path for "newlib libc", i.e. what other platforms would use. So the comments can be dropped, this is expected.


f! {
pub unsafe fn FD_CLR(fd: c_int, set: *mut fd_set) -> () {
let fd = fd as usize;
Expand Down
5 changes: 5 additions & 0 deletions src/unix/haiku/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;

// This module contains bindings to the native Haiku API. The Haiku API
// originates from BeOS, and it was the original way to perform low level
Expand Down Expand Up @@ -1386,6 +1387,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
23 changes: 23 additions & 0 deletions src/unix/linux_like/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;

pub type sa_family_t = u16;
pub type speed_t = c_uint;
Expand Down Expand Up @@ -1497,6 +1498,28 @@ pub const ARPHRD_IEEE802154: u16 = 804;
pub const ARPHRD_VOID: u16 = 0xFFFF;
pub const ARPHRD_NONE: u16 = 0xFFFE;

// include/paths.h
cfg_if! {
if #[cfg(target_os = "android")] {
pub const _PATH_DEFPATH: *const c_char = cstr(b"/product/bin:/apex/com.android.runtime/bin:\
/apex/com.android.art/bin:/apex/com.android.virt/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");
} else {
cfg_if! {
if #[cfg(any(target_env = "musl", target_env = "ohos"))] {
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/local/bin:/bin:/usr/bin\0");
} else if #[cfg(any(target_env = "gnu", target_env = "uclibc"))] {
// pub const _PATH_DEFPATH: *const c_char = c"/usr/bin:/bin".as_ptr();
pub const _PATH_DEFPATH: *const c_char = cstr(b"/usr/bin:/bin\0");
} else {
// Unknown target_env
}
}
pub const _PATH_BSHELL: *const c_char = cstr(b"/bin/sh\0");
}
}
Comment on lines +1502 to +1521

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

emscripten is mentioned but not actually covered here, it doesn't set target_env

But could you actually split this to android/mod.rs, emscripten/mod.rs, l4re/uclibc/mod.rs, and linux/{gnu,musl,uclib}/mod.rs? Makes the config a bit simpler and keeps the consts nested within their libcs.


cfg_if! {
if #[cfg(not(any(target_os = "emscripten", target_os = "l4re")))] {
// linux/if_tun.h
Expand Down
4 changes: 4 additions & 0 deletions src/unix/newlib/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;

pub type blkcnt_t = i32;
pub type blksize_t = i32;
Expand Down Expand Up @@ -842,6 +843,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 on lines +846 to +847

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


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
4 changes: 4 additions & 0 deletions src/unix/redox/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use crate::prelude::*;
use crate::types::cstr;

pub type wchar_t = i32;

Expand Down Expand Up @@ -1102,6 +1103,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