diff --git a/common/Cargo.toml b/common/Cargo.toml new file mode 100644 index 0000000000..3b6ffb5256 --- /dev/null +++ b/common/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "common" +version = "0.1.0" +authors = ["Jeremy Soller "] diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 0000000000..ecb19b8e28 --- /dev/null +++ b/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; diff --git a/fcntl/Cargo.toml b/fcntl/Cargo.toml index c8e3ff555c..ca316750d4 100644 --- a/fcntl/Cargo.toml +++ b/fcntl/Cargo.toml @@ -8,4 +8,4 @@ build = "build.rs" cbindgen = "0.5" [dependencies] -libc = { version = "0.2", default-features = false } +common = { path = "../common" } diff --git a/fcntl/src/lib.rs b/fcntl/src/lib.rs index 71c5787159..b68a5929bb 100644 --- a/fcntl/src/lib.rs +++ b/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; diff --git a/include/stdbool.h b/include/stdbool.h new file mode 100644 index 0000000000..e69de29bb2 diff --git a/include/stdint.h b/include/stdint.h new file mode 100644 index 0000000000..d7fa66c949 --- /dev/null +++ b/include/stdint.h @@ -0,0 +1,7 @@ +#ifndef _STDINT_H +#define _STDINT_H + +typedef int int32_t; +typedef int intptr_t; + +#endif /* _STDINT_H */ diff --git a/include/stdlib.h b/include/stdlib.h new file mode 100644 index 0000000000..d5f3b03cb3 --- /dev/null +++ b/include/stdlib.h @@ -0,0 +1,6 @@ +#ifndef _STDLIB_H +#define _STDLIB_H + +#include + +#endif /* _STDLIB_H */ diff --git a/include/sys/types.h b/include/sys/types.h new file mode 100644 index 0000000000..416f51149b --- /dev/null +++ b/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 */ diff --git a/src/lib.rs b/src/lib.rs index 4e4e661e2f..4c84deb549 100644 --- a/src/lib.rs +++ b/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 {} +} diff --git a/tests/.gitignore b/tests/.gitignore new file mode 100644 index 0000000000..7cd82ddb60 --- /dev/null +++ b/tests/.gitignore @@ -0,0 +1 @@ +/write diff --git a/tests/Makefile b/tests/Makefile new file mode 100644 index 0000000000..84981286b1 --- /dev/null +++ b/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 diff --git a/tests/write.c b/tests/write.c new file mode 100644 index 0000000000..0349a5c094 --- /dev/null +++ b/tests/write.c @@ -0,0 +1,5 @@ +#include + +void _start(void) { + write(STDOUT_FILENO, "Hello World!\n", 14); +} diff --git a/unistd/Cargo.toml b/unistd/Cargo.toml index 9d3813b9de..9e2a470951 100644 --- a/unistd/Cargo.toml +++ b/unistd/Cargo.toml @@ -8,4 +8,4 @@ build = "build.rs" cbindgen = "0.5" [dependencies] -libc = { version = "0.2", default-features = false } +common = { path = "../common" } diff --git a/unistd/src/lib.rs b/unistd/src/lib.rs index d85c672379..642965125b 100644 --- a/unistd/src/lib.rs +++ b/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;