--- a/src/header/sys_eventfd/mod.rs +++ b/src/header/sys_eventfd/mod.rs @@ -5,6 +5,7 @@ use crate::c_str::{CStr, CString}; use crate::error::{Errno, ResultExt}; use crate::header::fcntl::{O_CLOEXEC, O_NONBLOCK, O_RDWR}; +use crate::header::errno::EFAULT; use crate::header::errno::EINVAL; use crate::platform::{Pal, Sys, types::{c_int, c_uint}}; @@ -35,3 +36,24 @@ } Sys::open(CStr::borrow(&cpath), oflag, 0).or_minus_one_errno() } + +#[unsafe(no_mangle)] +pub extern "C" fn eventfd_read(fd: c_int, value: *mut eventfd_t) -> c_int { + if value.is_null() { + return Err::(Errno(EFAULT)).or_minus_one_errno(); + } + let mut buf = [0u8; 8]; + match Sys::read(fd, &mut buf) { + Ok(8) => { unsafe { *value = u64::from_ne_bytes(buf); } 0 } + _ => -1, + } +} + +#[unsafe(no_mangle)] +pub extern "C" fn eventfd_write(fd: c_int, value: eventfd_t) -> c_int { + let buf = value.to_ne_bytes(); + match Sys::write(fd, &buf) { + Ok(8) => 0, + _ => -1, + } +}