Skip to content

Commit

Permalink
Fix some implementation error
Browse files Browse the repository at this point in the history
  • Loading branch information
tiif committed Dec 13, 2024
1 parent 7a2af19 commit 6d9d5dd
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/shims/unix/unnamed_socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,13 @@ impl FileDescription for AnonSocket {
/// Write to AnonSocket based on the space available and return the written byte size.
/// This is only for socketpair/pipe without O_NONBLOCK flag.
fn anonsocket_write<'tcx>(
self_ref: WeakFileDescriptionRef,
weak_self_ref: WeakFileDescriptionRef,
ptr: Pointer,
len: usize,
dest: MPlaceTy<'tcx>,
ecx: &mut MiriInterpCx<'tcx>,
) -> InterpResult<'tcx> {
let self_ref = self_ref.upgrade().unwrap(); // TODO: handle this later
let self_ref = weak_self_ref.upgrade().unwrap(); // TODO: handle this later
let anonsocket = self_ref.downcast::<AnonSocket>().unwrap();
let peer_fd = anonsocket.peer_fd().upgrade().unwrap(); // TODO
let Some(writebuf) = &peer_fd.downcast::<AnonSocket>().unwrap().readbuf else {
Expand All @@ -193,21 +193,20 @@ fn anonsocket_write<'tcx>(
// This is only for blocking socketpair.
if available_space == 0 {
// Blocking socketpair with a full buffer.
let weak_peer_fd = peer_fd.downgrade();
let dest = dest.clone();
anonsocket.blocked_write_tid.borrow_mut().push(ecx.active_thread());
ecx.block_thread(
BlockReason::UnnamedSocket,
None,
callback!(
@capture<'tcx> {
weak_peer_fd: WeakFileDescriptionRef,
weak_self_ref: WeakFileDescriptionRef,
ptr: Pointer,
len: usize,
dest: MPlaceTy<'tcx>,
}
@unblock = |this| {
anonsocket_write(weak_peer_fd, ptr, len, dest, this)
anonsocket_write(weak_self_ref, ptr, len, dest, this)
}
),
);
Expand All @@ -229,8 +228,7 @@ fn anonsocket_write<'tcx>(
// The kernel does this even if the fd was already readable before, so we follow suit.
ecx.check_and_update_readiness(&peer_fd)?;
let peer_anonsocket = peer_fd.downcast::<AnonSocket>().unwrap();
// Unblock thread that is currently block on peer_fd's read.
// TODO: figure out unblock one or unblock all.
// Unblock all threads that are currently blocked on peer_fd's read.
let waiting_threads = std::mem::take(&mut *peer_anonsocket.blocked_read_tid.borrow_mut());
// FIXME: We can randomize the order of unblocking.
for thread_id in waiting_threads {
Expand Down Expand Up @@ -313,8 +311,7 @@ fn anonsocket_read<'tcx>(
if let Some(peer_fd) = anonsocket.peer_fd().upgrade() {
ecx.check_and_update_readiness(&peer_fd)?;
let peer_anonsocket = peer_fd.downcast::<AnonSocket>().unwrap();
// Unblock thread that is currently block on peer_fd's write.
// TODO: figure out unblock one or unblock all.
// Unblock all threads that are currently blocked on peer_fd's write.
let waiting_threads =
std::mem::take(&mut *peer_anonsocket.blocked_write_tid.borrow_mut());
// FIXME: We can randomize the order of unblocking.
Expand Down

0 comments on commit 6d9d5dd

Please sign in to comment.