Skip to content

Commit 4bc5309

Browse files
authored
Rollup merge of rust-lang#47033 - EdSchouten:cloudabi-oom, r=kennytm
Disable printing of error message on file descriptor 2 on CloudABI. As CloudABI is a capability-based runtime environment, file descriptors are the mechanism that grants rights to a process. These file descriptors may be passed into processes on startup using a utility called cloudabi-run. Unlike the POSIX shell, cloudabi-run does not follow the UNIX model where file descriptors 0, 1 and 2 represent stdin, stdout and stderr. There can be arbitrary many (or few) file descriptors that can be provided. For this reason, CloudABI's C library also doesn't define STD*_FILENO. liblibc should also not declare these. Disable the code in liballoc_system that tries to print error messages over file descriptor 2. For now, let's keep this function quiet. We'll see if we can think of some other way to log this in the future.
2 parents b6f7484 + c661e38 commit 4bc5309

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

src/liballoc_system/lib.rs

+12-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#![feature(core_intrinsics)]
2222
#![feature(staged_api)]
2323
#![feature(rustc_attrs)]
24-
#![cfg_attr(any(unix, target_os = "redox"), feature(libc))]
24+
#![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))]
2525
#![rustc_alloc_kind = "lib"]
2626

2727
// The minimum alignment guaranteed by the architecture. This value is used to
@@ -116,7 +116,7 @@ unsafe impl Alloc for System {
116116
}
117117
}
118118

119-
#[cfg(any(unix, target_os = "redox"))]
119+
#[cfg(any(unix, target_os = "cloudabi", target_os = "redox"))]
120120
mod platform {
121121
extern crate libc;
122122

@@ -213,6 +213,16 @@ mod platform {
213213
struct Stderr;
214214

215215
impl Write for Stderr {
216+
#[cfg(target_os = "cloudabi")]
217+
fn write_str(&mut self, _: &str) -> fmt::Result {
218+
// CloudABI does not have any reserved file descriptor
219+
// numbers. We should not attempt to write to file
220+
// descriptor #2, as it may be associated with any kind of
221+
// resource.
222+
Ok(())
223+
}
224+
225+
#[cfg(not(target_os = "cloudabi"))]
216226
fn write_str(&mut self, s: &str) -> fmt::Result {
217227
unsafe {
218228
libc::write(libc::STDERR_FILENO,

0 commit comments

Comments
 (0)