Skip to content
Closed
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
9 changes: 7 additions & 2 deletions src/shims/unix/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
);
};

if mode != 0o666 {
throw_unsup_format!("non-default mode 0o{:o} is not supported", mode);
// currently we only support that the owner must always have
// read-write permissions and that none of the owner, group
// and other may have execute permissions.
let owner_has_read_write_permissions = mode & 0o600 == 0o600;
let has_any_execute_permissions = mode & 0o111 != 0;
if !owner_has_read_write_permissions || has_any_execute_permissions {
throw_unsup_format!("mode 0o{:o} is not supported", mode);
}

mirror |= o_creat;
Expand Down
42 changes: 42 additions & 0 deletions test_dependencies/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions test_dependencies/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ tokio = { version = "1.0", features = ["full"] }
libc = "0.2"
page_size = "0.5"
num_cpus = "1.10.1"
tempfile = "3"

getrandom_1 = { package = "getrandom", version = "0.1" }
getrandom = { version = "0.2" }
Expand Down
39 changes: 39 additions & 0 deletions tests/pass-dep/tempfile.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//@ignore-target-windows: no libc on Windows
//@compile-flags: -Zmiri-disable-isolation

use std::ffi::{CStr, CString};
use std::path::PathBuf;

/// Test that the [`tempfile`] crate is compatible with miri.
fn main() {
// test_tempfile(); // does not work when host!=target
test_tempfile_in();
}

fn tmp() -> PathBuf {
let path = std::env::var("MIRI_TEMP")
.unwrap_or_else(|_| std::env::temp_dir().into_os_string().into_string().unwrap());
// These are host paths. We need to convert them to the target.
let path = CString::new(path).unwrap();
let mut out = Vec::with_capacity(1024);

unsafe {
extern "Rust" {
fn miri_host_to_target_path(path: *const i8, out: *mut i8, out_size: usize) -> usize;
}
let ret = miri_host_to_target_path(path.as_ptr(), out.as_mut_ptr(), out.capacity());
assert_eq!(ret, 0);
let out = CStr::from_ptr(out.as_ptr()).to_str().unwrap();
PathBuf::from(out)
}
}

// does not work when host!=target:
// fn test_tempfile() {
// tempfile::tempfile().unwrap();
// }

fn test_tempfile_in() {
let dir_path = tmp();
tempfile::tempfile_in(dir_path).unwrap();
}