From 85aec2e6b92c688692562b638422ad377a2ea9cf Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 14:15:40 +0100 Subject: [PATCH 1/8] using compiler builtins to realize basic operation (e.g. memcpy) --- .cargo/config | 1 + src/lib.rs | 2 - src/rlib.rs | 171 -------------------------------------------------- 3 files changed, 1 insertion(+), 173 deletions(-) delete mode 100644 src/rlib.rs diff --git a/.cargo/config b/.cargo/config index 89070681fb..42399c1716 100644 --- a/.cargo/config +++ b/.cargo/config @@ -1,5 +1,6 @@ [unstable] build-std = ["core", "alloc"] +build-std-features = ["compiler-builtins-mem"] [build] target = "x86_64-unknown-hermit-kernel" diff --git a/src/lib.rs b/src/lib.rs index ae81c07528..7998321e7c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,8 +95,6 @@ pub mod environment; mod errno; mod kernel_message_buffer; mod mm; -#[cfg(not(feature = "newlib"))] -mod rlib; #[cfg(target_os = "hermit")] mod runtime_glue; mod scheduler; diff --git a/src/rlib.rs b/src/rlib.rs deleted file mode 100644 index 1ed6a41e9f..0000000000 --- a/src/rlib.rs +++ /dev/null @@ -1,171 +0,0 @@ -// Copyright 2014 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! This library is derived from rlibc, not intended for general use, -//! and is superseded by a system libc if one is available. In a -//! freestanding context, however, common functions such as memset, memcpy, -//! etc are not implemented. This library provides an implementation of -//! these functions which are either required by libcore or called by rustc -//! implicitly. - -#[no_mangle] -pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { - let mut i = 0; - while i < n { - *dest.add(i) = *src.add(i); - i += 1; - } - dest -} - -#[no_mangle] -pub unsafe extern "C" fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { - if src < dest as *const u8 { - // copy from end - let mut i = n; - while i != 0 { - i -= 1; - *dest.add(i) = *src.add(i); - } - } else { - // copy from beginning - let mut i = 0; - while i < n { - *dest.add(i) = *src.add(i); - i += 1; - } - } - dest -} - -#[no_mangle] -pub unsafe extern "C" fn memset(s: *mut u8, c: i32, n: usize) -> *mut u8 { - let mut i = 0; - while i < n { - *s.add(i) = c as u8; - i += 1; - } - s -} - -#[no_mangle] -pub unsafe extern "C" fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { - let mut i = 0; - while i < n { - let a = *s1.add(i); - let b = *s2.add(i); - if a != b { - return a as i32 - b as i32; - } - i += 1; - } - 0 -} - -#[cfg(not(target_os = "hermit"))] -#[cfg(test)] -mod test { - use super::{memcmp, memcpy, memmove, memset}; - - #[cfg(not(target_os = "hermit"))] - #[test] - fn memcmp_single_byte_pointers() { - unsafe { - assert_eq!(memcmp(&0xFAu8, &0xFAu8, 1), 0x00); - assert!(memcmp(&0xEFu8, &0xFEu8, 1) < 0x00); - } - } - - #[cfg(not(target_os = "hermit"))] - #[test] - fn memcmp_strings() { - { - let (x, z) = ("Hello!", "Good Bye."); - let l = x.len(); - unsafe { - assert_eq!(memcmp(x.as_ptr(), x.as_ptr(), l), 0); - assert!(memcmp(x.as_ptr(), z.as_ptr(), l) > 0); - assert!(memcmp(z.as_ptr(), x.as_ptr(), l) < 0); - } - } - { - let (x, z) = ("hey!", "hey."); - let l = x.len(); - unsafe { - assert!(memcmp(x.as_ptr(), z.as_ptr(), l) < 0); - } - } - } - - #[cfg(not(target_os = "hermit"))] - #[test] - fn memset_single_byte_pointers() { - let mut x: u8 = 0xFF; - unsafe { - memset(&mut x, 0xAA, 1); - assert_eq!(x, 0xAA); - memset(&mut x, 0x00, 1); - assert_eq!(x, 0x00); - x = 0x01; - memset(&mut x, 0x12, 0); - assert_eq!(x, 0x01); - } - } - - #[cfg(not(target_os = "hermit"))] - #[test] - fn memset_array() { - let mut buffer = [b'X'; 100]; - unsafe { - memset(buffer.as_mut_ptr(), b'#' as i32, buffer.len()); - } - for byte in buffer.iter() { - assert_eq!(*byte, b'#'); - } - } - - #[cfg(not(target_os = "hermit"))] - #[test] - fn memcpy_and_memcmp_arrays() { - let (src, mut dst) = ([b'X'; 100], [b'Y'; 100]); - unsafe { - assert_ne!(memcmp(src.as_ptr(), dst.as_ptr(), 100), 0); - let _ = memcpy(dst.as_mut_ptr(), src.as_ptr(), 100); - assert_eq!(memcmp(src.as_ptr(), dst.as_ptr(), 100), 0); - } - } - - #[cfg(not(target_os = "hermit"))] - #[test] - fn memmove_overlapping() { - { - let mut buffer = [b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9']; - unsafe { - memmove(&mut buffer[4], &buffer[0], 6); - let mut i = 0; - for byte in b"0123012345".iter() { - assert_eq!(buffer[i], *byte); - i += 1; - } - } - } - { - let mut buffer = [b'0', b'1', b'2', b'3', b'4', b'5', b'6', b'7', b'8', b'9']; - unsafe { - memmove(&mut buffer[0], &buffer[4], 6); - let mut i = 0; - for byte in b"4567896789".iter() { - assert_eq!(buffer[i], *byte); - i += 1; - } - } - } - } -} From 5f374711f80c7bbf86eab56878df9a64f966256e Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 14:17:12 +0100 Subject: [PATCH 2/8] update dependencies --- Cargo.lock | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6872f80f52..cdfcb15d77 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -20,9 +20,9 @@ checksum = "cf1de2fe8c75bc145a2f577add951f8134889b4795d47466a54a5c846d691693" [[package]] name = "cc" -version = "1.0.60" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ef611cc68ff783f18535d77ddd080185275713d852c4f5cbb6122c462a7a825c" +checksum = "ed67cbde08356238e75fc4656be4749481eeffb09e19f320a25237d5221c985d" [[package]] name = "cfg-if" @@ -131,9 +131,9 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.23" +version = "1.0.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51ef7cd2518ead700af67bf9d1a658d90b6037d77110fd9c0445429d0ba1c6c9" +checksum = "1e0704ee1a7e00d7bb417d0770ea303c1bccbabf0ef1667dae92b5967f5f8a71" dependencies = [ "unicode-xid", ] @@ -149,9 +149,9 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "8.1.1" +version = "8.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cee2c7710d96f9f90f56824fca5438b301dc0fb49ece4cf9dfa044e54067e10" +checksum = "1fdf7d9dbd43f3d81d94a49c1c3df73cc2b3827995147e6cf7f89d4ec5483e73" dependencies = [ "bitflags", "cc", @@ -205,9 +205,9 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "syn" -version = "1.0.42" +version = "1.0.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c51d92969d209b54a98397e1b91c8ae82d8c87a7bb87df0b29aa2ad81454228" +checksum = "cc371affeffc477f42a221a1e4297aedcea33d47d19b61455588bd9d8f6b19ac" dependencies = [ "proc-macro2", "quote", From cd97bbc8785701271970edb58f10944c620b5641 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 14:44:27 +0100 Subject: [PATCH 3/8] remove dependency to rustfmt --- .github/workflows/experimental.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/experimental.yml b/.github/workflows/experimental.yml index ae5414b0b7..8e21da97c3 100644 --- a/.github/workflows/experimental.yml +++ b/.github/workflows/experimental.yml @@ -31,7 +31,7 @@ jobs: targets: 'x86_64-pc-windows-msvc' - os: ubuntu-latest rust: 'nightly' - components: 'rust-src, llvm-tools-preview, rustfmt' + components: 'rust-src, llvm-tools-preview' targets: 'x86_64-unknown-linux-gnu' From 363f4be8394f3f28a66d4e27138e85bcad8d16be Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 14:58:35 +0100 Subject: [PATCH 4/8] rename workflow --- .github/workflows/{experimental.yml => nightly.yml} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename .github/workflows/{experimental.yml => nightly.yml} (99%) diff --git a/.github/workflows/experimental.yml b/.github/workflows/nightly.yml similarity index 99% rename from .github/workflows/experimental.yml rename to .github/workflows/nightly.yml index 8e21da97c3..1965b4dbfe 100644 --- a/.github/workflows/experimental.yml +++ b/.github/workflows/nightly.yml @@ -1,4 +1,4 @@ -name: Tests (experimental) +name: Tests (nightly) on: pull_request: From 7f4fb2b4bbc5782edc8097b5f9d3821faf2584ae Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 16:32:42 +0100 Subject: [PATCH 5/8] use libhermit-rs as working directory for the integration tests --- .github/workflows/nightly.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 1965b4dbfe..be81ede632 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -116,8 +116,10 @@ jobs: qemu-system-x86_64 -display none -smp 2 -m 64M -serial stdio -kernel loader/target/x86_64-unknown-hermit-loader/debug/rusty-loader -initrd target/x86_64-unknown-hermit/release/rusty_demo -cpu qemu64,apic,fsgsbase,rdtscp,xsave,fxsr timeout-minutes: 20 - name: Integration Tests + working-directory: libhermit-rs run: cargo test --tests --no-fail-fast -Z build-std=core,alloc --target x86_64-unknown-hermit-kernel -- --bootloader_path=../loader/target/x86_64-unknown-hermit-loader/debug/rusty-loader - name: Integration Tests (smp) + working-directory: libhermit-rs run: cargo test --tests --no-fail-fast -Z build-std=core,alloc --target x86_64-unknown-hermit-kernel -- --bootloader_path=../loader/target/x86_64-unknown-hermit-loader/debug/rusty-loader --num_cores 2 From de368a44ced13eda6d53d01f59ccf748aa7d45e0 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 17:18:00 +0100 Subject: [PATCH 6/8] run integration tests only on Linux --- .github/workflows/nightly.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index be81ede632..05663bce41 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -119,7 +119,9 @@ jobs: working-directory: libhermit-rs run: cargo test --tests --no-fail-fast -Z build-std=core,alloc --target x86_64-unknown-hermit-kernel -- --bootloader_path=../loader/target/x86_64-unknown-hermit-loader/debug/rusty-loader + if: ${{ matrix.os == 'ubuntu-latest' }} - name: Integration Tests (smp) working-directory: libhermit-rs run: cargo test --tests --no-fail-fast -Z build-std=core,alloc --target x86_64-unknown-hermit-kernel -- --bootloader_path=../loader/target/x86_64-unknown-hermit-loader/debug/rusty-loader --num_cores 2 + if: ${{ matrix.os == 'ubuntu-latest' }} From 8aea32510d59d2a8105d6b03cf2b154618a5f6e2 Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 17:24:22 +0100 Subject: [PATCH 7/8] rename job in the nightly workflow --- .github/workflows/nightly.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index 05663bce41..f3b8c8bed6 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -10,7 +10,7 @@ on: jobs: build: - name: Tests (experimental) + name: Tests runs-on: ${{ matrix.os }} # these tests based on the nightly compiler, which can be broken # consequently, we continue on an error From 705e50395c6f879cc9042858d3073696b9e6efde Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Tue, 27 Oct 2020 17:27:55 +0100 Subject: [PATCH 8/8] add nightly tests to the required bors tests --- .github/workflows/nightly.yml | 2 +- bors.toml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/nightly.yml b/.github/workflows/nightly.yml index f3b8c8bed6..a584861d59 100644 --- a/.github/workflows/nightly.yml +++ b/.github/workflows/nightly.yml @@ -14,7 +14,7 @@ jobs: runs-on: ${{ matrix.os }} # these tests based on the nightly compiler, which can be broken # consequently, we continue on an error - continue-on-error: true + #continue-on-error: true strategy: matrix: diff --git a/bors.toml b/bors.toml index f53631b8d9..256b290f6e 100644 --- a/bors.toml +++ b/bors.toml @@ -1,5 +1,8 @@ status = [ "Tests", + "Tests (macOS-latest, nightly)", + "Tests (windows-latest, nightly)", + "Tests (ubuntu-latest, nightly)", "Format check (ubuntu-latest, nightly)", "continuous-integration/travis-ci/push" ]