about summary refs log tree commit diff
path: root/library/std/src
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2020-09-28 18:39:47 +0200
committerGitHub <noreply@github.com>2020-09-28 18:39:47 +0200
commita966f54bbb4325c74450ae65d2ca771eca652516 (patch)
tree3cf055350f52d0b246d59efab93979fa990f825e /library/std/src
parentaba966a592b29249a652c3632f4c209e00e30795 (diff)
parentdc8414b6076656b0722b0d5a8230a8613d8ccb57 (diff)
downloadrust-a966f54bbb4325c74450ae65d2ca771eca652516.tar.gz
rust-a966f54bbb4325c74450ae65d2ca771eca652516.zip
Rollup merge of #77288 - RalfJung:miri-macos, r=Amanieu
fix building libstd for Miri on macOS

Fixes a Miri regression introduced by https://github.com/rust-lang/rust/pull/75295
Cc @tmiasko @Amanieu
Diffstat (limited to 'library/std/src')
-rw-r--r--library/std/src/sys/unix/mod.rs99
1 files changed, 50 insertions, 49 deletions
diff --git a/library/std/src/sys/unix/mod.rs b/library/std/src/sys/unix/mod.rs
index b48d2162eca..00680fadc18 100644
--- a/library/std/src/sys/unix/mod.rs
+++ b/library/std/src/sys/unix/mod.rs
@@ -93,60 +93,61 @@ pub fn init() {
         reset_sigpipe();
     }
 
-    // In the case when all file descriptors are open, the poll has been
-    // observed to perform better than fcntl (on GNU/Linux).
-    #[cfg(not(any(
-        miri,
-        target_os = "emscripten",
-        target_os = "fuchsia",
-        // The poll on Darwin doesn't set POLLNVAL for closed fds.
-        target_os = "macos",
-        target_os = "ios",
-        target_os = "redox",
-    )))]
-    unsafe fn sanitize_standard_fds() {
-        use crate::sys::os::errno;
-        let pfds: &mut [_] = &mut [
-            libc::pollfd { fd: 0, events: 0, revents: 0 },
-            libc::pollfd { fd: 1, events: 0, revents: 0 },
-            libc::pollfd { fd: 2, events: 0, revents: 0 },
-        ];
-        while libc::poll(pfds.as_mut_ptr(), 3, 0) == -1 {
-            if errno() == libc::EINTR {
-                continue;
-            }
-            libc::abort();
-        }
-        for pfd in pfds {
-            if pfd.revents & libc::POLLNVAL == 0 {
-                continue;
-            }
-            if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
-                // If the stream is closed but we failed to reopen it, abort the
-                // process. Otherwise we wouldn't preserve the safety of
-                // operations on the corresponding Rust object Stdin, Stdout, or
-                // Stderr.
-                libc::abort();
-            }
-        }
-    }
-    #[cfg(any(target_os = "macos", target_os = "ios", target_os = "redox"))]
-    unsafe fn sanitize_standard_fds() {
-        use crate::sys::os::errno;
-        for fd in 0..3 {
-            if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
-                if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
+    cfg_if::cfg_if! {
+        if #[cfg(miri)] {
+            // The standard fds are always available in Miri.
+            unsafe fn sanitize_standard_fds() {}
+        } else if #[cfg(not(any(
+            target_os = "emscripten",
+            target_os = "fuchsia",
+            // The poll on Darwin doesn't set POLLNVAL for closed fds.
+            target_os = "macos",
+            target_os = "ios",
+            target_os = "redox",
+        )))] {
+            // In the case when all file descriptors are open, the poll has been
+            // observed to perform better than fcntl (on GNU/Linux).
+            unsafe fn sanitize_standard_fds() {
+                use crate::sys::os::errno;
+                let pfds: &mut [_] = &mut [
+                    libc::pollfd { fd: 0, events: 0, revents: 0 },
+                    libc::pollfd { fd: 1, events: 0, revents: 0 },
+                    libc::pollfd { fd: 2, events: 0, revents: 0 },
+                ];
+                while libc::poll(pfds.as_mut_ptr(), 3, 0) == -1 {
+                    if errno() == libc::EINTR {
+                        continue;
+                    }
                     libc::abort();
                 }
+                for pfd in pfds {
+                    if pfd.revents & libc::POLLNVAL == 0 {
+                        continue;
+                    }
+                    if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
+                        // If the stream is closed but we failed to reopen it, abort the
+                        // process. Otherwise we wouldn't preserve the safety of
+                        // operations on the corresponding Rust object Stdin, Stdout, or
+                        // Stderr.
+                        libc::abort();
+                    }
+                }
+            }
+        } else if #[cfg(any(target_os = "macos", target_os = "ios", target_os = "redox"))] {
+            unsafe fn sanitize_standard_fds() {
+                use crate::sys::os::errno;
+                for fd in 0..3 {
+                    if libc::fcntl(fd, libc::F_GETFD) == -1 && errno() == libc::EBADF {
+                        if libc::open("/dev/null\0".as_ptr().cast(), libc::O_RDWR, 0) == -1 {
+                            libc::abort();
+                        }
+                    }
+                }
             }
+        } else {
+            unsafe fn sanitize_standard_fds() {}
         }
     }
-    #[cfg(any(
-        // The standard fds are always available in Miri.
-        miri,
-        target_os = "emscripten",
-        target_os = "fuchsia"))]
-    unsafe fn sanitize_standard_fds() {}
 
     #[cfg(not(any(target_os = "emscripten", target_os = "fuchsia")))]
     unsafe fn reset_sigpipe() {