summaryrefslogtreecommitdiff
path: root/src/sys
diff options
context:
space:
mode:
authorJonah Petri <jonah@petri.us>2021-12-07 16:57:52 -0500
committerJonah Petri <jonah@petri.us>2022-01-24 10:06:35 -0500
commit6c4b9133f14d4488dc1b86411568b49e99fbe629 (patch)
treeec06e25f28ac2f989b1af4408d00407b9e548258 /src/sys
parentae2b7b3552f3b800ab0f5e92dad06cd2e7df25e6 (diff)
downloadnix-6c4b9133f14d4488dc1b86411568b49e99fbe629.zip
uclibc support
Diffstat (limited to 'src/sys')
-rw-r--r--src/sys/mod.rs2
-rw-r--r--src/sys/personality.rs4
-rw-r--r--src/sys/ptrace/linux.rs7
-rw-r--r--src/sys/resource.rs10
-rw-r--r--src/sys/signal.rs16
-rw-r--r--src/sys/socket/addr.rs4
-rw-r--r--src/sys/statfs.rs34
-rw-r--r--src/sys/uio.rs8
8 files changed, 61 insertions, 24 deletions
diff --git a/src/sys/mod.rs b/src/sys/mod.rs
index 0bd0bc9f..2fd2a698 100644
--- a/src/sys/mod.rs
+++ b/src/sys/mod.rs
@@ -2,7 +2,7 @@
#[cfg(any(target_os = "dragonfly",
target_os = "freebsd",
target_os = "ios",
- target_os = "linux",
+ all(target_os = "linux", not(target_env = "uclibc")),
target_os = "macos",
target_os = "netbsd"))]
feature! {
diff --git a/src/sys/personality.rs b/src/sys/personality.rs
index b15956c4..e64c906d 100644
--- a/src/sys/personality.rs
+++ b/src/sys/personality.rs
@@ -11,13 +11,13 @@ libc_bitflags! {
ADDR_NO_RANDOMIZE;
ADDR_LIMIT_32BIT;
ADDR_LIMIT_3GB;
- #[cfg(not(target_env = "musl"))]
+ #[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
FDPIC_FUNCPTRS;
MMAP_PAGE_ZERO;
READ_IMPLIES_EXEC;
SHORT_INODE;
STICKY_TIMEOUTS;
- #[cfg(not(target_env = "musl"))]
+ #[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
UNAME26;
WHOLE_SECONDS;
}
diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs
index fb6ff199..24152d7d 100644
--- a/src/sys/ptrace/linux.rs
+++ b/src/sys/ptrace/linux.rs
@@ -20,7 +20,8 @@ use libc::user_regs_struct;
cfg_if! {
if #[cfg(any(all(target_os = "linux", target_arch = "s390x"),
- all(target_os = "linux", target_env = "gnu")))] {
+ all(target_os = "linux", target_env = "gnu"),
+ target_env = "uclibc"))] {
#[doc(hidden)]
pub type RequestType = ::libc::c_uint;
} else {
@@ -30,8 +31,8 @@ cfg_if! {
}
libc_enum!{
- #[cfg_attr(not(any(target_env = "musl", target_os = "android")), repr(u32))]
- #[cfg_attr(any(target_env = "musl", target_os = "android"), repr(i32))]
+ #[cfg_attr(not(any(target_env = "musl", target_env = "uclibc", target_os = "android")), repr(u32))]
+ #[cfg_attr(any(target_env = "musl", target_env = "uclibc", target_os = "android"), repr(i32))]
/// Ptrace Request enum defining the action to be taken.
#[non_exhaustive]
pub enum Request {
diff --git a/src/sys/resource.rs b/src/sys/resource.rs
index 7f2927b4..ba206aa2 100644
--- a/src/sys/resource.rs
+++ b/src/sys/resource.rs
@@ -7,9 +7,9 @@ pub use libc::rlim_t;
use std::mem;
cfg_if! {
- if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
+ if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
use libc::{__rlimit_resource_t, rlimit, RLIM_INFINITY};
- }else if #[cfg(any(
+ } else if #[cfg(any(
target_os = "freebsd",
target_os = "openbsd",
target_os = "netbsd",
@@ -199,9 +199,9 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
let mut old_rlim = mem::MaybeUninit::<rlimit>::uninit();
cfg_if! {
- if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
+ if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
let res = unsafe { libc::getrlimit(resource as __rlimit_resource_t, old_rlim.as_mut_ptr()) };
- }else{
+ } else {
let res = unsafe { libc::getrlimit(resource as c_int, old_rlim.as_mut_ptr()) };
}
}
@@ -253,7 +253,7 @@ pub fn setrlimit(
rlim_max: hard_limit.unwrap_or(RLIM_INFINITY),
};
cfg_if! {
- if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
+ if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
let res = unsafe { libc::setrlimit(resource as __rlimit_resource_t, &new_rlim as *const rlimit) };
}else{
let res = unsafe { libc::setrlimit(resource as c_int, &new_rlim as *const rlimit) };
diff --git a/src/sys/signal.rs b/src/sys/signal.rs
index 9750d890..ddc02483 100644
--- a/src/sys/signal.rs
+++ b/src/sys/signal.rs
@@ -11,6 +11,7 @@ use std::str::FromStr;
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
use std::os::unix::io::RawFd;
use std::ptr;
+use cfg_if::cfg_if;
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
#[cfg(any(feature = "aio", feature = "signal"))]
@@ -420,10 +421,15 @@ pub const SIGPOLL : Signal = SIGIO;
/// Alias for [`SIGSYS`]
pub const SIGUNUSED : Signal = SIGSYS;
-#[cfg(not(target_os = "redox"))]
-type SaFlags_t = libc::c_int;
-#[cfg(target_os = "redox")]
-type SaFlags_t = libc::c_ulong;
+cfg_if! {
+ if #[cfg(target_os = "redox")] {
+ type SaFlags_t = libc::c_ulong;
+ } else if #[cfg(target_env = "uclibc")] {
+ type SaFlags_t = libc::c_ulong;
+ } else {
+ type SaFlags_t = libc::c_int;
+ }
+}
}
#[cfg(feature = "signal")]
@@ -1046,6 +1052,8 @@ mod sigevent {
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
#[cfg(all(target_os = "linux", target_env = "gnu", not(target_arch = "mips")))]
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
+ #[cfg(all(target_os = "linux", target_env = "uclibc"))]
+ SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
#[cfg(any(all(target_os = "linux", target_env = "musl"), target_arch = "mips"))]
SigevNotify::SigevThreadId{..} => 4 // No SIGEV_THREAD_ID defined
};
diff --git a/src/sys/socket/addr.rs b/src/sys/socket/addr.rs
index 4517c548..51999a3d 100644
--- a/src/sys/socket/addr.rs
+++ b/src/sys/socket/addr.rs
@@ -120,10 +120,10 @@ pub enum AddressFamily {
#[cfg(any(target_os = "android", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all())))]
Llc = libc::AF_LLC,
- #[cfg(target_os = "linux")]
+ #[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
Ib = libc::AF_IB,
- #[cfg(target_os = "linux")]
+ #[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
#[cfg_attr(docsrs, doc(cfg(all())))]
Mpls = libc::AF_MPLS,
#[cfg(any(target_os = "android", target_os = "linux"))]
diff --git a/src/sys/statfs.rs b/src/sys/statfs.rs
index e46733e7..838ca3ac 100644
--- a/src/sys/statfs.rs
+++ b/src/sys/statfs.rs
@@ -31,7 +31,9 @@ type fs_type_t = libc::c_ulong;
type fs_type_t = libc::c_uint;
#[cfg(all(target_os = "linux", target_env = "musl"))]
type fs_type_t = libc::c_ulong;
-#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
+#[cfg(all(target_os = "linux", target_env = "uclibc"))]
+type fs_type_t = libc::c_int;
+#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
type fs_type_t = libc::__fsword_t;
/// Describes the file system type as known by the operating system.
@@ -71,7 +73,7 @@ pub const EXT3_SUPER_MAGIC: FsType = FsType(libc::EXT3_SUPER_MAGIC as fs_type_t)
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
#[allow(missing_docs)]
pub const EXT4_SUPER_MAGIC: FsType = FsType(libc::EXT4_SUPER_MAGIC as fs_type_t);
-#[cfg(all(target_os = "linux", not(target_env = "musl")))]
+#[cfg(all(target_os = "linux", not(any(target_env = "musl", target_env = "uclibc"))))]
#[allow(missing_docs)]
pub const FUSE_SUPER_MAGIC: FsType = FsType(libc::FUSE_SUPER_MAGIC as fs_type_t);
#[cfg(all(target_os = "linux", not(target_env = "musl")))]
@@ -192,13 +194,20 @@ impl Statfs {
}
/// Optimal transfer block size
- #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
+ #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> libc::__fsword_t {
self.0.f_bsize
}
/// Optimal transfer block size
+ #[cfg(all(target_os = "linux", target_env = "uclibc"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
+ pub fn optimal_transfer_size(&self) -> libc::c_int {
+ self.0.f_bsize
+ }
+
+ /// Optimal transfer block size
#[cfg(target_os = "dragonfly")]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn optimal_transfer_size(&self) -> libc::c_long {
@@ -237,7 +246,15 @@ impl Statfs {
/// Size of a block
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
- #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
+ #[cfg(all(target_os = "linux", target_env = "uclibc"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
+ pub fn block_size(&self) -> libc::c_int {
+ self.0.f_bsize
+ }
+
+ /// Size of a block
+ // f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
+ #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn block_size(&self) -> libc::__fsword_t {
self.0.f_bsize
@@ -286,7 +303,14 @@ impl Statfs {
}
/// Maximum length of filenames
- #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
+ #[cfg(all(target_os = "linux", target_env = "uclibc"))]
+ #[cfg_attr(docsrs, doc(cfg(all())))]
+ pub fn maximum_name_length(&self) -> libc::c_int {
+ self.0.f_namelen
+ }
+
+ /// Maximum length of filenames
+ #[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn maximum_name_length(&self) -> libc::__fsword_t {
self.0.f_namelen
diff --git a/src/sys/uio.rs b/src/sys/uio.rs
index 125c2e6c..a1fc8e5f 100644
--- a/src/sys/uio.rs
+++ b/src/sys/uio.rs
@@ -34,6 +34,8 @@ pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
offset: off_t) -> Result<usize> {
+ #[cfg(target_env = "uclibc")]
+ let offset = offset as libc::off64_t; // uclibc doesn't use off_t
let res = unsafe {
libc::pwritev(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
};
@@ -52,6 +54,8 @@ pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
#[cfg_attr(docsrs, doc(cfg(all())))]
pub fn preadv(fd: RawFd, iov: &[IoVec<&mut [u8]>],
offset: off_t) -> Result<usize> {
+ #[cfg(target_env = "uclibc")]
+ let offset = offset as libc::off64_t; // uclibc doesn't use off_t
let res = unsafe {
libc::preadv(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
};
@@ -127,7 +131,7 @@ feature! {
/// [ptrace]: ../ptrace/index.html
/// [`IoVec`]: struct.IoVec.html
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
-#[cfg(target_os = "linux")]
+#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
pub fn process_vm_writev(
pid: crate::unistd::Pid,
local_iov: &[IoVec<&[u8]>],
@@ -162,7 +166,7 @@ pub fn process_vm_writev(
/// [`ptrace`]: ../ptrace/index.html
/// [`IoVec`]: struct.IoVec.html
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
-#[cfg(any(target_os = "linux"))]
+#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
pub fn process_vm_readv(
pid: crate::unistd::Pid,
local_iov: &[IoVec<&mut [u8]>],