Skip to content

Commit 26731c2

Browse files
committed
Merge branch 'main' into fix/sendall-deadline-stw-test
Keep the per-thread eval-breaker test. Drop the STOP_BIT retry from RustPython#8788 and the unused stop_bit_set helper. Assisted-by: Grok:4.6
2 parents f1fef34 + cb3d5db commit 26731c2

25 files changed

Lines changed: 586 additions & 177 deletions

File tree

‎crates/host_env/src/errno_wasm.rs‎

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,86 @@
11
//! Errno numbers for `wasm32-unknown-unknown`.
22
//!
3-
//! There is no libc errno table. The values are the Linux ABI the stdlib
4-
//! and `OSError` subclasses match against.
3+
//! There is no libc errno table. The values are the Darwin/BSD numbers the
4+
//! guest `O_*` flags and `OSError` subclasses match against.
5+
6+
#[must_use]
7+
pub fn strerror_string(errno: i32) -> Option<String> {
8+
errors::strerror(errno).map(str::to_owned)
9+
}
510

611
pub mod errors {
7-
pub const EAGAIN: i32 = 11;
8-
pub const ECONNABORTED: i32 = 103;
9-
pub const ECONNRESET: i32 = 104;
12+
pub const EPERM: i32 = 1;
13+
pub const ENOENT: i32 = 2;
14+
pub const ESRCH: i32 = 3;
15+
pub const EINTR: i32 = 4;
16+
pub const EIO: i32 = 5;
17+
pub const EBADF: i32 = 9;
18+
pub const ECHILD: i32 = 10;
19+
pub const EAGAIN: i32 = 35;
20+
pub const EWOULDBLOCK: i32 = 35;
21+
pub const EINPROGRESS: i32 = 36;
22+
pub const EALREADY: i32 = 37;
23+
pub const EPIPE: i32 = 32;
24+
pub const ENOTDIR: i32 = 20;
25+
pub const EISDIR: i32 = 21;
26+
pub const EINVAL: i32 = 22;
27+
pub const EMFILE: i32 = 24;
28+
pub const ESPIPE: i32 = 29;
29+
pub const EROFS: i32 = 30;
30+
pub const EACCES: i32 = 13;
31+
pub const EEXIST: i32 = 17;
32+
pub const ENOTSUP: i32 = 45;
33+
pub const EAFNOSUPPORT: i32 = 47;
34+
pub const ECONNABORTED: i32 = 53;
35+
pub const ECONNRESET: i32 = 54;
36+
pub const ESHUTDOWN: i32 = 58;
37+
pub const ETIMEDOUT: i32 = 60;
38+
pub const ECONNREFUSED: i32 = 61;
39+
40+
pub fn strerror(errno: i32) -> Option<&'static str> {
41+
Some(match errno {
42+
EPERM => "Operation not permitted",
43+
ENOENT => "No such file or directory",
44+
ESRCH => "No such process",
45+
EIO => "Input/output error",
46+
EINTR => "Interrupted system call",
47+
ECHILD => "No child processes",
48+
EACCES => "Permission denied",
49+
EEXIST => "File exists",
50+
ENOTDIR => "Not a directory",
51+
EISDIR => "Is a directory",
52+
EPIPE => "Broken pipe",
53+
EAGAIN => "Resource temporarily unavailable",
54+
EINPROGRESS => "Operation now in progress",
55+
EALREADY => "Operation already in progress",
56+
ENOTSUP => "Operation not supported",
57+
EAFNOSUPPORT => "Address family not supported by protocol",
58+
ECONNABORTED => "Software caused connection abort",
59+
ECONNRESET => "Connection reset by peer",
60+
ETIMEDOUT => "Operation timed out",
61+
ECONNREFUSED => "Connection refused",
62+
EBADF => "Bad file descriptor",
63+
EINVAL => "Invalid argument",
64+
EMFILE => "Too many open files",
65+
ESPIPE => "Illegal seek",
66+
EROFS => "Read-only file system",
67+
ESHUTDOWN => "Can't send after socket shutdown",
68+
_ => return None,
69+
})
70+
}
71+
}
72+
73+
#[cfg(test)]
74+
mod tests {
75+
use super::errors;
76+
77+
#[test]
78+
fn eagain_is_darwin() {
79+
assert_eq!(errors::EAGAIN, 35);
80+
assert_eq!(errors::EWOULDBLOCK, 35);
81+
assert_eq!(
82+
errors::strerror(errors::EAGAIN),
83+
Some("Resource temporarily unavailable")
84+
);
85+
}
1086
}

‎crates/host_env/src/fcntl.rs‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ use crate::os::CheckLibcResult;
77

88
pub use libc::{F_GETFD, F_GETFL, F_SETFD, F_SETFL, FD_CLOEXEC};
99

10+
#[cfg(any(
11+
target_os = "android",
12+
target_os = "dragonfly",
13+
target_os = "freebsd",
14+
target_os = "linux",
15+
target_os = "macos",
16+
target_os = "netbsd",
17+
target_os = "redox"
18+
))]
19+
pub use libc::{F_LOCK, F_TEST, F_TLOCK, F_ULOCK};
20+
1021
#[cfg(not(target_os = "wasi"))]
1122
pub use libc::{F_DUPFD, F_DUPFD_CLOEXEC, F_GETLK, F_SETLK, F_SETLKW};
1223

‎crates/host_env/src/fileutils.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ pub fn fopen(path: &std::path::Path, mode: &str) -> std::io::Result<*mut CFile>
466466

467467
// Convert File handle to CRT file descriptor
468468
let handle = file.into_raw_handle();
469-
let fd = unsafe { libc::open_osfhandle(handle as isize, libc::O_RDONLY) };
469+
let fd = unsafe { libc::open_osfhandle(handle as isize, crate::os::O_RDONLY) };
470470
if fd == -1 {
471471
return Err(std::io::Error::last_os_error());
472472
}

‎crates/host_env/src/io.rs‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn parse_fileio_mode(mode_str: &str) -> Result<ParsedFileMode, FileModeError
8282
}
8383
rwa = true;
8484
mode.insert(FileMode::WRITABLE | FileMode::CREATED);
85-
flags |= libc::O_EXCL | libc::O_CREAT;
85+
flags |= os::O_EXCL | os::O_CREAT;
8686
}
8787
b'r' => {
8888
if rwa {
@@ -97,15 +97,15 @@ pub fn parse_fileio_mode(mode_str: &str) -> Result<ParsedFileMode, FileModeError
9797
}
9898
rwa = true;
9999
mode.insert(FileMode::WRITABLE);
100-
flags |= libc::O_CREAT | libc::O_TRUNC;
100+
flags |= os::O_CREAT | os::O_TRUNC;
101101
}
102102
b'a' => {
103103
if rwa {
104104
return Err(FileModeError::BadRwa);
105105
}
106106
rwa = true;
107107
mode.insert(FileMode::WRITABLE | FileMode::APPENDING);
108-
flags |= libc::O_APPEND | libc::O_CREAT;
108+
flags |= os::O_APPEND | os::O_CREAT;
109109
}
110110
b'+' => {
111111
if plus {
@@ -124,20 +124,20 @@ pub fn parse_fileio_mode(mode_str: &str) -> Result<ParsedFileMode, FileModeError
124124
}
125125

126126
if mode.contains(FileMode::READABLE | FileMode::WRITABLE) {
127-
flags |= libc::O_RDWR;
127+
flags |= os::O_RDWR;
128128
} else if mode.contains(FileMode::READABLE) {
129-
flags |= libc::O_RDONLY;
129+
flags |= os::O_RDONLY;
130130
} else {
131-
flags |= libc::O_WRONLY;
131+
flags |= os::O_WRONLY;
132132
}
133133

134134
#[cfg(windows)]
135135
{
136-
flags |= libc::O_BINARY | libc::O_NOINHERIT;
136+
flags |= os::O_BINARY | os::O_NOINHERIT;
137137
}
138138
#[cfg(unix)]
139139
{
140-
flags |= libc::O_CLOEXEC;
140+
flags |= os::O_CLOEXEC;
141141
}
142142

143143
Ok(ParsedFileMode { mode, flags })

‎crates/host_env/src/io_unsupported.rs‎

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,8 @@ use core::ffi::CStr;
22
use std::io;
33

44
use crate::crt_fd;
5-
6-
const EBADF: i32 = 9;
7-
const EAGAIN: i32 = 11;
8-
const EINTR: i32 = 4;
9-
const EISDIR: i32 = 21;
10-
11-
const O_RDONLY: i32 = 0;
12-
const O_WRONLY: i32 = 1;
13-
const O_RDWR: i32 = 2;
14-
const O_APPEND: i32 = 0x0008;
15-
const O_CREAT: i32 = 0x0200;
16-
const O_TRUNC: i32 = 0x0400;
17-
const O_EXCL: i32 = 0x0800;
5+
use crate::errno::errors::{EAGAIN, EBADF, EINTR, EISDIR};
6+
use crate::os::{O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
187

198
bitflags::bitflags! {
209
#[derive(Copy, Clone, Debug, PartialEq, Eq)]

‎crates/host_env/src/msvcrt.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ unsafe extern "C" {
4646
}
4747

4848
pub fn setmode_binary(fd: crt_fd::Borrowed<'_>) {
49-
unsafe { suppress_iph!(_setmode(fd, libc::O_BINARY)) };
49+
unsafe { suppress_iph!(_setmode(fd, crate::os::O_BINARY)) };
5050
}
5151

5252
#[must_use]

‎crates/host_env/src/multiprocessing.rs‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,14 @@ impl SemHandle {
136136
unlink: bool,
137137
) -> Result<(Self, Option<String>), SemError> {
138138
let cname = semaphore_name(name)?;
139-
let raw =
140-
unsafe { libc::sem_open(cname.as_ptr(), libc::O_CREAT | libc::O_EXCL, 0o600, value) };
139+
let raw = unsafe {
140+
libc::sem_open(
141+
cname.as_ptr(),
142+
crate::os::O_CREAT | crate::os::O_EXCL,
143+
0o600,
144+
value,
145+
)
146+
};
141147
if raw == libc::SEM_FAILED {
142148
return Err(SemError::from_errno(Errno::last()));
143149
}

‎crates/host_env/src/nt.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,7 +1369,7 @@ pub fn pipe() -> io::Result<(i32, i32)> {
13691369

13701370
let write_fd = match crate::msvcrt::open_osfhandle(
13711371
write_handle.as_raw_handle() as isize,
1372-
libc::O_WRONLY | O_NOINHERIT,
1372+
crate::os::O_WRONLY | O_NOINHERIT,
13731373
) {
13741374
Ok(fd) => {
13751375
let _ = write_handle.into_raw_handle();
@@ -2370,9 +2370,9 @@ pub fn open_console_path_fd(path: &widestring::WideCStr, writable: bool) -> io::
23702370
}
23712371

23722372
let osf_flags = if writable {
2373-
libc::O_WRONLY | libc::O_BINARY | 0x80
2373+
crate::os::O_WRONLY | crate::os::O_BINARY | 0x80
23742374
} else {
2375-
libc::O_RDONLY | libc::O_BINARY | 0x80
2375+
crate::os::O_RDONLY | crate::os::O_BINARY | 0x80
23762376
};
23772377
match crate::msvcrt::open_osfhandle(handle as isize, osf_flags) {
23782378
Ok(fd) => Ok(fd),

‎crates/host_env/src/os.rs‎

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,124 @@ pub use libc::AT_FDCWD;
4040
#[cfg(not(any(unix, target_os = "wasi")))]
4141
pub const AT_FDCWD: i32 = -100;
4242

43+
#[cfg(unix)]
44+
pub use libc::{AT_REMOVEDIR, AT_SYMLINK_FOLLOW, AT_SYMLINK_NOFOLLOW};
45+
46+
#[cfg(any(
47+
target_os = "freebsd",
48+
target_os = "linux",
49+
target_os = "netbsd",
50+
target_vendor = "apple"
51+
))]
52+
pub use libc::AT_EACCESS;
53+
54+
/// bionic does not export `AT_EACCESS`; the value is the Linux `fcntl.h` one.
55+
#[cfg(target_os = "android")]
56+
pub const AT_EACCESS: i32 = 0x200;
57+
58+
#[cfg(all(unix, not(target_os = "redox")))]
59+
pub use libc::{ST_NOSUID, ST_RDONLY};
60+
61+
/// `open(2)` flags. libc on hosts that bind them; Darwin/BSD numbers on
62+
/// `wasm32-unknown-unknown`, matching the guest errno table.
63+
#[cfg(any(unix, windows, target_os = "wasi"))]
64+
pub use libc::{O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_RDWR, O_TRUNC, O_WRONLY};
65+
66+
#[cfg(unix)]
67+
pub use libc::{O_ACCMODE, O_CLOEXEC, O_DIRECTORY, O_NOFOLLOW, O_NONBLOCK};
68+
69+
#[cfg(any(
70+
target_os = "android",
71+
target_os = "dragonfly",
72+
target_os = "freebsd",
73+
target_os = "linux",
74+
target_os = "macos",
75+
target_os = "netbsd",
76+
target_os = "redox"
77+
))]
78+
pub use libc::{O_ASYNC, O_NDELAY, O_NOCTTY};
79+
80+
#[cfg(any(
81+
target_os = "android",
82+
target_os = "freebsd",
83+
target_os = "linux",
84+
target_os = "macos",
85+
target_os = "netbsd"
86+
))]
87+
pub use libc::O_DSYNC;
88+
89+
#[cfg(any(
90+
target_os = "android",
91+
target_os = "dragonfly",
92+
target_os = "freebsd",
93+
target_os = "linux",
94+
target_os = "macos",
95+
target_os = "netbsd"
96+
))]
97+
pub use libc::O_SYNC;
98+
99+
#[cfg(any(
100+
target_os = "dragonfly",
101+
target_os = "freebsd",
102+
target_os = "macos",
103+
target_os = "netbsd",
104+
target_os = "redox"
105+
))]
106+
pub use libc::O_FSYNC;
107+
108+
#[cfg(any(target_os = "linux", target_os = "android"))]
109+
pub use libc::{O_DIRECT, O_LARGEFILE, O_NOATIME, O_PATH, O_RSYNC, O_TMPFILE};
110+
111+
#[cfg(target_os = "freebsd")]
112+
pub use libc::{O_DIRECT, O_PATH};
113+
114+
#[cfg(target_os = "redox")]
115+
pub use libc::O_PATH;
116+
117+
#[cfg(target_os = "netbsd")]
118+
pub use libc::{O_DIRECT, O_RSYNC};
119+
120+
#[cfg(target_os = "dragonfly")]
121+
pub use libc::O_DIRECT;
122+
123+
#[cfg(any(target_os = "macos", target_os = "ios"))]
124+
pub use libc::{O_EVTONLY, O_EXEC, O_EXLOCK, O_NOFOLLOW_ANY, O_SEARCH, O_SHLOCK, O_SYMLINK};
125+
126+
#[cfg(any(
127+
target_os = "dragonfly",
128+
target_os = "freebsd",
129+
target_os = "netbsd",
130+
target_os = "redox"
131+
))]
132+
pub use libc::{O_EXLOCK, O_SHLOCK};
133+
134+
#[cfg(target_os = "redox")]
135+
pub use libc::O_SYMLINK;
136+
137+
#[cfg(windows)]
138+
pub use libc::{O_BINARY, O_NOINHERIT, O_RANDOM, O_SEQUENTIAL, O_TEMPORARY, O_TEXT};
139+
140+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
141+
mod wasm_oflag {
142+
pub const O_RDONLY: i32 = 0x0000;
143+
pub const O_WRONLY: i32 = 0x0001;
144+
pub const O_RDWR: i32 = 0x0002;
145+
pub const O_ACCMODE: i32 = 0x0003;
146+
pub const O_NONBLOCK: i32 = 0x0004;
147+
pub const O_APPEND: i32 = 0x0008;
148+
pub const O_SYNC: i32 = 0x0080;
149+
pub const O_NOFOLLOW: i32 = 0x0100;
150+
pub const O_CREAT: i32 = 0x0200;
151+
pub const O_TRUNC: i32 = 0x0400;
152+
pub const O_EXCL: i32 = 0x0800;
153+
pub const O_DIRECTORY: i32 = 0x0010_0000;
154+
pub const O_CLOEXEC: i32 = 0x0100_0000;
155+
pub const O_NDELAY: i32 = O_NONBLOCK;
156+
}
157+
158+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
159+
pub use wasm_oflag::*;
160+
43161
/// BSD `chflags` bits the `libc` crate does not bind. Published by `_stat`
44162
/// on every platform.
45163
pub const UF_SETTABLE: u32 = 0x0000ffff;
@@ -837,3 +955,16 @@ pub fn winerror_to_errno(winerror: i32) -> i32 {
837955
_ => EINVAL,
838956
}
839957
}
958+
959+
#[cfg(test)]
960+
mod tests {
961+
#[test]
962+
fn o_rdonly_is_zero() {
963+
assert_eq!(super::O_RDONLY, 0);
964+
}
965+
966+
#[test]
967+
fn o_wronly_is_one() {
968+
assert_eq!(super::O_WRONLY, 1);
969+
}
970+
}

0 commit comments

Comments
 (0)