浏览代码

WIP: Define common types

Jeremy Soller 7 年之前
父节点
当前提交
a9aae80ae0
共有 14 个文件被更改,包括 117 次插入6 次删除
  1. 4 0
      common/Cargo.toml
  2. 60 0
      common/src/lib.rs
  3. 1 1
      fcntl/Cargo.toml
  4. 2 2
      fcntl/src/lib.rs
  5. 0 0
      include/stdbool.h
  6. 7 0
      include/stdint.h
  7. 6 0
      include/stdlib.h
  8. 16 0
      include/sys/types.h
  9. 7 0
      src/lib.rs
  10. 1 0
      tests/.gitignore
  11. 5 0
      tests/Makefile
  12. 5 0
      tests/write.c
  13. 1 1
      unistd/Cargo.toml
  14. 2 2
      unistd/src/lib.rs

+ 4 - 0
common/Cargo.toml

@@ -0,0 +1,4 @@
+[package]
+name = "common"
+version = "0.1.0"
+authors = ["Jeremy Soller <jackpot51@gmail.com>"]

+ 60 - 0
common/src/lib.rs

@@ -0,0 +1,60 @@
+//! fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html
+
+#![no_std]
+#![allow(non_camel_case_types)]
+
+// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
+// more optimization opportunities around it recognizing things like
+// malloc/free.
+#[repr(u8)]
+pub enum c_void {
+    // Two dummy variants so the #[repr] attribute can be used.
+    #[doc(hidden)]
+    __variant1,
+    #[doc(hidden)]
+    __variant2,
+}
+
+pub type int8_t = i8;
+pub type int16_t = i16;
+pub type int32_t = i32;
+pub type int64_t = i64;
+pub type uint8_t = u8;
+pub type uint16_t = u16;
+pub type uint32_t = u32;
+pub type uint64_t = u64;
+
+pub type c_schar = i8;
+pub type c_uchar = u8;
+pub type c_short = i16;
+pub type c_ushort = u16;
+pub type c_int = i32;
+pub type c_uint = u32;
+pub type c_float = f32;
+pub type c_double = f64;
+pub type c_longlong = i64;
+pub type c_ulonglong = u64;
+pub type intmax_t = i64;
+pub type uintmax_t = u64;
+
+pub type size_t = usize;
+pub type ptrdiff_t = isize;
+pub type intptr_t = isize;
+pub type uintptr_t = usize;
+pub type ssize_t = isize;
+
+pub type c_char = i8;
+pub type c_long = i64;
+pub type c_ulong = u64;
+
+pub type wchar_t = i16;
+
+pub type off_t = c_long;
+pub type mode_t = u16;
+pub type time_t = i64;
+pub type pid_t = usize;
+pub type gid_t = usize;
+pub type uid_t = usize;
+
+pub type useconds_t = i32;
+pub type suseconds_t = i64;

+ 1 - 1
fcntl/Cargo.toml

@@ -8,4 +8,4 @@ build = "build.rs"
 cbindgen = "0.5"
 
 [dependencies]
-libc = { version = "0.2", default-features = false }
+common = { path = "../common" }

+ 2 - 2
fcntl/src/lib.rs

@@ -2,9 +2,9 @@
 
 #![no_std]
 
-extern crate libc;
+extern crate common;
 
-use libc::*;
+pub use common::*;
 
 pub const F_DUPFD: c_int = 0;
 pub const F_GETFD: c_int = 1;

+ 0 - 0
include/stdbool.h


+ 7 - 0
include/stdint.h

@@ -0,0 +1,7 @@
+#ifndef _STDINT_H
+#define _STDINT_H
+
+typedef int int32_t;
+typedef int intptr_t;
+
+#endif /* _STDINT_H */

+ 6 - 0
include/stdlib.h

@@ -0,0 +1,6 @@
+#ifndef _STDLIB_H
+#define _STDLIB_H
+
+#include <sys/types.h>
+
+#endif /* _STDLIB_H */

+ 16 - 0
include/sys/types.h

@@ -0,0 +1,16 @@
+#ifndef _SYS_TYPES_H
+#define _SYS_TYPES_H
+
+typedef int gid_t;
+typedef int uid_t;
+
+typedef long off_t;
+
+typedef int pid_t;
+
+typedef unsigned long size_t;
+typedef long ssize_t;
+
+typedef int useconds_t;
+
+#endif /* _SYS_TYPES_H */

+ 7 - 0
src/lib.rs

@@ -1,7 +1,14 @@
 #![no_std]
+#![feature(lang_items)]
 
 extern crate fcntl;
 extern crate unistd;
 
 pub use fcntl::*;
 pub use unistd::*;
+
+#[lang = "panic_fmt"]
+#[no_mangle]
+pub extern "C" fn rust_begin_unwind(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> ! {
+    loop {}
+}

+ 1 - 0
tests/.gitignore

@@ -0,0 +1 @@
+/write

+ 5 - 0
tests/Makefile

@@ -0,0 +1,5 @@
+write: write.c
+	gcc -nostdinc -nostdlib -I ../include -I ../target/include $< ../target/debug/libc.a -o $@
+
+clean:
+	rm -f write

+ 5 - 0
tests/write.c

@@ -0,0 +1,5 @@
+#include <unistd.h>
+
+void _start(void) {
+    write(STDOUT_FILENO, "Hello World!\n", 14);
+}

+ 1 - 1
unistd/Cargo.toml

@@ -8,4 +8,4 @@ build = "build.rs"
 cbindgen = "0.5"
 
 [dependencies]
-libc = { version = "0.2", default-features = false }
+common = { path = "../common" }

+ 2 - 2
unistd/src/lib.rs

@@ -2,9 +2,9 @@
 
 #![no_std]
 
-extern crate libc;
+extern crate common;
 
-use libc::*;
+pub use common::*;
 
 pub const NULL: c_int = 0;