Skip to content

Commit f50a3be

Browse files
committed
uclibc support
1 parent d9b69f9 commit f50a3be

File tree

9 files changed

+58
-24
lines changed

9 files changed

+58
-24
lines changed

src/sys/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#[cfg(any(target_os = "dragonfly",
33
target_os = "freebsd",
44
target_os = "ios",
5-
target_os = "linux",
5+
not(all(target_os = "linux", target_env = "uclibc")),
66
target_os = "macos",
77
target_os = "netbsd"))]
88
pub mod aio;

src/sys/personality.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ libc_bitflags! {
1111
ADDR_NO_RANDOMIZE;
1212
ADDR_LIMIT_32BIT;
1313
ADDR_LIMIT_3GB;
14-
#[cfg(not(target_env = "musl"))]
14+
#[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
1515
FDPIC_FUNCPTRS;
1616
MMAP_PAGE_ZERO;
1717
READ_IMPLIES_EXEC;
1818
SHORT_INODE;
1919
STICKY_TIMEOUTS;
20-
#[cfg(not(target_env = "musl"))]
20+
#[cfg(not(any(target_env = "musl", target_env = "uclibc")))]
2121
UNAME26;
2222
WHOLE_SECONDS;
2323
}

src/sys/ptrace/linux.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ use libc::user_regs_struct;
2020

2121
cfg_if! {
2222
if #[cfg(any(all(target_os = "linux", target_arch = "s390x"),
23-
all(target_os = "linux", target_env = "gnu")))] {
23+
all(target_os = "linux", target_env = "gnu"),
24+
target_env = "uclibc"))] {
2425
#[doc(hidden)]
2526
pub type RequestType = ::libc::c_uint;
2627
} else {
@@ -30,8 +31,8 @@ cfg_if! {
3031
}
3132

3233
libc_enum!{
33-
#[cfg_attr(not(any(target_env = "musl", target_os = "android")), repr(u32))]
34-
#[cfg_attr(any(target_env = "musl", target_os = "android"), repr(i32))]
34+
#[cfg_attr(not(any(target_env = "musl", target_env = "uclibc", target_os = "android")), repr(u32))]
35+
#[cfg_attr(any(target_env = "musl", target_env = "uclibc", target_os = "android"), repr(i32))]
3536
/// Ptrace Request enum defining the action to be taken.
3637
#[non_exhaustive]
3738
pub enum Request {

src/sys/resource.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ pub use libc::rlim_t;
77
use std::mem;
88

99
cfg_if! {
10-
if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
10+
if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
1111
use libc::{__rlimit_resource_t, rlimit, RLIM_INFINITY};
12-
}else if #[cfg(any(
12+
} else if #[cfg(any(
1313
target_os = "freebsd",
1414
target_os = "openbsd",
1515
target_os = "netbsd",
@@ -168,9 +168,9 @@ pub fn getrlimit(resource: Resource) -> Result<(Option<rlim_t>, Option<rlim_t>)>
168168
let mut old_rlim = mem::MaybeUninit::<rlimit>::uninit();
169169

170170
cfg_if! {
171-
if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
171+
if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
172172
let res = unsafe { libc::getrlimit(resource as __rlimit_resource_t, old_rlim.as_mut_ptr()) };
173-
}else{
173+
} else {
174174
let res = unsafe { libc::getrlimit(resource as c_int, old_rlim.as_mut_ptr()) };
175175
}
176176
}
@@ -222,7 +222,7 @@ pub fn setrlimit(
222222
rlim_max: hard_limit.unwrap_or(RLIM_INFINITY),
223223
};
224224
cfg_if! {
225-
if #[cfg(all(target_os = "linux", target_env = "gnu"))]{
225+
if #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))]{
226226
let res = unsafe { libc::setrlimit(resource as __rlimit_resource_t, &new_rlim as *const rlimit) };
227227
}else{
228228
let res = unsafe { libc::setrlimit(resource as c_int, &new_rlim as *const rlimit) };

src/sys/signal.rs

+12-4
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::str::FromStr;
1212
#[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
1313
use std::os::unix::io::RawFd;
1414
use std::ptr;
15+
use cfg_if::cfg_if;
1516

1617
#[cfg(not(any(target_os = "openbsd", target_os = "redox")))]
1718
pub use self::sigevent::*;
@@ -403,10 +404,15 @@ pub const SIGPOLL : Signal = SIGIO;
403404
/// Alias for [`SIGSYS`]
404405
pub const SIGUNUSED : Signal = SIGSYS;
405406

406-
#[cfg(not(target_os = "redox"))]
407-
type SaFlags_t = libc::c_int;
408-
#[cfg(target_os = "redox")]
409-
type SaFlags_t = libc::c_ulong;
407+
cfg_if! {
408+
if #[cfg(target_os = "redox")] {
409+
type SaFlags_t = libc::c_ulong;
410+
} else if #[cfg(target_env = "uclibc")] {
411+
type SaFlags_t = libc::c_ulong;
412+
} else {
413+
type SaFlags_t = libc::c_int;
414+
}
415+
}
410416

411417
libc_bitflags!{
412418
/// Controls the behavior of a [`SigAction`]
@@ -1005,6 +1011,8 @@ mod sigevent {
10051011
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
10061012
#[cfg(all(target_os = "linux", target_env = "gnu", not(target_arch = "mips")))]
10071013
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
1014+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
1015+
SigevNotify::SigevThreadId{..} => libc::SIGEV_THREAD_ID,
10081016
#[cfg(any(all(target_os = "linux", target_env = "musl"), target_arch = "mips"))]
10091017
SigevNotify::SigevThreadId{..} => 4 // No SIGEV_THREAD_ID defined
10101018
};

src/sys/socket/addr.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ pub enum AddressFamily {
9797
Wanpipe = libc::AF_WANPIPE,
9898
#[cfg(any(target_os = "android", target_os = "linux"))]
9999
Llc = libc::AF_LLC,
100-
#[cfg(target_os = "linux")]
100+
#[cfg(all(target_os = "linux",not(target_env = "uclibc")))]
101101
Ib = libc::AF_IB,
102-
#[cfg(target_os = "linux")]
102+
#[cfg(all(target_os = "linux",not(target_env = "uclibc")))]
103103
Mpls = libc::AF_MPLS,
104104
#[cfg(any(target_os = "android", target_os = "linux"))]
105105
Can = libc::AF_CAN,

src/sys/statfs.rs

+25-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ type fs_type_t = libc::c_ulong;
2929
type fs_type_t = libc::c_uint;
3030
#[cfg(all(target_os = "linux", target_env = "musl"))]
3131
type fs_type_t = libc::c_ulong;
32-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
32+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
33+
type fs_type_t = libc::c_int;
34+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
3335
type fs_type_t = libc::__fsword_t;
3436

3537
/// Describes the file system type as known by the operating system.
@@ -181,11 +183,17 @@ impl Statfs {
181183
}
182184

183185
/// Optimal transfer block size
184-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
186+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
185187
pub fn optimal_transfer_size(&self) -> libc::__fsword_t {
186188
self.0.f_bsize
187189
}
188190

191+
/// Optimal transfer block size
192+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
193+
pub fn optimal_transfer_size(&self) -> libc::c_int {
194+
self.0.f_bsize
195+
}
196+
189197
/// Optimal transfer block size
190198
#[cfg(target_os = "dragonfly")]
191199
pub fn optimal_transfer_size(&self) -> libc::c_long {
@@ -220,7 +228,14 @@ impl Statfs {
220228

221229
/// Size of a block
222230
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
223-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
231+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
232+
pub fn block_size(&self) -> libc::c_int {
233+
self.0.f_bsize
234+
}
235+
236+
/// Size of a block
237+
// f_bsize on linux: https://github.com/torvalds/linux/blob/master/fs/nfs/super.c#L471
238+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
224239
pub fn block_size(&self) -> libc::__fsword_t {
225240
self.0.f_bsize
226241
}
@@ -262,7 +277,13 @@ impl Statfs {
262277
}
263278

264279
/// Maximum length of filenames
265-
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl"))))]
280+
#[cfg(all(target_os = "linux", target_env = "uclibc"))]
281+
pub fn maximum_name_length(&self) -> libc::c_int {
282+
self.0.f_namelen
283+
}
284+
285+
/// Maximum length of filenames
286+
#[cfg(all(target_os = "linux", not(any(target_arch = "s390x", target_env = "musl", target_env = "uclibc"))))]
266287
pub fn maximum_name_length(&self) -> libc::__fsword_t {
267288
self.0.f_namelen
268289
}

src/sys/termios.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -776,7 +776,7 @@ libc_bitflags! {
776776
ALTWERASE;
777777
IEXTEN;
778778
#[cfg(not(target_os = "redox"))]
779-
EXTPROC;
779+
EXTPROC as tcflag_t; // uclibc gets the type wrong
780780
TOSTOP;
781781
#[cfg(not(target_os = "redox"))]
782782
FLUSHO;

src/sys/uio.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ pub fn readv(fd: RawFd, iov: &mut [IoVec<&mut [u8]>]) -> Result<usize> {
3333
#[cfg(not(target_os = "redox"))]
3434
pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
3535
offset: off_t) -> Result<usize> {
36+
#[cfg(target_env = "uclibc")]
37+
let offset = offset as libc::off64_t; // uclibc doesn't use off_t
3638
let res = unsafe {
3739
libc::pwritev(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
3840
};
@@ -50,6 +52,8 @@ pub fn pwritev(fd: RawFd, iov: &[IoVec<&[u8]>],
5052
#[cfg(not(target_os = "redox"))]
5153
pub fn preadv(fd: RawFd, iov: &[IoVec<&mut [u8]>],
5254
offset: off_t) -> Result<usize> {
55+
#[cfg(target_env = "uclibc")]
56+
let offset = offset as libc::off64_t; // uclibc doesn't use off_t
5357
let res = unsafe {
5458
libc::preadv(fd, iov.as_ptr() as *const libc::iovec, iov.len() as c_int, offset)
5559
};
@@ -121,7 +125,7 @@ pub struct RemoteIoVec {
121125
/// [ptrace]: ../ptrace/index.html
122126
/// [`IoVec`]: struct.IoVec.html
123127
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
124-
#[cfg(target_os = "linux")]
128+
#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
125129
pub fn process_vm_writev(
126130
pid: crate::unistd::Pid,
127131
local_iov: &[IoVec<&[u8]>],
@@ -156,7 +160,7 @@ pub fn process_vm_writev(
156160
/// [`ptrace`]: ../ptrace/index.html
157161
/// [`IoVec`]: struct.IoVec.html
158162
/// [`RemoteIoVec`]: struct.RemoteIoVec.html
159-
#[cfg(any(target_os = "linux"))]
163+
#[cfg(all(target_os = "linux", not(target_env = "uclibc")))]
160164
pub fn process_vm_readv(
161165
pid: crate::unistd::Pid,
162166
local_iov: &[IoVec<&mut [u8]>],

0 commit comments

Comments
 (0)