Skip to content

Commit 98d2049

Browse files
committed
move some POSIX file shims from linux to unix module
1 parent 24c5eaf commit 98d2049

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

src/shims/unix/foreign_items.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6262
let result = this.open(args)?;
6363
this.write_scalar(Scalar::from_i32(result), dest)?;
6464
}
65+
"close" => {
66+
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
67+
let result = this.close(fd)?;
68+
this.write_scalar(Scalar::from_i32(result), dest)?;
69+
}
6570
"fcntl" => {
6671
// `fcntl` is variadic. The argument count is checked based on the first argument
6772
// in `this.fcntl()`, so we do not use `check_shim` here.
@@ -112,17 +117,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
112117
let result = this.rmdir(path)?;
113118
this.write_scalar(Scalar::from_i32(result), dest)?;
114119
}
120+
"opendir" => {
121+
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
122+
let result = this.opendir(name)?;
123+
this.write_scalar(result, dest)?;
124+
}
115125
"closedir" => {
116126
let [dirp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
117127
let result = this.closedir(dirp)?;
118128
this.write_scalar(Scalar::from_i32(result), dest)?;
119129
}
120-
"lseek" | "lseek64" => {
130+
"lseek64" => {
121131
let [fd, offset, whence] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
122132
let result = this.lseek64(fd, offset, whence)?;
123-
// "lseek" is only used on macOS which is 64bit-only, so `i64` always works.
124133
this.write_scalar(Scalar::from_i64(result), dest)?;
125134
}
135+
"ftruncate64" => {
136+
let [fd, length] =
137+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
138+
let result = this.ftruncate64(fd, length)?;
139+
this.write_scalar(Scalar::from_i32(result), dest)?;
140+
}
126141
"fsync" => {
127142
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
128143
let result = this.fsync(fd)?;

src/shims/unix/linux/foreign_items.rs

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,29 +30,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3030
}
3131

3232
// File related shims (but also see "syscall" below for statx)
33-
// These symbols have different names on Linux and macOS, which is the only reason they are not
34-
// in the `posix` module.
35-
"close" => {
36-
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
37-
let result = this.close(fd)?;
38-
this.write_scalar(Scalar::from_i32(result), dest)?;
39-
}
40-
"opendir" => {
41-
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
42-
let result = this.opendir(name)?;
43-
this.write_scalar(result, dest)?;
44-
}
4533
"readdir64" => {
4634
let [dirp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
4735
let result = this.linux_readdir64(dirp)?;
4836
this.write_scalar(result, dest)?;
4937
}
50-
"ftruncate64" => {
51-
let [fd, length] =
52-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
53-
let result = this.ftruncate64(fd, length)?;
54-
this.write_scalar(Scalar::from_i32(result), dest)?;
55-
}
5638
// Linux-only
5739
"posix_fadvise" => {
5840
let [fd, offset, len, advice] =

src/shims/unix/macos/foreign_items.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2828
}
2929

3030
// File related shims
31-
"close" | "close$NOCANCEL" => {
31+
"close$NOCANCEL" => {
3232
let [result] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
3333
let result = this.close(result)?;
3434
this.write_scalar(Scalar::from_i32(result), dest)?;
@@ -50,7 +50,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5050
let result = this.macos_fstat(fd, buf)?;
5151
this.write_scalar(Scalar::from_i32(result), dest)?;
5252
}
53-
"opendir" | "opendir$INODE64" => {
53+
"opendir$INODE64" => {
5454
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
5555
let result = this.opendir(name)?;
5656
this.write_scalar(result, dest)?;
@@ -61,9 +61,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6161
let result = this.macos_readdir_r(dirp, entry, result)?;
6262
this.write_scalar(Scalar::from_i32(result), dest)?;
6363
}
64+
"lseek" => {
65+
let [fd, offset, whence] =
66+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
67+
// macOS is 64bit-only, so this is lseek64
68+
let result = this.lseek64(fd, offset, whence)?;
69+
this.write_scalar(Scalar::from_i64(result), dest)?;
70+
}
6471
"ftruncate" => {
6572
let [fd, length] =
6673
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
74+
// macOS is 64bit-only, so this is ftruncate64
6775
let result = this.ftruncate64(fd, length)?;
6876
this.write_scalar(Scalar::from_i32(result), dest)?;
6977
}

0 commit comments

Comments
 (0)