File tree Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Expand file tree Collapse file tree 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
122122
123123 let sys_getrandom = this. eval_libc ( "SYS_getrandom" ) . to_target_usize ( this) ?;
124124 let sys_futex = this. eval_libc ( "SYS_futex" ) . to_target_usize ( this) ?;
125+ let sys_eventfd2 = this. eval_libc ( "SYS_eventfd2" ) . to_target_usize ( this) ?;
125126
126127 if args. is_empty ( ) {
127128 throw_ub_format ! (
@@ -155,6 +156,17 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
155156 id if id == sys_futex => {
156157 futex ( this, & args[ 1 ..] , dest) ?;
157158 }
159+ id if id == sys_eventfd2 => {
160+ let [ _, initval, flags, ..] = args else {
161+ throw_ub_format ! (
162+ "incorrect number of arguments for `eventfd2` syscall: got {}, expected at least 3" ,
163+ args. len( )
164+ ) ;
165+ } ;
166+
167+ let result = this. eventfd ( initval, flags) ?;
168+ this. write_int ( result. to_i32 ( ) ?, dest) ?;
169+ }
158170 id => {
159171 this. handle_unsupported_foreign_item ( format ! (
160172 "can't execute syscall with ID {id}"
Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ use std::thread;
1010fn main ( ) {
1111 test_read_write ( ) ;
1212 test_race ( ) ;
13+ test_syscall ( ) ;
1314}
1415
1516fn read_bytes < const N : usize > ( fd : i32 , buf : & mut [ u8 ; N ] ) -> i32 {
@@ -109,3 +110,11 @@ fn test_race() {
109110 thread:: yield_now ( ) ;
110111 thread1. join ( ) . unwrap ( ) ;
111112}
113+
114+ // This is a test for calling eventfd2 through a syscall.
115+ fn test_syscall ( ) {
116+ let initval = 0 as libc:: c_uint ;
117+ let flags = ( libc:: EFD_CLOEXEC | libc:: EFD_NONBLOCK ) as libc:: c_int ;
118+ let fd = unsafe { libc:: syscall ( libc:: SYS_eventfd2 , initval, flags) } ;
119+ assert_ne ! ( fd, -1 ) ;
120+ }
You can’t perform that action at this time.
0 commit comments