Skip to content

Commit 80d407e

Browse files
committed
ICE BorrowMutError: Attempt to pass in FileDescriptionRef for check_and_update_readiness
1 parent 2cb8b0c commit 80d407e

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
@@ -29,6 +29,7 @@ pub trait FileDescription: std::fmt::Debug + Any {
2929
fn read<'tcx>(
3030
&mut self,
3131
_communicate_allowed: bool,
32+
_fd_ref: &FileDescriptionRef,
3233
_bytes: &mut [u8],
3334
_ecx: &mut MiriInterpCx<'tcx>,
3435
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -39,6 +40,7 @@ pub trait FileDescription: std::fmt::Debug + Any {
3940
fn write<'tcx>(
4041
&mut self,
4142
_communicate_allowed: bool,
43+
_fd_ref: &FileDescriptionRef,
4244
_bytes: &[u8],
4345
_ecx: &mut MiriInterpCx<'tcx>,
4446
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -127,6 +129,7 @@ impl FileDescription for io::Stdin {
127129
fn read<'tcx>(
128130
&mut self,
129131
communicate_allowed: bool,
132+
_fd_ref: &FileDescriptionRef,
130133
bytes: &mut [u8],
131134
_ecx: &mut MiriInterpCx<'tcx>,
132135
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -150,6 +153,7 @@ impl FileDescription for io::Stdout {
150153
fn write<'tcx>(
151154
&mut self,
152155
_communicate_allowed: bool,
156+
_fd_ref: &FileDescriptionRef,
153157
bytes: &[u8],
154158
_ecx: &mut MiriInterpCx<'tcx>,
155159
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -178,6 +182,7 @@ impl FileDescription for io::Stderr {
178182
fn write<'tcx>(
179183
&mut self,
180184
_communicate_allowed: bool,
185+
_fd_ref: &FileDescriptionRef,
181186
bytes: &[u8],
182187
_ecx: &mut MiriInterpCx<'tcx>,
183188
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -203,6 +208,7 @@ impl FileDescription for NullOutput {
203208
fn write<'tcx>(
204209
&mut self,
205210
_communicate_allowed: bool,
211+
_fd_ref: &FileDescriptionRef,
206212
bytes: &[u8],
207213
_ecx: &mut MiriInterpCx<'tcx>,
208214
) -> InterpResult<'tcx, io::Result<usize>> {
@@ -271,7 +277,7 @@ impl FileDescriptionRef {
271277
ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>,
272278
) -> InterpResult<'tcx, ()> {
273279
use crate::shims::unix::linux::epoll::EvalContextExt;
274-
ecx.check_and_update_readiness(self.get_id(), || self.borrow_mut().get_epoll_ready_events())
280+
ecx.check_and_update_readiness(self)
275281
}
276282
}
277283

@@ -574,7 +580,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
574580
// `usize::MAX` because it is bounded by the host's `isize`.
575581
let mut bytes = vec![0; usize::try_from(count).unwrap()];
576582
let result = match offset {
577-
None => fd.borrow_mut().read(communicate, &mut bytes, this),
583+
None => fd.borrow_mut().read(communicate, &fd, &mut bytes, this),
578584
Some(offset) => {
579585
let Ok(offset) = u64::try_from(offset) else {
580586
let einval = this.eval_libc("EINVAL");
@@ -632,7 +638,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
632638
};
633639

634640
let result = match offset {
635-
None => fd.borrow_mut().write(communicate, &bytes, this),
641+
None => fd.borrow_mut().write(communicate, &fd, &bytes, this),
636642
Some(offset) => {
637643
let Ok(offset) = u64::try_from(offset) else {
638644
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)