milestone1
This commit is contained in:
@@ -1,19 +1,17 @@
|
||||
diff --git a/src/header/sys_eventfd/cbindgen.toml b/src/header/sys_eventfd/cbindgen.toml
|
||||
new file mode 100644
|
||||
index 00000000..c47f467f
|
||||
index 00000000..a1b2c3d4
|
||||
--- /dev/null
|
||||
+++ b/src/header/sys_eventfd/cbindgen.toml
|
||||
@@ -0,0 +1,13 @@
|
||||
@@ -0,0 +1,11 @@
|
||||
+sys_includes = ["stdint.h"]
|
||||
+after_includes = """
|
||||
+typedef uint64_t eventfd_t;
|
||||
+int eventfd(unsigned int initval, int flags);
|
||||
+"""
|
||||
+include_guard = "_SYS_EVENTFD_H"
|
||||
+language = "C"
|
||||
+style = "Tag"
|
||||
+no_includes = true
|
||||
+cpp_compat = true
|
||||
+
|
||||
+[enum]
|
||||
+prefix_with_name = true
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
--- 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::<c_int, _>(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,
|
||||
+ }
|
||||
+}
|
||||
@@ -0,0 +1,20 @@
|
||||
diff --git a/include/stddef.h b/include/stddef.h
|
||||
index 334267f4..beefde5e 100644
|
||||
--- a/include/stddef.h
|
||||
+++ b/include/stddef.h
|
||||
@@ -1,6 +1,5 @@
|
||||
#ifndef _STDDEF_H
|
||||
#define _STDDEF_H
|
||||
-#include <stdint.h>
|
||||
|
||||
#define NULL 0
|
||||
|
||||
@@ -11,6 +10,8 @@ typedef __PTRDIFF_TYPE__ ptrdiff_t;
|
||||
|
||||
typedef long unsigned int size_t;
|
||||
|
||||
+#include <stdint.h>
|
||||
+
|
||||
typedef struct { long long __ll; long double __ld; } max_align_t;
|
||||
|
||||
#define offsetof(type, member) __builtin_offsetof(type, member)
|
||||
Reference in New Issue
Block a user