From 441bf9f00b67a5c82ddb2e33d77a8961a2279a69 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Mon, 25 Jun 2018 11:43:44 +0200 Subject: [PATCH 01/13] Add the few last things to get gcc_complete working --- include/assert.h | 14 ++++++++++++++ include/stddef.h | 4 ++-- include/stdint.h | 24 ++++++++++++------------ src/stdlib/src/lib.rs | 10 +++++++--- tests/.gitignore | 1 + tests/Makefile | 1 + tests/assert.c | 14 ++++++++++++++ tests/expected/assert.stderr | 0 tests/expected/assert.stdout | 1 + 9 files changed, 52 insertions(+), 17 deletions(-) create mode 100644 tests/assert.c create mode 100644 tests/expected/assert.stderr create mode 100644 tests/expected/assert.stdout diff --git a/include/assert.h b/include/assert.h index e69de29bb2..1a40206214 100644 --- a/include/assert.h +++ b/include/assert.h @@ -0,0 +1,14 @@ +#ifndef _ASSERT_H +#define _ASSERT_H + +#ifdef NDEBUG +# define assert(cond) +#else +# include +# define assert(cond) if (!(cond)) { \ + fprintf(stderr, "%s: %s:%d: Assertion `%s` failed.\n", __func__, __FILE__, __LINE__, #cond); \ + abort(); \ + } +#endif + +#endif diff --git a/include/stddef.h b/include/stddef.h index fa0bc7daf5..099ca1574b 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -3,10 +3,10 @@ #define NULL 0 -typedef signed long long ptrdiff_t; +typedef signed long ptrdiff_t; typedef unsigned char wchar_t; -typedef unsigned long long size_t; +typedef unsigned long size_t; #endif /* _STDDEF_H */ diff --git a/include/stdint.h b/include/stdint.h index 8b787427af..cf25e00fbe 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -56,54 +56,54 @@ typedef unsigned short uint_fast16_t; #define INT32_C(value) value ## L #define INT32_MIN -0x80000000 #define INT32_MAX 0x7FFFFFFF -typedef signed long int32_t; +typedef signed int int32_t; #define INT_LEAST32_MIN -0x80000000 #define INT_LEAST32_MAX 0x7FFFFFFF -typedef signed long int_least32_t; +typedef signed int int_least32_t; #define INT_FAST32_MIN -0x80000000 #define INT_FAST32_MAX 0x7FFFFFFF -typedef signed long int_fast32_t; +typedef signed int int_fast32_t; #define UINT32_C(value) value ## UL #define UINT32_MIN 0x00000000 #define UINT32_MAX 0xFFFFFFFF -typedef unsigned long uint32_t; +typedef unsigned int uint32_t; #define UINT_LEAST32_MIN 0x00000000 #define UINT_LEAST32_MAX 0xFFFFFFFF -typedef unsigned long uint_least32_t; +typedef unsigned int uint_least32_t; #define UINT_FAST32_MIN 0x00000000 #define UINT_FAST32_MAX 0xFFFFFFFF -typedef unsigned long uint_fast32_t; +typedef unsigned int uint_fast32_t; #define INT64_C(value) value ## LL #define INT64_MIN -0x8000000000000000 #define INT64_MAX 0x7FFFFFFFFFFFFFFF -typedef signed long long int64_t; +typedef signed long int64_t; #define INT_LEAST64_MIN -0x8000000000000000 #define INT_LEAST64_MAX 0x7FFFFFFFFFFFFFFF -typedef signed long long int_least64_t; +typedef signed long int_least64_t; #define INT_FAST64_MIN -0x8000000000000000 #define INT_FAST64_MAX 0x7FFFFFFFFFFFFFFF -typedef signed long long int_fast64_t; +typedef signed long int_fast64_t; #define UINT64_C(value) value ## ULL #define UINT64_MIN 0x0000000000000000 #define UINT64_MAX 0xFFFFFFFFFFFFFFFF -typedef unsigned long long uint64_t; +typedef unsigned long uint64_t; #define UINT_LEAST64_MIN 0x0000000000000000 #define UINT_LEAST64_MAX 0xFFFFFFFFFFFFFFFF -typedef unsigned long long uint_least64_t; +typedef unsigned long uint_least64_t; #define UINT_FAST64_MIN 0x0000000000000000 #define UINT_FAST64_MAX 0xFFFFFFFFFFFFFFFF -typedef unsigned long long uint_fast64_t; +typedef unsigned long uint_fast64_t; #define INTMAX_C(value) value ## LL #define INTMAX_MIN INT64_MIN diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index 8707ef5429..de4b44bac5 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -620,7 +620,11 @@ macro_rules! strto_impl { let set_endptr = |idx: isize| { if !$endptr.is_null() { - *$endptr = $s.offset(idx); + // This is stupid, but apparently strto* functions want + // const input but mut output, yet the man page says + // "stores the address of the first invalid character in *endptr" + // so obviously it doesn't want us to clone it. + *$endptr = $s.offset(idx) as *mut _; } }; @@ -712,7 +716,7 @@ macro_rules! strto_impl { #[no_mangle] pub unsafe extern "C" fn strtoul(s: *const c_char, - endptr: *mut *const c_char, + endptr: *mut *mut c_char, base: c_int) -> c_ulong { strto_impl!( @@ -728,7 +732,7 @@ pub unsafe extern "C" fn strtoul(s: *const c_char, #[no_mangle] pub unsafe extern "C" fn strtol(s: *const c_char, - endptr: *mut *const c_char, + endptr: *mut *mut c_char, base: c_int) -> c_long { strto_impl!( diff --git a/tests/.gitignore b/tests/.gitignore index 37a4bde5c4..156ddf2607 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -1,6 +1,7 @@ /*.out /gen/ /alloc +/assert /args /atof /atoi diff --git a/tests/Makefile b/tests/Makefile index c15213a22a..c08209e3ec 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -1,5 +1,6 @@ # Binaries that should generate the same output every time EXPECT_BINS=\ + assert \ atof \ atoi \ brk \ diff --git a/tests/assert.c b/tests/assert.c new file mode 100644 index 0000000000..320737f2f6 --- /dev/null +++ b/tests/assert.c @@ -0,0 +1,14 @@ +#include +#include +#include + +int main() { + assert(1 == 1); + assert(1 + 1 == 2); + + puts("yay!"); + + //This fails, but I can't test it because that'd + //make the test fail lol + //assert(42 == 1337); +} diff --git a/tests/expected/assert.stderr b/tests/expected/assert.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/assert.stdout b/tests/expected/assert.stdout new file mode 100644 index 0000000000..3650d378d3 --- /dev/null +++ b/tests/expected/assert.stdout @@ -0,0 +1 @@ +yay! From 5537817594ff8401719225aba2972a68e0eb8f83 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 08:35:27 +0200 Subject: [PATCH 02/13] Export libm as well --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 319784926b..8ffd601d91 100644 --- a/Makefile +++ b/Makefile @@ -40,6 +40,7 @@ install: all cp -v "$(BUILD)/debug/crt0.o" "$(DESTDIR)/lib" cp -rv "openlibm/include"/* "$(DESTDIR)/include" cp -rv "openlibm/src"/*.h "$(DESTDIR)/include" + cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a" libc: $(BUILD)/debug/libc.a $(BUILD)/debug/crt0.o From feed73ffccec88cd81b78a864b5db9a37ec46141 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 09:51:07 +0200 Subject: [PATCH 03/13] inttypes --- Cargo.lock | 13 ++- Cargo.toml | 1 + include/bits/inttypes.h | 190 +++++++++++++++++++++++++++++++++++++ include/complex.h | 2 + src/inttypes/Cargo.toml | 14 +++ src/inttypes/build.rs | 11 +++ src/inttypes/cbindgen.toml | 7 ++ src/inttypes/src/lib.rs | 74 +++++++++++++++ src/setjmp/Cargo.toml | 3 - src/stdlib/src/lib.rs | 11 ++- 10 files changed, 317 insertions(+), 9 deletions(-) create mode 100644 include/bits/inttypes.h create mode 100644 include/complex.h create mode 100644 src/inttypes/Cargo.toml create mode 100644 src/inttypes/build.rs create mode 100644 src/inttypes/cbindgen.toml create mode 100644 src/inttypes/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 62797b88a5..958708dd69 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -148,6 +148,17 @@ dependencies = [ "sys_socket 0.1.0", ] +[[package]] +name = "inttypes" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.2", + "ctype 0.1.0", + "errno 0.1.0", + "platform 0.1.0", + "stdlib 0.1.0", +] + [[package]] name = "itoa" version = "0.4.1" @@ -274,6 +285,7 @@ dependencies = [ "fenv 0.1.0", "float 0.1.0", "grp 0.1.0", + "inttypes 0.1.0", "locale 0.1.0", "netinet 0.1.0", "platform 0.1.0", @@ -357,7 +369,6 @@ name = "setjmp" version = "0.1.0" dependencies = [ "cbindgen 0.5.2", - "platform 0.1.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index e30486397e..c644f51227 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,6 +20,7 @@ fcntl = { path = "src/fcntl" } fenv = { path = "src/fenv" } float = { path = "src/float" } grp = { path = "src/grp" } +inttypes = { path = "src/inttypes" } locale = { path = "src/locale" } netinet = { path = "src/netinet" } platform = { path = "src/platform" } diff --git a/include/bits/inttypes.h b/include/bits/inttypes.h new file mode 100644 index 0000000000..996a450554 --- /dev/null +++ b/include/bits/inttypes.h @@ -0,0 +1,190 @@ +#define PRId8 "i" +#define PRId16 "i" +#define PRId32 "i" +#define PRId64 "i" + +#define PRIdLEAST8 "i" +#define PRIdLEAST16 "i" +#define PRIdLEAST32 "i" +#define PRIdLEAST64 "i" + +#define PRIdFAST8 "i" +#define PRIdFAST16 "i" +#define PRIdFAST32 "i" +#define PRIdFAST64 "i" + +#define PRIi8 "i" +#define PRIi16 "i" +#define PRIi32 "i" +#define PRIi64 "i" + +#define PRIiLEAST8 "i" +#define PRIiLEAST16 "i" +#define PRIiLEAST32 "i" +#define PRIiLEAST64 "i" + +#define PRIiFAST8 "i" +#define PRIiFAST16 "i" +#define PRIiFAST32 "i" +#define PRIiFAST64 "i" + +#define PRIo8 "o" +#define PRIo16 "o" +#define PRIo32 "o" +#define PRIo64 "o" + +#define PRIoLEAST8 "o" +#define PRIoLEAST16 "o" +#define PRIoLEAST32 "o" +#define PRIoLEAST64 "o" + +#define PRIoFAST8 "o" +#define PRIoFAST16 "o" +#define PRIoFAST32 "o" +#define PRIoFAST64 "o" + +#define PRIu8 "u" +#define PRIu16 "u" +#define PRIu32 "u" +#define PRIu64 "u" + +#define PRIuLEAST8 "u" +#define PRIuLEAST16 "u" +#define PRIuLEAST32 "u" +#define PRIuLEAST64 "u" + +#define PRIuFAST8 "u" +#define PRIuFAST16 "u" +#define PRIuFAST32 "u" +#define PRIuFAST64 "u" + +#define PRIx8 "x" +#define PRIx16 "x" +#define PRIx32 "x" +#define PRIx64 "x" + +#define PRIxLEAST8 "x" +#define PRIxLEAST16 "x" +#define PRIxLEAST32 "x" +#define PRIxLEAST64 "x" + +#define PRIxFAST8 "x" +#define PRIxFAST16 "x" +#define PRIxFAST32 "x" +#define PRIxFAST64 "x" + +#define PRIX8 "X" +#define PRIX16 "X" +#define PRIX32 "X" +#define PRIX64 "X" + +#define PRIXLEAST8 "X" +#define PRIXLEAST16 "X" +#define PRIXLEAST32 "X" +#define PRIXLEAST64 "X" + +#define PRIXFAST8 "X" +#define PRIXFAST16 "X" +#define PRIXFAST32 "X" +#define PRIXFAST64 "X" + +#define PRIdMAX "d" +#define PRIiMAX "i" +#define PRIoMAX "o" +#define PRIuMAX "u" +#define PRIxMAX "x" +#define PRIXMAX "X" + +#define PRIdPTR "d" +#define PRIiPTR "i" +#define PRIoPTR "o" +#define PRIuPTR "u" +#define PRIxPTR "x" +#define PRIXPTR "X" + +#define SCNd8 "hhd" +#define SCNd16 "hd" +#define SCNd32 "d" +#define SCNd64 "ld" + +#define SCNdLEAST8 "hhd" +#define SCNdLEAST16 "hd" +#define SCNdLEAST32 "d" +#define SCNdLEAST64 "ld" + +#define SCNdFAST8 "hhd" +#define SCNdFAST16 "hd" +#define SCNdFAST32 "d" +#define SCNdFAST64 "ld" + +#define SCNi8 "hhi" +#define SCNi16 "hi" +#define SCNi32 "i" +#define SCNi64 "li" + +#define SCNiLEAST8 "hhi" +#define SCNiLEAST16 "hi" +#define SCNiLEAST32 "i" +#define SCNiLEAST64 "li" + +#define SCNiFAST8 "hhi" +#define SCNiFAST16 "hi" +#define SCNiFAST32 "i" +#define SCNiFAST64 "li" + +#define SCNo8 "hho" +#define SCNo16 "ho" +#define SCNo32 "o" +#define SCNo64 "lo" + +#define SCNoLEAST8 "hho" +#define SCNoLEAST16 "ho" +#define SCNoLEAST32 "o" +#define SCNoLEAST64 "lo" + +#define SCNoFAST8 "hho" +#define SCNoFAST16 "ho" +#define SCNoFAST32 "o" +#define SCNoFAST64 "lo" + +#define SCNu8 "hhu" +#define SCNu16 "hu" +#define SCNu32 "u" +#define SCNu64 "lu" + +#define SCNuLEAST8 "hhu" +#define SCNuLEAST16 "hu" +#define SCNuLEAST32 "u" +#define SCNuLEAST64 "lu" + +#define SCNuFAST8 "hhu" +#define SCNuFAST16 "hu" +#define SCNuFAST32 "u" +#define SCNuFAST64 "lu" + +#define SCNx8 "hhx" +#define SCNx16 "hx" +#define SCNx32 "x" +#define SCNx64 "lx" + +#define SCNxLEAST8 "hhx" +#define SCNxLEAST16 "hx" +#define SCNxLEAST32 "x" +#define SCNxLEAST64 "lx" + +#define SCNxFAST8 "hhx" +#define SCNxFAST16 "hx" +#define SCNxFAST32 "x" +#define SCNxFAST64 "lx" + +#define SCNdMAX "jd" +#define SCNiMAX "ji" +#define SCNoMAX "jo" +#define SCNuMAX "ju" +#define SCNxMAX "jx" + +#define SCNdPTR "td" +#define SCNiPTR "ti" +#define SCNoPTR "to" +#define SCNuPTR "tu" +#define SCNxPTR "tx" diff --git a/include/complex.h b/include/complex.h new file mode 100644 index 0000000000..5ce9f25af7 --- /dev/null +++ b/include/complex.h @@ -0,0 +1,2 @@ +#define OPENLIBM_USE_HOST_FENV_H 1 +#include diff --git a/src/inttypes/Cargo.toml b/src/inttypes/Cargo.toml new file mode 100644 index 0000000000..68a991073e --- /dev/null +++ b/src/inttypes/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "inttypes" +version = "0.1.0" +authors = ["jD91mZM2 "] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +ctype = { path = "../ctype" } +errno = { path = "../errno" } +platform = { path = "../platform" } +stdlib = { path = "../stdlib" } diff --git a/src/inttypes/build.rs b/src/inttypes/build.rs new file mode 100644 index 0000000000..483201ff82 --- /dev/null +++ b/src/inttypes/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/inttypes.h"); +} diff --git a/src/inttypes/cbindgen.toml b/src/inttypes/cbindgen.toml new file mode 100644 index 0000000000..cf838460c5 --- /dev/null +++ b/src/inttypes/cbindgen.toml @@ -0,0 +1,7 @@ +sys_includes = ["stdint.h"] +include_guard = "_INTTYPES_H" +trailer = "#include " +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/inttypes/src/lib.rs b/src/inttypes/src/lib.rs new file mode 100644 index 0000000000..0ceb7bc55b --- /dev/null +++ b/src/inttypes/src/lib.rs @@ -0,0 +1,74 @@ +#[macro_use] extern crate stdlib; +extern crate ctype; +extern crate errno; +extern crate platform; + +use errno::*; +use platform::types::*; + +#[no_mangle] +pub extern "C" fn imaxabs(i: intmax_t) -> intmax_t { + i.abs() +} + +#[no_mangle] +#[repr(C)] +pub struct intmaxdiv_t { + quot: intmax_t, + rem: intmax_t +} + +#[no_mangle] +pub extern "C" fn imaxdiv(i: intmax_t, j: intmax_t) -> intmaxdiv_t { + intmaxdiv_t { + quot: i / j, + rem: i % j + } +} + +#[no_mangle] +pub unsafe extern "C" fn strtoimax(s: *const c_char, + endptr: *mut *mut c_char, + base: c_int) + -> intmax_t { + use stdlib::*; + strto_impl!( + intmax_t, + false, + intmax_t::max_value(), + intmax_t::min_value(), + s, + endptr, + base + ) +} + +#[no_mangle] +pub unsafe extern "C" fn strtoumax(s: *const c_char, + endptr: *mut *mut c_char, + base: c_int) + -> uintmax_t { + use stdlib::*; + strto_impl!( + uintmax_t, + false, + uintmax_t::max_value(), + uintmax_t::min_value(), + s, + endptr, + base + ) +} + +#[allow(unused)] +#[no_mangle] +pub extern "C" fn wcstoimax(nptr: *const wchar_t, endptr: *mut *mut wchar_t, + base: c_int) -> intmax_t { + unimplemented!(); +} +#[allow(unused)] +#[no_mangle] +pub extern "C" fn wcstoumax(nptr: *const wchar_t, endptr: *mut *mut wchar_t, + base: c_int) -> uintmax_t { + unimplemented!(); +} diff --git a/src/setjmp/Cargo.toml b/src/setjmp/Cargo.toml index 1874c87603..ab9cbaa880 100644 --- a/src/setjmp/Cargo.toml +++ b/src/setjmp/Cargo.toml @@ -6,6 +6,3 @@ build = "build.rs" [build-dependencies] cbindgen = { path = "../../cbindgen" } - -[dependencies] -platform = { path = "../platform" } diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index de4b44bac5..7715ff53e4 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -498,7 +498,7 @@ pub unsafe extern "C" fn strtod(s: *const c_char, endptr: *mut *mut c_char) -> c } } -fn is_positive(ch: c_char) -> Option<(bool, isize)> { +pub fn is_positive(ch: c_char) -> Option<(bool, isize)> { match ch { 0 => None, ch if ch == b'+' as c_char => Some((true, 1)), @@ -507,7 +507,7 @@ fn is_positive(ch: c_char) -> Option<(bool, isize)> { } } -fn detect_base(s: *const c_char) -> Option<(c_int, isize)> { +pub fn detect_base(s: *const c_char) -> Option<(c_int, isize)> { let first = unsafe { *s } as u8; match first { 0 => None, @@ -526,7 +526,7 @@ fn detect_base(s: *const c_char) -> Option<(c_int, isize)> { } } -unsafe fn convert_octal(s: *const c_char) -> Option<(c_ulong, isize, bool)> { +pub unsafe fn convert_octal(s: *const c_char) -> Option<(c_ulong, isize, bool)> { if *s != 0 && *s == b'0' as c_char { if let Some((val, idx, overflow)) = convert_integer(s.offset(1), 8) { Some((val, idx + 1, overflow)) @@ -539,7 +539,7 @@ unsafe fn convert_octal(s: *const c_char) -> Option<(c_ulong, isize, bool)> { } } -unsafe fn convert_hex(s: *const c_char) -> Option<(c_ulong, isize, bool)> { +pub unsafe fn convert_hex(s: *const c_char) -> Option<(c_ulong, isize, bool)> { if (*s != 0 && *s == b'0' as c_char) && (*s.offset(1) != 0 && (*s.offset(1) == b'x' as c_char || *s.offset(1) == b'X' as c_char)) { @@ -549,7 +549,7 @@ unsafe fn convert_hex(s: *const c_char) -> Option<(c_ulong, isize, bool)> { } } -fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong, isize, bool)> { +pub fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong, isize, bool)> { // -1 means the character is invalid #[cfg_attr(rustfmt, rustfmt_skip)] const LOOKUP_TABLE: [c_long; 256] = [ @@ -603,6 +603,7 @@ fn convert_integer(s: *const c_char, base: c_int) -> Option<(c_ulong, isize, boo } } +#[macro_export] macro_rules! strto_impl { ( $rettype:ty, From ad324a0e4d202903533667ab2742ad375e9f9a4e Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 10:06:09 +0200 Subject: [PATCH 04/13] Use global_asm for setjmp instead --- Cargo.lock | 3 - include/{bits => }/setjmp.h | 4 +- src/setjmp/Cargo.toml | 4 -- src/setjmp/build.rs | 72 ------------------- src/setjmp/cbindgen.toml | 6 -- src/setjmp/{ => src}/impl/README.md | 0 src/setjmp/{ => src}/impl/aarch64/longjmp.s | 0 src/setjmp/{ => src}/impl/aarch64/setjmp.s | 0 src/setjmp/{ => src}/impl/arm/longjmp.s | 0 src/setjmp/{ => src}/impl/arm/setjmp.s | 0 src/setjmp/{ => src}/impl/bin/.gitignore | 0 src/setjmp/{ => src}/impl/i386/longjmp.s | 0 src/setjmp/{ => src}/impl/i386/setjmp.s | 0 src/setjmp/{ => src}/impl/m68k/longjmp.s | 0 src/setjmp/{ => src}/impl/m68k/setjmp.s | 0 .../{ => src}/impl/microblaze/longjmp.s | 0 src/setjmp/{ => src}/impl/microblaze/setjmp.s | 0 src/setjmp/{ => src}/impl/mips/longjmp.S | 0 src/setjmp/{ => src}/impl/mips/setjmp.S | 0 src/setjmp/{ => src}/impl/mips64/longjmp.S | 0 src/setjmp/{ => src}/impl/mips64/setjmp.S | 0 src/setjmp/{ => src}/impl/mipsn32/longjmp.S | 0 src/setjmp/{ => src}/impl/mipsn32/setjmp.S | 0 src/setjmp/{ => src}/impl/or1k/longjmp.s | 0 src/setjmp/{ => src}/impl/or1k/setjmp.s | 0 src/setjmp/{ => src}/impl/powerpc/longjmp.S | 0 src/setjmp/{ => src}/impl/powerpc/setjmp.S | 0 src/setjmp/{ => src}/impl/powerpc64/longjmp.s | 0 src/setjmp/{ => src}/impl/powerpc64/setjmp.s | 0 src/setjmp/{ => src}/impl/s390x/longjmp.s | 0 src/setjmp/{ => src}/impl/s390x/setjmp.s | 0 src/setjmp/{ => src}/impl/sh/longjmp.S | 0 src/setjmp/{ => src}/impl/sh/setjmp.S | 0 src/setjmp/{ => src}/impl/x32/longjmp.s | 0 src/setjmp/{ => src}/impl/x32/setjmp.s | 0 src/setjmp/{ => src}/impl/x86_64/longjmp.s | 0 src/setjmp/{ => src}/impl/x86_64/setjmp.s | 0 src/setjmp/src/lib.rs | 31 +++++++- 38 files changed, 31 insertions(+), 89 deletions(-) rename include/{bits => }/setjmp.h (95%) delete mode 100644 src/setjmp/build.rs delete mode 100644 src/setjmp/cbindgen.toml rename src/setjmp/{ => src}/impl/README.md (100%) rename src/setjmp/{ => src}/impl/aarch64/longjmp.s (100%) rename src/setjmp/{ => src}/impl/aarch64/setjmp.s (100%) rename src/setjmp/{ => src}/impl/arm/longjmp.s (100%) rename src/setjmp/{ => src}/impl/arm/setjmp.s (100%) rename src/setjmp/{ => src}/impl/bin/.gitignore (100%) rename src/setjmp/{ => src}/impl/i386/longjmp.s (100%) rename src/setjmp/{ => src}/impl/i386/setjmp.s (100%) rename src/setjmp/{ => src}/impl/m68k/longjmp.s (100%) rename src/setjmp/{ => src}/impl/m68k/setjmp.s (100%) rename src/setjmp/{ => src}/impl/microblaze/longjmp.s (100%) rename src/setjmp/{ => src}/impl/microblaze/setjmp.s (100%) rename src/setjmp/{ => src}/impl/mips/longjmp.S (100%) rename src/setjmp/{ => src}/impl/mips/setjmp.S (100%) rename src/setjmp/{ => src}/impl/mips64/longjmp.S (100%) rename src/setjmp/{ => src}/impl/mips64/setjmp.S (100%) rename src/setjmp/{ => src}/impl/mipsn32/longjmp.S (100%) rename src/setjmp/{ => src}/impl/mipsn32/setjmp.S (100%) rename src/setjmp/{ => src}/impl/or1k/longjmp.s (100%) rename src/setjmp/{ => src}/impl/or1k/setjmp.s (100%) rename src/setjmp/{ => src}/impl/powerpc/longjmp.S (100%) rename src/setjmp/{ => src}/impl/powerpc/setjmp.S (100%) rename src/setjmp/{ => src}/impl/powerpc64/longjmp.s (100%) rename src/setjmp/{ => src}/impl/powerpc64/setjmp.s (100%) rename src/setjmp/{ => src}/impl/s390x/longjmp.s (100%) rename src/setjmp/{ => src}/impl/s390x/setjmp.s (100%) rename src/setjmp/{ => src}/impl/sh/longjmp.S (100%) rename src/setjmp/{ => src}/impl/sh/setjmp.S (100%) rename src/setjmp/{ => src}/impl/x32/longjmp.s (100%) rename src/setjmp/{ => src}/impl/x32/setjmp.s (100%) rename src/setjmp/{ => src}/impl/x86_64/longjmp.s (100%) rename src/setjmp/{ => src}/impl/x86_64/setjmp.s (100%) diff --git a/Cargo.lock b/Cargo.lock index 958708dd69..d242203e94 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -367,9 +367,6 @@ dependencies = [ [[package]] name = "setjmp" version = "0.1.0" -dependencies = [ - "cbindgen 0.5.2", -] [[package]] name = "signal" diff --git a/include/bits/setjmp.h b/include/setjmp.h similarity index 95% rename from include/bits/setjmp.h rename to include/setjmp.h index aa40a2dc75..837b21bafa 100644 --- a/include/bits/setjmp.h +++ b/include/setjmp.h @@ -1,5 +1,5 @@ -#ifndef _BITS_SETJMP_H -#define _BITS_SETJMP_H +#ifndef _SETJMP_H +#define _SETJMP_H #ifdef __arch64__ typedef unsigned long jmp_buf[22]; diff --git a/src/setjmp/Cargo.toml b/src/setjmp/Cargo.toml index ab9cbaa880..2826a4e541 100644 --- a/src/setjmp/Cargo.toml +++ b/src/setjmp/Cargo.toml @@ -2,7 +2,3 @@ name = "setjmp" version = "0.1.0" authors = ["Jeremy Soller "] -build = "build.rs" - -[build-dependencies] -cbindgen = { path = "../../cbindgen" } diff --git a/src/setjmp/build.rs b/src/setjmp/build.rs deleted file mode 100644 index e24e6d2efb..0000000000 --- a/src/setjmp/build.rs +++ /dev/null @@ -1,72 +0,0 @@ -extern crate cbindgen; - -use std::{env, fs, process::Command}; - -fn compile(file: &str, object: &str, output: &str) { - let status = Command::new("gcc") - .args(&["-c", file, "-o", object]) - .status() - .expect("failed to run gcc to compile assembly"); - - if !status.success() { - panic!("compilation error"); - } - - let status = Command::new("ar") - .args(&["rcs", output, object]) - .status() - .expect("failed to run ar to convert object to a static library"); - - if !status.success() { - panic!("error converting object to static library"); - } -} - -fn main() { - println!("cargo:rustc-link-lib=static=setjmp"); - println!("cargo:rustc-link-lib=static=longjmp"); - - macro_rules! detect_arch { - ($($($token:tt);+),+) => { - $( - detect_arch!(inner $($token);+); - )+ - }; - (inner $arch:expr) => { - detect_arch!(inner $arch; ".s"); - }; - (inner $arch:expr; $ext:expr) => { - #[cfg(target_arch = $arch)] { - compile(concat!("impl/", $arch, "/setjmp", $ext), "impl/bin/setjmp.o", "impl/bin/libsetjmp.a"); - compile(concat!("impl/", $arch, "/longjmp", $ext), "impl/bin/longjmp.o", "impl/bin/liblongjmp.a"); - - let dir = env::current_dir().expect("failed to find current directory"); - println!("cargo:rustc-link-search=native={}/impl/bin", dir.display()); - } - }; - } - - detect_arch! { - "aarch64", - "arm", - "i386", - "m68k", - "microblaze", - "mips"; ".S", - "mips64"; ".S", - "mipsn32"; ".S", - "or1k", - "powerpc"; ".S", - "powerpc64", - "s390x", - "sh"; ".S", - "x32", - "x86_64" - } - - let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); - fs::create_dir_all("../../target/include").expect("failed to create include directory"); - cbindgen::generate(crate_dir) - .expect("failed to generate bindings") - .write_to_file("../../target/include/setjmp.h"); -} diff --git a/src/setjmp/cbindgen.toml b/src/setjmp/cbindgen.toml deleted file mode 100644 index 30958dd223..0000000000 --- a/src/setjmp/cbindgen.toml +++ /dev/null @@ -1,6 +0,0 @@ -include_guard = "_SETJMP_H" -trailer = "#include " -language = "C" - -[enum] -prefix_with_name = true diff --git a/src/setjmp/impl/README.md b/src/setjmp/src/impl/README.md similarity index 100% rename from src/setjmp/impl/README.md rename to src/setjmp/src/impl/README.md diff --git a/src/setjmp/impl/aarch64/longjmp.s b/src/setjmp/src/impl/aarch64/longjmp.s similarity index 100% rename from src/setjmp/impl/aarch64/longjmp.s rename to src/setjmp/src/impl/aarch64/longjmp.s diff --git a/src/setjmp/impl/aarch64/setjmp.s b/src/setjmp/src/impl/aarch64/setjmp.s similarity index 100% rename from src/setjmp/impl/aarch64/setjmp.s rename to src/setjmp/src/impl/aarch64/setjmp.s diff --git a/src/setjmp/impl/arm/longjmp.s b/src/setjmp/src/impl/arm/longjmp.s similarity index 100% rename from src/setjmp/impl/arm/longjmp.s rename to src/setjmp/src/impl/arm/longjmp.s diff --git a/src/setjmp/impl/arm/setjmp.s b/src/setjmp/src/impl/arm/setjmp.s similarity index 100% rename from src/setjmp/impl/arm/setjmp.s rename to src/setjmp/src/impl/arm/setjmp.s diff --git a/src/setjmp/impl/bin/.gitignore b/src/setjmp/src/impl/bin/.gitignore similarity index 100% rename from src/setjmp/impl/bin/.gitignore rename to src/setjmp/src/impl/bin/.gitignore diff --git a/src/setjmp/impl/i386/longjmp.s b/src/setjmp/src/impl/i386/longjmp.s similarity index 100% rename from src/setjmp/impl/i386/longjmp.s rename to src/setjmp/src/impl/i386/longjmp.s diff --git a/src/setjmp/impl/i386/setjmp.s b/src/setjmp/src/impl/i386/setjmp.s similarity index 100% rename from src/setjmp/impl/i386/setjmp.s rename to src/setjmp/src/impl/i386/setjmp.s diff --git a/src/setjmp/impl/m68k/longjmp.s b/src/setjmp/src/impl/m68k/longjmp.s similarity index 100% rename from src/setjmp/impl/m68k/longjmp.s rename to src/setjmp/src/impl/m68k/longjmp.s diff --git a/src/setjmp/impl/m68k/setjmp.s b/src/setjmp/src/impl/m68k/setjmp.s similarity index 100% rename from src/setjmp/impl/m68k/setjmp.s rename to src/setjmp/src/impl/m68k/setjmp.s diff --git a/src/setjmp/impl/microblaze/longjmp.s b/src/setjmp/src/impl/microblaze/longjmp.s similarity index 100% rename from src/setjmp/impl/microblaze/longjmp.s rename to src/setjmp/src/impl/microblaze/longjmp.s diff --git a/src/setjmp/impl/microblaze/setjmp.s b/src/setjmp/src/impl/microblaze/setjmp.s similarity index 100% rename from src/setjmp/impl/microblaze/setjmp.s rename to src/setjmp/src/impl/microblaze/setjmp.s diff --git a/src/setjmp/impl/mips/longjmp.S b/src/setjmp/src/impl/mips/longjmp.S similarity index 100% rename from src/setjmp/impl/mips/longjmp.S rename to src/setjmp/src/impl/mips/longjmp.S diff --git a/src/setjmp/impl/mips/setjmp.S b/src/setjmp/src/impl/mips/setjmp.S similarity index 100% rename from src/setjmp/impl/mips/setjmp.S rename to src/setjmp/src/impl/mips/setjmp.S diff --git a/src/setjmp/impl/mips64/longjmp.S b/src/setjmp/src/impl/mips64/longjmp.S similarity index 100% rename from src/setjmp/impl/mips64/longjmp.S rename to src/setjmp/src/impl/mips64/longjmp.S diff --git a/src/setjmp/impl/mips64/setjmp.S b/src/setjmp/src/impl/mips64/setjmp.S similarity index 100% rename from src/setjmp/impl/mips64/setjmp.S rename to src/setjmp/src/impl/mips64/setjmp.S diff --git a/src/setjmp/impl/mipsn32/longjmp.S b/src/setjmp/src/impl/mipsn32/longjmp.S similarity index 100% rename from src/setjmp/impl/mipsn32/longjmp.S rename to src/setjmp/src/impl/mipsn32/longjmp.S diff --git a/src/setjmp/impl/mipsn32/setjmp.S b/src/setjmp/src/impl/mipsn32/setjmp.S similarity index 100% rename from src/setjmp/impl/mipsn32/setjmp.S rename to src/setjmp/src/impl/mipsn32/setjmp.S diff --git a/src/setjmp/impl/or1k/longjmp.s b/src/setjmp/src/impl/or1k/longjmp.s similarity index 100% rename from src/setjmp/impl/or1k/longjmp.s rename to src/setjmp/src/impl/or1k/longjmp.s diff --git a/src/setjmp/impl/or1k/setjmp.s b/src/setjmp/src/impl/or1k/setjmp.s similarity index 100% rename from src/setjmp/impl/or1k/setjmp.s rename to src/setjmp/src/impl/or1k/setjmp.s diff --git a/src/setjmp/impl/powerpc/longjmp.S b/src/setjmp/src/impl/powerpc/longjmp.S similarity index 100% rename from src/setjmp/impl/powerpc/longjmp.S rename to src/setjmp/src/impl/powerpc/longjmp.S diff --git a/src/setjmp/impl/powerpc/setjmp.S b/src/setjmp/src/impl/powerpc/setjmp.S similarity index 100% rename from src/setjmp/impl/powerpc/setjmp.S rename to src/setjmp/src/impl/powerpc/setjmp.S diff --git a/src/setjmp/impl/powerpc64/longjmp.s b/src/setjmp/src/impl/powerpc64/longjmp.s similarity index 100% rename from src/setjmp/impl/powerpc64/longjmp.s rename to src/setjmp/src/impl/powerpc64/longjmp.s diff --git a/src/setjmp/impl/powerpc64/setjmp.s b/src/setjmp/src/impl/powerpc64/setjmp.s similarity index 100% rename from src/setjmp/impl/powerpc64/setjmp.s rename to src/setjmp/src/impl/powerpc64/setjmp.s diff --git a/src/setjmp/impl/s390x/longjmp.s b/src/setjmp/src/impl/s390x/longjmp.s similarity index 100% rename from src/setjmp/impl/s390x/longjmp.s rename to src/setjmp/src/impl/s390x/longjmp.s diff --git a/src/setjmp/impl/s390x/setjmp.s b/src/setjmp/src/impl/s390x/setjmp.s similarity index 100% rename from src/setjmp/impl/s390x/setjmp.s rename to src/setjmp/src/impl/s390x/setjmp.s diff --git a/src/setjmp/impl/sh/longjmp.S b/src/setjmp/src/impl/sh/longjmp.S similarity index 100% rename from src/setjmp/impl/sh/longjmp.S rename to src/setjmp/src/impl/sh/longjmp.S diff --git a/src/setjmp/impl/sh/setjmp.S b/src/setjmp/src/impl/sh/setjmp.S similarity index 100% rename from src/setjmp/impl/sh/setjmp.S rename to src/setjmp/src/impl/sh/setjmp.S diff --git a/src/setjmp/impl/x32/longjmp.s b/src/setjmp/src/impl/x32/longjmp.s similarity index 100% rename from src/setjmp/impl/x32/longjmp.s rename to src/setjmp/src/impl/x32/longjmp.s diff --git a/src/setjmp/impl/x32/setjmp.s b/src/setjmp/src/impl/x32/setjmp.s similarity index 100% rename from src/setjmp/impl/x32/setjmp.s rename to src/setjmp/src/impl/x32/setjmp.s diff --git a/src/setjmp/impl/x86_64/longjmp.s b/src/setjmp/src/impl/x86_64/longjmp.s similarity index 100% rename from src/setjmp/impl/x86_64/longjmp.s rename to src/setjmp/src/impl/x86_64/longjmp.s diff --git a/src/setjmp/impl/x86_64/setjmp.s b/src/setjmp/src/impl/x86_64/setjmp.s similarity index 100% rename from src/setjmp/impl/x86_64/setjmp.s rename to src/setjmp/src/impl/x86_64/setjmp.s diff --git a/src/setjmp/src/lib.rs b/src/setjmp/src/lib.rs index f26f3e5afb..0f6392dc9f 100644 --- a/src/setjmp/src/lib.rs +++ b/src/setjmp/src/lib.rs @@ -1,6 +1,33 @@ //! setjmp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/setjmp.h.html #![no_std] +#![feature(global_asm)] -// EMPTY FILE. -// This project is here because of the build.rs file which will compile musl's existing code for setjmp. +macro_rules! platform_specific { + ($($arch:expr,$ext:expr;)+) => { + $( + #[cfg(target_arch = $arch)] + global_asm!(include_str!(concat!("impl/", $arch, "/setjmp.", $ext))); + #[cfg(target_arch = $arch)] + global_asm!(include_str!(concat!("impl/", $arch, "/longjmp.", $ext))); + )+ + } +} + +platform_specific! { + "aarch64","s"; + "arm","s"; + "i386","s"; + "m68k","s"; + "microblaze","s"; + "mips","S"; + "mips64","S"; + "mipsn32","S"; + "or1k","s"; + "powerpc","S"; + "powerpc64","s"; + "s390x","s"; + "sh","S"; + "x32","s"; + "x86_64","s"; +} From 257040e16433a315d8e167b6fd107960a3d53529 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 10:47:22 +0200 Subject: [PATCH 05/13] Fix a few stat-related things --- include/bits/inttypes.h | 5 ++++ include/bits/stat.h | 11 +++++++++ src/sys_stat/cbindgen.toml | 1 + src/sys_stat/src/lib.rs | 50 +++++++++++++++++++------------------- 4 files changed, 42 insertions(+), 25 deletions(-) create mode 100644 include/bits/stat.h diff --git a/include/bits/inttypes.h b/include/bits/inttypes.h index 996a450554..20e998c8dc 100644 --- a/include/bits/inttypes.h +++ b/include/bits/inttypes.h @@ -1,3 +1,6 @@ +#ifndef _BITS_INTTYPE_H +#define _BITS_INTTYPE_H + #define PRId8 "i" #define PRId16 "i" #define PRId32 "i" @@ -188,3 +191,5 @@ #define SCNoPTR "to" #define SCNuPTR "tu" #define SCNxPTR "tx" + +#endif diff --git a/include/bits/stat.h b/include/bits/stat.h new file mode 100644 index 0000000000..9f62d7ff4f --- /dev/null +++ b/include/bits/stat.h @@ -0,0 +1,11 @@ +#ifndef _BITS_STAT_H +#define _BITS_STAT_H + +#define S_ISDIR(mode) mode & S_IFMT == S_IFDIR +#define S_ISCHR(mode) mode & S_IFMT == S_IFCHR +#define S_ISBLK(mode) mode & S_IFMT == S_IFBLK +#define S_ISREG(mode) mode & S_IFMT == S_IFREG +#define S_ISIFO(mode) mode & S_IFMT == S_IFIFO +#define S_ISLNK(mode) mode & S_IFMT == S_IFLNK + +#endif diff --git a/src/sys_stat/cbindgen.toml b/src/sys_stat/cbindgen.toml index 58eced99e1..cf9eef50c9 100644 --- a/src/sys_stat/cbindgen.toml +++ b/src/sys_stat/cbindgen.toml @@ -1,5 +1,6 @@ sys_includes = ["sys/types.h"] include_guard = "_SYS_STAT_H" +trailer = "#include " language = "C" style = "Tag" diff --git a/src/sys_stat/src/lib.rs b/src/sys_stat/src/lib.rs index 5b4a389d7d..b34cb2480d 100644 --- a/src/sys_stat/src/lib.rs +++ b/src/sys_stat/src/lib.rs @@ -6,31 +6,31 @@ extern crate platform; use platform::types::*; -pub const S_IFMT: c_int = 00170000; -pub const S_IFBLK: c_int = 0060000; -pub const S_IFCHR: c_int = 0020000; -pub const S_IFIFO: c_int = 0010000; -pub const S_IFREG: c_int = 0100000; -pub const S_IFDIR: c_int = 0040000; -pub const S_IFLNK: c_int = 0120000; +pub const S_IFMT: c_int = 0o0170000; +pub const S_IFBLK: c_int = 0o060000; +pub const S_IFCHR: c_int = 0o020000; +pub const S_IFIFO: c_int = 0o010000; +pub const S_IFREG: c_int = 0o100000; +pub const S_IFDIR: c_int = 0o040000; +pub const S_IFLNK: c_int = 0o120000; -pub const S_IRWXU: c_int = 00700; -pub const S_IRUSR: c_int = 00400; -pub const S_IWUSR: c_int = 00200; -pub const S_IXUSR: c_int = 00100; +pub const S_IRWXU: c_int = 0o0700; +pub const S_IRUSR: c_int = 0o0400; +pub const S_IWUSR: c_int = 0o0200; +pub const S_IXUSR: c_int = 0o0100; -pub const S_IRWXG: c_int = 00070; -pub const S_IRGRP: c_int = 00040; -pub const S_IWGRP: c_int = 00020; -pub const S_IXGRP: c_int = 00010; +pub const S_IRWXG: c_int = 0o0070; +pub const S_IRGRP: c_int = 0o0040; +pub const S_IWGRP: c_int = 0o0020; +pub const S_IXGRP: c_int = 0o0010; -pub const S_IRWXO: c_int = 00007; -pub const S_IROTH: c_int = 00004; -pub const S_IWOTH: c_int = 00002; -pub const S_IXOTH: c_int = 00001; -pub const S_ISUID: c_int = 04000; -pub const S_ISGID: c_int = 02000; -pub const S_ISVTX: c_int = 01000; +pub const S_IRWXO: c_int = 0o0007; +pub const S_IROTH: c_int = 0o0004; +pub const S_IWOTH: c_int = 0o0002; +pub const S_IXOTH: c_int = 0o0001; +pub const S_ISUID: c_int = 0o4000; +pub const S_ISGID: c_int = 0o2000; +pub const S_ISVTX: c_int = 0o1000; #[repr(C)] pub struct stat { @@ -43,9 +43,9 @@ pub struct stat { pub st_rdev: dev_t, pub st_size: off_t, pub st_blksize: blksize_t, - pub st_atim: time_t, - pub st_mtim: time_t, - pub st_ctim: time_t, + pub st_atime: time_t, + pub st_mtime: time_t, + pub st_ctime: time_t, pub st_blocks: blkcnt_t, } From 0776de1ae66551457c6ee85df58f727cbf6dde7e Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 11:09:49 +0200 Subject: [PATCH 06/13] Fix inttypes --- include/bits/inttypes.h | 138 +++++++++++++++++----------------- include/bits/{ => sys}/stat.h | 0 src/sys_stat/cbindgen.toml | 2 +- src/sys_time/cbindgen.toml | 1 + 4 files changed, 71 insertions(+), 70 deletions(-) rename include/bits/{ => sys}/stat.h (100%) diff --git a/include/bits/inttypes.h b/include/bits/inttypes.h index 20e998c8dc..c1a7cf4bfd 100644 --- a/include/bits/inttypes.h +++ b/include/bits/inttypes.h @@ -1,109 +1,109 @@ #ifndef _BITS_INTTYPE_H #define _BITS_INTTYPE_H -#define PRId8 "i" -#define PRId16 "i" -#define PRId32 "i" -#define PRId64 "i" +#define PRId8 "hhd" +#define PRId16 "hd" +#define PRId32 "d" +#define PRId64 "ld" -#define PRIdLEAST8 "i" -#define PRIdLEAST16 "i" -#define PRIdLEAST32 "i" -#define PRIdLEAST64 "i" +#define PRIdLEAST8 "hhd" +#define PRIdLEAST16 "hd" +#define PRIdLEAST32 "d" +#define PRIdLEAST64 "ld" -#define PRIdFAST8 "i" -#define PRIdFAST16 "i" -#define PRIdFAST32 "i" -#define PRIdFAST64 "i" +#define PRIdFAST8 "hhd" +#define PRIdFAST16 "hd" +#define PRIdFAST32 "d" +#define PRIdFAST64 "ld" -#define PRIi8 "i" -#define PRIi16 "i" +#define PRIi8 "hhi" +#define PRIi16 "hi" #define PRIi32 "i" -#define PRIi64 "i" +#define PRIi64 "li" -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" +#define PRIiLEAST8 "hhi" +#define PRIiLEAST16 "hi" #define PRIiLEAST32 "i" -#define PRIiLEAST64 "i" +#define PRIiLEAST64 "li" -#define PRIiFAST8 "i" -#define PRIiFAST16 "i" +#define PRIiFAST8 "hhi" +#define PRIiFAST16 "hi" #define PRIiFAST32 "i" -#define PRIiFAST64 "i" +#define PRIiFAST64 "li" -#define PRIo8 "o" -#define PRIo16 "o" +#define PRIo8 "hho" +#define PRIo16 "ho" #define PRIo32 "o" -#define PRIo64 "o" +#define PRIo64 "lo" -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" +#define PRIoLEAST8 "hho" +#define PRIoLEAST16 "ho" #define PRIoLEAST32 "o" -#define PRIoLEAST64 "o" +#define PRIoLEAST64 "lo" -#define PRIoFAST8 "o" -#define PRIoFAST16 "o" +#define PRIoFAST8 "hho" +#define PRIoFAST16 "ho" #define PRIoFAST32 "o" -#define PRIoFAST64 "o" +#define PRIoFAST64 "lo" -#define PRIu8 "u" -#define PRIu16 "u" +#define PRIu8 "hhu" +#define PRIu16 "hu" #define PRIu32 "u" -#define PRIu64 "u" +#define PRIu64 "lu" -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" +#define PRIuLEAST8 "hhu" +#define PRIuLEAST16 "hu" #define PRIuLEAST32 "u" -#define PRIuLEAST64 "u" +#define PRIuLEAST64 "lu" -#define PRIuFAST8 "u" -#define PRIuFAST16 "u" +#define PRIuFAST8 "hhu" +#define PRIuFAST16 "hu" #define PRIuFAST32 "u" -#define PRIuFAST64 "u" +#define PRIuFAST64 "lu" -#define PRIx8 "x" -#define PRIx16 "x" +#define PRIx8 "hhx" +#define PRIx16 "hx" #define PRIx32 "x" -#define PRIx64 "x" +#define PRIx64 "lx" -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" +#define PRIxLEAST8 "hhx" +#define PRIxLEAST16 "hx" #define PRIxLEAST32 "x" -#define PRIxLEAST64 "x" +#define PRIxLEAST64 "lx" -#define PRIxFAST8 "x" -#define PRIxFAST16 "x" +#define PRIxFAST8 "hhx" +#define PRIxFAST16 "hx" #define PRIxFAST32 "x" -#define PRIxFAST64 "x" +#define PRIxFAST64 "lx" -#define PRIX8 "X" -#define PRIX16 "X" +#define PRIX8 "hhX" +#define PRIX16 "hX" #define PRIX32 "X" -#define PRIX64 "X" +#define PRIX64 "lX" -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" +#define PRIXLEAST8 "hhX" +#define PRIXLEAST16 "hX" #define PRIXLEAST32 "X" -#define PRIXLEAST64 "X" +#define PRIXLEAST64 "lX" -#define PRIXFAST8 "X" -#define PRIXFAST16 "X" +#define PRIXFAST8 "hhX" +#define PRIXFAST16 "hX" #define PRIXFAST32 "X" -#define PRIXFAST64 "X" +#define PRIXFAST64 "lX" -#define PRIdMAX "d" -#define PRIiMAX "i" -#define PRIoMAX "o" -#define PRIuMAX "u" -#define PRIxMAX "x" -#define PRIXMAX "X" +#define PRIdMAX "jd" +#define PRIiMAX "ji" +#define PRIoMAX "jo" +#define PRIuMAX "ju" +#define PRIxMAX "jx" +#define PRIXMAX "jX" -#define PRIdPTR "d" -#define PRIiPTR "i" -#define PRIoPTR "o" -#define PRIuPTR "u" -#define PRIxPTR "x" -#define PRIXPTR "X" +#define PRIdPTR "td" +#define PRIiPTR "ti" +#define PRIoPTR "to" +#define PRIuPTR "tu" +#define PRIxPTR "tx" +#define PRIXPTR "tX" #define SCNd8 "hhd" #define SCNd16 "hd" diff --git a/include/bits/stat.h b/include/bits/sys/stat.h similarity index 100% rename from include/bits/stat.h rename to include/bits/sys/stat.h diff --git a/src/sys_stat/cbindgen.toml b/src/sys_stat/cbindgen.toml index cf9eef50c9..538e252782 100644 --- a/src/sys_stat/cbindgen.toml +++ b/src/sys_stat/cbindgen.toml @@ -1,6 +1,6 @@ sys_includes = ["sys/types.h"] include_guard = "_SYS_STAT_H" -trailer = "#include " +trailer = "#include " language = "C" style = "Tag" diff --git a/src/sys_time/cbindgen.toml b/src/sys_time/cbindgen.toml index bc1c131526..8ce5b2b402 100644 --- a/src/sys_time/cbindgen.toml +++ b/src/sys_time/cbindgen.toml @@ -1,6 +1,7 @@ sys_includes = ["sys/types.h"] include_guard = "_SYS_TIME_H" language = "C" +style = "Tag" [enum] prefix_with_name = true From 5fc1459eb9c9fef377c4bed3260384a526cb38b5 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 11:23:22 +0200 Subject: [PATCH 07/13] signal: Make constants visible from C --- src/signal/src/lib.rs | 4 ++ src/signal/src/linux.rs | 84 ++++++++++++++++++++--------------------- src/signal/src/redox.rs | 76 ++++++++++++++++++------------------- 3 files changed, 84 insertions(+), 80 deletions(-) diff --git a/src/signal/src/lib.rs b/src/signal/src/lib.rs index 031b8e4836..a59a136932 100644 --- a/src/signal/src/lib.rs +++ b/src/signal/src/lib.rs @@ -12,6 +12,10 @@ pub mod sys; #[path = "redox.rs"] pub mod sys; +#[no_mangle] pub static SIG_BLOCK: c_int = 0; +#[no_mangle] pub static SIG_UNBLOCK: c_int = 1; +#[no_mangle] pub static SIG_SETMASK: c_int = 2; + pub use sys::*; use platform::types::*; diff --git a/src/signal/src/linux.rs b/src/signal/src/linux.rs index 628e813390..d5ebf09213 100644 --- a/src/signal/src/linux.rs +++ b/src/signal/src/linux.rs @@ -3,46 +3,46 @@ pub struct sys_sigset_t { pub bits: [u64; 16], } -pub const SIGHUP: usize = 1; -pub const SIGINT: usize = 2; -pub const SIGQUIT: usize = 3; -pub const SIGILL: usize = 4; -pub const SIGTRAP: usize = 5; -pub const SIGABRT: usize = 6; -pub const SIGIOT: usize = SIGABRT; -pub const SIGBUS: usize = 7; -pub const SIGFPE: usize = 8; -pub const SIGKILL: usize = 9; -pub const SIGUSR1: usize = 10; -pub const SIGSEGV: usize = 11; -pub const SIGUSR2: usize = 12; -pub const SIGPIPE: usize = 13; -pub const SIGALRM: usize = 14; -pub const SIGTERM: usize = 15; -pub const SIGSTKFLT: usize = 16; -pub const SIGCHLD: usize = 17; -pub const SIGCONT: usize = 18; -pub const SIGSTOP: usize = 19; -pub const SIGTSTP: usize = 20; -pub const SIGTTIN: usize = 21; -pub const SIGTTOU: usize = 22; -pub const SIGURG: usize = 23; -pub const SIGXCPU: usize = 24; -pub const SIGXFSZ: usize = 25; -pub const SIGVTALRM: usize = 26; -pub const SIGPROF: usize = 27; -pub const SIGWINCH: usize = 28; -pub const SIGIO: usize = 29; -pub const SIGPOLL: usize = 29; -pub const SIGPWR: usize = 30; -pub const SIGSYS: usize = 31; -pub const SIGUNUSED: usize = SIGSYS; +#[no_mangle] pub static SIGHUP: usize = 1; +#[no_mangle] pub static SIGINT: usize = 2; +#[no_mangle] pub static SIGQUIT: usize = 3; +#[no_mangle] pub static SIGILL: usize = 4; +#[no_mangle] pub static SIGTRAP: usize = 5; +#[no_mangle] pub static SIGABRT: usize = 6; +#[no_mangle] pub static SIGIOT: usize = 6; +#[no_mangle] pub static SIGBUS: usize = 7; +#[no_mangle] pub static SIGFPE: usize = 8; +#[no_mangle] pub static SIGKILL: usize = 9; +#[no_mangle] pub static SIGUSR1: usize = 10; +#[no_mangle] pub static SIGSEGV: usize = 11; +#[no_mangle] pub static SIGUSR2: usize = 12; +#[no_mangle] pub static SIGPIPE: usize = 13; +#[no_mangle] pub static SIGALRM: usize = 14; +#[no_mangle] pub static SIGTERM: usize = 15; +#[no_mangle] pub static SIGSTKFLT: usize = 16; +#[no_mangle] pub static SIGCHLD: usize = 17; +#[no_mangle] pub static SIGCONT: usize = 18; +#[no_mangle] pub static SIGSTOP: usize = 19; +#[no_mangle] pub static SIGTSTP: usize = 20; +#[no_mangle] pub static SIGTTIN: usize = 21; +#[no_mangle] pub static SIGTTOU: usize = 22; +#[no_mangle] pub static SIGURG: usize = 23; +#[no_mangle] pub static SIGXCPU: usize = 24; +#[no_mangle] pub static SIGXFSZ: usize = 25; +#[no_mangle] pub static SIGVTALRM: usize = 26; +#[no_mangle] pub static SIGPROF: usize = 27; +#[no_mangle] pub static SIGWINCH: usize = 28; +#[no_mangle] pub static SIGIO: usize = 29; +#[no_mangle] pub static SIGPOLL: usize = 29; +#[no_mangle] pub static SIGPWR: usize = 30; +#[no_mangle] pub static SIGSYS: usize = 31; +#[no_mangle] pub static SIGUNUSED: usize = 31; -pub const SA_NOCLDSTOP: usize = 1; -pub const SA_NOCLDWAIT: usize = 2; -pub const SA_SIGINFO: usize = 4; -pub const SA_ONSTACK: usize = 0x08000000; -pub const SA_RESTART: usize = 0x10000000; -pub const SA_NODEFER: usize = 0x40000000; -pub const SA_RESETHAND: usize = 0x80000000; -pub const SA_RESTORER: usize = 0x04000000; +#[no_mangle] pub static SA_NOCLDSTOP: usize = 1; +#[no_mangle] pub static SA_NOCLDWAIT: usize = 2; +#[no_mangle] pub static SA_SIGINFO: usize = 4; +#[no_mangle] pub static SA_ONSTACK: usize = 0x08000000; +#[no_mangle] pub static SA_RESTART: usize = 0x10000000; +#[no_mangle] pub static SA_NODEFER: usize = 0x40000000; +#[no_mangle] pub static SA_RESETHAND: usize = 0x80000000; +#[no_mangle] pub static SA_RESTORER: usize = 0x04000000; diff --git a/src/signal/src/redox.rs b/src/signal/src/redox.rs index b5108b5a62..6abede5ff4 100644 --- a/src/signal/src/redox.rs +++ b/src/signal/src/redox.rs @@ -3,42 +3,42 @@ pub struct sys_sigset_t { pub bits: [u64; 2], } -pub const SIGHUP: usize = 1; -pub const SIGINT: usize = 2; -pub const SIGQUIT: usize = 3; -pub const SIGILL: usize = 4; -pub const SIGTRAP: usize = 5; -pub const SIGBUS: usize = 7; -pub const SIGFPE: usize = 8; -pub const SIGKILL: usize = 9; -pub const SIGUSR1: usize = 10; -pub const SIGSEGV: usize = 11; -pub const SIGUSR2: usize = 12; -pub const SIGPIPE: usize = 13; -pub const SIGALRM: usize = 14; -pub const SIGTERM: usize = 15; -pub const SIGSTKFLT: usize = 16; -pub const SIGCHLD: usize = 17; -pub const SIGCONT: usize = 18; -pub const SIGSTOP: usize = 19; -pub const SIGTSTP: usize = 20; -pub const SIGTTIN: usize = 21; -pub const SIGTTOU: usize = 22; -pub const SIGURG: usize = 23; -pub const SIGXCPU: usize = 24; -pub const SIGXFSZ: usize = 25; -pub const SIGVTALRM: usize = 26; -pub const SIGPROF: usize = 27; -pub const SIGWINCH: usize = 28; -pub const SIGIO: usize = 29; -pub const SIGPWR: usize = 30; -pub const SIGSYS: usize = 31; +#[no_mangle] pub static SIGHUP: usize = 1; +#[no_mangle] pub static SIGINT: usize = 2; +#[no_mangle] pub static SIGQUIT: usize = 3; +#[no_mangle] pub static SIGILL: usize = 4; +#[no_mangle] pub static SIGTRAP: usize = 5; +#[no_mangle] pub static SIGBUS: usize = 7; +#[no_mangle] pub static SIGFPE: usize = 8; +#[no_mangle] pub static SIGKILL: usize = 9; +#[no_mangle] pub static SIGUSR1: usize = 10; +#[no_mangle] pub static SIGSEGV: usize = 11; +#[no_mangle] pub static SIGUSR2: usize = 12; +#[no_mangle] pub static SIGPIPE: usize = 13; +#[no_mangle] pub static SIGALRM: usize = 14; +#[no_mangle] pub static SIGTERM: usize = 15; +#[no_mangle] pub static SIGSTKFLT: usize = 16; +#[no_mangle] pub static SIGCHLD: usize = 17; +#[no_mangle] pub static SIGCONT: usize = 18; +#[no_mangle] pub static SIGSTOP: usize = 19; +#[no_mangle] pub static SIGTSTP: usize = 20; +#[no_mangle] pub static SIGTTIN: usize = 21; +#[no_mangle] pub static SIGTTOU: usize = 22; +#[no_mangle] pub static SIGURG: usize = 23; +#[no_mangle] pub static SIGXCPU: usize = 24; +#[no_mangle] pub static SIGXFSZ: usize = 25; +#[no_mangle] pub static SIGVTALRM: usize = 26; +#[no_mangle] pub static SIGPROF: usize = 27; +#[no_mangle] pub static SIGWINCH: usize = 28; +#[no_mangle] pub static SIGIO: usize = 29; +#[no_mangle] pub static SIGPWR: usize = 30; +#[no_mangle] pub static SIGSYS: usize = 31; -pub const SA_NOCLDSTOP: usize = 0x00000001; -pub const SA_NOCLDWAIT: usize = 0x00000002; -pub const SA_SIGINFO: usize = 0x00000004; -pub const SA_RESTORER: usize = 0x04000000; -pub const SA_ONSTACK: usize = 0x08000000; -pub const SA_RESTART: usize = 0x10000000; -pub const SA_NODEFER: usize = 0x40000000; -pub const SA_RESETHAND: usize = 0x80000000; +#[no_mangle] pub static SA_NOCLDSTOP: usize = 0x00000001; +#[no_mangle] pub static SA_NOCLDWAIT: usize = 0x00000002; +#[no_mangle] pub static SA_SIGINFO: usize = 0x00000004; +#[no_mangle] pub static SA_RESTORER: usize = 0x04000000; +#[no_mangle] pub static SA_ONSTACK: usize = 0x08000000; +#[no_mangle] pub static SA_RESTART: usize = 0x10000000; +#[no_mangle] pub static SA_NODEFER: usize = 0x40000000; +#[no_mangle] pub static SA_RESETHAND: usize = 0x80000000; From 3927b0ab445f22fbdc5bb346b1b3e2a485e29d80 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 14:10:20 +0200 Subject: [PATCH 08/13] Revert int definitions --- include/stddef.h | 4 ++-- include/stdint.h | 26 +++++++++++++------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/include/stddef.h b/include/stddef.h index 099ca1574b..fa0bc7daf5 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -3,10 +3,10 @@ #define NULL 0 -typedef signed long ptrdiff_t; +typedef signed long long ptrdiff_t; typedef unsigned char wchar_t; -typedef unsigned long size_t; +typedef unsigned long long size_t; #endif /* _STDDEF_H */ diff --git a/include/stdint.h b/include/stdint.h index cf25e00fbe..cbe5e37fe7 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -56,54 +56,54 @@ typedef unsigned short uint_fast16_t; #define INT32_C(value) value ## L #define INT32_MIN -0x80000000 #define INT32_MAX 0x7FFFFFFF -typedef signed int int32_t; +typedef signed long int32_t; #define INT_LEAST32_MIN -0x80000000 #define INT_LEAST32_MAX 0x7FFFFFFF -typedef signed int int_least32_t; +typedef signed long int_least32_t; #define INT_FAST32_MIN -0x80000000 #define INT_FAST32_MAX 0x7FFFFFFF -typedef signed int int_fast32_t; +typedef signed long int_fast32_t; #define UINT32_C(value) value ## UL #define UINT32_MIN 0x00000000 #define UINT32_MAX 0xFFFFFFFF -typedef unsigned int uint32_t; +typedef unsigned long uint32_t; #define UINT_LEAST32_MIN 0x00000000 #define UINT_LEAST32_MAX 0xFFFFFFFF -typedef unsigned int uint_least32_t; +typedef unsigned long uint_least32_t; #define UINT_FAST32_MIN 0x00000000 #define UINT_FAST32_MAX 0xFFFFFFFF -typedef unsigned int uint_fast32_t; +typedef unsigned long uint_fast32_t; #define INT64_C(value) value ## LL #define INT64_MIN -0x8000000000000000 #define INT64_MAX 0x7FFFFFFFFFFFFFFF -typedef signed long int64_t; +typedef signed long long int64_t; #define INT_LEAST64_MIN -0x8000000000000000 #define INT_LEAST64_MAX 0x7FFFFFFFFFFFFFFF -typedef signed long int_least64_t; +typedef signed long long int_least64_t; #define INT_FAST64_MIN -0x8000000000000000 #define INT_FAST64_MAX 0x7FFFFFFFFFFFFFFF -typedef signed long int_fast64_t; +typedef signed long long int_fast64_t; #define UINT64_C(value) value ## ULL #define UINT64_MIN 0x0000000000000000 #define UINT64_MAX 0xFFFFFFFFFFFFFFFF -typedef unsigned long uint64_t; +typedef unsigned long long uint64_t; #define UINT_LEAST64_MIN 0x0000000000000000 #define UINT_LEAST64_MAX 0xFFFFFFFFFFFFFFFF -typedef unsigned long uint_least64_t; +typedef unsigned long long uint_least64_t; #define UINT_FAST64_MIN 0x0000000000000000 #define UINT_FAST64_MAX 0xFFFFFFFFFFFFFFFF -typedef unsigned long uint_fast64_t; +typedef unsigned long long uint_fast64_t; #define INTMAX_C(value) value ## LL #define INTMAX_MIN INT64_MIN @@ -125,6 +125,6 @@ typedef uint64_t uintptr_t; #define SIZE_MAX UINT64_MAX -typedef int sig_atomic_t; +typedef long sig_atomic_t; #endif /* _STDINT_H */ From 844e244851d600b4254fb4a18de28e8c2bab5a26 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 16:05:02 +0200 Subject: [PATCH 09/13] Use both Tag and Type --- src/sys_time/cbindgen.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sys_time/cbindgen.toml b/src/sys_time/cbindgen.toml index 8ce5b2b402..e25c54043f 100644 --- a/src/sys_time/cbindgen.toml +++ b/src/sys_time/cbindgen.toml @@ -1,7 +1,7 @@ sys_includes = ["sys/types.h"] include_guard = "_SYS_TIME_H" language = "C" -style = "Tag" +style = "Both" [enum] prefix_with_name = true From 9de73d0e5b7d222b040b4093138f3f2c4b69d089 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 16:37:26 +0200 Subject: [PATCH 10/13] Add uname and gethostname --- Cargo.lock | 10 + Cargo.toml | 3 +- src/lib.rs | 1 + src/platform/src/lib.rs | 2 +- src/platform/src/linux/mod.rs | 4 + src/sys_utsname/Cargo.toml | 11 + src/sys_utsname/build.rs | 11 + src/sys_utsname/cbindgen.toml | 5 + src/sys_utsname/src/lib.rs | 28 +++ src/unistd/Cargo.toml | 1 + src/unistd/src/lib.rs | 49 +++++ src/wchar/src/lib.rs | 394 ++++++++++++++++++++++++++++++++++ tests/.gitignore | 3 +- tests/Makefile | 1 + tests/gethostname.c | 12 ++ 15 files changed, 532 insertions(+), 3 deletions(-) create mode 100644 src/sys_utsname/Cargo.toml create mode 100644 src/sys_utsname/build.rs create mode 100644 src/sys_utsname/cbindgen.toml create mode 100644 src/sys_utsname/src/lib.rs create mode 100644 src/wchar/src/lib.rs create mode 100644 tests/gethostname.c diff --git a/Cargo.lock b/Cargo.lock index d242203e94..270193390b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -300,6 +300,7 @@ dependencies = [ "sys_socket 0.1.0", "sys_stat 0.1.0", "sys_time 0.1.0", + "sys_utsname 0.1.0", "sys_wait 0.1.0", "time 0.1.0", "unistd 0.1.0", @@ -493,6 +494,14 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "sys_utsname" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.2", + "platform 0.1.0", +] + [[package]] name = "sys_wait" version = "0.1.0" @@ -574,6 +583,7 @@ dependencies = [ "platform 0.1.0", "stdio 0.1.0", "string 0.1.0", + "sys_utsname 0.1.0", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index c644f51227..b64015bdad 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,6 +35,7 @@ sys_resource = { path = "src/sys_resource" } sys_socket = { path = "src/sys_socket" } sys_stat = { path = "src/sys_stat" } sys_time = { path = "src/sys_time" } +sys_utsname = { path = "src/sys_utsname" } sys_wait = { path = "src/sys_wait" } time = { path = "src/time" } unistd = { path = "src/unistd" } @@ -43,7 +44,7 @@ wctype = { path = "src/wctype" } [dependencies.compiler_builtins] git = "https://github.com/rust-lang-nursery/compiler-builtins.git" default-features = false -features = ["no-lang-items"] +features = ["no-lang-items", "mangled-names"] [profile.dev] panic = "abort" diff --git a/src/lib.rs b/src/lib.rs index db4ed93802..6d5cc2d208 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,7 @@ pub extern crate sys_resource; pub extern crate sys_socket; pub extern crate sys_stat; pub extern crate sys_time; +pub extern crate sys_utsname; pub extern crate sys_wait; pub extern crate time; pub extern crate unistd; diff --git a/src/platform/src/lib.rs b/src/platform/src/lib.rs index 3784ea30d7..4919e61308 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/src/lib.rs @@ -10,7 +10,7 @@ extern crate sc; #[cfg(all(not(feature = "no_std"), target_os = "redox"))] #[macro_use] -extern crate syscall; +pub extern crate syscall; pub use sys::*; diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index d241a4f582..0ae481e4f3 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -198,6 +198,10 @@ pub fn stat(file: *const c_char, buf: *mut stat) -> c_int { e(unsafe { syscall!(NEWFSTATAT, AT_FDCWD, file, buf, 0) }) as c_int } +pub fn uname(utsname: usize) -> c_int { + e(unsafe { syscall!(UNAME, utsname, 0) }) as c_int +} + pub fn unlink(path: *const c_char) -> c_int { e(unsafe { syscall!(UNLINKAT, AT_FDCWD, path, 0) }) as c_int } diff --git a/src/sys_utsname/Cargo.toml b/src/sys_utsname/Cargo.toml new file mode 100644 index 0000000000..e03fbb2fd0 --- /dev/null +++ b/src/sys_utsname/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "sys_utsname" +version = "0.1.0" +authors = ["jD91mZM2 "] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } diff --git a/src/sys_utsname/build.rs b/src/sys_utsname/build.rs new file mode 100644 index 0000000000..2f45974eee --- /dev/null +++ b/src/sys_utsname/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::{env, fs}; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set"); + fs::create_dir_all("../../target/include").expect("failed to create include directory"); + cbindgen::generate(crate_dir) + .expect("failed to generate bindings") + .write_to_file("../../target/include/sys/utsname.h"); +} diff --git a/src/sys_utsname/cbindgen.toml b/src/sys_utsname/cbindgen.toml new file mode 100644 index 0000000000..7429451f54 --- /dev/null +++ b/src/sys_utsname/cbindgen.toml @@ -0,0 +1,5 @@ +include_guard = "_SYS_UTSNAME_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/sys_utsname/src/lib.rs b/src/sys_utsname/src/lib.rs new file mode 100644 index 0000000000..a0792dd564 --- /dev/null +++ b/src/sys_utsname/src/lib.rs @@ -0,0 +1,28 @@ +//! sys/utsname implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/sysutsname.h.html + +#![no_std] +#![cfg(target_os = "linux")] + +extern crate platform; + +use core::ptr; +use platform::types::*; + +const LENGTH: usize = 65; + +#[allow(non_camel_case)] +#[no_mangle] +#[repr(C)] +pub struct utsname { + pub sysname: [c_char; LENGTH], + pub nodename: [c_char; LENGTH], + pub release: [c_char; LENGTH], + pub version: [c_char; LENGTH], + pub machine: [c_char; LENGTH], + pub domainname: [c_char; LENGTH] +} + +#[no_mangle] +pub unsafe extern "C" fn uname(uts: *mut utsname) -> c_int { + platform::uname(uts as usize) +} diff --git a/src/unistd/Cargo.toml b/src/unistd/Cargo.toml index 8de8a2b933..69cd4b57a7 100644 --- a/src/unistd/Cargo.toml +++ b/src/unistd/Cargo.toml @@ -11,3 +11,4 @@ cbindgen = { path = "../../cbindgen" } platform = { path = "../platform" } stdio = { path = "../stdio" } string = { path = "../string" } +sys_utsname = { path = "../sys_utsname" } diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index e5aa6bc926..a757781e2b 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -5,6 +5,7 @@ extern crate platform; extern crate stdio; extern crate string; +extern crate sys_utsname; pub use platform::types::*; pub use getopt::*; @@ -199,6 +200,54 @@ pub extern "C" fn gethostid() -> c_long { unimplemented!(); } +#[no_mangle] +pub unsafe extern "C" fn gethostname(mut name: *mut c_char, len: size_t) -> c_int { + #[cfg(target_os = "linux")] { + use core::mem; + + // len only needs to be mutable on linux + let mut len = len; + + let mut uts: sys_utsname::utsname = mem::uninitialized(); + let err = sys_utsname::uname(&mut uts); + if err < 0 { + mem::forget(uts); + return err; + } + for c in uts.nodename.iter() { + if len == 0 { break; } + len -= 1; + + *name = *c; + + if *name == 0 { + // We do want to copy the zero also, so we check this after the copying. + break; + } + + name = name.offset(1); + } + 0 + } + #[cfg(target_os = "redox")] { + use platform::{FileReader, Read}; + use platform::syscall::flag::*; + + let fd = platform::open("/etc/hostname\0",as_ptr(), 0, O_RDONLY); + if fd < 0 { + return fd; + } + let reader = FileReader(fd); + for _ in 0..len { + if !reader.read_u8(&mut *name) { + *name = 0; + break; + } + name = name.offset(1); + } + } +} + #[no_mangle] pub extern "C" fn getlogin() -> *mut c_char { unimplemented!(); diff --git a/src/wchar/src/lib.rs b/src/wchar/src/lib.rs new file mode 100644 index 0000000000..96bb95d1fe --- /dev/null +++ b/src/wchar/src/lib.rs @@ -0,0 +1,394 @@ +//! wchar implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/string.h.html + +#![no_std] + +extern crate errno; +extern crate platform; +extern crate stdlib; +extern crate string; +extern crate time; + +use platform::types::*; +use errno::*; +use time::*; +use core::cmp; +use core::usize; +use core::ptr; +use core::mem; +use string::*; + +pub type wint_t = i32; + +#[repr(C)] +pub struct mbstate_t { + pub mbs_count: c_int, + pub mbs_length: c_int, + pub mbs_wch: wint_t, +} + +#[no_mangle] +pub unsafe extern "C" fn btowc(c: c_int) -> wint_t { + //Check for EOF + if c == -1 { + return -1; + } + + let uc = c as u8; + let c = uc as c_char; + let mut ps: mbstate_t = mbstate_t { + mbs_count: 0, + mbs_length: 0, + mbs_wch: 0, + }; + let mut wc: wchar_t = 0; + let saved_errno = platform::errno; + let status = mbrtowc(&mut wc, &c as (*const c_char), 1, &mut ps); + if status == usize::max_value() || status == usize::max_value() - 1 { + platform::errno = saved_errno; + return platform::errno; + } + return wc as wint_t; +} + +#[no_mangle] +pub extern "C" fn getwchar() -> wint_t { + unimplemented!(); +} + +#[no_mangle] +pub unsafe extern "C" fn mbsinit(ps: *const mbstate_t) -> c_int { + if ps.is_null() || (*ps).mbs_count == 0 { + return 1; + } else { + return 0; + } +} + +#[no_mangle] +pub unsafe extern "C" fn mbrlen(s: *const c_char, n: usize, ps: *mut mbstate_t) -> usize { + static mut internal: mbstate_t = mbstate_t { + mbs_count: 0, + mbs_length: 0, + mbs_wch: 0, + }; + return mbrtowc(ptr::null_mut(), s, n, &mut internal); +} + +//Only works for utf8! +#[no_mangle] +pub unsafe extern "C" fn mbrtowc( + pwc: *mut wchar_t, + s: *const c_char, + n: usize, + ps: *mut mbstate_t, +) -> usize { + static mut internal: mbstate_t = mbstate_t { + mbs_count: 0, + mbs_length: 0, + mbs_wch: 0, + }; + + if ps.is_null() { + let ps = &mut internal; + } + if s.is_null() { + let xs: [c_char; 1] = [0]; + utf8_mbrtowc(pwc, &xs[0] as *const c_char, 1, ps); + } + + return utf8_mbrtowc(pwc, s, n, ps); +} + +#[no_mangle] +unsafe extern "C" fn utf8_mbrtowc( + pwc: *mut wchar_t, + s: *const c_char, + n: usize, + ps: *mut mbstate_t, +) -> usize { + let mut i: usize = 0; + + while !(i > 0 && (*ps).mbs_count == 0) { + if (n <= i) { + return -2isize as usize; + } + let c = s.offset(i as isize); + let uc = c as u8; + + if (*ps).mbs_count == 0 { + //1 byte sequence - 00–7F + if (uc & 0b10000000) == 0b00000000 { + (*ps).mbs_count = 0; + (*ps).mbs_length = 1; + (*ps).mbs_wch = (uc as wchar_t & 0b1111111) as wint_t; + } + //2 byte sequence - C2–DF + else if (uc & 0b11100000) == 0b11000000 { + (*ps).mbs_count = 1; + (*ps).mbs_length = 2; + (*ps).mbs_wch = (uc as wchar_t & 0b11111) as wint_t; + } + //3 byte sequence - E0–EF + else if (uc & 0b11110000) == 0b11100000 { + (*ps).mbs_count = 2; + (*ps).mbs_length = 3; + (*ps).mbs_wch = (uc as wchar_t & 0b1111) as wint_t; + } + //4 byte sequence - F0–F4 + else if (uc & 0b11111000) == 0b11110000 { + (*ps).mbs_count = 3; + (*ps).mbs_length = 4; + (*ps).mbs_wch = (uc as wchar_t & 0b111) as wint_t; + } else { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + } else { + if (uc & 0b11000000) != 0b10000000 { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + + (*ps).mbs_wch = (*ps).mbs_wch << 6 | (uc & 0b00111111) as wint_t; + (*ps).mbs_count -= 1; + } + + i += 1; + } + + // Reject the character if it was produced with an overly long sequence. + if (*ps).mbs_length == 1 && 1 << 7 <= (*ps).mbs_wch { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + if (*ps).mbs_length == 2 && 1 << (5 + 1 * 6) <= (*ps).mbs_wch { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + if (*ps).mbs_length == 3 && 1 << (5 + 2 * 6) <= (*ps).mbs_wch { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + if (*ps).mbs_length == 4 && 1 << (5 + 3 * 6) <= (*ps).mbs_wch { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + + // The definition of UTF-8 prohibits encoding character numbers between + // U+D800 and U+DFFF, which are reserved for use with the UTF-16 encoding + // form (as surrogate pairs) and do not directly represent characters. + if 0xD800 <= (*ps).mbs_wch && (*ps).mbs_wch <= 0xDFFF { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + // RFC 3629 limits UTF-8 to 0x0 through 0x10FFFF. + if 0x10FFFF <= (*ps).mbs_wch { + platform::errno = errno::EILSEQ; + return -1isize as usize; + } + + let result: wchar_t = (*ps).mbs_wch as wchar_t; + + if !pwc.is_null() { + *pwc = result; + } + + (*ps).mbs_length = 0; + (*ps).mbs_wch = 0; + + return if result != 0 { i } else { 0 }; +} + +#[no_mangle] +pub extern "C" fn mbsrtowcs( + dst: *mut wchar_t, + src: *mut *const c_char, + len: usize, + ps: *mut mbstate_t, +) -> usize { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn putwchar(wc: wchar_t) -> wint_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn towlower(wc: wint_t) -> wint_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn towupper(wc: wint_t) -> wint_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcrtomb(s: *mut c_char, wc: wchar_t, ps: *mut mbstate_t) -> usize { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcscat(ws1: *mut wchar_t, ws2: *const wchar_t) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcschr(ws1: *const wchar_t, ws2: wchar_t) -> *mut c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcscmp(ws1: *const wchar_t, ws2: *const wchar_t) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcscoll(ws1: *const wchar_t, ws2: *const wchar_t) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcscpy(ws1: *mut wchar_t, ws2: *const wchar_t) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcscspn(ws1: *const wchar_t, ws2: *const wchar_t) -> usize { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsftime( + wcs: *mut wchar_t, + maxsize: usize, + format: *const wchar_t, + timptr: *mut tm, +) -> usize { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcslen(ws: *const wchar_t) -> c_ulong { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsncat(ws1: *mut wchar_t, ws2: *const wchar_t, n: usize) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsncmp(ws1: *const wchar_t, ws2: *const wchar_t, n: usize) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsncpy(ws1: *mut wchar_t, ws2: *const wchar_t, n: usize) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcspbrk(ws1: *const wchar_t, ws2: *const wchar_t) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsrchr(ws1: *const wchar_t, ws2: wchar_t) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsrtombs( + dst: *mut c_char, + src: *mut *const wchar_t, + len: usize, + ps: *mut mbstate_t, +) -> usize { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsspn(ws1: *const wchar_t, ws2: *const wchar_t) -> usize { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsstr(ws1: *const wchar_t, ws2: *const wchar_t) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcstod(nptr: *const wchar_t, endptr: *mut *mut wchar_t) -> f64 { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcstok( + ws1: *mut wchar_t, + ws2: *const wchar_t, + ptr: *mut *mut wchar_t, +) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcstol(nptr: *const wchar_t, endptr: *mut *mut wchar_t, base: c_int) -> c_long { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcstoul(nptr: *const wchar_t, endptr: *mut *mut wchar_t, base: c_int) -> c_ulong { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcswcs(ws1: *const wchar_t, ws2: *const wchar_t) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcswidth(pwcs: *const wchar_t, n: usize) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcsxfrm(ws1: *mut wchar_t, ws2: *const wchar_t, n: usize) -> usize { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wctob(c: wint_t) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wcwidth(wc: wchar_t) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wmemchr(ws: *const wchar_t, wc: wchar_t, n: usize) -> *mut c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wmemcmp(ws1: *const wchar_t, ws2: *const wchar_t, n: usize) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wmemcpy(ws1: *mut wchar_t, ws2: *const wchar_t, n: usize) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wmemmove(ws1: *mut wchar_t, ws2: *const wchar_t, n: usize) -> *mut wchar_t { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn wmemset(ws1: *mut wchar_t, ws2: wchar_t, n: usize) -> *mut wchar_t { + unimplemented!(); +} diff --git a/tests/.gitignore b/tests/.gitignore index 156ddf2607..7887a5a61a 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -15,8 +15,9 @@ /fcntl /fsync /ftruncate -/getid /getc_unget +/gethostname +/getid /link /locale /math diff --git a/tests/Makefile b/tests/Makefile index c08209e3ec..fd7a02abd4 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -57,6 +57,7 @@ BINS=\ $(EXPECT_BINS) \ alloc \ chdir \ + gethostname \ getid \ setid diff --git a/tests/gethostname.c b/tests/gethostname.c new file mode 100644 index 0000000000..02a0b7a7d4 --- /dev/null +++ b/tests/gethostname.c @@ -0,0 +1,12 @@ +#include +#include +#include + +int main() { + char* hostname = malloc(256); + if (gethostname(hostname, 256) == 0) { + printf("Hostname: %s\n", hostname); + } else { + puts("error getting hostname"); + } +} From 727324fd7342140e6fc2e959c3898991d74f0c24 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 16:54:31 +0200 Subject: [PATCH 11/13] Apparently cbindgen works on constants --- src/signal/src/lib.rs | 6 +-- src/signal/src/linux.rs | 84 ++++++++++++++++++++--------------------- src/signal/src/redox.rs | 76 ++++++++++++++++++------------------- 3 files changed, 83 insertions(+), 83 deletions(-) diff --git a/src/signal/src/lib.rs b/src/signal/src/lib.rs index a59a136932..7195c5ff1a 100644 --- a/src/signal/src/lib.rs +++ b/src/signal/src/lib.rs @@ -12,9 +12,9 @@ pub mod sys; #[path = "redox.rs"] pub mod sys; -#[no_mangle] pub static SIG_BLOCK: c_int = 0; -#[no_mangle] pub static SIG_UNBLOCK: c_int = 1; -#[no_mangle] pub static SIG_SETMASK: c_int = 2; +pub const SIG_BLOCK: c_int = 0; +pub const SIG_UNBLOCK: c_int = 1; +pub const SIG_SETMASK: c_int = 2; pub use sys::*; diff --git a/src/signal/src/linux.rs b/src/signal/src/linux.rs index d5ebf09213..628e813390 100644 --- a/src/signal/src/linux.rs +++ b/src/signal/src/linux.rs @@ -3,46 +3,46 @@ pub struct sys_sigset_t { pub bits: [u64; 16], } -#[no_mangle] pub static SIGHUP: usize = 1; -#[no_mangle] pub static SIGINT: usize = 2; -#[no_mangle] pub static SIGQUIT: usize = 3; -#[no_mangle] pub static SIGILL: usize = 4; -#[no_mangle] pub static SIGTRAP: usize = 5; -#[no_mangle] pub static SIGABRT: usize = 6; -#[no_mangle] pub static SIGIOT: usize = 6; -#[no_mangle] pub static SIGBUS: usize = 7; -#[no_mangle] pub static SIGFPE: usize = 8; -#[no_mangle] pub static SIGKILL: usize = 9; -#[no_mangle] pub static SIGUSR1: usize = 10; -#[no_mangle] pub static SIGSEGV: usize = 11; -#[no_mangle] pub static SIGUSR2: usize = 12; -#[no_mangle] pub static SIGPIPE: usize = 13; -#[no_mangle] pub static SIGALRM: usize = 14; -#[no_mangle] pub static SIGTERM: usize = 15; -#[no_mangle] pub static SIGSTKFLT: usize = 16; -#[no_mangle] pub static SIGCHLD: usize = 17; -#[no_mangle] pub static SIGCONT: usize = 18; -#[no_mangle] pub static SIGSTOP: usize = 19; -#[no_mangle] pub static SIGTSTP: usize = 20; -#[no_mangle] pub static SIGTTIN: usize = 21; -#[no_mangle] pub static SIGTTOU: usize = 22; -#[no_mangle] pub static SIGURG: usize = 23; -#[no_mangle] pub static SIGXCPU: usize = 24; -#[no_mangle] pub static SIGXFSZ: usize = 25; -#[no_mangle] pub static SIGVTALRM: usize = 26; -#[no_mangle] pub static SIGPROF: usize = 27; -#[no_mangle] pub static SIGWINCH: usize = 28; -#[no_mangle] pub static SIGIO: usize = 29; -#[no_mangle] pub static SIGPOLL: usize = 29; -#[no_mangle] pub static SIGPWR: usize = 30; -#[no_mangle] pub static SIGSYS: usize = 31; -#[no_mangle] pub static SIGUNUSED: usize = 31; +pub const SIGHUP: usize = 1; +pub const SIGINT: usize = 2; +pub const SIGQUIT: usize = 3; +pub const SIGILL: usize = 4; +pub const SIGTRAP: usize = 5; +pub const SIGABRT: usize = 6; +pub const SIGIOT: usize = SIGABRT; +pub const SIGBUS: usize = 7; +pub const SIGFPE: usize = 8; +pub const SIGKILL: usize = 9; +pub const SIGUSR1: usize = 10; +pub const SIGSEGV: usize = 11; +pub const SIGUSR2: usize = 12; +pub const SIGPIPE: usize = 13; +pub const SIGALRM: usize = 14; +pub const SIGTERM: usize = 15; +pub const SIGSTKFLT: usize = 16; +pub const SIGCHLD: usize = 17; +pub const SIGCONT: usize = 18; +pub const SIGSTOP: usize = 19; +pub const SIGTSTP: usize = 20; +pub const SIGTTIN: usize = 21; +pub const SIGTTOU: usize = 22; +pub const SIGURG: usize = 23; +pub const SIGXCPU: usize = 24; +pub const SIGXFSZ: usize = 25; +pub const SIGVTALRM: usize = 26; +pub const SIGPROF: usize = 27; +pub const SIGWINCH: usize = 28; +pub const SIGIO: usize = 29; +pub const SIGPOLL: usize = 29; +pub const SIGPWR: usize = 30; +pub const SIGSYS: usize = 31; +pub const SIGUNUSED: usize = SIGSYS; -#[no_mangle] pub static SA_NOCLDSTOP: usize = 1; -#[no_mangle] pub static SA_NOCLDWAIT: usize = 2; -#[no_mangle] pub static SA_SIGINFO: usize = 4; -#[no_mangle] pub static SA_ONSTACK: usize = 0x08000000; -#[no_mangle] pub static SA_RESTART: usize = 0x10000000; -#[no_mangle] pub static SA_NODEFER: usize = 0x40000000; -#[no_mangle] pub static SA_RESETHAND: usize = 0x80000000; -#[no_mangle] pub static SA_RESTORER: usize = 0x04000000; +pub const SA_NOCLDSTOP: usize = 1; +pub const SA_NOCLDWAIT: usize = 2; +pub const SA_SIGINFO: usize = 4; +pub const SA_ONSTACK: usize = 0x08000000; +pub const SA_RESTART: usize = 0x10000000; +pub const SA_NODEFER: usize = 0x40000000; +pub const SA_RESETHAND: usize = 0x80000000; +pub const SA_RESTORER: usize = 0x04000000; diff --git a/src/signal/src/redox.rs b/src/signal/src/redox.rs index 6abede5ff4..b5108b5a62 100644 --- a/src/signal/src/redox.rs +++ b/src/signal/src/redox.rs @@ -3,42 +3,42 @@ pub struct sys_sigset_t { pub bits: [u64; 2], } -#[no_mangle] pub static SIGHUP: usize = 1; -#[no_mangle] pub static SIGINT: usize = 2; -#[no_mangle] pub static SIGQUIT: usize = 3; -#[no_mangle] pub static SIGILL: usize = 4; -#[no_mangle] pub static SIGTRAP: usize = 5; -#[no_mangle] pub static SIGBUS: usize = 7; -#[no_mangle] pub static SIGFPE: usize = 8; -#[no_mangle] pub static SIGKILL: usize = 9; -#[no_mangle] pub static SIGUSR1: usize = 10; -#[no_mangle] pub static SIGSEGV: usize = 11; -#[no_mangle] pub static SIGUSR2: usize = 12; -#[no_mangle] pub static SIGPIPE: usize = 13; -#[no_mangle] pub static SIGALRM: usize = 14; -#[no_mangle] pub static SIGTERM: usize = 15; -#[no_mangle] pub static SIGSTKFLT: usize = 16; -#[no_mangle] pub static SIGCHLD: usize = 17; -#[no_mangle] pub static SIGCONT: usize = 18; -#[no_mangle] pub static SIGSTOP: usize = 19; -#[no_mangle] pub static SIGTSTP: usize = 20; -#[no_mangle] pub static SIGTTIN: usize = 21; -#[no_mangle] pub static SIGTTOU: usize = 22; -#[no_mangle] pub static SIGURG: usize = 23; -#[no_mangle] pub static SIGXCPU: usize = 24; -#[no_mangle] pub static SIGXFSZ: usize = 25; -#[no_mangle] pub static SIGVTALRM: usize = 26; -#[no_mangle] pub static SIGPROF: usize = 27; -#[no_mangle] pub static SIGWINCH: usize = 28; -#[no_mangle] pub static SIGIO: usize = 29; -#[no_mangle] pub static SIGPWR: usize = 30; -#[no_mangle] pub static SIGSYS: usize = 31; +pub const SIGHUP: usize = 1; +pub const SIGINT: usize = 2; +pub const SIGQUIT: usize = 3; +pub const SIGILL: usize = 4; +pub const SIGTRAP: usize = 5; +pub const SIGBUS: usize = 7; +pub const SIGFPE: usize = 8; +pub const SIGKILL: usize = 9; +pub const SIGUSR1: usize = 10; +pub const SIGSEGV: usize = 11; +pub const SIGUSR2: usize = 12; +pub const SIGPIPE: usize = 13; +pub const SIGALRM: usize = 14; +pub const SIGTERM: usize = 15; +pub const SIGSTKFLT: usize = 16; +pub const SIGCHLD: usize = 17; +pub const SIGCONT: usize = 18; +pub const SIGSTOP: usize = 19; +pub const SIGTSTP: usize = 20; +pub const SIGTTIN: usize = 21; +pub const SIGTTOU: usize = 22; +pub const SIGURG: usize = 23; +pub const SIGXCPU: usize = 24; +pub const SIGXFSZ: usize = 25; +pub const SIGVTALRM: usize = 26; +pub const SIGPROF: usize = 27; +pub const SIGWINCH: usize = 28; +pub const SIGIO: usize = 29; +pub const SIGPWR: usize = 30; +pub const SIGSYS: usize = 31; -#[no_mangle] pub static SA_NOCLDSTOP: usize = 0x00000001; -#[no_mangle] pub static SA_NOCLDWAIT: usize = 0x00000002; -#[no_mangle] pub static SA_SIGINFO: usize = 0x00000004; -#[no_mangle] pub static SA_RESTORER: usize = 0x04000000; -#[no_mangle] pub static SA_ONSTACK: usize = 0x08000000; -#[no_mangle] pub static SA_RESTART: usize = 0x10000000; -#[no_mangle] pub static SA_NODEFER: usize = 0x40000000; -#[no_mangle] pub static SA_RESETHAND: usize = 0x80000000; +pub const SA_NOCLDSTOP: usize = 0x00000001; +pub const SA_NOCLDWAIT: usize = 0x00000002; +pub const SA_SIGINFO: usize = 0x00000004; +pub const SA_RESTORER: usize = 0x04000000; +pub const SA_ONSTACK: usize = 0x08000000; +pub const SA_RESTART: usize = 0x10000000; +pub const SA_NODEFER: usize = 0x40000000; +pub const SA_RESETHAND: usize = 0x80000000; From cbc3723c66852e4e17be4f409feb6d7840a68953 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Tue, 26 Jun 2018 17:16:56 +0200 Subject: [PATCH 12/13] Fix signal not being linked correctly --- src/lib.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib.rs b/src/lib.rs index 6d5cc2d208..7c9f060b59 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,7 @@ pub extern crate locale; pub extern crate netinet; pub extern crate semaphore; pub extern crate setjmp; +pub extern crate signal; pub extern crate stdio; pub extern crate stdlib; pub extern crate string; From a6ffd2cc460d3d1a493d518d28329429e99b139b Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Wed, 27 Jun 2018 08:08:14 +0200 Subject: [PATCH 13/13] Update inttypes to match the revert of ints --- include/bits/inttypes.h | 132 ++++++++++++++++++++-------------------- 1 file changed, 66 insertions(+), 66 deletions(-) diff --git a/include/bits/inttypes.h b/include/bits/inttypes.h index c1a7cf4bfd..e727b8a1c7 100644 --- a/include/bits/inttypes.h +++ b/include/bits/inttypes.h @@ -3,93 +3,93 @@ #define PRId8 "hhd" #define PRId16 "hd" -#define PRId32 "d" -#define PRId64 "ld" +#define PRId32 "ld" +#define PRId64 "Ld" #define PRIdLEAST8 "hhd" #define PRIdLEAST16 "hd" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 "ld" +#define PRIdLEAST32 "ld" +#define PRIdLEAST64 "Ld" #define PRIdFAST8 "hhd" #define PRIdFAST16 "hd" -#define PRIdFAST32 "d" -#define PRIdFAST64 "ld" +#define PRIdFAST32 "ld" +#define PRIdFAST64 "Ld" #define PRIi8 "hhi" #define PRIi16 "hi" -#define PRIi32 "i" -#define PRIi64 "li" +#define PRIi32 "li" +#define PRIi64 "Li" #define PRIiLEAST8 "hhi" #define PRIiLEAST16 "hi" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 "li" +#define PRIiLEAST32 "li" +#define PRIiLEAST64 "Li" #define PRIiFAST8 "hhi" #define PRIiFAST16 "hi" -#define PRIiFAST32 "i" -#define PRIiFAST64 "li" +#define PRIiFAST32 "li" +#define PRIiFAST64 "Li" #define PRIo8 "hho" #define PRIo16 "ho" -#define PRIo32 "o" -#define PRIo64 "lo" +#define PRIo32 "lo" +#define PRIo64 "Lo" #define PRIoLEAST8 "hho" #define PRIoLEAST16 "ho" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 "lo" +#define PRIoLEAST32 "lo" +#define PRIoLEAST64 "Lo" #define PRIoFAST8 "hho" #define PRIoFAST16 "ho" -#define PRIoFAST32 "o" -#define PRIoFAST64 "lo" +#define PRIoFAST32 "lo" +#define PRIoFAST64 "Lo" #define PRIu8 "hhu" #define PRIu16 "hu" -#define PRIu32 "u" -#define PRIu64 "lu" +#define PRIu32 "lu" +#define PRIu64 "Lu" #define PRIuLEAST8 "hhu" #define PRIuLEAST16 "hu" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 "lu" +#define PRIuLEAST32 "lu" +#define PRIuLEAST64 "Lu" #define PRIuFAST8 "hhu" #define PRIuFAST16 "hu" -#define PRIuFAST32 "u" -#define PRIuFAST64 "lu" +#define PRIuFAST32 "lu" +#define PRIuFAST64 "Lu" #define PRIx8 "hhx" #define PRIx16 "hx" -#define PRIx32 "x" -#define PRIx64 "lx" +#define PRIx32 "lx" +#define PRIx64 "Lx" #define PRIxLEAST8 "hhx" #define PRIxLEAST16 "hx" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 "lx" +#define PRIxLEAST32 "lx" +#define PRIxLEAST64 "Lx" #define PRIxFAST8 "hhx" #define PRIxFAST16 "hx" -#define PRIxFAST32 "x" -#define PRIxFAST64 "lx" +#define PRIxFAST32 "lx" +#define PRIxFAST64 "Lx" #define PRIX8 "hhX" #define PRIX16 "hX" -#define PRIX32 "X" -#define PRIX64 "lX" +#define PRIX32 "lX" +#define PRIX64 "LX" #define PRIXLEAST8 "hhX" #define PRIXLEAST16 "hX" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 "lX" +#define PRIXLEAST32 "lX" +#define PRIXLEAST64 "LX" #define PRIXFAST8 "hhX" #define PRIXFAST16 "hX" -#define PRIXFAST32 "X" -#define PRIXFAST64 "lX" +#define PRIXFAST32 "lX" +#define PRIXFAST64 "LX" #define PRIdMAX "jd" #define PRIiMAX "ji" @@ -107,78 +107,78 @@ #define SCNd8 "hhd" #define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 "ld" +#define SCNd32 "ld" +#define SCNd64 "Ld" #define SCNdLEAST8 "hhd" #define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 "ld" +#define SCNdLEAST32 "ld" +#define SCNdLEAST64 "Ld" #define SCNdFAST8 "hhd" #define SCNdFAST16 "hd" -#define SCNdFAST32 "d" -#define SCNdFAST64 "ld" +#define SCNdFAST32 "ld" +#define SCNdFAST64 "Ld" #define SCNi8 "hhi" #define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 "li" +#define SCNi32 "li" +#define SCNi64 "Li" #define SCNiLEAST8 "hhi" #define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 "li" +#define SCNiLEAST32 "li" +#define SCNiLEAST64 "Li" #define SCNiFAST8 "hhi" #define SCNiFAST16 "hi" -#define SCNiFAST32 "i" -#define SCNiFAST64 "li" +#define SCNiFAST32 "li" +#define SCNiFAST64 "Li" #define SCNo8 "hho" #define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 "lo" +#define SCNo32 "lo" +#define SCNo64 "Lo" #define SCNoLEAST8 "hho" #define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 "lo" +#define SCNoLEAST32 "lo" +#define SCNoLEAST64 "Lo" #define SCNoFAST8 "hho" #define SCNoFAST16 "ho" -#define SCNoFAST32 "o" -#define SCNoFAST64 "lo" +#define SCNoFAST32 "lo" +#define SCNoFAST64 "Lo" #define SCNu8 "hhu" #define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 "lu" +#define SCNu32 "lu" +#define SCNu64 "Lu" #define SCNuLEAST8 "hhu" #define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 "lu" +#define SCNuLEAST32 "lu" +#define SCNuLEAST64 "Lu" #define SCNuFAST8 "hhu" #define SCNuFAST16 "hu" -#define SCNuFAST32 "u" -#define SCNuFAST64 "lu" +#define SCNuFAST32 "lu" +#define SCNuFAST64 "Lu" #define SCNx8 "hhx" #define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 "lx" +#define SCNx32 "lx" +#define SCNx64 "Lx" #define SCNxLEAST8 "hhx" #define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 "lx" +#define SCNxLEAST32 "lx" +#define SCNxLEAST64 "Lx" #define SCNxFAST8 "hhx" #define SCNxFAST16 "hx" -#define SCNxFAST32 "x" -#define SCNxFAST64 "lx" +#define SCNxFAST32 "lx" +#define SCNxFAST64 "Lx" #define SCNdMAX "jd" #define SCNiMAX "ji"