Auto merge of #132512 - workingjubilee:update-miri-for-rustc-abi, r=RalfJung

miri: Directly use rustc_abi

I tried to make this a PR to the miri repo for funsies. Ironically, the integration flow meant that it would use a too-old toolchain hash, and I didn't understand the build system there enough to want to manually fiddle with the hashes.
This commit is contained in:
bors 2024-11-02 16:46:08 +00:00
commit 00ed73cdc0
61 changed files with 526 additions and 485 deletions

View File

@ -1 +1 @@
arithmetic-side-effects-allowed = ["rustc_target::abi::Size"] arithmetic-side-effects-allowed = ["rustc_abi::Size"]

View File

@ -7,9 +7,9 @@ use std::cell::RefCell;
use std::cmp::max; use std::cmp::max;
use rand::Rng; use rand::Rng;
use rustc_abi::{Align, Size};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_span::Span; use rustc_span::Span;
use rustc_target::abi::{Align, Size};
use self::reuse_pool::ReusePool; use self::reuse_pool::ReusePool;
use crate::concurrency::VClock; use crate::concurrency::VClock;

View File

@ -1,7 +1,7 @@
//! Manages a pool of addresses that can be reused. //! Manages a pool of addresses that can be reused.
use rand::Rng; use rand::Rng;
use rustc_target::abi::{Align, Size}; use rustc_abi::{Align, Size};
use crate::concurrency::VClock; use crate::concurrency::VClock;
use crate::{MemoryKind, MiriConfig, ThreadId}; use crate::{MemoryKind, MiriConfig, ThreadId};

View File

@ -2,8 +2,8 @@ use std::alloc::Layout;
use std::borrow::Cow; use std::borrow::Cow;
use std::{alloc, slice}; use std::{alloc, slice};
use rustc_abi::{Align, Size};
use rustc_middle::mir::interpret::AllocBytes; use rustc_middle::mir::interpret::AllocBytes;
use rustc_target::abi::{Align, Size};
/// Allocation bytes that explicitly handle the layout of the data they're storing. /// Allocation bytes that explicitly handle the layout of the data they're storing.
/// This is necessary to interface with native code that accesses the program store in Miri. /// This is necessary to interface with native code that accesses the program store in Miri.

View File

@ -11,6 +11,7 @@
extern crate tracing; extern crate tracing;
// The rustc crates we need // The rustc crates we need
extern crate rustc_abi;
extern crate rustc_data_structures; extern crate rustc_data_structures;
extern crate rustc_driver; extern crate rustc_driver;
extern crate rustc_hir; extern crate rustc_hir;
@ -21,7 +22,6 @@ extern crate rustc_metadata;
extern crate rustc_middle; extern crate rustc_middle;
extern crate rustc_session; extern crate rustc_session;
extern crate rustc_span; extern crate rustc_span;
extern crate rustc_target;
use std::env::{self, VarError}; use std::env::{self, VarError};
use std::num::NonZero; use std::num::NonZero;
@ -29,6 +29,7 @@ use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use miri::{BacktraceStyle, BorrowTrackerMethod, ProvenanceMode, RetagFields, ValidationMode}; use miri::{BacktraceStyle, BorrowTrackerMethod, ProvenanceMode, RetagFields, ValidationMode};
use rustc_abi::ExternAbi;
use rustc_data_structures::sync::Lrc; use rustc_data_structures::sync::Lrc;
use rustc_driver::Compilation; use rustc_driver::Compilation;
use rustc_hir::def_id::LOCAL_CRATE; use rustc_hir::def_id::LOCAL_CRATE;
@ -47,7 +48,6 @@ use rustc_session::config::{CrateType, EntryFnType, ErrorOutputType, OptLevel};
use rustc_session::search_paths::PathKind; use rustc_session::search_paths::PathKind;
use rustc_session::{CtfeBacktrace, EarlyDiagCtxt}; use rustc_session::{CtfeBacktrace, EarlyDiagCtxt};
use rustc_span::def_id::DefId; use rustc_span::def_id::DefId;
use rustc_target::spec::abi::Abi;
use tracing::debug; use tracing::debug;
struct MiriCompilerCalls { struct MiriCompilerCalls {
@ -368,7 +368,7 @@ fn entry_fn(tcx: TyCtxt<'_>) -> (DefId, EntryFnType) {
tcx.types.isize, tcx.types.isize,
false, false,
hir::Safety::Safe, hir::Safety::Safe,
Abi::Rust, ExternAbi::Rust,
)); ));
let correct_func_sig = check_function_signature( let correct_func_sig = check_function_signature(

View File

@ -2,9 +2,9 @@ use std::cell::RefCell;
use std::fmt; use std::fmt;
use std::num::NonZero; use std::num::NonZero;
use rustc_abi::Size;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_middle::mir::RetagKind; use rustc_middle::mir::RetagKind;
use rustc_target::abi::Size;
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::*; use crate::*;

View File

@ -1,8 +1,8 @@
use std::fmt; use std::fmt;
use rustc_abi::Size;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_span::{Span, SpanData}; use rustc_span::{Span, SpanData};
use rustc_target::abi::Size;
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::borrow_tracker::{GlobalStateInner, ProtectorKind}; use crate::borrow_tracker::{GlobalStateInner, ProtectorKind};

View File

@ -12,9 +12,9 @@
use std::{fmt, mem}; use std::{fmt, mem};
use rustc_abi::Size;
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::abi::Size;
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::borrow_tracker::tree_borrows::Permission; use crate::borrow_tracker::tree_borrows::Permission;

View File

@ -1,5 +1,5 @@
use rustc_abi::Endian;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_target::abi::Endian;
use crate::*; use crate::*;

View File

@ -44,13 +44,13 @@ use std::cell::{Cell, Ref, RefCell, RefMut};
use std::fmt::Debug; use std::fmt::Debug;
use std::mem; use std::mem;
use rustc_abi::{Align, HasDataLayout, Size};
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_index::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::abi::{Align, HasDataLayout, Size};
use super::vector_clock::{VClock, VTimestamp, VectorIdx}; use super::vector_clock::{VClock, VTimestamp, VectorIdx};
use super::weak_memory::EvalContextExt as _; use super::weak_memory::EvalContextExt as _;

View File

@ -4,8 +4,8 @@
use std::ops::{Index, IndexMut, Range}; use std::ops::{Index, IndexMut, Range};
use rustc_abi::Size;
use rustc_const_eval::interpret::AllocRange; use rustc_const_eval::interpret::AllocRange;
use rustc_target::abi::Size;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct Elem<T> { struct Elem<T> {

View File

@ -3,9 +3,9 @@ use std::collections::hash_map::Entry;
use std::ops::Not; use std::ops::Not;
use std::time::Duration; use std::time::Duration;
use rustc_abi::Size;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_index::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_target::abi::Size;
use super::init_once::InitOnce; use super::init_once::InitOnce;
use super::vector_clock::VClock; use super::vector_clock::VClock;

View File

@ -7,6 +7,7 @@ use std::task::Poll;
use std::time::{Duration, SystemTime}; use std::time::{Duration, SystemTime};
use either::Either; use either::Either;
use rustc_abi::ExternAbi;
use rustc_const_eval::CTRL_C_RECEIVED; use rustc_const_eval::CTRL_C_RECEIVED;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
@ -14,7 +15,6 @@ use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::Mutability; use rustc_middle::mir::Mutability;
use rustc_middle::ty::layout::TyAndLayout; use rustc_middle::ty::layout::TyAndLayout;
use rustc_span::Span; use rustc_span::Span;
use rustc_target::spec::abi::Abi;
use crate::concurrency::data_race; use crate::concurrency::data_race;
use crate::shims::tls; use crate::shims::tls;
@ -911,7 +911,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
&mut self, &mut self,
thread: Option<MPlaceTy<'tcx>>, thread: Option<MPlaceTy<'tcx>>,
start_routine: Pointer, start_routine: Pointer,
start_abi: Abi, start_abi: ExternAbi,
func_arg: ImmTy<'tcx>, func_arg: ImmTy<'tcx>,
ret_layout: TyAndLayout<'tcx>, ret_layout: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, ThreadId> { ) -> InterpResult<'tcx, ThreadId> {

View File

@ -1,9 +1,9 @@
use std::fmt::{self, Write}; use std::fmt::{self, Write};
use std::num::NonZero; use std::num::NonZero;
use rustc_abi::{Align, Size};
use rustc_errors::{Diag, DiagMessage, Level}; use rustc_errors::{Diag, DiagMessage, Level};
use rustc_span::{DUMMY_SP, SpanData, Symbol}; use rustc_span::{DUMMY_SP, SpanData, Symbol};
use rustc_target::abi::{Align, Size};
use crate::borrow_tracker::stacked_borrows::diagnostics::TagHistory; use crate::borrow_tracker::stacked_borrows::diagnostics::TagHistory;
use crate::borrow_tracker::tree_borrows::diagnostics as tree_diagnostics; use crate::borrow_tracker::tree_borrows::diagnostics as tree_diagnostics;

View File

@ -6,13 +6,13 @@ use std::path::PathBuf;
use std::task::Poll; use std::task::Poll;
use std::{iter, thread}; use std::{iter, thread};
use rustc_abi::ExternAbi;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_hir::def::Namespace; use rustc_hir::def::Namespace;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::layout::{LayoutCx, LayoutOf}; use rustc_middle::ty::layout::{LayoutCx, LayoutOf};
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_session::config::EntryFnType; use rustc_session::config::EntryFnType;
use rustc_target::spec::abi::Abi;
use crate::concurrency::thread::TlsAllocAction; use crate::concurrency::thread::TlsAllocAction;
use crate::diagnostics::report_leaks; use crate::diagnostics::report_leaks;
@ -391,7 +391,7 @@ pub fn create_ecx<'tcx>(
ecx.call_function( ecx.call_function(
start_instance, start_instance,
Abi::Rust, ExternAbi::Rust,
&[ &[
ImmTy::from_scalar( ImmTy::from_scalar(
Scalar::from_pointer(main_ptr, &ecx), Scalar::from_pointer(main_ptr, &ecx),
@ -409,7 +409,7 @@ pub fn create_ecx<'tcx>(
EntryFnType::Start => { EntryFnType::Start => {
ecx.call_function( ecx.call_function(
entry_instance, entry_instance,
Abi::Rust, ExternAbi::Rust,
&[argc, argv], &[argc, argv],
Some(&ret_place), Some(&ret_place),
StackPopCleanup::Root { cleanup: true }, StackPopCleanup::Root { cleanup: true },

View File

@ -5,6 +5,7 @@ use std::time::Duration;
use std::{cmp, iter}; use std::{cmp, iter};
use rand::RngCore; use rand::RngCore;
use rustc_abi::{Align, ExternAbi, FieldIdx, FieldsShape, Size, Variants};
use rustc_apfloat::Float; use rustc_apfloat::Float;
use rustc_apfloat::ieee::{Double, Half, Quad, Single}; use rustc_apfloat::ieee::{Double, Half, Quad, Single};
use rustc_hir::Safety; use rustc_hir::Safety;
@ -18,8 +19,6 @@ use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy}; use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy};
use rustc_session::config::CrateType; use rustc_session::config::CrateType;
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use rustc_target::abi::{Align, FieldIdx, FieldsShape, Size, Variants};
use rustc_target::spec::abi::Abi;
use crate::*; use crate::*;
@ -435,7 +434,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn call_function( fn call_function(
&mut self, &mut self,
f: ty::Instance<'tcx>, f: ty::Instance<'tcx>,
caller_abi: Abi, caller_abi: ExternAbi,
args: &[ImmTy<'tcx>], args: &[ImmTy<'tcx>],
dest: Option<&MPlaceTy<'tcx>>, dest: Option<&MPlaceTy<'tcx>>,
stack_pop: StackPopCleanup, stack_pop: StackPopCleanup,
@ -917,7 +916,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
/// Check that the ABI is what we expect. /// Check that the ABI is what we expect.
fn check_abi<'a>(&self, abi: Abi, exp_abi: Abi) -> InterpResult<'a, ()> { fn check_abi<'a>(&self, abi: ExternAbi, exp_abi: ExternAbi) -> InterpResult<'a, ()> {
if abi != exp_abi { if abi != exp_abi {
throw_ub_format!( throw_ub_format!(
"calling a function with ABI {} using caller ABI {}", "calling a function with ABI {} using caller ABI {}",
@ -953,8 +952,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn check_abi_and_shim_symbol_clash( fn check_abi_and_shim_symbol_clash(
&mut self, &mut self,
abi: Abi, abi: ExternAbi,
exp_abi: Abi, exp_abi: ExternAbi,
link_name: Symbol, link_name: Symbol,
) -> InterpResult<'tcx, ()> { ) -> InterpResult<'tcx, ()> {
self.check_abi(abi, exp_abi)?; self.check_abi(abi, exp_abi)?;
@ -978,8 +977,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn check_shim<'a, const N: usize>( fn check_shim<'a, const N: usize>(
&mut self, &mut self,
abi: Abi, abi: ExternAbi,
exp_abi: Abi, exp_abi: ExternAbi,
link_name: Symbol, link_name: Symbol,
args: &'a [OpTy<'tcx>], args: &'a [OpTy<'tcx>],
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]> ) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]>

View File

@ -4,11 +4,11 @@ mod atomic;
mod simd; mod simd;
use rand::Rng; use rand::Rng;
use rustc_abi::Size;
use rustc_apfloat::{Float, Round}; use rustc_apfloat::{Float, Round};
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::{self, FloatTy}; use rustc_middle::ty::{self, FloatTy};
use rustc_span::{Symbol, sym}; use rustc_span::{Symbol, sym};
use rustc_target::abi::Size;
use self::atomic::EvalContextExt as _; use self::atomic::EvalContextExt as _;
use self::helpers::{ToHost, ToSoft, check_arg_count}; use self::helpers::{ToHost, ToSoft, check_arg_count};

View File

@ -1,10 +1,10 @@
use either::Either; use either::Either;
use rustc_abi::{Endian, HasDataLayout};
use rustc_apfloat::{Float, Round}; use rustc_apfloat::{Float, Round};
use rustc_middle::ty::FloatTy; use rustc_middle::ty::FloatTy;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::{mir, ty}; use rustc_middle::{mir, ty};
use rustc_span::{Symbol, sym}; use rustc_span::{Symbol, sym};
use rustc_target::abi::{Endian, HasDataLayout};
use crate::helpers::{ToHost, ToSoft, bool_to_simd_element, check_arg_count, simd_element_to_bool}; use crate::helpers::{ToHost, ToSoft, bool_to_simd_element, check_arg_count, simd_element_to_bool};
use crate::*; use crate::*;

View File

@ -10,6 +10,7 @@ use std::{fmt, process};
use rand::rngs::StdRng; use rand::rngs::StdRng;
use rand::{Rng, SeedableRng}; use rand::{Rng, SeedableRng};
use rustc_abi::{Align, ExternAbi, Size};
use rustc_attr::InlineAttr; use rustc_attr::InlineAttr;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
#[allow(unused)] #[allow(unused)]
@ -21,8 +22,6 @@ use rustc_middle::ty::{self, Instance, Ty, TyCtxt};
use rustc_session::config::InliningThreshold; use rustc_session::config::InliningThreshold;
use rustc_span::def_id::{CrateNum, DefId}; use rustc_span::def_id::{CrateNum, DefId};
use rustc_span::{Span, SpanData, Symbol}; use rustc_span::{Span, SpanData, Symbol};
use rustc_target::abi::{Align, Size};
use rustc_target::spec::abi::Abi;
use crate::concurrency::cpu_affinity::{self, CpuAffinityMask}; use crate::concurrency::cpu_affinity::{self, CpuAffinityMask};
use crate::concurrency::data_race::{self, NaReadType, NaWriteType}; use crate::concurrency::data_race::{self, NaReadType, NaWriteType};
@ -1006,7 +1005,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
fn find_mir_or_eval_fn( fn find_mir_or_eval_fn(
ecx: &mut MiriInterpCx<'tcx>, ecx: &mut MiriInterpCx<'tcx>,
instance: ty::Instance<'tcx>, instance: ty::Instance<'tcx>,
abi: Abi, abi: ExternAbi,
args: &[FnArg<'tcx, Provenance>], args: &[FnArg<'tcx, Provenance>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>, ret: Option<mir::BasicBlock>,
@ -1033,7 +1032,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
fn call_extra_fn( fn call_extra_fn(
ecx: &mut MiriInterpCx<'tcx>, ecx: &mut MiriInterpCx<'tcx>,
fn_val: DynSym, fn_val: DynSym,
abi: Abi, abi: ExternAbi,
args: &[FnArg<'tcx, Provenance>], args: &[FnArg<'tcx, Provenance>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>, ret: Option<mir::BasicBlock>,
@ -1075,7 +1074,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
// Call the lang item. // Call the lang item.
let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap(); let panic = ecx.tcx.lang_items().get(reason.lang_item()).unwrap();
let panic = ty::Instance::mono(ecx.tcx.tcx, panic); let panic = ty::Instance::mono(ecx.tcx.tcx, panic);
ecx.call_function(panic, Abi::Rust, &[], None, StackPopCleanup::Goto { ecx.call_function(panic, ExternAbi::Rust, &[], None, StackPopCleanup::Goto {
ret: None, ret: None,
unwind: mir::UnwindAction::Unreachable, unwind: mir::UnwindAction::Unreachable,
})?; })?;

View File

@ -2,9 +2,9 @@ use std::iter;
use rand::Rng; use rand::Rng;
use rand::seq::IteratorRandom; use rand::seq::IteratorRandom;
use rustc_abi::Size;
use rustc_apfloat::{Float, FloatConvert}; use rustc_apfloat::{Float, FloatConvert};
use rustc_middle::mir; use rustc_middle::mir;
use rustc_target::abi::Size;
use crate::*; use crate::*;

View File

@ -7,7 +7,7 @@
use std::ops; use std::ops;
use rustc_target::abi::Size; use rustc_abi::Size;
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
struct Elem<T> { struct Elem<T> {

View File

@ -1,7 +1,7 @@
use std::iter; use std::iter;
use rustc_abi::{Align, Size};
use rustc_ast::expand::allocator::AllocatorKind; use rustc_ast::expand::allocator::AllocatorKind;
use rustc_target::abi::{Align, Size};
use crate::*; use crate::*;

View File

@ -1,9 +1,8 @@
use rustc_abi::{ExternAbi, Size};
use rustc_ast::ast::Mutability; use rustc_ast::ast::Mutability;
use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::layout::LayoutOf as _;
use rustc_middle::ty::{self, Instance, Ty}; use rustc_middle::ty::{self, Instance, Ty};
use rustc_span::{BytePos, Loc, Symbol, hygiene}; use rustc_span::{BytePos, Loc, Symbol, hygiene};
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use crate::helpers::check_min_arg_count; use crate::helpers::check_min_arg_count;
use crate::*; use crate::*;
@ -12,13 +11,13 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn handle_miri_backtrace_size( fn handle_miri_backtrace_size(
&mut self, &mut self,
abi: Abi, abi: ExternAbi,
link_name: Symbol, link_name: Symbol,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
let [flags] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let flags = this.read_scalar(flags)?.to_u64()?; let flags = this.read_scalar(flags)?.to_u64()?;
if flags != 0 { if flags != 0 {
@ -32,7 +31,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn handle_miri_get_backtrace( fn handle_miri_get_backtrace(
&mut self, &mut self,
abi: Abi, abi: ExternAbi,
link_name: Symbol, link_name: Symbol,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
@ -73,7 +72,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// storage for pointers is allocated by miri // storage for pointers is allocated by miri
// deallocating the slice is undefined behavior with a custom global allocator // deallocating the slice is undefined behavior with a custom global allocator
0 => { 0 => {
let [_flags] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [_flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let alloc = this.allocate(array_layout, MiriMemoryKind::Rust.into())?; let alloc = this.allocate(array_layout, MiriMemoryKind::Rust.into())?;
@ -88,7 +87,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
// storage for pointers is allocated by the caller // storage for pointers is allocated by the caller
1 => { 1 => {
let [_flags, buf] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [_flags, buf] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let buf_place = this.deref_pointer(buf)?; let buf_place = this.deref_pointer(buf)?;
@ -138,13 +137,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn handle_miri_resolve_frame( fn handle_miri_resolve_frame(
&mut self, &mut self,
abi: Abi, abi: ExternAbi,
link_name: Symbol, link_name: Symbol,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
let [ptr, flags] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [ptr, flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let flags = this.read_scalar(flags)?.to_u64()?; let flags = this.read_scalar(flags)?.to_u64()?;
@ -216,14 +215,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn handle_miri_resolve_frame_names( fn handle_miri_resolve_frame_names(
&mut self, &mut self,
abi: Abi, abi: ExternAbi,
link_name: Symbol, link_name: Symbol,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
let this = self.eval_context_mut(); let this = self.eval_context_mut();
let [ptr, flags, name_ptr, filename_ptr] = let [ptr, flags, name_ptr, filename_ptr] =
this.check_shim(abi, Abi::Rust, link_name, args)?; this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let flags = this.read_scalar(flags)?.to_u64()?; let flags = this.read_scalar(flags)?.to_u64()?;
if flags != 0 { if flags != 0 {

View File

@ -3,6 +3,7 @@ use std::io::Write;
use std::iter; use std::iter;
use std::path::Path; use std::path::Path;
use rustc_abi::{Align, AlignFromBytesError, ExternAbi, Size};
use rustc_apfloat::Float; use rustc_apfloat::Float;
use rustc_ast::expand::allocator::alloc_error_handler_name; use rustc_ast::expand::allocator::alloc_error_handler_name;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
@ -10,8 +11,6 @@ use rustc_hir::def_id::CrateNum;
use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags; use rustc_middle::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use rustc_middle::{mir, ty}; use rustc_middle::{mir, ty};
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::abi::{Align, AlignFromBytesError, Size};
use rustc_target::spec::abi::Abi;
use self::helpers::{ToHost, ToSoft}; use self::helpers::{ToHost, ToSoft};
use super::alloc::EvalContextExt as _; use super::alloc::EvalContextExt as _;
@ -40,7 +39,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item( fn emulate_foreign_item(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>, ret: Option<mir::BasicBlock>,
@ -107,7 +106,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_dyn_sym( fn emulate_dyn_sym(
&mut self, &mut self,
sym: DynSym, sym: DynSym,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>, ret: Option<mir::BasicBlock>,
@ -219,7 +218,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -240,7 +239,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// When adding a new shim, you should follow the following pattern: // When adding a new shim, you should follow the following pattern:
// ``` // ```
// "shim_name" => { // "shim_name" => {
// let [arg1, arg2, arg3] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; // let [arg1, arg2, arg3] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// let result = this.shim_name(arg1, arg2, arg3)?; // let result = this.shim_name(arg1, arg2, arg3)?;
// this.write_scalar(result, dest)?; // this.write_scalar(result, dest)?;
// } // }
@ -278,16 +277,16 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
match link_name.as_str() { match link_name.as_str() {
// Miri-specific extern functions // Miri-specific extern functions
"miri_start_unwind" => { "miri_start_unwind" => {
let [payload] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [payload] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
this.handle_miri_start_unwind(payload)?; this.handle_miri_start_unwind(payload)?;
return interp_ok(EmulateItemResult::NeedsUnwind); return interp_ok(EmulateItemResult::NeedsUnwind);
} }
"miri_run_provenance_gc" => { "miri_run_provenance_gc" => {
let [] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
this.run_provenance_gc(); this.run_provenance_gc();
} }
"miri_get_alloc_id" => { "miri_get_alloc_id" => {
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [ptr] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr, 0).map_err_kind(|_e| { let (alloc_id, _, _) = this.ptr_get_alloc_id(ptr, 0).map_err_kind(|_e| {
err_machine_stop!(TerminationInfo::Abort(format!( err_machine_stop!(TerminationInfo::Abort(format!(
@ -297,7 +296,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(Scalar::from_u64(alloc_id.0.get()), dest)?; this.write_scalar(Scalar::from_u64(alloc_id.0.get()), dest)?;
} }
"miri_print_borrow_state" => { "miri_print_borrow_state" => {
let [id, show_unnamed] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [id, show_unnamed] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let id = this.read_scalar(id)?.to_u64()?; let id = this.read_scalar(id)?.to_u64()?;
let show_unnamed = this.read_scalar(show_unnamed)?.to_bool()?; let show_unnamed = this.read_scalar(show_unnamed)?.to_bool()?;
if let Some(id) = std::num::NonZero::new(id).map(AllocId) if let Some(id) = std::num::NonZero::new(id).map(AllocId)
@ -311,7 +310,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
"miri_pointer_name" => { "miri_pointer_name" => {
// This associates a name to a tag. Very useful for debugging, and also makes // This associates a name to a tag. Very useful for debugging, and also makes
// tests more strict. // tests more strict.
let [ptr, nth_parent, name] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [ptr, nth_parent, name] =
this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let nth_parent = this.read_scalar(nth_parent)?.to_u8()?; let nth_parent = this.read_scalar(nth_parent)?.to_u8()?;
let name = this.read_immediate(name)?; let name = this.read_immediate(name)?;
@ -324,7 +324,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.give_pointer_debug_name(ptr, nth_parent, &name)?; this.give_pointer_debug_name(ptr, nth_parent, &name)?;
} }
"miri_static_root" => { "miri_static_root" => {
let [ptr] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [ptr] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let (alloc_id, offset, _) = this.ptr_get_alloc_id(ptr, 0)?; let (alloc_id, offset, _) = this.ptr_get_alloc_id(ptr, 0)?;
if offset != Size::ZERO { if offset != Size::ZERO {
@ -335,7 +335,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.machine.static_roots.push(alloc_id); this.machine.static_roots.push(alloc_id);
} }
"miri_host_to_target_path" => { "miri_host_to_target_path" => {
let [ptr, out, out_size] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [ptr, out, out_size] =
this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let out = this.read_pointer(out)?; let out = this.read_pointer(out)?;
let out_size = this.read_scalar(out_size)?.to_target_usize(this)?; let out_size = this.read_scalar(out_size)?.to_target_usize(this)?;
@ -371,7 +372,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Writes some bytes to the interpreter's stdout/stderr. See the // Writes some bytes to the interpreter's stdout/stderr. See the
// README for details. // README for details.
"miri_write_to_stdout" | "miri_write_to_stderr" => { "miri_write_to_stdout" | "miri_write_to_stderr" => {
let [msg] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [msg] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let msg = this.read_immediate(msg)?; let msg = this.read_immediate(msg)?;
let msg = this.read_byte_slice(&msg)?; let msg = this.read_byte_slice(&msg)?;
// Note: we're ignoring errors writing to host stdout/stderr. // Note: we're ignoring errors writing to host stdout/stderr.
@ -383,9 +384,9 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
// Promises that a pointer has a given symbolic alignment. // Promises that a pointer has a given symbolic alignment.
"miri_promise_symbolic_alignment" => { "miri_promise_symbolic_alignment" => {
use rustc_target::abi::AlignFromBytesError; use rustc_abi::AlignFromBytesError;
let [ptr, align] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [ptr, align] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let align = this.read_target_usize(align)?; let align = this.read_target_usize(align)?;
if !align.is_power_of_two() { if !align.is_power_of_two() {
@ -426,12 +427,13 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Aborting the process. // Aborting the process.
"exit" => { "exit" => {
let [code] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [code] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let code = this.read_scalar(code)?.to_i32()?; let code = this.read_scalar(code)?.to_i32()?;
throw_machine_stop!(TerminationInfo::Exit { code: code.into(), leak_check: false }); throw_machine_stop!(TerminationInfo::Exit { code: code.into(), leak_check: false });
} }
"abort" => { "abort" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
throw_machine_stop!(TerminationInfo::Abort( throw_machine_stop!(TerminationInfo::Abort(
"the program aborted execution".to_owned() "the program aborted execution".to_owned()
)) ))
@ -439,7 +441,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Standard C allocation // Standard C allocation
"malloc" => { "malloc" => {
let [size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [size] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let size = this.read_target_usize(size)?; let size = this.read_target_usize(size)?;
if size <= this.max_size_of_val().bytes() { if size <= this.max_size_of_val().bytes() {
let res = this.malloc(size, /*zero_init:*/ false)?; let res = this.malloc(size, /*zero_init:*/ false)?;
@ -454,7 +457,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"calloc" => { "calloc" => {
let [items, elem_size] = let [items, elem_size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let items = this.read_target_usize(items)?; let items = this.read_target_usize(items)?;
let elem_size = this.read_target_usize(elem_size)?; let elem_size = this.read_target_usize(elem_size)?;
if let Some(size) = this.compute_size_in_bytes(Size::from_bytes(elem_size), items) { if let Some(size) = this.compute_size_in_bytes(Size::from_bytes(elem_size), items) {
@ -469,13 +472,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
} }
"free" => { "free" => {
let [ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [ptr] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
this.free(ptr)?; this.free(ptr)?;
} }
"realloc" => { "realloc" => {
let [old_ptr, new_size] = let [old_ptr, new_size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let old_ptr = this.read_pointer(old_ptr)?; let old_ptr = this.read_pointer(old_ptr)?;
let new_size = this.read_target_usize(new_size)?; let new_size = this.read_target_usize(new_size)?;
if new_size <= this.max_size_of_val().bytes() { if new_size <= this.max_size_of_val().bytes() {
@ -495,7 +499,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
let default = |this: &mut MiriInterpCx<'tcx>| { let default = |this: &mut MiriInterpCx<'tcx>| {
// Only call `check_shim` when `#[global_allocator]` isn't used. When that // Only call `check_shim` when `#[global_allocator]` isn't used. When that
// macro is used, we act like no shim exists, so that the exported function can run. // macro is used, we act like no shim exists, so that the exported function can run.
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [size, align] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let size = this.read_target_usize(size)?; let size = this.read_target_usize(size)?;
let align = this.read_target_usize(align)?; let align = this.read_target_usize(align)?;
@ -529,7 +533,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
return this.emulate_allocator(|this| { return this.emulate_allocator(|this| {
// See the comment for `__rust_alloc` why `check_shim` is only called in the // See the comment for `__rust_alloc` why `check_shim` is only called in the
// default case. // default case.
let [size, align] = this.check_shim(abi, Abi::Rust, link_name, args)?; let [size, align] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let size = this.read_target_usize(size)?; let size = this.read_target_usize(size)?;
let align = this.read_target_usize(align)?; let align = this.read_target_usize(align)?;
@ -555,7 +559,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// See the comment for `__rust_alloc` why `check_shim` is only called in the // See the comment for `__rust_alloc` why `check_shim` is only called in the
// default case. // default case.
let [ptr, old_size, align] = let [ptr, old_size, align] =
this.check_shim(abi, Abi::Rust, link_name, args)?; this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let old_size = this.read_target_usize(old_size)?; let old_size = this.read_target_usize(old_size)?;
let align = this.read_target_usize(align)?; let align = this.read_target_usize(align)?;
@ -590,7 +594,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// See the comment for `__rust_alloc` why `check_shim` is only called in the // See the comment for `__rust_alloc` why `check_shim` is only called in the
// default case. // default case.
let [ptr, old_size, align, new_size] = let [ptr, old_size, align, new_size] =
this.check_shim(abi, Abi::Rust, link_name, args)?; this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let old_size = this.read_target_usize(old_size)?; let old_size = this.read_target_usize(old_size)?;
let align = this.read_target_usize(align)?; let align = this.read_target_usize(align)?;
@ -614,7 +618,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// C memory handling functions // C memory handling functions
"memcmp" => { "memcmp" => {
let [left, right, n] = let [left, right, n] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let left = this.read_pointer(left)?; let left = this.read_pointer(left)?;
let right = this.read_pointer(right)?; let right = this.read_pointer(right)?;
let n = Size::from_bytes(this.read_target_usize(n)?); let n = Size::from_bytes(this.read_target_usize(n)?);
@ -639,7 +643,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"memrchr" => { "memrchr" => {
let [ptr, val, num] = let [ptr, val, num] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let val = this.read_scalar(val)?.to_i32()?; let val = this.read_scalar(val)?.to_i32()?;
let num = this.read_target_usize(num)?; let num = this.read_target_usize(num)?;
@ -666,7 +670,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"memchr" => { "memchr" => {
let [ptr, val, num] = let [ptr, val, num] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let val = this.read_scalar(val)?.to_i32()?; let val = this.read_scalar(val)?.to_i32()?;
let num = this.read_target_usize(num)?; let num = this.read_target_usize(num)?;
@ -689,7 +693,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
} }
"strlen" => { "strlen" => {
let [ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [ptr] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
// This reads at least 1 byte, so we are already enforcing that this is a valid pointer. // This reads at least 1 byte, so we are already enforcing that this is a valid pointer.
let n = this.read_c_str(ptr)?.len(); let n = this.read_c_str(ptr)?.len();
@ -699,7 +704,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
)?; )?;
} }
"wcslen" => { "wcslen" => {
let [ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [ptr] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
// This reads at least 1 byte, so we are already enforcing that this is a valid pointer. // This reads at least 1 byte, so we are already enforcing that this is a valid pointer.
let n = this.read_wchar_t_str(ptr)?.len(); let n = this.read_wchar_t_str(ptr)?.len();
@ -710,7 +716,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"memcpy" => { "memcpy" => {
let [ptr_dest, ptr_src, n] = let [ptr_dest, ptr_src, n] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr_dest = this.read_pointer(ptr_dest)?; let ptr_dest = this.read_pointer(ptr_dest)?;
let ptr_src = this.read_pointer(ptr_src)?; let ptr_src = this.read_pointer(ptr_src)?;
let n = this.read_target_usize(n)?; let n = this.read_target_usize(n)?;
@ -725,7 +731,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"strcpy" => { "strcpy" => {
let [ptr_dest, ptr_src] = let [ptr_dest, ptr_src] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr_dest = this.read_pointer(ptr_dest)?; let ptr_dest = this.read_pointer(ptr_dest)?;
let ptr_src = this.read_pointer(ptr_src)?; let ptr_src = this.read_pointer(ptr_src)?;
@ -754,7 +760,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "expm1f" | "expm1f"
| "tgammaf" | "tgammaf"
=> { => {
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [f] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let f = this.read_scalar(f)?.to_f32()?; let f = this.read_scalar(f)?.to_f32()?;
// Using host floats (but it's fine, these operations do not have guaranteed precision). // Using host floats (but it's fine, these operations do not have guaranteed precision).
let f_host = f.to_host(); let f_host = f.to_host();
@ -782,7 +788,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "atan2f" | "atan2f"
| "fdimf" | "fdimf"
=> { => {
let [f1, f2] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [f1, f2] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let f1 = this.read_scalar(f1)?.to_f32()?; let f1 = this.read_scalar(f1)?.to_f32()?;
let f2 = this.read_scalar(f2)?.to_f32()?; let f2 = this.read_scalar(f2)?.to_f32()?;
// underscore case for windows, here and below // underscore case for windows, here and below
@ -811,7 +817,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "expm1" | "expm1"
| "tgamma" | "tgamma"
=> { => {
let [f] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [f] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let f = this.read_scalar(f)?.to_f64()?; let f = this.read_scalar(f)?.to_f64()?;
// Using host floats (but it's fine, these operations do not have guaranteed precision). // Using host floats (but it's fine, these operations do not have guaranteed precision).
let f_host = f.to_host(); let f_host = f.to_host();
@ -839,7 +845,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "atan2" | "atan2"
| "fdim" | "fdim"
=> { => {
let [f1, f2] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [f1, f2] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let f1 = this.read_scalar(f1)?.to_f64()?; let f1 = this.read_scalar(f1)?.to_f64()?;
let f2 = this.read_scalar(f2)?.to_f64()?; let f2 = this.read_scalar(f2)?.to_f64()?;
// underscore case for windows, here and below // underscore case for windows, here and below
@ -860,7 +866,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "ldexp" | "ldexp"
| "scalbn" | "scalbn"
=> { => {
let [x, exp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [x, exp] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// For radix-2 (binary) systems, `ldexp` and `scalbn` are the same. // For radix-2 (binary) systems, `ldexp` and `scalbn` are the same.
let x = this.read_scalar(x)?.to_f64()?; let x = this.read_scalar(x)?.to_f64()?;
let exp = this.read_scalar(exp)?.to_i32()?; let exp = this.read_scalar(exp)?.to_i32()?;
@ -870,7 +876,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(res, dest)?; this.write_scalar(res, dest)?;
} }
"lgammaf_r" => { "lgammaf_r" => {
let [x, signp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [x, signp] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let x = this.read_scalar(x)?.to_f32()?; let x = this.read_scalar(x)?.to_f32()?;
let signp = this.deref_pointer(signp)?; let signp = this.deref_pointer(signp)?;
@ -881,7 +888,8 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(res, dest)?; this.write_scalar(res, dest)?;
} }
"lgamma_r" => { "lgamma_r" => {
let [x, signp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [x, signp] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let x = this.read_scalar(x)?.to_f64()?; let x = this.read_scalar(x)?.to_f64()?;
let signp = this.deref_pointer(signp)?; let signp = this.deref_pointer(signp)?;
@ -895,7 +903,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// LLVM intrinsics // LLVM intrinsics
"llvm.prefetch" => { "llvm.prefetch" => {
let [p, rw, loc, ty] = let [p, rw, loc, ty] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let _ = this.read_pointer(p)?; let _ = this.read_pointer(p)?;
let rw = this.read_scalar(rw)?.to_i32()?; let rw = this.read_scalar(rw)?.to_i32()?;
@ -922,7 +930,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Used to implement the x86 `_mm{,256,512}_popcnt_epi{8,16,32,64}` and wasm // Used to implement the x86 `_mm{,256,512}_popcnt_epi{8,16,32,64}` and wasm
// `{i,u}8x16_popcnt` functions. // `{i,u}8x16_popcnt` functions.
name if name.starts_with("llvm.ctpop.v") => { name if name.starts_with("llvm.ctpop.v") => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (op, op_len) = this.project_to_simd(op)?; let (op, op_len) = this.project_to_simd(op)?;
let (dest, dest_len) = this.project_to_simd(dest)?; let (dest, dest_len) = this.project_to_simd(dest)?;
@ -953,7 +961,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
// FIXME: Move these to an `arm` submodule. // FIXME: Move these to an `arm` submodule.
"llvm.aarch64.isb" if this.tcx.sess.target.arch == "aarch64" => { "llvm.aarch64.isb" if this.tcx.sess.target.arch == "aarch64" => {
let [arg] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?; let [arg] = this.check_shim(abi, ExternAbi::Unadjusted, link_name, args)?;
let arg = this.read_scalar(arg)?.to_i32()?; let arg = this.read_scalar(arg)?.to_i32()?;
match arg { match arg {
// SY ("full system scope") // SY ("full system scope")
@ -966,7 +974,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
} }
"llvm.arm.hint" if this.tcx.sess.target.arch == "arm" => { "llvm.arm.hint" if this.tcx.sess.target.arch == "arm" => {
let [arg] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?; let [arg] = this.check_shim(abi, ExternAbi::Unadjusted, link_name, args)?;
let arg = this.read_scalar(arg)?.to_i32()?; let arg = this.read_scalar(arg)?.to_i32()?;
// Note that different arguments might have different target feature requirements. // Note that different arguments might have different target feature requirements.
match arg { match arg {

View File

@ -3,9 +3,9 @@ use std::ops::Deref;
use libffi::high::call as ffi; use libffi::high::call as ffi;
use libffi::low::CodePtr; use libffi::low::CodePtr;
use rustc_abi::{BackendRepr, HasDataLayout};
use rustc_middle::ty::{self as ty, IntTy, UintTy}; use rustc_middle::ty::{self as ty, IntTy, UintTy};
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_abi::{BackendRepr, HasDataLayout};
use crate::*; use crate::*;

View File

@ -11,10 +11,10 @@
//! gets popped *during unwinding*, we take the panic payload and store it according to the extra //! gets popped *during unwinding*, we take the panic payload and store it according to the extra
//! metadata we remembered when pushing said frame. //! metadata we remembered when pushing said frame.
use rustc_abi::ExternAbi;
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_middle::{mir, ty}; use rustc_middle::{mir, ty};
use rustc_target::spec::PanicStrategy; use rustc_target::spec::PanicStrategy;
use rustc_target::spec::abi::Abi;
use self::helpers::check_arg_count; use self::helpers::check_arg_count;
use crate::*; use crate::*;
@ -88,7 +88,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
trace!("try_fn: {:?}", f_instance); trace!("try_fn: {:?}", f_instance);
this.call_function( this.call_function(
f_instance, f_instance,
Abi::Rust, ExternAbi::Rust,
&[data.clone()], &[data.clone()],
None, None,
// Directly return to caller. // Directly return to caller.
@ -139,7 +139,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
trace!("catch_fn: {:?}", f_instance); trace!("catch_fn: {:?}", f_instance);
this.call_function( this.call_function(
f_instance, f_instance,
Abi::Rust, ExternAbi::Rust,
&[catch_unwind.data, payload], &[catch_unwind.data, payload],
None, None,
// Directly return to caller of `try`. // Directly return to caller of `try`.
@ -168,7 +168,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let panic = ty::Instance::mono(this.tcx.tcx, panic); let panic = ty::Instance::mono(this.tcx.tcx, panic);
this.call_function( this.call_function(
panic, panic,
Abi::Rust, ExternAbi::Rust,
&[this.mplace_to_ref(&msg)?], &[this.mplace_to_ref(&msg)?],
None, None,
StackPopCleanup::Goto { ret: None, unwind }, StackPopCleanup::Goto { ret: None, unwind },
@ -187,7 +187,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let panic = ty::Instance::mono(this.tcx.tcx, panic); let panic = ty::Instance::mono(this.tcx.tcx, panic);
this.call_function( this.call_function(
panic, panic,
Abi::Rust, ExternAbi::Rust,
&[this.mplace_to_ref(&msg)?], &[this.mplace_to_ref(&msg)?],
None, None,
StackPopCleanup::Goto { ret: None, unwind: mir::UnwindAction::Unreachable }, StackPopCleanup::Goto { ret: None, unwind: mir::UnwindAction::Unreachable },
@ -216,7 +216,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
let panic_bounds_check = ty::Instance::mono(this.tcx.tcx, panic_bounds_check); let panic_bounds_check = ty::Instance::mono(this.tcx.tcx, panic_bounds_check);
this.call_function( this.call_function(
panic_bounds_check, panic_bounds_check,
Abi::Rust, ExternAbi::Rust,
&[index, len], &[index, len],
None, None,
StackPopCleanup::Goto { ret: None, unwind }, StackPopCleanup::Goto { ret: None, unwind },
@ -237,7 +237,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
ty::Instance::mono(this.tcx.tcx, panic_misaligned_pointer_dereference); ty::Instance::mono(this.tcx.tcx, panic_misaligned_pointer_dereference);
this.call_function( this.call_function(
panic_misaligned_pointer_dereference, panic_misaligned_pointer_dereference,
Abi::Rust, ExternAbi::Rust,
&[required, found], &[required, found],
None, None,
StackPopCleanup::Goto { ret: None, unwind }, StackPopCleanup::Goto { ret: None, unwind },
@ -248,7 +248,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Call the lang item associated with this message. // Call the lang item associated with this message.
let fn_item = this.tcx.require_lang_item(msg.panic_function(), None); let fn_item = this.tcx.require_lang_item(msg.panic_function(), None);
let instance = ty::Instance::mono(this.tcx.tcx, fn_item); let instance = ty::Instance::mono(this.tcx.tcx, fn_item);
this.call_function(instance, Abi::Rust, &[], None, StackPopCleanup::Goto { this.call_function(instance, ExternAbi::Rust, &[], None, StackPopCleanup::Goto {
ret: None, ret: None,
unwind, unwind,
})?; })?;

View File

@ -4,9 +4,8 @@ use std::collections::BTreeMap;
use std::collections::btree_map::Entry as BTreeEntry; use std::collections::btree_map::Entry as BTreeEntry;
use std::task::Poll; use std::task::Poll;
use rustc_abi::{ExternAbi, HasDataLayout, Size};
use rustc_middle::ty; use rustc_middle::ty;
use rustc_target::abi::{HasDataLayout, Size};
use rustc_target::spec::abi::Abi;
use crate::*; use crate::*;
@ -323,7 +322,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// but both are ignored by std. // but both are ignored by std.
this.call_function( this.call_function(
thread_callback, thread_callback,
Abi::System { unwind: false }, ExternAbi::System { unwind: false },
&[null_ptr.clone(), ImmTy::from_scalar(reason, this.machine.layouts.u32), null_ptr], &[null_ptr.clone(), ImmTy::from_scalar(reason, this.machine.layouts.u32), null_ptr],
None, None,
StackPopCleanup::Root { cleanup: true }, StackPopCleanup::Root { cleanup: true },
@ -344,7 +343,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.call_function( this.call_function(
instance, instance,
Abi::C { unwind: false }, ExternAbi::C { unwind: false },
&[ImmTy::from_scalar(data, this.machine.layouts.mut_raw_ptr)], &[ImmTy::from_scalar(data, this.machine.layouts.mut_raw_ptr)],
None, None,
StackPopCleanup::Root { cleanup: true }, StackPopCleanup::Root { cleanup: true },
@ -381,7 +380,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.call_function( this.call_function(
instance, instance,
Abi::C { unwind: false }, ExternAbi::C { unwind: false },
&[ImmTy::from_scalar(ptr, this.machine.layouts.mut_raw_ptr)], &[ImmTy::from_scalar(ptr, this.machine.layouts.mut_raw_ptr)],
None, None,
StackPopCleanup::Root { cleanup: true }, StackPopCleanup::Root { cleanup: true },

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::shims::unix::android::thread::prctl; use crate::shims::unix::android::thread::prctl;
use crate::*; use crate::*;
@ -13,7 +13,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -21,7 +21,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
match link_name.as_str() { match link_name.as_str() {
// Miscellaneous // Miscellaneous
"__errno" => { "__errno" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let errno_place = this.last_error_place()?; let errno_place = this.last_error_place()?;
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?; this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
} }

View File

@ -1,6 +1,5 @@
use rustc_abi::{ExternAbi, Size};
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use crate::helpers::check_min_arg_count; use crate::helpers::check_min_arg_count;
use crate::shims::unix::thread::EvalContextExt as _; use crate::shims::unix::thread::EvalContextExt as _;
@ -11,13 +10,13 @@ const TASK_COMM_LEN: usize = 16;
pub fn prctl<'tcx>( pub fn prctl<'tcx>(
this: &mut MiriInterpCx<'tcx>, this: &mut MiriInterpCx<'tcx>,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx> { ) -> InterpResult<'tcx> {
// We do not use `check_shim` here because `prctl` is variadic. The argument // We do not use `check_shim` here because `prctl` is variadic. The argument
// count is checked bellow. // count is checked bellow.
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?; this.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?;
// FIXME: Use constants once https://github.com/rust-lang/libc/pull/3941 backported to the 0.2 branch. // FIXME: Use constants once https://github.com/rust-lang/libc/pull/3941 backported to the 0.2 branch.
let pr_set_name = 15; let pr_set_name = 15;

View File

@ -2,10 +2,10 @@ use std::ffi::{OsStr, OsString};
use std::io::ErrorKind; use std::io::ErrorKind;
use std::{env, mem}; use std::{env, mem};
use rustc_abi::Size;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_target::abi::Size;
use crate::*; use crate::*;

View File

@ -7,7 +7,7 @@ use std::io::{self, ErrorKind, IsTerminal, Read, SeekFrom, Write};
use std::ops::Deref; use std::ops::Deref;
use std::rc::{Rc, Weak}; use std::rc::{Rc, Weak};
use rustc_target::abi::Size; use rustc_abi::Size;
use crate::helpers::check_min_arg_count; use crate::helpers::check_min_arg_count;
use crate::shims::unix::linux::epoll::EpollReadyEvents; use crate::shims::unix::linux::epoll::EpollReadyEvents;

View File

@ -1,10 +1,9 @@
use std::ffi::OsStr; use std::ffi::OsStr;
use std::str; use std::str;
use rustc_abi::{ExternAbi, Size};
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use self::shims::unix::android::foreign_items as android; use self::shims::unix::android::foreign_items as android;
use self::shims::unix::freebsd::foreign_items as freebsd; use self::shims::unix::freebsd::foreign_items as freebsd;
@ -43,7 +42,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -54,47 +53,47 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
match link_name.as_str() { match link_name.as_str() {
// Environment related shims // Environment related shims
"getenv" => { "getenv" => {
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [name] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.getenv(name)?; let result = this.getenv(name)?;
this.write_pointer(result, dest)?; this.write_pointer(result, dest)?;
} }
"unsetenv" => { "unsetenv" => {
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [name] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.unsetenv(name)?; let result = this.unsetenv(name)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"setenv" => { "setenv" => {
let [name, value, overwrite] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [name, value, overwrite] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.read_scalar(overwrite)?.to_i32()?; this.read_scalar(overwrite)?.to_i32()?;
let result = this.setenv(name, value)?; let result = this.setenv(name, value)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"getcwd" => { "getcwd" => {
let [buf, size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [buf, size] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.getcwd(buf, size)?; let result = this.getcwd(buf, size)?;
this.write_pointer(result, dest)?; this.write_pointer(result, dest)?;
} }
"chdir" => { "chdir" => {
let [path] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [path] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.chdir(path)?; let result = this.chdir(path)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"getpid" => { "getpid" => {
let [] = this.check_shim(abi, Abi::C { unwind: false}, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false}, link_name, args)?;
let result = this.getpid()?; let result = this.getpid()?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
// File descriptors // File descriptors
"read" => { "read" => {
let [fd, buf, count] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf, count] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let count = this.read_target_usize(count)?; let count = this.read_target_usize(count)?;
this.read(fd, buf, count, None, dest)?; this.read(fd, buf, count, None, dest)?;
} }
"write" => { "write" => {
let [fd, buf, n] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf, n] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let count = this.read_target_usize(n)?; let count = this.read_target_usize(n)?;
@ -102,7 +101,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write(fd, buf, count, None, dest)?; this.write(fd, buf, count, None, dest)?;
} }
"pread" => { "pread" => {
let [fd, buf, count, offset] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf, count, offset] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let count = this.read_target_usize(count)?; let count = this.read_target_usize(count)?;
@ -110,7 +109,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.read(fd, buf, count, Some(offset), dest)?; this.read(fd, buf, count, Some(offset), dest)?;
} }
"pwrite" => { "pwrite" => {
let [fd, buf, n, offset] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf, n, offset] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let count = this.read_target_usize(n)?; let count = this.read_target_usize(n)?;
@ -119,7 +118,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write(fd, buf, count, Some(offset), dest)?; this.write(fd, buf, count, Some(offset), dest)?;
} }
"pread64" => { "pread64" => {
let [fd, buf, count, offset] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf, count, offset] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let count = this.read_target_usize(count)?; let count = this.read_target_usize(count)?;
@ -127,7 +126,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.read(fd, buf, count, Some(offset), dest)?; this.read(fd, buf, count, Some(offset), dest)?;
} }
"pwrite64" => { "pwrite64" => {
let [fd, buf, n, offset] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf, n, offset] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let count = this.read_target_usize(n)?; let count = this.read_target_usize(n)?;
@ -136,32 +135,32 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write(fd, buf, count, Some(offset), dest)?; this.write(fd, buf, count, Some(offset), dest)?;
} }
"close" => { "close" => {
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.close(fd)?; let result = this.close(fd)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"fcntl" => { "fcntl" => {
// `fcntl` is variadic. The argument count is checked based on the first argument // `fcntl` is variadic. The argument count is checked based on the first argument
// in `this.fcntl()`, so we do not use `check_shim` here. // in `this.fcntl()`, so we do not use `check_shim` here.
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?; this.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?;
let result = this.fcntl(args)?; let result = this.fcntl(args)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"dup" => { "dup" => {
let [old_fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [old_fd] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let old_fd = this.read_scalar(old_fd)?.to_i32()?; let old_fd = this.read_scalar(old_fd)?.to_i32()?;
let new_fd = this.dup(old_fd)?; let new_fd = this.dup(old_fd)?;
this.write_scalar(new_fd, dest)?; this.write_scalar(new_fd, dest)?;
} }
"dup2" => { "dup2" => {
let [old_fd, new_fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [old_fd, new_fd] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let old_fd = this.read_scalar(old_fd)?.to_i32()?; let old_fd = this.read_scalar(old_fd)?.to_i32()?;
let new_fd = this.read_scalar(new_fd)?.to_i32()?; let new_fd = this.read_scalar(new_fd)?.to_i32()?;
let result = this.dup2(old_fd, new_fd)?; let result = this.dup2(old_fd, new_fd)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"flock" => { "flock" => {
let [fd, op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let op = this.read_scalar(op)?.to_i32()?; let op = this.read_scalar(op)?.to_i32()?;
let result = this.flock(fd, op)?; let result = this.flock(fd, op)?;
@ -171,47 +170,47 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// File and file system access // File and file system access
"open" | "open64" => { "open" | "open64" => {
// `open` is variadic, the third argument is only present when the second argument has O_CREAT (or on linux O_TMPFILE, but miri doesn't support that) set // `open` is variadic, the third argument is only present when the second argument has O_CREAT (or on linux O_TMPFILE, but miri doesn't support that) set
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?; this.check_abi_and_shim_symbol_clash(abi, ExternAbi::C { unwind: false }, link_name)?;
let result = this.open(args)?; let result = this.open(args)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"unlink" => { "unlink" => {
let [path] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [path] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.unlink(path)?; let result = this.unlink(path)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"symlink" => { "symlink" => {
let [target, linkpath] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [target, linkpath] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.symlink(target, linkpath)?; let result = this.symlink(target, linkpath)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"rename" => { "rename" => {
let [oldpath, newpath] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [oldpath, newpath] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.rename(oldpath, newpath)?; let result = this.rename(oldpath, newpath)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"mkdir" => { "mkdir" => {
let [path, mode] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [path, mode] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.mkdir(path, mode)?; let result = this.mkdir(path, mode)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"rmdir" => { "rmdir" => {
let [path] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [path] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.rmdir(path)?; let result = this.rmdir(path)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"opendir" => { "opendir" => {
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [name] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.opendir(name)?; let result = this.opendir(name)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"closedir" => { "closedir" => {
let [dirp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [dirp] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.closedir(dirp)?; let result = this.closedir(dirp)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"lseek64" => { "lseek64" => {
let [fd, offset, whence] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, offset, whence] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let offset = this.read_scalar(offset)?.to_i64()?; let offset = this.read_scalar(offset)?.to_i64()?;
let whence = this.read_scalar(whence)?.to_i32()?; let whence = this.read_scalar(whence)?.to_i32()?;
@ -219,7 +218,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"lseek" => { "lseek" => {
let [fd, offset, whence] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, offset, whence] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let offset = this.read_scalar(offset)?.to_int(this.libc_ty_layout("off_t").size)?; let offset = this.read_scalar(offset)?.to_int(this.libc_ty_layout("off_t").size)?;
let whence = this.read_scalar(whence)?.to_i32()?; let whence = this.read_scalar(whence)?.to_i32()?;
@ -228,7 +227,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"ftruncate64" => { "ftruncate64" => {
let [fd, length] = let [fd, length] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let length = this.read_scalar(length)?.to_i64()?; let length = this.read_scalar(length)?.to_i64()?;
let result = this.ftruncate64(fd, length.into())?; let result = this.ftruncate64(fd, length.into())?;
@ -236,30 +235,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"ftruncate" => { "ftruncate" => {
let [fd, length] = let [fd, length] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let fd = this.read_scalar(fd)?.to_i32()?; let fd = this.read_scalar(fd)?.to_i32()?;
let length = this.read_scalar(length)?.to_int(this.libc_ty_layout("off_t").size)?; let length = this.read_scalar(length)?.to_int(this.libc_ty_layout("off_t").size)?;
let result = this.ftruncate64(fd, length)?; let result = this.ftruncate64(fd, length)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"fsync" => { "fsync" => {
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.fsync(fd)?; let result = this.fsync(fd)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"fdatasync" => { "fdatasync" => {
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.fdatasync(fd)?; let result = this.fdatasync(fd)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"readlink" => { "readlink" => {
let [pathname, buf, bufsize] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [pathname, buf, bufsize] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.readlink(pathname, buf, bufsize)?; let result = this.readlink(pathname, buf, bufsize)?;
this.write_scalar(Scalar::from_target_isize(result, this), dest)?; this.write_scalar(Scalar::from_target_isize(result, this), dest)?;
} }
"posix_fadvise" => { "posix_fadvise" => {
let [fd, offset, len, advice] = let [fd, offset, len, advice] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.read_scalar(fd)?.to_i32()?; this.read_scalar(fd)?.to_i32()?;
this.read_target_isize(offset)?; this.read_target_isize(offset)?;
this.read_target_isize(len)?; this.read_target_isize(len)?;
@ -268,12 +267,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_null(dest)?; this.write_null(dest)?;
} }
"realpath" => { "realpath" => {
let [path, resolved_path] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [path, resolved_path] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.realpath(path, resolved_path)?; let result = this.realpath(path, resolved_path)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"mkstemp" => { "mkstemp" => {
let [template] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [template] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.mkstemp(template)?; let result = this.mkstemp(template)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
@ -281,13 +280,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Unnamed sockets and pipes // Unnamed sockets and pipes
"socketpair" => { "socketpair" => {
let [domain, type_, protocol, sv] = let [domain, type_, protocol, sv] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.socketpair(domain, type_, protocol, sv)?; let result = this.socketpair(domain, type_, protocol, sv)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pipe" => { "pipe" => {
let [pipefd] = let [pipefd] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pipe2(pipefd, /*flags*/ None)?; let result = this.pipe2(pipefd, /*flags*/ None)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
@ -300,44 +299,44 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
); );
} }
let [pipefd, flags] = let [pipefd, flags] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pipe2(pipefd, Some(flags))?; let result = this.pipe2(pipefd, Some(flags))?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
// Time // Time
"gettimeofday" => { "gettimeofday" => {
let [tv, tz] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [tv, tz] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.gettimeofday(tv, tz)?; let result = this.gettimeofday(tv, tz)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"localtime_r" => { "localtime_r" => {
let [timep, result_op] = this.check_shim(abi, Abi::C {unwind: false}, link_name, args)?; let [timep, result_op] = this.check_shim(abi, ExternAbi::C {unwind: false}, link_name, args)?;
let result = this.localtime_r(timep, result_op)?; let result = this.localtime_r(timep, result_op)?;
this.write_pointer(result, dest)?; this.write_pointer(result, dest)?;
} }
"clock_gettime" => { "clock_gettime" => {
let [clk_id, tp] = let [clk_id, tp] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.clock_gettime(clk_id, tp)?; let result = this.clock_gettime(clk_id, tp)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
// Allocation // Allocation
"posix_memalign" => { "posix_memalign" => {
let [memptr, align, size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [memptr, align, size] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.posix_memalign(memptr, align, size)?; let result = this.posix_memalign(memptr, align, size)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"mmap" => { "mmap" => {
let [addr, length, prot, flags, fd, offset] = this.check_shim(abi, Abi::C {unwind: false}, link_name, args)?; let [addr, length, prot, flags, fd, offset] = this.check_shim(abi, ExternAbi::C {unwind: false}, link_name, args)?;
let offset = this.read_scalar(offset)?.to_int(this.libc_ty_layout("off_t").size)?; let offset = this.read_scalar(offset)?.to_int(this.libc_ty_layout("off_t").size)?;
let ptr = this.mmap(addr, length, prot, flags, fd, offset)?; let ptr = this.mmap(addr, length, prot, flags, fd, offset)?;
this.write_scalar(ptr, dest)?; this.write_scalar(ptr, dest)?;
} }
"munmap" => { "munmap" => {
let [addr, length] = this.check_shim(abi, Abi::C {unwind: false}, link_name, args)?; let [addr, length] = this.check_shim(abi, ExternAbi::C {unwind: false}, link_name, args)?;
let result = this.munmap(addr, length)?; let result = this.munmap(addr, length)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
@ -351,7 +350,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
); );
} }
let [ptr, nmemb, size] = let [ptr, nmemb, size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let nmemb = this.read_target_usize(nmemb)?; let nmemb = this.read_target_usize(nmemb)?;
let size = this.read_target_usize(size)?; let size = this.read_target_usize(size)?;
@ -375,14 +374,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// This is a C11 function, we assume all Unixes have it. // This is a C11 function, we assume all Unixes have it.
// (MSVC explicitly does not support this.) // (MSVC explicitly does not support this.)
let [align, size] = let [align, size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let res = this.aligned_alloc(align, size)?; let res = this.aligned_alloc(align, size)?;
this.write_pointer(res, dest)?; this.write_pointer(res, dest)?;
} }
// Dynamic symbol loading // Dynamic symbol loading
"dlsym" => { "dlsym" => {
let [handle, symbol] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [handle, symbol] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.read_target_usize(handle)?; this.read_target_usize(handle)?;
let symbol = this.read_pointer(symbol)?; let symbol = this.read_pointer(symbol)?;
let name = this.read_c_str(symbol)?; let name = this.read_c_str(symbol)?;
@ -396,7 +395,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Querying system information // Querying system information
"sysconf" => { "sysconf" => {
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [name] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let name = this.read_scalar(name)?.to_i32()?; let name = this.read_scalar(name)?.to_i32()?;
// FIXME: Which of these are POSIX, and which are GNU/Linux? // FIXME: Which of these are POSIX, and which are GNU/Linux?
// At least the names seem to all also exist on macOS. // At least the names seem to all also exist on macOS.
@ -425,7 +424,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Thread-local storage // Thread-local storage
"pthread_key_create" => { "pthread_key_create" => {
let [key, dtor] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [key, dtor] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let key_place = this.deref_pointer_as(key, this.libc_ty_layout("pthread_key_t"))?; let key_place = this.deref_pointer_as(key, this.libc_ty_layout("pthread_key_t"))?;
let dtor = this.read_pointer(dtor)?; let dtor = this.read_pointer(dtor)?;
@ -453,21 +452,21 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_key_delete" => { "pthread_key_delete" => {
let [key] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [key] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let key = this.read_scalar(key)?.to_bits(key.layout.size)?; let key = this.read_scalar(key)?.to_bits(key.layout.size)?;
this.machine.tls.delete_tls_key(key)?; this.machine.tls.delete_tls_key(key)?;
// Return success (0) // Return success (0)
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_getspecific" => { "pthread_getspecific" => {
let [key] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [key] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let key = this.read_scalar(key)?.to_bits(key.layout.size)?; let key = this.read_scalar(key)?.to_bits(key.layout.size)?;
let active_thread = this.active_thread(); let active_thread = this.active_thread();
let ptr = this.machine.tls.load_tls(key, active_thread, this)?; let ptr = this.machine.tls.load_tls(key, active_thread, this)?;
this.write_scalar(ptr, dest)?; this.write_scalar(ptr, dest)?;
} }
"pthread_setspecific" => { "pthread_setspecific" => {
let [key, new_ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [key, new_ptr] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let key = this.read_scalar(key)?.to_bits(key.layout.size)?; let key = this.read_scalar(key)?.to_bits(key.layout.size)?;
let active_thread = this.active_thread(); let active_thread = this.active_thread();
let new_data = this.read_scalar(new_ptr)?; let new_data = this.read_scalar(new_ptr)?;
@ -479,151 +478,151 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Synchronization primitives // Synchronization primitives
"pthread_mutexattr_init" => { "pthread_mutexattr_init" => {
let [attr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [attr] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_mutexattr_init(attr)?; this.pthread_mutexattr_init(attr)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_mutexattr_settype" => { "pthread_mutexattr_settype" => {
let [attr, kind] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [attr, kind] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pthread_mutexattr_settype(attr, kind)?; let result = this.pthread_mutexattr_settype(attr, kind)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pthread_mutexattr_destroy" => { "pthread_mutexattr_destroy" => {
let [attr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [attr] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_mutexattr_destroy(attr)?; this.pthread_mutexattr_destroy(attr)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_mutex_init" => { "pthread_mutex_init" => {
let [mutex, attr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [mutex, attr] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_mutex_init(mutex, attr)?; this.pthread_mutex_init(mutex, attr)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_mutex_lock" => { "pthread_mutex_lock" => {
let [mutex] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [mutex] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_mutex_lock(mutex, dest)?; this.pthread_mutex_lock(mutex, dest)?;
} }
"pthread_mutex_trylock" => { "pthread_mutex_trylock" => {
let [mutex] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [mutex] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pthread_mutex_trylock(mutex)?; let result = this.pthread_mutex_trylock(mutex)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pthread_mutex_unlock" => { "pthread_mutex_unlock" => {
let [mutex] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [mutex] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pthread_mutex_unlock(mutex)?; let result = this.pthread_mutex_unlock(mutex)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pthread_mutex_destroy" => { "pthread_mutex_destroy" => {
let [mutex] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [mutex] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_mutex_destroy(mutex)?; this.pthread_mutex_destroy(mutex)?;
this.write_int(0, dest)?; this.write_int(0, dest)?;
} }
"pthread_rwlock_rdlock" => { "pthread_rwlock_rdlock" => {
let [rwlock] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [rwlock] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_rwlock_rdlock(rwlock, dest)?; this.pthread_rwlock_rdlock(rwlock, dest)?;
} }
"pthread_rwlock_tryrdlock" => { "pthread_rwlock_tryrdlock" => {
let [rwlock] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [rwlock] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pthread_rwlock_tryrdlock(rwlock)?; let result = this.pthread_rwlock_tryrdlock(rwlock)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pthread_rwlock_wrlock" => { "pthread_rwlock_wrlock" => {
let [rwlock] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [rwlock] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_rwlock_wrlock(rwlock, dest)?; this.pthread_rwlock_wrlock(rwlock, dest)?;
} }
"pthread_rwlock_trywrlock" => { "pthread_rwlock_trywrlock" => {
let [rwlock] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [rwlock] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pthread_rwlock_trywrlock(rwlock)?; let result = this.pthread_rwlock_trywrlock(rwlock)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pthread_rwlock_unlock" => { "pthread_rwlock_unlock" => {
let [rwlock] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [rwlock] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_rwlock_unlock(rwlock)?; this.pthread_rwlock_unlock(rwlock)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_rwlock_destroy" => { "pthread_rwlock_destroy" => {
let [rwlock] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [rwlock] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_rwlock_destroy(rwlock)?; this.pthread_rwlock_destroy(rwlock)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_condattr_init" => { "pthread_condattr_init" => {
let [attr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [attr] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_condattr_init(attr)?; this.pthread_condattr_init(attr)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_condattr_setclock" => { "pthread_condattr_setclock" => {
let [attr, clock_id] = let [attr, clock_id] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.pthread_condattr_setclock(attr, clock_id)?; let result = this.pthread_condattr_setclock(attr, clock_id)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pthread_condattr_getclock" => { "pthread_condattr_getclock" => {
let [attr, clock_id] = let [attr, clock_id] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_condattr_getclock(attr, clock_id)?; this.pthread_condattr_getclock(attr, clock_id)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_condattr_destroy" => { "pthread_condattr_destroy" => {
let [attr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [attr] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_condattr_destroy(attr)?; this.pthread_condattr_destroy(attr)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_cond_init" => { "pthread_cond_init" => {
let [cond, attr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [cond, attr] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_cond_init(cond, attr)?; this.pthread_cond_init(cond, attr)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_cond_signal" => { "pthread_cond_signal" => {
let [cond] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [cond] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_cond_signal(cond)?; this.pthread_cond_signal(cond)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_cond_broadcast" => { "pthread_cond_broadcast" => {
let [cond] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [cond] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_cond_broadcast(cond)?; this.pthread_cond_broadcast(cond)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_cond_wait" => { "pthread_cond_wait" => {
let [cond, mutex] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [cond, mutex] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_cond_wait(cond, mutex, dest)?; this.pthread_cond_wait(cond, mutex, dest)?;
} }
"pthread_cond_timedwait" => { "pthread_cond_timedwait" => {
let [cond, mutex, abstime] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [cond, mutex, abstime] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_cond_timedwait(cond, mutex, abstime, dest)?; this.pthread_cond_timedwait(cond, mutex, abstime, dest)?;
} }
"pthread_cond_destroy" => { "pthread_cond_destroy" => {
let [cond] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [cond] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_cond_destroy(cond)?; this.pthread_cond_destroy(cond)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
// Threading // Threading
"pthread_create" => { "pthread_create" => {
let [thread, attr, start, arg] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [thread, attr, start, arg] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_create(thread, attr, start, arg)?; this.pthread_create(thread, attr, start, arg)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_join" => { "pthread_join" => {
let [thread, retval] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [thread, retval] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_join(thread, retval)?; this.pthread_join(thread, retval)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_detach" => { "pthread_detach" => {
let [thread] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [thread] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.pthread_detach(thread)?; this.pthread_detach(thread)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"pthread_self" => { "pthread_self" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let res = this.pthread_self()?; let res = this.pthread_self()?;
this.write_scalar(res, dest)?; this.write_scalar(res, dest)?;
} }
"sched_yield" => { "sched_yield" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.sched_yield()?; this.sched_yield()?;
this.write_null(dest)?; this.write_null(dest)?;
} }
"nanosleep" => { "nanosleep" => {
let [req, rem] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [req, rem] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.nanosleep(req, rem)?; let result = this.nanosleep(req, rem)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
@ -637,7 +636,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
let [pid, cpusetsize, mask] = let [pid, cpusetsize, mask] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let pid = this.read_scalar(pid)?.to_u32()?; let pid = this.read_scalar(pid)?.to_u32()?;
let cpusetsize = this.read_target_usize(cpusetsize)?; let cpusetsize = this.read_target_usize(cpusetsize)?;
let mask = this.read_pointer(mask)?; let mask = this.read_pointer(mask)?;
@ -677,7 +676,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
let [pid, cpusetsize, mask] = let [pid, cpusetsize, mask] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let pid = this.read_scalar(pid)?.to_u32()?; let pid = this.read_scalar(pid)?.to_u32()?;
let cpusetsize = this.read_target_usize(cpusetsize)?; let cpusetsize = this.read_target_usize(cpusetsize)?;
let mask = this.read_pointer(mask)?; let mask = this.read_pointer(mask)?;
@ -713,12 +712,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Miscellaneous // Miscellaneous
"isatty" => { "isatty" => {
let [fd] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.isatty(fd)?; let result = this.isatty(fd)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"pthread_atfork" => { "pthread_atfork" => {
let [prepare, parent, child] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [prepare, parent, child] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.read_pointer(prepare)?; this.read_pointer(prepare)?;
this.read_pointer(parent)?; this.read_pointer(parent)?;
this.read_pointer(child)?; this.read_pointer(child)?;
@ -726,7 +725,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_null(dest)?; this.write_null(dest)?;
} }
"strerror_r" | "__xpg_strerror_r" => { "strerror_r" | "__xpg_strerror_r" => {
let [errnum, buf, buflen] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [errnum, buf, buflen] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let errnum = this.read_scalar(errnum)?; let errnum = this.read_scalar(errnum)?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let buflen = this.read_target_usize(buflen)?; let buflen = this.read_target_usize(buflen)?;
@ -751,7 +750,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
let [buf, bufsize] = let [buf, bufsize] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let bufsize = this.read_target_usize(bufsize)?; let bufsize = this.read_target_usize(bufsize)?;
@ -777,7 +776,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
); );
} }
let [ptr, len, flags] = let [ptr, len, flags] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let len = this.read_target_usize(len)?; let len = this.read_target_usize(len)?;
let _flags = this.read_scalar(flags)?.to_i32()?; let _flags = this.read_scalar(flags)?.to_i32()?;
@ -794,7 +793,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.tcx.sess.target.os this.tcx.sess.target.os
); );
} }
let [ptr, len] = this.check_shim(abi, Abi::C { unwind: false}, link_name, args)?; let [ptr, len] = this.check_shim(abi, ExternAbi::C { unwind: false}, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let len = this.read_target_usize(len)?; let len = this.read_target_usize(len)?;
this.gen_random(ptr, len)?; this.gen_random(ptr, len)?;
@ -820,12 +819,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
); );
} }
// This function looks and behaves excatly like miri_start_unwind. // This function looks and behaves excatly like miri_start_unwind.
let [payload] = this.check_shim(abi, Abi::C { unwind: true }, link_name, args)?; let [payload] = this.check_shim(abi, ExternAbi::C { unwind: true }, link_name, args)?;
this.handle_miri_start_unwind(payload)?; this.handle_miri_start_unwind(payload)?;
return interp_ok(EmulateItemResult::NeedsUnwind); return interp_ok(EmulateItemResult::NeedsUnwind);
} }
"getuid" => { "getuid" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// For now, just pretend we always have this fixed UID. // For now, just pretend we always have this fixed UID.
this.write_int(UID, dest)?; this.write_int(UID, dest)?;
} }
@ -834,7 +833,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// These shims are enabled only when the caller is in the standard library. // These shims are enabled only when the caller is in the standard library.
"pthread_attr_getguardsize" "pthread_attr_getguardsize"
if this.frame_in_std() => { if this.frame_in_std() => {
let [_attr, guard_size] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [_attr, guard_size] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let guard_size = this.deref_pointer(guard_size)?; let guard_size = this.deref_pointer(guard_size)?;
let guard_size_layout = this.libc_ty_layout("size_t"); let guard_size_layout = this.libc_ty_layout("size_t");
this.write_scalar(Scalar::from_uint(this.machine.page_size, guard_size_layout.size), &guard_size)?; this.write_scalar(Scalar::from_uint(this.machine.page_size, guard_size_layout.size), &guard_size)?;
@ -846,12 +845,12 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "pthread_attr_init" | "pthread_attr_init"
| "pthread_attr_destroy" | "pthread_attr_destroy"
if this.frame_in_std() => { if this.frame_in_std() => {
let [_] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [_] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
| "pthread_attr_setstacksize" | "pthread_attr_setstacksize"
if this.frame_in_std() => { if this.frame_in_std() => {
let [_, _] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [_, _] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
@ -860,7 +859,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here. // We don't support "pthread_attr_setstack", so we just pretend all stacks have the same values here.
// Hence we can mostly ignore the input `attr_place`. // Hence we can mostly ignore the input `attr_place`.
let [attr_place, addr_place, size_place] = let [attr_place, addr_place, size_place] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let _attr_place = this.deref_pointer_as(attr_place, this.libc_ty_layout("pthread_attr_t"))?; let _attr_place = this.deref_pointer_as(attr_place, this.libc_ty_layout("pthread_attr_t"))?;
let addr_place = this.deref_pointer(addr_place)?; let addr_place = this.deref_pointer(addr_place)?;
let size_place = this.deref_pointer(size_place)?; let size_place = this.deref_pointer(size_place)?;
@ -881,13 +880,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "signal" | "signal"
| "sigaltstack" | "sigaltstack"
if this.frame_in_std() => { if this.frame_in_std() => {
let [_, _] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [_, _] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
| "sigaction" | "sigaction"
| "mprotect" | "mprotect"
if this.frame_in_std() => { if this.frame_in_std() => {
let [_, _, _] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [_, _, _] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_null(dest)?; this.write_null(dest)?;
} }
@ -895,7 +894,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
if this.frame_in_std() => { if this.frame_in_std() => {
// getpwuid_r is the standard name, __posix_getpwuid_r is used on solarish // getpwuid_r is the standard name, __posix_getpwuid_r is used on solarish
let [uid, pwd, buf, buflen, result] = let [uid, pwd, buf, buflen, result] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.check_no_isolation("`getpwuid_r`")?; this.check_no_isolation("`getpwuid_r`")?;
let uid = this.read_scalar(uid)?.to_u32()?; let uid = this.read_scalar(uid)?.to_u32()?;

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::shims::unix::*; use crate::shims::unix::*;
use crate::*; use crate::*;
@ -13,7 +13,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -22,7 +22,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Threading // Threading
"pthread_set_name_np" => { "pthread_set_name_np" => {
let [thread, name] = let [thread, name] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let max_len = usize::MAX; // FreeBSD does not seem to have a limit. let max_len = usize::MAX; // FreeBSD does not seem to have a limit.
// FreeBSD's pthread_set_name_np does not return anything. // FreeBSD's pthread_set_name_np does not return anything.
this.pthread_setname_np( this.pthread_setname_np(
@ -34,7 +34,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"pthread_get_name_np" => { "pthread_get_name_np" => {
let [thread, name, len] = let [thread, name, len] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// FreeBSD's pthread_get_name_np does not return anything // FreeBSD's pthread_get_name_np does not return anything
// and uses strlcpy, which truncates the resulting value, // and uses strlcpy, which truncates the resulting value,
// but always adds a null terminator (except for zero-sized buffers). // but always adds a null terminator (except for zero-sized buffers).
@ -52,31 +52,32 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// since freebsd 12 the former form can be expected. // since freebsd 12 the former form can be expected.
"stat" | "stat@FBSD_1.0" => { "stat" | "stat@FBSD_1.0" => {
let [path, buf] = let [path, buf] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_stat(path, buf)?; let result = this.macos_fbsd_stat(path, buf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"lstat" | "lstat@FBSD_1.0" => { "lstat" | "lstat@FBSD_1.0" => {
let [path, buf] = let [path, buf] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_lstat(path, buf)?; let result = this.macos_fbsd_lstat(path, buf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"fstat" | "fstat@FBSD_1.0" => { "fstat" | "fstat@FBSD_1.0" => {
let [fd, buf] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_fstat(fd, buf)?; let result = this.macos_fbsd_fstat(fd, buf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"readdir_r" | "readdir_r@FBSD_1.0" => { "readdir_r" | "readdir_r@FBSD_1.0" => {
let [dirp, entry, result] = let [dirp, entry, result] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_readdir_r(dirp, entry, result)?; let result = this.macos_fbsd_readdir_r(dirp, entry, result)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
// Miscellaneous // Miscellaneous
"__error" => { "__error" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let errno_place = this.last_error_place()?; let errno_place = this.last_error_place()?;
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?; this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
} }
@ -85,7 +86,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// These shims are enabled only when the caller is in the standard library. // These shims are enabled only when the caller is in the standard library.
"pthread_attr_get_np" if this.frame_in_std() => { "pthread_attr_get_np" if this.frame_in_std() => {
let [_thread, _attr] = let [_thread, _attr] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_null(dest)?; this.write_null(dest)?;
} }

View File

@ -8,8 +8,8 @@ use std::io::{self, ErrorKind, IsTerminal, Read, Seek, SeekFrom, Write};
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::time::SystemTime; use std::time::SystemTime;
use rustc_abi::Size;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_target::abi::Size;
use self::fd::FlockOp; use self::fd::FlockOp;
use self::shims::time::system_time_to_duration; use self::shims::time::system_time_to_duration;

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use self::shims::unix::linux::epoll::EvalContextExt as _; use self::shims::unix::linux::epoll::EvalContextExt as _;
use self::shims::unix::linux::eventfd::EvalContextExt as _; use self::shims::unix::linux::eventfd::EvalContextExt as _;
@ -24,7 +24,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -35,43 +35,45 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
match link_name.as_str() { match link_name.as_str() {
// File related shims // File related shims
"readdir64" => { "readdir64" => {
let [dirp] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [dirp] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.linux_readdir64(dirp)?; let result = this.linux_readdir64(dirp)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"sync_file_range" => { "sync_file_range" => {
let [fd, offset, nbytes, flags] = let [fd, offset, nbytes, flags] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.sync_file_range(fd, offset, nbytes, flags)?; let result = this.sync_file_range(fd, offset, nbytes, flags)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"statx" => { "statx" => {
let [dirfd, pathname, flags, mask, statxbuf] = let [dirfd, pathname, flags, mask, statxbuf] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.linux_statx(dirfd, pathname, flags, mask, statxbuf)?; let result = this.linux_statx(dirfd, pathname, flags, mask, statxbuf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
// epoll, eventfd // epoll, eventfd
"epoll_create1" => { "epoll_create1" => {
let [flag] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [flag] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.epoll_create1(flag)?; let result = this.epoll_create1(flag)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"epoll_ctl" => { "epoll_ctl" => {
let [epfd, op, fd, event] = let [epfd, op, fd, event] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.epoll_ctl(epfd, op, fd, event)?; let result = this.epoll_ctl(epfd, op, fd, event)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"epoll_wait" => { "epoll_wait" => {
let [epfd, events, maxevents, timeout] = let [epfd, events, maxevents, timeout] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.epoll_wait(epfd, events, maxevents, timeout, dest)?; this.epoll_wait(epfd, events, maxevents, timeout, dest)?;
} }
"eventfd" => { "eventfd" => {
let [val, flag] = let [val, flag] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.eventfd(val, flag)?; let result = this.eventfd(val, flag)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
@ -79,7 +81,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Threading // Threading
"pthread_setname_np" => { "pthread_setname_np" => {
let [thread, name] = let [thread, name] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let res = this.pthread_setname_np( let res = this.pthread_setname_np(
this.read_scalar(thread)?, this.read_scalar(thread)?,
this.read_scalar(name)?, this.read_scalar(name)?,
@ -91,7 +93,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"pthread_getname_np" => { "pthread_getname_np" => {
let [thread, name, len] = let [thread, name, len] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// The function's behavior isn't portable between platforms. // The function's behavior isn't portable between platforms.
// In case of glibc, the length of the output buffer must // In case of glibc, the length of the output buffer must
// be not shorter than TASK_COMM_LEN. // be not shorter than TASK_COMM_LEN.
@ -110,7 +112,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_scalar(res, dest)?; this.write_scalar(res, dest)?;
} }
"gettid" => { "gettid" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.linux_gettid()?; let result = this.linux_gettid()?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
@ -119,7 +121,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"syscall" => { "syscall" => {
// We do not use `check_shim` here because `syscall` is variadic. The argument // We do not use `check_shim` here because `syscall` is variadic. The argument
// count is checked bellow. // count is checked bellow.
this.check_abi_and_shim_symbol_clash(abi, Abi::C { unwind: false }, link_name)?; this.check_abi_and_shim_symbol_clash(
abi,
ExternAbi::C { unwind: false },
link_name,
)?;
// The syscall variadic function is legal to call with more arguments than needed, // The syscall variadic function is legal to call with more arguments than needed,
// extra arguments are simply ignored. The important check is that when we use an // extra arguments are simply ignored. The important check is that when we use an
// argument, we have to also check all arguments *before* it to ensure that they // argument, we have to also check all arguments *before* it to ensure that they
@ -169,29 +175,29 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Miscellaneous // Miscellaneous
"mmap64" => { "mmap64" => {
let [addr, length, prot, flags, fd, offset] = let [addr, length, prot, flags, fd, offset] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let offset = this.read_scalar(offset)?.to_i64()?; let offset = this.read_scalar(offset)?.to_i64()?;
let ptr = this.mmap(addr, length, prot, flags, fd, offset.into())?; let ptr = this.mmap(addr, length, prot, flags, fd, offset.into())?;
this.write_scalar(ptr, dest)?; this.write_scalar(ptr, dest)?;
} }
"mremap" => { "mremap" => {
let [old_address, old_size, new_size, flags] = let [old_address, old_size, new_size, flags] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let ptr = this.mremap(old_address, old_size, new_size, flags)?; let ptr = this.mremap(old_address, old_size, new_size, flags)?;
this.write_scalar(ptr, dest)?; this.write_scalar(ptr, dest)?;
} }
"__errno_location" => { "__errno_location" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let errno_place = this.last_error_place()?; let errno_place = this.last_error_place()?;
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?; this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
} }
"__libc_current_sigrtmin" => { "__libc_current_sigrtmin" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_int(SIGRTMIN, dest)?; this.write_int(SIGRTMIN, dest)?;
} }
"__libc_current_sigrtmax" => { "__libc_current_sigrtmax" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_int(SIGRTMAX, dest)?; this.write_int(SIGRTMAX, dest)?;
} }
@ -200,7 +206,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// These shims are enabled only when the caller is in the standard library. // These shims are enabled only when the caller is in the standard library.
"pthread_getattr_np" if this.frame_in_std() => { "pthread_getattr_np" if this.frame_in_std() => {
let [_thread, _attr] = let [_thread, _attr] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_null(dest)?; this.write_null(dest)?;
} }

View File

@ -1,7 +1,7 @@
//! This follows the pattern in src/shims/unix/mem.rs: We only support uses of mremap that would //! This follows the pattern in src/shims/unix/mem.rs: We only support uses of mremap that would
//! correspond to valid uses of realloc. //! correspond to valid uses of realloc.
use rustc_target::abi::Size; use rustc_abi::Size;
use crate::*; use crate::*;

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::sync::EvalContextExt as _; use super::sync::EvalContextExt as _;
use crate::shims::unix::*; use crate::shims::unix::*;
@ -14,7 +14,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -25,55 +25,58 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
match link_name.as_str() { match link_name.as_str() {
// errno // errno
"__error" => { "__error" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let errno_place = this.last_error_place()?; let errno_place = this.last_error_place()?;
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?; this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
} }
// File related shims // File related shims
"close$NOCANCEL" => { "close$NOCANCEL" => {
let [result] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [result] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.close(result)?; let result = this.close(result)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"stat" | "stat64" | "stat$INODE64" => { "stat" | "stat64" | "stat$INODE64" => {
let [path, buf] = let [path, buf] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_stat(path, buf)?; let result = this.macos_fbsd_stat(path, buf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"lstat" | "lstat64" | "lstat$INODE64" => { "lstat" | "lstat64" | "lstat$INODE64" => {
let [path, buf] = let [path, buf] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_lstat(path, buf)?; let result = this.macos_fbsd_lstat(path, buf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"fstat" | "fstat64" | "fstat$INODE64" => { "fstat" | "fstat64" | "fstat$INODE64" => {
let [fd, buf] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [fd, buf] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_fstat(fd, buf)?; let result = this.macos_fbsd_fstat(fd, buf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"opendir$INODE64" => { "opendir$INODE64" => {
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [name] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.opendir(name)?; let result = this.opendir(name)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"readdir_r" | "readdir_r$INODE64" => { "readdir_r" | "readdir_r$INODE64" => {
let [dirp, entry, result] = let [dirp, entry, result] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.macos_fbsd_readdir_r(dirp, entry, result)?; let result = this.macos_fbsd_readdir_r(dirp, entry, result)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"realpath$DARWIN_EXTSN" => { "realpath$DARWIN_EXTSN" => {
let [path, resolved_path] = let [path, resolved_path] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.realpath(path, resolved_path)?; let result = this.realpath(path, resolved_path)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
// Environment related shims // Environment related shims
"_NSGetEnviron" => { "_NSGetEnviron" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let environ = this.machine.env_vars.unix().environ(); let environ = this.machine.env_vars.unix().environ();
this.write_pointer(environ, dest)?; this.write_pointer(environ, dest)?;
} }
@ -81,7 +84,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Random data generation // Random data generation
"CCRandomGenerateBytes" => { "CCRandomGenerateBytes" => {
let [bytes, count] = let [bytes, count] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let bytes = this.read_pointer(bytes)?; let bytes = this.read_pointer(bytes)?;
let count = this.read_target_usize(count)?; let count = this.read_target_usize(count)?;
let success = this.eval_libc_i32("kCCSuccess"); let success = this.eval_libc_i32("kCCSuccess");
@ -91,29 +94,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Time related shims // Time related shims
"mach_absolute_time" => { "mach_absolute_time" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.mach_absolute_time()?; let result = this.mach_absolute_time()?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"mach_timebase_info" => { "mach_timebase_info" => {
let [info] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [info] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.mach_timebase_info(info)?; let result = this.mach_timebase_info(info)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
// Access to command-line arguments // Access to command-line arguments
"_NSGetArgc" => { "_NSGetArgc" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_pointer(this.machine.argc.expect("machine must be initialized"), dest)?; this.write_pointer(this.machine.argc.expect("machine must be initialized"), dest)?;
} }
"_NSGetArgv" => { "_NSGetArgv" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.write_pointer(this.machine.argv.expect("machine must be initialized"), dest)?; this.write_pointer(this.machine.argv.expect("machine must be initialized"), dest)?;
} }
"_NSGetExecutablePath" => { "_NSGetExecutablePath" => {
let [buf, bufsize] = let [buf, bufsize] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.check_no_isolation("`_NSGetExecutablePath`")?; this.check_no_isolation("`_NSGetExecutablePath`")?;
let buf_ptr = this.read_pointer(buf)?; let buf_ptr = this.read_pointer(buf)?;
@ -139,7 +143,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Thread-local storage // Thread-local storage
"_tlv_atexit" => { "_tlv_atexit" => {
let [dtor, data] = let [dtor, data] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let dtor = this.read_pointer(dtor)?; let dtor = this.read_pointer(dtor)?;
let dtor = this.get_ptr_fn(dtor)?.as_instance()?; let dtor = this.get_ptr_fn(dtor)?.as_instance()?;
let data = this.read_scalar(data)?; let data = this.read_scalar(data)?;
@ -149,13 +153,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Querying system information // Querying system information
"pthread_get_stackaddr_np" => { "pthread_get_stackaddr_np" => {
let [thread] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [thread] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.read_target_usize(thread)?; this.read_target_usize(thread)?;
let stack_addr = Scalar::from_uint(this.machine.stack_addr, this.pointer_size()); let stack_addr = Scalar::from_uint(this.machine.stack_addr, this.pointer_size());
this.write_scalar(stack_addr, dest)?; this.write_scalar(stack_addr, dest)?;
} }
"pthread_get_stacksize_np" => { "pthread_get_stacksize_np" => {
let [thread] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [thread] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.read_target_usize(thread)?; this.read_target_usize(thread)?;
let stack_size = Scalar::from_uint(this.machine.stack_size, this.pointer_size()); let stack_size = Scalar::from_uint(this.machine.stack_size, this.pointer_size());
this.write_scalar(stack_size, dest)?; this.write_scalar(stack_size, dest)?;
@ -163,7 +169,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Threading // Threading
"pthread_setname_np" => { "pthread_setname_np" => {
let [name] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [name] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// The real implementation has logic in two places: // The real implementation has logic in two places:
// * in userland at https://github.com/apple-oss-distributions/libpthread/blob/c032e0b076700a0a47db75528a282b8d3a06531a/src/pthread.c#L1178-L1200, // * in userland at https://github.com/apple-oss-distributions/libpthread/blob/c032e0b076700a0a47db75528a282b8d3a06531a/src/pthread.c#L1178-L1200,
@ -193,7 +200,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"pthread_getname_np" => { "pthread_getname_np" => {
let [thread, name, len] = let [thread, name, len] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// The function's behavior isn't portable between platforms. // The function's behavior isn't portable between platforms.
// In case of macOS, a truncated name (due to a too small buffer) // In case of macOS, a truncated name (due to a too small buffer)
@ -216,23 +223,28 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"os_unfair_lock_lock" => { "os_unfair_lock_lock" => {
let [lock_op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [lock_op] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.os_unfair_lock_lock(lock_op)?; this.os_unfair_lock_lock(lock_op)?;
} }
"os_unfair_lock_trylock" => { "os_unfair_lock_trylock" => {
let [lock_op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [lock_op] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.os_unfair_lock_trylock(lock_op, dest)?; this.os_unfair_lock_trylock(lock_op, dest)?;
} }
"os_unfair_lock_unlock" => { "os_unfair_lock_unlock" => {
let [lock_op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [lock_op] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.os_unfair_lock_unlock(lock_op)?; this.os_unfair_lock_unlock(lock_op)?;
} }
"os_unfair_lock_assert_owner" => { "os_unfair_lock_assert_owner" => {
let [lock_op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [lock_op] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.os_unfair_lock_assert_owner(lock_op)?; this.os_unfair_lock_assert_owner(lock_op)?;
} }
"os_unfair_lock_assert_not_owner" => { "os_unfair_lock_assert_not_owner" => {
let [lock_op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [lock_op] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
this.os_unfair_lock_assert_not_owner(lock_op)?; this.os_unfair_lock_assert_not_owner(lock_op)?;
} }

View File

@ -10,7 +10,7 @@
//! and we do not detect copying of the lock, but macOS doesn't guarantee anything //! and we do not detect copying of the lock, but macOS doesn't guarantee anything
//! in that case either. //! in that case either.
use rustc_target::abi::Size; use rustc_abi::Size;
use crate::*; use crate::*;

View File

@ -14,7 +14,7 @@
//! munmap shim which would partially unmap a region of address space previously mapped by mmap will //! munmap shim which would partially unmap a region of address space previously mapped by mmap will
//! report UB. //! report UB.
use rustc_target::abi::Size; use rustc_abi::Size;
use crate::*; use crate::*;

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::shims::unix::*; use crate::shims::unix::*;
use crate::*; use crate::*;
@ -13,7 +13,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -22,7 +22,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Threading // Threading
"pthread_setname_np" => { "pthread_setname_np" => {
let [thread, name] = let [thread, name] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// THREAD_NAME_MAX allows a thread name of 31+1 length // THREAD_NAME_MAX allows a thread name of 31+1 length
// https://github.com/illumos/illumos-gate/blob/7671517e13b8123748eda4ef1ee165c6d9dba7fe/usr/src/uts/common/sys/thread.h#L613 // https://github.com/illumos/illumos-gate/blob/7671517e13b8123748eda4ef1ee165c6d9dba7fe/usr/src/uts/common/sys/thread.h#L613
let max_len = 32; let max_len = 32;
@ -37,7 +37,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"pthread_getname_np" => { "pthread_getname_np" => {
let [thread, name, len] = let [thread, name, len] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// https://github.com/illumos/illumos-gate/blob/c56822be04b6c157c8b6f2281e47214c3b86f657/usr/src/lib/libc/port/threads/thr.c#L2449-L2480 // https://github.com/illumos/illumos-gate/blob/c56822be04b6c157c8b6f2281e47214c3b86f657/usr/src/lib/libc/port/threads/thr.c#L2449-L2480
let res = this.pthread_getname_np( let res = this.pthread_getname_np(
this.read_scalar(thread)?, this.read_scalar(thread)?,
@ -51,13 +51,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Miscellaneous // Miscellaneous
"___errno" => { "___errno" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let errno_place = this.last_error_place()?; let errno_place = this.last_error_place()?;
this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?; this.write_scalar(errno_place.to_ref(this).to_scalar(), dest)?;
} }
"stack_getbounds" => { "stack_getbounds" => {
let [stack] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [stack] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let stack = this.deref_pointer_as(stack, this.libc_ty_layout("stack_t"))?; let stack = this.deref_pointer_as(stack, this.libc_ty_layout("stack_t"))?;
this.write_int_fields_named( this.write_int_fields_named(
@ -76,7 +77,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"pset_info" => { "pset_info" => {
let [pset, tpe, cpus, list] = let [pset, tpe, cpus, list] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// We do not need to handle the current process cpu mask, available_parallelism // We do not need to handle the current process cpu mask, available_parallelism
// implementation pass null anyway. We only care for the number of // implementation pass null anyway. We only care for the number of
// cpus. // cpus.

View File

@ -1,6 +1,6 @@
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use rustc_target::abi::Size; use rustc_abi::Size;
use crate::concurrency::sync::LAZY_INIT_COOKIE; use crate::concurrency::sync::LAZY_INIT_COOKIE;
use crate::*; use crate::*;

View File

@ -1,4 +1,4 @@
use rustc_target::spec::abi::Abi; use rustc_abi::ExternAbi;
use crate::*; use crate::*;
@ -22,7 +22,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.start_regular_thread( this.start_regular_thread(
Some(thread_info_place), Some(thread_info_place),
start_routine, start_routine,
Abi::C { unwind: false }, ExternAbi::C { unwind: false },
func_arg, func_arg,
this.machine.layouts.mut_raw_ptr, this.machine.layouts.mut_raw_ptr,
)?; )?;

View File

@ -7,7 +7,7 @@ use std::collections::VecDeque;
use std::io; use std::io;
use std::io::{ErrorKind, Read}; use std::io::{ErrorKind, Read};
use rustc_target::abi::Size; use rustc_abi::Size;
use crate::concurrency::VClock; use crate::concurrency::VClock;
use crate::shims::unix::fd::{FileDescriptionRef, WeakFileDescriptionRef}; use crate::shims::unix::fd::{FileDescriptionRef, WeakFileDescriptionRef};

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::shims::alloc::EvalContextExt as _; use crate::shims::alloc::EvalContextExt as _;
use crate::*; use crate::*;
@ -13,7 +13,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -22,13 +22,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Allocation // Allocation
"posix_memalign" => { "posix_memalign" => {
let [memptr, align, size] = let [memptr, align, size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let result = this.posix_memalign(memptr, align, size)?; let result = this.posix_memalign(memptr, align, size)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"aligned_alloc" => { "aligned_alloc" => {
let [align, size] = let [align, size] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let res = this.aligned_alloc(align, size)?; let res = this.aligned_alloc(align, size)?;
this.write_pointer(res, dest)?; this.write_pointer(res, dest)?;
} }

View File

@ -2,9 +2,8 @@ use std::ffi::OsStr;
use std::path::{self, Path, PathBuf}; use std::path::{self, Path, PathBuf};
use std::{io, iter, str}; use std::{io, iter, str};
use rustc_abi::{Align, ExternAbi, Size};
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::abi::{Align, Size};
use rustc_target::spec::abi::Abi;
use self::shims::windows::handle::{Handle, PseudoHandle}; use self::shims::windows::handle::{Handle, PseudoHandle};
use crate::shims::os_str::bytes_to_os_str; use crate::shims::os_str::bytes_to_os_str;
@ -79,7 +78,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_foreign_item_inner( fn emulate_foreign_item_inner(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -97,47 +96,49 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Environment related shims // Environment related shims
"GetEnvironmentVariableW" => { "GetEnvironmentVariableW" => {
let [name, buf, size] = let [name, buf, size] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.GetEnvironmentVariableW(name, buf, size)?; let result = this.GetEnvironmentVariableW(name, buf, size)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"SetEnvironmentVariableW" => { "SetEnvironmentVariableW" => {
let [name, value] = let [name, value] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.SetEnvironmentVariableW(name, value)?; let result = this.SetEnvironmentVariableW(name, value)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"GetEnvironmentStringsW" => { "GetEnvironmentStringsW" => {
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.GetEnvironmentStringsW()?; let result = this.GetEnvironmentStringsW()?;
this.write_pointer(result, dest)?; this.write_pointer(result, dest)?;
} }
"FreeEnvironmentStringsW" => { "FreeEnvironmentStringsW" => {
let [env_block] = let [env_block] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.FreeEnvironmentStringsW(env_block)?; let result = this.FreeEnvironmentStringsW(env_block)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"GetCurrentDirectoryW" => { "GetCurrentDirectoryW" => {
let [size, buf] = let [size, buf] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.GetCurrentDirectoryW(size, buf)?; let result = this.GetCurrentDirectoryW(size, buf)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"SetCurrentDirectoryW" => { "SetCurrentDirectoryW" => {
let [path] = let [path] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.SetCurrentDirectoryW(path)?; let result = this.SetCurrentDirectoryW(path)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"GetUserProfileDirectoryW" => { "GetUserProfileDirectoryW" => {
let [token, buf, size] = let [token, buf, size] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.GetUserProfileDirectoryW(token, buf, size)?; let result = this.GetUserProfileDirectoryW(token, buf, size)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"GetCurrentProcessId" => { "GetCurrentProcessId" => {
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.GetCurrentProcessId()?; let result = this.GetCurrentProcessId()?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
@ -160,7 +161,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
n, n,
byte_offset, byte_offset,
_key, _key,
] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; ] = this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let handle = this.read_target_isize(handle)?; let handle = this.read_target_isize(handle)?;
let buf = this.read_pointer(buf)?; let buf = this.read_pointer(buf)?;
let n = this.read_scalar(n)?.to_u32()?; let n = this.read_scalar(n)?.to_u32()?;
@ -212,7 +213,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"GetFullPathNameW" => { "GetFullPathNameW" => {
let [filename, size, buffer, filepart] = let [filename, size, buffer, filepart] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.check_no_isolation("`GetFullPathNameW`")?; this.check_no_isolation("`GetFullPathNameW`")?;
let filename = this.read_pointer(filename)?; let filename = this.read_pointer(filename)?;
@ -244,7 +245,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Allocation // Allocation
"HeapAlloc" => { "HeapAlloc" => {
let [handle, flags, size] = let [handle, flags, size] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.read_target_isize(handle)?; this.read_target_isize(handle)?;
let flags = this.read_scalar(flags)?.to_u32()?; let flags = this.read_scalar(flags)?.to_u32()?;
let size = this.read_target_usize(size)?; let size = this.read_target_usize(size)?;
@ -268,7 +269,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"HeapFree" => { "HeapFree" => {
let [handle, flags, ptr] = let [handle, flags, ptr] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.read_target_isize(handle)?; this.read_target_isize(handle)?;
this.read_scalar(flags)?.to_u32()?; this.read_scalar(flags)?.to_u32()?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
@ -281,7 +282,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"HeapReAlloc" => { "HeapReAlloc" => {
let [handle, flags, old_ptr, size] = let [handle, flags, old_ptr, size] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.read_target_isize(handle)?; this.read_target_isize(handle)?;
this.read_scalar(flags)?.to_u32()?; this.read_scalar(flags)?.to_u32()?;
let old_ptr = this.read_pointer(old_ptr)?; let old_ptr = this.read_pointer(old_ptr)?;
@ -300,7 +301,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.write_pointer(new_ptr, dest)?; this.write_pointer(new_ptr, dest)?;
} }
"LocalFree" => { "LocalFree" => {
let [ptr] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [ptr] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
// "If the hMem parameter is NULL, LocalFree ignores the parameter and returns NULL." // "If the hMem parameter is NULL, LocalFree ignores the parameter and returns NULL."
// (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-localfree) // (https://learn.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-localfree)
@ -313,12 +315,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// errno // errno
"SetLastError" => { "SetLastError" => {
let [error] = let [error] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let error = this.read_scalar(error)?; let error = this.read_scalar(error)?;
this.set_last_error(error)?; this.set_last_error(error)?;
} }
"GetLastError" => { "GetLastError" => {
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let last_error = this.get_last_error()?; let last_error = this.get_last_error()?;
this.write_scalar(last_error, dest)?; this.write_scalar(last_error, dest)?;
} }
@ -327,7 +330,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"GetSystemInfo" => { "GetSystemInfo" => {
// Also called from `page_size` crate. // Also called from `page_size` crate.
let [system_info] = let [system_info] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let system_info = let system_info =
this.deref_pointer_as(system_info, this.windows_ty_layout("SYSTEM_INFO"))?; this.deref_pointer_as(system_info, this.windows_ty_layout("SYSTEM_INFO"))?;
// Initialize with `0`. // Initialize with `0`.
@ -350,12 +353,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// This just creates a key; Windows does not natively support TLS destructors. // This just creates a key; Windows does not natively support TLS destructors.
// Create key and return it. // Create key and return it.
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let key = this.machine.tls.create_tls_key(None, dest.layout.size)?; let key = this.machine.tls.create_tls_key(None, dest.layout.size)?;
this.write_scalar(Scalar::from_uint(key, dest.layout.size), dest)?; this.write_scalar(Scalar::from_uint(key, dest.layout.size), dest)?;
} }
"TlsGetValue" => { "TlsGetValue" => {
let [key] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [key] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let key = u128::from(this.read_scalar(key)?.to_u32()?); let key = u128::from(this.read_scalar(key)?.to_u32()?);
let active_thread = this.active_thread(); let active_thread = this.active_thread();
let ptr = this.machine.tls.load_tls(key, active_thread, this)?; let ptr = this.machine.tls.load_tls(key, active_thread, this)?;
@ -363,7 +368,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"TlsSetValue" => { "TlsSetValue" => {
let [key, new_ptr] = let [key, new_ptr] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let key = u128::from(this.read_scalar(key)?.to_u32()?); let key = u128::from(this.read_scalar(key)?.to_u32()?);
let active_thread = this.active_thread(); let active_thread = this.active_thread();
let new_data = this.read_scalar(new_ptr)?; let new_data = this.read_scalar(new_ptr)?;
@ -375,7 +380,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Access to command-line arguments // Access to command-line arguments
"GetCommandLineW" => { "GetCommandLineW" => {
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.write_pointer( this.write_pointer(
this.machine.cmd_line.expect("machine must be initialized"), this.machine.cmd_line.expect("machine must be initialized"),
dest, dest,
@ -386,32 +392,32 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"GetSystemTimeAsFileTime" | "GetSystemTimePreciseAsFileTime" => { "GetSystemTimeAsFileTime" | "GetSystemTimePreciseAsFileTime" => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [LPFILETIME] = let [LPFILETIME] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.GetSystemTimeAsFileTime(link_name.as_str(), LPFILETIME)?; this.GetSystemTimeAsFileTime(link_name.as_str(), LPFILETIME)?;
} }
"QueryPerformanceCounter" => { "QueryPerformanceCounter" => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [lpPerformanceCount] = let [lpPerformanceCount] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.QueryPerformanceCounter(lpPerformanceCount)?; let result = this.QueryPerformanceCounter(lpPerformanceCount)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"QueryPerformanceFrequency" => { "QueryPerformanceFrequency" => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [lpFrequency] = let [lpFrequency] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.QueryPerformanceFrequency(lpFrequency)?; let result = this.QueryPerformanceFrequency(lpFrequency)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"Sleep" => { "Sleep" => {
let [timeout] = let [timeout] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.Sleep(timeout)?; this.Sleep(timeout)?;
} }
"CreateWaitableTimerExW" => { "CreateWaitableTimerExW" => {
let [attributes, name, flags, access] = let [attributes, name, flags, access] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.read_pointer(attributes)?; this.read_pointer(attributes)?;
this.read_pointer(name)?; this.read_pointer(name)?;
this.read_scalar(flags)?.to_u32()?; this.read_scalar(flags)?.to_u32()?;
@ -425,30 +431,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Synchronization primitives // Synchronization primitives
"InitOnceBeginInitialize" => { "InitOnceBeginInitialize" => {
let [ptr, flags, pending, context] = let [ptr, flags, pending, context] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.InitOnceBeginInitialize(ptr, flags, pending, context, dest)?; this.InitOnceBeginInitialize(ptr, flags, pending, context, dest)?;
} }
"InitOnceComplete" => { "InitOnceComplete" => {
let [ptr, flags, context] = let [ptr, flags, context] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let result = this.InitOnceComplete(ptr, flags, context)?; let result = this.InitOnceComplete(ptr, flags, context)?;
this.write_scalar(result, dest)?; this.write_scalar(result, dest)?;
} }
"WaitOnAddress" => { "WaitOnAddress" => {
let [ptr_op, compare_op, size_op, timeout_op] = let [ptr_op, compare_op, size_op, timeout_op] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.WaitOnAddress(ptr_op, compare_op, size_op, timeout_op, dest)?; this.WaitOnAddress(ptr_op, compare_op, size_op, timeout_op, dest)?;
} }
"WakeByAddressSingle" => { "WakeByAddressSingle" => {
let [ptr_op] = let [ptr_op] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.WakeByAddressSingle(ptr_op)?; this.WakeByAddressSingle(ptr_op)?;
} }
"WakeByAddressAll" => { "WakeByAddressAll" => {
let [ptr_op] = let [ptr_op] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.WakeByAddressAll(ptr_op)?; this.WakeByAddressAll(ptr_op)?;
} }
@ -457,7 +463,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"GetProcAddress" => { "GetProcAddress" => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [hModule, lpProcName] = let [hModule, lpProcName] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.read_target_isize(hModule)?; this.read_target_isize(hModule)?;
let name = this.read_c_str(this.read_pointer(lpProcName)?)?; let name = this.read_c_str(this.read_pointer(lpProcName)?)?;
if let Ok(name) = str::from_utf8(name) if let Ok(name) = str::from_utf8(name)
@ -473,7 +479,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Threading // Threading
"CreateThread" => { "CreateThread" => {
let [security, stacksize, start, arg, flags, thread] = let [security, stacksize, start, arg, flags, thread] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let thread_id = let thread_id =
this.CreateThread(security, stacksize, start, arg, flags, thread)?; this.CreateThread(security, stacksize, start, arg, flags, thread)?;
@ -482,13 +488,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"WaitForSingleObject" => { "WaitForSingleObject" => {
let [handle, timeout] = let [handle, timeout] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let ret = this.WaitForSingleObject(handle, timeout)?; let ret = this.WaitForSingleObject(handle, timeout)?;
this.write_scalar(Scalar::from_u32(ret), dest)?; this.write_scalar(Scalar::from_u32(ret), dest)?;
} }
"GetCurrentThread" => { "GetCurrentThread" => {
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.write_scalar( this.write_scalar(
Handle::Pseudo(PseudoHandle::CurrentThread).to_scalar(this), Handle::Pseudo(PseudoHandle::CurrentThread).to_scalar(this),
@ -497,7 +504,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"SetThreadDescription" => { "SetThreadDescription" => {
let [handle, name] = let [handle, name] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let handle = this.read_scalar(handle)?; let handle = this.read_scalar(handle)?;
let name = this.read_wide_str(this.read_pointer(name)?)?; let name = this.read_wide_str(this.read_pointer(name)?)?;
@ -515,7 +522,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"GetThreadDescription" => { "GetThreadDescription" => {
let [handle, name_ptr] = let [handle, name_ptr] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let handle = this.read_scalar(handle)?; let handle = this.read_scalar(handle)?;
let name_ptr = this.deref_pointer(name_ptr)?; // the pointer where we should store the ptr to the name let name_ptr = this.deref_pointer(name_ptr)?; // the pointer where we should store the ptr to the name
@ -540,7 +547,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Miscellaneous // Miscellaneous
"ExitProcess" => { "ExitProcess" => {
let [code] = let [code] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let code = this.read_scalar(code)?.to_u32()?; let code = this.read_scalar(code)?.to_u32()?;
throw_machine_stop!(TerminationInfo::Exit { code: code.into(), leak_check: false }); throw_machine_stop!(TerminationInfo::Exit { code: code.into(), leak_check: false });
} }
@ -548,7 +555,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// used by getrandom 0.1 // used by getrandom 0.1
// This is really 'RtlGenRandom'. // This is really 'RtlGenRandom'.
let [ptr, len] = let [ptr, len] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let len = this.read_scalar(len)?.to_u32()?; let len = this.read_scalar(len)?.to_u32()?;
this.gen_random(ptr, len.into())?; this.gen_random(ptr, len.into())?;
@ -557,7 +564,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"ProcessPrng" => { "ProcessPrng" => {
// used by `std` // used by `std`
let [ptr, len] = let [ptr, len] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
let len = this.read_target_usize(len)?; let len = this.read_target_usize(len)?;
this.gen_random(ptr, len)?; this.gen_random(ptr, len)?;
@ -566,7 +573,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"BCryptGenRandom" => { "BCryptGenRandom" => {
// used by getrandom 0.2 // used by getrandom 0.2
let [algorithm, ptr, len, flags] = let [algorithm, ptr, len, flags] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let algorithm = this.read_scalar(algorithm)?; let algorithm = this.read_scalar(algorithm)?;
let algorithm = algorithm.to_target_usize(this)?; let algorithm = algorithm.to_target_usize(this)?;
let ptr = this.read_pointer(ptr)?; let ptr = this.read_pointer(ptr)?;
@ -601,7 +608,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"GetConsoleScreenBufferInfo" => { "GetConsoleScreenBufferInfo" => {
// `term` needs this, so we fake it. // `term` needs this, so we fake it.
let [console, buffer_info] = let [console, buffer_info] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.read_target_isize(console)?; this.read_target_isize(console)?;
// FIXME: this should use deref_pointer_as, but CONSOLE_SCREEN_BUFFER_INFO is not in std // FIXME: this should use deref_pointer_as, but CONSOLE_SCREEN_BUFFER_INFO is not in std
this.deref_pointer(buffer_info)?; this.deref_pointer(buffer_info)?;
@ -611,7 +618,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"GetStdHandle" => { "GetStdHandle" => {
let [which] = let [which] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let which = this.read_scalar(which)?.to_i32()?; let which = this.read_scalar(which)?.to_i32()?;
// We just make this the identity function, so we know later in `NtWriteFile` which // We just make this the identity function, so we know later in `NtWriteFile` which
// one it is. This is very fake, but libtest needs it so we cannot make it a // one it is. This is very fake, but libtest needs it so we cannot make it a
@ -621,7 +628,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"CloseHandle" => { "CloseHandle" => {
let [handle] = let [handle] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.CloseHandle(handle)?; this.CloseHandle(handle)?;
@ -629,7 +636,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"GetModuleFileNameW" => { "GetModuleFileNameW" => {
let [handle, filename, size] = let [handle, filename, size] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.check_no_isolation("`GetModuleFileNameW`")?; this.check_no_isolation("`GetModuleFileNameW`")?;
let handle = this.read_target_usize(handle)?; let handle = this.read_target_usize(handle)?;
@ -663,7 +670,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
"FormatMessageW" => { "FormatMessageW" => {
let [flags, module, message_id, language_id, buffer, size, arguments] = let [flags, module, message_id, language_id, buffer, size, arguments] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
let flags = this.read_scalar(flags)?.to_u32()?; let flags = this.read_scalar(flags)?.to_u32()?;
let _module = this.read_pointer(module)?; // seems to contain a module name let _module = this.read_pointer(module)?; // seems to contain a module name
@ -698,7 +705,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Incomplete shims that we "stub out" just to get pre-main initialization code to work. // Incomplete shims that we "stub out" just to get pre-main initialization code to work.
// These shims are enabled only when the caller is in the standard library. // These shims are enabled only when the caller is in the standard library.
"GetProcessHeap" if this.frame_in_std() => { "GetProcessHeap" if this.frame_in_std() => {
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
// Just fake a HANDLE // Just fake a HANDLE
// It's fine to not use the Handle type here because its a stub // It's fine to not use the Handle type here because its a stub
this.write_int(1, dest)?; this.write_int(1, dest)?;
@ -706,20 +714,20 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"GetModuleHandleA" if this.frame_in_std() => { "GetModuleHandleA" if this.frame_in_std() => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [_lpModuleName] = let [_lpModuleName] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
// We need to return something non-null here to make `compat_fn!` work. // We need to return something non-null here to make `compat_fn!` work.
this.write_int(1, dest)?; this.write_int(1, dest)?;
} }
"SetConsoleTextAttribute" if this.frame_in_std() => { "SetConsoleTextAttribute" if this.frame_in_std() => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [_hConsoleOutput, _wAttribute] = let [_hConsoleOutput, _wAttribute] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
// Pretend these does not exist / nothing happened, by returning zero. // Pretend these does not exist / nothing happened, by returning zero.
this.write_null(dest)?; this.write_null(dest)?;
} }
"GetConsoleMode" if this.frame_in_std() => { "GetConsoleMode" if this.frame_in_std() => {
let [console, mode] = let [console, mode] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.read_target_isize(console)?; this.read_target_isize(console)?;
this.deref_pointer(mode)?; this.deref_pointer(mode)?;
// Indicate an error. // Indicate an error.
@ -728,27 +736,28 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"GetFileType" if this.frame_in_std() => { "GetFileType" if this.frame_in_std() => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [_hFile] = let [_hFile] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
// Return unknown file type. // Return unknown file type.
this.write_null(dest)?; this.write_null(dest)?;
} }
"AddVectoredExceptionHandler" if this.frame_in_std() => { "AddVectoredExceptionHandler" if this.frame_in_std() => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [_First, _Handler] = let [_First, _Handler] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
// Any non zero value works for the stdlib. This is just used for stack overflows anyway. // Any non zero value works for the stdlib. This is just used for stack overflows anyway.
this.write_int(1, dest)?; this.write_int(1, dest)?;
} }
"SetThreadStackGuarantee" if this.frame_in_std() => { "SetThreadStackGuarantee" if this.frame_in_std() => {
#[allow(non_snake_case)] #[allow(non_snake_case)]
let [_StackSizeInBytes] = let [_StackSizeInBytes] =
this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
// Any non zero value works for the stdlib. This is just used for stack overflows anyway. // Any non zero value works for the stdlib. This is just used for stack overflows anyway.
this.write_int(1, dest)?; this.write_int(1, dest)?;
} }
// this is only callable from std because we know that std ignores the return value // this is only callable from std because we know that std ignores the return value
"SwitchToThread" if this.frame_in_std() => { "SwitchToThread" if this.frame_in_std() => {
let [] = this.check_shim(abi, Abi::System { unwind: false }, link_name, args)?; let [] =
this.check_shim(abi, ExternAbi::System { unwind: false }, link_name, args)?;
this.yield_active_thread(); this.yield_active_thread();
@ -767,7 +776,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
); );
} }
// This function looks and behaves excatly like miri_start_unwind. // This function looks and behaves excatly like miri_start_unwind.
let [payload] = this.check_shim(abi, Abi::C { unwind: true }, link_name, args)?; let [payload] =
this.check_shim(abi, ExternAbi::C { unwind: true }, link_name, args)?;
this.handle_miri_start_unwind(payload)?; this.handle_miri_start_unwind(payload)?;
return interp_ok(EmulateItemResult::NeedsUnwind); return interp_ok(EmulateItemResult::NeedsUnwind);
} }

View File

@ -1,6 +1,6 @@
use std::mem::variant_count; use std::mem::variant_count;
use rustc_target::abi::HasDataLayout; use rustc_abi::HasDataLayout;
use crate::*; use crate::*;

View File

@ -1,6 +1,6 @@
use std::time::Duration; use std::time::Duration;
use rustc_target::abi::Size; use rustc_abi::Size;
use crate::concurrency::init_once::InitOnceStatus; use crate::concurrency::init_once::InitOnceStatus;
use crate::*; use crate::*;

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_middle::ty::layout::LayoutOf; use rustc_middle::ty::layout::LayoutOf;
use rustc_target::spec::abi::Abi;
use self::shims::windows::handle::{EvalContextExt as _, Handle, PseudoHandle}; use self::shims::windows::handle::{EvalContextExt as _, Handle, PseudoHandle};
use crate::*; use crate::*;
@ -49,7 +49,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
this.start_regular_thread( this.start_regular_thread(
thread, thread,
start_routine, start_routine,
Abi::System { unwind: false }, ExternAbi::System { unwind: false },
func_arg, func_arg,
this.layout_of(this.tcx.types.u32)?, this.layout_of(this.tcx.types.u32)?,
) )

View File

@ -1,7 +1,7 @@
use rustc_abi::ExternAbi;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::layout::LayoutOf as _;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::*; use crate::*;
@ -10,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_aesni_intrinsic( fn emulate_x86_aesni_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -27,7 +27,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdec_si128 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdec_si128
"aesdec" | "aesdec.256" | "aesdec.512" => { "aesdec" | "aesdec.256" | "aesdec.512" => {
let [state, key] = let [state, key] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
aes_round(this, state, key, dest, |state, key| { aes_round(this, state, key, dest, |state, key| {
let key = aes::Block::from(key.to_le_bytes()); let key = aes::Block::from(key.to_le_bytes());
@ -45,7 +45,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdeclast_si128 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesdeclast_si128
"aesdeclast" | "aesdeclast.256" | "aesdeclast.512" => { "aesdeclast" | "aesdeclast.256" | "aesdeclast.512" => {
let [state, key] = let [state, key] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
aes_round(this, state, key, dest, |state, key| { aes_round(this, state, key, dest, |state, key| {
let mut state = aes::Block::from(state.to_le_bytes()); let mut state = aes::Block::from(state.to_le_bytes());
@ -70,7 +70,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenc_si128 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenc_si128
"aesenc" | "aesenc.256" | "aesenc.512" => { "aesenc" | "aesenc.256" | "aesenc.512" => {
let [state, key] = let [state, key] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
aes_round(this, state, key, dest, |state, key| { aes_round(this, state, key, dest, |state, key| {
let key = aes::Block::from(key.to_le_bytes()); let key = aes::Block::from(key.to_le_bytes());
@ -88,7 +88,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenclast_si128 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_aesenclast_si128
"aesenclast" | "aesenclast.256" | "aesenclast.512" => { "aesenclast" | "aesenclast.256" | "aesenclast.512" => {
let [state, key] = let [state, key] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
aes_round(this, state, key, dest, |state, key| { aes_round(this, state, key, dest, |state, key| {
let mut state = aes::Block::from(state.to_le_bytes()); let mut state = aes::Block::from(state.to_le_bytes());
@ -109,7 +109,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Used to implement the _mm_aesimc_si128 function. // Used to implement the _mm_aesimc_si128 function.
// Performs the AES InvMixColumns operation on `op` // Performs the AES InvMixColumns operation on `op`
"aesimc" => { "aesimc" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// Transmute to `u128` // Transmute to `u128`
let op = op.transmute(this.machine.layouts.u128, this)?; let op = op.transmute(this.machine.layouts.u128, this)?;

View File

@ -1,9 +1,9 @@
use rustc_abi::ExternAbi;
use rustc_apfloat::ieee::{Double, Single}; use rustc_apfloat::ieee::{Double, Single};
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::layout::LayoutOf as _;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::{ use super::{
FloatBinOp, FloatUnaryOp, bin_op_simd_float_all, conditional_dot_product, convert_float_to_int, FloatBinOp, FloatUnaryOp, bin_op_simd_float_all, conditional_dot_product, convert_float_to_int,
@ -17,7 +17,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_avx_intrinsic( fn emulate_x86_avx_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -34,7 +34,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// semantics. // semantics.
"min.ps.256" | "max.ps.256" => { "min.ps.256" | "max.ps.256" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"min.ps.256" => FloatBinOp::Min, "min.ps.256" => FloatBinOp::Min,
@ -47,7 +47,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Used to implement _mm256_min_pd and _mm256_max_pd functions. // Used to implement _mm256_min_pd and _mm256_max_pd functions.
"min.pd.256" | "max.pd.256" => { "min.pd.256" | "max.pd.256" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"min.pd.256" => FloatBinOp::Min, "min.pd.256" => FloatBinOp::Min,
@ -61,7 +61,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Rounds the elements of `op` according to `rounding`. // Rounds the elements of `op` according to `rounding`.
"round.ps.256" => { "round.ps.256" => {
let [op, rounding] = let [op, rounding] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
round_all::<rustc_apfloat::ieee::Single>(this, op, rounding, dest)?; round_all::<rustc_apfloat::ieee::Single>(this, op, rounding, dest)?;
} }
@ -69,14 +69,14 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Rounds the elements of `op` according to `rounding`. // Rounds the elements of `op` according to `rounding`.
"round.pd.256" => { "round.pd.256" => {
let [op, rounding] = let [op, rounding] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
round_all::<rustc_apfloat::ieee::Double>(this, op, rounding, dest)?; round_all::<rustc_apfloat::ieee::Double>(this, op, rounding, dest)?;
} }
// Used to implement _mm256_{rcp,rsqrt}_ps functions. // Used to implement _mm256_{rcp,rsqrt}_ps functions.
// Performs the operations on all components of `op`. // Performs the operations on all components of `op`.
"rcp.ps.256" | "rsqrt.ps.256" => { "rcp.ps.256" | "rsqrt.ps.256" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"rcp.ps.256" => FloatUnaryOp::Rcp, "rcp.ps.256" => FloatUnaryOp::Rcp,
@ -89,7 +89,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Used to implement the _mm256_dp_ps function. // Used to implement the _mm256_dp_ps function.
"dp.ps.256" => { "dp.ps.256" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
conditional_dot_product(this, left, right, imm, dest)?; conditional_dot_product(this, left, right, imm, dest)?;
} }
@ -98,7 +98,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// in `left` and `right`. // in `left` and `right`.
"hadd.ps.256" | "hadd.pd.256" | "hsub.ps.256" | "hsub.pd.256" => { "hadd.ps.256" | "hadd.pd.256" | "hsub.ps.256" | "hsub.pd.256" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"hadd.ps.256" | "hadd.pd.256" => mir::BinOp::Add, "hadd.ps.256" | "hadd.pd.256" => mir::BinOp::Add,
@ -114,7 +114,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// if true. // if true.
"cmp.ps.256" => { "cmp.ps.256" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = let which =
FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?; FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?;
@ -127,7 +127,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// if true. // if true.
"cmp.pd.256" => { "cmp.pd.256" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = let which =
FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?; FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?;
@ -138,7 +138,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// and _mm256_cvttpd_epi32 functions. // and _mm256_cvttpd_epi32 functions.
// Converts packed f32/f64 to packed i32. // Converts packed f32/f64 to packed i32.
"cvt.ps2dq.256" | "cvtt.ps2dq.256" | "cvt.pd2dq.256" | "cvtt.pd2dq.256" => { "cvt.ps2dq.256" | "cvtt.ps2dq.256" | "cvt.pd2dq.256" | "cvtt.pd2dq.256" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let rnd = match unprefixed_name { let rnd = match unprefixed_name {
// "current SSE rounding mode", assume nearest // "current SSE rounding mode", assume nearest
@ -157,7 +157,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// `control` determines which element of the current `data` array is written. // `control` determines which element of the current `data` array is written.
"vpermilvar.ps" | "vpermilvar.ps.256" => { "vpermilvar.ps" | "vpermilvar.ps.256" => {
let [data, control] = let [data, control] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (data, data_len) = this.project_to_simd(data)?; let (data, data_len) = this.project_to_simd(data)?;
let (control, control_len) = this.project_to_simd(control)?; let (control, control_len) = this.project_to_simd(control)?;
@ -191,7 +191,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// written. // written.
"vpermilvar.pd" | "vpermilvar.pd.256" => { "vpermilvar.pd" | "vpermilvar.pd.256" => {
let [data, control] = let [data, control] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (data, data_len) = this.project_to_simd(data)?; let (data, data_len) = this.project_to_simd(data)?;
let (control, control_len) = this.project_to_simd(control)?; let (control, control_len) = this.project_to_simd(control)?;
@ -224,7 +224,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// zero, according to `imm`. // zero, according to `imm`.
"vperm2f128.ps.256" | "vperm2f128.pd.256" | "vperm2f128.si.256" => { "vperm2f128.ps.256" | "vperm2f128.pd.256" | "vperm2f128.si.256" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
assert_eq!(dest.layout, left.layout); assert_eq!(dest.layout, left.layout);
assert_eq!(dest.layout, right.layout); assert_eq!(dest.layout, right.layout);
@ -268,7 +268,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// loaded. // loaded.
"maskload.ps" | "maskload.pd" | "maskload.ps.256" | "maskload.pd.256" => { "maskload.ps" | "maskload.pd" | "maskload.ps.256" | "maskload.pd.256" => {
let [ptr, mask] = let [ptr, mask] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
mask_load(this, ptr, mask, dest)?; mask_load(this, ptr, mask, dest)?;
} }
@ -279,7 +279,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Unlike SSE2's _mm_maskmoveu_si128, these are not non-temporal stores. // Unlike SSE2's _mm_maskmoveu_si128, these are not non-temporal stores.
"maskstore.ps" | "maskstore.pd" | "maskstore.ps.256" | "maskstore.pd.256" => { "maskstore.ps" | "maskstore.pd" | "maskstore.ps.256" | "maskstore.pd.256" => {
let [ptr, mask, value] = let [ptr, mask, value] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
mask_store(this, ptr, mask, value)?; mask_store(this, ptr, mask, value)?;
} }
@ -289,7 +289,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// the data crosses a cache line, but for Miri this is just a regular // the data crosses a cache line, but for Miri this is just a regular
// unaligned read. // unaligned read.
"ldu.dq.256" => { "ldu.dq.256" => {
let [src_ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [src_ptr] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let src_ptr = this.read_pointer(src_ptr)?; let src_ptr = this.read_pointer(src_ptr)?;
let dest = dest.force_mplace(this)?; let dest = dest.force_mplace(this)?;
@ -301,7 +302,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Tests `op & mask == 0`, `op & mask == mask` or // Tests `op & mask == 0`, `op & mask == mask` or
// `op & mask != 0 && op & mask != mask` // `op & mask != 0 && op & mask != mask`
"ptestz.256" | "ptestc.256" | "ptestnzc.256" => { "ptestz.256" | "ptestc.256" | "ptestnzc.256" => {
let [op, mask] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op, mask] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (all_zero, masked_set) = test_bits_masked(this, op, mask)?; let (all_zero, masked_set) = test_bits_masked(this, op, mask)?;
let res = match unprefixed_name { let res = match unprefixed_name {
@ -324,7 +326,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"vtestz.pd.256" | "vtestc.pd.256" | "vtestnzc.pd.256" | "vtestz.pd" | "vtestc.pd" "vtestz.pd.256" | "vtestc.pd.256" | "vtestnzc.pd.256" | "vtestz.pd" | "vtestc.pd"
| "vtestnzc.pd" | "vtestz.ps.256" | "vtestc.ps.256" | "vtestnzc.ps.256" | "vtestnzc.pd" | "vtestz.ps.256" | "vtestc.ps.256" | "vtestnzc.ps.256"
| "vtestz.ps" | "vtestc.ps" | "vtestnzc.ps" => { | "vtestz.ps" | "vtestc.ps" | "vtestnzc.ps" => {
let [op, mask] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op, mask] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (direct, negated) = test_high_bits_masked(this, op, mask)?; let (direct, negated) = test_high_bits_masked(this, op, mask)?;
let res = match unprefixed_name { let res = match unprefixed_name {
@ -346,7 +349,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// compiler, making these functions no-ops. // compiler, making these functions no-ops.
// The only thing that needs to be ensured is the correct calling convention. // The only thing that needs to be ensured is the correct calling convention.
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
} }
_ => return interp_ok(EmulateItemResult::NotSupported), _ => return interp_ok(EmulateItemResult::NotSupported),
} }

View File

@ -1,8 +1,8 @@
use rustc_abi::ExternAbi;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::layout::LayoutOf as _;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::{ use super::{
ShiftOp, horizontal_bin_op, int_abs, mask_load, mask_store, mpsadbw, packssdw, packsswb, ShiftOp, horizontal_bin_op, int_abs, mask_load, mask_store, mpsadbw, packssdw, packsswb,
@ -15,7 +15,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_avx2_intrinsic( fn emulate_x86_avx2_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -28,7 +28,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Used to implement the _mm256_abs_epi{8,16,32} functions. // Used to implement the _mm256_abs_epi{8,16,32} functions.
// Calculates the absolute value of packed 8/16/32-bit integers. // Calculates the absolute value of packed 8/16/32-bit integers.
"pabs.b" | "pabs.w" | "pabs.d" => { "pabs.b" | "pabs.w" | "pabs.d" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
int_abs(this, op, dest)?; int_abs(this, op, dest)?;
} }
@ -37,7 +37,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// integer values in `left` and `right`. // integer values in `left` and `right`.
"phadd.w" | "phadd.sw" | "phadd.d" | "phsub.w" | "phsub.sw" | "phsub.d" => { "phadd.w" | "phadd.sw" | "phadd.d" | "phsub.w" | "phsub.sw" | "phsub.d" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (which, saturating) = match unprefixed_name { let (which, saturating) = match unprefixed_name {
"phadd.w" | "phadd.d" => (mir::BinOp::Add, false), "phadd.w" | "phadd.d" => (mir::BinOp::Add, false),
@ -58,7 +58,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "gather.d.pd.256" | "gather.q.pd" | "gather.q.pd.256" | "gather.d.ps" | "gather.d.pd.256" | "gather.q.pd" | "gather.q.pd.256" | "gather.d.ps"
| "gather.d.ps.256" | "gather.q.ps" | "gather.q.ps.256" => { | "gather.d.ps.256" | "gather.q.ps" | "gather.q.ps.256" => {
let [src, slice, offsets, mask, scale] = let [src, slice, offsets, mask, scale] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
assert_eq!(dest.layout, src.layout); assert_eq!(dest.layout, src.layout);
@ -116,7 +116,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// intermediate 32-bit integers, and pack the results in `dest`. // intermediate 32-bit integers, and pack the results in `dest`.
"pmadd.wd" => { "pmadd.wd" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -153,7 +153,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// produces the output at index `i`. // produces the output at index `i`.
"pmadd.ub.sw" => { "pmadd.ub.sw" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -188,7 +188,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// loaded. // loaded.
"maskload.d" | "maskload.q" | "maskload.d.256" | "maskload.q.256" => { "maskload.d" | "maskload.q" | "maskload.d.256" | "maskload.q.256" => {
let [ptr, mask] = let [ptr, mask] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
mask_load(this, ptr, mask, dest)?; mask_load(this, ptr, mask, dest)?;
} }
@ -199,7 +199,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Unlike SSE2's _mm_maskmoveu_si128, these are not non-temporal stores. // Unlike SSE2's _mm_maskmoveu_si128, these are not non-temporal stores.
"maskstore.d" | "maskstore.q" | "maskstore.d.256" | "maskstore.q.256" => { "maskstore.d" | "maskstore.q" | "maskstore.d.256" | "maskstore.q.256" => {
let [ptr, mask, value] = let [ptr, mask, value] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
mask_store(this, ptr, mask, value)?; mask_store(this, ptr, mask, value)?;
} }
@ -211,7 +211,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mpsadbw_epu8 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mpsadbw_epu8
"mpsadbw" => { "mpsadbw" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
mpsadbw(this, left, right, imm, dest)?; mpsadbw(this, left, right, imm, dest)?;
} }
@ -223,7 +223,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mulhrs_epi16 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_mulhrs_epi16
"pmul.hr.sw" => { "pmul.hr.sw" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
pmulhrsw(this, left, right, dest)?; pmulhrsw(this, left, right, dest)?;
} }
@ -232,7 +232,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// vector with signed saturation. // vector with signed saturation.
"packsswb" => { "packsswb" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packsswb(this, left, right, dest)?; packsswb(this, left, right, dest)?;
} }
@ -241,7 +241,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// vector with signed saturation. // vector with signed saturation.
"packssdw" => { "packssdw" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packssdw(this, left, right, dest)?; packssdw(this, left, right, dest)?;
} }
@ -250,7 +250,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// unsigned integer vector with saturation. // unsigned integer vector with saturation.
"packuswb" => { "packuswb" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packuswb(this, left, right, dest)?; packuswb(this, left, right, dest)?;
} }
@ -259,7 +259,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// the result to a 16-bit unsigned integer vector with saturation. // the result to a 16-bit unsigned integer vector with saturation.
"packusdw" => { "packusdw" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packusdw(this, left, right, dest)?; packusdw(this, left, right, dest)?;
} }
@ -269,7 +269,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// as indices. // as indices.
"permd" | "permps" => { "permd" | "permps" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -290,7 +290,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Shuffles 128-bit blocks of `a` and `b` using `imm` as pattern. // Shuffles 128-bit blocks of `a` and `b` using `imm` as pattern.
"vperm2i128" => { "vperm2i128" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
assert_eq!(left.layout.size.bits(), 256); assert_eq!(left.layout.size.bits(), 256);
assert_eq!(right.layout.size.bits(), 256); assert_eq!(right.layout.size.bits(), 256);
@ -328,7 +328,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sad_epu8 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm256_sad_epu8
"psad.bw" => { "psad.bw" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -361,7 +361,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Each 128-bit block is shuffled independently. // Each 128-bit block is shuffled independently.
"pshuf.b" => { "pshuf.b" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -393,7 +393,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Basically, we multiply `left` with `right.signum()`. // Basically, we multiply `left` with `right.signum()`.
"psign.b" | "psign.w" | "psign.d" => { "psign.b" | "psign.w" | "psign.d" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
psign(this, left, right, dest)?; psign(this, left, right, dest)?;
} }
@ -408,7 +408,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"psll.w" | "psrl.w" | "psra.w" | "psll.d" | "psrl.d" | "psra.d" | "psll.q" "psll.w" | "psrl.w" | "psra.w" | "psll.d" | "psrl.d" | "psra.d" | "psll.q"
| "psrl.q" => { | "psrl.q" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"psll.w" | "psll.d" | "psll.q" => ShiftOp::Left, "psll.w" | "psll.d" | "psll.q" => ShiftOp::Left,
@ -424,7 +424,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"psllv.d" | "psllv.d.256" | "psllv.q" | "psllv.q.256" | "psrlv.d" | "psrlv.d.256" "psllv.d" | "psllv.d.256" | "psllv.q" | "psllv.q.256" | "psrlv.d" | "psrlv.d.256"
| "psrlv.q" | "psrlv.q.256" | "psrav.d" | "psrav.d.256" => { | "psrlv.q" | "psrlv.q.256" | "psrav.d" | "psrav.d.256" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"psllv.d" | "psllv.d.256" | "psllv.q" | "psllv.q.256" => ShiftOp::Left, "psllv.d" | "psllv.d.256" | "psllv.q" | "psllv.q.256" => ShiftOp::Left,

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::*; use crate::*;
@ -8,7 +8,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_bmi_intrinsic( fn emulate_x86_bmi_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -33,7 +33,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
return interp_ok(EmulateItemResult::NotSupported); return interp_ok(EmulateItemResult::NotSupported);
} }
let [left, right] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [left, right] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let left = this.read_scalar(left)?; let left = this.read_scalar(left)?;
let right = this.read_scalar(right)?; let right = this.read_scalar(right)?;

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::*; use crate::*;
@ -8,7 +8,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_gfni_intrinsic( fn emulate_x86_gfni_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -30,7 +30,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8affine_ // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8affine_
"vgf2p8affineqb.128" | "vgf2p8affineqb.256" | "vgf2p8affineqb.512" => { "vgf2p8affineqb.128" | "vgf2p8affineqb.256" | "vgf2p8affineqb.512" => {
let [left, right, imm8] = let [left, right, imm8] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
affine_transform(this, left, right, imm8, dest, /* inverse */ false)?; affine_transform(this, left, right, imm8, dest, /* inverse */ false)?;
} }
// Used to implement the `_mm{, 256, 512}_gf2p8affineinv_epi64_epi8` functions. // Used to implement the `_mm{, 256, 512}_gf2p8affineinv_epi64_epi8` functions.
@ -38,7 +38,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8affineinv // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8affineinv
"vgf2p8affineinvqb.128" | "vgf2p8affineinvqb.256" | "vgf2p8affineinvqb.512" => { "vgf2p8affineinvqb.128" | "vgf2p8affineinvqb.256" | "vgf2p8affineinvqb.512" => {
let [left, right, imm8] = let [left, right, imm8] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
affine_transform(this, left, right, imm8, dest, /* inverse */ true)?; affine_transform(this, left, right, imm8, dest, /* inverse */ true)?;
} }
// Used to implement the `_mm{, 256, 512}_gf2p8mul_epi8` functions. // Used to implement the `_mm{, 256, 512}_gf2p8mul_epi8` functions.
@ -48,7 +48,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8mul // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=gf2p8mul
"vgf2p8mulb.128" | "vgf2p8mulb.256" | "vgf2p8mulb.512" => { "vgf2p8mulb.128" | "vgf2p8mulb.256" | "vgf2p8mulb.512" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;

View File

@ -1,12 +1,11 @@
use rand::Rng as _; use rand::Rng as _;
use rustc_abi::{ExternAbi, Size};
use rustc_apfloat::Float; use rustc_apfloat::Float;
use rustc_apfloat::ieee::Single; use rustc_apfloat::ieee::Single;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::layout::LayoutOf as _;
use rustc_middle::{mir, ty}; use rustc_middle::{mir, ty};
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use self::helpers::bool_to_simd_element; use self::helpers::bool_to_simd_element;
use crate::*; use crate::*;
@ -29,7 +28,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_intrinsic( fn emulate_x86_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -47,7 +46,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
return interp_ok(EmulateItemResult::NotSupported); return interp_ok(EmulateItemResult::NotSupported);
} }
let [cb_in, a, b] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?; let [cb_in, a, b] = this.check_shim(abi, ExternAbi::Unadjusted, link_name, args)?;
let op = if unprefixed_name.starts_with("add") { let op = if unprefixed_name.starts_with("add") {
mir::BinOp::AddWithOverflow mir::BinOp::AddWithOverflow
@ -71,7 +70,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
return interp_ok(EmulateItemResult::NotSupported); return interp_ok(EmulateItemResult::NotSupported);
} }
let [c_in, a, b, out] = this.check_shim(abi, Abi::Unadjusted, link_name, args)?; let [c_in, a, b, out] =
this.check_shim(abi, ExternAbi::Unadjusted, link_name, args)?;
let out = this.deref_pointer_as( let out = this.deref_pointer_as(
out, out,
if is_u64 { this.machine.layouts.u64 } else { this.machine.layouts.u32 }, if is_u64 { this.machine.layouts.u64 } else { this.machine.layouts.u32 },
@ -88,7 +88,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// the instruction behaves like a no-op, so it is always safe to call the // the instruction behaves like a no-op, so it is always safe to call the
// intrinsic. // intrinsic.
"sse2.pause" => { "sse2.pause" => {
let [] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
// Only exhibit the spin-loop hint behavior when SSE2 is enabled. // Only exhibit the spin-loop hint behavior when SSE2 is enabled.
if this.tcx.sess.unstable_target_features.contains(&Symbol::intern("sse2")) { if this.tcx.sess.unstable_target_features.contains(&Symbol::intern("sse2")) {
this.yield_active_thread(); this.yield_active_thread();
@ -97,7 +97,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"pclmulqdq" => { "pclmulqdq" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
pclmulqdq(this, left, right, imm, dest)?; pclmulqdq(this, left, right, imm, dest)?;
} }

View File

@ -4,8 +4,8 @@
//! //!
//! [RustCrypto's sha256 module]: https://github.com/RustCrypto/hashes/blob/6be8466247e936c415d8aafb848697f39894a386/sha2/src/sha256/soft.rs //! [RustCrypto's sha256 module]: https://github.com/RustCrypto/hashes/blob/6be8466247e936c415d8aafb848697f39894a386/sha2/src/sha256/soft.rs
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use crate::*; use crate::*;
@ -14,7 +14,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_sha_intrinsic( fn emulate_x86_sha_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -51,7 +51,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
match unprefixed_name { match unprefixed_name {
// Used to implement the _mm_sha256rnds2_epu32 function. // Used to implement the _mm_sha256rnds2_epu32 function.
"256rnds2" => { "256rnds2" => {
let [a, b, k] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [a, b, k] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (a_reg, a_len) = this.project_to_simd(a)?; let (a_reg, a_len) = this.project_to_simd(a)?;
let (b_reg, b_len) = this.project_to_simd(b)?; let (b_reg, b_len) = this.project_to_simd(b)?;
@ -72,7 +73,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
// Used to implement the _mm_sha256msg1_epu32 function. // Used to implement the _mm_sha256msg1_epu32 function.
"256msg1" => { "256msg1" => {
let [a, b] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [a, b] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (a_reg, a_len) = this.project_to_simd(a)?; let (a_reg, a_len) = this.project_to_simd(a)?;
let (b_reg, b_len) = this.project_to_simd(b)?; let (b_reg, b_len) = this.project_to_simd(b)?;
@ -90,7 +92,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
// Used to implement the _mm_sha256msg2_epu32 function. // Used to implement the _mm_sha256msg2_epu32 function.
"256msg2" => { "256msg2" => {
let [a, b] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [a, b] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (a_reg, a_len) = this.project_to_simd(a)?; let (a_reg, a_len) = this.project_to_simd(a)?;
let (b_reg, b_len) = this.project_to_simd(b)?; let (b_reg, b_len) = this.project_to_simd(b)?;

View File

@ -1,6 +1,6 @@
use rustc_abi::ExternAbi;
use rustc_apfloat::ieee::Single; use rustc_apfloat::ieee::Single;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::{ use super::{
FloatBinOp, FloatUnaryOp, bin_op_simd_float_all, bin_op_simd_float_first, unary_op_ps, FloatBinOp, FloatUnaryOp, bin_op_simd_float_all, bin_op_simd_float_first, unary_op_ps,
@ -13,7 +13,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_sse_intrinsic( fn emulate_x86_sse_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -33,7 +33,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// `right` and copies the remaining components from `left`. // `right` and copies the remaining components from `left`.
"min.ss" | "max.ss" => { "min.ss" | "max.ss" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"min.ss" => FloatBinOp::Min, "min.ss" => FloatBinOp::Min,
@ -50,7 +50,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// semantics. // semantics.
"min.ps" | "max.ps" => { "min.ps" | "max.ps" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"min.ps" => FloatBinOp::Min, "min.ps" => FloatBinOp::Min,
@ -64,7 +64,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Performs the operations on the first component of `op` and // Performs the operations on the first component of `op` and
// copies the remaining components from `op`. // copies the remaining components from `op`.
"rcp.ss" | "rsqrt.ss" => { "rcp.ss" | "rsqrt.ss" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"rcp.ss" => FloatUnaryOp::Rcp, "rcp.ss" => FloatUnaryOp::Rcp,
@ -77,7 +77,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Used to implement _mm_{sqrt,rcp,rsqrt}_ps functions. // Used to implement _mm_{sqrt,rcp,rsqrt}_ps functions.
// Performs the operations on all components of `op`. // Performs the operations on all components of `op`.
"rcp.ps" | "rsqrt.ps" => { "rcp.ps" | "rsqrt.ps" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"rcp.ps" => FloatUnaryOp::Rcp, "rcp.ps" => FloatUnaryOp::Rcp,
@ -97,7 +97,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// with hard-coded operations. // with hard-coded operations.
"cmp.ss" => { "cmp.ss" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = let which =
FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?; FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?;
@ -114,7 +114,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// with hard-coded operations. // with hard-coded operations.
"cmp.ps" => { "cmp.ps" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = let which =
FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?; FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?;
@ -128,7 +128,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "ucomieq.ss" | "ucomilt.ss" | "ucomile.ss" | "ucomigt.ss" | "ucomige.ss" | "ucomieq.ss" | "ucomilt.ss" | "ucomile.ss" | "ucomigt.ss" | "ucomige.ss"
| "ucomineq.ss" => { | "ucomineq.ss" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -156,7 +156,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// _mm_cvtss_si64 and _mm_cvttss_si64 functions. // _mm_cvtss_si64 and _mm_cvttss_si64 functions.
// Converts the first component of `op` from f32 to i32/i64. // Converts the first component of `op` from f32 to i32/i64.
"cvtss2si" | "cvttss2si" | "cvtss2si64" | "cvttss2si64" => { "cvtss2si" | "cvttss2si" | "cvtss2si64" | "cvttss2si64" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (op, _) = this.project_to_simd(op)?; let (op, _) = this.project_to_simd(op)?;
let op = this.read_immediate(&this.project_index(&op, 0)?)?; let op = this.read_immediate(&this.project_index(&op, 0)?)?;
@ -185,7 +185,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.felixcloutier.com/x86/cvtsi2ss // https://www.felixcloutier.com/x86/cvtsi2ss
"cvtsi2ss" | "cvtsi642ss" => { "cvtsi2ss" | "cvtsi642ss" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (dest, dest_len) = this.project_to_simd(dest)?; let (dest, dest_len) = this.project_to_simd(dest)?;

View File

@ -1,6 +1,6 @@
use rustc_abi::ExternAbi;
use rustc_apfloat::ieee::Double; use rustc_apfloat::ieee::Double;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::{ use super::{
FloatBinOp, ShiftOp, bin_op_simd_float_all, bin_op_simd_float_first, convert_float_to_int, FloatBinOp, ShiftOp, bin_op_simd_float_all, bin_op_simd_float_first, convert_float_to_int,
@ -13,7 +13,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_sse2_intrinsic( fn emulate_x86_sse2_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -40,7 +40,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// intermediate 32-bit integers, and pack the results in `dest`. // intermediate 32-bit integers, and pack the results in `dest`.
"pmadd.wd" => { "pmadd.wd" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -79,7 +79,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sad_epu8 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_sad_epu8
"psad.bw" => { "psad.bw" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -118,7 +118,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"psll.w" | "psrl.w" | "psra.w" | "psll.d" | "psrl.d" | "psra.d" | "psll.q" "psll.w" | "psrl.w" | "psra.w" | "psll.d" | "psrl.d" | "psra.d" | "psll.q"
| "psrl.q" => { | "psrl.q" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"psll.w" | "psll.d" | "psll.q" => ShiftOp::Left, "psll.w" | "psll.d" | "psll.q" => ShiftOp::Left,
@ -133,7 +133,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// and _mm_cvttpd_epi32 functions. // and _mm_cvttpd_epi32 functions.
// Converts packed f32/f64 to packed i32. // Converts packed f32/f64 to packed i32.
"cvtps2dq" | "cvttps2dq" | "cvtpd2dq" | "cvttpd2dq" => { "cvtps2dq" | "cvttps2dq" | "cvtpd2dq" | "cvttpd2dq" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (op_len, _) = op.layout.ty.simd_size_and_type(*this.tcx); let (op_len, _) = op.layout.ty.simd_size_and_type(*this.tcx);
let (dest_len, _) = dest.layout.ty.simd_size_and_type(*this.tcx); let (dest_len, _) = dest.layout.ty.simd_size_and_type(*this.tcx);
@ -171,7 +171,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// vector with signed saturation. // vector with signed saturation.
"packsswb.128" => { "packsswb.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packsswb(this, left, right, dest)?; packsswb(this, left, right, dest)?;
} }
@ -180,7 +180,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// unsigned integer vector with saturation. // unsigned integer vector with saturation.
"packuswb.128" => { "packuswb.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packuswb(this, left, right, dest)?; packuswb(this, left, right, dest)?;
} }
@ -189,7 +189,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// vector with signed saturation. // vector with signed saturation.
"packssdw.128" => { "packssdw.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packssdw(this, left, right, dest)?; packssdw(this, left, right, dest)?;
} }
@ -200,7 +200,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// semantics. // semantics.
"min.sd" | "max.sd" => { "min.sd" | "max.sd" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"min.sd" => FloatBinOp::Min, "min.sd" => FloatBinOp::Min,
@ -217,7 +217,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// semantics. // semantics.
"min.pd" | "max.pd" => { "min.pd" | "max.pd" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"min.pd" => FloatBinOp::Min, "min.pd" => FloatBinOp::Min,
@ -237,7 +237,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// with hard-coded operations. // with hard-coded operations.
"cmp.sd" => { "cmp.sd" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = let which =
FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?; FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?;
@ -254,7 +254,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// with hard-coded operations. // with hard-coded operations.
"cmp.pd" => { "cmp.pd" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = let which =
FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?; FloatBinOp::cmp_from_imm(this, this.read_scalar(imm)?.to_i8()?, link_name)?;
@ -268,7 +268,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
| "ucomieq.sd" | "ucomilt.sd" | "ucomile.sd" | "ucomigt.sd" | "ucomige.sd" | "ucomieq.sd" | "ucomilt.sd" | "ucomile.sd" | "ucomigt.sd" | "ucomige.sd"
| "ucomineq.sd" => { | "ucomineq.sd" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -296,7 +296,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// _mm_cvtsd_si64 and _mm_cvttsd_si64 functions. // _mm_cvtsd_si64 and _mm_cvttsd_si64 functions.
// Converts the first component of `op` from f64 to i32/i64. // Converts the first component of `op` from f64 to i32/i64.
"cvtsd2si" | "cvttsd2si" | "cvtsd2si64" | "cvttsd2si64" => { "cvtsd2si" | "cvttsd2si" | "cvtsd2si64" | "cvttsd2si64" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (op, _) = this.project_to_simd(op)?; let (op, _) = this.project_to_simd(op)?;
let op = this.read_immediate(&this.project_index(&op, 0)?)?; let op = this.read_immediate(&this.project_index(&op, 0)?)?;
@ -323,7 +323,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// the remaining elements from `left` // the remaining elements from `left`
"cvtsd2ss" | "cvtss2sd" => { "cvtsd2ss" | "cvtss2sd" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, _) = this.project_to_simd(right)?; let (right, _) = this.project_to_simd(right)?;

View File

@ -1,6 +1,6 @@
use rustc_abi::ExternAbi;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::horizontal_bin_op; use super::horizontal_bin_op;
use crate::*; use crate::*;
@ -10,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_sse3_intrinsic( fn emulate_x86_sse3_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -25,7 +25,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// in `left` and `right`. // in `left` and `right`.
"hadd.ps" | "hadd.pd" | "hsub.ps" | "hsub.pd" => { "hadd.ps" | "hadd.pd" | "hsub.ps" | "hsub.pd" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let which = match unprefixed_name { let which = match unprefixed_name {
"hadd.ps" | "hadd.pd" => mir::BinOp::Add, "hadd.ps" | "hadd.pd" => mir::BinOp::Add,
@ -41,7 +41,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// the data crosses a cache line, but for Miri this is just a regular // the data crosses a cache line, but for Miri this is just a regular
// unaligned read. // unaligned read.
"ldu.dq" => { "ldu.dq" => {
let [src_ptr] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [src_ptr] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let src_ptr = this.read_pointer(src_ptr)?; let src_ptr = this.read_pointer(src_ptr)?;
let dest = dest.force_mplace(this)?; let dest = dest.force_mplace(this)?;

View File

@ -1,5 +1,5 @@
use rustc_abi::ExternAbi;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::{conditional_dot_product, mpsadbw, packusdw, round_all, round_first, test_bits_masked}; use super::{conditional_dot_product, mpsadbw, packusdw, round_all, round_first, test_bits_masked};
use crate::*; use crate::*;
@ -9,7 +9,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_sse41_intrinsic( fn emulate_x86_sse41_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -27,7 +27,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// `i` is zeroed. // `i` is zeroed.
"insertps" => { "insertps" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -63,7 +63,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// the result to a 16-bit unsigned integer vector with saturation. // the result to a 16-bit unsigned integer vector with saturation.
"packusdw" => { "packusdw" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
packusdw(this, left, right, dest)?; packusdw(this, left, right, dest)?;
} }
@ -74,7 +74,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// 4 bits of `imm`. // 4 bits of `imm`.
"dpps" | "dppd" => { "dpps" | "dppd" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
conditional_dot_product(this, left, right, imm, dest)?; conditional_dot_product(this, left, right, imm, dest)?;
} }
@ -83,7 +83,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// and copies the remaining elements from `left`. // and copies the remaining elements from `left`.
"round.ss" => { "round.ss" => {
let [left, right, rounding] = let [left, right, rounding] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
round_first::<rustc_apfloat::ieee::Single>(this, left, right, rounding, dest)?; round_first::<rustc_apfloat::ieee::Single>(this, left, right, rounding, dest)?;
} }
@ -91,7 +91,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// functions. Rounds the elements of `op` according to `rounding`. // functions. Rounds the elements of `op` according to `rounding`.
"round.ps" => { "round.ps" => {
let [op, rounding] = let [op, rounding] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
round_all::<rustc_apfloat::ieee::Single>(this, op, rounding, dest)?; round_all::<rustc_apfloat::ieee::Single>(this, op, rounding, dest)?;
} }
@ -100,7 +100,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// and copies the remaining elements from `left`. // and copies the remaining elements from `left`.
"round.sd" => { "round.sd" => {
let [left, right, rounding] = let [left, right, rounding] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
round_first::<rustc_apfloat::ieee::Double>(this, left, right, rounding, dest)?; round_first::<rustc_apfloat::ieee::Double>(this, left, right, rounding, dest)?;
} }
@ -108,7 +108,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// functions. Rounds the elements of `op` according to `rounding`. // functions. Rounds the elements of `op` according to `rounding`.
"round.pd" => { "round.pd" => {
let [op, rounding] = let [op, rounding] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
round_all::<rustc_apfloat::ieee::Double>(this, op, rounding, dest)?; round_all::<rustc_apfloat::ieee::Double>(this, op, rounding, dest)?;
} }
@ -116,7 +116,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Find the minimum unsinged 16-bit integer in `op` and // Find the minimum unsinged 16-bit integer in `op` and
// returns its value and position. // returns its value and position.
"phminposuw" => { "phminposuw" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (op, op_len) = this.project_to_simd(op)?; let (op, op_len) = this.project_to_simd(op)?;
let (dest, dest_len) = this.project_to_simd(dest)?; let (dest, dest_len) = this.project_to_simd(dest)?;
@ -151,7 +151,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mpsadbw_epu8 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mpsadbw_epu8
"mpsadbw" => { "mpsadbw" => {
let [left, right, imm] = let [left, right, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
mpsadbw(this, left, right, imm, dest)?; mpsadbw(this, left, right, imm, dest)?;
} }
@ -160,7 +160,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Tests `(op & mask) == 0`, `(op & mask) == mask` or // Tests `(op & mask) == 0`, `(op & mask) == mask` or
// `(op & mask) != 0 && (op & mask) != mask` // `(op & mask) != 0 && (op & mask) != mask`
"ptestz" | "ptestc" | "ptestnzc" => { "ptestz" | "ptestc" | "ptestnzc" => {
let [op, mask] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op, mask] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (all_zero, masked_set) = test_bits_masked(this, op, mask)?; let (all_zero, masked_set) = test_bits_masked(this, op, mask)?;
let res = match unprefixed_name { let res = match unprefixed_name {

View File

@ -1,9 +1,8 @@
use rustc_abi::{ExternAbi, Size};
use rustc_middle::mir; use rustc_middle::mir;
use rustc_middle::ty::Ty; use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::layout::LayoutOf as _;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::abi::Size;
use rustc_target::spec::abi::Abi;
use crate::*; use crate::*;
@ -201,7 +200,7 @@ fn deconstruct_args<'tcx>(
unprefixed_name: &str, unprefixed_name: &str,
this: &mut MiriInterpCx<'tcx>, this: &mut MiriInterpCx<'tcx>,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
) -> InterpResult<'tcx, (OpTy<'tcx>, OpTy<'tcx>, Option<(u64, u64)>, u8)> { ) -> InterpResult<'tcx, (OpTy<'tcx>, OpTy<'tcx>, Option<(u64, u64)>, u8)> {
let array_layout_fn = |this: &mut MiriInterpCx<'tcx>, imm: u8| { let array_layout_fn = |this: &mut MiriInterpCx<'tcx>, imm: u8| {
@ -224,7 +223,7 @@ fn deconstruct_args<'tcx>(
if is_explicit { if is_explicit {
let [str1, len1, str2, len2, imm] = let [str1, len1, str2, len2, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let imm = this.read_scalar(imm)?.to_u8()?; let imm = this.read_scalar(imm)?.to_u8()?;
let default_len = default_len::<u32>(imm); let default_len = default_len::<u32>(imm);
@ -237,7 +236,8 @@ fn deconstruct_args<'tcx>(
interp_ok((str1, str2, Some((len1, len2)), imm)) interp_ok((str1, str2, Some((len1, len2)), imm))
} else { } else {
let [str1, str2, imm] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [str1, str2, imm] =
this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let imm = this.read_scalar(imm)?.to_u8()?; let imm = this.read_scalar(imm)?.to_u8()?;
let array_layout = array_layout_fn(this, imm)?; let array_layout = array_layout_fn(this, imm)?;
@ -279,7 +279,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_sse42_intrinsic( fn emulate_x86_sse42_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -388,7 +388,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#ig_expand=924,925 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#ig_expand=924,925
"pcmpistriz128" | "pcmpistris128" => { "pcmpistriz128" | "pcmpistris128" => {
let [str1, str2, imm] = let [str1, str2, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let imm = this.read_scalar(imm)?.to_u8()?; let imm = this.read_scalar(imm)?.to_u8()?;
let str = if unprefixed_name == "pcmpistris128" { str1 } else { str2 }; let str = if unprefixed_name == "pcmpistris128" { str1 } else { str2 };
@ -409,7 +409,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#ig_expand=1046,1047 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#ig_expand=1046,1047
"pcmpestriz128" | "pcmpestris128" => { "pcmpestriz128" | "pcmpestris128" => {
let [_, len1, _, len2, imm] = let [_, len1, _, len2, imm] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let len = if unprefixed_name == "pcmpestris128" { len1 } else { len2 }; let len = if unprefixed_name == "pcmpestris128" { len1 } else { len2 };
let len = this.read_scalar(len)?.to_i32()?; let len = this.read_scalar(len)?.to_i32()?;
let imm = this.read_scalar(imm)?.to_u8()?; let imm = this.read_scalar(imm)?.to_u8()?;
@ -437,7 +437,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
} }
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let left = this.read_scalar(left)?; let left = this.read_scalar(left)?;
let right = this.read_scalar(right)?; let right = this.read_scalar(right)?;

View File

@ -1,6 +1,6 @@
use rustc_abi::ExternAbi;
use rustc_middle::mir; use rustc_middle::mir;
use rustc_span::Symbol; use rustc_span::Symbol;
use rustc_target::spec::abi::Abi;
use super::{horizontal_bin_op, int_abs, pmulhrsw, psign}; use super::{horizontal_bin_op, int_abs, pmulhrsw, psign};
use crate::*; use crate::*;
@ -10,7 +10,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn emulate_x86_ssse3_intrinsic( fn emulate_x86_ssse3_intrinsic(
&mut self, &mut self,
link_name: Symbol, link_name: Symbol,
abi: Abi, abi: ExternAbi,
args: &[OpTy<'tcx>], args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>, dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx, EmulateItemResult> { ) -> InterpResult<'tcx, EmulateItemResult> {
@ -23,7 +23,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Used to implement the _mm_abs_epi{8,16,32} functions. // Used to implement the _mm_abs_epi{8,16,32} functions.
// Calculates the absolute value of packed 8/16/32-bit integers. // Calculates the absolute value of packed 8/16/32-bit integers.
"pabs.b.128" | "pabs.w.128" | "pabs.d.128" => { "pabs.b.128" | "pabs.w.128" | "pabs.d.128" => {
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; let [op] = this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
int_abs(this, op, dest)?; int_abs(this, op, dest)?;
} }
@ -32,7 +32,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_epi8 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_shuffle_epi8
"pshuf.b.128" => { "pshuf.b.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -62,7 +62,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
"phadd.w.128" | "phadd.sw.128" | "phadd.d.128" | "phsub.w.128" | "phsub.sw.128" "phadd.w.128" | "phadd.sw.128" | "phadd.d.128" | "phsub.w.128" | "phsub.sw.128"
| "phsub.d.128" => { | "phsub.d.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (which, saturating) = match unprefixed_name { let (which, saturating) = match unprefixed_name {
"phadd.w.128" | "phadd.d.128" => (mir::BinOp::Add, false), "phadd.w.128" | "phadd.d.128" => (mir::BinOp::Add, false),
@ -82,7 +82,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maddubs_epi16 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_maddubs_epi16
"pmadd.ub.sw.128" => { "pmadd.ub.sw.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
let (left, left_len) = this.project_to_simd(left)?; let (left, left_len) = this.project_to_simd(left)?;
let (right, right_len) = this.project_to_simd(right)?; let (right, right_len) = this.project_to_simd(right)?;
@ -118,7 +118,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhrs_epi16 // https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_mulhrs_epi16
"pmul.hr.sw.128" => { "pmul.hr.sw.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
pmulhrsw(this, left, right, dest)?; pmulhrsw(this, left, right, dest)?;
} }
@ -129,7 +129,7 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
// Basically, we multiply `left` with `right.signum()`. // Basically, we multiply `left` with `right.signum()`.
"psign.b.128" | "psign.w.128" | "psign.d.128" => { "psign.b.128" | "psign.w.128" | "psign.d.128" => {
let [left, right] = let [left, right] =
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?; this.check_shim(abi, ExternAbi::C { unwind: false }, link_name, args)?;
psign(this, left, right, dest)?; psign(this, left, right, dest)?;
} }