瀏覽代碼

Fix ioctl being defined on redox, add cxa_atexit for gcc

Jeremy Soller 6 年之前
父節點
當前提交
9b0c74b935
共有 4 個文件被更改,包括 42 次插入9 次删除
  1. 28 0
      src/cxa.rs
  2. 4 0
      src/header/sys_ioctl/cbindgen.toml
  3. 9 9
      src/header/sys_ioctl/mod.rs
  4. 1 0
      src/lib.rs

+ 28 - 0
src/cxa.rs

@@ -0,0 +1,28 @@
+use platform::types::*;
+
+#[derive(Clone, Copy)]
+struct CxaAtExitFunc {
+    func: extern "C" fn (*mut c_void),
+    arg: *mut c_void,
+    dso: *mut c_void
+}
+
+static mut CXA_ATEXIT_FUNCS: [Option<CxaAtExitFunc>; 32] = [None; 32];
+
+#[no_mangle]
+pub unsafe extern "C" fn __cxa_atexit (func_opt: Option<extern "C" fn (*mut c_void)>, arg: *mut c_void, dso: *mut c_void) -> c_int {
+    for i in 0..CXA_ATEXIT_FUNCS.len() {
+        if CXA_ATEXIT_FUNCS[i].is_none() {
+            CXA_ATEXIT_FUNCS[i] = func_opt.map(|func| CxaAtExitFunc {
+                func,
+                arg,
+                dso
+            });
+            return 0;
+        }
+    }
+
+    -1
+}
+
+// TODO: cxa_finalize

+ 4 - 0
src/header/sys_ioctl/cbindgen.toml

@@ -5,6 +5,10 @@ language = "C"
 # sgtty is used by another header, and cbindgen doesn't prefix that with `struct` :|
 style = "Both"
 
+[defines]
+"target_os=linux" = "__linux__"
+"target_os=redox" = "__redox__"
+
 [enum]
 prefix_with_name = true
 

+ 9 - 9
src/header/sys_ioctl/mod.rs

@@ -12,20 +12,20 @@ pub struct sgttyb {
     sg_flags: c_ushort,
 }
 
-#[repr(C)]
-#[derive(Default)]
-pub struct winsize {
-    ws_row: c_ushort,
-    ws_col: c_ushort,
-    ws_xpixel: c_ushort,
-    ws_ypixel: c_ushort,
-}
-
 #[cfg(target_os = "linux")]
 pub mod inner {
     use platform::types::*;
     use platform::Sys;
 
+    #[repr(C)]
+    #[derive(Default)]
+    pub struct winsize {
+        ws_row: c_ushort,
+        ws_col: c_ushort,
+        ws_xpixel: c_ushort,
+        ws_ypixel: c_ushort,
+    }
+
     #[no_mangle]
     pub extern "C" fn ioctl(fd: c_int, request: c_ulong, out: *mut c_void) -> c_int {
         // TODO: Somehow support varargs to syscall??

+ 1 - 0
src/lib.rs

@@ -36,6 +36,7 @@ extern crate spin;
 #[macro_use]
 mod macros;
 pub mod c_str;
+pub mod cxa;
 pub mod fs;
 pub mod header;
 pub mod io;