diff --git a/.gitattributes b/.gitattributes deleted file mode 100644 index 07ef07a5a..000000000 --- a/.gitattributes +++ /dev/null @@ -1,14 +0,0 @@ -regression/apps/hello_world/hello_world filter=lfs diff=lfs merge=lfs -text -regression/apps/fork/fork filter=lfs diff=lfs merge=lfs -text -regression/apps/hello_c/hello filter=lfs diff=lfs merge=lfs -text -regression/apps/execve/execve filter=lfs diff=lfs merge=lfs -text -regression/apps/execve/hello filter=lfs diff=lfs merge=lfs -text -regression/apps/fork_c/fork filter=lfs diff=lfs merge=lfs -text -regression/apps/signal_c/signal_test filter=lfs diff=lfs merge=lfs -text -regression/apps/busybox/busybox filter=lfs diff=lfs merge=lfs -text -regression/apps/pthread/pthread_test filter=lfs diff=lfs merge=lfs -text -regression/apps/hello_pie/hello filter=lfs diff=lfs merge=lfs -text -regression/apps/network/tcp/client filter=lfs diff=lfs merge=lfs -text -regression/apps/network/tcp/server filter=lfs diff=lfs merge=lfs -text -regression/apps/network/udp/client filter=lfs diff=lfs merge=lfs -text -regression/apps/network/udp/server filter=lfs diff=lfs merge=lfs -text \ No newline at end of file diff --git a/README.md b/README.md index d5ff8db6f..ced0c867f 100644 --- a/README.md +++ b/README.md @@ -24,38 +24,34 @@ As a zero-cost, least-privilege OS, Jinux provides the best of both worlds: the ## Build and test -While most of the code is written in Rust, the project-scope build process is governed by Makefile. The following commands are intended for use on an Ubuntu server that has installed qemu-system-x86_64. +While most of the code is written in Rust, the project-scope build process is governed by Makefile. The development environment is managed with Docker. Please ensure Docker is installed and can be run without sudo privilege. ### Preparation - -Before downloading source code, install and init Git LFS since the project manages binaries with Git LFS. -```bash -# 1. install git-lfs -apt install git-lfs - -# 2. init git-lfs for current user -git lfs install --skip-repo -``` - -Then, download source codes as normal. +1. Download the latest source code of jinux. ```bash git clone [repository url] ``` -After downloading the source code, run the following command once to make sure -all developmennt tools are installed. +2. After downloading the source code, run the following command to pull the development image. ```bash -make setup +docker pull jinuxdev/jinux:0.1.0 ``` +3. Start the development container. +```bash +docker run -it --privileged --network=host --device=/dev/kvm -v `pwd`:/root/jinux jinuxdev/jinux:0.1.0 +``` + +**All build and test commands should be run inside the development container.** + ### Build -Then, we can build the project. +1. Build the project. ```bash make build ``` -If everything goes well, then we can run the OS. +2. If everything goes well, then we can run the OS. ```bash make run ``` @@ -67,11 +63,11 @@ We can run unit tests and integration tests if building succeeds. make test ``` -If we want to check access control policy among components, install some standalone tools (e.g., `cargo-component`), and set environmental variables to enable `cargo` find installed tools under the project directory. +If we want to check access control policy among components, install some standalone tools (e.g., `cargo-component`). ``` bash make tools -export PATH=`pwd`/target/bin:${PATH} ``` + Then we can use the tool to check access control policy. ```bash cargo component-check diff --git a/kernel/main.rs b/kernel/main.rs index 1ad71771f..1d4807b32 100644 --- a/kernel/main.rs +++ b/kernel/main.rs @@ -38,9 +38,11 @@ fn read_ramdisk_content() -> &'static [u8] { #[cfg(not(test))] #[panic_handler] fn panic(info: &PanicInfo) -> ! { + use jinux_frame::{exit_qemu, QemuExitCode}; + println!("[panic]:{:?}", info); jinux_frame::panic_handler(); - loop {} + exit_qemu(QemuExitCode::Failed); } #[cfg(test)] diff --git a/regression/Makefile b/regression/Makefile index 8a2fda7cd..3418f0407 100644 --- a/regression/Makefile +++ b/regression/Makefile @@ -17,10 +17,10 @@ all: build $(INITRAMFS): @rm -rf $@ && mkdir -p $@ @# Mkdir necessary folders - @mkdir -p $@/tmp - @mkdir -p $@/opt - @mkdir -p $@/lib64 - @mkdir -p $@/lib/x86_64-linux-gnu + @mkdir -p $@/bin $@/etc $@/sbin $@/usr/bin $@/root $@/tmp $@/opt $@/lib64 $@/lib/x86_64-linux-gnu + @# Install busybox + @/bin/busybox --install -s $@/bin + @cp /usr/bin/busybox $@/usr/bin @# Copy necessary libs @cp -L /lib64/ld-linux-x86-64.so.2 $@/lib64 @cp -L /lib/x86_64-linux-gnu/libc.so.6 $@/lib/x86_64-linux-gnu diff --git a/regression/apps/Makefile b/regression/apps/Makefile index 9de37f7f3..09db3e9c4 100644 --- a/regression/apps/Makefile +++ b/regression/apps/Makefile @@ -2,11 +2,14 @@ MAKEFLAGS += --no-builtin-rules # Prevent the implicit rules from compiling ".c" MKFILE_PATH := $(abspath $(lastword $(MAKEFILE_LIST))) CUR_DIR := $(patsubst %/,%,$(dir $(MKFILE_PATH))) INITRAMFS ?= $(CUR_DIR)/../build/initramfs +REGRESSION_BUILD_DIR ?= $(INITRAMFS)/regression +TEST_APPS := signal_c pthread network hello_world hello_pie hello_c fork_c fork execve .PHONY: all -all: build - -build: - @cp -a $(CUR_DIR)/* $(INITRAMFS) - @cd $(INITRAMFS) && find . \( -name "*.s" -o -name "*.c" -o -name "Makefile" -o -name "README.md" \) -delete +all: + @mkdir -p $(REGRESSION_BUILD_DIR) + @for test_app in $(TEST_APPS); \ + do make --no-print-directory -C $${test_app}; \ + done + @make --no-print-directory BUILD_DIR=$(REGRESSION_BUILD_DIR) -C scripts diff --git a/regression/apps/bin/Makefile b/regression/apps/bin/Makefile deleted file mode 100644 index 058792aa5..000000000 --- a/regression/apps/bin/Makefile +++ /dev/null @@ -1,4 +0,0 @@ -.PHONY: all - -all: - ln -sf /busybox/busybox sh \ No newline at end of file diff --git a/regression/apps/bin/sh b/regression/apps/bin/sh deleted file mode 120000 index 032fe1be8..000000000 --- a/regression/apps/bin/sh +++ /dev/null @@ -1 +0,0 @@ -/busybox/busybox \ No newline at end of file diff --git a/regression/apps/busybox/README.md b/regression/apps/busybox/README.md deleted file mode 100644 index 06c61a01e..000000000 --- a/regression/apps/busybox/README.md +++ /dev/null @@ -1,7 +0,0 @@ -### How to compile this busybox -We don't include the source code of busybox here since the source code is really large. The busybox can be compiled with following commands. - -After download the source code of busybox 1.35.0 and unzip, then cd to the directory of busybox -1. `make defconfig`. We set all config as default. -2. Set static link option in .config: `CONFIG_STATIC=y`. We need a static-linked busybox binary since we does not support dynamic linking now. -3. Set standalone shell option in .config: `CONFIG_FEATURE_SH_STANDALONE=y`. The standalone ash will try to call busybox applets instead of search binaries in host system. e.g., when running ls, standalone ash will invoke `busybox ls`. \ No newline at end of file diff --git a/regression/apps/busybox/busybox b/regression/apps/busybox/busybox deleted file mode 100755 index 9e5aabe01..000000000 --- a/regression/apps/busybox/busybox +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6db28e1ed8bdac06ac595b2126cefc10ecf16156bf4c1005950f561aedc0531a -size 2701792 diff --git a/regression/apps/execve/Makefile b/regression/apps/execve/Makefile index 1a5184c03..d393e1212 100644 --- a/regression/apps/execve/Makefile +++ b/regression/apps/execve/Makefile @@ -1,12 +1,3 @@ -.PHONY: build clean run +include ../test_common.mk -build: hello.c execve.c - @gcc -static hello.c -o hello - @gcc -static execve.c -o execve - -clean: - @rm hello - @rm execve - -run: build - @./execve \ No newline at end of file +EXTRA_C_FLAGS :=-static diff --git a/regression/apps/execve/execve b/regression/apps/execve/execve deleted file mode 100755 index 143ed4450..000000000 --- a/regression/apps/execve/execve +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:c7cc90df87ade7ff2cb494e13678aceaf93542883558fda947bd2fc01e2d73a6 -size 871952 diff --git a/regression/apps/execve/execve.c b/regression/apps/execve/execve.c index 6d7ac44d1..a7bda5d96 100644 --- a/regression/apps/execve/execve.c +++ b/regression/apps/execve/execve.c @@ -8,7 +8,7 @@ int main() { printf("Execve a new file /execve/hello:\n"); // flush the stdout content to ensure the content print to console fflush(stdout); - execve("/execve/hello", argv, envp); + execve("/regression/execve/hello", argv, envp); printf("Should not print\n"); fflush(stdout); return 0; diff --git a/regression/apps/execve/hello b/regression/apps/execve/hello deleted file mode 100755 index be093b65e..000000000 --- a/regression/apps/execve/hello +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d0152798ba393fb04603ead02083e74de560d9cf51584f5cdca762d0706ebd2d -size 871960 diff --git a/regression/apps/fork/Makefile b/regression/apps/fork/Makefile index f045feea0..238cf33ab 100644 --- a/regression/apps/fork/Makefile +++ b/regression/apps/fork/Makefile @@ -1,10 +1,3 @@ -.PHONY: build clean run +include ../test_common.mk -build: fork.s - @gcc -static -nostdlib fork.s -o fork - -clean: - @rm fork - -run: build - @./fork \ No newline at end of file +EXTRA_C_FLAGS :=-static -nostdlib diff --git a/regression/apps/fork/fork b/regression/apps/fork/fork deleted file mode 100755 index 6f767f3d8..000000000 --- a/regression/apps/fork/fork +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:9bc1642390b9dc38ecc058240e529401c38aa8bb9a86bad3615e4bdad505fa8c -size 9592 diff --git a/regression/apps/fork_c/Makefile b/regression/apps/fork_c/Makefile index 03d5e36b4..d393e1212 100644 --- a/regression/apps/fork_c/Makefile +++ b/regression/apps/fork_c/Makefile @@ -1,10 +1,3 @@ -.PHONY: build clean run +include ../test_common.mk -build: fork.c - @gcc -static fork.c -o fork - -clean: - @rm fork - -run: build - @./fork \ No newline at end of file +EXTRA_C_FLAGS :=-static diff --git a/regression/apps/fork_c/fork b/regression/apps/fork_c/fork deleted file mode 100755 index 8d7f960c3..000000000 --- a/regression/apps/fork_c/fork +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ca7a77a72da160f11670a04a16b623944295b9059399da45f57668f121b00d11 -size 877152 diff --git a/regression/apps/hello_c/Makefile b/regression/apps/hello_c/Makefile index f6dfdfe8b..d6dcb9e58 100644 --- a/regression/apps/hello_c/Makefile +++ b/regression/apps/hello_c/Makefile @@ -1,10 +1,3 @@ -.PHONY: build clean run +include ../test_common.mk -build: hello.c - @gcc -static -mno-sse hello.c -o hello - -clean: - @rm hello - -run: build - @./hello \ No newline at end of file +EXTRA_C_FLAGS :=-static -mno-sse diff --git a/regression/apps/hello_c/hello b/regression/apps/hello_c/hello deleted file mode 100755 index 4db2c3de7..000000000 --- a/regression/apps/hello_c/hello +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:dda5a7d6081cc2252056375d0550731ef2fd24789aa5f17da189a36bf78c588d -size 871896 diff --git a/regression/apps/hello_pie/Makefile b/regression/apps/hello_pie/Makefile index ae07ee0e6..05ff449d2 100644 --- a/regression/apps/hello_pie/Makefile +++ b/regression/apps/hello_pie/Makefile @@ -1,10 +1,3 @@ -.PHONY: build clean run +include ../test_common.mk -build: hello.c - @gcc hello.c -o hello - -clean: - @rm hello - -run: build - @./hello \ No newline at end of file +EXTRA_C_FLAGS := diff --git a/regression/apps/hello_pie/hello b/regression/apps/hello_pie/hello deleted file mode 100755 index ec20a01e1..000000000 --- a/regression/apps/hello_pie/hello +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:64b67cf4ad247d668833888447ec7f12d37f5f816abd549d5c2c08fecfa4dd09 -size 16696 diff --git a/regression/apps/hello_world/Makefile b/regression/apps/hello_world/Makefile index 28bc7407e..238cf33ab 100644 --- a/regression/apps/hello_world/Makefile +++ b/regression/apps/hello_world/Makefile @@ -1,10 +1,3 @@ -.PHONY: build clean run +include ../test_common.mk -build: hello_world.s - @gcc -static -nostdlib hello_world.s -o hello_world - -clean: - @rm hello_world - -run: build - @./hello_world \ No newline at end of file +EXTRA_C_FLAGS :=-static -nostdlib diff --git a/regression/apps/hello_world/hello_world b/regression/apps/hello_world/hello_world deleted file mode 100755 index eef6650fa..000000000 --- a/regression/apps/hello_world/hello_world +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:f56fb5cf05f234578b13c8d73f2d29568f6f513602f1ea0b71a0dbf0cf8f60f8 -size 9104 diff --git a/regression/apps/network/Makefile b/regression/apps/network/Makefile index 07bde4319..05ff449d2 100644 --- a/regression/apps/network/Makefile +++ b/regression/apps/network/Makefile @@ -1,13 +1,3 @@ -.PHONY: build clean +include ../test_common.mk -build: tcp/client.c tcp/server.c udp/client.c udp/server.c - @gcc tcp/client.c -o tcp/client - @gcc tcp/server.c -o tcp/server - @gcc udp/server.c -o udp/server - @gcc udp/client.c -o udp/client - -clean: - @rm tcp/client - @rm tcp/server - @rm udp/client - @rm udp/server +EXTRA_C_FLAGS := diff --git a/regression/apps/network/nettest.sh b/regression/apps/network/nettest.sh deleted file mode 100755 index a133ae321..000000000 --- a/regression/apps/network/nettest.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -NETTEST_DIR=/network -cd ${NETTEST_DIR} -echo "Start net test......" -./tcp/server & -./tcp/client -./udp/server & -./udp/client - -echo "All net test passed" diff --git a/regression/apps/network/tcp/client b/regression/apps/network/tcp/client deleted file mode 100755 index 89ea0a558..000000000 --- a/regression/apps/network/tcp/client +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:6ba2aa2da39e5e6d7be121f13e9321a43a4a47b03f50d3d8303d3d51753e2f5c -size 17096 diff --git a/regression/apps/network/tcp/server b/regression/apps/network/tcp/server deleted file mode 100755 index 2d38b73ae..000000000 --- a/regression/apps/network/tcp/server +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:209ffb16164cc1e4f7dc978ce3d660e5c9bee5cd4f70e20088d59c8ff64b8d7d -size 17368 diff --git a/regression/apps/network/tcp/client.c b/regression/apps/network/tcp_client.c similarity index 100% rename from regression/apps/network/tcp/client.c rename to regression/apps/network/tcp_client.c diff --git a/regression/apps/network/tcp/server.c b/regression/apps/network/tcp_server.c similarity index 100% rename from regression/apps/network/tcp/server.c rename to regression/apps/network/tcp_server.c diff --git a/regression/apps/network/udp/client b/regression/apps/network/udp/client deleted file mode 100755 index 24847dae4..000000000 --- a/regression/apps/network/udp/client +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:2701b848bdcbde4c1a2af2923f6c57d261befd7b20180fe0c10ac820f7082303 -size 17280 diff --git a/regression/apps/network/udp/server b/regression/apps/network/udp/server deleted file mode 100755 index 5ee027fd6..000000000 --- a/regression/apps/network/udp/server +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:8e890e0782c4320369841b50abfb56f0059b02881ea5b3384224ae65ce9c1d65 -size 17328 diff --git a/regression/apps/network/udp/client.c b/regression/apps/network/udp_client.c similarity index 100% rename from regression/apps/network/udp/client.c rename to regression/apps/network/udp_client.c diff --git a/regression/apps/network/udp/server.c b/regression/apps/network/udp_server.c similarity index 100% rename from regression/apps/network/udp/server.c rename to regression/apps/network/udp_server.c diff --git a/regression/apps/pthread/Makefile b/regression/apps/pthread/Makefile index 36e965ac0..2eef3474a 100644 --- a/regression/apps/pthread/Makefile +++ b/regression/apps/pthread/Makefile @@ -1,10 +1,3 @@ -.PHONY: build clean run +include ../test_common.mk -build: pthread_test.c - @gcc -static pthread_test.c -lpthread -o pthread_test - -clean: - @rm pthread_test - -run: build - @./pthread_test \ No newline at end of file +EXTRA_C_FLAGS :=-static -lpthread diff --git a/regression/apps/pthread/pthread_test b/regression/apps/pthread/pthread_test deleted file mode 100755 index 56fafbb00..000000000 --- a/regression/apps/pthread/pthread_test +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:d40bfc16dbf95aba3afa1934fa4efc0147f0a0a12533362a8d95e105d4d2af21 -size 1693840 diff --git a/regression/apps/scripts/Makefile b/regression/apps/scripts/Makefile new file mode 100644 index 000000000..f2b54367a --- /dev/null +++ b/regression/apps/scripts/Makefile @@ -0,0 +1,4 @@ +.PHONY: all + +all: ./*.sh + @cp ./*.sh $(BUILD_DIR) \ No newline at end of file diff --git a/regression/apps/scripts/nettest.sh b/regression/apps/scripts/nettest.sh new file mode 100755 index 000000000..980ad35bc --- /dev/null +++ b/regression/apps/scripts/nettest.sh @@ -0,0 +1,11 @@ +#!/bin/sh + +NETTEST_DIR=/regression/network +cd ${NETTEST_DIR} +echo "Start net test......" +./tcp_server & +./tcp_client +./udp_server & +./udp_client + +echo "All net test passed" diff --git a/regression/apps/scripts/run_tests.sh b/regression/apps/scripts/run_tests.sh index 864b7aaef..7556dde7f 100755 --- a/regression/apps/scripts/run_tests.sh +++ b/regression/apps/scripts/run_tests.sh @@ -2,15 +2,14 @@ set -e -SCRIPT_DIR=/scripts +SCRIPT_DIR=/regression cd ${SCRIPT_DIR}/.. echo "Running tests......" tests="hello_world/hello_world fork/fork execve/execve fork_c/fork signal_c/signal_test pthread/pthread_test hello_pie/hello" - for testcase in ${tests} do echo "Running test ${testcase}......" - ${testcase} + ${SCRIPT_DIR}/${testcase} done echo "All tests passed" \ No newline at end of file diff --git a/regression/apps/scripts/test_cmd.sh b/regression/apps/scripts/test_cmd.sh index 14fa12b6e..f3961ed99 100755 --- a/regression/apps/scripts/test_cmd.sh +++ b/regression/apps/scripts/test_cmd.sh @@ -3,7 +3,7 @@ set -e set -x -SCRIPT_DIR=/scripts +SCRIPT_DIR=/regression cd ${SCRIPT_DIR} touch hello.txt diff --git a/regression/apps/signal_c/Makefile b/regression/apps/signal_c/Makefile index fd160a031..d393e1212 100644 --- a/regression/apps/signal_c/Makefile +++ b/regression/apps/signal_c/Makefile @@ -1,7 +1,3 @@ -.PHONY: build clean run -build: signal_test.c - @gcc -static signal_test.c -o signal_test -clean: - @rm signal_test -run: build - @./signal_test +include ../test_common.mk + +EXTRA_C_FLAGS :=-static diff --git a/regression/apps/signal_c/signal_test b/regression/apps/signal_c/signal_test deleted file mode 100755 index 6c47eb9d5..000000000 --- a/regression/apps/signal_c/signal_test +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:25894b343f222eea5074a83e16a7140868a992a66e7bc8e363fabf2c23e19451 -size 882520 diff --git a/regression/apps/test_common.mk b/regression/apps/test_common.mk new file mode 100644 index 000000000..718742900 --- /dev/null +++ b/regression/apps/test_common.mk @@ -0,0 +1,27 @@ +MAIN_MAKEFILE := $(firstword $(MAKEFILE_LIST)) +INCLUDE_MAKEFILE := $(lastword $(MAKEFILE_LIST)) +CUR_DIR := $(shell dirname $(realpath $(MAIN_MAKEFILE))) +CUR_DIR_NAME := $(shell basename $(realpath $(CUR_DIR))) +REGRESSION_BUILD_DIR := $(CUR_DIR)/../../build/initramfs/regression +OBJ_OUTPUT_DIR := $(REGRESSION_BUILD_DIR)/$(CUR_DIR_NAME) +C_SRCS := $(wildcard *.c) +C_OBJS := $(addprefix $(OBJ_OUTPUT_DIR)/,$(C_SRCS:%.c=%)) +ASM_SRCS := $(wildcard *.s) +ASM_OBJS := $(addprefix $(OBJ_OUTPUT_DIR)/,$(ASM_SRCS:%.s=%)) +CC := gcc +C_FLAGS := + +.PHONY: all + +all: $(OBJ_OUTPUT_DIR) $(C_OBJS) $(ASM_OBJS) + +$(OBJ_OUTPUT_DIR): + @mkdir -p $(OBJ_OUTPUT_DIR) + +$(CUR_DIR)/../../build/initramfs/regression/$(CUR_DIR_NAME)/%: %.c + @$(CC) $(C_FLAGS) $(EXTRA_C_FLAGS) $< -o $@ + @echo "CC <= $@" + +$(CUR_DIR)/../../build/initramfs/regression/$(CUR_DIR_NAME)/%: %.s + @$(CC) $(C_FLAGS) $(EXTRA_C_FLAGS) $< -o $@ + @echo "CC <= $@" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1f6f0ea95..c368a576a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,2 +1,3 @@ [toolchain] channel = "nightly-2023-02-05" +components = ["rust-src", "rustc-dev", "llvm-tools-preview"] diff --git a/services/libs/jinux-std/src/lib.rs b/services/libs/jinux-std/src/lib.rs index bacac88eb..bea7ab17a 100644 --- a/services/libs/jinux-std/src/lib.rs +++ b/services/libs/jinux-std/src/lib.rs @@ -98,7 +98,7 @@ pub fn run_first_process() -> ! { } fn run_busybox() -> Result> { - let executable_path = "/busybox/busybox"; + let executable_path = "/usr/bin/busybox"; let argv = ["sh", "-l"]; let envp = [ "SHELL=/bin/sh", diff --git a/services/libs/jinux-std/src/net/iface/util.rs b/services/libs/jinux-std/src/net/iface/util.rs index 320ddd250..57e254c51 100644 --- a/services/libs/jinux-std/src/net/iface/util.rs +++ b/services/libs/jinux-std/src/net/iface/util.rs @@ -53,14 +53,12 @@ pub fn spawn_background_poll_thread(iface: Arc) { debug!("spawn background poll thread"); loop { let next_poll_time = if let Some(next_poll_time) = iface.next_poll_at_ms() { - trace!("next poll time = {:?}", next_poll_time); next_poll_time } else { Thread::yield_now(); continue; }; let now = read_monotonic_milli_seconds(); - trace!("now = {:?}", now); if now > next_poll_time { // FIXME: now is later than next poll time. This may cause problem. iface.poll(); diff --git a/services/libs/jinux-std/src/process/fifo_scheduler.rs b/services/libs/jinux-std/src/process/fifo_scheduler.rs index 820a10a1e..cf3a63542 100644 --- a/services/libs/jinux-std/src/process/fifo_scheduler.rs +++ b/services/libs/jinux-std/src/process/fifo_scheduler.rs @@ -4,24 +4,24 @@ use jinux_frame::task::{set_scheduler, Scheduler, Task, TaskAdapter}; use intrusive_collections::LinkedList; pub struct FifoScheduler { - tasks: Mutex>, + tasks: SpinLock>, } impl FifoScheduler { pub fn new() -> Self { Self { - tasks: Mutex::new(LinkedList::new(TaskAdapter::new())), + tasks: SpinLock::new(LinkedList::new(TaskAdapter::new())), } } } impl Scheduler for FifoScheduler { fn enqueue(&self, task: Arc) { - self.tasks.lock().push_back(task.clone()); + self.tasks.lock_irq_disabled().push_back(task.clone()); } fn dequeue(&self) -> Option> { - self.tasks.lock().pop_front() + self.tasks.lock_irq_disabled().pop_front() } } diff --git a/services/libs/jinux-std/src/process/posix_thread/robust_list.rs b/services/libs/jinux-std/src/process/posix_thread/robust_list.rs index d4e37a9ae..0452b4c9b 100644 --- a/services/libs/jinux-std/src/process/posix_thread/robust_list.rs +++ b/services/libs/jinux-std/src/process/posix_thread/robust_list.rs @@ -102,7 +102,9 @@ impl<'a> Iterator for FutexIter<'a> { } else { None }; - let robust_list = read_val_from_user::(self.entry_ptr).unwrap(); + let Ok(robust_list) = read_val_from_user::(self.entry_ptr) else { + return None; + }; self.entry_ptr = robust_list.next; self.count += 1; if futex_addr.is_some() { diff --git a/services/libs/jinux-std/src/syscall/mod.rs b/services/libs/jinux-std/src/syscall/mod.rs index 50432aa3f..1a7154a44 100644 --- a/services/libs/jinux-std/src/syscall/mod.rs +++ b/services/libs/jinux-std/src/syscall/mod.rs @@ -465,7 +465,7 @@ pub fn syscall_dispatch( SYS_GETRANDOM => syscall_handler!(3, sys_getrandom, args), SYS_EXECVEAT => syscall_handler!(5, sys_execveat, args, context), _ => { - error!("Unimplemented syscall number: {}", syscall_number); + warn!("Unimplemented syscall number: {}", syscall_number); return_errno_with_message!(Errno::ENOSYS, "Syscall was unimplemented"); } } diff --git a/services/libs/jinux-std/src/vm/vmo/mod.rs b/services/libs/jinux-std/src/vm/vmo/mod.rs index a2fbfb9c0..443e3ec1c 100644 --- a/services/libs/jinux-std/src/vm/vmo/mod.rs +++ b/services/libs/jinux-std/src/vm/vmo/mod.rs @@ -254,7 +254,6 @@ impl Vmo_ { pub fn read_bytes(&self, offset: usize, buf: &mut [u8]) -> Result<()> { let read_len = buf.len(); - debug_assert!(offset + read_len <= self.size()); if offset + read_len > self.size() { return_errno_with_message!(Errno::EINVAL, "read range exceeds vmo size"); } diff --git a/tools/docker/Dockerfile.ubuntu22.04 b/tools/docker/Dockerfile.ubuntu22.04 new file mode 100644 index 000000000..aae099072 --- /dev/null +++ b/tools/docker/Dockerfile.ubuntu22.04 @@ -0,0 +1,72 @@ +FROM ubuntu:22.04 + +SHELL ["/bin/bash", "-c"] + +ARG DEBIAN_FRONTEND=noninteractive +RUN apt update && apt-get install -y --no-install-recommends \ + build-essential \ + ca-certificates \ + cpio \ + cpuid \ + curl \ + file \ + g++ \ + gdb \ + git-core \ + gnupg \ + grub-common \ + libssl-dev \ + net-tools \ + openssh-server \ + pkg-config \ + python-is-python3 \ + python3-pip \ + qemu-system-x86 \ + strace \ + sudo \ + unzip \ + vim \ + wget \ + xorriso \ + zip + +# Install bazel, , which is required by the system call test suite from Gvisor project +RUN curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg \ + && mv bazel.gpg /etc/apt/trusted.gpg.d/ \ + && echo 'deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8' | tee /etc/apt/sources.list.d/bazel.list \ + && apt update \ + && apt install bazel=5.4.0 -y + +# Clean apt cache +RUN apt clean \ + && rm -rf /var/lib/apt/lists/* + +# Install Rust +ENV PATH="/root/.cargo/bin:${PATH}" +ENV JINUX_RUST_VERSION="nightly-2023-02-05" +RUN curl https://sh.rustup.rs -sSf | \ + sh -s -- --default-toolchain ${JINUX_RUST_VERSION} -y \ + && rm -rf /root/.cargo/registry && rm -rf /root/.cargo/git \ + && cargo -V \ + && rustup component add rust-src rustc-dev llvm-tools-preview + +# Install mdbook +RUN cargo install mdbook + +# Add the path of jinux tools +ENV PATH="/root/jinux/target/bin:${PATH}" + +# Build busybox +RUN curl --output busybox.tar.bz2 https://busybox.net/downloads/busybox-1.35.0.tar.bz2 \ + && mkdir /root/busybox \ + && tar xf busybox.tar.bz2 --strip-components=1 -C /root/busybox +WORKDIR /root/busybox +RUN make defconfig \ + && sed -i "s/# CONFIG_STATIC is not set/CONFIG_STATIC=y/g" .config \ + && sed -i "s/# CONFIG_FEATURE_SH_STANDALONE is not set/CONFIG_FEATURE_SH_STANDALONE=y/g" .config \ + && make -j \ + && cp /root/busybox/busybox /bin/busybox + +VOLUME [ "/root/jinux" ] + +WORKDIR /root/jinux diff --git a/tools/docker/build_image.sh b/tools/docker/build_image.sh new file mode 100755 index 000000000..77d569673 --- /dev/null +++ b/tools/docker/build_image.sh @@ -0,0 +1,14 @@ +#!/bin/bash + +set -e + +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +CARGO_TOML_PATH=${SCRIPT_DIR}/../../Cargo.toml +VERSION=$( grep -m1 -o '[0-9]\+\.[0-9]\+\.[0-9]\+' ${CARGO_TOML_PATH} | sed 's/[^0-9\.]//g' ) +IMAGE_NAME=jinuxdev/jinux:${VERSION} +DOCKER_FILE=${SCRIPT_DIR}/Dockerfile.ubuntu22.04 +ARCH=linux/amd64 + +# Build docker +cd ${SCRIPT_DIR} +docker buildx build -f ${DOCKER_FILE} --platform ${ARCH} -t ${IMAGE_NAME} . diff --git a/tools/docker/run_dev_container.sh b/tools/docker/run_dev_container.sh new file mode 100755 index 000000000..6a8f300ce --- /dev/null +++ b/tools/docker/run_dev_container.sh @@ -0,0 +1,11 @@ +#!/bin/bash + +set -e + +SCRIPT_DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd ) +JINUX_SRC_DIR=${SCRIPT_DIR}/../.. +CARGO_TOML_PATH=${SCRIPT_DIR}/../../Cargo.toml +VERSION=$( grep -m1 -o '[0-9]\+\.[0-9]\+\.[0-9]\+' ${CARGO_TOML_PATH} | sed 's/[^0-9\.]//g' ) +IMAGE_NAME=jinuxdev/jinux:${VERSION} + +docker run -it --privileged --network=host --device=/dev/kvm -v ${JINUX_SRC_DIR}:/root/jinux ${IMAGE_NAME}