Skip to content

Commit c7d5f76

Browse files
author
Nym Seddon
committed
fixup! Add ABI check for shims
1 parent 62239c4 commit c7d5f76

File tree

7 files changed

+26
-8
lines changed

7 files changed

+26
-8
lines changed

src/machine.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,12 +365,12 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'mir, 'tcx> {
365365
fn call_extra_fn(
366366
ecx: &mut InterpCx<'mir, 'tcx, Self>,
367367
fn_val: Dlsym,
368-
_abi: Abi,
368+
abi: Abi,
369369
args: &[OpTy<'tcx, Tag>],
370370
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
371371
_unwind: Option<mir::BasicBlock>,
372372
) -> InterpResult<'tcx> {
373-
ecx.call_dlsym(fn_val, args, ret)
373+
ecx.call_dlsym(fn_val, abi, args, ret)
374374
}
375375

376376
#[inline(always)]

src/shims/dlsym.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_middle::mir;
2+
use rustc_target::spec::abi::Abi;
23

34
use crate::*;
45
use shims::posix::dlsym as posix;
@@ -29,13 +30,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2930
fn call_dlsym(
3031
&mut self,
3132
dlsym: Dlsym,
33+
abi: Abi,
3234
args: &[OpTy<'tcx, Tag>],
3335
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
3436
) -> InterpResult<'tcx> {
3537
let this = self.eval_context_mut();
3638
match dlsym {
37-
Dlsym::Posix(dlsym) => posix::EvalContextExt::call_dlsym(this, dlsym, args, ret),
38-
Dlsym::Windows(dlsym) => windows::EvalContextExt::call_dlsym(this, dlsym, args, ret),
39+
Dlsym::Posix(dlsym) => posix::EvalContextExt::call_dlsym(this, dlsym, abi, args, ret),
40+
Dlsym::Windows(dlsym) => windows::EvalContextExt::call_dlsym(this, dlsym, abi, args, ret),
3941
}
4042
}
4143
}

src/shims/foreign_items.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,29 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
131131
let (dest, ret) = match ret {
132132
None => match link_name {
133133
"miri_start_panic" => {
134+
check_abi(abi, Abi::Rust)?;
134135
this.handle_miri_start_panic(args, unwind)?;
135136
return Ok(None);
136137
}
137138
// This matches calls to the foreign item `panic_impl`.
138139
// The implementation is provided by the function with the `#[panic_handler]` attribute.
139140
"panic_impl" => {
141+
check_abi(abi, Abi::Rust)?;
140142
let panic_impl_id = tcx.lang_items().panic_impl().unwrap();
141143
let panic_impl_instance = ty::Instance::mono(tcx, panic_impl_id);
142144
return Ok(Some(&*this.load_mir(panic_impl_instance.def, None)?));
143145
}
144146
| "exit"
145147
| "ExitProcess"
146148
=> {
149+
check_abi(abi, if link_name == "exit" { Abi::C } else { Abi::System })?;
147150
let &[code] = check_arg_count(args)?;
148151
// it's really u32 for ExitProcess, but we have to put it into the `Exit` variant anyway
149152
let code = this.read_scalar(code)?.to_i32()?;
150153
throw_machine_stop!(TerminationInfo::Exit(code.into()));
151154
}
152155
"abort" => {
156+
check_abi(abi, Abi::C)?;
153157
throw_machine_stop!(TerminationInfo::Abort("the program aborted execution".to_owned()))
154158
}
155159
_ => throw_unsup_format!("can't call (diverging) foreign function: {}", link_name),
@@ -504,6 +508,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
504508

505509
// Architecture-specific shims
506510
"llvm.x86.sse2.pause" if this.tcx.sess.target.arch == "x86" || this.tcx.sess.target.arch == "x86_64" => {
511+
check_abi(abi, Abi::C)?;
507512
let &[] = check_arg_count(args)?;
508513
this.yield_active_thread();
509514
}

src/shims/posix/dlsym.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_middle::mir;
2+
use rustc_target::spec::abi::Abi;
23

34
use crate::*;
45
use shims::posix::linux::dlsym as linux;
@@ -27,13 +28,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2728
fn call_dlsym(
2829
&mut self,
2930
dlsym: Dlsym,
31+
abi: Abi,
3032
args: &[OpTy<'tcx, Tag>],
3133
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
3234
) -> InterpResult<'tcx> {
3335
let this = self.eval_context_mut();
3436
match dlsym {
35-
Dlsym::Linux(dlsym) => linux::EvalContextExt::call_dlsym(this, dlsym, args, ret),
36-
Dlsym::MacOs(dlsym) => macos::EvalContextExt::call_dlsym(this, dlsym, args, ret),
37+
Dlsym::Linux(dlsym) => linux::EvalContextExt::call_dlsym(this, dlsym, abi, args, ret),
38+
Dlsym::MacOs(dlsym) => macos::EvalContextExt::call_dlsym(this, dlsym, abi, args, ret),
3739
}
3840
}
3941
}

src/shims/posix/linux/dlsym.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use rustc_middle::mir;
2+
use rustc_target::spec::abi::Abi;
23

34
use crate::*;
45

@@ -24,6 +25,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2425
fn call_dlsym(
2526
&mut self,
2627
dlsym: Dlsym,
28+
_abi: Abi,
2729
_args: &[OpTy<'tcx, Tag>],
2830
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
2931
) -> InterpResult<'tcx> {

src/shims/posix/macos/dlsym.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use rustc_middle::mir;
2+
use rustc_target::spec::abi::Abi;
23

34
use log::trace;
45

56
use crate::*;
6-
use helpers::check_arg_count;
7+
use helpers::{check_abi, check_arg_count};
78

89
#[derive(Debug, Copy, Clone)]
910
#[allow(non_camel_case_types)]
@@ -27,6 +28,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2728
fn call_dlsym(
2829
&mut self,
2930
dlsym: Dlsym,
31+
abi: Abi,
3032
args: &[OpTy<'tcx, Tag>],
3133
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
3234
) -> InterpResult<'tcx> {
@@ -36,6 +38,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3638

3739
match dlsym {
3840
Dlsym::getentropy => {
41+
check_abi(abi, Abi::C)?;
3942
let &[ptr, len] = check_arg_count(args)?;
4043
let ptr = this.read_scalar(ptr)?.check_init()?;
4144
let len = this.read_scalar(len)?.to_machine_usize(this)?;

src/shims/windows/dlsym.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use rustc_middle::mir;
2+
use rustc_target::spec::abi::Abi;
23

34
use log::trace;
45

56
use crate::*;
6-
use helpers::check_arg_count;
7+
use helpers::{check_abi, check_arg_count};
78
use shims::windows::sync::EvalContextExt as _;
89

910
#[derive(Debug, Copy, Clone)]
@@ -39,13 +40,16 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3940
fn call_dlsym(
4041
&mut self,
4142
dlsym: Dlsym,
43+
abi: Abi,
4244
args: &[OpTy<'tcx, Tag>],
4345
ret: Option<(PlaceTy<'tcx, Tag>, mir::BasicBlock)>,
4446
) -> InterpResult<'tcx> {
4547
let this = self.eval_context_mut();
4648
let (dest, ret) = ret.expect("we don't support any diverging dlsym");
4749
assert!(this.tcx.sess.target.os == "windows");
4850

51+
check_abi(abi, Abi::System)?;
52+
4953
match dlsym {
5054
Dlsym::AcquireSRWLockExclusive => {
5155
let &[ptr] = check_arg_count(args)?;

0 commit comments

Comments
 (0)