Skip to content

Commit 8355437

Browse files
committed
Auto merge of #1044 - RalfJung:uprust, r=RalfJung
rustup
2 parents 9316d90 + 37b1190 commit 8355437

File tree

10 files changed

+48
-46
lines changed

10 files changed

+48
-46
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
c34472b77084c9f76f872871aeab121daf81fb99
1+
9e346646e93cc243567e27bb0f4e8716d56ad1f1

src/intptrcast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ impl<'mir, 'tcx> GlobalState {
6363
// This never overflows because `int >= glb`
6464
let offset = int - glb;
6565
// If the offset exceeds the size of the allocation, this access is illegal
66-
if offset <= memory.get(alloc_id)?.size.bytes() {
66+
if offset <= memory.get_size_and_align(alloc_id, AllocCheck::MaybeDead)?.0.bytes() {
6767
// This pointer is untagged because it was created from a cast
6868
Pointer::new_with_tag(alloc_id, Size::from_bytes(offset), Tag::Untagged)
6969
} else {

src/operator.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ impl<'mir, 'tcx> EvalContextExt<'tcx> for super::MiriEvalContext<'mir, 'tcx> {
7575
let ptr = self.pointer_offset_inbounds(
7676
left.to_scalar()?,
7777
pointee_ty,
78-
right.to_scalar()?.to_isize(self)?,
78+
right.to_scalar()?.to_machine_isize(self)?,
7979
)?;
8080
(ptr, false, left.layout.ty)
8181
}

src/shims/dlsym.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
4040
match dlsym {
4141
GetEntropy => {
4242
let ptr = this.read_scalar(args[0])?.not_undef()?;
43-
let len = this.read_scalar(args[1])?.to_usize(this)?;
43+
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
4444
this.gen_random(ptr, len as usize)?;
4545
this.write_null(dest)?;
4646
}

src/shims/env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
124124
this.check_no_isolation("getcwd")?;
125125

126126
let buf = this.read_scalar(buf_op)?.not_undef()?;
127-
let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?;
127+
let size = this.read_scalar(size_op)?.to_machine_usize(&*this.tcx)?;
128128
// If we cannot get the current directory, we return null
129129
match env::current_dir() {
130130
Ok(cwd) => {

src/shims/foreign_items.rs

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -144,13 +144,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
144144
let ret = ret.expect("dest is `Some` but ret is `None`");
145145
match link_name {
146146
"malloc" => {
147-
let size = this.read_scalar(args[0])?.to_usize(this)?;
147+
let size = this.read_scalar(args[0])?.to_machine_usize(this)?;
148148
let res = this.malloc(size, /*zero_init:*/ false, MiriMemoryKind::C);
149149
this.write_scalar(res, dest)?;
150150
}
151151
"calloc" => {
152-
let items = this.read_scalar(args[0])?.to_usize(this)?;
153-
let len = this.read_scalar(args[1])?.to_usize(this)?;
152+
let items = this.read_scalar(args[0])?.to_machine_usize(this)?;
153+
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
154154
let size = items
155155
.checked_mul(len)
156156
.ok_or_else(|| err_panic!(Overflow(mir::BinOp::Mul)))?;
@@ -159,8 +159,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
159159
}
160160
"posix_memalign" => {
161161
let ret = this.deref_operand(args[0])?;
162-
let align = this.read_scalar(args[1])?.to_usize(this)?;
163-
let size = this.read_scalar(args[2])?.to_usize(this)?;
162+
let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
163+
let size = this.read_scalar(args[2])?.to_machine_usize(this)?;
164164
// Align must be power of 2, and also at least ptr-sized (POSIX rules).
165165
if !align.is_power_of_two() {
166166
throw_unsup!(HeapAllocNonPowerOfTwoAlignment(align));
@@ -190,14 +190,14 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
190190
}
191191
"realloc" => {
192192
let old_ptr = this.read_scalar(args[0])?.not_undef()?;
193-
let new_size = this.read_scalar(args[1])?.to_usize(this)?;
193+
let new_size = this.read_scalar(args[1])?.to_machine_usize(this)?;
194194
let res = this.realloc(old_ptr, new_size, MiriMemoryKind::C)?;
195195
this.write_scalar(res, dest)?;
196196
}
197197

198198
"__rust_alloc" => {
199-
let size = this.read_scalar(args[0])?.to_usize(this)?;
200-
let align = this.read_scalar(args[1])?.to_usize(this)?;
199+
let size = this.read_scalar(args[0])?.to_machine_usize(this)?;
200+
let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
201201
if size == 0 {
202202
throw_unsup!(HeapAllocZeroBytes);
203203
}
@@ -212,8 +212,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
212212
this.write_scalar(Scalar::Ptr(ptr), dest)?;
213213
}
214214
"__rust_alloc_zeroed" => {
215-
let size = this.read_scalar(args[0])?.to_usize(this)?;
216-
let align = this.read_scalar(args[1])?.to_usize(this)?;
215+
let size = this.read_scalar(args[0])?.to_machine_usize(this)?;
216+
let align = this.read_scalar(args[1])?.to_machine_usize(this)?;
217217
if size == 0 {
218218
throw_unsup!(HeapAllocZeroBytes);
219219
}
@@ -233,8 +233,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
233233
}
234234
"__rust_dealloc" => {
235235
let ptr = this.read_scalar(args[0])?.not_undef()?;
236-
let old_size = this.read_scalar(args[1])?.to_usize(this)?;
237-
let align = this.read_scalar(args[2])?.to_usize(this)?;
236+
let old_size = this.read_scalar(args[1])?.to_machine_usize(this)?;
237+
let align = this.read_scalar(args[2])?.to_machine_usize(this)?;
238238
if old_size == 0 {
239239
throw_unsup!(HeapAllocZeroBytes);
240240
}
@@ -253,9 +253,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
253253
}
254254
"__rust_realloc" => {
255255
let ptr = this.read_scalar(args[0])?.to_ptr()?;
256-
let old_size = this.read_scalar(args[1])?.to_usize(this)?;
257-
let align = this.read_scalar(args[2])?.to_usize(this)?;
258-
let new_size = this.read_scalar(args[3])?.to_usize(this)?;
256+
let old_size = this.read_scalar(args[1])?.to_machine_usize(this)?;
257+
let align = this.read_scalar(args[2])?.to_machine_usize(this)?;
258+
let new_size = this.read_scalar(args[3])?.to_machine_usize(this)?;
259259
if old_size == 0 || new_size == 0 {
260260
throw_unsup!(HeapAllocZeroBytes);
261261
}
@@ -277,11 +277,11 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
277277
let sys_getrandom = this
278278
.eval_path_scalar(&["libc", "SYS_getrandom"])?
279279
.expect("Failed to get libc::SYS_getrandom")
280-
.to_usize(this)?;
280+
.to_machine_usize(this)?;
281281

282282
// `libc::syscall(NR_GETRANDOM, buf.as_mut_ptr(), buf.len(), GRND_NONBLOCK)`
283283
// is called if a `HashMap` is created the regular way (e.g. HashMap<K, V>).
284-
match this.read_scalar(args[0])?.to_usize(this)? {
284+
match this.read_scalar(args[0])?.to_machine_usize(this)? {
285285
id if id == sys_getrandom => {
286286
// The first argument is the syscall id,
287287
// so skip over it.
@@ -357,7 +357,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
357357
"memcmp" => {
358358
let left = this.read_scalar(args[0])?.not_undef()?;
359359
let right = this.read_scalar(args[1])?.not_undef()?;
360-
let n = Size::from_bytes(this.read_scalar(args[2])?.to_usize(this)?);
360+
let n = Size::from_bytes(this.read_scalar(args[2])?.to_machine_usize(this)?);
361361

362362
let result = {
363363
let left_bytes = this.memory.read_bytes(left, n)?;
@@ -377,7 +377,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
377377
"memrchr" => {
378378
let ptr = this.read_scalar(args[0])?.not_undef()?;
379379
let val = this.read_scalar(args[1])?.to_i32()? as u8;
380-
let num = this.read_scalar(args[2])?.to_usize(this)?;
380+
let num = this.read_scalar(args[2])?.to_machine_usize(this)?;
381381
if let Some(idx) = this
382382
.memory
383383
.read_bytes(ptr, Size::from_bytes(num))?
@@ -395,7 +395,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
395395
"memchr" => {
396396
let ptr = this.read_scalar(args[0])?.not_undef()?;
397397
let val = this.read_scalar(args[1])?.to_i32()? as u8;
398-
let num = this.read_scalar(args[2])?.to_usize(this)?;
398+
let num = this.read_scalar(args[2])?.to_machine_usize(this)?;
399399
let idx = this
400400
.memory
401401
.read_bytes(ptr, Size::from_bytes(num))?
@@ -462,7 +462,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
462462
"write" => {
463463
let fd = this.read_scalar(args[0])?.to_i32()?;
464464
let buf = this.read_scalar(args[1])?.not_undef()?;
465-
let n = this.read_scalar(args[2])?.to_usize(tcx)?;
465+
let n = this.read_scalar(args[2])?.to_machine_usize(tcx)?;
466466
trace!("Called write({:?}, {:?}, {:?})", fd, buf, n);
467467
let result = if fd == 1 || fd == 2 {
468468
// stdout/stderr
@@ -771,7 +771,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
771771
this.write_scalar(this.machine.argv.expect("machine must be initialized"), dest)?;
772772
}
773773
"SecRandomCopyBytes" => {
774-
let len = this.read_scalar(args[1])?.to_usize(this)?;
774+
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
775775
let ptr = this.read_scalar(args[2])?.not_undef()?;
776776
this.gen_random(ptr, len as usize)?;
777777
this.write_null(dest)?;
@@ -786,25 +786,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
786786
this.write_scalar(Scalar::from_int(1, this.pointer_size()), dest)?;
787787
}
788788
"HeapAlloc" => {
789-
let _handle = this.read_scalar(args[0])?.to_isize(this)?;
789+
let _handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
790790
let flags = this.read_scalar(args[1])?.to_u32()?;
791-
let size = this.read_scalar(args[2])?.to_usize(this)?;
791+
let size = this.read_scalar(args[2])?.to_machine_usize(this)?;
792792
let zero_init = (flags & 0x00000008) != 0; // HEAP_ZERO_MEMORY
793793
let res = this.malloc(size, zero_init, MiriMemoryKind::WinHeap);
794794
this.write_scalar(res, dest)?;
795795
}
796796
"HeapFree" => {
797-
let _handle = this.read_scalar(args[0])?.to_isize(this)?;
797+
let _handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
798798
let _flags = this.read_scalar(args[1])?.to_u32()?;
799799
let ptr = this.read_scalar(args[2])?.not_undef()?;
800800
this.free(ptr, MiriMemoryKind::WinHeap)?;
801801
this.write_scalar(Scalar::from_int(1, Size::from_bytes(4)), dest)?;
802802
}
803803
"HeapReAlloc" => {
804-
let _handle = this.read_scalar(args[0])?.to_isize(this)?;
804+
let _handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
805805
let _flags = this.read_scalar(args[1])?.to_u32()?;
806806
let ptr = this.read_scalar(args[2])?.not_undef()?;
807-
let size = this.read_scalar(args[3])?.to_usize(this)?;
807+
let size = this.read_scalar(args[3])?.to_machine_usize(this)?;
808808
let res = this.realloc(ptr, size, MiriMemoryKind::WinHeap)?;
809809
this.write_scalar(res, dest)?;
810810
}
@@ -883,7 +883,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
883883
this.write_scalar(Scalar::from_int(which, this.pointer_size()), dest)?;
884884
}
885885
"WriteFile" => {
886-
let handle = this.read_scalar(args[0])?.to_isize(this)?;
886+
let handle = this.read_scalar(args[0])?.to_machine_isize(this)?;
887887
let buf = this.read_scalar(args[1])?.not_undef()?;
888888
let n = this.read_scalar(args[2])?.to_u32()?;
889889
let written_place = this.deref_operand(args[3])?;
@@ -973,7 +973,7 @@ fn linux_getrandom<'tcx>(
973973
dest: PlaceTy<'tcx, Tag>,
974974
) -> InterpResult<'tcx> {
975975
let ptr = this.read_scalar(args[0])?.not_undef()?;
976-
let len = this.read_scalar(args[1])?.to_usize(this)?;
976+
let len = this.read_scalar(args[1])?.to_machine_usize(this)?;
977977

978978
// The only supported flags are GRND_RANDOM and GRND_NONBLOCK,
979979
// neither of which have any effect on our current PRNG.

src/shims/fs.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
154154

155155
this.check_no_isolation("read")?;
156156

157-
let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
157+
let count = this.read_scalar(count_op)?.to_machine_usize(&*this.tcx)?;
158158
// Reading zero bytes should not change `buf`.
159159
if count == 0 {
160160
return Ok(0);
@@ -166,8 +166,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
166166
this.remove_handle_and(fd, |mut handle, this| {
167167
// Don't use `?` to avoid returning before reinserting the handle.
168168
let bytes = this.force_ptr(buf_scalar).and_then(|buf| {
169+
// FIXME: Don't use raw methods
169170
this.memory
170-
.get_mut(buf.alloc_id)?
171+
.get_raw_mut(buf.alloc_id)?
171172
.get_bytes_mut(&*this.tcx, buf, Size::from_bytes(count))
172173
.map(|buffer| handle.file.read(buffer))
173174
});
@@ -186,7 +187,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
186187

187188
this.check_no_isolation("write")?;
188189

189-
let count = this.read_scalar(count_op)?.to_usize(&*this.tcx)?;
190+
let count = this.read_scalar(count_op)?.to_machine_usize(&*this.tcx)?;
190191
// Writing zero bytes should not change `buf`.
191192
if count == 0 {
192193
return Ok(0);
@@ -195,7 +196,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
195196
let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?;
196197

197198
this.remove_handle_and(fd, |mut handle, this| {
198-
let bytes = this.memory.get(buf.alloc_id).and_then(|alloc| {
199+
// FIXME: Don't use raw methods
200+
let bytes = this.memory.get_raw(buf.alloc_id).and_then(|alloc| {
199201
alloc
200202
.get_bytes(&*this.tcx, buf, Size::from_bytes(count))
201203
.map(|bytes| handle.file.write(bytes).map(|bytes| bytes as i64))

src/shims/intrinsics.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3535
let intrinsic_name = &*tcx.item_name(instance.def_id()).as_str();
3636
match intrinsic_name {
3737
"arith_offset" => {
38-
let offset = this.read_scalar(args[1])?.to_isize(this)?;
38+
let offset = this.read_scalar(args[1])?.to_machine_isize(this)?;
3939
let ptr = this.read_scalar(args[0])?.not_undef()?;
4040

4141
let pointee_ty = substs.type_at(0);
@@ -206,7 +206,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
206206
let elem_ty = substs.type_at(0);
207207
let elem_layout = this.layout_of(elem_ty)?;
208208
let elem_size = elem_layout.size.bytes();
209-
let count = this.read_scalar(args[2])?.to_usize(this)?;
209+
let count = this.read_scalar(args[2])?.to_machine_usize(this)?;
210210
let elem_align = elem_layout.align.abi;
211211

212212
let size = Size::from_bytes(count * elem_size);
@@ -371,7 +371,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
371371
}
372372

373373
"offset" => {
374-
let offset = this.read_scalar(args[1])?.to_isize(this)?;
374+
let offset = this.read_scalar(args[1])?.to_machine_isize(this)?;
375375
let ptr = this.read_scalar(args[0])?.not_undef()?;
376376
let result_ptr = this.pointer_offset_inbounds(ptr, substs.type_at(0), offset)?;
377377
this.write_scalar(result_ptr, dest)?;
@@ -542,7 +542,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
542542
let ptr = mplace.ptr.to_ptr()?;
543543
// We know the return place is in-bounds
544544
this.memory
545-
.get_mut(ptr.alloc_id)?
545+
.get_raw_mut(ptr.alloc_id)?
546546
.mark_definedness(ptr, dest.layout.size, false);
547547
}
548548
}
@@ -554,7 +554,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
554554
let ty_layout = this.layout_of(ty)?;
555555
let val_byte = this.read_scalar(args[1])?.to_u8()?;
556556
let ptr = this.read_scalar(args[0])?.not_undef()?;
557-
let count = this.read_scalar(args[2])?.to_usize(this)?;
557+
let count = this.read_scalar(args[2])?.to_machine_usize(this)?;
558558
let byte_count = ty_layout.size * count;
559559
this.memory.write_bytes(ptr, iter::repeat(val_byte).take(byte_count.bytes() as usize))?;
560560
}

src/shims/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
7575
let ptr_scalar = this.read_scalar(ptr_op)?.not_undef()?;
7676

7777
if let Ok(ptr) = this.force_ptr(ptr_scalar) {
78-
let cur_align = this.memory.get(ptr.alloc_id)?.align.bytes() as usize;
78+
let cur_align = this.memory.get_size_and_align(ptr.alloc_id, AllocCheck::MaybeDead)?.1.bytes() as usize;
7979
if cur_align >= req_align {
8080
// if the allocation alignment is at least the required alignment we use the
8181
// libcore implementation

src/stacked_borrows.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,8 @@ trait EvalContextPrivExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
540540
kind, new_tag, ptr.tag, place.layout.ty, ptr.erase_tag(), size.bytes());
541541

542542
// Get the allocation. It might not be mutable, so we cannot use `get_mut`.
543-
let alloc = this.memory.get(ptr.alloc_id)?;
544-
let stacked_borrows = alloc.extra.stacked_borrows.as_ref().expect("we should have Stacked Borrows data");
543+
let extra = &this.memory.get_raw(ptr.alloc_id)?.extra;
544+
let stacked_borrows = extra.stacked_borrows.as_ref().expect("we should have Stacked Borrows data");
545545
// Update the stacks.
546546
// Make sure that raw pointers and mutable shared references are reborrowed "weak":
547547
// There could be existing unique pointers reborrowed from them that should remain valid!

0 commit comments

Comments
 (0)