Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 7 pull requests #62428

Merged
merged 35 commits into from
Jul 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
16b37b5
Update linked OpenSSL version
alexcrichton Jun 26, 2019
05f4a57
forward read_c_str method from Memory to Alloc
RalfJung Jun 30, 2019
2bad604
request at least ptr-size alignment from posix_memalign
RalfJung Jul 2, 2019
576369b
improve and deduplicate comments
RalfJung Jul 2, 2019
45e7ba9
test more possible overaligned requests
RalfJung Jul 2, 2019
2e47fc3
fix unused-import error on android
RalfJung Jul 3, 2019
830ff4a
remove StringReader::peek
matklad Jul 2, 2019
e9dc95c
remove peek_token from StringReader
matklad Jul 2, 2019
256df83
remove peek_span_src_raw from StringReader
matklad Jul 3, 2019
601bad8
cleanup lexer constructors
matklad Jul 3, 2019
30fa99e
move constructors to top
matklad Jul 3, 2019
1c6eb19
slightly comment lexer API
matklad Jul 3, 2019
8bea334
don't rely on spans when checking tokens for jointness
matklad Jul 3, 2019
3035a05
remove unused mk_sp_and_raw
matklad Jul 3, 2019
3e362a4
make unwrap_or_abort non-generic again
matklad Jul 3, 2019
8ad28cd
Machine: make self-like parameters come first
RalfJung Jul 2, 2019
127610b
Go back to just passing MemoryExtra to the machine-level allocation h…
RalfJung Jul 2, 2019
1297a27
Add basic support for "other" kinds of values for function pointers, …
RalfJung Jun 30, 2019
5612feb
add machine hook to handle calls to 'extra' function values
RalfJung Jun 30, 2019
486720f
fix determinig the size of foreign static allocations
RalfJung Jun 30, 2019
b4be08a
fix for tidy
RalfJung Jun 30, 2019
842bbd2
make Memory::get_fn take a Scalar like most of the Memory API surface
RalfJung Jul 1, 2019
956a3ef
more inlining
RalfJung Jul 2, 2019
52e6f85
organize methods a bit better
RalfJung Jul 2, 2019
317c6ac
use get_size_and_align to test if an allocation is live
RalfJung Jul 1, 2019
d9d6b3b
turns out that dangling pointer branch is dead code; remove it and im…
RalfJung Jul 1, 2019
ceb496c
improve validity error range printing for singleton ranges
RalfJung Jul 1, 2019
12672e2
Add test for ICE #62375
wesleywiser Jul 4, 2019
a8f8c7c
Rollup merge of #62151 - alexcrichton:update-openssl, r=Mark-Simulacrum
Centril Jul 6, 2019
182248a
Rollup merge of #62245 - RalfJung:miri-extra-fn, r=eddyb,zackmdavis
Centril Jul 6, 2019
947d7cf
Rollup merge of #62257 - RalfJung:miri-c-str, r=estebank
Centril Jul 6, 2019
0383be8
Rollup merge of #62264 - RalfJung:inline-forcing, r=zackmdavis
Centril Jul 6, 2019
3c4a6c8
Rollup merge of #62296 - RalfJung:memalign, r=alexcrichton
Centril Jul 6, 2019
952ee77
Rollup merge of #62329 - matklad:no-peeking, r=petrochenkov
Centril Jul 6, 2019
46edb51
Rollup merge of #62377 - wesleywiser:fix_62375, r=alexcrichton
Centril Jul 6, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1835,7 +1835,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"

[[package]]
name = "openssl-src"
version = "111.1.0+1.1.1a"
version = "111.3.0+1.1.1c"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
Expand All @@ -1848,7 +1848,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"cc 1.0.35 (registry+https://github.com/rust-lang/crates.io-index)",
"libc 0.2.54 (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)",
"openssl-src 111.3.0+1.1.1c (registry+https://github.com/rust-lang/crates.io-index)",
"pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
"vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)",
Expand Down Expand Up @@ -4384,7 +4384,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum opener 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "998c59e83d9474c01127a96e023b7a04bb061dd286bf8bb939d31dc8d31a7448"
"checksum openssl 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ec7bd7ca4cce6dbdc77e7c1230682740d307d1218a87fb0349a571272be749f9"
"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de"
"checksum openssl-src 111.1.0+1.1.1a (registry+https://github.com/rust-lang/crates.io-index)" = "26bb632127731bf4ac49bf86a5dde12d2ca0918c2234fc39d79d4da2ccbc6da7"
"checksum openssl-src 111.3.0+1.1.1c (registry+https://github.com/rust-lang/crates.io-index)" = "53ed5f31d294bdf5f7a4ba0a206c2754b0f60e9a63b7e3076babc5317873c797"
"checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d"
"checksum ordermap 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a86ed3f5f244b372d6b1a00b72ef7f8876d0bc6a78a4c9985c53614041512063"
"checksum ordslice 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dd20eec3dbe4376829cb7d80ae6ac45e0a766831dca50202ff2d40db46a8a024"
Expand Down
32 changes: 17 additions & 15 deletions src/liballoc/tests/heap.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::alloc::{Global, Alloc, Layout, System};

/// Issue #45955.
/// Issue #45955 and #62251.
#[test]
fn alloc_system_overaligned_request() {
check_overalign_requests(System)
Expand All @@ -12,21 +12,23 @@ fn std_heap_overaligned_request() {
}

fn check_overalign_requests<T: Alloc>(mut allocator: T) {
let size = 8;
let align = 16; // greater than size
let iterations = 100;
unsafe {
let pointers: Vec<_> = (0..iterations).map(|_| {
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
}).collect();
for &ptr in &pointers {
assert_eq!((ptr.as_ptr() as usize) % align, 0,
"Got a pointer less aligned than requested")
}
for &align in &[4, 8, 16, 32] { // less than and bigger than `MIN_ALIGN`
for &size in &[align/2, align-1] { // size less than alignment
let iterations = 128;
unsafe {
let pointers: Vec<_> = (0..iterations).map(|_| {
allocator.alloc(Layout::from_size_align(size, align).unwrap()).unwrap()
}).collect();
for &ptr in &pointers {
assert_eq!((ptr.as_ptr() as usize) % align, 0,
"Got a pointer less aligned than requested")
}

// Clean up
for &ptr in &pointers {
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
// Clean up
for &ptr in &pointers {
allocator.dealloc(ptr, Layout::from_size_align(size, align).unwrap())
}
}
}
}
}
21 changes: 16 additions & 5 deletions src/librustc_mir/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc::hir::def::DefKind;
use rustc::hir::def_id::DefId;
use rustc::mir::interpret::{ConstEvalErr, ErrorHandled, ScalarMaybeUndef};
use rustc::mir;
use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
use rustc::ty::{self, TyCtxt};
use rustc::ty::layout::{self, LayoutOf, VariantIdx};
use rustc::ty::subst::Subst;
use rustc::traits::Reveal;
Expand All @@ -23,7 +23,7 @@ use crate::interpret::{self,
PlaceTy, MPlaceTy, OpTy, ImmTy, Immediate, Scalar,
RawConst, ConstValue,
InterpResult, InterpErrorInfo, InterpError, GlobalId, InterpCx, StackPopCleanup,
Allocation, AllocId, MemoryKind, Memory,
Allocation, AllocId, MemoryKind,
snapshot, RefTracking, intern_const_alloc_recursive,
};

Expand Down Expand Up @@ -316,6 +316,7 @@ impl interpret::MayLeak for ! {
impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, 'tcx> {
type MemoryKinds = !;
type PointerTag = ();
type ExtraFnVal = !;

type FrameExtra = ();
type MemoryExtra = ();
Expand Down Expand Up @@ -370,6 +371,16 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
}))
}

fn call_extra_fn(
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
fn_val: !,
_args: &[OpTy<'tcx>],
_dest: Option<PlaceTy<'tcx>>,
_ret: Option<mir::BasicBlock>,
) -> InterpResult<'tcx> {
match fn_val {}
}

fn call_intrinsic(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
instance: ty::Instance<'tcx>,
Expand Down Expand Up @@ -398,27 +409,27 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
}

fn find_foreign_static(
_tcx: TyCtxt<'tcx>,
_def_id: DefId,
_tcx: TyCtxtAt<'tcx>,
) -> InterpResult<'tcx, Cow<'tcx, Allocation<Self::PointerTag>>> {
err!(ReadForeignStatic)
}

#[inline(always)]
fn tag_allocation<'b>(
_memory_extra: &(),
_id: AllocId,
alloc: Cow<'b, Allocation>,
_kind: Option<MemoryKind<!>>,
_memory: &Memory<'mir, 'tcx, Self>,
) -> (Cow<'b, Allocation<Self::PointerTag>>, Self::PointerTag) {
// We do not use a tag so we can just cheaply forward the allocation
(alloc, ())
}

#[inline(always)]
fn tag_static_base_pointer(
_memory_extra: &(),
_id: AllocId,
_memory: &Memory<'mir, 'tcx, Self>,
) -> Self::PointerTag {
()
}
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use rustc::mir::interpret::{
};
use rustc::mir::CastKind;

use super::{InterpCx, Machine, PlaceTy, OpTy, Immediate};
use super::{InterpCx, Machine, PlaceTy, OpTy, Immediate, FnVal};

impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
fn type_is_fat_ptr(&self, ty: Ty<'tcx>) -> bool {
Expand Down Expand Up @@ -86,7 +86,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
def_id,
substs,
).ok_or_else(|| InterpError::TooGeneric.into());
let fn_ptr = self.memory.create_fn_alloc(instance?);
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance?));
self.write_scalar(Scalar::Ptr(fn_ptr.into()), dest)?;
}
_ => bug!("reify fn pointer on {:?}", src.layout.ty),
Expand Down Expand Up @@ -115,7 +115,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
substs,
ty::ClosureKind::FnOnce,
);
let fn_ptr = self.memory.create_fn_alloc(instance);
let fn_ptr = self.memory.create_fn_alloc(FnVal::Instance(instance));
let val = Immediate::Scalar(Scalar::Ptr(fn_ptr.into()).into());
self.write_immediate(val, dest)?;
}
Expand Down
74 changes: 38 additions & 36 deletions src/librustc_mir/interpret/eval_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,23 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
&mut self.memory
}

#[inline(always)]
pub fn force_ptr(
&self,
scalar: Scalar<M::PointerTag>,
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
self.memory.force_ptr(scalar)
}

#[inline(always)]
pub fn force_bits(
&self,
scalar: Scalar<M::PointerTag>,
size: Size
) -> InterpResult<'tcx, u128> {
self.memory.force_bits(scalar, size)
}

#[inline(always)]
pub fn tag_static_base_pointer(&self, ptr: Pointer) -> Pointer<M::PointerTag> {
self.memory.tag_static_base_pointer(ptr)
Expand Down Expand Up @@ -253,6 +270,27 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
self.frame().body
}

#[inline(always)]
pub fn sign_extend(&self, value: u128, ty: TyLayout<'_>) -> u128 {
assert!(ty.abi.is_signed());
sign_extend(value, ty.size)
}

#[inline(always)]
pub fn truncate(&self, value: u128, ty: TyLayout<'_>) -> u128 {
truncate(value, ty.size)
}

#[inline]
pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
ty.is_sized(self.tcx, self.param_env)
}

#[inline]
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
}

pub(super) fn subst_and_normalize_erasing_regions<T: TypeFoldable<'tcx>>(
&self,
substs: T,
Expand Down Expand Up @@ -288,14 +326,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
).ok_or_else(|| InterpError::TooGeneric.into())
}

pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
ty.is_sized(self.tcx, self.param_env)
}

pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
ty.is_freeze(*self.tcx, self.param_env, DUMMY_SP)
}

pub fn load_mir(
&self,
instance: ty::InstanceDef<'tcx>,
Expand Down Expand Up @@ -766,32 +796,4 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
trace!("generate stacktrace: {:#?}, {:?}", frames, explicit_span);
frames
}

#[inline(always)]
pub fn sign_extend(&self, value: u128, ty: TyLayout<'_>) -> u128 {
assert!(ty.abi.is_signed());
sign_extend(value, ty.size)
}

#[inline(always)]
pub fn truncate(&self, value: u128, ty: TyLayout<'_>) -> u128 {
truncate(value, ty.size)
}

#[inline(always)]
pub fn force_ptr(
&self,
scalar: Scalar<M::PointerTag>,
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
self.memory.force_ptr(scalar)
}

#[inline(always)]
pub fn force_bits(
&self,
scalar: Scalar<M::PointerTag>,
size: Size
) -> InterpResult<'tcx, u128> {
self.memory.force_bits(scalar, size)
}
}
41 changes: 29 additions & 12 deletions src/librustc_mir/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use std::hash::Hash;

use rustc::hir::def_id::DefId;
use rustc::mir;
use rustc::ty::{self, query::TyCtxtAt};
use rustc::ty::{self, TyCtxt};

use super::{
Allocation, AllocId, InterpResult, Scalar, AllocationExtra,
InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory
Allocation, AllocId, InterpResult, InterpError, Scalar, AllocationExtra,
InterpCx, PlaceTy, OpTy, ImmTy, MemoryKind, Pointer, Memory,
};

/// Whether this kind of memory is allowed to leak
Expand Down Expand Up @@ -67,6 +67,11 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// The `default()` is used for pointers to consts, statics, vtables and functions.
type PointerTag: ::std::fmt::Debug + Copy + Eq + Hash + 'static;

/// Machines can define extra (non-instance) things that represent values of function pointers.
/// For example, Miri uses this to return a fucntion pointer from `dlsym`
/// that can later be called to execute the right thing.
type ExtraFnVal: ::std::fmt::Debug + Copy;

/// Extra data stored in every call frame.
type FrameExtra;

Expand Down Expand Up @@ -119,6 +124,16 @@ pub trait Machine<'mir, 'tcx>: Sized {
ret: Option<mir::BasicBlock>,
) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>>;

/// Execute `fn_val`. it is the hook's responsibility to advance the instruction
/// pointer as appropriate.
fn call_extra_fn(
ecx: &mut InterpCx<'mir, 'tcx, Self>,
fn_val: Self::ExtraFnVal,
args: &[OpTy<'tcx, Self::PointerTag>],
dest: Option<PlaceTy<'tcx, Self::PointerTag>>,
ret: Option<mir::BasicBlock>,
) -> InterpResult<'tcx>;

/// Directly process an intrinsic without pushing a stack frame.
/// If this returns successfully, the engine will take care of jumping to the next block.
fn call_intrinsic(
Expand All @@ -136,8 +151,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
///
/// This allocation will then be fed to `tag_allocation` to initialize the "extra" state.
fn find_foreign_static(
tcx: TyCtxt<'tcx>,
def_id: DefId,
tcx: TyCtxtAt<'tcx>,
) -> InterpResult<'tcx, Cow<'tcx, Allocation>>;

/// Called for all binary operations on integer(-like) types when one operand is a pointer
Expand Down Expand Up @@ -174,10 +189,10 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// For static allocations, the tag returned must be the same as the one returned by
/// `tag_static_base_pointer`.
fn tag_allocation<'b>(
memory_extra: &Self::MemoryExtra,
id: AllocId,
alloc: Cow<'b, Allocation>,
kind: Option<MemoryKind<Self::MemoryKinds>>,
memory: &Memory<'mir, 'tcx, Self>,
) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag);

/// Return the "base" tag for the given static allocation: the one that is used for direct
Expand All @@ -186,8 +201,8 @@ pub trait Machine<'mir, 'tcx>: Sized {
/// Be aware that requesting the `Allocation` for that `id` will lead to cycles
/// for cyclic statics!
fn tag_static_base_pointer(
memory_extra: &Self::MemoryExtra,
id: AllocId,
memory: &Memory<'mir, 'tcx, Self>,
) -> Self::PointerTag;

/// Executes a retagging operation
Expand All @@ -209,20 +224,22 @@ pub trait Machine<'mir, 'tcx>: Sized {
extra: Self::FrameExtra,
) -> InterpResult<'tcx>;

#[inline(always)]
fn int_to_ptr(
int: u64,
_mem: &Memory<'mir, 'tcx, Self>,
int: u64,
) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
if int == 0 {
err!(InvalidNullPointerUsage)
Err((if int == 0 {
InterpError::InvalidNullPointerUsage
} else {
err!(ReadBytesAsPointer)
}
InterpError::ReadBytesAsPointer
}).into())
}

#[inline(always)]
fn ptr_to_int(
_ptr: Pointer<Self::PointerTag>,
_mem: &Memory<'mir, 'tcx, Self>,
_ptr: Pointer<Self::PointerTag>,
) -> InterpResult<'tcx, u64> {
err!(ReadPointerAsBytes)
}
Expand Down
Loading