Skip to content

Commit 2365131

Browse files
authored
Enable several features enabled by libc 0.2.144. (#668)
- enable `makedev`/`major`/`minor` on solarish and bsd - enable more poll constants on redox - enable `ioctl_ficlone` on mips and power - add new Linux `MADV_` constants - enable `IPPROTO_MPTCP` on android - enable `getpriority`/`setpriority` on redox - add new OpenBSD `CLOCK_` constants
1 parent 43025d8 commit 2365131

File tree

18 files changed

+86
-103
lines changed

18 files changed

+86
-103
lines changed

src/backend/libc/fs/makedev.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use crate::fs::Dev;
44

55
#[cfg(not(any(
66
apple,
7+
solarish,
78
target_os = "aix",
89
target_os = "android",
910
target_os = "emscripten",
@@ -13,6 +14,13 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
1314
c::makedev(maj, min)
1415
}
1516

17+
#[cfg(solarish)]
18+
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
19+
// SAFETY: Solarish's `makedev` is marked unsafe but it isn't doing
20+
// anything unsafe.
21+
unsafe { c::makedev(maj, min) }
22+
}
23+
1624
#[cfg(all(target_os = "android", not(target_pointer_width = "32")))]
1725
#[inline]
1826
pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
@@ -54,19 +62,24 @@ pub(crate) fn makedev(maj: u32, min: u32) -> Dev {
5462
#[cfg(not(any(
5563
apple,
5664
freebsdlike,
57-
netbsdlike,
5865
target_os = "android",
5966
target_os = "emscripten",
67+
target_os = "netbsd"
6068
)))]
6169
#[inline]
6270
pub(crate) fn major(dev: Dev) -> u32 {
6371
unsafe { c::major(dev) }
6472
}
6573

66-
#[cfg(all(target_os = "android", not(target_pointer_width = "32")))]
74+
#[cfg(any(
75+
apple,
76+
freebsdlike,
77+
target_os = "netbsd",
78+
all(target_os = "android", not(target_pointer_width = "32")),
79+
))]
6780
#[inline]
6881
pub(crate) fn major(dev: Dev) -> u32 {
69-
// Android's `major` oddly has signed return types.
82+
// On some platforms `major` oddly has signed return types.
7083
(unsafe { c::major(dev) }) as u32
7184
}
7285

@@ -88,19 +101,24 @@ pub(crate) fn major(dev: Dev) -> u32 {
88101
#[cfg(not(any(
89102
apple,
90103
freebsdlike,
91-
netbsdlike,
92104
target_os = "android",
93105
target_os = "emscripten",
106+
target_os = "netbsd"
94107
)))]
95108
#[inline]
96109
pub(crate) fn minor(dev: Dev) -> u32 {
97110
unsafe { c::minor(dev) }
98111
}
99112

100-
#[cfg(all(target_os = "android", not(target_pointer_width = "32")))]
113+
#[cfg(any(
114+
apple,
115+
freebsdlike,
116+
target_os = "netbsd",
117+
all(target_os = "android", not(target_pointer_width = "32"))
118+
))]
101119
#[inline]
102120
pub(crate) fn minor(dev: Dev) -> u32 {
103-
// Android's `minor` oddly has signed return types.
121+
// On some platforms, `minor` oddly has signed return types.
104122
(unsafe { c::minor(dev) }) as u32
105123
}
106124

src/backend/libc/fs/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
pub(crate) mod dir;
33
#[cfg(any(target_os = "android", target_os = "linux"))]
44
pub mod inotify;
5-
#[cfg(not(any(solarish, target_os = "haiku", target_os = "redox", target_os = "wasi")))]
5+
#[cfg(not(any(target_os = "haiku", target_os = "redox", target_os = "wasi")))]
66
pub(crate) mod makedev;
77
#[cfg(not(windows))]
88
pub(crate) mod syscalls;

src/backend/libc/io/poll_fd.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,14 @@ bitflags! {
2121
/// `POLLOUT`
2222
const OUT = c::POLLOUT;
2323
/// `POLLRDNORM`
24-
#[cfg(not(target_os = "redox"))]
2524
const RDNORM = c::POLLRDNORM;
2625
/// `POLLWRNORM`
27-
#[cfg(not(target_os = "redox"))]
2826
const WRNORM = c::POLLWRNORM;
2927
/// `POLLRDBAND`
30-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
28+
#[cfg(not(target_os = "wasi"))]
3129
const RDBAND = c::POLLRDBAND;
3230
/// `POLLWRBAND`
33-
#[cfg(not(any(target_os = "redox", target_os = "wasi")))]
31+
#[cfg(not(target_os = "wasi"))]
3432
const WRBAND = c::POLLWRBAND;
3533
/// `POLLERR`
3634
const ERR = c::POLLERR;

src/backend/libc/io/syscalls.rs

Lines changed: 5 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -339,38 +339,19 @@ pub(crate) fn ioctl_fionbio(fd: BorrowedFd<'_>, value: bool) -> io::Result<()> {
339339
}
340340
}
341341

342-
#[cfg(any(target_os = "android", target_os = "linux"))]
342+
// Sparc lacks `FICLONE`.
343+
#[cfg(all(
344+
not(any(target_arch = "sparc", target_arch = "sparc64")),
345+
any(target_os = "android", target_os = "linux"),
346+
))]
343347
pub(crate) fn ioctl_ficlone(fd: BorrowedFd<'_>, src_fd: BorrowedFd<'_>) -> io::Result<()> {
344-
// TODO: Enable this on mips and power once libc is updated.
345-
#[cfg(not(any(
346-
target_arch = "mips",
347-
target_arch = "mips64",
348-
target_arch = "powerpc",
349-
target_arch = "powerpc64",
350-
target_arch = "sparc",
351-
target_arch = "sparc64"
352-
)))]
353348
unsafe {
354349
ret(c::ioctl(
355350
borrowed_fd(fd),
356351
c::FICLONE as _,
357352
borrowed_fd(src_fd),
358353
))
359354
}
360-
361-
#[cfg(any(
362-
target_arch = "mips",
363-
target_arch = "mips64",
364-
target_arch = "powerpc",
365-
target_arch = "powerpc64",
366-
target_arch = "sparc",
367-
target_arch = "sparc64"
368-
))]
369-
{
370-
let _ = fd;
371-
let _ = src_fd;
372-
Err(io::Errno::NOSYS)
373-
}
374355
}
375356

376357
#[cfg(any(target_os = "android", target_os = "linux"))]

src/backend/libc/mm/types.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -321,28 +321,25 @@ pub enum Advice {
321321
LinuxDoDump = c::MADV_DODUMP,
322322
/// `MADV_WIPEONFORK` (since Linux 4.14)
323323
#[cfg(any(target_os = "android", target_os = "linux"))]
324-
#[cfg(feature = "mm")]
325-
LinuxWipeOnFork = linux_raw_sys::general::MADV_WIPEONFORK as i32,
324+
LinuxWipeOnFork = libc::MADV_WIPEONFORK as i32,
326325
/// `MADV_KEEPONFORK` (since Linux 4.14)
327326
#[cfg(any(target_os = "android", target_os = "linux"))]
328-
#[cfg(feature = "mm")]
329-
LinuxKeepOnFork = linux_raw_sys::general::MADV_KEEPONFORK as i32,
327+
LinuxKeepOnFork = libc::MADV_KEEPONFORK as i32,
330328
/// `MADV_COLD` (since Linux 5.4)
331329
#[cfg(any(target_os = "android", target_os = "linux"))]
332-
#[cfg(feature = "mm")]
333-
LinuxCold = linux_raw_sys::general::MADV_COLD as i32,
330+
LinuxCold = libc::MADV_COLD as i32,
334331
/// `MADV_PAGEOUT` (since Linux 5.4)
335332
#[cfg(any(target_os = "android", target_os = "linux"))]
336-
#[cfg(feature = "mm")]
337-
LinuxPageOut = linux_raw_sys::general::MADV_PAGEOUT as i32,
333+
LinuxPageOut = libc::MADV_PAGEOUT as i32,
338334
/// `MADV_POPULATE_READ` (since Linux 5.14)
339335
#[cfg(any(target_os = "android", target_os = "linux"))]
340-
#[cfg(feature = "mm")]
341-
LinuxPopulateRead = linux_raw_sys::general::MADV_POPULATE_READ as i32,
336+
LinuxPopulateRead = libc::MADV_POPULATE_READ as i32,
342337
/// `MADV_POPULATE_WRITE` (since Linux 5.14)
343338
#[cfg(any(target_os = "android", target_os = "linux"))]
344-
#[cfg(feature = "mm")]
345-
LinuxPopulateWrite = linux_raw_sys::general::MADV_POPULATE_WRITE as i32,
339+
LinuxPopulateWrite = libc::MADV_POPULATE_WRITE as i32,
340+
/// `MADV_DONTNEED_LOCKED` (since Linux 5.18)
341+
#[cfg(any(target_os = "android", target_os = "linux"))]
342+
LinuxDontneedLocked = libc::MADV_DONTNEED_LOCKED as i32,
346343
}
347344

348345
#[cfg(target_os = "emscripten")]

src/backend/libc/net/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ impl Protocol {
414414
bsd,
415415
solarish,
416416
windows,
417-
target_os = "android",
418417
target_os = "emscripten",
419418
target_os = "fuchsia",
420419
target_os = "haiku",

src/backend/libc/process/syscalls.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ pub(crate) fn nice(inc: i32) -> io::Result<i32> {
259259
}
260260
}
261261

262-
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
262+
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
263263
#[inline]
264264
pub(crate) fn getpriority_user(uid: Uid) -> io::Result<i32> {
265265
libc_errno::set_errno(libc_errno::Errno(0));
@@ -271,7 +271,7 @@ pub(crate) fn getpriority_user(uid: Uid) -> io::Result<i32> {
271271
}
272272
}
273273

274-
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
274+
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
275275
#[inline]
276276
pub(crate) fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> {
277277
libc_errno::set_errno(libc_errno::Errno(0));
@@ -283,7 +283,7 @@ pub(crate) fn getpriority_pgrp(pgid: Option<Pid>) -> io::Result<i32> {
283283
}
284284
}
285285

286-
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
286+
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
287287
#[inline]
288288
pub(crate) fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> {
289289
libc_errno::set_errno(libc_errno::Errno(0));
@@ -295,13 +295,13 @@ pub(crate) fn getpriority_process(pid: Option<Pid>) -> io::Result<i32> {
295295
}
296296
}
297297

298-
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
298+
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
299299
#[inline]
300300
pub(crate) fn setpriority_user(uid: Uid, priority: i32) -> io::Result<()> {
301301
unsafe { ret(c::setpriority(c::PRIO_USER, uid.as_raw() as _, priority)) }
302302
}
303303

304-
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
304+
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
305305
#[inline]
306306
pub(crate) fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<()> {
307307
unsafe {
@@ -313,7 +313,7 @@ pub(crate) fn setpriority_pgrp(pgid: Option<Pid>, priority: i32) -> io::Result<(
313313
}
314314
}
315315

316-
#[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
316+
#[cfg(not(any(target_os = "fuchsia", target_os = "wasi")))]
317317
#[inline]
318318
pub(crate) fn setpriority_process(pid: Option<Pid>, priority: i32) -> io::Result<()> {
319319
unsafe {

src/backend/libc/time/syscalls.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub(crate) fn clock_gettime_dynamic(id: DynamicClockId<'_>) -> io::Result<Timesp
181181
#[cfg(any(target_os = "android", target_os = "linux"))]
182182
DynamicClockId::Tai => c::CLOCK_TAI,
183183

184-
#[cfg(any(target_os = "android", target_os = "linux"))]
184+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "openbsd"))]
185185
DynamicClockId::Boottime => c::CLOCK_BOOTTIME,
186186

187187
#[cfg(any(target_os = "android", target_os = "linux"))]

src/backend/libc/time/types.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ pub enum ClockId {
127127
Monotonic = c::CLOCK_MONOTONIC,
128128

129129
/// `CLOCK_UPTIME`
130-
#[cfg(any(freebsdlike))]
130+
#[cfg(any(freebsdlike, target_os = "openbsd"))]
131131
Uptime = c::CLOCK_UPTIME,
132132

133133
/// `CLOCK_PROCESS_CPUTIME_ID`
134-
#[cfg(not(any(netbsdlike, solarish, target_os = "redox")))]
134+
#[cfg(not(any(solarish, target_os = "netbsd", target_os = "redox")))]
135135
ProcessCPUTime = c::CLOCK_PROCESS_CPUTIME_ID,
136136

137137
/// `CLOCK_THREAD_CPUTIME_ID`
138-
#[cfg(not(any(netbsdlike, solarish, target_os = "redox")))]
138+
#[cfg(not(any(solarish, target_os = "netbsd", target_os = "redox")))]
139139
ThreadCPUTime = c::CLOCK_THREAD_CPUTIME_ID,
140140

141141
/// `CLOCK_REALTIME_COARSE`
@@ -201,7 +201,7 @@ pub enum DynamicClockId<'a> {
201201
Tai,
202202

203203
/// `CLOCK_BOOTTIME`, available on Linux >= 2.6.39
204-
#[cfg(any(target_os = "android", target_os = "linux"))]
204+
#[cfg(any(target_os = "android", target_os = "linux", target_os = "openbsd"))]
205205
Boottime,
206206

207207
/// `CLOCK_BOOTTIME_ALARM`, available on Linux >= 2.6.39

src/backend/libc/winsock_c.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,12 @@ pub(crate) const AF_UNSPEC: i32 = WinSock::AF_UNSPEC as _;
3333
// `WSAECANCELLED` will be removed in the future.
3434
// <https://docs.microsoft.com/en-us/windows/win32/api/ws2spi/nc-ws2spi-lpnsplookupserviceend#remarks>
3535
pub(crate) use WinSock::{
36-
closesocket as close, ioctlsocket as ioctl, socklen_t, WSAPoll as poll,
37-
ADDRESS_FAMILY as sa_family_t, ADDRINFOA as addrinfo, IN6_ADDR as in6_addr, IN_ADDR as in_addr,
38-
IPV6_ADD_MEMBERSHIP, IPV6_DROP_MEMBERSHIP, IPV6_MREQ as ipv6_mreq, IPV6_MULTICAST_LOOP,
39-
IPV6_V6ONLY, IP_ADD_MEMBERSHIP, IP_DROP_MEMBERSHIP, IP_MREQ as ip_mreq, IP_MULTICAST_LOOP,
40-
IP_MULTICAST_TTL, IP_TTL, LINGER as linger, POLLERR, POLLHUP, POLLIN, POLLNVAL, POLLOUT,
41-
POLLPRI, POLLRDBAND, POLLRDNORM, POLLWRBAND, POLLWRNORM, SD_BOTH as SHUT_RDWR,
42-
SD_RECEIVE as SHUT_RD, SD_SEND as SHUT_WR, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in,
43-
SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_STORAGE as sockaddr_storage, SOL_SOCKET, SO_BROADCAST,
44-
SO_ERROR, SO_LINGER, SO_RCVTIMEO, SO_REUSEADDR, SO_SNDTIMEO, SO_TYPE, TCP_NODELAY,
45-
WSAEACCES as EACCES, WSAEADDRINUSE as EADDRINUSE, WSAEADDRNOTAVAIL as EADDRNOTAVAIL,
36+
closesocket as close, ioctlsocket as ioctl, WSAPoll as poll, ADDRESS_FAMILY as sa_family_t,
37+
ADDRINFOA as addrinfo, IN6_ADDR as in6_addr, IN_ADDR as in_addr, IPV6_MREQ as ipv6_mreq,
38+
IP_MREQ as ip_mreq, LINGER as linger, SD_BOTH as SHUT_RDWR, SD_RECEIVE as SHUT_RD,
39+
SD_SEND as SHUT_WR, SOCKADDR as sockaddr, SOCKADDR_IN as sockaddr_in,
40+
SOCKADDR_IN6 as sockaddr_in6, SOCKADDR_STORAGE as sockaddr_storage, WSAEACCES as EACCES,
41+
WSAEADDRINUSE as EADDRINUSE, WSAEADDRNOTAVAIL as EADDRNOTAVAIL,
4642
WSAEAFNOSUPPORT as EAFNOSUPPORT, WSAEALREADY as EALREADY, WSAEBADF as EBADF,
4743
WSAECONNABORTED as ECONNABORTED, WSAECONNREFUSED as ECONNREFUSED, WSAECONNRESET as ECONNRESET,
4844
WSAEDESTADDRREQ as EDESTADDRREQ, WSAEDISCON as EDISCON, WSAEDQUOT as EDQUOT,

0 commit comments

Comments
 (0)