diff --git a/Cargo.lock b/Cargo.lock index a6b99aad..7d624bcb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,6 +349,7 @@ dependencies = [ "axerrno", "axhal", "kspin", + "lazy_static", "lazyinit", "log", "memory_addr", @@ -828,6 +829,15 @@ dependencies = [ "kernel_guard", ] +[[package]] +name = "lazy_static" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" +dependencies = [ + "spin", +] + [[package]] name = "lazyinit" version = "0.2.1" @@ -982,7 +992,7 @@ checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "page_table_entry" version = "0.5.3" -source = "git+https://github.com/Mivik/page_table_multiarch.git?rev=19ededd#19ededdb806ab3b22efb4880661790524fa421a5" +source = "git+https://github.com/Mivik/page_table_multiarch.git?rev=5c222f2#5c222f2199a6c566e9009dca8d86a589b4f66757" dependencies = [ "aarch64-cpu", "bitflags 2.9.0", @@ -993,7 +1003,7 @@ dependencies = [ [[package]] name = "page_table_multiarch" version = "0.5.3" -source = "git+https://github.com/Mivik/page_table_multiarch.git?rev=19ededd#19ededdb806ab3b22efb4880661790524fa421a5" +source = "git+https://github.com/Mivik/page_table_multiarch.git?rev=5c222f2#5c222f2199a6c566e9009dca8d86a589b4f66757" dependencies = [ "log", "memory_addr", diff --git a/Cargo.toml b/Cargo.toml index 9d11edb5..7c776b96 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,7 +26,7 @@ axconfig = { git = "https://github.com/oscomp/arceos.git" } axfs = { git = "https://github.com/oscomp/arceos.git" } axhal = { git = "https://github.com/oscomp/arceos.git", features = ["uspace"] } axlog = { git = "https://github.com/oscomp/arceos.git" } -axmm = { git = "https://github.com/oscomp/arceos.git" } +axmm = { git = "https://github.com/oscomp/arceos.git", features = ["cow"] } axnet = { git = "https://github.com/oscomp/arceos.git" } axns = { git = "https://github.com/oscomp/arceos.git", features = [ "thread-local", @@ -90,5 +90,5 @@ shlex = { version = "1.3.0", default-features = false } syscalls = { git = "https://github.com/jasonwhite/syscalls.git", rev = "92624de", default-features = false } [patch.crates-io] -page_table_multiarch = { git = "https://github.com/Mivik/page_table_multiarch.git", rev = "19ededd" } -page_table_entry = { git = "https://github.com/Mivik/page_table_multiarch.git", rev = "19ededd" } +page_table_multiarch = { git = "https://github.com/Mivik/page_table_multiarch.git", rev = "5c222f2" } +page_table_entry = { git = "https://github.com/Mivik/page_table_multiarch.git", rev = "5c222f2" } diff --git a/apps/libc/c/forkcow/forkcow.c b/apps/libc/c/forkcow/forkcow.c new file mode 100644 index 00000000..fcb4d3d5 --- /dev/null +++ b/apps/libc/c/forkcow/forkcow.c @@ -0,0 +1,51 @@ +#include +#include +#include +#include +#include + +#define N 150 +#define LEN (1024 * 1024) + +void forktest(void) { + int n, pid; + + printf("fork test\n"); + + char *ptr = mmap(NULL, LEN * sizeof(char), PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + + for (n = 0; n < LEN; n++) { + *(ptr + n) = 'a'; + } + + for (n = 0; n < N; n++) { + pid = fork(); + if (pid < 0) + break; + if (pid == 0) + exit(0); + } + + if (n == N) { + printf("fork test OK\n"); + exit(0); + } + + for (; n > 0; n--) { + if (wait(0) < 0) { + printf("wait stopped early\n"); + exit(1); + } + } + + if (wait(0) != -1) { + printf("wait got too many\n"); + exit(1); + } +} + +int main(void) { + forktest(); + exit(1); +} diff --git a/apps/libc/expect_off.out b/apps/libc/expect_off.out index 4e86961f..3c428cb4 100644 --- a/apps/libc/expect_off.out +++ b/apps/libc/expect_off.out @@ -22,3 +22,6 @@ test_sigwait ok3 test_sigsuspend ok1 test_sigsuspend ok2 test_sigsuspend ok3 + +fork test +fork test OK diff --git a/apps/libc/testcase_list b/apps/libc/testcase_list index 3f68ac85..97999977 100644 --- a/apps/libc/testcase_list +++ b/apps/libc/testcase_list @@ -1,4 +1,5 @@ helloworld_c sleep_c signal_c +forkcow_c mmap_c diff --git a/scripts/get_deps.sh b/scripts/get_deps.sh index eea6e2f4..7bceed1d 100755 --- a/scripts/get_deps.sh +++ b/scripts/get_deps.sh @@ -1,7 +1,7 @@ #!/bin/bash AX_ROOT=.arceos -COMMIT=54d5739 +COMMIT=a634925 test ! -d "$AX_ROOT" && echo "Cloning repositories ..." || true test ! -d "$AX_ROOT" && git clone https://github.com/oscomp/arceos "$AX_ROOT" || true