From 838fb4a6a0d11ac2c24189518415d181638af001 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 27 Dec 2017 18:38:57 +0100 Subject: [PATCH 1/2] 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. --- src/liballoc_system/lib.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 27259cc31a5ed..4597175474810 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -213,6 +213,16 @@ mod platform { struct Stderr; impl Write for Stderr { + #[cfg(target_os = "cloudabi")] + fn write_str(&mut self, _: &str) -> fmt::Result { + // CloudABI does not have any reserved file descriptor + // numbers. We should not attempt to write to file + // descriptor #2, as it may be associated with any kind of + // resource. + Ok(()) + } + + #[cfg(not(target_os = "cloudabi"))] fn write_str(&mut self, s: &str) -> fmt::Result { unsafe { libc::write(libc::STDERR_FILENO, From c661e385fd81afef808f414867cc44a6c897195e Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Sun, 31 Dec 2017 13:21:46 +0100 Subject: [PATCH 2/2] Build the right platform module on CloudABI. After #47089 lands, CloudABI will no longer be considered UNIX. We need to pick the right allocator flavour now. --- src/liballoc_system/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 4597175474810..1d5e7b73be557 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -21,7 +21,7 @@ #![feature(core_intrinsics)] #![feature(staged_api)] #![feature(rustc_attrs)] -#![cfg_attr(any(unix, target_os = "redox"), feature(libc))] +#![cfg_attr(any(unix, target_os = "cloudabi", target_os = "redox"), feature(libc))] #![rustc_alloc_kind = "lib"] // The minimum alignment guaranteed by the architecture. This value is used to @@ -116,7 +116,7 @@ unsafe impl Alloc for System { } } -#[cfg(any(unix, target_os = "redox"))] +#[cfg(any(unix, target_os = "cloudabi", target_os = "redox"))] mod platform { extern crate libc;