Skip to content

Commit cda7898

Browse files
committed
Auto merge of #3451 - RalfJung:linux-foreign-items, r=RalfJung
linux/foreign_items: reorder things to make more sense also remove duplicate socketpair
2 parents 394aa87 + 219226f commit cda7898

File tree

3 files changed

+32
-47
lines changed

3 files changed

+32
-47
lines changed

src/tools/miri/src/shims/unix/foreign_items.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,9 @@ use rustc_span::Symbol;
66
use rustc_target::abi::{Align, Size};
77
use rustc_target::spec::abi::Abi;
88

9+
use crate::shims::unix::*;
910
use crate::*;
1011
use shims::foreign_items::EmulateForeignItemResult;
11-
use shims::unix::fd::EvalContextExt as _;
12-
use shims::unix::fs::EvalContextExt as _;
13-
use shims::unix::mem::EvalContextExt as _;
14-
use shims::unix::socket::EvalContextExt as _;
15-
use shims::unix::sync::EvalContextExt as _;
16-
use shims::unix::thread::EvalContextExt as _;
1712

1813
use shims::unix::freebsd::foreign_items as freebsd;
1914
use shims::unix::linux::foreign_items as linux;

src/tools/miri/src/shims/unix/freebsd/foreign_items.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use rustc_span::Symbol;
22
use rustc_target::spec::abi::Abi;
33

4+
use crate::shims::unix::*;
45
use crate::*;
56
use shims::foreign_items::EmulateForeignItemResult;
6-
use shims::unix::fs::EvalContextExt as _;
7-
use shims::unix::thread::EvalContextExt as _;
87

98
pub fn is_dyn_sym(_name: &str) -> bool {
109
false

src/tools/miri/src/shims/unix/linux/foreign_items.rs

+30-39
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,20 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
2929
// See `fn emulate_foreign_item_inner` in `shims/foreign_items.rs` for the general pattern.
3030

3131
match link_name.as_str() {
32-
// errno
33-
"__errno_location" => {
34-
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
35-
let errno_place = this.last_error_place()?;
36-
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
37-
}
38-
3932
// File related shims (but also see "syscall" below for statx)
4033
"readdir64" => {
4134
let [dirp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
4235
let result = this.linux_readdir64(dirp)?;
4336
this.write_scalar(result, dest)?;
4437
}
45-
"mmap64" => {
46-
let [addr, length, prot, flags, fd, offset] =
47-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
48-
let offset = this.read_scalar(offset)?.to_i64()?;
49-
let ptr = this.mmap(addr, length, prot, flags, fd, offset.into())?;
50-
this.write_scalar(ptr, dest)?;
51-
}
52-
53-
// Linux-only
5438
"sync_file_range" => {
5539
let [fd, offset, nbytes, flags] =
5640
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
5741
let result = this.sync_file_range(fd, offset, nbytes, flags)?;
5842
this.write_scalar(result, dest)?;
5943
}
44+
45+
// epoll, eventfd
6046
"epoll_create1" => {
6147
let [flag] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
6248
let result = this.epoll_create1(flag)?;
@@ -80,29 +66,6 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
8066
let result = this.eventfd(val, flag)?;
8167
this.write_scalar(result, dest)?;
8268
}
83-
"mremap" => {
84-
let [old_address, old_size, new_size, flags] =
85-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
86-
let ptr = this.mremap(old_address, old_size, new_size, flags)?;
87-
this.write_scalar(ptr, dest)?;
88-
}
89-
"socketpair" => {
90-
let [domain, type_, protocol, sv] =
91-
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
92-
93-
let result = this.socketpair(domain, type_, protocol, sv)?;
94-
this.write_scalar(result, dest)?;
95-
}
96-
"__libc_current_sigrtmin" => {
97-
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
98-
99-
this.write_scalar(Scalar::from_i32(SIGRTMIN), dest)?;
100-
}
101-
"__libc_current_sigrtmax" => {
102-
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
103-
104-
this.write_scalar(Scalar::from_i32(SIGRTMAX), dest)?;
105-
}
10669

10770
// Threading
10871
"pthread_condattr_setclock" => {
@@ -204,6 +167,34 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
204167
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
205168
getrandom(this, ptr, len, flags, dest)?;
206169
}
170+
"mmap64" => {
171+
let [addr, length, prot, flags, fd, offset] =
172+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
173+
let offset = this.read_scalar(offset)?.to_i64()?;
174+
let ptr = this.mmap(addr, length, prot, flags, fd, offset.into())?;
175+
this.write_scalar(ptr, dest)?;
176+
}
177+
"mremap" => {
178+
let [old_address, old_size, new_size, flags] =
179+
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
180+
let ptr = this.mremap(old_address, old_size, new_size, flags)?;
181+
this.write_scalar(ptr, dest)?;
182+
}
183+
"__errno_location" => {
184+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
185+
let errno_place = this.last_error_place()?;
186+
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
187+
}
188+
"__libc_current_sigrtmin" => {
189+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
190+
191+
this.write_scalar(Scalar::from_i32(SIGRTMIN), dest)?;
192+
}
193+
"__libc_current_sigrtmax" => {
194+
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
195+
196+
this.write_scalar(Scalar::from_i32(SIGRTMAX), dest)?;
197+
}
207198

208199
// Incomplete shims that we "stub out" just to get pre-main initialization code to work.
209200
// These shims are enabled only when the caller is in the standard library.

0 commit comments

Comments
 (0)