Skip to content

Commit 3125c69

Browse files
authored
Merge pull request #4031 from devnexen/solarish_stat
filesystem support for solarish: stat
2 parents 7b10fd0 + d49b20c commit 3125c69

File tree

6 files changed

+75
-34
lines changed

6 files changed

+75
-34
lines changed

ci/ci.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ case $HOST_TARGET in
152152
UNIX="hello panic/panic panic/unwind concurrency/simple atomic libc-mem libc-misc libc-random env num_cpus" # the things that are very similar across all Unixes, and hence easily supported there
153153
TEST_TARGET=x86_64-unknown-freebsd run_tests_minimal $BASIC $UNIX time hashmap random threadname pthread fs libc-pipe
154154
TEST_TARGET=i686-unknown-freebsd run_tests_minimal $BASIC $UNIX time hashmap random threadname pthread fs libc-pipe
155-
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
156-
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe
155+
TEST_TARGET=x86_64-unknown-illumos run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe fs
156+
TEST_TARGET=x86_64-pc-solaris run_tests_minimal $BASIC $UNIX time hashmap random thread sync available-parallelism tls libc-pipe fs
157157
TEST_TARGET=aarch64-linux-android run_tests_minimal $BASIC $UNIX time hashmap random sync threadname pthread epoll eventfd
158158
TEST_TARGET=wasm32-wasip2 run_tests_minimal $BASIC wasm
159159
TEST_TARGET=wasm32-unknown-unknown run_tests_minimal no_std empty_main wasm # this target doesn't really have std

src/shims/unix/freebsd/foreign_items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,19 +53,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5353
"stat" | "stat@FBSD_1.0" => {
5454
let [path, buf] =
5555
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
56-
let result = this.macos_fbsd_stat(path, buf)?;
56+
let result = this.macos_fbsd_solaris_stat(path, buf)?;
5757
this.write_scalar(result, dest)?;
5858
}
5959
"lstat" | "lstat@FBSD_1.0" => {
6060
let [path, buf] =
6161
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
62-
let result = this.macos_fbsd_lstat(path, buf)?;
62+
let result = this.macos_fbsd_solaris_lstat(path, buf)?;
6363
this.write_scalar(result, dest)?;
6464
}
6565
"fstat" | "fstat@FBSD_1.0" => {
6666
let [fd, buf] =
6767
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
68-
let result = this.macos_fbsd_fstat(fd, buf)?;
68+
let result = this.macos_fbsd_solaris_fstat(fd, buf)?;
6969
this.write_scalar(result, dest)?;
7070
}
7171
"readdir_r" | "readdir_r@FBSD_1.0" => {

src/shims/unix/fs.rs

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -265,47 +265,59 @@ impl FileDescription for FileHandle {
265265

266266
impl<'tcx> EvalContextExtPrivate<'tcx> for crate::MiriInterpCx<'tcx> {}
267267
trait EvalContextExtPrivate<'tcx>: crate::MiriInterpCxExt<'tcx> {
268-
fn macos_stat_write_buf(
268+
fn macos_fbsd_solaris_write_buf(
269269
&mut self,
270270
metadata: FileMetadata,
271271
buf_op: &OpTy<'tcx>,
272272
) -> InterpResult<'tcx, i32> {
273273
let this = self.eval_context_mut();
274274

275-
let mode: u16 = metadata.mode.to_u16()?;
276-
277275
let (access_sec, access_nsec) = metadata.accessed.unwrap_or((0, 0));
278276
let (created_sec, created_nsec) = metadata.created.unwrap_or((0, 0));
279277
let (modified_sec, modified_nsec) = metadata.modified.unwrap_or((0, 0));
278+
let mode = metadata.mode.to_uint(this.libc_ty_layout("mode_t").size)?;
280279

281280
let buf = this.deref_pointer_as(buf_op, this.libc_ty_layout("stat"))?;
282-
283281
this.write_int_fields_named(
284282
&[
285283
("st_dev", 0),
286-
("st_mode", mode.into()),
284+
("st_mode", mode.try_into().unwrap()),
287285
("st_nlink", 0),
288286
("st_ino", 0),
289287
("st_uid", 0),
290288
("st_gid", 0),
291289
("st_rdev", 0),
292290
("st_atime", access_sec.into()),
293-
("st_atime_nsec", access_nsec.into()),
294291
("st_mtime", modified_sec.into()),
295-
("st_mtime_nsec", modified_nsec.into()),
296292
("st_ctime", 0),
297-
("st_ctime_nsec", 0),
298-
("st_birthtime", created_sec.into()),
299-
("st_birthtime_nsec", created_nsec.into()),
300293
("st_size", metadata.size.into()),
301294
("st_blocks", 0),
302295
("st_blksize", 0),
303-
("st_flags", 0),
304-
("st_gen", 0),
305296
],
306297
&buf,
307298
)?;
308299

300+
if matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") {
301+
this.write_int_fields_named(
302+
&[
303+
("st_atime_nsec", access_nsec.into()),
304+
("st_mtime_nsec", modified_nsec.into()),
305+
("st_ctime_nsec", 0),
306+
("st_birthtime", created_sec.into()),
307+
("st_birthtime_nsec", created_nsec.into()),
308+
("st_flags", 0),
309+
("st_gen", 0),
310+
],
311+
&buf,
312+
)?;
313+
}
314+
315+
if matches!(&*this.tcx.sess.target.os, "solaris" | "illumos") {
316+
// FIXME: write st_fstype field once libc is updated.
317+
// https://github.com/rust-lang/libc/pull/4145
318+
//this.write_int_fields_named(&[("st_fstype", 0)], &buf)?;
319+
}
320+
309321
interp_ok(0)
310322
}
311323

@@ -648,15 +660,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
648660
interp_ok(Scalar::from_i32(this.try_unwrap_io_result(result)?))
649661
}
650662

651-
fn macos_fbsd_stat(
663+
fn macos_fbsd_solaris_stat(
652664
&mut self,
653665
path_op: &OpTy<'tcx>,
654666
buf_op: &OpTy<'tcx>,
655667
) -> InterpResult<'tcx, Scalar> {
656668
let this = self.eval_context_mut();
657669

658-
if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") {
659-
panic!("`macos_fbsd_stat` should not be called on {}", this.tcx.sess.target.os);
670+
if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd" | "solaris" | "illumos") {
671+
panic!("`macos_fbsd_solaris_stat` should not be called on {}", this.tcx.sess.target.os);
660672
}
661673

662674
let path_scalar = this.read_pointer(path_op)?;
@@ -674,19 +686,22 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
674686
Err(err) => return this.set_last_error_and_return_i32(err),
675687
};
676688

677-
interp_ok(Scalar::from_i32(this.macos_stat_write_buf(metadata, buf_op)?))
689+
interp_ok(Scalar::from_i32(this.macos_fbsd_solaris_write_buf(metadata, buf_op)?))
678690
}
679691

680692
// `lstat` is used to get symlink metadata.
681-
fn macos_fbsd_lstat(
693+
fn macos_fbsd_solaris_lstat(
682694
&mut self,
683695
path_op: &OpTy<'tcx>,
684696
buf_op: &OpTy<'tcx>,
685697
) -> InterpResult<'tcx, Scalar> {
686698
let this = self.eval_context_mut();
687699

688-
if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") {
689-
panic!("`macos_fbsd_lstat` should not be called on {}", this.tcx.sess.target.os);
700+
if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd" | "solaris" | "illumos") {
701+
panic!(
702+
"`macos_fbsd_solaris_lstat` should not be called on {}",
703+
this.tcx.sess.target.os
704+
);
690705
}
691706

692707
let path_scalar = this.read_pointer(path_op)?;
@@ -703,18 +718,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
703718
Err(err) => return this.set_last_error_and_return_i32(err),
704719
};
705720

706-
interp_ok(Scalar::from_i32(this.macos_stat_write_buf(metadata, buf_op)?))
721+
interp_ok(Scalar::from_i32(this.macos_fbsd_solaris_write_buf(metadata, buf_op)?))
707722
}
708723

709-
fn macos_fbsd_fstat(
724+
fn macos_fbsd_solaris_fstat(
710725
&mut self,
711726
fd_op: &OpTy<'tcx>,
712727
buf_op: &OpTy<'tcx>,
713728
) -> InterpResult<'tcx, Scalar> {
714729
let this = self.eval_context_mut();
715730

716-
if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd") {
717-
panic!("`macos_fbsd_fstat` should not be called on {}", this.tcx.sess.target.os);
731+
if !matches!(&*this.tcx.sess.target.os, "macos" | "freebsd" | "solaris" | "illumos") {
732+
panic!(
733+
"`macos_fbsd_solaris_fstat` should not be called on {}",
734+
this.tcx.sess.target.os
735+
);
718736
}
719737

720738
let fd = this.read_scalar(fd_op)?.to_i32()?;
@@ -730,7 +748,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
730748
Ok(metadata) => metadata,
731749
Err(err) => return this.set_last_error_and_return_i32(err),
732750
};
733-
interp_ok(Scalar::from_i32(this.macos_stat_write_buf(metadata, buf_op)?))
751+
interp_ok(Scalar::from_i32(this.macos_fbsd_solaris_write_buf(metadata, buf_op)?))
734752
}
735753

736754
fn linux_statx(

src/shims/unix/macos/foreign_items.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,19 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
4040
"stat" | "stat64" | "stat$INODE64" => {
4141
let [path, buf] =
4242
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
43-
let result = this.macos_fbsd_stat(path, buf)?;
43+
let result = this.macos_fbsd_solaris_stat(path, buf)?;
4444
this.write_scalar(result, dest)?;
4545
}
4646
"lstat" | "lstat64" | "lstat$INODE64" => {
4747
let [path, buf] =
4848
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
49-
let result = this.macos_fbsd_lstat(path, buf)?;
49+
let result = this.macos_fbsd_solaris_lstat(path, buf)?;
5050
this.write_scalar(result, dest)?;
5151
}
5252
"fstat" | "fstat64" | "fstat$INODE64" => {
5353
let [fd, buf] =
5454
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
55-
let result = this.macos_fbsd_fstat(fd, buf)?;
55+
let result = this.macos_fbsd_solaris_fstat(fd, buf)?;
5656
this.write_scalar(result, dest)?;
5757
}
5858
"opendir$INODE64" => {

src/shims/unix/solarish/foreign_items.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5757
this.write_scalar(res, dest)?;
5858
}
5959

60+
// File related shims
61+
"stat" | "stat64" => {
62+
let [path, buf] =
63+
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
64+
let result = this.macos_fbsd_solaris_stat(path, buf)?;
65+
this.write_scalar(result, dest)?;
66+
}
67+
"lstat" | "lstat64" => {
68+
let [path, buf] =
69+
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
70+
let result = this.macos_fbsd_solaris_lstat(path, buf)?;
71+
this.write_scalar(result, dest)?;
72+
}
73+
"fstat" | "fstat64" => {
74+
let [fd, buf] =
75+
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
76+
let result = this.macos_fbsd_solaris_fstat(fd, buf)?;
77+
this.write_scalar(result, dest)?;
78+
}
79+
6080
// Miscellaneous
6181
"___errno" => {
6282
let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;

tests/pass/shims/fs.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,11 @@ fn main() {
2727
test_file_sync();
2828
test_errors();
2929
test_rename();
30-
test_directory();
31-
test_canonicalize();
30+
// solarish needs to support readdir/readdir64 for these tests.
31+
if cfg!(not(any(target_os = "solaris", target_os = "illumos"))) {
32+
test_directory();
33+
test_canonicalize();
34+
}
3235
test_from_raw_os_error();
3336
#[cfg(unix)]
3437
test_pread_pwrite();

0 commit comments

Comments
 (0)