@@ -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.
267269fn 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