Skip to content

Commit 5178c02

Browse files
committed
ICE BorrowMutError: Attempt to pass in FileDescriptionRef for check_and_update_readiness
1 parent ac7b81f commit 5178c02

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

src/shims/unix/fd.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub trait FileDescription: std::fmt::Debug + Any {
2222
fn read<'tcx>(
2323
&mut self,
2424
_communicate_allowed: bool,
25+
_fd_ref: &FileDescriptionRef,
2526
_bytes: &mut [u8],
2627
_ecx: &mut MiriInterpCx<'tcx>,
2728
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -32,6 +33,7 @@ pub trait FileDescription: std::fmt::Debug + Any {
3233
fn write<'tcx>(
3334
&mut self,
3435
_communicate_allowed: bool,
36+
_fd_ref: &FileDescriptionRef,
3537
_bytes: &[u8],
3638
_ecx: &mut MiriInterpCx<'tcx>,
3739
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -120,6 +122,7 @@ impl FileDescription for io::Stdin {
120122
fn read<'tcx>(
121123
&mut self,
122124
communicate_allowed: bool,
125+
_fd_ref: &FileDescriptionRef,
123126
bytes: &mut [u8],
124127
_ecx: &mut MiriInterpCx<'tcx>,
125128
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -143,6 +146,7 @@ impl FileDescription for io::Stdout {
143146
fn write<'tcx>(
144147
&mut self,
145148
_communicate_allowed: bool,
149+
_fd_ref: &FileDescriptionRef,
146150
bytes: &[u8],
147151
_ecx: &mut MiriInterpCx<'tcx>,
148152
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -171,6 +175,7 @@ impl FileDescription for io::Stderr {
171175
fn write<'tcx>(
172176
&mut self,
173177
_communicate_allowed: bool,
178+
_fd_ref: &FileDescriptionRef,
174179
bytes: &[u8],
175180
_ecx: &mut MiriInterpCx<'tcx>,
176181
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -196,6 +201,7 @@ impl FileDescription for NullOutput {
196201
fn write<'tcx>(
197202
&mut self,
198203
_communicate_allowed: bool,
204+
_fd_ref: &FileDescriptionRef,
199205
bytes: &[u8],
200206
_ecx: &mut MiriInterpCx<'tcx>,
201207
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -264,7 +270,7 @@ impl FileDescriptionRef {
264270
ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>,
265271
) -> InterpResult<'tcx, ()> {
266272
use crate::shims::unix::linux::epoll::EvalContextExt;
267-
ecx.check_and_update_readiness(self.get_id(), || self.borrow_mut().get_epoll_ready_events())
273+
ecx.check_and_update_readiness(self)
268274
}
269275
}
270276

@@ -567,7 +573,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
567573
// `usize::MAX` because it is bounded by the host's `isize`.
568574
let mut bytes = vec![0; usize::try_from(count).unwrap()];
569575
let result = match offset {
570-
None => fd.borrow_mut().read(communicate, &mut bytes, this),
576+
None => fd.borrow_mut().read(communicate, &fd, &mut bytes, this),
571577
Some(offset) => {
572578
let Ok(offset) = u64::try_from(offset) else {
573579
let einval = this.eval_libc("EINVAL");
@@ -625,7 +631,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
625631
};
626632

627633
let result = match offset {
628-
None => fd.borrow_mut().write(communicate, &bytes, this),
634+
None => fd.borrow_mut().write(communicate, &fd, &bytes, this),
629635
Some(offset) => {
630636
let Ok(offset) = u64::try_from(offset) else {
631637
let einval = this.eval_libc("EINVAL");

src/shims/unix/fs.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_data_structures::fx::FxHashMap;
1212
use rustc_target::abi::Size;
1313

1414
use crate::shims::os_str::bytes_to_os_str;
15+
use crate::shims::unix::fd::FileDescriptionRef;
1516
use crate::shims::unix::*;
1617
use crate::*;
1718
use shims::time::system_time_to_duration;
@@ -32,6 +33,7 @@ impl FileDescription for FileHandle {
3233
fn read<'tcx>(
3334
&mut self,
3435
communicate_allowed: bool,
36+
_fd_ref: &FileDescriptionRef,
3537
bytes: &mut [u8],
3638
_ecx: &mut MiriInterpCx<'tcx>,
3739
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -42,6 +44,7 @@ impl FileDescription for FileHandle {
4244
fn write<'tcx>(
4345
&mut self,
4446
communicate_allowed: bool,
47+
_fd_ref: &FileDescriptionRef,
4548
bytes: &[u8],
4649
_ecx: &mut MiriInterpCx<'tcx>,
4750
) -> InterpResult<'tcx, io::Result<usize>> {

src/shims/unix/linux/epoll.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::collections::BTreeMap;
33
use std::io;
44
use std::rc::{Rc, Weak};
55

6-
use crate::shims::unix::fd::FdId;
6+
use crate::shims::unix::fd::{FdId, FileDescriptionRef};
77
use crate::shims::unix::*;
88
use crate::*;
99

@@ -440,15 +440,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
440440

441441
/// For a specific unique file descriptor id, get its ready events and update
442442
/// the corresponding ready list.
443-
fn check_and_update_readiness(
444-
&self,
445-
id: FdId,
446-
get_ready_events: impl FnOnce() -> InterpResult<'tcx, EpollReadyEvents>,
447-
) -> InterpResult<'tcx, ()> {
443+
fn check_and_update_readiness(&self, fd_ref: &FileDescriptionRef) -> InterpResult<'tcx, ()> {
448444
let this = self.eval_context_ref();
445+
let id = fd_ref.get_id();
449446
// Get a list of EpollEventInterest that is associated to a specific file description.
450447
if let Some(epoll_interests) = this.machine.epoll_interests.get_epoll_interest(id) {
451-
let epoll_ready_events = get_ready_events()?;
448+
// TODO: this second borrow will panic
449+
let epoll_ready_events = fd_ref.borrow_mut().get_epoll_ready_events()?;
452450
// Get the bitmask of ready events.
453451
let ready_events = epoll_ready_events.get_event_bitmask(this);
454452

src/shims/unix/linux/eventfd.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::mem;
66
use fd::FdId;
77
use rustc_target::abi::Endian;
88

9+
use crate::shims::unix::fd::FileDescriptionRef;
910
use crate::shims::unix::linux::epoll::EpollReadyEvents;
1011
use crate::shims::unix::*;
1112
use crate::{concurrency::VClock, *};
@@ -65,6 +66,7 @@ impl FileDescription for Event {
6566
fn read<'tcx>(
6667
&mut self,
6768
_communicate_allowed: bool,
69+
fd_ref: &FileDescriptionRef,
6870
bytes: &mut [u8],
6971
ecx: &mut MiriInterpCx<'tcx>,
7072
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -92,7 +94,7 @@ impl FileDescription for Event {
9294
// When any of the event happened, we check and update the status of all supported event
9395
// types for current file description.
9496
use crate::shims::unix::linux::epoll::EvalContextExt;
95-
ecx.check_and_update_readiness(self.id, || self.get_epoll_ready_events())?;
97+
ecx.check_and_update_readiness(fd_ref)?;
9698
return Ok(Ok(U64_ARRAY_SIZE));
9799
}
98100
}
@@ -112,6 +114,7 @@ impl FileDescription for Event {
112114
fn write<'tcx>(
113115
&mut self,
114116
_communicate_allowed: bool,
117+
fd_ref: &FileDescriptionRef,
115118
bytes: &[u8],
116119
ecx: &mut MiriInterpCx<'tcx>,
117120
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -150,7 +153,7 @@ impl FileDescription for Event {
150153
// When any of the event happened, we check and update the status of all supported event
151154
// types for current file description.
152155
use crate::shims::unix::linux::epoll::EvalContextExt;
153-
ecx.check_and_update_readiness(self.id, || self.get_epoll_ready_events())?;
156+
ecx.check_and_update_readiness(fd_ref)?;
154157
Ok(Ok(U64_ARRAY_SIZE))
155158
}
156159
}

src/shims/unix/socket.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::io;
44
use std::io::{Error, ErrorKind, Read};
55
use std::rc::{Rc, Weak};
66

7-
use crate::shims::unix::fd::WeakFileDescriptionRef;
7+
use crate::shims::unix::fd::{FileDescriptionRef, WeakFileDescriptionRef};
88
use crate::shims::unix::linux::epoll::EpollReadyEvents;
99
use crate::shims::unix::*;
1010
use crate::{concurrency::VClock, *};
@@ -99,6 +99,7 @@ impl FileDescription for SocketPair {
9999
fn read<'tcx>(
100100
&mut self,
101101
_communicate_allowed: bool,
102+
_fd_ref: &FileDescriptionRef,
102103
bytes: &mut [u8],
103104
ecx: &mut MiriInterpCx<'tcx>,
104105
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -150,6 +151,7 @@ impl FileDescription for SocketPair {
150151
fn write<'tcx>(
151152
&mut self,
152153
_communicate_allowed: bool,
154+
_fd_ref: &FileDescriptionRef,
153155
bytes: &[u8],
154156
ecx: &mut MiriInterpCx<'tcx>,
155157
) -> InterpResult<'tcx, io::Result<usize>> {

0 commit comments

Comments
 (0)