@@ -422,6 +422,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
422422 } else {
423423 // Blocking
424424 let duration = Duration :: from_millis ( timeout. into ( ) ) ;
425+ drop ( ready_list) ;
425426 this. block_thread (
426427 BlockReason :: Epoll ,
427428 Some ( ( TimeoutClock :: Monotonic , TimeoutAnchor :: Relative , duration) ) ,
@@ -437,14 +438,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
437438 Ok ( ( ) )
438439 }
439440 @timeout = |this| {
441+ // No notification after blocking timeout.
440442 this. write_scalar( Scalar :: from_i32( 0 ) , & dest) ?;
441443 Ok ( ( ) )
442444 }
443445 ) ,
444446 ) ;
445447 }
446448 } else {
447- // Non-blocking with notification returned.
449+ // Immediately return epoll notification without blocking.
450+
451+ // Attempt to prevent epfd.borrow_mut in blocking_epoll_callback causing ICE.
452+ drop ( ready_list) ;
448453 this. blocking_epoll_callback ( epfd_value, weak_epfd, & dest, & event) ?;
449454 return Ok ( ( ) ) ;
450455 }
@@ -463,15 +468,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
463468 let this = self . eval_context_mut ( ) ;
464469
465470 let Some ( epfd) = weak_epfd. upgrade ( ) else {
466- throw_unsup_format ! ( "epoll file descriptor {epfd_value} is closed while blocking." )
471+ throw_unsup_format ! ( "epoll FD {epfd_value} is closed while blocking." )
467472 } ;
468473
469- let mut binding = epfd. borrow_mut ( ) ;
470- let epoll_file_description = & mut binding
471- . downcast_mut :: < Epoll > ( )
472- . ok_or_else ( || err_unsup_format ! ( "non-epoll FD passed to `epoll_wait`" ) ) ?;
474+ //TODO: What if, there is another thread that make changes to the global fd table here?
475+ // For example close the current epfd, then insert a new one inside?
473476
474- let binding = epoll_file_description . get_ready_list ( ) ;
477+ let binding = epfd . borrow_mut ( ) . downcast_mut :: < Epoll > ( ) . unwrap ( ) . get_ready_list ( ) ;
475478 let mut ready_list = binding. borrow_mut ( ) ;
476479 let mut num_of_events: i32 = 0 ;
477480 let mut array_iter = this. project_array_fields ( event) ?;
0 commit comments