Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
fn isatty(&mut self, miri_fd: &OpTy<'tcx, Tag>) -> InterpResult<'tcx, i32> {
let this = self.eval_context_mut();
#[cfg(unix)]
{
if matches!(this.machine.isolated_op, IsolatedOp::Allow) {
let miri_fd = this.read_scalar(miri_fd)?.to_i32()?;
if let Some(host_fd) =
this.machine.file_handler.handles.get(&miri_fd).and_then(|fd| fd.as_unix_host_fd())
Expand All @@ -1714,7 +1714,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
}
// We are attemping to use a Unix interface on a non-Unix platform, or we are on a Unix
// platform and the passed file descriptor is not open.
// platform and the passed file descriptor is not open, or isolation is enabled
// FIXME: It should be possible to emulate this at least on Windows by using
// GetConsoleMode.
let enotty = this.eval_libc("ENOTTY")?;
Expand Down
22 changes: 16 additions & 6 deletions tests/pass/libc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
//@ignore-windows: No libc on Windows
//@compile-flags: -Zmiri-disable-isolation

#![feature(rustc_private)]

use std::fs::{remove_file, File};
use std::os::unix::io::AsRawFd;

extern crate libc;

#[cfg(any(target_os = "linux", target_os = "freebsd"))]
fn tmp() -> std::path::PathBuf {
std::env::var("MIRI_TEMP")
.map(std::path::PathBuf::from)
Expand All @@ -15,9 +16,7 @@ fn tmp() -> std::path::PathBuf {
#[cfg(any(target_os = "linux", target_os = "freebsd"))]
fn test_posix_fadvise() {
use std::convert::TryInto;
use std::fs::{remove_file, File};
use std::io::Write;
use std::os::unix::io::AsRawFd;

let path = tmp().join("miri_test_libc_posix_fadvise.txt");
// Cleanup before test
Expand All @@ -44,9 +43,7 @@ fn test_posix_fadvise() {

#[cfg(any(target_os = "linux"))]
fn test_sync_file_range() {
use std::fs::{remove_file, File};
use std::io::Write;
use std::os::unix::io::AsRawFd;

let path = tmp().join("miri_test_libc_sync_file_range.txt");
// Cleanup before test.
Expand Down Expand Up @@ -319,6 +316,19 @@ fn test_isatty() {
libc::isatty(libc::STDIN_FILENO);
libc::isatty(libc::STDOUT_FILENO);
libc::isatty(libc::STDERR_FILENO);

// But when we open a file, it is definitely not a TTY.
let path = tmp().join("notatty.txt");
// Cleanup before test.
remove_file(&path).ok();
let file = File::create(&path).unwrap();

assert_eq!(libc::isatty(file.as_raw_fd()), 0);
assert_eq!(std::io::Error::last_os_error().raw_os_error().unwrap(), libc::ENOTTY);

// Cleanup after test.
drop(file);
remove_file(&path).unwrap();
}
}

Expand Down