Skip to content

Commit c4d53ab

Browse files
committed
Stuck at passing byte slice to unblock_thread
1 parent 1fde65b commit c4d53ab

File tree

3 files changed

+28
-19
lines changed

3 files changed

+28
-19
lines changed

src/concurrency/thread.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,6 @@ pub enum BlockReason {
161161
Eventfd,
162162
/// Blocked on unnamed_socket.
163163
UnnamedSocket,
164-
165164
}
166165

167166
/// The state of a thread.

src/provenance_gc.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ impl<T: VisitProvenance> VisitProvenance for std::cell::RefCell<T> {
4646
}
4747
}
4848

49+
impl<T: VisitProvenance> VisitProvenance for std::vec::Vec<T> {
50+
fn visit_provenance(&self, _visit: &mut VisitWith<'_>) {
51+
// TODO: this is just a temporary change to get Vec<u8> to work in unblock_thread, might remove later.
52+
}
53+
}
54+
4955
impl VisitProvenance for BorTag {
5056
fn visit_provenance(&self, visit: &mut VisitWith<'_>) {
5157
visit(None, Some(*self))

src/shims/unix/unnamed_socket.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ impl FileDescription for AnonSocket {
127127

128128
fn read<'tcx>(
129129
&self,
130-
_self_ref: &FileDescriptionRef,
130+
self_ref: &FileDescriptionRef,
131131
_communicate_allowed: bool,
132132
ptr: Pointer,
133133
len: usize,
@@ -162,28 +162,30 @@ impl FileDescription for AnonSocket {
162162
} else {
163163
// TODO: move this to helper
164164
// Blocking socketpair with writer and empty buffer.
165-
let peer_fd = self.peer_fd().upgrade().unwrap();
166-
bytes = bytes.clone();
165+
let peer_fd = self.peer_fd().clone();
166+
let dest = dest.clone();
167+
let weak_self_ref = self_ref.downgrade();
167168
ecx.block_thread(
168169
BlockReason::UnnamedSocket,
169170
None,
170171
callback!(
171-
@capture<'tcx> {
172-
self_ref: FileDescriptionRef,
173-
peer_fd: Option<FileDescriptionRef>,
174-
bytes: [u8],
175-
ptr: Pointer,
176-
dest: MPlaceTy<'tcx>,
177-
}
178-
@unblock = |this| {
179-
// TODO: We might need to decide what to do if peer_fd is closed when read is blocked.
180-
anonsocket_read(self_ref, peer_fd, &bytes, ptr, dest, ecx)
181-
}
182-
),
172+
@capture<'tcx> {
173+
weak_self_ref: WeakFileDescriptionRef,
174+
peer_fd: WeakFileDescriptionRef,
175+
bytes: Vec<u8>,
176+
ptr: Pointer,
177+
dest: MPlaceTy<'tcx>,
178+
}
179+
@unblock = |this| {
180+
// TODO: We might need to decide what to do if peer_fd is closed when read is blocked.
181+
anonsocket_read(weak_self_ref, peer_fd, &mut bytes[..], ptr, &dest, this)
182+
}
183+
),
183184
);
184185
}
185186
}
186187
}
188+
interp_ok(())
187189
}
188190

189191
fn write<'tcx>(
@@ -265,13 +267,14 @@ fn anonsocket_write<'tcx>(
265267

266268
/// Read from AnonSocket and return the number of bytes read.
267269
fn anonsocket_read<'tcx>(
268-
self_ref: FileDescriptionRef,
269-
peer_fd: Option<FileDescriptionRef>,
270-
bytes: &[u8],
270+
self_ref: WeakFileDescriptionRef,
271+
peer_fd: WeakFileDescriptionRef,
272+
bytes: &mut [u8],
271273
ptr: Pointer,
272274
dest: &MPlaceTy<'tcx>,
273275
ecx: &mut MiriInterpCx<'tcx>,
274276
) -> InterpResult<'tcx> {
277+
let self_ref = self_ref.upgrade().unwrap(); // TODO: handle this later
275278
let anonsocket = self_ref.downcast::<AnonSocket>().unwrap();
276279
let Some(readbuf) = &anonsocket.readbuf else {
277280
// FIXME: This should return EBADF, but there's no nice way to do that as there's no
@@ -299,6 +302,7 @@ fn anonsocket_read<'tcx>(
299302
// don't know what that *certain number* is, we will provide a notification every time
300303
// a read is successful. This might result in our epoll emulation providing more
301304
// notifications than the real system.
305+
let peer_fd = peer_fd.upgrade(); // TODO: handle unwrap
302306
if let Some(peer_fd) = peer_fd {
303307
ecx.check_and_update_readiness(&peer_fd)?;
304308
}

0 commit comments

Comments
 (0)