11//! Linux `eventfd` implementation.
22//! Currently just a stub.
3- use std:: cell:: Cell ;
43use std:: io;
54
65use rustc_middle:: ty:: TyCtxt ;
@@ -20,7 +19,7 @@ use crate::*;
2019struct Event {
2120 /// The object contains an unsigned 64-bit integer (uint64_t) counter that is maintained by the
2221 /// kernel. This counter is initialized with the value specified in the argument initval.
23- val : Cell < u64 > ,
22+ val : u64 ,
2423}
2524
2625impl FileDescriptor for Event {
@@ -30,7 +29,7 @@ impl FileDescriptor for Event {
3029
3130 fn dup ( & mut self ) -> io:: Result < Box < dyn FileDescriptor > > {
3231 // FIXME: this is wrong, the new and old FD should refer to the same event object!
33- Ok ( Box :: new ( Event { val : self . val . clone ( ) } ) )
32+ Ok ( Box :: new ( Event { val : self . val } ) )
3433 }
3534
3635 fn close < ' tcx > (
@@ -53,12 +52,11 @@ impl FileDescriptor for Event {
5352 /// supplied buffer is less than 8 bytes, or if an attempt is
5453 /// made to write the value 0xffffffffffffffff.
5554 fn write < ' tcx > (
56- & self ,
55+ & mut self ,
5756 _communicate_allowed : bool ,
5857 bytes : & [ u8 ] ,
5958 tcx : TyCtxt < ' tcx > ,
6059 ) -> InterpResult < ' tcx , io:: Result < usize > > {
61- let v1 = self . val . get ( ) ;
6260 let bytes: [ u8 ; 8 ] = bytes. try_into ( ) . unwrap ( ) ; // FIXME fail gracefully when this has the wrong size
6361 // Convert from target endianness to host endianness.
6462 let num = match tcx. sess . target . endian {
@@ -67,9 +65,7 @@ impl FileDescriptor for Event {
6765 } ;
6866 // FIXME handle blocking when addition results in exceeding the max u64 value
6967 // or fail with EAGAIN if the file descriptor is nonblocking.
70- let v2 = v1. checked_add ( num) . unwrap ( ) ;
71- self . val . set ( v2) ;
72- assert_eq ! ( 8 , bytes. len( ) ) ;
68+ self . val = self . val . checked_add ( num) . unwrap ( ) ;
7369 Ok ( Ok ( 8 ) )
7470 }
7571}
@@ -119,7 +115,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
119115 throw_unsup_format ! ( "eventfd: EFD_SEMAPHORE is unsupported" ) ;
120116 }
121117
122- let fd = this. machine . fds . insert_fd ( Box :: new ( Event { val : Cell :: new ( val. into ( ) ) } ) ) ;
118+ let fd = this. machine . fds . insert_fd ( Box :: new ( Event { val : val. into ( ) } ) ) ;
123119 Ok ( Scalar :: from_i32 ( fd) )
124120 }
125121}
0 commit comments