From 12ce441f5c9c9fc62a29b5a32efcf64154bb19d4 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Fri, 22 Jun 2018 22:12:29 +0200 Subject: [PATCH 01/34] Use static mut over UnsafeCell --- src/stdio/src/default.rs | 31 +++++++++---------------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/src/stdio/src/default.rs b/src/stdio/src/default.rs index 25b5844719..9337856c5d 100644 --- a/src/stdio/src/default.rs +++ b/src/stdio/src/default.rs @@ -1,25 +1,12 @@ -use core::cell::UnsafeCell; use core::sync::atomic::AtomicBool; use core::ptr; use super::{constants, internal, BUFSIZ, FILE, UNGET}; -struct GlobalFile(UnsafeCell); -impl GlobalFile { - const fn new(file: FILE) -> Self { - GlobalFile(UnsafeCell::new(file)) - } - fn get(&self) -> *mut FILE { - self.0.get() - } -} -// statics need to be Sync -unsafe impl Sync for GlobalFile {} - #[allow(non_upper_case_globals)] static mut default_stdin_buf: [u8; BUFSIZ as usize + UNGET] = [0; BUFSIZ as usize + UNGET]; #[allow(non_upper_case_globals)] -static mut default_stdin: GlobalFile = GlobalFile::new(FILE { +static mut default_stdin: FILE = FILE { flags: constants::F_PERM | constants::F_NOWR | constants::F_BADJ, rpos: ptr::null_mut(), rend: ptr::null_mut(), @@ -32,13 +19,13 @@ static mut default_stdin: GlobalFile = GlobalFile::new(FILE { buf_char: -1, unget: UNGET, lock: AtomicBool::new(false), -}); +}; #[allow(non_upper_case_globals)] static mut default_stdout_buf: [u8; BUFSIZ as usize] = [0; BUFSIZ as usize]; #[allow(non_upper_case_globals)] -static mut default_stdout: GlobalFile = GlobalFile::new(FILE { +static mut default_stdout: FILE = FILE { flags: constants::F_PERM | constants::F_NORD | constants::F_BADJ, rpos: ptr::null_mut(), rend: ptr::null_mut(), @@ -51,13 +38,13 @@ static mut default_stdout: GlobalFile = GlobalFile::new(FILE { buf_char: b'\n' as i8, unget: 0, lock: AtomicBool::new(false), -}); +}; #[allow(non_upper_case_globals)] static mut default_stderr_buf: [u8; BUFSIZ as usize] = [0; BUFSIZ as usize]; #[allow(non_upper_case_globals)] -static mut default_stderr: GlobalFile = GlobalFile::new(FILE { +static mut default_stderr: FILE = FILE { flags: constants::F_PERM | constants::F_NORD | constants::F_BADJ, rpos: ptr::null_mut(), rend: ptr::null_mut(), @@ -70,19 +57,19 @@ static mut default_stderr: GlobalFile = GlobalFile::new(FILE { buf_char: -1, unget: 0, lock: AtomicBool::new(false), -}); +}; #[no_mangle] pub extern "C" fn __stdin() -> *mut FILE { - unsafe { default_stdin.get() } + unsafe { &mut default_stdin } } #[no_mangle] pub extern "C" fn __stdout() -> *mut FILE { - unsafe { default_stdout.get() } + unsafe { &mut default_stdout } } #[no_mangle] pub extern "C" fn __stderr() -> *mut FILE { - unsafe { default_stderr.get() } + unsafe { &mut default_stderr } } From 5945de62cbc3e83881ed755452b27723f063dfb8 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sat, 23 Jun 2018 06:54:23 +0200 Subject: [PATCH 02/34] Install openlibm from Makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 48323ac902..7f647342d3 100644 --- a/Makefile +++ b/Makefile @@ -36,6 +36,8 @@ install: all mkdir -pv "$(DESTDIR)/include" cp -rv "include"/* "$(DESTDIR)/include" cp -rv "target/include"/* "$(DESTDIR)/include" + cp -rv "target/openlibm/include"/* "$(DESTDIR)/include" + cp -rv "target/openlibm/src"/*.h "$(DESTDIR)/include" cp -v "$(BUILD)/debug/libc.a" "$(DESTDIR)/lib" cp -v "$(BUILD)/debug/crt0.o" "$(DESTDIR)/lib" cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a" From 829bc64ad6b337707c45a703af776d8b6a3f2d05 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sat, 23 Jun 2018 07:54:36 +0200 Subject: [PATCH 03/34] Remove unused import from test --- tests/scanf.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/scanf.c b/tests/scanf.c index ce7f217bcb..5c3e1e89c5 100644 --- a/tests/scanf.c +++ b/tests/scanf.c @@ -1,5 +1,4 @@ #include -#include int main(int argc, char ** argv) { int a = 0; From 4e99b55417db3873952f91d541c26b7a3420cf1e Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sat, 23 Jun 2018 17:34:16 +0200 Subject: [PATCH 04/34] Implement basic setjmp using musl's awesome existing code --- Cargo.lock | 9 +++ Cargo.toml | 1 + include/bits/setjmp.h | 67 +++++++++++++++++++++ src/lib.rs | 1 + src/setjmp/Cargo.toml | 11 ++++ src/setjmp/build.rs | 72 ++++++++++++++++++++++ src/setjmp/cbindgen.toml | 6 ++ src/setjmp/impl/README.md | 6 ++ src/setjmp/impl/aarch64/longjmp.s | 24 ++++++++ src/setjmp/impl/aarch64/setjmp.s | 24 ++++++++ src/setjmp/impl/arm/longjmp.s | 43 ++++++++++++++ src/setjmp/impl/arm/setjmp.s | 45 ++++++++++++++ src/setjmp/impl/bin/.gitignore | 2 + src/setjmp/impl/i386/longjmp.s | 20 +++++++ src/setjmp/impl/i386/setjmp.s | 23 +++++++ src/setjmp/impl/m68k/longjmp.s | 14 +++++ src/setjmp/impl/m68k/setjmp.s | 18 ++++++ src/setjmp/impl/microblaze/longjmp.s | 29 +++++++++ src/setjmp/impl/microblaze/setjmp.s | 32 ++++++++++ src/setjmp/impl/mips/longjmp.S | 40 +++++++++++++ src/setjmp/impl/mips/setjmp.S | 39 ++++++++++++ src/setjmp/impl/mips64/longjmp.S | 37 ++++++++++++ src/setjmp/impl/mips64/setjmp.S | 34 +++++++++++ src/setjmp/impl/mipsn32/longjmp.S | 36 +++++++++++ src/setjmp/impl/mipsn32/setjmp.S | 34 +++++++++++ src/setjmp/impl/or1k/longjmp.s | 25 ++++++++ src/setjmp/impl/or1k/setjmp.s | 27 +++++++++ src/setjmp/impl/powerpc/longjmp.S | 69 +++++++++++++++++++++ src/setjmp/impl/powerpc/setjmp.S | 63 ++++++++++++++++++++ src/setjmp/impl/powerpc64/longjmp.s | 81 +++++++++++++++++++++++++ src/setjmp/impl/powerpc64/setjmp.s | 89 ++++++++++++++++++++++++++++ src/setjmp/impl/s390x/longjmp.s | 23 +++++++ src/setjmp/impl/s390x/setjmp.s | 25 ++++++++ src/setjmp/impl/sh/longjmp.S | 28 +++++++++ src/setjmp/impl/sh/setjmp.S | 32 ++++++++++ src/setjmp/impl/x32/longjmp.s | 22 +++++++ src/setjmp/impl/x32/setjmp.s | 22 +++++++ src/setjmp/impl/x86_64/longjmp.s | 22 +++++++ src/setjmp/impl/x86_64/setjmp.s | 22 +++++++ src/setjmp/src/lib.rs | 62 +++++++++++++++++++ src/stdlib/src/lib.rs | 4 +- tests/.gitignore | 2 +- tests/Makefile | 1 + tests/expected/setjmp.stderr | 0 tests/expected/setjmp.stdout | 2 + tests/setjmp.c | 12 ++++ 46 files changed, 1297 insertions(+), 3 deletions(-) create mode 100644 include/bits/setjmp.h create mode 100644 src/setjmp/Cargo.toml create mode 100644 src/setjmp/build.rs create mode 100644 src/setjmp/cbindgen.toml create mode 100644 src/setjmp/impl/README.md create mode 100644 src/setjmp/impl/aarch64/longjmp.s create mode 100644 src/setjmp/impl/aarch64/setjmp.s create mode 100644 src/setjmp/impl/arm/longjmp.s create mode 100644 src/setjmp/impl/arm/setjmp.s create mode 100644 src/setjmp/impl/bin/.gitignore create mode 100644 src/setjmp/impl/i386/longjmp.s create mode 100644 src/setjmp/impl/i386/setjmp.s create mode 100644 src/setjmp/impl/m68k/longjmp.s create mode 100644 src/setjmp/impl/m68k/setjmp.s create mode 100644 src/setjmp/impl/microblaze/longjmp.s create mode 100644 src/setjmp/impl/microblaze/setjmp.s create mode 100644 src/setjmp/impl/mips/longjmp.S create mode 100644 src/setjmp/impl/mips/setjmp.S create mode 100644 src/setjmp/impl/mips64/longjmp.S create mode 100644 src/setjmp/impl/mips64/setjmp.S create mode 100644 src/setjmp/impl/mipsn32/longjmp.S create mode 100644 src/setjmp/impl/mipsn32/setjmp.S create mode 100644 src/setjmp/impl/or1k/longjmp.s create mode 100644 src/setjmp/impl/or1k/setjmp.s create mode 100644 src/setjmp/impl/powerpc/longjmp.S create mode 100644 src/setjmp/impl/powerpc/setjmp.S create mode 100644 src/setjmp/impl/powerpc64/longjmp.s create mode 100644 src/setjmp/impl/powerpc64/setjmp.s create mode 100644 src/setjmp/impl/s390x/longjmp.s create mode 100644 src/setjmp/impl/s390x/setjmp.s create mode 100644 src/setjmp/impl/sh/longjmp.S create mode 100644 src/setjmp/impl/sh/setjmp.S create mode 100644 src/setjmp/impl/x32/longjmp.s create mode 100644 src/setjmp/impl/x32/setjmp.s create mode 100644 src/setjmp/impl/x86_64/longjmp.s create mode 100644 src/setjmp/impl/x86_64/setjmp.s create mode 100644 src/setjmp/src/lib.rs create mode 100644 tests/expected/setjmp.stderr create mode 100644 tests/expected/setjmp.stdout create mode 100644 tests/setjmp.c diff --git a/Cargo.lock b/Cargo.lock index 860ade9b40..61a8787b95 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -283,6 +283,7 @@ dependencies = [ "netinet 0.1.0", "platform 0.1.0", "semaphore 0.1.0", + "setjmp 0.1.0", "signal 0.1.0", "stdio 0.1.0", "stdlib 0.1.0", @@ -357,6 +358,14 @@ dependencies = [ "serde 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "setjmp" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.2", + "platform 0.1.0", +] + [[package]] name = "signal" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index 6b2b0fe0b2..dd15d54dca 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,7 @@ grp = { path = "src/grp" } locale = { path = "src/locale" } netinet = { path = "src/netinet" } platform = { path = "src/platform" } +setjmp = { path = "src/setjmp" } semaphore = { path = "src/semaphore" } signal = { path = "src/signal" } stdio = { path = "src/stdio" } diff --git a/include/bits/setjmp.h b/include/bits/setjmp.h new file mode 100644 index 0000000000..aa40a2dc75 --- /dev/null +++ b/include/bits/setjmp.h @@ -0,0 +1,67 @@ +#ifndef _BITS_SETJMP_H +#define _BITS_SETJMP_H + +#ifdef __arch64__ +typedef unsigned long jmp_buf[22]; +#endif + +#ifdef __arm__ +typedef unsigned long long jmp_buf[32]; +#endif + +#ifdef __i386__ +typedef unsigned long jmp_buf[6]; +#endif + +#ifdef __m68k__ +typedef unsigned long jmp_buf[39]; +#endif + +#ifdef __microblaze__ +typedef unsigned long jmp_buf[18]; +#endif + +#ifdef __mips__ +typedef unsigned long long jmp_buf[13]; +#endif + +#ifdef __mips64__ +typedef unsigned long long jmp_buf[23]; +#endif + +#ifdef __mipsn32__ +typedef unsigned long long jmp_buf[23]; +#endif + +#ifdef __or1k__ +typedef unsigned long jmp_buf[13]; +#endif + +#ifdef __powerpc__ +typedef unsigned long long jmp_buf[56]; +#endif + +#ifdef __powerpc64__ +typedef uint128_t jmp_buf[32]; +#endif + +#ifdef __s390x__ +typedef unsigned long jmp_buf[18]; +#endif + +#ifdef __sh__ +typedef unsigned long jmp_buf[15]; +#endif + +#ifdef __x32__ +typedef unsigned long long jmp_buf[8]; +#endif + +#ifdef __x86_64__ +typedef unsigned long jmp_buf[8]; +#endif + +int setjmp(jmp_buf buf); +void longjmp(jmp_buf buf, int value); + +#endif /* _SETJMP_H */ diff --git a/src/lib.rs b/src/lib.rs index 61672efd88..3ea9b7d7bd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,6 +13,7 @@ pub extern crate grp; pub extern crate locale; pub extern crate netinet; pub extern crate semaphore; +pub extern crate setjmp; pub extern crate stdio; pub extern crate stdlib; pub extern crate string; diff --git a/src/setjmp/Cargo.toml b/src/setjmp/Cargo.toml new file mode 100644 index 0000000000..1874c87603 --- /dev/null +++ b/src/setjmp/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "setjmp" +version = "0.1.0" +authors = ["Jeremy Soller "] +build = "build.rs" + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } diff --git a/src/setjmp/build.rs b/src/setjmp/build.rs new file mode 100644 index 0000000000..e24e6d2efb --- /dev/null +++ b/src/setjmp/build.rs @@ -0,0 +1,72 @@ +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 new file mode 100644 index 0000000000..30958dd223 --- /dev/null +++ b/src/setjmp/cbindgen.toml @@ -0,0 +1,6 @@ +include_guard = "_SETJMP_H" +trailer = "#include " +language = "C" + +[enum] +prefix_with_name = true diff --git a/src/setjmp/impl/README.md b/src/setjmp/impl/README.md new file mode 100644 index 0000000000..be1ebb9ee7 --- /dev/null +++ b/src/setjmp/impl/README.md @@ -0,0 +1,6 @@ +# setjmp implementation + +All this code belongs to [musl libc](https://www.musl-libc.org/). +They own it. All rights go to them. +Huge thanks to them for doing this tedious per-arch assembly work! +We will reuse this awesome effort :) diff --git a/src/setjmp/impl/aarch64/longjmp.s b/src/setjmp/impl/aarch64/longjmp.s new file mode 100644 index 0000000000..7c4655fa96 --- /dev/null +++ b/src/setjmp/impl/aarch64/longjmp.s @@ -0,0 +1,24 @@ +.global _longjmp +.global longjmp +.type _longjmp,%function +.type longjmp,%function +_longjmp: +longjmp: + // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers + ldp x19, x20, [x0,#0] + ldp x21, x22, [x0,#16] + ldp x23, x24, [x0,#32] + ldp x25, x26, [x0,#48] + ldp x27, x28, [x0,#64] + ldp x29, x30, [x0,#80] + ldr x2, [x0,#104] + mov sp, x2 + ldp d8 , d9, [x0,#112] + ldp d10, d11, [x0,#128] + ldp d12, d13, [x0,#144] + ldp d14, d15, [x0,#160] + + mov x0, x1 + cbnz x1, 1f + mov x0, #1 +1: br x30 diff --git a/src/setjmp/impl/aarch64/setjmp.s b/src/setjmp/impl/aarch64/setjmp.s new file mode 100644 index 0000000000..f49288aa1c --- /dev/null +++ b/src/setjmp/impl/aarch64/setjmp.s @@ -0,0 +1,24 @@ +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +__setjmp: +_setjmp: +setjmp: + // IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers + stp x19, x20, [x0,#0] + stp x21, x22, [x0,#16] + stp x23, x24, [x0,#32] + stp x25, x26, [x0,#48] + stp x27, x28, [x0,#64] + stp x29, x30, [x0,#80] + mov x2, sp + str x2, [x0,#104] + stp d8, d9, [x0,#112] + stp d10, d11, [x0,#128] + stp d12, d13, [x0,#144] + stp d14, d15, [x0,#160] + mov x0, #0 + ret diff --git a/src/setjmp/impl/arm/longjmp.s b/src/setjmp/impl/arm/longjmp.s new file mode 100644 index 0000000000..76cc2920a3 --- /dev/null +++ b/src/setjmp/impl/arm/longjmp.s @@ -0,0 +1,43 @@ +.syntax unified +.global _longjmp +.global longjmp +.type _longjmp,%function +.type longjmp,%function +_longjmp: +longjmp: + mov ip,r0 + movs r0,r1 + moveq r0,#1 + ldmia ip!, {v1,v2,v3,v4,v5,v6,sl,fp} + ldmia ip!, {r2,lr} + mov sp,r2 + + adr r1,1f + ldr r2,1f + ldr r1,[r1,r2] + + tst r1,#0x260 + beq 3f + tst r1,#0x20 + beq 2f + ldc p2, cr4, [ip], #48 +2: tst r1,#0x40 + beq 2f + .fpu vfp + vldmia ip!, {d8-d15} + .fpu softvfp + .eabi_attribute 10, 0 + .eabi_attribute 27, 0 +2: tst r1,#0x200 + beq 3f + ldcl p1, cr10, [ip], #8 + ldcl p1, cr11, [ip], #8 + ldcl p1, cr12, [ip], #8 + ldcl p1, cr13, [ip], #8 + ldcl p1, cr14, [ip], #8 + ldcl p1, cr15, [ip], #8 +3: bx lr + +.hidden __hwcap +.align 2 +1: .word __hwcap-1b diff --git a/src/setjmp/impl/arm/setjmp.s b/src/setjmp/impl/arm/setjmp.s new file mode 100644 index 0000000000..011315b70f --- /dev/null +++ b/src/setjmp/impl/arm/setjmp.s @@ -0,0 +1,45 @@ +.syntax unified +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,%function +.type _setjmp,%function +.type setjmp,%function +__setjmp: +_setjmp: +setjmp: + mov ip,r0 + stmia ip!,{v1,v2,v3,v4,v5,v6,sl,fp} + mov r2,sp + stmia ip!,{r2,lr} + mov r0,#0 + + adr r1,1f + ldr r2,1f + ldr r1,[r1,r2] + + tst r1,#0x260 + beq 3f + tst r1,#0x20 + beq 2f + stc p2, cr4, [ip], #48 +2: tst r1,#0x40 + beq 2f + .fpu vfp + vstmia ip!, {d8-d15} + .fpu softvfp + .eabi_attribute 10, 0 + .eabi_attribute 27, 0 +2: tst r1,#0x200 + beq 3f + stcl p1, cr10, [ip], #8 + stcl p1, cr11, [ip], #8 + stcl p1, cr12, [ip], #8 + stcl p1, cr13, [ip], #8 + stcl p1, cr14, [ip], #8 + stcl p1, cr15, [ip], #8 +3: bx lr + +.hidden __hwcap +.align 2 +1: .word __hwcap-1b diff --git a/src/setjmp/impl/bin/.gitignore b/src/setjmp/impl/bin/.gitignore new file mode 100644 index 0000000000..d6b7ef32c8 --- /dev/null +++ b/src/setjmp/impl/bin/.gitignore @@ -0,0 +1,2 @@ +* +!.gitignore diff --git a/src/setjmp/impl/i386/longjmp.s b/src/setjmp/impl/i386/longjmp.s new file mode 100644 index 0000000000..772d28ddb2 --- /dev/null +++ b/src/setjmp/impl/i386/longjmp.s @@ -0,0 +1,20 @@ +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + mov 4(%esp),%edx + mov 8(%esp),%eax + test %eax,%eax + jnz 1f + inc %eax +1: + mov (%edx),%ebx + mov 4(%edx),%esi + mov 8(%edx),%edi + mov 12(%edx),%ebp + mov 16(%edx),%ecx + mov %ecx,%esp + mov 20(%edx),%ecx + jmp *%ecx diff --git a/src/setjmp/impl/i386/setjmp.s b/src/setjmp/impl/i386/setjmp.s new file mode 100644 index 0000000000..4d19cf87cb --- /dev/null +++ b/src/setjmp/impl/i386/setjmp.s @@ -0,0 +1,23 @@ +.global ___setjmp +.hidden ___setjmp +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +___setjmp: +__setjmp: +_setjmp: +setjmp: + mov 4(%esp), %eax + mov %ebx, (%eax) + mov %esi, 4(%eax) + mov %edi, 8(%eax) + mov %ebp, 12(%eax) + lea 4(%esp), %ecx + mov %ecx, 16(%eax) + mov (%esp), %ecx + mov %ecx, 20(%eax) + xor %eax, %eax + ret diff --git a/src/setjmp/impl/m68k/longjmp.s b/src/setjmp/impl/m68k/longjmp.s new file mode 100644 index 0000000000..cdb05fb5a6 --- /dev/null +++ b/src/setjmp/impl/m68k/longjmp.s @@ -0,0 +1,14 @@ +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + movea.l 4(%sp),%a0 + move.l 8(%sp),%d0 + bne 1f + move.l #1,%d0 +1: movem.l (%a0),%d2-%d7/%a2-%a7 + fmovem.x 52(%a0),%fp2-%fp7 + move.l 48(%a0),(%sp) + rts diff --git a/src/setjmp/impl/m68k/setjmp.s b/src/setjmp/impl/m68k/setjmp.s new file mode 100644 index 0000000000..15e549b0ef --- /dev/null +++ b/src/setjmp/impl/m68k/setjmp.s @@ -0,0 +1,18 @@ +.global ___setjmp +.hidden ___setjmp +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +___setjmp: +__setjmp: +_setjmp: +setjmp: + movea.l 4(%sp),%a0 + movem.l %d2-%d7/%a2-%a7,(%a0) + move.l (%sp),48(%a0) + fmovem.x %fp2-%fp7,52(%a0) + clr.l %d0 + rts diff --git a/src/setjmp/impl/microblaze/longjmp.s b/src/setjmp/impl/microblaze/longjmp.s new file mode 100644 index 0000000000..c0760288a7 --- /dev/null +++ b/src/setjmp/impl/microblaze/longjmp.s @@ -0,0 +1,29 @@ +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + addi r3, r6, 0 + bnei r3, 1f + addi r3, r3, 1 +1: lwi r1, r5, 0 + lwi r15, r5, 4 + lwi r2, r5, 8 + lwi r13, r5, 12 + lwi r18, r5, 16 + lwi r19, r5, 20 + lwi r20, r5, 24 + lwi r21, r5, 28 + lwi r22, r5, 32 + lwi r23, r5, 36 + lwi r24, r5, 40 + lwi r25, r5, 44 + lwi r26, r5, 48 + lwi r27, r5, 52 + lwi r28, r5, 56 + lwi r29, r5, 60 + lwi r30, r5, 64 + lwi r31, r5, 68 + rtsd r15, 8 + nop diff --git a/src/setjmp/impl/microblaze/setjmp.s b/src/setjmp/impl/microblaze/setjmp.s new file mode 100644 index 0000000000..605ab20e4b --- /dev/null +++ b/src/setjmp/impl/microblaze/setjmp.s @@ -0,0 +1,32 @@ +.global ___setjmp +.hidden ___setjmp +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +___setjmp: +__setjmp: +_setjmp: +setjmp: + swi r1, r5, 0 + swi r15, r5, 4 + swi r2, r5, 8 + swi r13, r5, 12 + swi r18, r5, 16 + swi r19, r5, 20 + swi r20, r5, 24 + swi r21, r5, 28 + swi r22, r5, 32 + swi r23, r5, 36 + swi r24, r5, 40 + swi r25, r5, 44 + swi r26, r5, 48 + swi r27, r5, 52 + swi r28, r5, 56 + swi r29, r5, 60 + swi r30, r5, 64 + swi r31, r5, 68 + rtsd r15, 8 + ori r3, r0, 0 diff --git a/src/setjmp/impl/mips/longjmp.S b/src/setjmp/impl/mips/longjmp.S new file mode 100644 index 0000000000..fdb6c95d25 --- /dev/null +++ b/src/setjmp/impl/mips/longjmp.S @@ -0,0 +1,40 @@ +.set noreorder + +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + move $2, $5 + bne $2, $0, 1f + nop + addu $2, $2, 1 +1: +#ifndef __mips_soft_float + lwc1 $20, 56($4) + lwc1 $21, 60($4) + lwc1 $22, 64($4) + lwc1 $23, 68($4) + lwc1 $24, 72($4) + lwc1 $25, 76($4) + lwc1 $26, 80($4) + lwc1 $27, 84($4) + lwc1 $28, 88($4) + lwc1 $29, 92($4) + lwc1 $30, 96($4) + lwc1 $31, 100($4) +#endif + lw $ra, 0($4) + lw $sp, 4($4) + lw $16, 8($4) + lw $17, 12($4) + lw $18, 16($4) + lw $19, 20($4) + lw $20, 24($4) + lw $21, 28($4) + lw $22, 32($4) + lw $23, 36($4) + lw $30, 40($4) + jr $ra + lw $28, 44($4) diff --git a/src/setjmp/impl/mips/setjmp.S b/src/setjmp/impl/mips/setjmp.S new file mode 100644 index 0000000000..501d5264e6 --- /dev/null +++ b/src/setjmp/impl/mips/setjmp.S @@ -0,0 +1,39 @@ +.set noreorder + +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +__setjmp: +_setjmp: +setjmp: + sw $ra, 0($4) + sw $sp, 4($4) + sw $16, 8($4) + sw $17, 12($4) + sw $18, 16($4) + sw $19, 20($4) + sw $20, 24($4) + sw $21, 28($4) + sw $22, 32($4) + sw $23, 36($4) + sw $30, 40($4) + sw $28, 44($4) +#ifndef __mips_soft_float + swc1 $20, 56($4) + swc1 $21, 60($4) + swc1 $22, 64($4) + swc1 $23, 68($4) + swc1 $24, 72($4) + swc1 $25, 76($4) + swc1 $26, 80($4) + swc1 $27, 84($4) + swc1 $28, 88($4) + swc1 $29, 92($4) + swc1 $30, 96($4) + swc1 $31, 100($4) +#endif + jr $ra + li $2, 0 diff --git a/src/setjmp/impl/mips64/longjmp.S b/src/setjmp/impl/mips64/longjmp.S new file mode 100644 index 0000000000..3db8a883c6 --- /dev/null +++ b/src/setjmp/impl/mips64/longjmp.S @@ -0,0 +1,37 @@ +.set noreorder +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + move $2, $5 + + bne $2, $0, 1f + nop + daddu $2, $2, 1 +1: +#ifndef __mips_soft_float + ldc1 $24, 96($4) + ldc1 $25, 104($4) + ldc1 $26, 112($4) + ldc1 $27, 120($4) + ldc1 $28, 128($4) + ldc1 $29, 136($4) + ldc1 $30, 144($4) + ldc1 $31, 152($4) +#endif + ld $ra, 0($4) + ld $sp, 8($4) + ld $gp, 16($4) + ld $16, 24($4) + ld $17, 32($4) + ld $18, 40($4) + ld $19, 48($4) + ld $20, 56($4) + ld $21, 64($4) + ld $22, 72($4) + ld $23, 80($4) + ld $30, 88($4) + jr $ra + nop diff --git a/src/setjmp/impl/mips64/setjmp.S b/src/setjmp/impl/mips64/setjmp.S new file mode 100644 index 0000000000..b9646c2abe --- /dev/null +++ b/src/setjmp/impl/mips64/setjmp.S @@ -0,0 +1,34 @@ +.set noreorder +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +__setjmp: +_setjmp: +setjmp: + sd $ra, 0($4) + sd $sp, 8($4) + sd $gp, 16($4) + sd $16, 24($4) + sd $17, 32($4) + sd $18, 40($4) + sd $19, 48($4) + sd $20, 56($4) + sd $21, 64($4) + sd $22, 72($4) + sd $23, 80($4) + sd $30, 88($4) +#ifndef __mips_soft_float + sdc1 $24, 96($4) + sdc1 $25, 104($4) + sdc1 $26, 112($4) + sdc1 $27, 120($4) + sdc1 $28, 128($4) + sdc1 $29, 136($4) + sdc1 $30, 144($4) + sdc1 $31, 152($4) +#endif + jr $ra + li $2, 0 diff --git a/src/setjmp/impl/mipsn32/longjmp.S b/src/setjmp/impl/mipsn32/longjmp.S new file mode 100644 index 0000000000..30c3ee0b0c --- /dev/null +++ b/src/setjmp/impl/mipsn32/longjmp.S @@ -0,0 +1,36 @@ +.set noreorder +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + move $2, $5 + bne $2, $0, 1f + nop + addu $2, $2, 1 +1: +#ifndef __mips_soft_float + ldc1 $24, 96($4) + ldc1 $25, 104($4) + ldc1 $26, 112($4) + ldc1 $27, 120($4) + ldc1 $28, 128($4) + ldc1 $29, 136($4) + ldc1 $30, 144($4) + ldc1 $31, 152($4) +#endif + ld $ra, 0($4) + ld $sp, 8($4) + ld $gp, 16($4) + ld $16, 24($4) + ld $17, 32($4) + ld $18, 40($4) + ld $19, 48($4) + ld $20, 56($4) + ld $21, 64($4) + ld $22, 72($4) + ld $23, 80($4) + ld $30, 88($4) + jr $ra + nop diff --git a/src/setjmp/impl/mipsn32/setjmp.S b/src/setjmp/impl/mipsn32/setjmp.S new file mode 100644 index 0000000000..b9646c2abe --- /dev/null +++ b/src/setjmp/impl/mipsn32/setjmp.S @@ -0,0 +1,34 @@ +.set noreorder +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +__setjmp: +_setjmp: +setjmp: + sd $ra, 0($4) + sd $sp, 8($4) + sd $gp, 16($4) + sd $16, 24($4) + sd $17, 32($4) + sd $18, 40($4) + sd $19, 48($4) + sd $20, 56($4) + sd $21, 64($4) + sd $22, 72($4) + sd $23, 80($4) + sd $30, 88($4) +#ifndef __mips_soft_float + sdc1 $24, 96($4) + sdc1 $25, 104($4) + sdc1 $26, 112($4) + sdc1 $27, 120($4) + sdc1 $28, 128($4) + sdc1 $29, 136($4) + sdc1 $30, 144($4) + sdc1 $31, 152($4) +#endif + jr $ra + li $2, 0 diff --git a/src/setjmp/impl/or1k/longjmp.s b/src/setjmp/impl/or1k/longjmp.s new file mode 100644 index 0000000000..1db9fd9339 --- /dev/null +++ b/src/setjmp/impl/or1k/longjmp.s @@ -0,0 +1,25 @@ +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + l.sfeqi r4, 0 + l.bnf 1f + l.addi r11, r4,0 + l.ori r11, r0, 1 +1: l.lwz r1, 0(r3) + l.lwz r2, 4(r3) + l.lwz r9, 8(r3) + l.lwz r10, 12(r3) + l.lwz r14, 16(r3) + l.lwz r16, 20(r3) + l.lwz r18, 24(r3) + l.lwz r20, 28(r3) + l.lwz r22, 32(r3) + l.lwz r24, 36(r3) + l.lwz r26, 40(r3) + l.lwz r28, 44(r3) + l.lwz r30, 48(r3) + l.jr r9 + l.nop diff --git a/src/setjmp/impl/or1k/setjmp.s b/src/setjmp/impl/or1k/setjmp.s new file mode 100644 index 0000000000..0677033843 --- /dev/null +++ b/src/setjmp/impl/or1k/setjmp.s @@ -0,0 +1,27 @@ +.global ___setjmp +.hidden ___setjmp +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +___setjmp: +__setjmp: +_setjmp: +setjmp: + l.sw 0(r3), r1 + l.sw 4(r3), r2 + l.sw 8(r3), r9 + l.sw 12(r3), r10 + l.sw 16(r3), r14 + l.sw 20(r3), r16 + l.sw 24(r3), r18 + l.sw 28(r3), r20 + l.sw 32(r3), r22 + l.sw 36(r3), r24 + l.sw 40(r3), r26 + l.sw 44(r3), r28 + l.sw 48(r3), r30 + l.jr r9 + l.ori r11,r0,0 diff --git a/src/setjmp/impl/powerpc/longjmp.S b/src/setjmp/impl/powerpc/longjmp.S new file mode 100644 index 0000000000..e598bd056e --- /dev/null +++ b/src/setjmp/impl/powerpc/longjmp.S @@ -0,0 +1,69 @@ + .global _longjmp + .global longjmp + .type _longjmp,@function + .type longjmp,@function +_longjmp: +longjmp: + /* + * void longjmp(jmp_buf env, int val); + * put val into return register and restore the env saved in setjmp + * if val(r4) is 0, put 1 there. + */ + /* 0) move old return address into r0 */ + lwz 0, 0(3) + /* 1) put it into link reg */ + mtlr 0 + /* 2 ) restore stack ptr */ + lwz 1, 4(3) + /* 3) restore control reg */ + lwz 0, 8(3) + mtcr 0 + /* 4) restore r14-r31 */ + lwz 14, 12(3) + lwz 15, 16(3) + lwz 16, 20(3) + lwz 17, 24(3) + lwz 18, 28(3) + lwz 19, 32(3) + lwz 20, 36(3) + lwz 21, 40(3) + lwz 22, 44(3) + lwz 23, 48(3) + lwz 24, 52(3) + lwz 25, 56(3) + lwz 26, 60(3) + lwz 27, 64(3) + lwz 28, 68(3) + lwz 29, 72(3) + lwz 30, 76(3) + lwz 31, 80(3) +#ifndef _SOFT_FLOAT + lfd 14,88(3) + lfd 15,96(3) + lfd 16,104(3) + lfd 17,112(3) + lfd 18,120(3) + lfd 19,128(3) + lfd 20,136(3) + lfd 21,144(3) + lfd 22,152(3) + lfd 23,160(3) + lfd 24,168(3) + lfd 25,176(3) + lfd 26,184(3) + lfd 27,192(3) + lfd 28,200(3) + lfd 29,208(3) + lfd 30,216(3) + lfd 31,224(3) +#endif + /* 5) put val into return reg r3 */ + mr 3, 4 + + /* 6) check if return value is 0, make it 1 in that case */ + cmpwi cr7, 4, 0 + bne cr7, 1f + li 3, 1 +1: + blr + diff --git a/src/setjmp/impl/powerpc/setjmp.S b/src/setjmp/impl/powerpc/setjmp.S new file mode 100644 index 0000000000..cd91a207f5 --- /dev/null +++ b/src/setjmp/impl/powerpc/setjmp.S @@ -0,0 +1,63 @@ + .global ___setjmp + .hidden ___setjmp + .global __setjmp + .global _setjmp + .global setjmp + .type __setjmp,@function + .type _setjmp,@function + .type setjmp,@function +___setjmp: +__setjmp: +_setjmp: +setjmp: + /* 0) store IP int 0, then into the jmpbuf pointed to by r3 (first arg) */ + mflr 0 + stw 0, 0(3) + /* 1) store reg1 (SP) */ + stw 1, 4(3) + /* 2) store cr */ + mfcr 0 + stw 0, 8(3) + /* 3) store r14-31 */ + stw 14, 12(3) + stw 15, 16(3) + stw 16, 20(3) + stw 17, 24(3) + stw 18, 28(3) + stw 19, 32(3) + stw 20, 36(3) + stw 21, 40(3) + stw 22, 44(3) + stw 23, 48(3) + stw 24, 52(3) + stw 25, 56(3) + stw 26, 60(3) + stw 27, 64(3) + stw 28, 68(3) + stw 29, 72(3) + stw 30, 76(3) + stw 31, 80(3) +#ifndef _SOFT_FLOAT + stfd 14,88(3) + stfd 15,96(3) + stfd 16,104(3) + stfd 17,112(3) + stfd 18,120(3) + stfd 19,128(3) + stfd 20,136(3) + stfd 21,144(3) + stfd 22,152(3) + stfd 23,160(3) + stfd 24,168(3) + stfd 25,176(3) + stfd 26,184(3) + stfd 27,192(3) + stfd 28,200(3) + stfd 29,208(3) + stfd 30,216(3) + stfd 31,224(3) +#endif + /* 4) set return value to 0 */ + li 3, 0 + /* 5) return */ + blr diff --git a/src/setjmp/impl/powerpc64/longjmp.s b/src/setjmp/impl/powerpc64/longjmp.s new file mode 100644 index 0000000000..81d45ff60b --- /dev/null +++ b/src/setjmp/impl/powerpc64/longjmp.s @@ -0,0 +1,81 @@ + .global _longjmp + .global longjmp + .type _longjmp,@function + .type longjmp,@function +_longjmp: +longjmp: + # 0) move old return address into the link register + ld 0, 0*8(3) + mtlr 0 + # 1) restore cr + ld 0, 1*8(3) + mtcr 0 + # 2) restore SP + ld 1, 2*8(3) + # 3) restore TOC into both r2 and the caller's stack. + # Which location is required depends on whether setjmp was called + # locally or non-locally, but it's always safe to restore to both. + ld 2, 3*8(3) + std 2, 24(1) + # 4) restore r14-r31 + ld 14, 4*8(3) + ld 15, 5*8(3) + ld 16, 6*8(3) + ld 17, 7*8(3) + ld 18, 8*8(3) + ld 19, 9*8(3) + ld 20, 10*8(3) + ld 21, 11*8(3) + ld 22, 12*8(3) + ld 23, 13*8(3) + ld 24, 14*8(3) + ld 25, 15*8(3) + ld 26, 16*8(3) + ld 27, 17*8(3) + ld 28, 18*8(3) + ld 29, 19*8(3) + ld 30, 20*8(3) + ld 31, 21*8(3) + # 5) restore floating point registers f14-f31 + lfd 14, 22*8(3) + lfd 15, 23*8(3) + lfd 16, 24*8(3) + lfd 17, 25*8(3) + lfd 18, 26*8(3) + lfd 19, 27*8(3) + lfd 20, 28*8(3) + lfd 21, 29*8(3) + lfd 22, 30*8(3) + lfd 23, 31*8(3) + lfd 24, 32*8(3) + lfd 25, 33*8(3) + lfd 26, 34*8(3) + lfd 27, 35*8(3) + lfd 28, 36*8(3) + lfd 29, 37*8(3) + lfd 30, 38*8(3) + lfd 31, 39*8(3) + + # 6) restore vector registers v20-v31 + addi 3, 3, 40*8 + lvx 20, 0, 3 ; addi 3, 3, 16 + lvx 21, 0, 3 ; addi 3, 3, 16 + lvx 22, 0, 3 ; addi 3, 3, 16 + lvx 23, 0, 3 ; addi 3, 3, 16 + lvx 24, 0, 3 ; addi 3, 3, 16 + lvx 25, 0, 3 ; addi 3, 3, 16 + lvx 26, 0, 3 ; addi 3, 3, 16 + lvx 27, 0, 3 ; addi 3, 3, 16 + lvx 28, 0, 3 ; addi 3, 3, 16 + lvx 29, 0, 3 ; addi 3, 3, 16 + lvx 30, 0, 3 ; addi 3, 3, 16 + lvx 31, 0, 3 + + # 7) return r4 ? r4 : 1 + mr 3, 4 + cmpwi cr7, 4, 0 + bne cr7, 1f + li 3, 1 +1: + blr + diff --git a/src/setjmp/impl/powerpc64/setjmp.s b/src/setjmp/impl/powerpc64/setjmp.s new file mode 100644 index 0000000000..37683fdaf4 --- /dev/null +++ b/src/setjmp/impl/powerpc64/setjmp.s @@ -0,0 +1,89 @@ + .global __setjmp + .global _setjmp + .global setjmp + .type __setjmp,@function + .type _setjmp,@function + .type setjmp,@function +__setjmp: +_setjmp: +setjmp: + ld 5, 24(1) # load from the TOC slot in the caller's stack frame + b __setjmp_toc + + .localentry __setjmp,.-__setjmp + .localentry _setjmp,.-_setjmp + .localentry setjmp,.-setjmp + mr 5, 2 + + .global __setjmp_toc + .hidden __setjmp_toc + # same as normal setjmp, except TOC pointer to save is provided in r5. + # r4 would normally be the 2nd parameter, but we're using r5 to simplify calling from sigsetjmp. + # solves the problem of knowing whether to save the TOC pointer from r2 or the caller's stack frame. +__setjmp_toc: + # 0) store IP into 0, then into the jmpbuf pointed to by r3 (first arg) + mflr 0 + std 0, 0*8(3) + # 1) store cr + mfcr 0 + std 0, 1*8(3) + # 2) store SP and TOC + std 1, 2*8(3) + std 5, 3*8(3) + # 3) store r14-31 + std 14, 4*8(3) + std 15, 5*8(3) + std 16, 6*8(3) + std 17, 7*8(3) + std 18, 8*8(3) + std 19, 9*8(3) + std 20, 10*8(3) + std 21, 11*8(3) + std 22, 12*8(3) + std 23, 13*8(3) + std 24, 14*8(3) + std 25, 15*8(3) + std 26, 16*8(3) + std 27, 17*8(3) + std 28, 18*8(3) + std 29, 19*8(3) + std 30, 20*8(3) + std 31, 21*8(3) + # 4) store floating point registers f14-f31 + stfd 14, 22*8(3) + stfd 15, 23*8(3) + stfd 16, 24*8(3) + stfd 17, 25*8(3) + stfd 18, 26*8(3) + stfd 19, 27*8(3) + stfd 20, 28*8(3) + stfd 21, 29*8(3) + stfd 22, 30*8(3) + stfd 23, 31*8(3) + stfd 24, 32*8(3) + stfd 25, 33*8(3) + stfd 26, 34*8(3) + stfd 27, 35*8(3) + stfd 28, 36*8(3) + stfd 29, 37*8(3) + stfd 30, 38*8(3) + stfd 31, 39*8(3) + + # 5) store vector registers v20-v31 + addi 3, 3, 40*8 + stvx 20, 0, 3 ; addi 3, 3, 16 + stvx 21, 0, 3 ; addi 3, 3, 16 + stvx 22, 0, 3 ; addi 3, 3, 16 + stvx 23, 0, 3 ; addi 3, 3, 16 + stvx 24, 0, 3 ; addi 3, 3, 16 + stvx 25, 0, 3 ; addi 3, 3, 16 + stvx 26, 0, 3 ; addi 3, 3, 16 + stvx 27, 0, 3 ; addi 3, 3, 16 + stvx 28, 0, 3 ; addi 3, 3, 16 + stvx 29, 0, 3 ; addi 3, 3, 16 + stvx 30, 0, 3 ; addi 3, 3, 16 + stvx 31, 0, 3 + + # 6) return 0 + li 3, 0 + blr diff --git a/src/setjmp/impl/s390x/longjmp.s b/src/setjmp/impl/s390x/longjmp.s new file mode 100644 index 0000000000..b2310f8ad1 --- /dev/null +++ b/src/setjmp/impl/s390x/longjmp.s @@ -0,0 +1,23 @@ + .global _longjmp + .global longjmp + .type _longjmp,@function + .type longjmp,@function +_longjmp: +longjmp: + +1: + lmg %r6, %r15, 0(%r2) + + ld %f8, 10*8(%r2) + ld %f9, 11*8(%r2) + ld %f10, 12*8(%r2) + ld %f11, 13*8(%r2) + ld %f12, 14*8(%r2) + ld %f13, 15*8(%r2) + ld %f14, 16*8(%r2) + ld %f15, 17*8(%r2) + + ltgr %r2, %r3 + bnzr %r14 + lhi %r2, 1 + br %r14 diff --git a/src/setjmp/impl/s390x/setjmp.s b/src/setjmp/impl/s390x/setjmp.s new file mode 100644 index 0000000000..afae1b6755 --- /dev/null +++ b/src/setjmp/impl/s390x/setjmp.s @@ -0,0 +1,25 @@ + .global ___setjmp + .hidden ___setjmp + .global __setjmp + .global _setjmp + .global setjmp + .type __setjmp,@function + .type _setjmp,@function + .type setjmp,@function +___setjmp: +__setjmp: +_setjmp: +setjmp: + stmg %r6, %r15, 0(%r2) + + std %f8, 10*8(%r2) + std %f9, 11*8(%r2) + std %f10, 12*8(%r2) + std %f11, 13*8(%r2) + std %f12, 14*8(%r2) + std %f13, 15*8(%r2) + std %f14, 16*8(%r2) + std %f15, 17*8(%r2) + + lghi %r2, 0 + br %r14 diff --git a/src/setjmp/impl/sh/longjmp.S b/src/setjmp/impl/sh/longjmp.S new file mode 100644 index 0000000000..08f668b880 --- /dev/null +++ b/src/setjmp/impl/sh/longjmp.S @@ -0,0 +1,28 @@ +.global _longjmp +.global longjmp +.type _longjmp, @function +.type longjmp, @function +_longjmp: +longjmp: + mov.l @r4+, r8 + mov.l @r4+, r9 + mov.l @r4+, r10 + mov.l @r4+, r11 + mov.l @r4+, r12 + mov.l @r4+, r13 + mov.l @r4+, r14 + mov.l @r4+, r15 + lds.l @r4+, pr +#if __SH_FPU_ANY__ || __SH4__ + fmov.s @r4+, fr12 + fmov.s @r4+, fr13 + fmov.s @r4+, fr14 + fmov.s @r4+, fr15 +#endif + + tst r5, r5 + movt r0 + add r5, r0 + + rts + nop diff --git a/src/setjmp/impl/sh/setjmp.S b/src/setjmp/impl/sh/setjmp.S new file mode 100644 index 0000000000..d476e6395f --- /dev/null +++ b/src/setjmp/impl/sh/setjmp.S @@ -0,0 +1,32 @@ +.global ___setjmp +.hidden ___setjmp +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp, @function +.type _setjmp, @function +.type setjmp, @function +___setjmp: +__setjmp: +_setjmp: +setjmp: +#if __SH_FPU_ANY__ || __SH4__ + add #52, r4 + fmov.s fr15, @-r4 + fmov.s fr14, @-r4 + fmov.s fr13, @-r4 + fmov.s fr12, @-r4 +#else + add #36, r4 +#endif + sts.l pr, @-r4 + mov.l r15, @-r4 + mov.l r14, @-r4 + mov.l r13, @-r4 + mov.l r12, @-r4 + mov.l r11, @-r4 + mov.l r10, @-r4 + mov.l r9, @-r4 + mov.l r8, @-r4 + rts + mov #0, r0 diff --git a/src/setjmp/impl/x32/longjmp.s b/src/setjmp/impl/x32/longjmp.s new file mode 100644 index 0000000000..e175a4b960 --- /dev/null +++ b/src/setjmp/impl/x32/longjmp.s @@ -0,0 +1,22 @@ +/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + mov %rsi,%rax /* val will be longjmp return */ + test %rax,%rax + jnz 1f + inc %rax /* if val==0, val=1 per longjmp semantics */ +1: + mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */ + mov 8(%rdi),%rbp + mov 16(%rdi),%r12 + mov 24(%rdi),%r13 + mov 32(%rdi),%r14 + mov 40(%rdi),%r15 + mov 48(%rdi),%rdx /* this ends up being the stack pointer */ + mov %rdx,%rsp + mov 56(%rdi),%rdx /* this is the instruction pointer */ + jmp *%rdx /* goto saved address without altering rsp */ diff --git a/src/setjmp/impl/x32/setjmp.s b/src/setjmp/impl/x32/setjmp.s new file mode 100644 index 0000000000..98f58b8d65 --- /dev/null +++ b/src/setjmp/impl/x32/setjmp.s @@ -0,0 +1,22 @@ +/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +__setjmp: +_setjmp: +setjmp: + mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */ + mov %rbp,8(%rdi) + mov %r12,16(%rdi) + mov %r13,24(%rdi) + mov %r14,32(%rdi) + mov %r15,40(%rdi) + lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */ + mov %rdx,48(%rdi) + mov (%rsp),%rdx /* save return addr ptr for new rip */ + mov %rdx,56(%rdi) + xor %rax,%rax /* always return 0 */ + ret diff --git a/src/setjmp/impl/x86_64/longjmp.s b/src/setjmp/impl/x86_64/longjmp.s new file mode 100644 index 0000000000..e175a4b960 --- /dev/null +++ b/src/setjmp/impl/x86_64/longjmp.s @@ -0,0 +1,22 @@ +/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ +.global _longjmp +.global longjmp +.type _longjmp,@function +.type longjmp,@function +_longjmp: +longjmp: + mov %rsi,%rax /* val will be longjmp return */ + test %rax,%rax + jnz 1f + inc %rax /* if val==0, val=1 per longjmp semantics */ +1: + mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */ + mov 8(%rdi),%rbp + mov 16(%rdi),%r12 + mov 24(%rdi),%r13 + mov 32(%rdi),%r14 + mov 40(%rdi),%r15 + mov 48(%rdi),%rdx /* this ends up being the stack pointer */ + mov %rdx,%rsp + mov 56(%rdi),%rdx /* this is the instruction pointer */ + jmp *%rdx /* goto saved address without altering rsp */ diff --git a/src/setjmp/impl/x86_64/setjmp.s b/src/setjmp/impl/x86_64/setjmp.s new file mode 100644 index 0000000000..98f58b8d65 --- /dev/null +++ b/src/setjmp/impl/x86_64/setjmp.s @@ -0,0 +1,22 @@ +/* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ +.global __setjmp +.global _setjmp +.global setjmp +.type __setjmp,@function +.type _setjmp,@function +.type setjmp,@function +__setjmp: +_setjmp: +setjmp: + mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */ + mov %rbp,8(%rdi) + mov %r12,16(%rdi) + mov %r13,24(%rdi) + mov %r14,32(%rdi) + mov %r15,40(%rdi) + lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */ + mov %rdx,48(%rdi) + mov (%rsp),%rdx /* save return addr ptr for new rip */ + mov %rdx,56(%rdi) + xor %rax,%rax /* always return 0 */ + ret diff --git a/src/setjmp/src/lib.rs b/src/setjmp/src/lib.rs new file mode 100644 index 0000000000..59d35eac6a --- /dev/null +++ b/src/setjmp/src/lib.rs @@ -0,0 +1,62 @@ +//! setjmp implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/setjmp.h.html + +#![no_std] + +extern crate platform; + +use platform::types::*; + +#[cfg(target_arch = "aarch64")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 22]; +#[cfg(target_arch = "arm")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulonglong; 32]; +#[cfg(target_arch = "i386")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 6]; +#[cfg(target_arch = "m68k")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 39]; +#[cfg(target_arch = "microblaze")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 18]; +#[cfg(target_arch = "mips")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulonglong; 13]; +#[cfg(target_arch = "mips64")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulonglong; 23]; +#[cfg(target_arch = "mipsn32")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulonglong; 23]; +#[cfg(target_arch = "or1k")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 13]; +#[cfg(target_arch = "powerpc")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulonglong; 56]; +#[cfg(target_arch = "powerpc64")] +#[allow(non_camel_case_types)] +type jmp_buf = [u128; 32]; +#[cfg(target_arch = "s390x")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 18]; +#[cfg(target_arch = "sh")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 15]; +#[cfg(target_arch = "x32")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulonglong; 8]; +#[cfg(target_arch = "x86_64")] +#[allow(non_camel_case_types)] +type jmp_buf = [c_ulong; 8]; + +#[link(name = "setjmp", kind = "static")] +extern "C" { + fn setjmp(buf: jmp_buf) -> c_int; +} +#[link(name = "longjmp", kind = "static")] +extern "C" { + fn longjmp(buf: jmp_buf, val: c_int); +} diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index 17788dbdfa..8707ef5429 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -412,10 +412,10 @@ pub extern "C" fn qsort( #[no_mangle] pub unsafe extern "C" fn rand() -> c_int { match RNG { - Some(ref mut rng) => rng.gen_range::(0, RAND_MAX), + Some(ref mut rng) => rng.gen_range(0, RAND_MAX), None => { let mut rng = XorShiftRng::from_seed([1; 16]); - let ret = rng.gen_range::(0, RAND_MAX); + let ret = rng.gen_range(0, RAND_MAX); RNG = Some(rng); ret } diff --git a/tests/.gitignore b/tests/.gitignore index b54e9691b4..37a4bde5c4 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -26,7 +26,7 @@ /rename /scanf /setid -/setid +/setjmp /sleep /sprintf /stdlib/a64l diff --git a/tests/Makefile b/tests/Makefile index f961369c7f..c15213a22a 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -23,6 +23,7 @@ EXPECT_BINS=\ rename \ rmdir \ scanf \ + setjmp \ sleep \ sprintf \ stdio/fwrite \ diff --git a/tests/expected/setjmp.stderr b/tests/expected/setjmp.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/setjmp.stdout b/tests/expected/setjmp.stdout new file mode 100644 index 0000000000..c7e6bcddd8 --- /dev/null +++ b/tests/expected/setjmp.stdout @@ -0,0 +1,2 @@ +jumping... +hi from jump diff --git a/tests/setjmp.c b/tests/setjmp.c new file mode 100644 index 0000000000..c45390bf4a --- /dev/null +++ b/tests/setjmp.c @@ -0,0 +1,12 @@ +#include +#include + +int main() { + jmp_buf buf; + if (setjmp(buf)) { + puts("hi from jump"); + } else { + puts("jumping..."); + longjmp(buf, 0); + } +} From 2283243d951e6d9ca830377130853c79635a5aaf Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sat, 23 Jun 2018 17:36:57 +0200 Subject: [PATCH 05/34] Replace setjmp lib.rs with empty file --- src/setjmp/src/lib.rs | 60 ++----------------------------------------- 1 file changed, 2 insertions(+), 58 deletions(-) diff --git a/src/setjmp/src/lib.rs b/src/setjmp/src/lib.rs index 59d35eac6a..f26f3e5afb 100644 --- a/src/setjmp/src/lib.rs +++ b/src/setjmp/src/lib.rs @@ -2,61 +2,5 @@ #![no_std] -extern crate platform; - -use platform::types::*; - -#[cfg(target_arch = "aarch64")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 22]; -#[cfg(target_arch = "arm")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulonglong; 32]; -#[cfg(target_arch = "i386")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 6]; -#[cfg(target_arch = "m68k")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 39]; -#[cfg(target_arch = "microblaze")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 18]; -#[cfg(target_arch = "mips")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulonglong; 13]; -#[cfg(target_arch = "mips64")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulonglong; 23]; -#[cfg(target_arch = "mipsn32")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulonglong; 23]; -#[cfg(target_arch = "or1k")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 13]; -#[cfg(target_arch = "powerpc")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulonglong; 56]; -#[cfg(target_arch = "powerpc64")] -#[allow(non_camel_case_types)] -type jmp_buf = [u128; 32]; -#[cfg(target_arch = "s390x")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 18]; -#[cfg(target_arch = "sh")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 15]; -#[cfg(target_arch = "x32")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulonglong; 8]; -#[cfg(target_arch = "x86_64")] -#[allow(non_camel_case_types)] -type jmp_buf = [c_ulong; 8]; - -#[link(name = "setjmp", kind = "static")] -extern "C" { - fn setjmp(buf: jmp_buf) -> c_int; -} -#[link(name = "longjmp", kind = "static")] -extern "C" { - fn longjmp(buf: jmp_buf, val: c_int); -} +// EMPTY FILE. +// This project is here because of the build.rs file which will compile musl's existing code for setjmp. From 382c6efb3989baa3414ad60f7e113df8f4128df2 Mon Sep 17 00:00:00 2001 From: SamwiseFilmore Date: Sun, 24 Jun 2018 00:48:54 +0000 Subject: [PATCH 06/34] Add Gitlab CI --- .gitlab-ci.yml | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 .gitlab-ci.yml diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml new file mode 100644 index 0000000000..4fc1505dae --- /dev/null +++ b/.gitlab-ci.yml @@ -0,0 +1,26 @@ +image: "rust:latest" + +before_script: + - + - rustup toolchain add nightly + - rustup target add x86_64-unknown-redox --toolchain nightly + - rustup show # Print version info for debugging + +build:linux: + script: + - make all + +#build:redox: +# script: +# - make all + +test:linux: + script: + - make test + +fmt: + script: + - ./fmt.sh -- --write-mode=diff + +# TODO: Set up a docker image with a redox vm that would allow to +# run things like tests under redox \ No newline at end of file From 59f1b37be86db8b69af93a5fa12c597c60bb80cb Mon Sep 17 00:00:00 2001 From: SamwiseFilmore Date: Sun, 24 Jun 2018 00:51:37 +0000 Subject: [PATCH 07/34] Fix dumb mistake --- .gitlab-ci.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 4fc1505dae..ad1d6b1742 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,7 +1,6 @@ image: "rust:latest" before_script: - - - rustup toolchain add nightly - rustup target add x86_64-unknown-redox --toolchain nightly - rustup show # Print version info for debugging From 3e67314b97be62a21b3589244183a4f702cbd4e0 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sun, 24 Jun 2018 14:12:24 +0200 Subject: [PATCH 08/34] Fix openlibm & fenv and add more integer types --- Makefile | 4 +--- include/bits/stdio.h | 1 + include/math.h | 1 + include/stdint.h | 18 ++++++++++++++++++ 4 files changed, 21 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 7f647342d3..451a5a6614 100644 --- a/Makefile +++ b/Makefile @@ -36,11 +36,9 @@ install: all mkdir -pv "$(DESTDIR)/include" cp -rv "include"/* "$(DESTDIR)/include" cp -rv "target/include"/* "$(DESTDIR)/include" - cp -rv "target/openlibm/include"/* "$(DESTDIR)/include" - cp -rv "target/openlibm/src"/*.h "$(DESTDIR)/include" cp -v "$(BUILD)/debug/libc.a" "$(DESTDIR)/lib" cp -v "$(BUILD)/debug/crt0.o" "$(DESTDIR)/lib" - cp -v "$(BUILD)/openlibm/libopenlibm.a" "$(DESTDIR)/lib/libm.a" + $(MAKE) -C openlibm install libc: $(BUILD)/debug/libc.a $(BUILD)/debug/crt0.o diff --git a/include/bits/stdio.h b/include/bits/stdio.h index 506ff549e3..a4e2578d5d 100644 --- a/include/bits/stdio.h +++ b/include/bits/stdio.h @@ -2,6 +2,7 @@ #define _BITS_STDIO_H #define EOF (-1) +#define BUFSIZ 1024 #define stdin __stdin() #define stdout __stdout() #define stderr __stderr() diff --git a/include/math.h b/include/math.h index a228a4fafa..5ce9f25af7 100644 --- a/include/math.h +++ b/include/math.h @@ -1 +1,2 @@ +#define OPENLIBM_USE_HOST_FENV_H 1 #include diff --git a/include/stdint.h b/include/stdint.h index b02e58916b..a68af25e36 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -5,41 +5,57 @@ #define INT8_MIN -0x80 #define INT8_MAX 0x7F typedef signed char int8_t; +typedef signed char int_least8_t; +typedef signed char int_fast8_t; #define UINT8_C(value) ((uint8_t) value ## U) #define UINT8_MIN 0x00 #define UINT8_MAX 0xFF typedef unsigned char uint8_t; +typedef unsigned char uint_least8_t; +typedef unsigned char uint_fast8_t; #define INT16_C(value) value #define INT16_MIN -0x8000 #define INT16_MAX 0x7FFF typedef signed short int16_t; +typedef signed short int_least16_t; +typedef signed short int_fast16_t; #define UINT16_C(value) value ## U #define UINT16_MIN 0x0000 #define UINT16_MAX 0xFFFF typedef unsigned short uint16_t; +typedef unsigned short uint_least16_t; +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 long int_least32_t; +typedef signed long int_fast32_t; #define UINT32_C(value) value ## UL #define UINT32_MIN 0x00000000 #define UINT32_MAX 0xFFFFFFFF typedef unsigned long uint32_t; +typedef unsigned long uint_least32_t; +typedef unsigned long 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 long int_least64_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 long uint64_t; +typedef unsigned long long uint_least64_t; +typedef unsigned long long uint_fast64_t; #define INTMAX_C(value) value ## LL #define INTMAX_MIN INT64_MIN @@ -61,4 +77,6 @@ typedef uint64_t uintptr_t; #define SIZE_MAX UINT64_MAX +typedef int sig_atomic_t; + #endif /* _STDINT_H */ From 72e952582887a8b7a76b4be82ff8c724e4648b73 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sun, 24 Jun 2018 14:24:24 +0200 Subject: [PATCH 09/34] Add U?INT([0-9]+)_LEAST([0-9]+)_MIN/MAX macros --- include/stdint.h | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/include/stdint.h b/include/stdint.h index a68af25e36..8b787427af 100644 --- a/include/stdint.h +++ b/include/stdint.h @@ -5,56 +5,104 @@ #define INT8_MIN -0x80 #define INT8_MAX 0x7F typedef signed char int8_t; + +#define INT_LEAST8_MIN -0x80 +#define INT_LEAST8_MAX 0x7F typedef signed char int_least8_t; + +#define INT_FAST8_MIN -0x80 +#define INT_FAST8_MAX 0x7F typedef signed char int_fast8_t; #define UINT8_C(value) ((uint8_t) value ## U) #define UINT8_MIN 0x00 #define UINT8_MAX 0xFF typedef unsigned char uint8_t; + +#define UINT_LEAST8_MIN 0x00 +#define UINT_LEAST8_MAX 0xFF typedef unsigned char uint_least8_t; + +#define UINT_FAST8_MIN 0x00 +#define UINT_FAST8_MAX 0xFF typedef unsigned char uint_fast8_t; #define INT16_C(value) value #define INT16_MIN -0x8000 #define INT16_MAX 0x7FFF typedef signed short int16_t; + +#define INT_LEAST16_MIN -0x8000 +#define INT_LEAST16_MAX 0x7FFF typedef signed short int_least16_t; + +#define INT_FAST16_MIN -0x8000 +#define INT_FAST16_MAX 0x7FFF typedef signed short int_fast16_t; #define UINT16_C(value) value ## U #define UINT16_MIN 0x0000 #define UINT16_MAX 0xFFFF typedef unsigned short uint16_t; + +#define UINT_LEAST16_MIN 0x0000 +#define UINT_LEAST16_MAX 0xFFFF typedef unsigned short uint_least16_t; + +#define UINT_FAST16_MIN 0x0000 +#define UINT_FAST16_MAX 0xFFFF 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; + +#define INT_LEAST32_MIN -0x80000000 +#define INT_LEAST32_MAX 0x7FFFFFFF typedef signed long int_least32_t; + +#define INT_FAST32_MIN -0x80000000 +#define INT_FAST32_MAX 0x7FFFFFFF typedef signed long int_fast32_t; #define UINT32_C(value) value ## UL #define UINT32_MIN 0x00000000 #define UINT32_MAX 0xFFFFFFFF typedef unsigned long uint32_t; + +#define UINT_LEAST32_MIN 0x00000000 +#define UINT_LEAST32_MAX 0xFFFFFFFF typedef unsigned long uint_least32_t; + +#define UINT_FAST32_MIN 0x00000000 +#define UINT_FAST32_MAX 0xFFFFFFFF typedef unsigned long uint_fast32_t; #define INT64_C(value) value ## LL #define INT64_MIN -0x8000000000000000 #define INT64_MAX 0x7FFFFFFFFFFFFFFF typedef signed long long int64_t; + +#define INT_LEAST64_MIN -0x8000000000000000 +#define INT_LEAST64_MAX 0x7FFFFFFFFFFFFFFF typedef signed long long int_least64_t; + +#define INT_FAST64_MIN -0x8000000000000000 +#define INT_FAST64_MAX 0x7FFFFFFFFFFFFFFF typedef signed long long int_fast64_t; #define UINT64_C(value) value ## ULL #define UINT64_MIN 0x0000000000000000 #define UINT64_MAX 0xFFFFFFFFFFFFFFFF typedef unsigned long long uint64_t; + +#define UINT_LEAST64_MIN 0x0000000000000000 +#define UINT_LEAST64_MAX 0xFFFFFFFFFFFFFFFF typedef unsigned long long uint_least64_t; + +#define UINT_FAST64_MIN 0x0000000000000000 +#define UINT_FAST64_MAX 0xFFFFFFFFFFFFFFFF typedef unsigned long long uint_fast64_t; #define INTMAX_C(value) value ## LL From 878f466b676cbe1652bbf745139fcc9d2df4d6ed Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 24 Jun 2018 09:50:15 -0600 Subject: [PATCH 10/34] Update to new ralloc, new panic implementation, new compiler-builtins --- Cargo.lock | 135 +++++++++++++++++++---------------------- Cargo.toml | 8 ++- Makefile | 4 +- ralloc | 2 +- rust-toolchain | 2 +- src/crt0/src/lib.rs | 14 +++-- src/fenv/cbindgen.toml | 2 +- src/lib.rs | 19 +++--- 8 files changed, 93 insertions(+), 93 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 61a8787b95..62797b88a5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,22 +3,22 @@ name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "atty" -version = "0.2.8" +version = "0.2.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" -version = "1.0.1" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -27,22 +27,22 @@ version = "0.5.2" dependencies = [ "clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", "standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cc" -version = "1.0.9" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -51,18 +51,18 @@ version = "2.31.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "compiler_builtins" version = "0.1.0" -source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#2a2f6d96c8dc578d2474742f14c9bab0b36b0408" +source = "git+https://github.com/rust-lang-nursery/compiler-builtins.git#6eb8f8d710c5d77b0914bec56f68336ad3f06aac" [[package]] name = "crt0" @@ -122,7 +122,7 @@ name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -155,7 +155,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.40" +version = "0.2.42" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -171,15 +171,15 @@ name = "log" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "log" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -189,16 +189,11 @@ dependencies = [ "in_h 0.1.0", ] -[[package]] -name = "num-traits" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "platform" version = "0.1.0" dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -227,7 +222,7 @@ dependencies = [ name = "ralloc_shim" version = "0.1.1" dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -237,26 +232,26 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand" -version = "0.5.0-pre.0" -source = "git+https://github.com/rust-lang-nursery/rand/#1960f833c0ca54c75badd11c5af397c677f92584" +version = "0.5.2" +source = "git+https://github.com/rust-lang-nursery/rand/#af1303c8bde43fa478242adce607ce705ee766e0" dependencies = [ - "rand_core 0.1.0-pre.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.1 (git+https://github.com/rust-lang-nursery/rand/)", ] [[package]] name = "rand_core" -version = "0.1.0-pre.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.2.1" +source = "git+https://github.com/rust-lang-nursery/rand/#af1303c8bde43fa478242adce607ce705ee766e0" [[package]] name = "redox_syscall" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -264,14 +259,14 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "relibc" version = "0.1.0" dependencies = [ - "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", "compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)", "ctype 0.1.0", "errno 0.1.0", @@ -301,10 +296,10 @@ dependencies = [ [[package]] name = "remove_dir_all" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -322,7 +317,7 @@ dependencies = [ [[package]] name = "serde" -version = "1.0.36" +version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -349,13 +344,12 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.13" +version = "1.0.21" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -414,7 +408,7 @@ dependencies = [ "errno 0.1.0", "platform 0.1.0", "ralloc 1.0.0", - "rand 0.5.0-pre.0 (git+https://github.com/rust-lang-nursery/rand/)", + "rand 0.5.2 (git+https://github.com/rust-lang-nursery/rand/)", ] [[package]] @@ -506,7 +500,7 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "remove_dir_all 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -514,8 +508,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -524,7 +518,7 @@ name = "textwrap" version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -538,10 +532,10 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.5" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -551,7 +545,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-width" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -585,12 +579,12 @@ dependencies = [ name = "va_list-helper" version = "0.0.2" dependencies = [ - "cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "vec_map" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -603,7 +597,7 @@ dependencies = [ [[package]] name = "winapi" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -622,33 +616,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" -"checksum atty 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "af80143d6f7608d746df1520709e5d141c96f240b0e62b0aa41bdfb53374d9d4" -"checksum bitflags 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b3c30d3802dfb7281680d6285f2ccdaa8c2d8fee41f93805dba5c4cf50dc23cf" -"checksum cc 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)" = "2b4911e4bdcb4100c7680e7e854ff38e23f1b34d4d9e079efae3da2801341ffc" -"checksum cfg-if 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" +"checksum atty 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2fc4a1aa4c24c0718a250f0681885c1af91419d242f29eb8f2ab28502d80dbd1" +"checksum bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c54bb8f454c567f21197eefcdbf5679d0bd99f2ddbe52e84c77061952e6789" +"checksum cc 1.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "49ec142f5768efb5b7622aebc3fdbdbb8950a4b9ba996393cb76ef7466e8747d" +"checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum clap 2.31.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f0f16b89cbb9ee36d87483dc939fe9f1e13c05898d56d7b230a0d4dff033a536" "checksum compiler_builtins 0.1.0 (git+https://github.com/rust-lang-nursery/compiler-builtins.git)" = "" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum itoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c069bbec61e1ca5a596166e55dfe4773ff745c3d16b700013bcaff9a6df2c682" -"checksum libc 0.2.40 (registry+https://github.com/rust-lang/crates.io-index)" = "6fd41f331ac7c5b8ac259b8bf82c75c0fb2e469bbf37d2becbba9a6a2221965b" +"checksum libc 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "b685088df2b950fccadf07a7187c8ef846a959c142338a48f9dc0b94517eb5f1" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" -"checksum log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "89f010e843f2b1a31dbd316b3b8d443758bc634bed37aabade59c686d644e0a2" -"checksum num-traits 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dee092fcdf725aee04dd7da1d21debff559237d49ef1cb3e69bcb8ece44c7364" +"checksum log 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6fddaa003a65722a7fb9e26b0ce95921fe4ba590542ced664d8ce2fa26f9f3ac" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" -"checksum rand 0.5.0-pre.0 (git+https://github.com/rust-lang-nursery/rand/)" = "" -"checksum rand_core 0.1.0-pre.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2362a41734390a5953cfbf12dbb74b4573137f7ba9dad344bba804ea4355f23a" -"checksum redox_syscall 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "0d92eecebad22b767915e4d529f89f28ee96dbbf5a4810d2b844373f136417fd" +"checksum rand 0.5.2 (git+https://github.com/rust-lang-nursery/rand/)" = "" +"checksum rand_core 0.2.1 (git+https://github.com/rust-lang-nursery/rand/)" = "" +"checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum remove_dir_all 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dfc5b3ce5d5ea144bb04ebd093a9e14e9765bcfec866aecda9b6dec43b3d1e24" +"checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum sc 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4ebbb026ba4a707c25caec2db5ef59ad8b41f7ad77cad06257e06229c891f376" -"checksum serde 1.0.36 (registry+https://github.com/rust-lang/crates.io-index)" = "c70142ae874a42c70e03c63c6a49abe2ea0079b090bf6e136e99252fc1974bd6" +"checksum serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a2d9a9ac5120e0f768801ca2b58ad6eec929dc9d1d616c162f208869c2ce95" "checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788" "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab" -"checksum serde_json 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "5c508584d9913df116b91505eec55610a2f5b16e9ed793c46e4d0152872b3e74" +"checksum serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "eb40600c756f02d7ea34943626cefa85732fdae5f95b90b31f9797b3c526d1e6" "checksum standalone-quote 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcedac1d6d98e7e9d1d6e628f5635af9566688ae5f6cea70a3976f495ae8d839" "checksum standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "115808f5187c07c23cb93eee49d542fae54c6e8285d3a24c6ff683fcde9243db" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" @@ -657,12 +650,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c0b59b6b4b44d867f1370ef1bd91bfb262bf07bf0ae65c202ea2fbc16153b693" -"checksum toml 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7540f4ffc193e0d3c94121edb19b055670d369f77d5804db11ae053a45b6e7e" +"checksum toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a0263c6c02c4db6c8f7681f9fd35e90de799ebd4cfdeab77a38f4ff6b3d8c0d9" "checksum unborrow 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e92e959f029e4f8ee25d70d15ab58d2b46f98a17bc238b9265ff0c26f6f3d67f" -"checksum unicode-width 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3a113775714a22dcb774d8ea3655c53a32debae63a063acc00a91cc586245f" +"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" -"checksum vec_map 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "887b5b631c2ad01628bbbaa7dd4c869f80d3186688f8d0b6f58774fbe324988c" -"checksum winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "04e3bd221fcbe8a271359c04f21a76db7d0c6028862d1bb5512d85e1e2eb5bb3" +"checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" +"checksum winapi 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "773ef9dcc5f24b7d850d0ff101e542ff24c3b090a9768e03ff889fdef41f00fd" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index dd15d54dca..e30486397e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,10 +11,9 @@ crate-type = ["staticlib"] members = ["src/crt0"] [build-dependencies] -cc = "1.0" +cc = "1.0.17" [dependencies] -compiler_builtins = { git = "https://github.com/rust-lang-nursery/compiler-builtins.git", default-features = false } ctype = { path = "src/ctype" } errno = { path = "src/errno" } fcntl = { path = "src/fcntl" } @@ -40,6 +39,11 @@ time = { path = "src/time" } unistd = { path = "src/unistd" } wctype = { path = "src/wctype" } +[dependencies.compiler_builtins] +git = "https://github.com/rust-lang-nursery/compiler-builtins.git" +default-features = false +features = ["no-lang-items"] + [profile.dev] panic = "abort" diff --git a/Makefile b/Makefile index 451a5a6614..ff95acbc30 100644 --- a/Makefile +++ b/Makefile @@ -52,7 +52,7 @@ $(BUILD)/debug/libc.a: $(SRC) touch $@ $(BUILD)/debug/crt0.o: $(SRC) - cargo rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ + CARGO_INCREMENTAL=0 cargo --verbose --verbose rustc --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ touch $@ $(BUILD)/release/libc.a: $(SRC) @@ -60,7 +60,7 @@ $(BUILD)/release/libc.a: $(SRC) touch $@ $(BUILD)/release/crt0.o: $(SRC) - cargo rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ + CARGO_INCREMENTAL=0 cargo rustc --release --manifest-path src/crt0/Cargo.toml $(CARGOFLAGS) -- --emit obj=$@ touch $@ $(BUILD)/openlibm: openlibm diff --git a/ralloc b/ralloc index 2d8d44970e..311db75868 160000 --- a/ralloc +++ b/ralloc @@ -1 +1 @@ -Subproject commit 2d8d44970eb5bb2ecc55f5ced8a33f21ed9407f4 +Subproject commit 311db75868ff73089a3ab46258ce8cdb2d1670f9 diff --git a/rust-toolchain b/rust-toolchain index 1bcdc35a09..a47068b222 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2018-03-04 +nightly-2018-06-19 diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index 5139eb27df..a2a90ecc69 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -2,8 +2,8 @@ #![no_std] #![feature(asm)] -#![feature(lang_items)] #![feature(naked_functions)] +#![feature(panic_implementation)] extern crate platform; @@ -59,7 +59,13 @@ pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! { platform::exit(main(argc, argv)); } -#[lang = "panic_fmt"] -pub extern "C" fn rust_begin_unwind(_fmt: ::core::fmt::Arguments, _file: &str, _line: u32) -> ! { - loop {} +#[panic_implementation] +#[no_mangle] +pub extern "C" fn _start_panic(pi: &::core::panic::PanicInfo) -> ! { + use core::fmt::Write; + + let mut w = platform::FileWriter(2); + let _ = w.write_fmt(format_args!("RELIBC CRT0 PANIC: {}\n", pi)); + + platform::exit(1); } diff --git a/src/fenv/cbindgen.toml b/src/fenv/cbindgen.toml index 4d3d6737c2..c369f03b34 100644 --- a/src/fenv/cbindgen.toml +++ b/src/fenv/cbindgen.toml @@ -1,4 +1,4 @@ -sys_includes = ["sys/types.h"] +sys_includes = ["stdint.h", "sys/types.h"] include_guard = "_FENV_H" language = "C" diff --git a/src/lib.rs b/src/lib.rs index 3ea9b7d7bd..496b1e7677 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,7 +1,8 @@ #![no_std] #![feature(lang_items)] +#![feature(panic_implementation)] -extern crate compiler_builtins; +//extern crate compiler_builtins; extern crate platform; pub extern crate ctype; @@ -27,28 +28,24 @@ pub extern crate time; pub extern crate unistd; pub extern crate wctype; -#[lang = "eh_personality"] +#[panic_implementation] #[no_mangle] -pub extern "C" fn rust_eh_personality() {} - -#[lang = "panic_fmt"] -#[no_mangle] -pub extern "C" fn rust_begin_unwind(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> ! { +pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! { use core::fmt::Write; let mut w = platform::FileWriter(2); - let _ = w.write_fmt(format_args!("{}:{}: {}\n", file, line, fmt)); + let _ = w.write_fmt(format_args!("RELIBC PANIC: {}\n", pi)); platform::exit(1); } -#[allow(non_snake_case)] +#[lang = "oom"] #[no_mangle] -pub extern "C" fn _Unwind_Resume() -> ! { +pub extern fn relibc_oom(layout: ::core::alloc::Layout) -> ! { use core::fmt::Write; let mut w = platform::FileWriter(2); - let _ = w.write_str("_Unwind_Resume\n"); + let _ = w.write_fmt(format_args!("RELIBC OOM: {} bytes aligned to {} bytes\n", layout.size(), layout.align())); platform::exit(1); } From f265d7c5bef3637e918e07a7a77bb01827f2cb15 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sun, 24 Jun 2018 09:56:08 -0600 Subject: [PATCH 11/34] Fix linking issues with lang items --- src/crt0/src/lib.rs | 4 +++- src/lib.rs | 30 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/crt0/src/lib.rs b/src/crt0/src/lib.rs index a2a90ecc69..9de7f3c964 100644 --- a/src/crt0/src/lib.rs +++ b/src/crt0/src/lib.rs @@ -2,6 +2,7 @@ #![no_std] #![feature(asm)] +#![feature(linkage)] #![feature(naked_functions)] #![feature(panic_implementation)] @@ -60,8 +61,9 @@ pub unsafe extern "C" fn _start_rust(sp: &'static Stack) -> ! { } #[panic_implementation] +#[linkage = "weak"] #[no_mangle] -pub extern "C" fn _start_panic(pi: &::core::panic::PanicInfo) -> ! { +pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { use core::fmt::Write; let mut w = platform::FileWriter(2); diff --git a/src/lib.rs b/src/lib.rs index 496b1e7677..db4ed93802 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,5 +1,6 @@ #![no_std] #![feature(lang_items)] +#![feature(linkage)] #![feature(panic_implementation)] //extern crate compiler_builtins; @@ -28,9 +29,11 @@ pub extern crate time; pub extern crate unistd; pub extern crate wctype; +#[cfg(not(test))] #[panic_implementation] +#[linkage = "weak"] #[no_mangle] -pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! { +pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { use core::fmt::Write; let mut w = platform::FileWriter(2); @@ -39,9 +42,17 @@ pub extern "C" fn relibc_panic(pi: &::core::panic::PanicInfo) -> ! { platform::exit(1); } -#[lang = "oom"] +#[cfg(not(test))] +#[lang = "eh_personality"] #[no_mangle] -pub extern fn relibc_oom(layout: ::core::alloc::Layout) -> ! { +#[linkage = "weak"] +pub extern "C" fn rust_eh_personality() {} + +#[cfg(not(test))] +#[lang = "oom"] +#[linkage = "weak"] +#[no_mangle] +pub extern fn rust_oom(layout: ::core::alloc::Layout) -> ! { use core::fmt::Write; let mut w = platform::FileWriter(2); @@ -49,3 +60,16 @@ pub extern fn relibc_oom(layout: ::core::alloc::Layout) -> ! { platform::exit(1); } + +#[cfg(not(test))] +#[allow(non_snake_case)] +#[linkage = "weak"] +#[no_mangle] +pub extern "C" fn _Unwind_Resume() -> ! { + use core::fmt::Write; + + let mut w = platform::FileWriter(2); + let _ = w.write_str("_Unwind_Resume\n"); + + platform::exit(1); +} From 320eb0ecd095642f1700d11b21c07df1d1c0983c Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Sun, 24 Jun 2018 20:19:06 +0200 Subject: [PATCH 12/34] Revert openlibm install script Turns out that this only worked because I didn't clean before rebuilding, so it still had access to the old files. Sorry. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index ff95acbc30..319784926b 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,8 @@ install: all cp -rv "target/include"/* "$(DESTDIR)/include" cp -v "$(BUILD)/debug/libc.a" "$(DESTDIR)/lib" cp -v "$(BUILD)/debug/crt0.o" "$(DESTDIR)/lib" - $(MAKE) -C openlibm install + cp -rv "openlibm/include"/* "$(DESTDIR)/include" + cp -rv "openlibm/src"/*.h "$(DESTDIR)/include" libc: $(BUILD)/debug/libc.a $(BUILD)/debug/crt0.o From 441bf9f00b67a5c82ddb2e33d77a8961a2279a69 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Mon, 25 Jun 2018 11:43:44 +0200 Subject: [PATCH 13/34] 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 14/34] 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 15/34] 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 16/34] 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 17/34] 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 18/34] 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 19/34] 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 20/34] 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 21/34] 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 22/34] 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 23/34] 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 24/34] 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 25/34] 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" From 776491bae9eea753048de950cc0faac37cae31d7 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Wed, 27 Jun 2018 20:22:12 +0000 Subject: [PATCH 26/34] implement mktemp --- Cargo.lock | 19 +++++++------ src/stdlib/Cargo.toml | 3 +- src/stdlib/src/lib.rs | 59 +++++++++++++++++++++++++++++++++++++-- src/time/src/constants.rs | 2 +- tests/Makefile | 1 + tests/stdlib/mktemp.c | 12 ++++++++ 6 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 tests/stdlib/mktemp.c diff --git a/Cargo.lock b/Cargo.lock index 62797b88a5..fb3583a23b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -29,7 +29,7 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)", "standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -239,15 +239,15 @@ dependencies = [ [[package]] name = "rand" version = "0.5.2" -source = "git+https://github.com/rust-lang-nursery/rand/#af1303c8bde43fa478242adce607ce705ee766e0" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.2.1 (git+https://github.com/rust-lang-nursery/rand/)", + "rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rand_core" version = "0.2.1" -source = "git+https://github.com/rust-lang-nursery/rand/#af1303c8bde43fa478242adce607ce705ee766e0" +source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "redox_syscall" @@ -344,7 +344,7 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.21" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -408,7 +408,8 @@ dependencies = [ "errno 0.1.0", "platform 0.1.0", "ralloc 1.0.0", - "rand 0.5.2 (git+https://github.com/rust-lang-nursery/rand/)", + "rand 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.0", ] [[package]] @@ -632,8 +633,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum proc-macro2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cd07deb3c6d1d9ff827999c7f9b04cdfd66b1b17ae508e14fe47b620f2282ae0" "checksum quote 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "7a6e920b65c65f10b2ae65c831a81a073a89edd28c7cce89475bff467ab4167a" "checksum rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eba5f8cb59cc50ed56be8880a5c7b496bfd9bd26394e176bc67884094145c2c5" -"checksum rand 0.5.2 (git+https://github.com/rust-lang-nursery/rand/)" = "" -"checksum rand_core 0.2.1 (git+https://github.com/rust-lang-nursery/rand/)" = "" +"checksum rand 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0d9f869af32e387d9e0f2bdb64326b8ac84c81d5e55459d0bc7526b0fdb3671" +"checksum rand_core 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edecf0f94da5551fc9b492093e30b041a891657db7940ee221f9d2f66e82eef2" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" @@ -641,7 +642,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum serde 1.0.66 (registry+https://github.com/rust-lang/crates.io-index)" = "e9a2d9a9ac5120e0f768801ca2b58ad6eec929dc9d1d616c162f208869c2ce95" "checksum serde_derive 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "652bc323d694dc925829725ec6c890156d8e70ae5202919869cb00fe2eff3788" "checksum serde_derive_internals 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)" = "32f1926285523b2db55df263d2aa4eb69ddcfa7a7eade6430323637866b513ab" -"checksum serde_json 1.0.21 (registry+https://github.com/rust-lang/crates.io-index)" = "eb40600c756f02d7ea34943626cefa85732fdae5f95b90b31f9797b3c526d1e6" +"checksum serde_json 1.0.22 (registry+https://github.com/rust-lang/crates.io-index)" = "84b8035cabe9b35878adec8ac5fe03d5f6bc97ff6edd7ccb96b44c1276ba390e" "checksum standalone-quote 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dcedac1d6d98e7e9d1d6e628f5635af9566688ae5f6cea70a3976f495ae8d839" "checksum standalone-syn 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "115808f5187c07c23cb93eee49d542fae54c6e8285d3a24c6ff683fcde9243db" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" diff --git a/src/stdlib/Cargo.toml b/src/stdlib/Cargo.toml index cc96a5dc07..97ed4e9dfe 100644 --- a/src/stdlib/Cargo.toml +++ b/src/stdlib/Cargo.toml @@ -12,4 +12,5 @@ platform = { path = "../platform" } ralloc = { path = "../../ralloc", default-features = false } ctype = { path = "../ctype" } errno = { path = "../errno" } -rand = { git = "https://github.com/rust-lang-nursery/rand/", default-features = false } +rand = { version = "0.5.2", default-features = false } +time = { path = "../time" } diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index 8707ef5429..0c489d7b71 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -9,9 +9,13 @@ extern crate errno; extern crate platform; extern crate ralloc; extern crate rand; +extern crate time; use core::{ptr, str}; -use rand::{Rng, SeedableRng, XorShiftRng}; +use rand::{Rng, SeedableRng}; +use rand::rngs::JitterRng; +use rand::prng::XorShiftRng; +use rand::distributions::Alphanumeric; use errno::*; use platform::types::*; @@ -364,9 +368,60 @@ pub extern "C" fn mbtowc(pwc: *mut wchar_t, s: *const c_char, n: size_t) -> c_in #[no_mangle] pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { - unimplemented!(); + use core::slice; + use core::iter; + use core::mem; + extern "C" { + fn strlen(s: *const c_char) -> size_t; + } + let len = unsafe { strlen(name) }; + let mut retries = 100; + let name_buf = unsafe { slice::from_raw_parts(name as *const u8, len as usize) }; + let name_str = str::from_utf8(name_buf).unwrap_or(""); + if len < 6 || !name_str.ends_with("XXXXXX") { + unsafe { platform::errno = errno::EINVAL }; + unsafe { *name = 0 }; + return name; + } + + let mut rng = JitterRng::new_with_timer(get_nstime); + rng.test_timer(); + + loop { + let mut char_iter = iter::repeat(()) + .map(|()| rng.sample(Alphanumeric)) + .take(6); + unsafe { + for (i,c) in char_iter.enumerate() { + *name.offset(len as isize-i as isize) = c as c_char + } + } + + unsafe { + let mut st: stat = mem::uninitialized(); + if platform::stat(name, &mut st) != 0 { + if platform::errno != ENOENT { *name = 0; } + return name; + } + mem::forget(st); + } + retries = retries -1; + if retries == 0 { break; } + } + unsafe { platform::errno = EEXIST }; + unsafe { *name = 0 }; + name } +fn get_nstime() -> u64 { + use core::mem; + use time::constants::CLOCK_MONOTONIC; + let mut ts: timespec = unsafe { mem::uninitialized() }; + platform::clock_gettime(CLOCK_MONOTONIC, &mut ts); + unsafe { ts.tv_nsec as u64 } +} + + #[no_mangle] pub extern "C" fn mkstemp(name: *mut c_char) -> c_int { unimplemented!(); diff --git a/src/time/src/constants.rs b/src/time/src/constants.rs index becfaaceb9..5b0e3b1212 100644 --- a/src/time/src/constants.rs +++ b/src/time/src/constants.rs @@ -44,7 +44,7 @@ pub(crate) const MON_NAMES: [&str; 12] = [ ]; pub(crate) const CLOCK_REALTIME: clockid_t = 0; -pub(crate) const CLOCK_MONOTONIC: clockid_t = 1; +pub const CLOCK_MONOTONIC: clockid_t = 1; pub(crate) const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; pub(crate) const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; diff --git a/tests/Makefile b/tests/Makefile index c15213a22a..d49497f723 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -34,6 +34,7 @@ EXPECT_BINS=\ stdlib/strtoul \ stdlib/a64l \ stdlib/rand \ + stdlib/mktemp \ string/strncmp \ string/strcspn \ string/strchr \ diff --git a/tests/stdlib/mktemp.c b/tests/stdlib/mktemp.c new file mode 100644 index 0000000000..eaafe83480 --- /dev/null +++ b/tests/stdlib/mktemp.c @@ -0,0 +1,12 @@ +#include +#include +#include + +int main(int argc, char** argv) { + char* string = (char*) calloc(20, sizeof(char)); + strcpy(string, "tempXXXXXX"); + mktemp(string); + printf("%s\n",string); + free(string); + return 0; +} From 2dbe7ebee0a772441c3f5a329d38b97afd44e92f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 27 Jun 2018 14:33:03 -0600 Subject: [PATCH 27/34] Update ralloc --- ralloc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ralloc b/ralloc index 311db75868..867c809039 160000 --- a/ralloc +++ b/ralloc @@ -1 +1 @@ -Subproject commit 311db75868ff73089a3ab46258ce8cdb2d1670f9 +Subproject commit 867c809039aef77dbce22e98b1009b8995dfa868 From abbf0c9609826f988ff08365aa52625ea1160c8f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 27 Jun 2018 14:33:47 -0600 Subject: [PATCH 28/34] Add mktemp test binary to gitingore --- tests/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/.gitignore b/tests/.gitignore index 37a4bde5c4..ea86d023ee 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -31,6 +31,7 @@ /sprintf /stdlib/a64l /stdlib/bsearch +/stdlib/mktemp /stdlib/rand /stdlib/strtol /stdlib/strtoul From cf6c8093ab1a6292e1ab95c5d13c80dbbb086e2d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 27 Jun 2018 15:06:19 -0600 Subject: [PATCH 29/34] Update expected output --- tests/expected/printf.stdout | 1 + tests/expected/string/strtok.stdout | 3 +-- tests/expected/string/strtok_r.stdout | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/expected/printf.stdout b/tests/expected/printf.stdout index ad30d8fbca..d92e40b8ea 100644 --- a/tests/expected/printf.stdout +++ b/tests/expected/printf.stdout @@ -1,6 +1,7 @@ percent: % string: String char: c +char: þ int: -16 uint: 32 hex: beef diff --git a/tests/expected/string/strtok.stdout b/tests/expected/string/strtok.stdout index 201357e8cb..4428c25c54 100644 --- a/tests/expected/string/strtok.stdout +++ b/tests/expected/string/strtok.stdout @@ -1,2 +1 @@ -I'd_just_like_to_interject_for_a_moment.__What_you're_referring_to_as_Linux, -is_in_fact,_GNU/Linux,_or_as_I've_recently_taken_to_calling_it,_GNU_plus_Linux. +I'd_just_like_to_interject_for_a_moment._What_you're_referring_to_as_Linux,_is_in_fact,_GNU/Linux,_or_as_I've_recently_taken_to_calling_it,_GNU_plus_Linux. diff --git a/tests/expected/string/strtok_r.stdout b/tests/expected/string/strtok_r.stdout index 201357e8cb..4428c25c54 100644 --- a/tests/expected/string/strtok_r.stdout +++ b/tests/expected/string/strtok_r.stdout @@ -1,2 +1 @@ -I'd_just_like_to_interject_for_a_moment.__What_you're_referring_to_as_Linux, -is_in_fact,_GNU/Linux,_or_as_I've_recently_taken_to_calling_it,_GNU_plus_Linux. +I'd_just_like_to_interject_for_a_moment._What_you're_referring_to_as_Linux,_is_in_fact,_GNU/Linux,_or_as_I've_recently_taken_to_calling_it,_GNU_plus_Linux. From 2e3eda4612c967ee1d6345bba5f299f06d851eac Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 27 Jun 2018 15:08:29 -0600 Subject: [PATCH 30/34] Add more expected files --- tests/expected/asctime.stderr | 0 tests/expected/asctime.stdout | 0 tests/expected/getc_unget.stderr | 0 tests/expected/getc_unget.stdout | 1 + tests/expected/getid.stderr | 0 tests/expected/getid.stdout | 1 + tests/expected/gmtime.stderr | 0 tests/expected/gmtime.stdout | 0 tests/expected/link.stderr | 2 +- tests/expected/rename.stderr | 0 tests/expected/rename.stdout | 0 tests/expected/stdio/all.stderr | 0 tests/expected/stdio/all.stdout | 3 +++ tests/expected/stdio/freopen.stderr | 0 tests/expected/stdio/freopen.stdout | 1 + tests/expected/stdio/fwrite.stderr | 0 tests/expected/stdio/fwrite.stdout | 0 tests/expected/stdlib/bsearch.stderr | 0 tests/expected/stdlib/bsearch.stdout | 3 +++ tests/expected/stdlib/mktemp.stderr | 0 tests/expected/stdlib/mktemp.stdout | 1 + tests/expected/stdlib/rand.stderr | 0 tests/expected/stdlib/rand.stdout | 2 ++ tests/expected/stdlib/strtoul.stderr | 0 tests/expected/stdlib/strtoul.stdout | 12 ++++++++++++ tests/expected/time.stderr | 3 +++ tests/expected/time.stdout | 0 tests/expected/unlink.stderr | 2 +- tests/expected/waitpid.stderr | 0 tests/expected/waitpid.stdout | 0 30 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/expected/asctime.stderr create mode 100644 tests/expected/asctime.stdout create mode 100644 tests/expected/getc_unget.stderr create mode 100644 tests/expected/getc_unget.stdout create mode 100644 tests/expected/getid.stderr create mode 100644 tests/expected/getid.stdout create mode 100644 tests/expected/gmtime.stderr create mode 100644 tests/expected/gmtime.stdout create mode 100644 tests/expected/rename.stderr create mode 100644 tests/expected/rename.stdout create mode 100644 tests/expected/stdio/all.stderr create mode 100644 tests/expected/stdio/all.stdout create mode 100644 tests/expected/stdio/freopen.stderr create mode 100644 tests/expected/stdio/freopen.stdout create mode 100644 tests/expected/stdio/fwrite.stderr create mode 100644 tests/expected/stdio/fwrite.stdout create mode 100644 tests/expected/stdlib/bsearch.stderr create mode 100644 tests/expected/stdlib/bsearch.stdout create mode 100644 tests/expected/stdlib/mktemp.stderr create mode 100644 tests/expected/stdlib/mktemp.stdout create mode 100644 tests/expected/stdlib/rand.stderr create mode 100644 tests/expected/stdlib/rand.stdout create mode 100644 tests/expected/stdlib/strtoul.stderr create mode 100644 tests/expected/stdlib/strtoul.stdout create mode 100644 tests/expected/time.stderr create mode 100644 tests/expected/time.stdout create mode 100644 tests/expected/waitpid.stderr create mode 100644 tests/expected/waitpid.stdout diff --git a/tests/expected/asctime.stderr b/tests/expected/asctime.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/asctime.stdout b/tests/expected/asctime.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/getc_unget.stderr b/tests/expected/getc_unget.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/getc_unget.stdout b/tests/expected/getc_unget.stdout new file mode 100644 index 0000000000..f01a3f968d --- /dev/null +++ b/tests/expected/getc_unget.stdout @@ -0,0 +1 @@ +Worked! diff --git a/tests/expected/getid.stderr b/tests/expected/getid.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/getid.stdout b/tests/expected/getid.stdout new file mode 100644 index 0000000000..204c54dfda --- /dev/null +++ b/tests/expected/getid.stdout @@ -0,0 +1 @@ +egid: 1000, euid: 1000, gid: 1000, pgid: 9363, pid: 10165, ppid 10121, uid 1000 diff --git a/tests/expected/gmtime.stderr b/tests/expected/gmtime.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/gmtime.stdout b/tests/expected/gmtime.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/link.stderr b/tests/expected/link.stderr index 77bae796be..5ff5b2138a 100644 --- a/tests/expected/link.stderr +++ b/tests/expected/link.stderr @@ -1 +1 @@ -link: File exists +link: Success diff --git a/tests/expected/rename.stderr b/tests/expected/rename.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/rename.stdout b/tests/expected/rename.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdio/all.stderr b/tests/expected/stdio/all.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdio/all.stdout b/tests/expected/stdio/all.stdout new file mode 100644 index 0000000000..23bfb625a6 --- /dev/null +++ b/tests/expected/stdio/all.stdout @@ -0,0 +1,3 @@ +H +Hello World! + diff --git a/tests/expected/stdio/freopen.stderr b/tests/expected/stdio/freopen.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdio/freopen.stdout b/tests/expected/stdio/freopen.stdout new file mode 100644 index 0000000000..a8f9fd84ee --- /dev/null +++ b/tests/expected/stdio/freopen.stdout @@ -0,0 +1 @@ +Hello diff --git a/tests/expected/stdio/fwrite.stderr b/tests/expected/stdio/fwrite.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdio/fwrite.stdout b/tests/expected/stdio/fwrite.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdlib/bsearch.stderr b/tests/expected/stdlib/bsearch.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdlib/bsearch.stdout b/tests/expected/stdlib/bsearch.stdout new file mode 100644 index 0000000000..f2c934ddda --- /dev/null +++ b/tests/expected/stdlib/bsearch.stdout @@ -0,0 +1,3 @@ +0x7ffd837cb514 +0x7ffd837cb518 +PASS bsearch diff --git a/tests/expected/stdlib/mktemp.stderr b/tests/expected/stdlib/mktemp.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdlib/mktemp.stdout b/tests/expected/stdlib/mktemp.stdout new file mode 100644 index 0000000000..66174ea417 --- /dev/null +++ b/tests/expected/stdlib/mktemp.stdout @@ -0,0 +1 @@ +tempXXsTJ4p diff --git a/tests/expected/stdlib/rand.stderr b/tests/expected/stdlib/rand.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdlib/rand.stdout b/tests/expected/stdlib/rand.stdout new file mode 100644 index 0000000000..86ea6812ed --- /dev/null +++ b/tests/expected/stdlib/rand.stdout @@ -0,0 +1,2 @@ +67141780 +201425341 diff --git a/tests/expected/stdlib/strtoul.stderr b/tests/expected/stdlib/strtoul.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/stdlib/strtoul.stdout b/tests/expected/stdlib/strtoul.stdout new file mode 100644 index 0000000000..6f53efcf01 --- /dev/null +++ b/tests/expected/stdlib/strtoul.stdout @@ -0,0 +1,12 @@ +-42 +555 +1234567890 +-42 +555 +1234567890 +38acf +abcdef12 +731 +731 +0 +0 diff --git a/tests/expected/time.stderr b/tests/expected/time.stderr new file mode 100644 index 0000000000..b19be1d86c --- /dev/null +++ b/tests/expected/time.stderr @@ -0,0 +1,3 @@ +clock_gettime: Success +time: Success +clock: Success diff --git a/tests/expected/time.stdout b/tests/expected/time.stdout new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/unlink.stderr b/tests/expected/unlink.stderr index 19e51d7f67..4d72cf777b 100644 --- a/tests/expected/unlink.stderr +++ b/tests/expected/unlink.stderr @@ -1 +1 @@ -unlink: File exists +unlink: Success diff --git a/tests/expected/waitpid.stderr b/tests/expected/waitpid.stderr new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/expected/waitpid.stdout b/tests/expected/waitpid.stdout new file mode 100644 index 0000000000..e69de29bb2 From e4be43f617d8ade2320f5ec1b3778b060f71d6d5 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 27 Jun 2018 15:12:14 -0600 Subject: [PATCH 31/34] Adjust list of expected binaries --- tests/Makefile | 11 +++++------ tests/expected/getid.stderr | 0 tests/expected/getid.stdout | 1 - tests/expected/link.stderr | 1 - tests/expected/link.stdout | 0 tests/expected/stdlib/bsearch.stderr | 0 tests/expected/stdlib/bsearch.stdout | 3 --- tests/expected/stdlib/mktemp.stderr | 0 tests/expected/stdlib/mktemp.stdout | 1 - tests/expected/unlink.stderr | 1 - tests/expected/unlink.stdout | 0 11 files changed, 5 insertions(+), 13 deletions(-) delete mode 100644 tests/expected/getid.stderr delete mode 100644 tests/expected/getid.stdout delete mode 100644 tests/expected/link.stderr delete mode 100644 tests/expected/link.stdout delete mode 100644 tests/expected/stdlib/bsearch.stderr delete mode 100644 tests/expected/stdlib/bsearch.stdout delete mode 100644 tests/expected/stdlib/mktemp.stderr delete mode 100644 tests/expected/stdlib/mktemp.stdout delete mode 100644 tests/expected/unlink.stderr delete mode 100644 tests/expected/unlink.stdout diff --git a/tests/Makefile b/tests/Makefile index 5c906befb4..dcea342362 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -13,9 +13,7 @@ EXPECT_BINS=\ fcntl \ fsync \ ftruncate \ - getid \ getc_unget \ - link \ locale \ math \ mem \ @@ -30,12 +28,10 @@ EXPECT_BINS=\ stdio/fwrite \ stdio/all \ stdio/freopen \ - stdlib/bsearch \ stdlib/strtol \ stdlib/strtoul \ stdlib/a64l \ stdlib/rand \ - stdlib/mktemp \ string/strncmp \ string/strcspn \ string/strchr \ @@ -46,7 +42,6 @@ EXPECT_BINS=\ string/strtok \ string/strtok_r \ unistd/getopt \ - unlink \ waitpid \ write \ time \ @@ -60,7 +55,11 @@ BINS=\ chdir \ gethostname \ getid \ - setid + link \ + setid \ + stdlib/bsearch \ + stdlib/mktemp \ + unlink all: $(BINS) diff --git a/tests/expected/getid.stderr b/tests/expected/getid.stderr deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/expected/getid.stdout b/tests/expected/getid.stdout deleted file mode 100644 index 204c54dfda..0000000000 --- a/tests/expected/getid.stdout +++ /dev/null @@ -1 +0,0 @@ -egid: 1000, euid: 1000, gid: 1000, pgid: 9363, pid: 10165, ppid 10121, uid 1000 diff --git a/tests/expected/link.stderr b/tests/expected/link.stderr deleted file mode 100644 index 5ff5b2138a..0000000000 --- a/tests/expected/link.stderr +++ /dev/null @@ -1 +0,0 @@ -link: Success diff --git a/tests/expected/link.stdout b/tests/expected/link.stdout deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/expected/stdlib/bsearch.stderr b/tests/expected/stdlib/bsearch.stderr deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/expected/stdlib/bsearch.stdout b/tests/expected/stdlib/bsearch.stdout deleted file mode 100644 index f2c934ddda..0000000000 --- a/tests/expected/stdlib/bsearch.stdout +++ /dev/null @@ -1,3 +0,0 @@ -0x7ffd837cb514 -0x7ffd837cb518 -PASS bsearch diff --git a/tests/expected/stdlib/mktemp.stderr b/tests/expected/stdlib/mktemp.stderr deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/tests/expected/stdlib/mktemp.stdout b/tests/expected/stdlib/mktemp.stdout deleted file mode 100644 index 66174ea417..0000000000 --- a/tests/expected/stdlib/mktemp.stdout +++ /dev/null @@ -1 +0,0 @@ -tempXXsTJ4p diff --git a/tests/expected/unlink.stderr b/tests/expected/unlink.stderr deleted file mode 100644 index 4d72cf777b..0000000000 --- a/tests/expected/unlink.stderr +++ /dev/null @@ -1 +0,0 @@ -unlink: Success diff --git a/tests/expected/unlink.stdout b/tests/expected/unlink.stdout deleted file mode 100644 index e69de29bb2..0000000000 From 2c0f9ce7473b11c50b9a91cbccc6aa90528076d3 Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Thu, 28 Jun 2018 08:03:17 +0200 Subject: [PATCH 32/34] Fix off-by-one error and remove utf8 check in mktemp --- src/stdlib/src/lib.rs | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index 0a6016f9f1..f88743581d 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -375,30 +375,35 @@ pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char { fn strlen(s: *const c_char) -> size_t; } let len = unsafe { strlen(name) }; - let mut retries = 100; - let name_buf = unsafe { slice::from_raw_parts(name as *const u8, len as usize) }; - let name_str = str::from_utf8(name_buf).unwrap_or(""); - if len < 6 || !name_str.ends_with("XXXXXX") { + if len < 6 { unsafe { platform::errno = errno::EINVAL }; unsafe { *name = 0 }; - return name; - } + return name; + } + for i in len-6..len { + if unsafe { *name.offset(i as isize) } != b'X' as c_char { + unsafe { platform::errno = errno::EINVAL }; + unsafe { *name = 0 }; + return name; + } + } let mut rng = JitterRng::new_with_timer(get_nstime); rng.test_timer(); + let mut retries = 100; loop { let mut char_iter = iter::repeat(()) .map(|()| rng.sample(Alphanumeric)) - .take(6); + .take(6); unsafe { for (i,c) in char_iter.enumerate() { - *name.offset(len as isize-i as isize) = c as c_char + *name.offset(len as isize - i as isize - 1) = c as c_char } } unsafe { - let mut st: stat = mem::uninitialized(); + let mut st: stat = mem::uninitialized(); if platform::stat(name, &mut st) != 0 { if platform::errno != ENOENT { *name = 0; } return name; From 8e7cd11bc09667bf542856de1c4a1a380221c9cf Mon Sep 17 00:00:00 2001 From: jD91mZM2 Date: Thu, 28 Jun 2018 08:07:12 +0200 Subject: [PATCH 33/34] Fix CI --- .gitlab-ci.yml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index ad1d6b1742..e38d132959 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,6 +1,7 @@ image: "rust:latest" before_script: + - git submodule update --init --recursive - rustup toolchain add nightly - rustup target add x86_64-unknown-redox --toolchain nightly - rustup show # Print version info for debugging @@ -19,7 +20,8 @@ test:linux: fmt: script: - - ./fmt.sh -- --write-mode=diff + - rustup component add rustfmt-preview + - ./fmt.sh -- --check # TODO: Set up a docker image with a redox vm that would allow to -# run things like tests under redox \ No newline at end of file +# run things like tests under redox From 5c5e237042bfc04aabde6313700f5254e8f992f8 Mon Sep 17 00:00:00 2001 From: Paul Sajna Date: Thu, 28 Jun 2018 19:24:04 +0000 Subject: [PATCH 34/34] Exec Functions (again) (again) --- include/bits/exec.h | 47 ++++++++++++++++++++++++++++++ src/platform/Cargo.toml | 3 ++ src/platform/src/lib.rs | 7 +++++ src/platform/src/linux/mod.rs | 4 +++ src/platform/src/redox/mod.rs | 54 +++++++++++++++++++++++++++++++++++ src/stdlib/src/lib.rs | 1 - src/unistd/cbindgen.toml | 3 +- src/unistd/src/getopt.rs | 1 - src/unistd/src/lib.rs | 26 +++++++++++------ tests/.gitignore | 1 + tests/Makefile | 1 + tests/exec.c | 8 ++++++ 12 files changed, 144 insertions(+), 12 deletions(-) create mode 100644 include/bits/exec.h create mode 100644 tests/exec.c diff --git a/include/bits/exec.h b/include/bits/exec.h new file mode 100644 index 0000000000..94024518ba --- /dev/null +++ b/include/bits/exec.h @@ -0,0 +1,47 @@ +#ifndef _BITS_EXEC_H +#define _BITS_EXEC_H + +int execl(const char *path, const char* argv0, ...) +{ + int argc; + va_list ap; + va_start(ap, argv0); + for (argc = 1; va_arg(ap, const char*); argc++); + va_end(ap); + { + int i; + char *argv[argc+1]; + va_start(ap, argv0); + argv[0] = (char *)argv0; + for (i = 1; i < argc; i++) { + argv[i] = va_arg(ap, char *); + } + argv[i] = NULL; + va_end(ap); + return execv(path, argv); + } +} + +int execle(const char *path, const char* argv0, ...) +{ + int argc; + va_list ap; + va_start(ap, argv0); + for (argc = 1; va_arg(ap, const char *); argc++); + va_end(ap); + { + int i; + char *argv[argc+1]; + char **envp; + va_start(ap, argv0); + argv[0] = (char *)argv0; + for (i = 1; i <= argc; i++) { + argv[i] = va_arg(ap, char *); + } + envp = va_arg(ap, char **); + va_end(ap); + return execve(path, argv, envp); + } +} + +#endif diff --git a/src/platform/Cargo.toml b/src/platform/Cargo.toml index e25b8251c0..dd5ba725ac 100644 --- a/src/platform/Cargo.toml +++ b/src/platform/Cargo.toml @@ -8,3 +8,6 @@ sc = "0.2" [target.'cfg(target_os = "redox")'.dependencies] redox_syscall = "0.1" + +[dependencies] +ralloc = { path = "../../ralloc" } diff --git a/src/platform/src/lib.rs b/src/platform/src/lib.rs index 4919e61308..78bc4c39ca 100644 --- a/src/platform/src/lib.rs +++ b/src/platform/src/lib.rs @@ -2,6 +2,8 @@ #![no_std] #![allow(non_camel_case_types)] +#![feature(alloc)] +#![feature(global_allocator)] //TODO #![feature(thread_local)] #[cfg(all(not(feature = "no_std"), target_os = "linux"))] @@ -22,12 +24,17 @@ mod sys; #[path = "redox/mod.rs"] mod sys; +extern crate alloc; +extern crate ralloc; + pub mod types; use core::fmt; use types::*; +#[global_allocator] +static ALLOCATOR: ralloc::Allocator = ralloc::Allocator; //TODO #[thread_local] #[allow(non_upper_case_globals)] #[no_mangle] diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index 0ae481e4f3..1046549b0e 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -54,6 +54,10 @@ pub fn dup2(fildes: c_int, fildes2: c_int) -> c_int { e(unsafe { syscall!(DUP3, fildes, fildes2, 0) }) as c_int } +pub fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + e(unsafe { syscall!(EXECVE, path, argv, envp) }) as c_int +} + pub fn exit(status: c_int) -> ! { unsafe { syscall!(EXIT, status); diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 56eed2b259..71019375f7 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -1,5 +1,7 @@ use core::ptr; use core::slice; +use core::mem; +use alloc::Vec; use syscall; use syscall::flag::*; use syscall::data::TimeSpec as redox_timespec; @@ -66,6 +68,58 @@ pub fn dup2(fd1: c_int, fd2: c_int) -> c_int { e(syscall::dup2(fd1 as usize, fd2 as usize, &[])) as c_int } +pub fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int { + unsafe { + let mut env = envp; + while !(*env).is_null() { + let slice = c_str(*env); + // Should always contain a =, but worth checking + if let Some(sep) = slice.iter().position(|&c| c == b'=') { + // If the environment variable has no name, do not attempt + // to add it to the env. + if sep > 0 { + let mut path = b"env:".to_vec(); + path.extend_from_slice(&slice[..sep]); + match syscall::open(&path, O_WRONLY | O_CREAT) { + Ok(fd) => { + // If the environment variable has no value, there + // is no need to write anything to the env scheme. + if sep + 1 < slice.len() { + let n = match syscall::write(fd, &slice[sep + 1..]) { + Ok(n) => n, + err => { + return e(err) as c_int; + } + }; + } + // Cleanup after adding the variable. + match syscall::close(fd) { + Ok(_) => (), + err => { + return e(err) as c_int; + } + } + } + err => { + return e(err) as c_int; + } + } + } + } + env = env.offset(1); + } + + let mut args: Vec<[usize; 2]> = Vec::new(); + let mut arg = argv; + while !(*arg).is_null() { + args.push([*arg as usize, c_str(*arg).len()]); + arg = arg.offset(1); + } + + e(syscall::execve(c_str(path), &args)) as c_int + } +} + pub fn exit(status: c_int) -> ! { let _ = syscall::exit(status as usize); loop {} diff --git a/src/stdlib/src/lib.rs b/src/stdlib/src/lib.rs index f88743581d..ff5404d56d 100644 --- a/src/stdlib/src/lib.rs +++ b/src/stdlib/src/lib.rs @@ -2,7 +2,6 @@ #![no_std] #![feature(core_intrinsics)] -#![feature(global_allocator)] extern crate ctype; extern crate errno; diff --git a/src/unistd/cbindgen.toml b/src/unistd/cbindgen.toml index cf1de270d4..ef4ad8123a 100644 --- a/src/unistd/cbindgen.toml +++ b/src/unistd/cbindgen.toml @@ -1,5 +1,6 @@ -sys_includes = ["stddef.h", "stdint.h", "sys/types.h"] +sys_includes = ["stddef.h", "stdint.h", "sys/types.h", "stdarg.h", "bits/exec.h"] include_guard = "_UNISTD_H" +trailer = "#include " language = "C" [enum] diff --git a/src/unistd/src/getopt.rs b/src/unistd/src/getopt.rs index e1dac2dad7..1457e732be 100644 --- a/src/unistd/src/getopt.rs +++ b/src/unistd/src/getopt.rs @@ -1,7 +1,6 @@ //! getopt implementation for Redox, following http://pubs.opengroup.org/onlinepubs/009695399/functions/getopt.html use super::platform::types::*; -use super::platform; use super::stdio; use super::string; use core::ptr; diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index a757781e2b..db90a9feaf 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -9,6 +9,7 @@ extern crate sys_utsname; pub use platform::types::*; pub use getopt::*; + use core::ptr; mod getopt; @@ -31,6 +32,9 @@ pub const STDIN_FILENO: c_int = 0; pub const STDOUT_FILENO: c_int = 1; pub const STDERR_FILENO: c_int = 2; +#[no_mangle] +pub static mut environ: *const *mut c_char = 0 as *const *mut c_char; + #[no_mangle] pub extern "C" fn _exit(status: c_int) { platform::exit(status) @@ -97,23 +101,27 @@ pub extern "C" fn encrypt(block: [c_char; 64], edflag: c_int) { } // #[no_mangle] -// pub extern "C" fn execl(path: *const c_char, arg0: *const c_char /* TODO: , mut args: ... */) -> c_int { +// pub extern "C" fn execl(path: *const c_char, args: *const *mut c_char) -> c_int { // unimplemented!(); // } -// + // #[no_mangle] -// pub extern "C" fn execle(path: *const c_char, arg0: *const c_char /* TODO: , mut args: ... */) -> c_int { +// pub extern "C" fn execle( +// path: *const c_char, +// args: *const *mut c_char, +// envp: *const *mut c_char, +// ) -> c_int { // unimplemented!(); // } -// + // #[no_mangle] -// pub extern "C" fn execlp(file: *const c_char, arg0: *const c_char /* TODO: , mut args: ... */) -> c_int { +// pub extern "C" fn execlp(file: *const c_char, args: *const *mut c_char) -> c_int { // unimplemented!(); // } #[no_mangle] pub extern "C" fn execv(path: *const c_char, argv: *const *mut c_char) -> c_int { - unimplemented!(); + unsafe { execve(path, argv, environ) } } #[no_mangle] @@ -122,7 +130,7 @@ pub extern "C" fn execve( argv: *const *mut c_char, envp: *const *mut c_char, ) -> c_int { - unimplemented!(); + platform::execve(path, argv, envp) } #[no_mangle] @@ -396,7 +404,7 @@ pub extern "C" fn sbrk(incr: intptr_t) -> *mut c_void { #[no_mangle] pub extern "C" fn setgid(gid: gid_t) -> c_int { - unimplemented!(); + platform::setregid(gid, gid) } #[no_mangle] @@ -426,7 +434,7 @@ pub extern "C" fn setsid() -> pid_t { #[no_mangle] pub extern "C" fn setuid(uid: uid_t) -> c_int { - unimplemented!(); + platform::setreuid(uid, uid) } #[no_mangle] diff --git a/tests/.gitignore b/tests/.gitignore index c6837db381..c60d7feecf 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -11,6 +11,7 @@ /ctype /dup /error +/exec /fchdir /fcntl /fsync diff --git a/tests/Makefile b/tests/Makefile index dcea342362..dbe6063de2 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -9,6 +9,7 @@ EXPECT_BINS=\ ctype \ dup \ error \ + exec \ fchdir \ fcntl \ fsync \ diff --git a/tests/exec.c b/tests/exec.c new file mode 100644 index 0000000000..4a09e743b5 --- /dev/null +++ b/tests/exec.c @@ -0,0 +1,8 @@ +#include + +int main(int argc, char** argv) { + char *const args[1] = {"arg"}; + execv("write", args); + perror("execv"); + return 0; +}