@@ -142,15 +142,15 @@ impl FileDescription for Epoll {
142142
143143 fn destroy < ' tcx > (
144144 mut self ,
145- self_addr : usize ,
145+ self_id : FdId ,
146146 _communicate_allowed : bool ,
147147 ecx : & mut MiriInterpCx < ' tcx > ,
148148 ) -> InterpResult < ' tcx , io:: Result < ( ) > > {
149149 // If we were interested in some FDs, we can remove that now.
150150 let mut ids = self . interest_list . get_mut ( ) . keys ( ) . map ( |( id, _num) | * id) . collect :: < Vec < _ > > ( ) ;
151151 ids. dedup ( ) ; // they come out of the map sorted
152152 for id in ids {
153- ecx. machine . epoll_interests . remove ( id, self_addr ) ;
153+ ecx. machine . epoll_interests . remove ( id, self_id ) ;
154154 }
155155 interp_ok ( Ok ( ( ) ) )
156156 }
@@ -164,37 +164,38 @@ impl UnixFileDescription for Epoll {}
164164
165165/// The table of all EpollEventInterest.
166166/// This tracks, for each file description, which epoll instances have an interest in events
167- /// for this file description. The `Vec` is sorted by `addr`!
168- pub struct EpollInterestTable ( BTreeMap < FdId , Vec < WeakFileDescriptionRef < Epoll > > > ) ;
167+ /// for this file description. The `FdId` is the ID of the epoll instance, so that we can recognize
168+ /// it later when it is slated for removal. The vector is sorted by that ID.
169+ pub struct EpollInterestTable ( BTreeMap < FdId , Vec < ( FdId , WeakFileDescriptionRef < Epoll > ) > > ) ;
169170
170171impl EpollInterestTable {
171172 pub ( crate ) fn new ( ) -> Self {
172173 EpollInterestTable ( BTreeMap :: new ( ) )
173174 }
174175
175- fn insert ( & mut self , id : FdId , epoll : WeakFileDescriptionRef < Epoll > ) {
176+ fn insert ( & mut self , id : FdId , epoll : & FileDescriptionRef < Epoll > ) {
176177 let epolls = self . 0 . entry ( id) . or_default ( ) ;
177178 let idx = epolls
178- . binary_search_by_key ( & epoll. addr ( ) , |e| e . addr ( ) )
179+ . binary_search_by_key ( & epoll. id ( ) , |& ( id , _ ) | id )
179180 . expect_err ( "trying to add an epoll that's already in the list" ) ;
180- epolls. insert ( idx, epoll) ;
181+ epolls. insert ( idx, ( epoll. id ( ) , FileDescriptionRef :: downgrade ( epoll ) ) ) ;
181182 }
182183
183- fn remove ( & mut self , id : FdId , epoll_addr : usize ) {
184+ fn remove ( & mut self , id : FdId , epoll_id : FdId ) {
184185 let epolls = self . 0 . entry ( id) . or_default ( ) ;
185186 let idx = epolls
186- . binary_search_by_key ( & epoll_addr , |e| e . addr ( ) )
187+ . binary_search_by_key ( & epoll_id , |& ( id , _ ) | id )
187188 . expect ( "trying to remove an epoll that's not in the list" ) ;
188189 epolls. remove ( idx) ;
189190 }
190191
191- fn get_epolls ( & self , id : FdId ) -> Option < & Vec < WeakFileDescriptionRef < Epoll > > > {
192- self . 0 . get ( & id)
192+ fn get_epolls ( & self , id : FdId ) -> Option < impl Iterator < Item = & WeakFileDescriptionRef < Epoll > > > {
193+ self . 0 . get ( & id) . map ( |epolls| epolls . iter ( ) . map ( | ( _id , epoll ) | epoll ) )
193194 }
194195
195196 pub fn remove_epolls ( & mut self , id : FdId ) {
196197 if let Some ( epolls) = self . 0 . remove ( & id) {
197- for epoll in epolls. iter ( ) . filter_map ( |e| e . upgrade ( ) ) {
198+ for epoll in epolls. iter ( ) . filter_map ( |( _id , epoll ) | epoll . upgrade ( ) ) {
198199 // This is a still-live epoll with interest in this FD. Remove all
199200 // relevent interests.
200201 epoll
@@ -348,7 +349,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
348349 if interest_list. range ( range_for_id ( id) ) . next ( ) . is_none ( ) {
349350 // This is the first time this FD got added to this epoll.
350351 // Remember that in the global list so we get notified about FD events.
351- this. machine . epoll_interests . insert ( id, FileDescriptionRef :: downgrade ( & epfd) ) ;
352+ this. machine . epoll_interests . insert ( id, & epfd) ;
352353 }
353354 match interest_list. entry ( epoll_key) {
354355 btree_map:: Entry :: Occupied ( _) => {
@@ -388,7 +389,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
388389 // If this was the last interest in this FD, remove us from the global list
389390 // of who is interested in this FD.
390391 if interest_list. range ( range_for_id ( id) ) . next ( ) . is_none ( ) {
391- this. machine . epoll_interests . remove ( id, epfd. addr ( ) ) ;
392+ this. machine . epoll_interests . remove ( id, epfd. id ( ) ) ;
392393 }
393394
394395 // Remove related event instance from ready list.
@@ -541,7 +542,6 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
541542 return interp_ok ( ( ) ) ;
542543 } ;
543544 let epolls = epolls
544- . iter ( )
545545 . map ( |weak| {
546546 weak. upgrade ( )
547547 . expect ( "someone forgot to remove the garbage from `machine.epoll_interests`" )
0 commit comments