diff --git a/.github/workflows/sync.tmp b/.github/workflows/sync.tmp index cdd7d4c..c1423b3 100644 --- a/.github/workflows/sync.tmp +++ b/.github/workflows/sync.tmp @@ -1,27 +1,27 @@ -name: Sync CI -on: - workflow_run: - workflows: - - Build CI - - Test CI - - Build & Deploy docs - types: - - completed - branches: - - main +# name: Sync CI +# on: +# workflow_run: +# workflows: +# - Build CI +# - Test CI +# - Build & Deploy docs +# types: +# - completed +# branches: +# - main -jobs: - sync: - runs-on: ubuntu-latest - if: ${{ github.event.workflow_run.conclusion == 'success' }} - steps: - - uses: actions/checkout@v4 - - name: Setup SSH - uses: webfactory/ssh-agent@v0.7.0 - with: - # Please set the private key in the repository settings - ssh-private-key: ${{ secrets.SSH_KEY }} - - name: Enable git-subrepo subcommands - run: git clone https://github.com/ingydotnet/git-subrepo /tmp/git-subrepo - - name: Synchronize with remote terminal modules - run: ./scripts/build/sync.sh ${{github.actor}} ${{github.actor_id}} \ No newline at end of file +# jobs: +# sync: +# runs-on: ubuntu-latest +# if: ${{ github.event.workflow_run.conclusion == 'success' }} +# steps: +# - uses: actions/checkout@v4 +# - name: Setup SSH +# uses: webfactory/ssh-agent@v0.7.0 +# with: +# # Please set the private key in the repository settings +# ssh-private-key: ${{ secrets.SSH_KEY }} +# - name: Enable git-subrepo subcommands +# run: git clone https://github.com/ingydotnet/git-subrepo /tmp/git-subrepo +# - name: Synchronize with remote terminal modules +# run: ./scripts/build/sync.sh ${{github.actor}} ${{github.actor_id}} \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index d7b9884..57e4ada 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -37,7 +37,19 @@ version = "0.1.0" source = "git+https://github.com/Starry-OS/allocator.git#7c9f5b83faf77893a5fb4387cd94fa6a27b65779" dependencies = [ "bitmap-allocator", + "buddy_system_allocator 0.9.1", "rlsf", + "slab_allocator", +] + +[[package]] +name = "another_ext4" +version = "0.1.0" +source = "git+https://github.com/LJxTHUCS/another_ext4.git?branch=main#282418b4b197472acaae60469b608499ef1161d2" +dependencies = [ + "axsync 0.1.0 (git+https://github.com/Starry-OS/axsync.git)", + "bitflags 2.6.0", + "log", ] [[package]] @@ -135,7 +147,7 @@ dependencies = [ name = "arceos-tls" version = "0.1.0" dependencies = [ - "axhal", + "axhal 0.1.0", "axstd", ] @@ -156,39 +168,37 @@ dependencies = [ [[package]] name = "arceos_api" version = "0.1.0" -source = "git+https://github.com/Starry-OS/arceos_api.git#fc77e8d99632a8d89fd10481a74186891f2fa1f2" dependencies = [ "axalloc", - "axconfig", + "axconfig 0.1.0", "axdisplay", "axerrno", "axfeat", "axfs", - "axhal", + "axhal 0.1.0", "axio", "axlog", "axnet", "axruntime", - "axtask", + "axtask 0.1.0", ] [[package]] name = "arceos_posix_api" version = "0.1.0" -source = "git+https://github.com/Starry-OS/arceos_posix_api.git#0ef12d062570badfad6b9832d2c886c2c24d6bcb" dependencies = [ "axalloc", - "axconfig", + "axconfig 0.1.0", "axerrno", "axfeat", "axfs", - "axhal", + "axhal 0.1.0", "axio", "axlog", "axnet", "axruntime", - "axsync", - "axtask", + "axsync 0.1.0", + "axtask 0.1.0", "bindgen", "flatten_objects", "lazy_static", @@ -199,11 +209,11 @@ dependencies = [ [[package]] name = "arch_boot" version = "0.1.0" -source = "git+https://github.com/Starry-OS/arch_boot.git#af6f02387de6fe6544e40d5ff254d899314b035c" dependencies = [ "aarch64-cpu", - "axconfig", - "axhal", + "axalloc", + "axconfig 0.1.0", + "axhal 0.1.0", "axlog", "axruntime", "axtrap", @@ -238,6 +248,15 @@ dependencies = [ "tock-registers", ] +[[package]] +name = "atomic-polyfill" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8cf2bce30dfe09ef0bfaef228b9d414faaf7e563035494d7fe092dba54b300f4" +dependencies = [ + "critical-section", +] + [[package]] name = "autocfg" version = "1.3.0" @@ -247,7 +266,6 @@ checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "axalloc" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axalloc.git#da0de65d739b91fb422d33477d10cee473436c42" dependencies = [ "allocator", "axerrno", @@ -257,6 +275,23 @@ dependencies = [ "spinlock", ] +[[package]] +name = "axbacktrace" +version = "0.1.0" +source = "git+https://github.com/kern-crates/axbacktrace.git#c0371ca8ef4a06ff2e21428b33aab51bcbdc16fa" +dependencies = [ + "cfg-if", + "log", +] + +[[package]] +name = "axconfig" +version = "0.1.0" +dependencies = [ + "serde", + "toml_edit", +] + [[package]] name = "axconfig" version = "0.1.0" @@ -269,10 +304,9 @@ dependencies = [ [[package]] name = "axdisplay" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axdisplay.git#ada3928ed2f9303cc0bbf75758c53716447ac730" dependencies = [ "axdriver", - "axsync", + "axsync 0.1.0 (git+https://github.com/Starry-OS/axsync.git)", "driver_display", "lazy_init", "log", @@ -281,11 +315,10 @@ dependencies = [ [[package]] name = "axdriver" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axdriver.git#fdf9d5efb411cfecfe4cc06bc9517a1fc8f3f7d3" dependencies = [ "axalloc", - "axconfig", - "axhal", + "axconfig 0.1.0", + "axhal 0.1.0", "cfg-if", "driver_block", "driver_common", @@ -307,19 +340,18 @@ dependencies = [ [[package]] name = "axfeat" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axfeat.git#a0d5a4813397aae6ce84a749a1c16955f4e9a874" dependencies = [ "axalloc", "axdisplay", "axdriver", "axfs", - "axhal", + "axhal 0.1.0", "axlog", "axnet", "axprocess", "axruntime", - "axsync", - "axtask", + "axsync 0.1.0", + "axtask 0.1.0", "spinlock", "taskctx", ] @@ -327,24 +359,27 @@ dependencies = [ [[package]] name = "axfs" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axfs.git#74ba6295c0113d2305d0037ffbae558fa237e846" dependencies = [ - "axconfig", + "another_ext4", + "axconfig 0.1.0", "axdriver", "axerrno", "axfs_devfs", "axfs_ramfs", "axfs_vfs", "axio", - "axsync", + "axsync 0.1.0", + "axtask 0.1.0", "bitflags 2.6.0", "capability", "cfg-if", "crate_interface", "driver_block", + "ext4_rs", "fatfs", "lazy_init", "log", + "lwext4_rust", ] [[package]] @@ -383,29 +418,29 @@ dependencies = [ [[package]] name = "axfutex" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axfutex.git#5eee19d07e750720c1b540dc8990dbf96c565433" dependencies = [ "axerrno", "axfs", - "axhal", + "axhal 0.1.0", "axlog", - "axsync", - "axtask", + "axsync 0.1.0", + "axtask 0.1.0", + "bitflags 2.6.0", "hashbrown 0.11.2", "lazy_static", "log", + "numeric-enum-macro", ] [[package]] name = "axhal" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axhal.git#769caa8b8749b324a1370a8da11c0e6a7597eedf" dependencies = [ "aarch64-cpu", "arm_gic", "arm_pl011", "axalloc", - "axconfig", + "axconfig 0.1.0", "axfs_ramfs", "axlog", "bitflags 2.6.0", @@ -435,6 +470,42 @@ dependencies = [ "x86_64 0.15.1", ] +[[package]] +name = "axhal" +version = "0.1.0" +source = "git+https://github.com/Starry-OS/axhal.git#769caa8b8749b324a1370a8da11c0e6a7597eedf" +dependencies = [ + "aarch64-cpu", + "arm_gic", + "arm_pl011", + "axconfig 0.1.0 (git+https://github.com/Starry-OS/axconfig.git)", + "axlog", + "bitflags 2.6.0", + "cfg-if", + "crate_interface", + "dw_apb_uart", + "either", + "handler_table", + "kernel_guard", + "lazy_init", + "log", + "memory_addr", + "of", + "page_table_entry", + "percpu", + "ratio", + "raw-cpuid 11.1.0", + "riscv 0.11.1", + "sbi-rt 0.0.3", + "spinlock", + "static_assertions", + "taskctx", + "tock-registers", + "x2apic", + "x86", + "x86_64 0.15.1", +] + [[package]] name = "axio" version = "0.1.0" @@ -469,15 +540,14 @@ dependencies = [ [[package]] name = "axmem" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axmem.git#2e66a8ad1a4f14f629d2a07e67abcf21f5216012" dependencies = [ "axalloc", - "axconfig", + "axconfig 0.1.0", "axerrno", "axfs", - "axhal", + "axhal 0.1.0", "axio", - "axsync", + "axsync 0.1.0", "elf_parser", "log", "page_table_entry", @@ -489,40 +559,38 @@ dependencies = [ [[package]] name = "axnet" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axnet.git#48d68eb8c32bfb1bb89977fbe19ca42a0d1fb7a9" dependencies = [ "axdriver", "axerrno", - "axhal", + "axhal 0.1.0", "axio", "axprocess", - "axsync", - "axtask", + "axsync 0.1.0", + "axtask 0.1.0", "cfg-if", "driver_net", "lazy_init", "log", - "smoltcp", + "smoltcp 0.11.0", "spin", ] [[package]] name = "axprocess" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axprocess.git#6ab9c7a7d41f43ecebcd6ee329bd9fa7edc763b8" dependencies = [ "axalloc", - "axconfig", + "axconfig 0.1.0", "axerrno", "axfs", "axfutex", - "axhal", + "axhal 0.1.0", "axio", "axlog", "axmem", - "axsignal", - "axsync", - "axtask", + "axsignal 0.1.0", + "axsync 0.1.0", + "axtask 0.1.0", "bitflags 2.6.0", "cfg-if", "elf_parser", @@ -535,19 +603,18 @@ dependencies = [ [[package]] name = "axruntime" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axruntime.git#3ff4e76febe8b92ef6f502b1260d05f3fdc498a4" dependencies = [ "axalloc", - "axconfig", + "axconfig 0.1.0", "axdisplay", "axdriver", "axfs", - "axhal", + "axhal 0.1.0", "axlog", "axmem", "axnet", "axprocess", - "axtask", + "axtask 0.1.0", "cfg-if", "crate_interface", "kernel_guard", @@ -558,9 +625,19 @@ dependencies = [ [[package]] name = "axsignal" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axsignal.git#2bd62ee3a0a5e7135803315db87df1edc51004ce" dependencies = [ - "axhal", + "axhal 0.1.0", + "bitflags 2.6.0", + "cfg-if", + "numeric-enum-macro", +] + +[[package]] +name = "axsignal" +version = "0.1.0" +source = "git+https://github.com/Starry-OS/axsignal.git#1cc27325ed3ce8477d10ed0c22af027ce85ca6d3" +dependencies = [ + "axhal 0.1.0 (git+https://github.com/Starry-OS/axhal.git)", "bitflags 2.6.0", "cfg-if", "numeric-enum-macro", @@ -569,19 +646,18 @@ dependencies = [ [[package]] name = "axstarry" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axstarry.git#a60752d10eb805a820436b86c429d621a95384ce" dependencies = [ "arch_boot", "axfeat", "axfs", "axlog", + "axtask 0.1.0", "linux_syscall_api", ] [[package]] name = "axstd" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axstd.git#0b0595b3f24a68009a47d120e5991b89a6c9f2d3" dependencies = [ "arceos_api", "arch_boot", @@ -591,13 +667,25 @@ dependencies = [ "spinlock", ] +[[package]] +name = "axsync" +version = "0.1.0" +dependencies = [ + "axhal 0.1.0", + "axsync 0.1.0", + "axtask 0.1.0", + "cfg-if", + "rand", + "spinlock", +] + [[package]] name = "axsync" version = "0.1.0" source = "git+https://github.com/Starry-OS/axsync.git#70651a7c8e918e6f6aced3014acfd16f209aa4c0" dependencies = [ - "axhal", - "axtask", + "axhal 0.1.0 (git+https://github.com/Starry-OS/axhal.git)", + "axtask 0.1.0 (git+https://github.com/Starry-OS/axtask.git)", "cfg-if", "spinlock", ] @@ -605,12 +693,13 @@ dependencies = [ [[package]] name = "axtask" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axtask.git#4ae6b15a574b5351ac3843d6ef97843164298341" dependencies = [ - "axconfig", - "axhal", + "axbacktrace", + "axconfig 0.1.0", + "axhal 0.1.0", "axlog", - "axsignal", + "axsignal 0.1.0", + "axtask 0.1.0", "cfg-if", "kernel_guard", "lazy_init", @@ -619,21 +708,38 @@ dependencies = [ "memory_addr", "numeric-enum-macro", "percpu", + "rand", "scheduler", "spinlock", "taskctx", "timer_list", ] +[[package]] +name = "axtask" +version = "0.1.0" +source = "git+https://github.com/Starry-OS/axtask.git#5c7f4e485a4ab08d51b3118828e3ee1552d54dc6" +dependencies = [ + "axbacktrace", + "axconfig 0.1.0 (git+https://github.com/Starry-OS/axconfig.git)", + "axhal 0.1.0 (git+https://github.com/Starry-OS/axhal.git)", + "axlog", + "axsignal 0.1.0 (git+https://github.com/Starry-OS/axsignal.git)", + "cfg-if", + "linked_list", + "log", + "numeric-enum-macro", + "taskctx", +] + [[package]] name = "axtrap" version = "0.1.0" -source = "git+https://github.com/Starry-OS/axtrap.git#f2529e64355db2c4df9561fd6603bf9eb9325cc4" dependencies = [ "aarch64-cpu", - "axhal", + "axhal 0.1.0", "axlog", - "axtask", + "axtask 0.1.0", "cfg-if", "handler_table", "kernel_guard", @@ -659,6 +765,17 @@ version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" +[[package]] +name = "bcm2835-sdhci" +version = "0.1.0" +source = "git+https://github.com/lhw2002426/bcm2835-sdhci.git?rev=e974f16#e974f168efa72b470a01f61bdef32240c66f54fc" +dependencies = [ + "aarch64-cpu", + "log", + "tock-registers", + "volatile 0.2.7", +] + [[package]] name = "bindgen" version = "0.69.4" @@ -668,7 +785,7 @@ dependencies = [ "bitflags 2.6.0", "cexpr", "clang-sys", - "itertools", + "itertools 0.12.1", "lazy_static", "lazycell", "log", @@ -678,7 +795,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.72", + "syn 2.0.77", "which", ] @@ -720,6 +837,18 @@ version = "3.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d084b0137aaa901caf9f1e8b21daa6aa24d41cd806e111335541eff9683bd6" +[[package]] +name = "buddy_system_allocator" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d44d578cadd17312c75e7d0ef489361f160ace58f7139aa32001fee1a51b89b5" + +[[package]] +name = "buddy_system_allocator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7913f22349ffcfc6ca0ca9a656ec26cfbba538ed49c31a273dff2c5d1ea83d9" + [[package]] name = "byteorder" version = "1.5.0" @@ -767,6 +896,12 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b396d1f76d455557e1218ec8066ae14bba60b4b36ecd55577ba979f5db7ecaa" +[[package]] +name = "core_detect" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" + [[package]] name = "crate_interface" version = "0.1.1" @@ -774,14 +909,30 @@ source = "git+https://github.com/Starry-OS/crate_interface.git#d27dd9608dbf04b31 dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] name = "critical-section" -version = "1.1.2" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f64009896348fc5af4222e9cf7d7d82a95a256c634ebcf61c53e4ea461422242" + +[[package]] +name = "cstr_core" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd98742e4fdca832d40cab219dc2e3048de17d873248f83f17df47c1bea70956" +dependencies = [ + "cty", + "memchr", +] + +[[package]] +name = "cty" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7059fff8937831a9ae6f0fe4d658ffabf58f2ca96aa9dec1c889f936f705f216" +checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "defmt" @@ -803,7 +954,7 @@ dependencies = [ "proc-macro-error", "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -818,8 +969,9 @@ dependencies = [ [[package]] name = "driver_block" version = "0.1.0" -source = "git+https://github.com/Starry-OS/driver_block.git#47e771d7d312ad7090d452a0ac95e1d617f13aca" +source = "git+https://github.com/Starry-OS/driver_block.git#077ab12e19b3bdea99b0c8bcb484ceef076965ce" dependencies = [ + "bcm2835-sdhci", "driver_common", "log", ] @@ -843,6 +995,8 @@ version = "0.1.0" source = "git+https://github.com/Starry-OS/driver_net.git#5d16bf2fe6eae2aa3b7d4f929162c07d949a6955" dependencies = [ "driver_common", + "e1000-driver", + "ixgbe-driver", "log", "spin", ] @@ -875,6 +1029,15 @@ dependencies = [ "tock-registers", ] +[[package]] +name = "e1000-driver" +version = "0.2.0" +source = "git+https://github.com/elliott10/e1000-driver.git?rev=7b2458e5#7b2458e5606909fd7116072cf07844db006559a0" +dependencies = [ + "log", + "volatile 0.3.0", +] + [[package]] name = "either" version = "1.13.0" @@ -933,17 +1096,6 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "361a90feb7004eca4019fb28352a9465666b24f840f5c3cddf0ff13920590b89" -[[package]] -name = "enumn" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.72", -] - [[package]] name = "equivalent" version = "1.0.1" @@ -960,6 +1112,15 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "ext4_rs" +version = "1.0.0" +source = "git+https://github.com/yuoo655/ext4_rs.git?rev=6bcc7f5#6bcc7f5d6382ba1940f29f9a15869f35fe77b5c0" +dependencies = [ + "bitflags 2.6.0", + "log", +] + [[package]] name = "fatfs" version = "0.4.0" @@ -1014,6 +1175,15 @@ name = "handler_table" version = "0.1.0" source = "git+https://github.com/Starry-OS/handler_table.git#d6495e7d835cbc999874f0ecf466ee1211447a79" +[[package]] +name = "hash32" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b0c35f58762feb77d74ebe43bdbc3210f09be9fe6742234d573bacc26ed92b67" +dependencies = [ + "byteorder", +] + [[package]] name = "hash32" version = "0.3.1" @@ -1038,13 +1208,26 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "heapless" +version = "0.7.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdc6457c0eb62c71aac4bc17216026d8410337c4126773b9c5daba343f17964f" +dependencies = [ + "atomic-polyfill", + "hash32 0.2.1", + "rustc_version", + "spin", + "stable_deref_trait", +] + [[package]] name = "heapless" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0bfb9eb618601c89945a70e254898da93b13be0388091d42117462b265bb3fad" dependencies = [ - "hash32", + "hash32 0.3.1", "stable_deref_trait", ] @@ -1059,14 +1242,23 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.6" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" +checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", "hashbrown 0.14.5", ] +[[package]] +name = "itertools" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "284f18f85651fe11e8a991b2adb42cb078325c996ed026d994719efcfca1d54b" +dependencies = [ + "either", +] + [[package]] name = "itertools" version = "0.12.1" @@ -1076,6 +1268,18 @@ dependencies = [ "either", ] +[[package]] +name = "ixgbe-driver" +version = "0.1.0" +source = "git+https://github.com/KuangjuX/ixgbe-driver.git?rev=8e5eb74#8e5eb741299d7d95c373ec745e39a1473fe84563" +dependencies = [ + "bit_field", + "core_detect", + "log", + "smoltcp 0.10.0", + "volatile 0.3.0", +] + [[package]] name = "kernel_guard" version = "0.1.0" @@ -1107,9 +1311,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.155" +version = "0.2.158" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" +checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" [[package]] name = "libloading" @@ -1135,22 +1339,21 @@ checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "linux_syscall_api" version = "0.1.0" -source = "git+https://github.com/Starry-OS/linux_syscall_api.git#bc828f3316e6b4560f5e79602b679c7d9d31d5ff" dependencies = [ - "axconfig", + "axconfig 0.1.0", "axerrno", "axfeat", "axfs", "axfutex", - "axhal", + "axhal 0.1.0", "axlog", "axmem", "axnet", "axprocess", "axruntime", - "axsignal", - "axsync", - "axtask", + "axsignal 0.1.0", + "axsync 0.1.0", + "axtask 0.1.0", "bitflags 2.6.0", "cfg-if", "lazy_init", @@ -1172,9 +1375,18 @@ dependencies = [ [[package]] name = "log" -version = "0.4.22" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" + +[[package]] +name = "lwext4_rust" +version = "0.2.0" +source = "git+https://github.com/elliott10/lwext4_rust.git#83489293ef4535672caee0c5755729f3e0315a96" +dependencies = [ + "log", + "printf-compat", +] [[package]] name = "managed" @@ -1274,7 +1486,7 @@ source = "git+https://github.com/mexus/numeric-enum-macro#20aef288b2ecd2381ab662 [[package]] name = "of" version = "0.1.0" -source = "git+https://github.com/Starry-OS/of.git#f54b1eeb959605978aa3cdccb014be7ddeba5bb8" +source = "git+https://github.com/Starry-OS/of.git#ae6dc82903a23f2ad7d959beccb7651efe21e935" dependencies = [ "fdt", "lazy_static", @@ -1332,17 +1544,38 @@ source = "git+https://github.com/Starry-OS/percpu_macros.git#b785b814c5489ac7043 dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] -name = "prettyplease" +name = "ppv-lite86" version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" +checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +dependencies = [ + "zerocopy", +] + +[[package]] +name = "prettyplease" +version = "0.2.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" dependencies = [ "proc-macro2", - "syn 2.0.72", + "syn 2.0.77", +] + +[[package]] +name = "printf-compat" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b002af28ffe3d3d67202ae717810a28125a494d5396debc43de01ee136ac404" +dependencies = [ + "bitflags 1.3.2", + "cstr_core", + "cty", + "itertools 0.9.0", ] [[package]] @@ -1380,9 +1613,9 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.36" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" dependencies = [ "proc-macro2", ] @@ -1393,6 +1626,18 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", "rand_core", ] @@ -1401,6 +1646,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] [[package]] name = "ratio" @@ -1427,9 +1675,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.5" +version = "1.10.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b91213439dad192326a0d7c6ee3955910425f441d7038e0d6933b0aec5c4517f" +checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" dependencies = [ "aho-corasick", "memchr", @@ -1493,11 +1741,20 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + [[package]] name = "rustix" -version = "0.38.34" +version = "0.38.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" +checksum = "3f55e80d50763938498dd5ebb18647174e0c76dc38c5505294bb224624f30f36" dependencies = [ "bitflags 2.6.0", "errno", @@ -1559,24 +1816,30 @@ version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" +[[package]] +name = "semver" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" + [[package]] name = "serde" -version = "1.0.204" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc76f558e0cbb2a839d37354c575f1dc3fdc6546b5be373ba43d95f231bf7c12" +checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.204" +version = "1.0.210" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" +checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -1585,16 +1848,38 @@ version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64" +[[package]] +name = "slab_allocator" +version = "0.3.1" +source = "git+https://github.com/arceos-org/slab_allocator.git#3c13499d664ccd36f66786985b753340aea57f5a" +dependencies = [ + "buddy_system_allocator 0.10.0", +] + +[[package]] +name = "smoltcp" +version = "0.10.0" +source = "git+https://github.com/rcore-os/smoltcp.git?rev=2ade274#2ade2747abc4d779d0836154b0413d13ce16cd5b" +dependencies = [ + "bitflags 1.3.2", + "byteorder", + "cfg-if", + "defmt", + "heapless 0.7.17", + "log", + "managed", +] + [[package]] name = "smoltcp" version = "0.11.0" -source = "git+https://github.com/rcore-os/smoltcp.git?rev=b7134a3#b7134a31442db149c2398b27f95a5d2b54414a4d" +source = "git+https://github.com/rcore-os/smoltcp.git?rev=8bf9a9a#8bf9a9a61ce9d50e72b71d541ecb24e29cc5450e" dependencies = [ "bitflags 1.3.2", "byteorder", "cfg-if", "defmt", - "heapless", + "heapless 0.8.0", "log", "managed", ] @@ -1655,9 +1940,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.72" +version = "2.0.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc4b9b9bf2add8093d3f2c0204471e951b2285580335de42f9d2534f3ae7a8af" +checksum = "9f35bcdf61fd8e7be6caf75f429fdca8beb3ed76584befb503b1569faee373ed" dependencies = [ "proc-macro2", "quote", @@ -1667,9 +1952,10 @@ dependencies = [ [[package]] name = "taskctx" version = "0.1.0" -source = "git+https://github.com/Starry-OS/taskctx.git#d7d646ca1f4cc2bd0466563b0563b2c321fb0929" +source = "git+https://github.com/Starry-OS/taskctx.git#8a3436e3668cd1ead02f88882f5391290ad9ca6f" dependencies = [ "aarch64-cpu", + "axconfig 0.1.0 (git+https://github.com/Starry-OS/axconfig.git)", "cfg-if", "log", "memory_addr", @@ -1696,7 +1982,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] [[package]] @@ -1718,9 +2004,9 @@ checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" [[package]] name = "toml_edit" -version = "0.22.18" +version = "0.22.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1490595c74d930da779e944f5ba2ecdf538af67df1a9848cbd156af43c1b7cf0" +checksum = "583c44c02ad26b0c3f3066fe629275e50627026c51ac2e595cca4c230ce1ce1d" dependencies = [ "indexmap", "toml_datetime", @@ -1747,12 +2033,11 @@ checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" [[package]] name = "virtio-drivers" -version = "0.7.5" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6a39747311dabb3d37807037ed1c3c38d39f99198d091b5b79ecd5c8d82f799" +checksum = "aa40e09453618c7a927c08c5a990497a2954da7c2aaa6c65e0d4f0fc975f6114" dependencies = [ "bitflags 2.6.0", - "enumn", "log", "zerocopy", ] @@ -1763,6 +2048,18 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" +[[package]] +name = "volatile" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b06ad3ed06fef1713569d547cdbdb439eafed76341820fb0e0344f29a41945" + +[[package]] +name = "volatile" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8e76fae08f03f96e166d2dfda232190638c10e0383841252416f9cfe2ae60e6" + [[package]] name = "volatile" version = "0.4.6" @@ -1862,9 +2159,9 @@ checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" [[package]] name = "winnow" -version = "0.6.16" +version = "0.6.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b480ae9340fc261e6be3e95a1ba86d54ae3f9171132a73ce8d4bbaf68339507c" +checksum = "68a9bda4691f099d435ad181000724da8e5899daa10713c2d432552b9ccd3a6f" dependencies = [ "memchr", ] @@ -1902,7 +2199,7 @@ dependencies = [ "bit_field", "bitflags 2.6.0", "rustversion", - "volatile", + "volatile 0.4.6", ] [[package]] @@ -1914,7 +2211,7 @@ dependencies = [ "bit_field", "bitflags 2.6.0", "rustversion", - "volatile", + "volatile 0.4.6", ] [[package]] @@ -1950,5 +2247,5 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn 2.0.72", + "syn 2.0.77", ] diff --git a/Cargo.toml b/Cargo.toml index fa2521f..1aeae64 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,5 +7,50 @@ lto = true lto = true [workspace] -members = ["apps/display", "apps/exception", "apps/helloworld", "apps/memtest", "apps/fs/shell", "apps/net/echoserver", "apps/net/httpclient", "apps/net/httpserver", "apps/net/udpserver", "apps/net/bwbench", "apps/task/parallel", "apps/task/sleep", "apps/task/yield", "apps/task/priority", "apps/task/tls", "apps/monolithic_userboot", "tools/axlibc"] + +members = [ + "modules/axalloc", + "modules/axconfig", + "modules/axdisplay", + "modules/axdriver", + "modules/axfs", + "modules/axhal", + "modules/axmem", + "modules/axnet", + "modules/axruntime", + "modules/axsync", + "modules/axtask", + "modules/axprocess", + "modules/axtrap", + "modules/arch_boot", + "modules/axfutex", + "modules/axsignal", + + "api/axfeat", + "api/arceos_api", + "api/arceos_posix_api", + "api/linux_syscall_api", + + "ulib/axstd", + "ulib/axstarry", + "tools/axlibc", + + "apps/display", + "apps/exception", + "apps/helloworld", + "apps/memtest", + "apps/fs/shell", + "apps/net/echoserver", + "apps/net/httpclient", + "apps/net/httpserver", + "apps/net/udpserver", + "apps/net/bwbench", + "apps/task/parallel", + "apps/task/sleep", + "apps/task/yield", + "apps/task/priority", + "apps/task/tls", + "apps/monolithic_userboot" +] + resolver = "2" diff --git a/Makefile b/Makefile index 4441f49..7d4be3c 100644 --- a/Makefile +++ b/Makefile @@ -169,9 +169,6 @@ else ifeq ($(PLATFORM_NAME), aarch64-rk3588j) include scripts/make/rk3588.mk endif -pre_update: - cargo update - build: $(OUT_DIR) $(OUT_BIN) disasm: diff --git a/api/arceos_api/Cargo.toml b/api/arceos_api/Cargo.toml index acd96a1..7df9a56 100644 --- a/api/arceos_api/Cargo.toml +++ b/api/arceos_api/Cargo.toml @@ -26,15 +26,15 @@ myfs = ["axfeat/myfs"] dummy-if-not-enabled = [] [dependencies] -axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } -axruntime = { git = "https://github.com/Starry-OS/axruntime.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } +axfeat = { path = "../axfeat" } +axruntime = { path = "../../modules/axruntime" } +axconfig = { path = "../../modules/axconfig" } axlog = { git = "https://github.com/Starry-OS/axlog.git" } axio = { git = "https://github.com/Starry-OS/axio.git" } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git", optional = true } -axtask = { git = "https://github.com/Starry-OS/axtask.git", optional = true } -axfs = { git = "https://github.com/Starry-OS/axfs.git", optional = true } -axnet = { git = "https://github.com/Starry-OS/axnet.git", optional = true } -axdisplay = { git = "https://github.com/Starry-OS/axdisplay.git", optional = true } +axhal = { path = "../../modules/axhal" } +axalloc = { path = "../../modules/axalloc", optional = true } +axtask = { path = "../../modules/axtask", optional = true } +axfs = { path = "../../modules/axfs", optional = true } +axnet = { path = "../../modules/axnet", optional = true } +axdisplay = { path = "../../modules/axdisplay", optional = true } diff --git a/api/arceos_posix_api/Cargo.toml b/api/arceos_posix_api/Cargo.toml index e6165ea..63af5c2 100644 --- a/api/arceos_posix_api/Cargo.toml +++ b/api/arceos_posix_api/Cargo.toml @@ -31,16 +31,16 @@ epoll = ["fd"] [dependencies] # ArceOS modules -axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } -axruntime = { git = "https://github.com/Starry-OS/axruntime.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } +axfeat = { path = "../axfeat" } +axruntime = { path = "../../modules/axruntime" } +axconfig = { path = "../../modules/axconfig" } axlog = { git = "https://github.com/Starry-OS/axlog.git" } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -axsync = { git = "https://github.com/Starry-OS/axsync.git" } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git", optional = true } -axtask = { git = "https://github.com/Starry-OS/axtask.git", optional = true } -axfs = { git = "https://github.com/Starry-OS/axfs.git", optional = true } -axnet = { git = "https://github.com/Starry-OS/axnet.git", optional = true } +axhal = { path = "../../modules/axhal" } +axsync = { path = "../../modules/axsync" } +axalloc = { path = "../../modules/axalloc", optional = true } +axtask = { path = "../../modules/axtask", optional = true } +axfs = { path = "../../modules/axfs", optional = true } +axnet = { path = "../../modules/axnet", optional = true } # Other crates axio = { git = "https://github.com/Starry-OS/axio.git" } diff --git a/api/arceos_posix_api/build.rs b/api/arceos_posix_api/build.rs index e0e8cfc..8365af2 100644 --- a/api/arceos_posix_api/build.rs +++ b/api/arceos_posix_api/build.rs @@ -80,7 +80,7 @@ typedef struct {{ } } let libc_dir = option_env!("AX_LIBC_DIR").unwrap_or("."); - println!("{}", format!("-I{}/include", libc_dir)); + println!("-I{}/include", libc_dir); let mut builder = bindgen::Builder::default() .header(in_file) .clang_arg(format!("-I{}/include", libc_dir)) diff --git a/api/arceos_posix_api/src/ctypes_gen.rs b/api/arceos_posix_api/src/ctypes_gen.rs index 9d8154c..2ad7249 100644 --- a/api/arceos_posix_api/src/ctypes_gen.rs +++ b/api/arceos_posix_api/src/ctypes_gen.rs @@ -1,4 +1,4 @@ -/* automatically generated by rust-bindgen 0.66.1 */ +/* automatically generated by rust-bindgen 0.69.4 */ pub const O_CREAT: u32 = 64; pub const O_EXCL: u32 = 128; @@ -1052,7 +1052,7 @@ fn bindgen_test_layout_timespec() { #[repr(C)] #[derive(Debug, Default, Copy, Clone)] pub struct pthread_mutex_t { - pub __l: [::core::ffi::c_long; 6usize], + pub __l: [::core::ffi::c_long; 3usize], } #[test] fn bindgen_test_layout_pthread_mutex_t() { @@ -1060,7 +1060,7 @@ fn bindgen_test_layout_pthread_mutex_t() { let ptr = UNINIT.as_ptr(); assert_eq!( ::core::mem::size_of::(), - 48usize, + 24usize, concat!("Size of: ", stringify!(pthread_mutex_t)) ); assert_eq!( diff --git a/api/axfeat/Cargo.toml b/api/axfeat/Cargo.toml index 0621aa2..18b82df 100644 --- a/api/axfeat/Cargo.toml +++ b/api/axfeat/Cargo.toml @@ -71,16 +71,16 @@ log-level-debug = ["axlog/log-level-debug"] log-level-trace = ["axlog/log-level-trace"] [dependencies] -axruntime = { git = "https://github.com/Starry-OS/axruntime.git" } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } +axruntime = { path = "../../modules/axruntime" } +axhal = { path = "../../modules/axhal" } axlog = { git = "https://github.com/Starry-OS/axlog.git" } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git", optional = true } -axdriver = { git = "https://github.com/Starry-OS/axdriver.git", optional = true } -axfs = { git = "https://github.com/Starry-OS/axfs.git", optional = true } -axnet = { git = "https://github.com/Starry-OS/axnet.git", optional = true } -axdisplay = { git = "https://github.com/Starry-OS/axdisplay.git", optional = true } -axsync = { git = "https://github.com/Starry-OS/axsync.git", optional = true } -axtask = { git = "https://github.com/Starry-OS/axtask.git", optional = true } -axprocess = { git = "https://github.com/Starry-OS/axprocess.git", optional = true } +axalloc = { path = "../../modules/axalloc", optional = true } +axdriver = { path = "../../modules/axdriver", optional = true } +axfs = { path = "../../modules/axfs", optional = true } +axnet = { path = "../../modules/axnet", optional = true } +axdisplay = { path = "../../modules/axdisplay", optional = true } +axsync = { path = "../../modules/axsync", optional = true } +axtask = { path = "../../modules/axtask", optional = true } +axprocess = { path = "../../modules/axprocess", optional = true } spinlock = { git = "https://github.com/Starry-OS/spinlock.git", optional = true } taskctx = { git = "https://github.com/Starry-OS/taskctx.git", optional = true } \ No newline at end of file diff --git a/api/linux_syscall_api/Cargo.toml b/api/linux_syscall_api/Cargo.toml index 6d160d0..654c62e 100644 --- a/api/linux_syscall_api/Cargo.toml +++ b/api/linux_syscall_api/Cargo.toml @@ -32,18 +32,18 @@ net = ["ip", "axnet/monolithic"] [dependencies] cfg-if = "1.0" axlog = { git = "https://github.com/Starry-OS/axlog.git" } -axfs = { git = "https://github.com/Starry-OS/axfs.git" } -axruntime = { git = "https://github.com/Starry-OS/axruntime.git" } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -axtask = { git = "https://github.com/Starry-OS/axtask.git" } -axnet = { git = "https://github.com/Starry-OS/axnet.git" } -axprocess = { git = "https://github.com/Starry-OS/axprocess.git" } -axsignal = { git = "https://github.com/Starry-OS/axsignal.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } -axsync = { git = "https://github.com/Starry-OS/axsync.git" } -axmem = { git = "https://github.com/Starry-OS/axmem.git" } -axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } -axfutex = { git = "https://github.com/Starry-OS/axfutex.git"} +axfs = { path = "../../modules/axfs" } +axruntime = { path = "../../modules/axruntime" } +axhal = { path = "../../modules/axhal" } +axtask = { path = "../../modules/axtask" } +axnet = { path = "../../modules/axnet" } +axprocess = { path = "../../modules/axprocess" } +axsignal = { path = "../../modules/axsignal" } +axconfig = { path = "../../modules/axconfig" } +axsync = { path = "../../modules/axsync" } +axmem = { path = "../../modules/axmem" } +axfeat = { path = "../axfeat" } +axfutex = { path = "../../modules/axfutex" } lazy_init = { git = "https://github.com/Starry-OS/lazy_init.git" } spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } diff --git a/api/linux_syscall_api/src/ctypes.rs b/api/linux_syscall_api/src/ctypes.rs index 2356e43..c930ceb 100644 --- a/api/linux_syscall_api/src/ctypes.rs +++ b/api/linux_syscall_api/src/ctypes.rs @@ -294,25 +294,6 @@ pub struct IoVec { #[allow(unused)] pub(crate) const FUTEX_BITSET_MATCH_ANY: u32 = 0xffffffff; -bitflags::bitflags! { - /// 对 futex 的操作 - #[derive(PartialEq, Eq)] - pub struct FutexFlags: i32 { - /// 检查用户地址 uaddr 处的值。如果不是要求的值则等待 wake - const WAIT = 0; - /// 唤醒最多 val 个在等待 uaddr 位置的线程。 - const WAKE = 1; - /// 将等待 uaddr 的线程移动到 uaddr2 - const REQUEUE = 3; - /// WAIT_BITSET - const WAIT_BITSET = 9; - /// WAKT_BITSET - const WAKE_BITSET = 10; - /// FUTEX_PRIVATE_FLAG - const FUTEX_PRIVATE_FLAG = 128; - } -} - numeric_enum_macro::numeric_enum! { #[repr(usize)] #[allow(non_camel_case_types)] diff --git a/api/linux_syscall_api/src/syscall_fs/ctype/pidfd.rs b/api/linux_syscall_api/src/syscall_fs/ctype/pidfd.rs index 70ad582..5d9677c 100644 --- a/api/linux_syscall_api/src/syscall_fs/ctype/pidfd.rs +++ b/api/linux_syscall_api/src/syscall_fs/ctype/pidfd.rs @@ -53,7 +53,7 @@ impl FileIO for PidFd { } fn get_status(&self) -> OpenFlags { - self.flags.lock().clone() + *self.flags.lock() } fn set_status(&self, flags: OpenFlags) -> bool { diff --git a/api/linux_syscall_api/src/syscall_fs/imp/ctl.rs b/api/linux_syscall_api/src/syscall_fs/imp/ctl.rs index a032cda..a14726c 100644 --- a/api/linux_syscall_api/src/syscall_fs/imp/ctl.rs +++ b/api/linux_syscall_api/src/syscall_fs/imp/ctl.rs @@ -473,7 +473,7 @@ pub fn syscall_ioctl(args: [usize; 6]) -> SyscallResult { let old_status = file.get_status(); let _ = file.set_status(old_status | OpenFlags::NON_BLOCK); } - return Ok(0); + Ok(0) } FIOCLEX => Ok(0), _ => Err(SyscallError::EOPNOTSUPP), diff --git a/api/linux_syscall_api/src/syscall_net/imp.rs b/api/linux_syscall_api/src/syscall_net/imp.rs index 98d8068..58a791d 100644 --- a/api/linux_syscall_api/src/syscall_net/imp.rs +++ b/api/linux_syscall_api/src/syscall_net/imp.rs @@ -665,7 +665,6 @@ pub fn syscall_socketpair(args: [usize; 6]) -> SyscallResult { Ok(0) } - /// return sockerpair read write pub fn make_socketpair(socket_type: usize) -> (Arc, Arc) { let s_type = SocketType::try_from(socket_type & SOCKET_TYPE_MASK).unwrap(); diff --git a/api/linux_syscall_api/src/syscall_net/socket.rs b/api/linux_syscall_api/src/syscall_net/socket.rs index 3e88297..605a7cf 100644 --- a/api/linux_syscall_api/src/syscall_net/socket.rs +++ b/api/linux_syscall_api/src/syscall_net/socket.rs @@ -427,9 +427,7 @@ impl TcpSocketOption { // TODO: achieve the real implementation of Ipv6Option impl Ipv6Option { pub fn set(&self, socket: &Socket, opt: &[u8]) -> SyscallResult { - match self { - _ => Ok(0), - } + Ok(0) } } @@ -856,8 +854,6 @@ pub unsafe fn socket_address_from(addr: *const u8, socket: &Socket) -> SocketAdd let addr = IpAddr::v4(a[0], a[1], a[2], a[3]); SocketAddr { addr, port } } - // TODO: support ipv6 - // Domain::AF_INET6 => {} } } /// Only support INET (ipv4) diff --git a/api/linux_syscall_api/src/syscall_task/imp/futex.rs b/api/linux_syscall_api/src/syscall_task/imp/futex.rs index 55c3348..791f350 100644 --- a/api/linux_syscall_api/src/syscall_task/imp/futex.rs +++ b/api/linux_syscall_api/src/syscall_task/imp/futex.rs @@ -31,22 +31,24 @@ pub fn syscall_futex(args: [usize; 6]) -> SyscallResult { 0 }; - let flags: i32 = futex_op_to_flag(futex_op); - // cmd determines the operation of futex - let cmd: i32 = futex_op & FUTEX_CMD_MASK; + let mut flags = FutexFlags::from_bits(futex_op).ok_or(SyscallError::EINVAL)?; + // TODO: shared futex and real time clock // It's Ok for ananonymous mmap to use private futex - if (flags & FLAGS_SHARED) != 0 { + if flags.contains(FutexFlags::PRIVATE) { + if flags.contains(FutexFlags::SHARED) { + return Err(SyscallError::EINVAL); + } + } else { + flags |= FutexFlags::SHARED; debug!( "shared futex is not supported, but it's ok for anonymous mmap to use private futex" ); } - if (flags & FLAGS_CLOCKRT) != 0 { - panic!("FUTEX_CLOCK_REALTIME is not supported"); - } - match cmd { - FUTEX_WAIT => { - val3 = FUTEX_BITSET_MATCH_ANY; + + match FutexOp::try_from(futex_op) { + Ok(FutexOp::WAIT) => { + val3 = FutexFlags::BITSET_MATCH_ANY.bits() as u32; // convert relative timeout to absolute timeout let deadline: Option = if timeout != 0 { Some(Duration::from_nanos(timeout as u64) + axhal::time::current_time()) @@ -55,7 +57,7 @@ pub fn syscall_futex(args: [usize; 6]) -> SyscallResult { }; futex_wait(uaddr.into(), flags, val, deadline, val3) } - FUTEX_WAIT_BITSET => { + Ok(FutexOp::WAIT_BITSET) => { let deadline: Option = if timeout != 0 { Some(Duration::from_nanos(timeout as u64)) } else { @@ -63,25 +65,25 @@ pub fn syscall_futex(args: [usize; 6]) -> SyscallResult { }; futex_wait(uaddr.into(), flags, val, deadline, val3) } - FUTEX_WAKE => futex_wake(uaddr.into(), flags, val), - FUTEX_WAKE_BITSET => futex_wake_bitset(uaddr.into(), flags, val, val3), - FUTEX_REQUEUE => futex_requeue(uaddr.into(), flags, val, uaddr2.into(), val2 as u32), - FUTEX_CMP_REQUEUE => { + Ok(FutexOp::WAKE) => futex_wake(uaddr.into(), flags, val), + Ok(FutexOp::WAKE_BITSET) => futex_wake_bitset(uaddr.into(), flags, val, val3), + Ok(FutexOp::REQUEUE) => futex_requeue(uaddr.into(), flags, val, uaddr2.into(), val2 as u32), + Ok(FutexOp::CMP_REQUEUE) => { error!("[linux_syscall_api] futex: unsupported futex operation: FUTEX_CMP_REQUEUE"); - return Err(SyscallError::ENOSYS); + Err(SyscallError::ENOSYS) } - FUTEX_WAKE_OP => { + Ok(FutexOp::WAKE_OP) => { // futex_wake(uaddr, flags, uaddr2, val, val2, val3) error!("[linux_syscall_api] futex: unsupported futex operation: FUTEX_WAKE_OP"); - return Err(SyscallError::ENOSYS); + Err(SyscallError::ENOSYS) } // TODO: priority-inheritance futex _ => { error!( "[linux_syscall_api] futex: unsupported futex operation: {}", - cmd + futex_op ); - return Err(SyscallError::ENOSYS); + Err(SyscallError::ENOSYS) } } // success anyway and reach here diff --git a/api/linux_syscall_api/src/syscall_task/imp/task.rs b/api/linux_syscall_api/src/syscall_task/imp/task.rs index d2f6c21..321a8de 100644 --- a/api/linux_syscall_api/src/syscall_task/imp/task.rs +++ b/api/linux_syscall_api/src/syscall_task/imp/task.rs @@ -538,7 +538,7 @@ pub fn syscall_setsid() -> SyscallResult { process.get_parent(), Mutex::new(process.memory_set.lock().clone()), process.get_heap_bottom(), - Arc::new(Mutex::new(String::from("/").into())), + Arc::new(Mutex::new(String::from("/"))), Arc::new(AtomicI32::new(0o022)), Arc::new(Mutex::new(process.fd_manager.fd_table.lock().clone())), ); @@ -662,7 +662,7 @@ pub fn syscall_prctl(args: [usize; 6]) -> SyscallResult { /// Sendthe signal sig to the target process referred to by pidfd pub fn syscall_pidfd_send_signal(args: [usize; 6]) -> SyscallResult { - let fd = args[0] as usize; + let fd = args[0]; let signum = args[1] as i32; axlog::warn!("Ignore the info arguments"); diff --git a/apps/display/Cargo.toml b/apps/display/Cargo.toml index c24e197..4cfc2ba 100644 --- a/apps/display/Cargo.toml +++ b/apps/display/Cargo.toml @@ -7,5 +7,5 @@ authors = ["Shiping Yuan "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["display"], optional = true } +axstd = { path = "../../ulib/axstd", features = ["display"], optional = true } embedded-graphics = "0.8" diff --git a/apps/exception/Cargo.toml b/apps/exception/Cargo.toml index d973de2..1be50f0 100644 --- a/apps/exception/Cargo.toml +++ b/apps/exception/Cargo.toml @@ -7,4 +7,4 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", optional = true } +axstd = { path = "../../ulib/axstd", optional = true } diff --git a/apps/fs/shell/Cargo.toml b/apps/fs/shell/Cargo.toml index 56ce651..9758ea4 100644 --- a/apps/fs/shell/Cargo.toml +++ b/apps/fs/shell/Cargo.toml @@ -14,4 +14,4 @@ default = [] axfs_vfs = { git = "https://github.com/Starry-OS/axfs_vfs.git", optional = true } axfs_ramfs = { git = "https://github.com/Starry-OS/axfs_ramfs.git", optional = true } crate_interface = { git = "https://github.com/Starry-OS/crate_interface.git", optional = true } -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["alloc", "fs"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["alloc", "fs"], optional = true } diff --git a/apps/helloworld/Cargo.toml b/apps/helloworld/Cargo.toml index d758f2d..9b759ec 100644 --- a/apps/helloworld/Cargo.toml +++ b/apps/helloworld/Cargo.toml @@ -7,4 +7,4 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", optional = true } +axstd = { path = "../../ulib/axstd", optional = true } diff --git a/apps/memtest/Cargo.toml b/apps/memtest/Cargo.toml index 2e3f93e..592b6c4 100644 --- a/apps/memtest/Cargo.toml +++ b/apps/memtest/Cargo.toml @@ -8,4 +8,4 @@ authors = ["Yuekai Jia "] [dependencies] rand = { version = "0.8", default-features = false, features = ["small_rng"] } -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["alloc"], optional = true } +axstd = { path = "../../ulib/axstd", features = ["alloc"], optional = true } diff --git a/apps/monolithic_userboot/Cargo.toml b/apps/monolithic_userboot/Cargo.toml index 057ad78..8465918 100644 --- a/apps/monolithic_userboot/Cargo.toml +++ b/apps/monolithic_userboot/Cargo.toml @@ -11,4 +11,4 @@ authors = ["Youjie Zheng "] batch = [] [dependencies] -axstarry = { git = "https://github.com/Starry-OS/axstarry.git" } +axstarry = { path = "../../ulib/axstarry" } diff --git a/apps/net/bwbench/Cargo.toml b/apps/net/bwbench/Cargo.toml index 1914c6f..d51c402 100644 --- a/apps/net/bwbench/Cargo.toml +++ b/apps/net/bwbench/Cargo.toml @@ -7,5 +7,5 @@ authors = ["ChengXiang Qi "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["net"] } -axnet = { git = "https://github.com/Starry-OS/axnet.git" } \ No newline at end of file +axstd = { path = "../../../ulib/axstd", features = ["net"] } +axnet = { path = "../../../modules/axnet" } \ No newline at end of file diff --git a/apps/net/echoserver/Cargo.toml b/apps/net/echoserver/Cargo.toml index 62d12a3..7698bf0 100644 --- a/apps/net/echoserver/Cargo.toml +++ b/apps/net/echoserver/Cargo.toml @@ -7,4 +7,4 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["alloc", "multitask", "net"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["alloc", "multitask", "net"], optional = true } diff --git a/apps/net/httpclient/Cargo.toml b/apps/net/httpclient/Cargo.toml index 8027f01..8efffa0 100644 --- a/apps/net/httpclient/Cargo.toml +++ b/apps/net/httpclient/Cargo.toml @@ -7,7 +7,7 @@ authors = ["Yuekai Jia ", "Dashuai Wu "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["alloc", "multitask", "net"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["alloc", "multitask", "net"], optional = true } diff --git a/apps/net/udpserver/Cargo.toml b/apps/net/udpserver/Cargo.toml index 9068162..0c6b86a 100644 --- a/apps/net/udpserver/Cargo.toml +++ b/apps/net/udpserver/Cargo.toml @@ -5,4 +5,4 @@ edition = "2021" authors = ["Dashuai Wu "] [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["net"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["net"], optional = true } diff --git a/apps/task/parallel/Cargo.toml b/apps/task/parallel/Cargo.toml index 668f462..ea93409 100644 --- a/apps/task/parallel/Cargo.toml +++ b/apps/task/parallel/Cargo.toml @@ -8,4 +8,4 @@ authors = ["Yuekai Jia "] [dependencies] rand = { version = "0.8", default-features = false, features = ["small_rng"] } -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["alloc", "multitask", "irq"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["alloc", "multitask", "irq"], optional = true } diff --git a/apps/task/priority/Cargo.toml b/apps/task/priority/Cargo.toml index d5c166f..5c4061a 100644 --- a/apps/task/priority/Cargo.toml +++ b/apps/task/priority/Cargo.toml @@ -11,4 +11,4 @@ sched_rr = ["axstd?/sched_rr"] sched_cfs = ["axstd?/sched_cfs"] [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["alloc", "multitask"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["alloc", "multitask"], optional = true } diff --git a/apps/task/sleep/Cargo.toml b/apps/task/sleep/Cargo.toml index 2512aca..2608c3d 100644 --- a/apps/task/sleep/Cargo.toml +++ b/apps/task/sleep/Cargo.toml @@ -7,4 +7,4 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["multitask", "irq"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["multitask", "irq"], optional = true } diff --git a/apps/task/tls/Cargo.toml b/apps/task/tls/Cargo.toml index b2638e0..28fc2e9 100644 --- a/apps/task/tls/Cargo.toml +++ b/apps/task/tls/Cargo.toml @@ -7,5 +7,5 @@ authors = ["Yuekai Jia "] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["tls", "alloc", "multitask"], optional = true } -axhal = { git = "https://github.com/Starry-OS/axhal.git", features = ["tls"] } \ No newline at end of file +axstd = { path = "../../../ulib/axstd", features = ["tls", "alloc", "multitask"], optional = true } +axhal = { path = "../../../modules/axhal", features = ["tls"] } \ No newline at end of file diff --git a/apps/task/yield/Cargo.toml b/apps/task/yield/Cargo.toml index cd3e8c2..b8d775b 100644 --- a/apps/task/yield/Cargo.toml +++ b/apps/task/yield/Cargo.toml @@ -11,4 +11,4 @@ sched_rr = ["axstd?/sched_rr"] sched_cfs = ["axstd?/sched_cfs"] [dependencies] -axstd = { git = "https://github.com/Starry-OS/axstd.git", features = ["multitask"], optional = true } +axstd = { path = "../../../ulib/axstd", features = ["multitask"], optional = true } diff --git a/modules/arch_boot/Cargo.toml b/modules/arch_boot/Cargo.toml index 9a9da01..d1b3782 100644 --- a/modules/arch_boot/Cargo.toml +++ b/modules/arch_boot/Cargo.toml @@ -17,17 +17,17 @@ default = [] [dependencies] cfg-if = "1.0" -log = "0.4" -linux_syscall_api = { git = "https://github.com/Starry-OS/linux_syscall_api.git", optional = true } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -axtrap = { git = "https://github.com/Starry-OS/axtrap.git" } -axruntime = { git = "https://github.com/Starry-OS/axruntime.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git", optional = true } +log = "0.4.21" +linux_syscall_api = { path = "../../api/linux_syscall_api", optional = true } +axhal = { path = "../axhal" } +axtrap = { path = "../axtrap" } +axruntime = { path = "../axruntime" } +axconfig = { path = "../axconfig" } +axalloc = { path = "../axalloc", optional = true } axlog = { git = "https://github.com/Starry-OS/axlog.git" } [build-dependencies] -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } +axconfig = { path = "../axconfig" } [target.'cfg(target_arch = "x86_64")'.dependencies] x86 = "0.52" diff --git a/modules/arch_boot/src/lib.rs b/modules/arch_boot/src/lib.rs index d119e4f..ac364b5 100644 --- a/modules/arch_boot/src/lib.rs +++ b/modules/arch_boot/src/lib.rs @@ -16,6 +16,7 @@ mod mp; #[link_section = ".bss.stack"] pub(crate) static mut BOOT_STACK: [u8; TASK_STACK_SIZE] = [0; TASK_STACK_SIZE]; +/// Get the pointer to the boot stack of this core #[no_mangle] pub extern "C" fn current_boot_stack() -> *mut u8 { unsafe { @@ -35,7 +36,7 @@ pub extern "C" fn current_boot_stack() -> *mut u8 { if sp >= stack_low && sp < stack_high { log::debug!("get sp {:#x} in boot_stack", sp); - return BOOT_STACK.as_mut_ptr() + return BOOT_STACK.as_mut_ptr(); } #[cfg(feature = "smp")] @@ -43,5 +44,4 @@ pub extern "C" fn current_boot_stack() -> *mut u8 { #[cfg(not(feature = "smp"))] return 0 as *mut u8; } - } diff --git a/modules/arch_boot/src/mp.rs b/modules/arch_boot/src/mp.rs index f329de7..f50767d 100644 --- a/modules/arch_boot/src/mp.rs +++ b/modules/arch_boot/src/mp.rs @@ -33,8 +33,8 @@ pub(crate) unsafe fn mp_boot_stack(sp: usize) -> *mut u8 { if sp >= stack_low && sp < stack_high { log::info!("get sp {:#x} in second boot_stack", sp); - return SECONDARY_BOOT_STACK[i].as_mut_ptr() + return SECONDARY_BOOT_STACK[i].as_mut_ptr(); } } - return 0 as *mut u8; + core::ptr::null_mut::() } diff --git a/modules/axalloc/Cargo.toml b/modules/axalloc/Cargo.toml index ecdc597..6fc6321 100644 --- a/modules/axalloc/Cargo.toml +++ b/modules/axalloc/Cargo.toml @@ -17,7 +17,7 @@ slab = ["allocator/slab"] buddy = ["allocator/buddy"] [dependencies] -log = "0.4" +log = "0.4.21" cfg-if = "1.0" spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } memory_addr = { git = "https://github.com/Starry-OS/memory_addr.git" } diff --git a/modules/axconfig/.gitignore b/modules/axconfig/.gitignore new file mode 100644 index 0000000..6985cf1 --- /dev/null +++ b/modules/axconfig/.gitignore @@ -0,0 +1,14 @@ +# Generated by Cargo +# will have compiled files and executables +debug/ +target/ + +# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries +# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html +Cargo.lock + +# These are backup files generated by rustfmt +**/*.rs.bk + +# MSVC Windows builds of rustc generate these, which store debugging information +*.pdb diff --git a/modules/axconfig/Cargo.toml b/modules/axconfig/Cargo.toml new file mode 100644 index 0000000..9c231f9 --- /dev/null +++ b/modules/axconfig/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "axconfig" +version = "0.1.0" +edition = "2021" +authors = ["Yuekai Jia "] +description = "Platform-specific constants and parameters for ArceOS" +license = "GPL-3.0-or-later OR Apache-2.0" +homepage = "https://github.com/rcore-os/arceos" +repository = "https://github.com/rcore-os/arceos/tree/main/modules/axconfig" +documentation = "https://rcore-os.github.io/arceos/axconfig/index.html" +keywords = ["Starry"] + +[build-dependencies] +toml_edit = "0.22" +serde = "1.0" diff --git a/modules/axconfig/build.rs b/modules/axconfig/build.rs new file mode 100644 index 0000000..8722607 --- /dev/null +++ b/modules/axconfig/build.rs @@ -0,0 +1,171 @@ +use std::io::{Result, Write}; +use std::path::{Path, PathBuf}; +use toml_edit::{Decor, DocumentMut, Item, Table, Value}; + +fn resolve_config_path(platform: Option<&str>) -> Result { + let root_dir = PathBuf::from(std::env!("AX_WORK_DIR")); + let config_dir = root_dir.join("platforms"); + + let builtin_platforms = std::fs::read_dir(&config_dir)? + .filter_map(|e| { + e.unwrap() + .file_name() + .to_str()? + .strip_suffix(".toml") + .map(String::from) + }) + .collect::>(); + + let path = match platform { + None | Some("") => "defconfig.toml".into(), + Some(plat) if builtin_platforms.contains(&plat.to_string()) => { + config_dir.join(format!("{plat}.toml")) + } + Some(plat) => { + let path = PathBuf::from(&plat); + if path.is_absolute() { + path + } else { + root_dir.join(plat) + } + } + }; + + Ok(path) +} + +fn get_comments<'a>(config: &'a Table, key: &str) -> Option<&'a str> { + config + .key(key) + .and_then(|k| k.leaf_decor().prefix()) + .and_then(|s| s.as_str()) + .map(|s| s.trim()) +} + +fn add_config(config: &mut Table, key: &str, item: Item, comments: Option<&str>) { + config.insert(key, item); + if let Some(comm) = comments { + if let Some(mut dst) = config.key_mut(key) { + *dst.leaf_decor_mut() = Decor::new(comm, ""); + } + } +} + +fn load_config_toml(config_path: &Path) -> Result { + let config_content = std::fs::read_to_string(config_path)?; + let toml = config_content + .parse::() + .expect("failed to parse config file") + .as_table() + .clone(); + Ok(toml) +} + +fn gen_config_rs(config_path: &Path) -> Result> { + fn is_num(s: &str) -> bool { + let s = s.replace('_', ""); + if s.parse::().is_ok() { + true + } else if let Some(s) = s.strip_prefix("0x") { + usize::from_str_radix(s, 16).is_ok() + } else { + false + } + } + + // Load TOML config file + let mut config = if config_path == Path::new("defconfig.toml") { + load_config_toml(config_path)? + } else { + // Set default values for missing items + let defconfig = load_config_toml(Path::new("defconfig.toml"))?; + let mut config = load_config_toml(config_path)?; + + for (key, item) in defconfig.iter() { + if !config.contains_key(key) { + add_config( + &mut config, + key, + item.clone(), + get_comments(&defconfig, key), + ); + } + } + config + }; + + add_config( + &mut config, + "smp", + toml_edit::value(std::env::var("AX_SMP").unwrap_or("1".into())), + Some("# Number of CPUs"), + ); + + // Generate config.rs + let mut output = Vec::new(); + writeln!( + output, + "// Platform constants and parameters for {}.", + config["platform"].as_str().unwrap(), + )?; + writeln!(output, "// Generated by build.rs, DO NOT edit!\n")?; + + for (key, item) in config.iter() { + let var_name = key.to_uppercase().replace('-', "_"); + if let Item::Value(value) = item { + let comments = get_comments(&config, key) + .unwrap_or_default() + .replace('#', "///"); + match value { + Value::String(s) => { + writeln!(output, "{comments}")?; + let s = s.value(); + if is_num(s) { + writeln!(output, "pub const {var_name}: usize = {s};")?; + } else { + writeln!(output, "pub const {var_name}: &str = \"{s}\";")?; + } + } + Value::Array(regions) => { + if key != "mmio-regions" && key != "virtio-mmio-regions" && key != "pci-ranges" + { + continue; + } + writeln!(output, "{comments}")?; + writeln!(output, "pub const {var_name}: &[(usize, usize)] = &[")?; + for r in regions.iter() { + let r = r.as_array().unwrap(); + writeln!( + output, + " ({}, {}),", + r.get(0).unwrap().as_str().unwrap(), + r.get(1).unwrap().as_str().unwrap() + )?; + } + writeln!(output, "];")?; + } + _ => {} + } + } + } + + Ok(output) +} + +fn main() -> Result<()> { + let platform = option_env!("AX_PLATFORM"); + let config_path = resolve_config_path(platform)?; + + println!("Reading config file: {:?}", config_path); + let config_rs = gen_config_rs(&config_path)?; + + let out_dir = std::env::var("OUT_DIR").unwrap(); + let out_path = Path::new(&out_dir).join("config.rs"); + println!("Generating config file: {}", out_path.display()); + std::fs::write(out_path, config_rs)?; + + println!("cargo:rerun-if-changed={}", config_path.display()); + println!("cargo:rerun-if-env-changed=AX_PLATFORM"); + println!("cargo:rerun-if-env-changed=AX_SMP"); + Ok(()) +} diff --git a/modules/axconfig/defconfig.toml b/modules/axconfig/defconfig.toml new file mode 100644 index 0000000..cf98d89 --- /dev/null +++ b/modules/axconfig/defconfig.toml @@ -0,0 +1,57 @@ +# Architecture identifier. +arch = "unknown" +# Platform identifier. +platform = "dummy" +# Platform family. +family = "dummy" + +# Base address of the whole physical memory. +phys-memory-base = "0" +# Size of the whole physical memory. +phys-memory-size = "0" +# Base physical address of the kernel image. +kernel-base-paddr = "0" +# Base virtual address of the kernel image. +kernel-base-vaddr = "0" + +# Linear mapping offset, for quick conversions between physical and virtual +# addresses. +phys-virt-offset = "0" +# MMIO regions with format (`base_paddr`, `size`). +mmio-regions = [] +# VirtIO MMIO regions with format (`base_paddr`, `size`). +virtio-mmio-regions = [] +# Base physical address of the PCIe ECAM space. +pci-ecam-base = "0" +# End PCI bus number. +pci-bus-end = "0" +# PCI device memory ranges. +pci-ranges = [] + +# Timer interrupt frequency in Hz. +timer-frequency = "0" + +# Stack size of each task. +task-stack-size = "0x40000" # 256 K + +# Number of timer ticks per second (Hz). A timer tick may contain several timer +# interrupts. +ticks-per-sec = "100" + +# Number of CPUs +smp = "1" + +# Testcase memory start address. +testcase-memory-start = "0" +# Testcase memory size. +testcase-memory-size = "0" +# The base address of the user heap. +user-heap-base = "0" +# The base address of the user stack. And the stack bottom is `user-stack-top + max-user-stack-size`. +user-stack-top = "0" +# The size of the user heap. +max-user-heap-size = "0" +# The size of the user stack. +max-user-stack-size = "0" +# The base address of the signal trampoline. +signal-trampoline = "0" \ No newline at end of file diff --git a/modules/axconfig/src/config_dummy.rs b/modules/axconfig/src/config_dummy.rs new file mode 100644 index 0000000..9938254 --- /dev/null +++ b/modules/axconfig/src/config_dummy.rs @@ -0,0 +1,40 @@ +//! Platform constants and parameters for dummy. +//! Generated by build.rs, DO NOT edit! + +/// Stack size of each task. +pub const TASK_STACK_SIZE: usize = 0x40000; +/// Number of timer ticks per second (Hz). A timer tick may contain several timer +/// interrupts. +pub const TICKS_PER_SEC: usize = 100; +/// Architecture identifier. +pub const ARCH: &str = "unknown"; +/// Platform identifier. +pub const PLATFORM: &str = "dummy"; +/// Base address of the whole physical memory. +pub const PHYS_MEMORY_BASE: usize = 0; +/// Size of the whole physical memory. +pub const PHYS_MEMORY_SIZE: usize = 0; +/// Base physical address of the kernel image. +pub const KERNEL_BASE_PADDR: usize = 0; +/// Base virtual address of the kernel image. +pub const KERNEL_BASE_VADDR: usize = 0; +/// Linear mapping offset, for quick conversions between physical and virtual +/// addresses. +pub const PHYS_VIRT_OFFSET: usize = 0; +/// MMIO regions with format (`base_paddr`, `size`). +pub const MMIO_REGIONS: &[(usize, usize)] = &[ +]; +/// VirtIO MMIO regions with format (`base_paddr`, `size`). +pub const VIRTIO_MMIO_REGIONS: &[(usize, usize)] = &[ +]; +/// Base physical address of the PCIe ECAM space. +pub const PCI_ECAM_BASE: usize = 0; +/// End PCI bus number. +pub const PCI_BUS_END: usize = 0; +/// PCI device memory ranges. +pub const PCI_RANGES: &[(usize, usize)] = &[ +]; +/// Timer interrupt frequency in Hz. +pub const TIMER_FREQUENCY: usize = 0; +/// Number of CPUs +pub const SMP: usize = 1; diff --git a/modules/axconfig/src/config_pc_x86.rs b/modules/axconfig/src/config_pc_x86.rs new file mode 100644 index 0000000..1798641 --- /dev/null +++ b/modules/axconfig/src/config_pc_x86.rs @@ -0,0 +1,45 @@ +//! Platform constants and parameters for pc-x86. +//! Generated by build.rs, DO NOT edit! + +/// Stack size of each task. +pub const TASK_STACK_SIZE: usize = 0x40000; +/// Number of timer ticks per second (Hz). A timer tick may contain several timer +/// interrupts. +pub const TICKS_PER_SEC: usize = 100; +/// Architecture identifier. +pub const ARCH: &str = "x86_64"; +/// Platform identifier. +pub const PLATFORM: &str = "pc-x86"; +/// Base address of the whole physical memory. +pub const PHYS_MEMORY_BASE: usize = 0; +/// Size of the whole physical memory. +pub const PHYS_MEMORY_SIZE: usize = 0x800_0000; +/// Base physical address of the kernel image. +pub const KERNEL_BASE_PADDR: usize = 0x20_0000; +/// Base virtual address of the kernel image. +pub const KERNEL_BASE_VADDR: usize = 0xffff_ff80_0020_0000; +/// Linear mapping offset, for quick conversions between physical and virtual +/// addresses. +pub const PHYS_VIRT_OFFSET: usize = 0xffff_ff80_0000_0000; +/// MMIO regions with format (`base_paddr`, `size`). +pub const MMIO_REGIONS: &[(usize, usize)] = &[ + (0xb000_0000, 0x1000_0000), + (0xfe00_0000, 0xc0_0000), + (0xfec0_0000, 0x1000), + (0xfed0_0000, 0x1000), + (0xfee0_0000, 0x1000), +]; +/// VirtIO MMIO regions with format (`base_paddr`, `size`). +pub const VIRTIO_MMIO_REGIONS: &[(usize, usize)] = &[ +]; +/// Base physical address of the PCIe ECAM space (should read from ACPI 'MCFG' table). +pub const PCI_ECAM_BASE: usize = 0xb000_0000; +/// End PCI bus number. +pub const PCI_BUS_END: usize = 0xff; +/// PCI device memory ranges (not used on x86). +pub const PCI_RANGES: &[(usize, usize)] = &[ +]; +/// Timer interrupt frequencyin Hz. +pub const TIMER_FREQUENCY: usize = 4_000_000_000; +/// Number of CPUs +pub const SMP: usize = 1; diff --git a/modules/axconfig/src/config_qemu_virt_aarch64.rs b/modules/axconfig/src/config_qemu_virt_aarch64.rs new file mode 100644 index 0000000..aabcee0 --- /dev/null +++ b/modules/axconfig/src/config_qemu_virt_aarch64.rs @@ -0,0 +1,86 @@ +//! Platform constants and parameters for qemu-virt-aarch64. +//! Generated by build.rs, DO NOT edit! + +/// Stack size of each task. +pub const TASK_STACK_SIZE: usize = 0x40000; +/// Number of timer ticks per second (Hz). A timer tick may contain several timer +/// interrupts. +pub const TICKS_PER_SEC: usize = 100; +/// Architecture identifier. +pub const ARCH: &str = "aarch64"; +/// Platform identifier. +pub const PLATFORM: &str = "qemu-virt-aarch64"; +/// Base address of the whole physical memory. +pub const PHYS_MEMORY_BASE: usize = 0x4000_0000; +/// Size of the whole physical memory. +pub const PHYS_MEMORY_SIZE: usize = 0x800_0000; +/// Base physical address of the kernel image. +pub const KERNEL_BASE_PADDR: usize = 0x4008_0000; +/// Base virtual address of the kernel image. +pub const KERNEL_BASE_VADDR: usize = 0xffff_0000_4008_0000; +/// Linear mapping offset, for quick conversions between physical and virtual +/// addresses. +pub const PHYS_VIRT_OFFSET: usize = 0xffff_0000_0000_0000; +/// MMIO regions with format (`base_paddr`, `size`). +pub const MMIO_REGIONS: &[(usize, usize)] = &[ + (0x0900_0000, 0x1000), + (0x0800_0000, 0x2_0000), + (0x0a00_0000, 0x4000), + (0x1000_0000, 0x2eff_0000), + (0x40_1000_0000, 0x1000_0000), +]; +/// VirtIO MMIO regions with format (`base_paddr`, `size`). +pub const VIRTIO_MMIO_REGIONS: &[(usize, usize)] = &[ + (0x0a00_0000, 0x200), + (0x0a00_0200, 0x200), + (0x0a00_0400, 0x200), + (0x0a00_0600, 0x200), + (0x0a00_0800, 0x200), + (0x0a00_0a00, 0x200), + (0x0a00_0c00, 0x200), + (0x0a00_0e00, 0x200), + (0x0a00_1000, 0x200), + (0x0a00_1200, 0x200), + (0x0a00_1400, 0x200), + (0x0a00_1600, 0x200), + (0x0a00_1800, 0x200), + (0x0a00_1a00, 0x200), + (0x0a00_1c00, 0x200), + (0x0a00_1e00, 0x200), + (0x0a00_3000, 0x200), + (0x0a00_2200, 0x200), + (0x0a00_2400, 0x200), + (0x0a00_2600, 0x200), + (0x0a00_2800, 0x200), + (0x0a00_2a00, 0x200), + (0x0a00_2c00, 0x200), + (0x0a00_2e00, 0x200), + (0x0a00_3000, 0x200), + (0x0a00_3200, 0x200), + (0x0a00_3400, 0x200), + (0x0a00_3600, 0x200), + (0x0a00_3800, 0x200), + (0x0a00_3a00, 0x200), + (0x0a00_3c00, 0x200), + (0x0a00_3e00, 0x200), +]; +/// Base physical address of the PCIe ECAM space. +pub const PCI_ECAM_BASE: usize = 0x40_1000_0000; +/// End PCI bus number (`bus-range` property in device tree). +pub const PCI_BUS_END: usize = 0xff; +/// PCI device memory ranges (`ranges` property in device tree). +pub const PCI_RANGES: &[(usize, usize)] = &[ + (0x3ef_f0000, 0x1_0000), + (0x1000_0000, 0x2eff_0000), + (0x80_0000_0000, 0x80_0000_0000), +]; +/// UART Address +pub const UART_PADDR: usize = 0x0900_0000; + +pub const UART_IRQ_NUM: usize = 33; +/// GICC Address +pub const GICC_PADDR: usize = 0x0801_0000; + +pub const GICD_PADDR: usize = 0x0800_0000; +/// Number of CPUs +pub const SMP: usize = 1; diff --git a/modules/axconfig/src/config_qemu_virt_riscv.rs b/modules/axconfig/src/config_qemu_virt_riscv.rs new file mode 100644 index 0000000..15fcd37 --- /dev/null +++ b/modules/axconfig/src/config_qemu_virt_riscv.rs @@ -0,0 +1,67 @@ +//! Platform constants and parameters for qemu-virt-riscv. +//! Generated by build.rs, DO NOT edit! + +/// Stack size of each task. +pub const TASK_STACK_SIZE: usize = 0x40000; +/// Number of timer ticks per second (Hz). A timer tick may contain several timer +/// interrupts. +pub const TICKS_PER_SEC: usize = 100; +/// Architecture identifier. +pub const ARCH: &str = "riscv64"; +/// Platform identifier. +pub const PLATFORM: &str = "qemu-virt-riscv"; +/// Base address of the whole physical memory. +pub const PHYS_MEMORY_BASE: usize = 0x8000_0000; +/// Size of the pre physical memory. +/// If now it is in patch, then it will have the other physical memory. +pub const PHYS_MEMORY_SIZE: usize = 0x800_0000; +/// Base physical address of the kernel image. +pub const KERNEL_BASE_PADDR: usize = 0x8020_0000; +/// Base virtual address of the kernel image. +pub const KERNEL_BASE_VADDR: usize = 0xffff_ffc0_8020_0000; +/// Linear mapping offset, for quick conversions between physical and virtual +/// addresses. +pub const PHYS_VIRT_OFFSET: usize = 0xffff_ffc0_0000_0000; +/// user memory +pub const USER_MEMORY_START: usize = 0x1000; + +pub const USER_MEMORY_LIMIT: usize = 0xffff_ffff; +/// Testcase memory +pub const TESTCASE_MEMORY_START: usize = 0x9000_0000; + +pub const TESTCASE_MEMORY_SIZE: usize = 0x400_0000; + +pub const QEMU_MEMORY_SIZE: usize = 0x4000_0000; +/// MMIO regions with format (`base_paddr`, `size`). +pub const MMIO_REGIONS: &[(usize, usize)] = &[ + (0x0c00_0000, 0x21_0000), + (0x1000_0000, 0x1000), + (0x1000_1000, 0x8000), + (0x3000_0000, 0x1000_0000), + (0x4000_0000, 0x4000_0000), +]; +/// VirtIO MMIO regions with format (`base_paddr`, `size`). +pub const VIRTIO_MMIO_REGIONS: &[(usize, usize)] = &[ + (0x1000_1000, 0x1000), + (0x1000_2000, 0x1000), + (0x1000_3000, 0x1000), + (0x1000_4000, 0x1000), + (0x1000_5000, 0x1000), + (0x1000_6000, 0x1000), + (0x1000_7000, 0x1000), + (0x1000_8000, 0x1000), +]; +/// Base physical address of the PCIe ECAM space. +pub const PCI_ECAM_BASE: usize = 0x3000_0000; +/// End PCI bus number (`bus-range` property in device tree). +pub const PCI_BUS_END: usize = 0xff; +/// PCI device memory ranges (`ranges` property in device tree). +pub const PCI_RANGES: &[(usize, usize)] = &[ + (0x0300_0000, 0x1_0000), + (0x4000_0000, 0x4000_0000), + (0x4_0000_0000, 0x4_0000_0000), +]; +/// Timer interrupt frequency in Hz. +pub const TIMER_FREQUENCY: usize = 1000_000; +/// Number of CPUs +pub const SMP: usize = 1; diff --git a/modules/axconfig/src/config_raspi4_aarch64.rs b/modules/axconfig/src/config_raspi4_aarch64.rs new file mode 100644 index 0000000..e8e3a2e --- /dev/null +++ b/modules/axconfig/src/config_raspi4_aarch64.rs @@ -0,0 +1,41 @@ +//! Platform constants and parameters for raspi4-aarch64. +//! Generated by build.rs, DO NOT edit! + +/// Stack size of each task. +pub const TASK_STACK_SIZE: usize = 0x40000; +/// Number of timer ticks per second (Hz). A timer tick may contain several timer +/// interrupts. +pub const TICKS_PER_SEC: usize = 100; +/// Architecture identifier. +pub const ARCH: &str = "aarch64"; +/// Platform identifier. +pub const PLATFORM: &str = "raspi4-aarch64"; +/// Base address of the whole physical memory. +pub const PHYS_MEMORY_BASE: usize = 0x0; +/// Size of the whole physical memory. +pub const PHYS_MEMORY_SIZE: usize = 0xFC00_0000; +/// Base physical address of the kernel image. +pub const KERNEL_BASE_PADDR: usize = 0x8_0000; +/// Base virtual address of the kernel image. +pub const KERNEL_BASE_VADDR: usize = 0xffff_0000_0008_0000; +/// Linear mapping offset, for quick conversions between physical and virtual +/// addresses. +pub const PHYS_VIRT_OFFSET: usize = 0xffff_0000_0000_0000; +/// MMIO regions with format (`base_paddr`, `size`). +pub const MMIO_REGIONS: &[(usize, usize)] = &[ + (0xFE20_1000, 0x1000), + (0xFF84_1000, 0x8000), +]; + +pub const VIRTIO_MMIO_REGIONS: &[(usize, usize)] = &[ +]; +/// UART Address +pub const UART_PADDR: usize = 0xFE20_1000; + +pub const UART_IRQ_NUM: usize = 153; +/// GIC Address +pub const GICC_PADDR: usize = 0xFF84_2000; + +pub const GICD_PADDR: usize = 0xFF84_1000; +/// Number of CPUs +pub const SMP: usize = 1; diff --git a/modules/axconfig/src/lib.rs b/modules/axconfig/src/lib.rs new file mode 100644 index 0000000..b40ac4f --- /dev/null +++ b/modules/axconfig/src/lib.rs @@ -0,0 +1,22 @@ +//! Platform-specific constants and parameters for [ArceOS]. +//! +//! Currently supported platforms can be found in the [platforms] directory of +//! the [ArceOS] root. +//! +//! [ArceOS]: https://github.com/rcore-os/arceos +//! [platforms]: https://github.com/rcore-os/arceos/tree/main/platforms + +#![no_std] + +#[rustfmt::skip] +mod config { + include!(concat!(env!("OUT_DIR"), "/config.rs")); +} + +pub use config::*; + +/// End address of the whole physical memory. +pub const PHYS_MEMORY_END: usize = PHYS_MEMORY_BASE + PHYS_MEMORY_SIZE; + +/// user memory +pub const USER_MEMORY_START: usize = 0x1000; diff --git a/modules/axdisplay/.gitrepo b/modules/axdisplay/.gitrepo deleted file mode 100644 index 96d1440..0000000 --- a/modules/axdisplay/.gitrepo +++ /dev/null @@ -1,12 +0,0 @@ -; DO NOT EDIT (unless you know what you are doing) -; -; This subdirectory is a git "subrepo", and this file is maintained by the -; git-subrepo command. See https://github.com/ingydotnet/git-subrepo#readme -; -[subrepo] - remote = git@github.com:Starry-OS/axdisplay.git - branch = main - commit = 803cda0fbfb5d3761d8d40d177fd6e19a8eba21f - parent = d9a6cf127dc1d7017c2842717ab873ca13678417 - method = merge - cmdver = 0.4.9 diff --git a/modules/axdriver/Cargo.toml b/modules/axdriver/Cargo.toml index 24dab1c..9efc028 100644 --- a/modules/axdriver/Cargo.toml +++ b/modules/axdriver/Cargo.toml @@ -35,7 +35,7 @@ img = ["ramdisk", "dep:axconfig"] default = ["bus-pci"] [dependencies] -log = "0.4" +log = "0.4.21" cfg-if = "1.0" driver_common = { git = "https://github.com/Starry-OS/driver_common.git" } driver_block = { git = "https://github.com/Starry-OS/driver_block.git", optional = true } @@ -43,6 +43,6 @@ driver_net = { git = "https://github.com/Starry-OS/driver_net.git", optional = t driver_display = { git = "https://github.com/Starry-OS/driver_display.git", optional = true } driver_pci = { git = "https://github.com/Starry-OS/driver_pci.git", optional = true } driver_virtio = { git = "https://github.com/Starry-OS/driver_virtio.git", optional = true } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git", optional = true } -axhal = { git = "https://github.com/Starry-OS/axhal.git", optional = true } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git", optional = true } +axalloc = { path = "../axalloc", optional = true } +axhal = { path = "../axhal", optional = true } +axconfig = { path = "../axconfig", optional = true } diff --git a/modules/axdriver/src/drivers.rs b/modules/axdriver/src/drivers.rs index f31b54e..de743a0 100644 --- a/modules/axdriver/src/drivers.rs +++ b/modules/axdriver/src/drivers.rs @@ -86,7 +86,6 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(net_dev = "ixgbe")] { use crate::ixgbe::IxgbeHalImpl; - use axhal::mem::phys_to_virt; pub struct IxgbeDriver; register_net_driver!(IxgbeDriver, driver_net::ixgbe::IxgbeNic); impl DriverProbe for IxgbeDriver { @@ -113,7 +112,7 @@ cfg_if::cfg_if! { .. } => { let ixgbe_nic = IxgbeNic::::init( - phys_to_virt((address as usize).into()).into(), + axhal::mem::phys_to_virt((address as usize).into()).into(), size as usize ) .expect("failed to initialize ixgbe device"); @@ -134,7 +133,7 @@ cfg_if::cfg_if! { cfg_if::cfg_if! { if #[cfg(net_dev = "e1000")] { use axalloc::global_allocator; - use axhal::mem::{phys_to_virt, virt_to_phys}; + use axhal::mem::virt_to_phys; use driver_net::e1000::{E1000Nic, KernelFunc}; use core::alloc::Layout; @@ -166,6 +165,7 @@ cfg_if::cfg_if! { impl DriverProbe for E1000Driver { + #[cfg(bus = "pci")] fn probe_pci( root: &mut driver_pci::PciRoot, bdf: driver_pci::DeviceFunction, @@ -186,7 +186,7 @@ cfg_if::cfg_if! { let kfn = KernelFuncObj; let nic = E1000Nic::::init( kfn, - phys_to_virt((address as usize).into()).into() + axhal::mem::phys_to_virt((address as usize).into()).into() ) .expect("failed to initialize e1000 device"); return Some(AxDeviceEnum::from_net(nic)); diff --git a/modules/axfs/Cargo.toml b/modules/axfs/Cargo.toml index 2ca6d46..b10c9d7 100644 --- a/modules/axfs/Cargo.toml +++ b/modules/axfs/Cargo.toml @@ -28,22 +28,22 @@ another_ext4 = ["dep:another_ext4", "devfs", "ramfs", "procfs", "sysfs"] default = ["devfs", "ramfs", "fatfs", "procfs", "sysfs"] [dependencies] -log = "0.4" +log = "0.4.21" cfg-if = "1.0" lazy_init = { git = "https://github.com/Starry-OS/lazy_init.git" } capability = { git = "https://github.com/Starry-OS/capability.git" } driver_block = { git = "https://github.com/Starry-OS/driver_block.git" } axio = { git = "https://github.com/Starry-OS/axio.git", features = ["alloc"] } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git", optional = true } +axconfig = { path = "../axconfig", optional = true } axfs_vfs = { git = "https://github.com/Starry-OS/axfs_vfs.git" } axfs_devfs = { git = "https://github.com/Starry-OS/axfs_devfs.git", optional = true } axfs_ramfs = { git = "https://github.com/Starry-OS/axfs_ramfs.git", optional = true } ext4_rs = { git = "https://github.com/yuoo655/ext4_rs.git", rev= "6bcc7f5", optional = true } lwext4_rust = { git = "https://github.com/elliott10/lwext4_rust.git", optional = true } another_ext4 = { git = "https://github.com/LJxTHUCS/another_ext4.git", branch = "main", features = ["block_cache"], optional = true } -axdriver = { git = "https://github.com/Starry-OS/axdriver.git", features = ["block"] } -axsync = { git = "https://github.com/Starry-OS/axsync.git" } +axdriver = { path = "../axdriver", features = ["block"] } +axsync = { path = "../axsync" } crate_interface = { git = "https://github.com/Starry-OS/crate_interface.git", optional = true } bitflags = "2.6" @@ -60,7 +60,7 @@ features = [ # no std ] [dev-dependencies] -axdriver = { git = "https://github.com/Starry-OS/axdriver.git", features = ["block", "ramdisk"] } +axdriver = { path = "../axdriver", features = ["block", "ramdisk"] } driver_block = { git = "https://github.com/Starry-OS/driver_block.git", features = ["ramdisk"] } -axsync = { git = "https://github.com/Starry-OS/axsync.git", features = ["multitask"] } -axtask = { git = "https://github.com/Starry-OS/axtask.git", features = ["test"] } +axsync = { path = "../axsync", features = ["multitask"] } +axtask = { path = "../axtask", features = ["test"] } diff --git a/modules/axfs/src/dev.rs b/modules/axfs/src/dev.rs index 5977e04..825be7f 100644 --- a/modules/axfs/src/dev.rs +++ b/modules/axfs/src/dev.rs @@ -119,4 +119,3 @@ impl Disk { Ok(buf.len()) } } - diff --git a/modules/axfutex/Cargo.toml b/modules/axfutex/Cargo.toml index 9581676..629cdd4 100644 --- a/modules/axfutex/Cargo.toml +++ b/modules/axfutex/Cargo.toml @@ -14,12 +14,14 @@ monolithic = ["fs" ,"axfs/monolithic", "axhal/monolithic", "axtask/monolithic"] default = ["monolithic"] [dependencies] -axfs = { git = "https://github.com/Starry-OS/axfs.git", optional = true } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -log = "0.4" +axfs = { path = "../axfs", optional = true } +axhal = { path = "../axhal" } +log = "0.4.21" axlog = { git = "https://github.com/Starry-OS/axlog.git" } -axtask = { git = "https://github.com/Starry-OS/axtask.git" } +axtask = { path = "../axtask" } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } -axsync = {git = "https://github.com/Starry-OS/axsync.git"} +axsync = { path = "../axsync" } hashbrown = "0.11" lazy_static = "1.5.0" +bitflags = "2.6" +numeric-enum-macro = { git = "https://github.com/mexus/numeric-enum-macro" } \ No newline at end of file diff --git a/modules/axfutex/src/flags.rs b/modules/axfutex/src/flags.rs index 5094575..9e0d170 100644 --- a/modules/axfutex/src/flags.rs +++ b/modules/axfutex/src/flags.rs @@ -1,40 +1,44 @@ -#![allow(unused)] -// Futex options -pub const FUTEX_PRIVATE_FLAG: i32 = 128; -pub const FUTEX_CLOCK_REALTIME: i32 = 256; -pub const FUTEX_CMD_MASK: i32 = !(FUTEX_PRIVATE_FLAG | FUTEX_CLOCK_REALTIME); +//! Futex operations and flags for posix syscall. +//! +//! Details are listed in -// Futex operations -pub const FUTEX_WAIT: i32 = 0; -pub const FUTEX_WAKE: i32 = 1; -pub const FUTEX_FD: i32 = 2; -pub const FUTEX_REQUEUE: i32 = 3; -pub const FUTEX_CMP_REQUEUE: i32 = 4; -pub const FUTEX_WAKE_OP: i32 = 5; -pub const FUTEX_LOCK_PI: i32 = 6; -pub const FUTEX_UNLOCK_PI: i32 = 7; -pub const FUTEX_TRYLOCK_PI: i32 = 8; -pub const FUTEX_WAIT_BITSET: i32 = 9; -pub const FUTEX_WAKE_BITSET: i32 = 10; -pub const FUTEX_WAIT_REQUEUE_PI: i32 = 11; -pub const FUTEX_CMP_REQUEUE_PI: i32 = 12; -pub const FUTEX_LOCK_PI2: i32 = 13; - -// Futex flags -pub const FLAGS_SHARED: i32 = 0x10; -pub const FLAGS_CLOCKRT: i32 = 0x20; - - -// Futex bitset -pub const FUTEX_BITSET_MATCH_ANY: u32 = u32::MAX; +numeric_enum_macro::numeric_enum! { + #[repr(i32)] + #[allow(missing_docs)] + #[allow(non_camel_case_types)] + #[derive(Eq, PartialEq, Debug, Copy, Clone)] + /// Futex operation for posix syscall listed in + /// + pub enum FutexOp { + WAIT = 0, + WAKE = 1, + FD = 2, + REQUEUE = 3, + CMP_REQUEUE = 4, + WAKE_OP = 5, + LOCK_PI = 6, + UNLOCK_PI = 7, + TRYLOCK_PI = 8, + WAIT_BITSET = 9, + WAKE_BITSET = 10, + WAIT_REQUEUE_PI = 11, + CMP_REQUEUE_PI = 12, + LOCK_PI2 = 13, + } +} -pub fn futex_op_to_flag(op: i32) -> i32 { - let mut flags = 0; - if (op & FUTEX_PRIVATE_FLAG) == 0 { - flags = flags | FLAGS_SHARED; - } - if (op & FUTEX_CLOCK_REALTIME) != 0 { - flags = flags | FLAGS_CLOCKRT; +bitflags::bitflags! { + #[allow(missing_docs)] + #[derive(PartialEq, Eq, Debug)] + /// Futex flags for posix syscall listed in + pub struct FutexFlags: i32 { + /// Futex is shared with other processes + const SHARED = 0x10; + /// Futex is process-private and not shared with another process + const PRIVATE = 128; + /// Futex is associated with CLOCK_REALTIME + const CLOCK_REALTIME = 256; + /// If the futex contains this flag,it will matche any bitset value + const BITSET_MATCH_ANY = -1; } - return flags; } diff --git a/modules/axfutex/src/futex.rs b/modules/axfutex/src/futex.rs index da3f59e..74ff0c3 100644 --- a/modules/axfutex/src/futex.rs +++ b/modules/axfutex/src/futex.rs @@ -1,6 +1,6 @@ use axtask::AxTaskRef; -/// Kernel futex +/// Kernel futex pub struct FutexQ { /// The `val` of the futex /// the task in the queue waiting for the same futex may have different `val` @@ -14,7 +14,7 @@ pub struct FutexQ { impl FutexQ { /// Create a new futex queue pub fn new(key: FutexKey, task: AxTaskRef, bitset: u32) -> Self { - Self { key, task, bitset} + Self { key, task, bitset } } /// check if the futex queues matches the key pub fn match_key(&self, key: &FutexKey) -> bool { @@ -39,7 +39,12 @@ pub struct FutexKey { } impl FutexKey { + #[allow(missing_docs)] pub fn new(pid: u64, aligned: usize, offset: u32) -> Self { - Self { pid: pid as u32, aligned: aligned as u32, offset } + Self { + pid: pid as u32, + aligned: aligned as u32, + offset, + } } -} \ No newline at end of file +} diff --git a/modules/axfutex/src/jhash.rs b/modules/axfutex/src/jhash.rs index 2a08683..64b5835 100644 --- a/modules/axfutex/src/jhash.rs +++ b/modules/axfutex/src/jhash.rs @@ -1,7 +1,7 @@ const JHASH_INITVAL: u32 = 0xdeadbeef; #[inline(always)] -pub fn jhash_mix(a: &mut u32, b: &mut u32, c: &mut u32) { +pub(crate) fn jhash_mix(a: &mut u32, b: &mut u32, c: &mut u32) { *a = a.wrapping_sub(*c); *a ^= c.rotate_left(4); *c = c.wrapping_add(*b); @@ -27,7 +27,7 @@ pub fn jhash_mix(a: &mut u32, b: &mut u32, c: &mut u32) { *b = b.wrapping_add(*a); } -pub fn jhash_final(mut a: u32, mut b: u32, mut c: u32) -> u32 { +pub(crate) fn jhash_final(mut a: u32, mut b: u32, mut c: u32) -> u32 { c ^= b; c = c.wrapping_sub(b.rotate_left(14)); @@ -51,9 +51,7 @@ pub fn jhash_final(mut a: u32, mut b: u32, mut c: u32) -> u32 { c } - - -pub fn jhash2(mut key: &[u32], initval: u32) -> u32 { +pub(crate) fn jhash2(mut key: &[u32], initval: u32) -> u32 { let mut a = JHASH_INITVAL .wrapping_add(key.len() as u32) .wrapping_add(initval); diff --git a/modules/axfutex/src/lib.rs b/modules/axfutex/src/lib.rs index e60fe3f..cab93bf 100644 --- a/modules/axfutex/src/lib.rs +++ b/modules/axfutex/src/lib.rs @@ -1,10 +1,15 @@ -//! 支持 futex 相关的 syscall +//! A module to implement futexes with jhash algorithm. +//! +//! Futex is a fast userspace mutex, which is used to implement synchronization primitives. #![cfg_attr(all(not(test), not(doc)), no_std)] #![feature(stmt_expr_attributes)] extern crate alloc; pub mod flags; -pub mod queues; -pub mod futex; -mod jhash; \ No newline at end of file +mod futex; +mod jhash; +mod queues; +pub use queues::{futex_hash, FUTEXQUEUES}; + +pub use futex::{FutexKey, FutexQ}; diff --git a/modules/axfutex/src/queues.rs b/modules/axfutex/src/queues.rs index 948a45a..3fbd36c 100644 --- a/modules/axfutex/src/queues.rs +++ b/modules/axfutex/src/queues.rs @@ -1,8 +1,8 @@ -use alloc::collections::VecDeque; +use crate::futex::{FutexKey, FutexQ}; use alloc::boxed::Box; +use alloc::collections::VecDeque; use alloc::vec::Vec; use axlog::info; -use crate::futex::{FutexKey, FutexQ}; use crate::jhash::jhash2; use axsync::Mutex; @@ -12,12 +12,12 @@ use lazy_static::lazy_static; const FUTEX_HASH_SIZE: usize = 256; lazy_static! { - // can only hold the mutex through `futex_hash_bucket` - pub static ref FUTEXQUEUES: FutexQueues = { + /// A global futex queues, which stores all futex queues + /// It only holds the mutex through `futex_hash_bucket` + pub static ref FUTEXQUEUES: FutexQueues = { info!("Initializing futex queues"); - let futex_queues = FutexQueues::new(FUTEX_HASH_SIZE); - futex_queues - }; + FutexQueues::new(FUTEX_HASH_SIZE) + }; } #[allow(unused)] @@ -28,7 +28,11 @@ pub fn display_futexqueues() { let hash_bucket = FUTEXQUEUES.buckets[i].lock(); if !hash_bucket.is_empty() { for futex_q in hash_bucket.iter() { - axlog::warn!("task {} is still wait for {:?}", futex_q.task.id().as_u64(), futex_q.key); + axlog::warn!( + "task {} is still wait for {:?}", + futex_q.task.id().as_u64(), + futex_q.key + ); } } drop(hash_bucket); @@ -48,15 +52,13 @@ impl FutexQueues { } Self { buckets: buckets.into_boxed_slice(), - } + } } } -pub fn futex_hash(futex_key: &FutexKey) -> usize{ +/// Hash a [`FutexKey`] to a bucket index +pub fn futex_hash(futex_key: &FutexKey) -> usize { let key = &[futex_key.pid, futex_key.aligned, futex_key.offset]; let hash = jhash2(key, key[2]); - let index = hash as usize & (FUTEX_HASH_SIZE - 1); - index + hash as usize & (FUTEX_HASH_SIZE - 1) } - - diff --git a/modules/axhal/Cargo.toml b/modules/axhal/Cargo.toml index 4077486..0d1e466 100644 --- a/modules/axhal/Cargo.toml +++ b/modules/axhal/Cargo.toml @@ -21,13 +21,13 @@ monolithic = ["paging", "dep:axfs_ramfs"] default = [] [dependencies] -log = "0.4" +log = "0.4.21" cfg-if = "1.0" bitflags = "2.6" static_assertions = "1.1.0" axlog = { git = "https://github.com/Starry-OS/axlog.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git", optional = true } +axconfig = { path = "../axconfig" } +axalloc = { path = "../axalloc", optional = true } kernel_guard = { git = "https://github.com/Starry-OS/kernel_guard.git" } spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } ratio = { git = "https://github.com/Starry-OS/ratio.git" } @@ -61,4 +61,4 @@ arm_pl011 = { git = "https://github.com/Starry-OS/arm_pl011.git" } dw_apb_uart = { git = "https://github.com/Starry-OS/dw_apb_uart.git" } [build-dependencies] -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } +axconfig = { path = "../axconfig" } diff --git a/modules/axhal/src/platform/x86_pc/time.rs b/modules/axhal/src/platform/x86_pc/time.rs index bca87da..252351a 100644 --- a/modules/axhal/src/platform/x86_pc/time.rs +++ b/modules/axhal/src/platform/x86_pc/time.rs @@ -1,7 +1,7 @@ use raw_cpuid::CpuId; #[cfg(feature = "irq")] -const LAPIC_TICKS_PER_SEC: u64 = 1_000_000_00; // TODO: need to calibrate +const LAPIC_TICKS_PER_SEC: u64 = 1_000_000_000; // TODO: need to calibrate #[cfg(feature = "irq")] static mut NANOS_TO_LAPIC_TICKS_RATIO: ratio::Ratio = ratio::Ratio::zero(); diff --git a/modules/axmem/Cargo.toml b/modules/axmem/Cargo.toml index db00eab..5091f1c 100644 --- a/modules/axmem/Cargo.toml +++ b/modules/axmem/Cargo.toml @@ -14,14 +14,14 @@ monolithic = ["axfs/monolithic"] default = [] [dependencies] -log = "0.4" -axhal = { git = "https://github.com/Starry-OS/axhal.git", features = ["paging"] } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } +log = "0.4.21" +axhal = { path = "../axhal", features = ["paging"] } +axalloc = { path = "../axalloc" } +axconfig = { path = "../axconfig" } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } -axfs = { git = "https://github.com/Starry-OS/axfs.git" } +axfs = { path = "../axfs" } axio = { git = "https://github.com/Starry-OS/axio.git" } -axsync = { git = "https://github.com/Starry-OS/axsync.git" } +axsync = { path = "../axsync" } spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } xmas-elf = "0.9.0" riscv = "0.10" diff --git a/modules/axnet/Cargo.toml b/modules/axnet/Cargo.toml index 6b91e17..abcd9c6 100644 --- a/modules/axnet/Cargo.toml +++ b/modules/axnet/Cargo.toml @@ -21,18 +21,18 @@ ip = [] default = ["smoltcp"] [dependencies] -log = "0.4" +log = "0.4.21" cfg-if = "1.0" spin = "0.9" driver_net = { git = "https://github.com/Starry-OS/driver_net.git" } lazy_init = { git = "https://github.com/Starry-OS/lazy_init.git" } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -axsync = { git = "https://github.com/Starry-OS/axsync.git" } -axtask = { git = "https://github.com/Starry-OS/axtask.git" } -axdriver = { git = "https://github.com/Starry-OS/axdriver.git", features = ["net"] } +axhal = { path = "../axhal" } +axsync = { path = "../axsync" } +axtask = { path = "../axtask" } +axdriver = { path = "../axdriver", features = ["net"] } axio = { git = "https://github.com/Starry-OS/axio.git" } -axprocess = { git = "https://github.com/Starry-OS/axprocess.git", optional = true } +axprocess = { path = "../axprocess", optional = true } [dependencies.smoltcp] git = "https://github.com/rcore-os/smoltcp.git" diff --git a/modules/axnet/src/lib.rs b/modules/axnet/src/lib.rs index b027459..691e49f 100644 --- a/modules/axnet/src/lib.rs +++ b/modules/axnet/src/lib.rs @@ -38,7 +38,9 @@ pub use self::net_impl::{ }; pub use self::net_impl::{bench_receive, bench_transmit}; pub use smoltcp::time::Duration; -pub use smoltcp::wire::{IpAddress as IpAddr, IpEndpoint as SocketAddr, Ipv4Address as Ipv4Addr, Ipv6Address as Ipv6Addr}; +pub use smoltcp::wire::{ + IpAddress as IpAddr, IpEndpoint as SocketAddr, Ipv4Address as Ipv4Addr, Ipv6Address as Ipv6Addr, +}; use axdriver::{prelude::*, AxDeviceContainer}; diff --git a/modules/axnet/src/smoltcp_impl/listen_table.rs b/modules/axnet/src/smoltcp_impl/listen_table.rs index f1f841a..7fa9e96 100644 --- a/modules/axnet/src/smoltcp_impl/listen_table.rs +++ b/modules/axnet/src/smoltcp_impl/listen_table.rs @@ -92,7 +92,7 @@ impl ListenTable { let idx = syn_queue .iter() .enumerate() - .find_map(|(idx, &handle)| is_connected(handle).then(|| idx)) + .find_map(|(idx, &handle)| is_connected(handle).then_some(idx)) .ok_or(AxError::WouldBlock)?; // wait for connection if idx > 0 { warn!( diff --git a/modules/axnet/src/smoltcp_impl/mod.rs b/modules/axnet/src/smoltcp_impl/mod.rs index 19293f9..2fdf49e 100644 --- a/modules/axnet/src/smoltcp_impl/mod.rs +++ b/modules/axnet/src/smoltcp_impl/mod.rs @@ -148,11 +148,9 @@ impl<'a> SocketSetWrapper<'a> { } pub fn poll_interfaces(&self) { - let timestamp = - Instant::from_micros_const((current_time_nanos() / NANOS_PER_MICROS) as i64); #[cfg(feature = "monolithic")] LOOPBACK.lock().poll( - timestamp, + Instant::from_micros_const((current_time_nanos() / NANOS_PER_MICROS) as i64), LOOPBACK_DEV.lock().deref_mut(), &mut self.0.lock(), ); diff --git a/modules/axprocess/Cargo.toml b/modules/axprocess/Cargo.toml index 3874863..743c018 100644 --- a/modules/axprocess/Cargo.toml +++ b/modules/axprocess/Cargo.toml @@ -19,18 +19,18 @@ default = ["monolithic"] [dependencies] cfg-if = "1.0" spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } -axtask = { git = "https://github.com/Starry-OS/axtask.git" } -axsync = { git = "https://github.com/Starry-OS/axsync.git" } -axmem = { git = "https://github.com/Starry-OS/axmem.git" } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git" } +axtask = { path = "../axtask" } +axsync = { path = "../axsync" } +axmem = { path = "../axmem" } +axalloc = { path = "../axalloc" } axio = { git = "https://github.com/Starry-OS/axio.git", features = ["alloc"] } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } +axhal = { path = "../axhal" } axlog = { git = "https://github.com/Starry-OS/axlog.git" } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } -axfs = { git = "https://github.com/Starry-OS/axfs.git", optional = true } -axsignal = { git = "https://github.com/Starry-OS/axsignal.git" } -axfutex = { git = "https://github.com/Starry-OS/axfutex.git" } +axconfig = { path = "../axconfig" } +axfs = { path = "../axfs", optional = true } +axsignal = { path = "../axsignal" } +axfutex = { path = "../axfutex" } riscv = "0.10" bitflags = "2.0" lazy_static = { version = "1.4", features = ["spin_no_std"] } diff --git a/modules/axprocess/src/api.rs b/modules/axprocess/src/api.rs index aeab73e..f2be728 100644 --- a/modules/axprocess/src/api.rs +++ b/modules/axprocess/src/api.rs @@ -10,6 +10,7 @@ use alloc::{ }; use axconfig::{MAX_USER_HEAP_SIZE, MAX_USER_STACK_SIZE, USER_HEAP_BASE, USER_STACK_TOP}; use axerrno::{AxError, AxResult}; +use axfutex::flags::FutexFlags; use axhal::mem::VirtAddr; use axhal::paging::MappingFlags; use axhal::time::{current_time_nanos, NANOS_PER_MICROS, NANOS_PER_SEC}; @@ -41,7 +42,7 @@ pub fn init_kernel_process() { 0, Mutex::new(Arc::new(Mutex::new(MemorySet::new_empty()))), 0, - Arc::new(Mutex::new(String::from("/").into())), + Arc::new(Mutex::new(String::from("/"))), Arc::new(AtomicI32::new(0o022)), Arc::new(Mutex::new(vec![])), )); @@ -83,8 +84,8 @@ pub fn exit_current_task(exit_code: i32) -> ! { let parent = process.get_parent(); if parent != KERNEL_PROCESS_ID { // send exit signal - let signal = if exit_signal.is_some() { - exit_signal.unwrap() + let signal = if let Some(exit_signal) = exit_signal { + exit_signal } else { SignalNo::SIGCHLD }; @@ -101,7 +102,7 @@ pub fn exit_current_task(exit_code: i32) -> ! { { unsafe { *(clear_child_tid as *mut i32) = 0; - let _ = futex_wake(clear_child_tid.into(), 0, 1); + let _ = futex_wake(clear_child_tid.into(), FutexFlags::empty(), 1); } } } diff --git a/modules/axprocess/src/futex.rs b/modules/axprocess/src/futex.rs index 3bec2fe..5b5e927 100644 --- a/modules/axprocess/src/futex.rs +++ b/modules/axprocess/src/futex.rs @@ -1,11 +1,7 @@ //! 实现与futex相关的系统调用 use crate::{current_process, current_task, signal::current_have_signals, yield_now_task}; use axerrno::LinuxError; -use axfutex::{ - flags::FLAGS_SHARED, - futex::{FutexKey, FutexQ}, - queues::{futex_hash, FUTEXQUEUES}, -}; +use axfutex::{flags::FutexFlags, futex_hash, FutexKey, FutexQ, FUTEXQUEUES}; use axhal::mem::VirtAddr; use axlog::info; use core::time::Duration; @@ -13,7 +9,7 @@ use core::time::Duration; extern crate alloc; -pub type AxSyscallResult = Result; +type AxSyscallResult = Result; /// waiting queue which stores tasks waiting for futex variable //pub static WAIT_FOR_FUTEX: WaitQueue = WaitQueue::new(); @@ -34,7 +30,7 @@ impl FutexRobustList { } } -pub fn futex_get_value_locked(vaddr: VirtAddr) -> AxSyscallResult { +fn futex_get_value_locked(vaddr: VirtAddr) -> AxSyscallResult { let process = current_process(); if process.manual_alloc_for_lazy(vaddr).is_ok() { let real_futex_val = unsafe { (vaddr.as_usize() as *const u32).read_volatile() }; @@ -44,8 +40,8 @@ pub fn futex_get_value_locked(vaddr: VirtAddr) -> AxSyscallResult { } } -pub fn get_futex_key(uaddr: VirtAddr, flags: i32) -> FutexKey { - if flags & FLAGS_SHARED != 0 { +fn get_futex_key(uaddr: VirtAddr, flags: &FutexFlags) -> FutexKey { + if flags.contains(FutexFlags::SHARED) { /* Todo: after implement inode layer let inode = uaddr.get_inode(); let page_index = uaddr.get_page_index(); @@ -56,18 +52,21 @@ pub fn get_futex_key(uaddr: VirtAddr, flags: i32) -> FutexKey { let pid = 0; let aligned = uaddr.align_down_4k().as_usize(); let offset = uaddr.align_offset_4k() as u32; - return FutexKey::new(pid, aligned, offset); + FutexKey::new(pid, aligned, offset) } else { let pid = current_process().pid(); let aligned = uaddr.align_down_4k().as_usize(); let offset = uaddr.align_offset_4k() as u32; - return FutexKey::new(pid, aligned, offset); + FutexKey::new(pid, aligned, offset) } } +/// Wait on a futex variable +/// +/// Details: pub fn futex_wait( vaddr: VirtAddr, - flags: i32, + flags: FutexFlags, expected_val: u32, deadline: Option, bitset: u32, @@ -84,7 +83,7 @@ pub fn futex_wait( // we may be victim of spurious wakeups, so we need to loop loop { - let key = get_futex_key(vaddr, flags); + let key = get_futex_key(vaddr, &flags); let real_futex_val = futex_get_value_locked(vaddr)?; if expected_val != real_futex_val as u32 { return Err(LinuxError::EAGAIN); @@ -138,14 +137,18 @@ pub fn futex_wait( } } -// no need to check the bitset, faster than futex_wake_bitset -pub fn futex_wake(vaddr: VirtAddr, flags: i32, nr_waken: u32) -> AxSyscallResult { +/// Wake up tasks waiting on a futex variable +/// +/// Details: +/// +/// Tips: There is no need to check the bitset, faster than futex_wake_bitset +pub fn futex_wake(vaddr: VirtAddr, flags: FutexFlags, nr_waken: u32) -> AxSyscallResult { info!( "[futex_wake] vaddr: {:?}, flags: {:?}, nr_waken: {:?}", vaddr, flags, nr_waken ); let mut ret = 0; - let key = get_futex_key(vaddr, flags); + let key = get_futex_key(vaddr, &flags); let mut hash_bucket = FUTEXQUEUES.buckets[futex_hash(&key)].lock(); if hash_bucket.is_empty() { @@ -167,9 +170,10 @@ pub fn futex_wake(vaddr: VirtAddr, flags: i32, nr_waken: u32) -> AxSyscallResult Ok(ret as isize) } +/// Wake up tasks specified by a bitset waiting on a futex variable pub fn futex_wake_bitset( vaddr: VirtAddr, - flags: i32, + flags: FutexFlags, nr_waken: u32, bitset: u32, ) -> AxSyscallResult { @@ -181,7 +185,7 @@ pub fn futex_wake_bitset( return Err(LinuxError::EINVAL); } let mut ret = 0; - let key = get_futex_key(vaddr, flags); + let key = get_futex_key(vaddr, &flags); let mut hash_bucket = FUTEXQUEUES.buckets[futex_hash(&key)].lock(); if hash_bucket.is_empty() { return Ok(0); @@ -195,7 +199,7 @@ pub fn futex_wake_bitset( ret += 1; return false; } - return true; + true }) } // drop hash_bucket to avoid deadlock @@ -203,17 +207,18 @@ pub fn futex_wake_bitset( Ok(ret as isize) } +/// Requeue tasks waiting on a futex variable pub fn futex_requeue( uaddr: VirtAddr, - flags: i32, + flags: FutexFlags, nr_waken: u32, uaddr2: VirtAddr, nr_requeue: u32, ) -> AxSyscallResult { let mut ret = 0; let mut requeued = 0; - let key = get_futex_key(uaddr, flags); - let req_key = get_futex_key(uaddr2, flags); + let key = get_futex_key(uaddr, &flags); + let req_key = get_futex_key(uaddr2, &flags); if key == req_key { return futex_wake(uaddr, flags, nr_waken); diff --git a/modules/axprocess/src/link.rs b/modules/axprocess/src/link.rs index 69926d8..2185fb5 100644 --- a/modules/axprocess/src/link.rs +++ b/modules/axprocess/src/link.rs @@ -307,9 +307,7 @@ pub fn deal_with_path( } process .manual_alloc_for_lazy((path_addr as usize).into()) - .map(|_| { - path = unsafe { raw_ptr_to_ref_str(path_addr) }.to_string().clone(); - })?; + .map(|_| path.clone_from(&unsafe { raw_ptr_to_ref_str(path_addr) }.to_string()))?; } if path.is_empty() { diff --git a/modules/axprocess/src/process.rs b/modules/axprocess/src/process.rs index 3afbab9..c0c34d7 100644 --- a/modules/axprocess/src/process.rs +++ b/modules/axprocess/src/process.rs @@ -1,8 +1,8 @@ //! 规定进程控制块内容 extern crate alloc; +use alloc::format; use alloc::string::ToString; use alloc::sync::Arc; -use alloc::format; use alloc::vec; use alloc::vec::Vec; use alloc::{collections::BTreeMap, string::String}; @@ -164,6 +164,7 @@ impl Process { *self.blocked_by_vfork.lock() = value; } + /// Whether the process is blocked by vfork pub fn get_vfork_block(&self) -> bool { *self.blocked_by_vfork.lock() } @@ -277,7 +278,7 @@ impl Process { KERNEL_PROCESS_ID, Mutex::new(Arc::new(Mutex::new(memory_set))), heap_bottom.as_usize() as u64, - Arc::new(Mutex::new(String::from("/").into())), + Arc::new(Mutex::new(String::from("/"))), Arc::new(AtomicI32::new(0o022)), new_fd_table, )); @@ -646,8 +647,8 @@ impl Process { let mut signal_module = SignalModule::init_signal(Some(new_handler)); // exit signal, default to be SIGCHLD - if exit_signal.is_some() { - signal_module.set_exit_signal(exit_signal.unwrap()); + if let Some(exit_signal) = exit_signal { + signal_module.set_exit_signal(exit_signal); } self.signal_modules .lock() @@ -658,7 +659,7 @@ impl Process { .insert(new_task.id().as_u64(), FutexRobustList::default()); return_id = new_task.id().as_u64(); } else { - let mut cwd_src = Arc::new(Mutex::new(String::from("/").into())); + let mut cwd_src = Arc::new(Mutex::new(String::from("/"))); let mut mask_src = Arc::new(AtomicI32::new(0o022)); if clone_flags.contains(CloneFlags::CLONE_FS) { cwd_src = Arc::clone(&self.fd_manager.cwd); @@ -689,8 +690,8 @@ impl Process { // 若是新建了进程,那么需要把进程的父子关系进行记录 let mut signal_module = SignalModule::init_signal(Some(new_handler)); // exit signal, default to be SIGCHLD - if exit_signal.is_some() { - signal_module.set_exit_signal(exit_signal.unwrap()); + if let Some(exit_signal) = exit_signal { + signal_module.set_exit_signal(exit_signal); } new_process .signal_modules @@ -804,7 +805,7 @@ impl Process { /// Set the current working directory of the process pub fn set_cwd(&self, cwd: String) { - *self.fd_manager.cwd.lock() = cwd.into(); + *self.fd_manager.cwd.lock() = cwd; } } diff --git a/modules/axprocess/src/signal.rs b/modules/axprocess/src/signal.rs index a8fffad..014e046 100644 --- a/modules/axprocess/src/signal.rs +++ b/modules/axprocess/src/signal.rs @@ -58,22 +58,22 @@ impl SignalModule { /// - Some(true): The interrupted syscall should be restarted /// - Some(false): The interrupted syscall should not be restarted pub fn have_restart_signal(&self) -> Option { - match self.signal_set.find_signal() { - Some(sig_num) => Some( - self.signal_handler - .lock() - .get_action(sig_num) - .need_restart(), - ), - - None => None, - } + self.signal_set.find_signal().map(|sig_num| { + self.signal_handler + .lock() + .get_action(sig_num) + .need_restart() + }) } + /// Set the exit signal of the process + /// + /// When the process exits, it will send the exit signal to the parent process pub fn set_exit_signal(&mut self, signal: SignalNo) { self.exit_signal = Some(signal); } + /// Get the exit signal of the process pub fn get_exit_signal(&self) -> Option { self.exit_signal } diff --git a/modules/axprocess/src/stdio.rs b/modules/axprocess/src/stdio.rs index e5f9cc3..382dc43 100644 --- a/modules/axprocess/src/stdio.rs +++ b/modules/axprocess/src/stdio.rs @@ -56,8 +56,7 @@ fn stdin_read(buf: &mut [u8]) -> AxResult { buf.as_mut_ptr().write_volatile(ch); } Ok(1) - } - else { + } else { // user appilcation let mut line = String::new(); loop { @@ -77,7 +76,6 @@ fn stdin_read(buf: &mut [u8]) -> AxResult { } } _ => { - // echo putchar(c); line.push(c as char); } diff --git a/modules/axruntime/Cargo.toml b/modules/axruntime/Cargo.toml index c577a13..6ee6460 100644 --- a/modules/axruntime/Cargo.toml +++ b/modules/axruntime/Cargo.toml @@ -28,17 +28,17 @@ monolithic = ["axprocess/monolithic", "axhal/monolithic", "axtask/monolithic", " [dependencies] cfg-if = "1.0" -axhal = { git = "https://github.com/Starry-OS/axhal.git" } +axhal = { path = "../axhal" } axlog = { git = "https://github.com/Starry-OS/axlog.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git" } -axalloc = { git = "https://github.com/Starry-OS/axalloc.git", optional = true } -axdriver = { git = "https://github.com/Starry-OS/axdriver.git", optional = true } -axfs = { git = "https://github.com/Starry-OS/axfs.git", optional = true } -axnet = { git = "https://github.com/Starry-OS/axnet.git", optional = true } -axdisplay = { git = "https://github.com/Starry-OS/axdisplay.git", optional = true } -axtask = { git = "https://github.com/Starry-OS/axtask.git"} -axprocess = { git = "https://github.com/Starry-OS/axprocess.git", optional = true } -axmem = { git = "https://github.com/Starry-OS/axmem.git", optional = true } +axconfig = { path = "../axconfig" } +axalloc = { path = "../axalloc", optional = true } +axdriver = { path = "../axdriver", optional = true } +axfs = { path = "../axfs", optional = true } +axnet = { path = "../axnet", optional = true } +axdisplay = { path = "../axdisplay", optional = true } +axtask = { path = "../axtask"} +axprocess = { path = "../axprocess", optional = true } +axmem = { path = "../axmem", optional = true } crate_interface = { git = "https://github.com/Starry-OS/crate_interface.git" } percpu = { git = "https://github.com/Starry-OS/percpu.git", optional = true } kernel_guard = { git = "https://github.com/Starry-OS/kernel_guard.git", optional = true } diff --git a/modules/axsignal/Cargo.toml b/modules/axsignal/Cargo.toml index 1fdf80f..ea39d17 100644 --- a/modules/axsignal/Cargo.toml +++ b/modules/axsignal/Cargo.toml @@ -14,5 +14,5 @@ default = [] [dependencies] numeric-enum-macro = { git = "https://github.com/mexus/numeric-enum-macro" } bitflags = "2.6" -axhal = { git = "https://github.com/Starry-OS/axhal.git" } +axhal = { path = "../axhal" } cfg-if = "1.0" \ No newline at end of file diff --git a/modules/axsignal/src/action.rs b/modules/axsignal/src/action.rs index 3f3f489..026f75e 100644 --- a/modules/axsignal/src/action.rs +++ b/modules/axsignal/src/action.rs @@ -119,6 +119,7 @@ impl SigAction { } } + /// Whether the syscall should be restarted after the signal handler returns pub fn need_restart(&self) -> bool { self.sa_flags.contains(SigActionFlags::SA_RESTART) } diff --git a/modules/axsignal/src/info.rs b/modules/axsignal/src/info.rs index dd44597..eaed43e 100644 --- a/modules/axsignal/src/info.rs +++ b/modules/axsignal/src/info.rs @@ -15,15 +15,16 @@ pub struct SigInfo { /// The code of the signal pub si_code: i32, + /// Padding #[allow(unused)] pub pad: u32, - + /// The process ID of the sender pub pid: i32, - + /// The real user ID of the sender pub uid: u32, - + /// The value sent with the signal pub si_val_int: i32, - + /// The value pointer of the signal pub si_val_ptr: usize, } diff --git a/modules/axsignal/src/lib.rs b/modules/axsignal/src/lib.rs index e8ba938..3777680 100644 --- a/modules/axsignal/src/lib.rs +++ b/modules/axsignal/src/lib.rs @@ -50,7 +50,7 @@ impl SignalHandler { } /// To get the action of a signal with the signal number - pub fn get_action<'a>(&'a self, sig_num: usize) -> &'a SigAction { + pub fn get_action(&self, sig_num: usize) -> &SigAction { &self.handlers[sig_num - 1] } /// 设置信号处理函数 diff --git a/modules/axsignal/src/ucontext/mod.rs b/modules/axsignal/src/ucontext/mod.rs index 0cbcde0..ac3fe88 100644 --- a/modules/axsignal/src/ucontext/mod.rs +++ b/modules/axsignal/src/ucontext/mod.rs @@ -5,7 +5,7 @@ pub const SS_ONSTACK: u32 = 1; /// The alternate signal stack is disabled. pub const SS_DISABLE: u32 = 2; /// The alternate signal stack has been marked to be autodisarmed as described above. -pub const SS_AUTODISARM: u32 = (1 as u32) << 31; +pub const SS_AUTODISARM: u32 = 1_u32 << 31; cfg_if::cfg_if! { if #[cfg(target_arch = "x86_64")] { diff --git a/modules/axsync/Cargo.toml b/modules/axsync/Cargo.toml index f1127f8..93856e2 100644 --- a/modules/axsync/Cargo.toml +++ b/modules/axsync/Cargo.toml @@ -18,10 +18,10 @@ default = [] [dependencies] cfg-if = "1.0" spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } -axtask = { git = "https://github.com/Starry-OS/axtask.git" } -axhal = {git = "https://github.com/Starry-OS/axhal.git"} +axtask = { path = "../axtask" } +axhal = { path = "../axhal" } [dev-dependencies] rand = "0.8" -axsync = { git = "https://github.com/Starry-OS/axsync.git", features = ["multitask"] } -axtask = { git = "https://github.com/Starry-OS/axtask.git", features = ["test"] } +axsync = { path = "../axsync", features = ["multitask"] } +axtask = { path = "../axtask", features = ["test"] } diff --git a/modules/axsync/src/completion.rs b/modules/axsync/src/completion.rs index eb4d522..44fd7d1 100644 --- a/modules/axsync/src/completion.rs +++ b/modules/axsync/src/completion.rs @@ -1,4 +1,4 @@ -//! completion +//! completion //! If you have one or more threads that must wait for some kernel activity //! to have reached a point or a specific state, completions can provide a //! race-free solution to this problem. Semantically they are somewhat like a @@ -10,18 +10,18 @@ //! you probably want to look into using one of the wait_for_completion*() //! calls and complete() instead. //! -//! Completions are built on top of the waitqueue and wakeup infrastructure of +//! Completions are built on top of the waitqueue and wakeup infrastructure of //! scheduler(axtask). The event the threads on the waitqueue are waiting for //! is reduced to a simple flag in 'struct completion', appropriately called "done". //! use alloc::sync::Arc; -use axtask::{WaitTaskList, WaitTaskNode}; -use spinlock::SpinNoIrq; use axtask::schedule; #[cfg(feature = "irq")] use axtask::schedule_timeout; +use axtask::{WaitTaskList, WaitTaskNode}; #[cfg(feature = "irq")] use core::time::Duration; +use spinlock::SpinNoIrq; use axtask::declare_wait; @@ -43,10 +43,10 @@ impl Inner { /// Cpmpletion struct, it protect by done pub struct Completion { - inner: SpinNoIrq + inner: SpinNoIrq, } -// SAFETY: have it's own SpinNoIrq protect +// SAFETY: have it's own SpinNoIrq protect unsafe impl Sync for Completion {} unsafe impl Send for Completion {} @@ -64,13 +64,13 @@ impl Completion { pub fn reinit(&self) { self.inner.lock().done = 0; } - + /// waits for completion of a task pub fn wait_for_completion(&self) { declare_wait!(waiter); loop { let mut inner = self.inner.lock(); - assert!(inner.done >=0); + assert!(inner.done >= 0); if inner.done == 0 { inner.queue.prepare_to_wait(waiter.clone()); drop(inner); @@ -83,13 +83,13 @@ impl Completion { } #[cfg(feature = "irq")] - /// waits for completion of a task (w/timeout secs) + /// waits for completion of a task (w/timeout secs) pub fn wait_for_completion_timeout(&self, secs: u64) -> bool { declare_wait!(waiter); let deadline = axhal::time::current_time() + Duration::from_secs(secs); let timeout = loop { let mut inner = self.inner.lock(); - assert!(inner.done >=0); + assert!(inner.done >= 0); if inner.done == 0 { inner.queue.prepare_to_wait(waiter.clone()); drop(inner); @@ -108,7 +108,7 @@ impl Completion { /// signals a single thread waiting on this completion pub fn complete(&self) { let mut inner = self.inner.lock(); - inner.done+=1; + inner.done += 1; inner.queue.notify_one(); } diff --git a/modules/axsync/src/lib.rs b/modules/axsync/src/lib.rs index 97e624f..a7744ce 100644 --- a/modules/axsync/src/lib.rs +++ b/modules/axsync/src/lib.rs @@ -15,15 +15,14 @@ #![feature(doc_cfg)] cfg_if::cfg_if! { if #[cfg(feature = "multitask")] { - #[macro_use] extern crate axtask; extern crate alloc; - + mod mutex; mod completion; - + pub use self::completion::Completion; - + #[doc(cfg(feature = "multitask"))] pub use self::mutex::{Mutex, MutexGuard}; } else { @@ -33,4 +32,3 @@ cfg_if::cfg_if! { } pub use spinlock as spin; - diff --git a/modules/axtask/Cargo.toml b/modules/axtask/Cargo.toml index 0880d35..18806aa 100644 --- a/modules/axtask/Cargo.toml +++ b/modules/axtask/Cargo.toml @@ -31,11 +31,11 @@ monolithic = ["multitask", "axhal/monolithic", "taskctx/monolithic"] [dependencies] cfg-if = "1.0" -log = "0.4" +log = "0.4.21" numeric-enum-macro = { git = "https://github.com/mexus/numeric-enum-macro" } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -axsignal = { git = "https://github.com/Starry-OS/axsignal.git" } -axconfig = { git = "https://github.com/Starry-OS/axconfig.git"} +axhal = { path = "../axhal" } +axsignal = { path = "../axsignal" } +axconfig = { path = "../axconfig" } percpu = { git = "https://github.com/Starry-OS/percpu.git", optional = true } spinlock = { git = "https://github.com/Starry-OS/spinlock.git", optional = true } lazy_init = { git = "https://github.com/Starry-OS/lazy_init.git", optional = true } @@ -50,5 +50,5 @@ axbacktrace = { git = "https://github.com/kern-crates/axbacktrace.git" } [dev-dependencies] rand = "0.8" -axhal = { git = "https://github.com/Starry-OS/axhal.git", features = ["fp_simd"] } -axtask = { git = "https://github.com/Starry-OS/axtask.git", features = ["test"] } +axhal = { path = "../axhal", features = ["fp_simd"] } +axtask = { path = "../axtask", features = ["test"] } diff --git a/modules/axtask/src/api.rs b/modules/axtask/src/api.rs index 08c85aa..08b4c8a 100644 --- a/modules/axtask/src/api.rs +++ b/modules/axtask/src/api.rs @@ -186,7 +186,7 @@ pub fn vfork_suspend(task: &AxTaskRef) { wait_queue.wait_until(|| { // If the given task does the exec syscall, it will be the leader of the new process. task.is_leader() || task.state() == TaskState::Exited - }); + }) }); } @@ -213,17 +213,24 @@ pub fn run_idle() -> ! { } } +/// Dump the current task backtrace. pub fn dump_curr_backtrace() { dump_task_backtrace(current().as_task_ref().clone()); } + +#[allow(missing_docs)] pub fn dump_task_backtrace(task: AxTaskRef) { - use axbacktrace::{dump_backtrace, Unwind, UnwindIf, StackInfo}; + use axbacktrace::{dump_backtrace, StackInfo, Unwind, UnwindIf}; let stack_low = task.get_kernel_stack_down().unwrap(); let stack_high = task.get_kernel_stack_top().unwrap(); - info!("dump task: {}, stack range: {:#016x}: {:#016x}", - task.id_name(), stack_low, stack_high); - let stack_info = StackInfo::new(stack_low,stack_high); + info!( + "dump task: {}, stack range: {:#016x}: {:#016x}", + task.id_name(), + stack_low, + stack_high + ); + let stack_info = StackInfo::new(stack_low, stack_high); //Init Unwind instance from current context let curr = crate::current(); @@ -231,7 +238,7 @@ pub fn dump_task_backtrace(task: AxTaskRef) { Unwind::new_from_cur_ctx(stack_info) } else { let (pc, fp) = task.ctx_unwind(); - Unwind::new(pc,fp,stack_info) + Unwind::new(pc, fp, stack_info) }; // dump current task trace dump_backtrace(&mut unwind); diff --git a/modules/axtask/src/api_s.rs b/modules/axtask/src/api_s.rs index 28e2754..52eef26 100644 --- a/modules/axtask/src/api_s.rs +++ b/modules/axtask/src/api_s.rs @@ -27,19 +27,20 @@ extern "C" { } pub fn global_unique_ts() -> (usize, usize) { - let boot_stack = unsafe { - current_boot_stack() as usize - }; + let boot_stack = unsafe { current_boot_stack() as usize }; (boot_stack, boot_stack + axconfig::TASK_STACK_SIZE) } pub fn dump_curr_backtrace() { //Init Unwind instance from current context - use axbacktrace::{dump_backtrace, Unwind, UnwindIf, StackInfo}; + use axbacktrace::{dump_backtrace, StackInfo, Unwind, UnwindIf}; let stack = global_unique_ts(); let stack_info = StackInfo::new(stack.0, stack.1); - axlog::info!("dump task stack range: {:#016x}: {:#016x}", - stack.0, stack.1); + axlog::info!( + "dump task stack range: {:#016x}: {:#016x}", + stack.0, + stack.1 + ); let mut unwind = Unwind::new_from_cur_ctx(stack_info); // dump current task trace dump_backtrace(&mut unwind); diff --git a/modules/axtask/src/processor.rs b/modules/axtask/src/processor.rs index 55a77b6..e3a4bff 100644 --- a/modules/axtask/src/processor.rs +++ b/modules/axtask/src/processor.rs @@ -19,6 +19,7 @@ static PROCESSORS: SpinNoIrqOnly> = #[percpu::def_percpu] static PROCESSOR: LazyInit = LazyInit::new(); +/// Processor on coresponding core pub struct Processor { /// Processor SCHEDULER scheduler: SpinNoIrq, @@ -40,6 +41,7 @@ unsafe impl Sync for Processor {} unsafe impl Send for Processor {} impl Processor { + /// Create a new processor pub fn new(idle_task: AxTaskRef) -> Self { let gc_task = new_task( gc_entry, @@ -58,10 +60,11 @@ impl Processor { exited_tasks: SpinNoIrq::new(VecDeque::new()), gc_wait: WaitQueue::new(), task_nr: AtomicUsize::new(0), - gc_task: gc_task, + gc_task, } } + /// The idle task of the processor pub fn idle_task(&self) -> &AxTaskRef { &self.idle_task } @@ -118,6 +121,7 @@ impl Processor { task.get_processor().scheduler.lock().add_task(task); } + #[cfg(feature = "irq")] #[inline] /// Processor Clean pub(crate) fn task_tick(&self, task: &AxTaskRef) -> bool { @@ -185,7 +189,7 @@ impl Processor { #[inline] /// gc init pub(crate) fn gc_init(&'static self) { - self.gc_task.init_processor(&self); + self.gc_task.init_processor(self); self.scheduler.lock().add_task(self.gc_task.clone()); } @@ -200,6 +204,10 @@ impl Processor { } } +/// Get current processor pointer +/// +/// # Safety +/// The processor pointer is a per-core global variable, so it is safe to access it. pub fn current_processor() -> &'static Processor { unsafe { PROCESSOR.current_ref_raw() } } diff --git a/modules/axtask/src/schedule.rs b/modules/axtask/src/schedule.rs index 20aa484..99821b9 100644 --- a/modules/axtask/src/schedule.rs +++ b/modules/axtask/src/schedule.rs @@ -56,6 +56,7 @@ pub(crate) fn yield_current() { schedule(); } +/// Sleep the current task until the deadline. #[cfg(feature = "irq")] pub fn schedule_timeout(deadline: axhal::time::TimeValue) -> bool { let curr = crate::current(); @@ -69,6 +70,7 @@ pub fn schedule_timeout(deadline: axhal::time::TimeValue) -> bool { timeout } +/// Check whether the current task should be preempted. #[cfg(feature = "irq")] pub fn scheduler_timer_tick() { let curr = crate::current(); @@ -78,10 +80,12 @@ pub fn scheduler_timer_tick() { } } +/// Set the sched priority of the current task. pub fn set_current_priority(prio: isize) -> bool { current_processor().set_priority(crate::current().as_task_ref(), prio) } +/// Wake up the given task from the blocking state. pub fn wakeup_task(task: AxTaskRef) { let mut state = task.state_lock_manual(); match **state { @@ -95,12 +99,12 @@ pub fn wakeup_task(task: AxTaskRef) { Processor::add_task(task.clone()); return; } - _ => panic!("try to wakeup {:?} unexpect state {:?}", - task.id(), **state), + _ => panic!("try to wakeup {:?} unexpect state {:?}", task.id(), **state), } ManuallyDrop::into_inner(state); } +/// Schedule the next task to run. pub fn schedule() { let next_task = current_processor().pick_next_task(); switch_to(next_task); @@ -117,7 +121,6 @@ fn switch_to(mut next_task: AxTaskRef) { prev_task.id_name() ); - // When the prev_task state_lock is locked, it records the irq configuration of // the prev_task at that time, after swich(in switch_post) it would be unlocked, // and restore the irq configuration to the lock_state store(NOTE: it own the prev_task). @@ -129,35 +132,27 @@ fn switch_to(mut next_task: AxTaskRef) { // Here must lock curr state, and no one can change curr state // when excuting ctx_switch let mut prev_state_lock = prev_task.state_lock_manual(); - - loop { - match **prev_state_lock { - TaskState::Runable => { - if next_task.is_idle() { - next_task = prev_task.clone(); - break; - } - if !prev_task.is_idle() { - #[cfg(feature = "preempt")] - current_processor() - .put_prev_task(prev_task.clone(), prev_task.get_preempt_pending()); - #[cfg(not(feature = "preempt"))] - current_processor().put_prev_task(prev_task.clone(), false); - } - break; - } - TaskState::Blocking => { - debug!("task block: {}", prev_task.id_name()); - **prev_state_lock = TaskState::Blocked; - break; - } - TaskState::Exited => { - break; - } - _ => { - panic!("unexpect state when switch_to happend "); + + match **prev_state_lock { + TaskState::Runable => { + if next_task.is_idle() { + next_task = prev_task.clone(); + } else if !prev_task.is_idle() { + #[cfg(feature = "preempt")] + current_processor() + .put_prev_task(prev_task.clone(), prev_task.get_preempt_pending()); + #[cfg(not(feature = "preempt"))] + current_processor().put_prev_task(prev_task.clone(), false); } } + TaskState::Blocking => { + debug!("task block: {}", prev_task.id_name()); + **prev_state_lock = TaskState::Blocked; + } + TaskState::Exited => {} + _ => { + panic!("unexpect state when switch_to happend "); + } } #[cfg(feature = "preempt")] @@ -216,6 +211,5 @@ fn switch_to(mut next_task: AxTaskRef) { axhal::arch::task_context_switch(&mut (*prev_ctx_ptr), &(*next_ctx_ptr)); current_processor().switch_post(); - } } diff --git a/modules/axtask/src/task.rs b/modules/axtask/src/task.rs index b38e0ce..cfa63ef 100644 --- a/modules/axtask/src/task.rs +++ b/modules/axtask/src/task.rs @@ -15,8 +15,8 @@ use crate::{ pub use taskctx::{TaskId, TaskInner}; +use core::sync::atomic::AtomicBool; use spinlock::{SpinNoIrq, SpinNoIrqOnly, SpinNoIrqOnlyGuard}; -use core::sync::atomic::{AtomicBool, Ordering}; extern "C" { fn _stdata(); @@ -43,6 +43,7 @@ pub enum TaskState { pub struct ScheduleTask { inner: TaskInner, /// Store task irq state + #[allow(unused)] irq_state: AtomicBool, /// Task state state: SpinNoIrqOnly, @@ -56,7 +57,7 @@ impl ScheduleTask { state: SpinNoIrqOnly::new(TaskState::Runable), processor: SpinNoIrq::new(None), irq_state: AtomicBool::new(irq_init_state), - inner: inner, + inner, } } @@ -121,14 +122,15 @@ impl ScheduleTask { #[cfg(feature = "irq")] #[inline] pub(crate) fn set_irq_state(&self, irq_state: bool) { - self.irq_state.store(irq_state,Ordering::Relaxed); + self.irq_state + .store(irq_state, core::sync::atomic::Ordering::Relaxed); } /// get irq state #[cfg(feature = "irq")] #[inline] pub(crate) fn get_irq_state(&self) -> bool { - self.irq_state.load(Ordering::Relaxed) + self.irq_state.load(core::sync::atomic::Ordering::Relaxed) } } @@ -191,7 +193,7 @@ where task.reset_time_stat(current_time_nanos() as usize); // a new task start, irq should be enabled by default - let axtask = Arc::new(AxTask::new(ScheduleTask::new(task,true))); + let axtask = Arc::new(AxTask::new(ScheduleTask::new(task, true))); add_wait_for_exit_queue(&axtask); axtask } @@ -231,7 +233,7 @@ where } pub(crate) fn new_init_task(name: String) -> AxTaskRef { - // init task irq should be disabled by default + // init task irq should be disabled by default // it would be reinit when switch happend let axtask = Arc::new(AxTask::new(ScheduleTask::new( taskctx::TaskInner::new_init( @@ -305,7 +307,7 @@ impl Deref for CurrentTask { extern "C" fn task_entry() -> ! { // SAFETY: INIT when switch_to // First into task entry, manually perform the subsequent work of switch_to - + current_processor().switch_post(); let task = crate::current(); diff --git a/modules/axtask/src/timers.rs b/modules/axtask/src/timers.rs index d4c2ea8..3a9ba24 100644 --- a/modules/axtask/src/timers.rs +++ b/modules/axtask/src/timers.rs @@ -4,7 +4,7 @@ use lazy_init::LazyInit; use spinlock::SpinNoIrq; use timer_list::{TimeValue, TimerEvent, TimerList}; -use crate::{AxTaskRef,TaskState}; +use crate::{AxTaskRef, TaskState}; // TODO: per-CPU static TIMER_LIST: LazyInit>> = LazyInit::new(); diff --git a/modules/axtask/src/wait_list.rs b/modules/axtask/src/wait_list.rs index 0e1fb1b..800ca63 100644 --- a/modules/axtask/src/wait_list.rs +++ b/modules/axtask/src/wait_list.rs @@ -1,8 +1,8 @@ +use crate::schedule::wakeup_task; +use crate::task::TaskState; +use crate::AxTaskRef; use alloc::sync::Arc; use core::ops::Deref; -use crate::AxTaskRef; -use crate::task::TaskState; -use crate::schedule::wakeup_task; use linked_list::{GetLinks, Links, List}; @@ -24,7 +24,7 @@ impl GetLinks for WaitTaskNode { } impl WaitTaskNode { - /// Creates a new [`FifoTask`] from the inner task struct. + /// Creates a new FifoTask from the inner task struct. pub const fn new(inner: AxTaskRef) -> Self { Self { inner, @@ -48,18 +48,16 @@ impl Deref for WaitTaskNode { /// A simple FIFO wait task list /// -/// When a task is added to the list, it's placed at the end of the waitlist. +/// When a task is added to the list, it's placed at the end of the waitlist. /// When picking the next task to run, the head of the wait list is taken. pub struct WaitTaskList { list: List>, } impl WaitTaskList { - /// Creates a new empty [WaitList]. + /// Creates a new empty WaitList. pub const fn new() -> Self { - Self { - list: List::new(), - } + Self { list: List::new() } } /// add wait to list back @@ -75,7 +73,7 @@ impl WaitTaskList { /// Callers must ensure that `data` is either on this list or in no list. It being on another /// list leads to memory unsafety. pub fn remove(&mut self, node: &Arc) -> Option> { - unsafe { self.list.remove(node)} + unsafe { self.list.remove(node) } } /// notify special task and remove it @@ -96,7 +94,7 @@ impl WaitTaskList { if wake { cursor.remove_current(); } - + false } @@ -118,4 +116,3 @@ impl WaitTaskList { } } } - diff --git a/modules/axtask/src/wait_queue.rs b/modules/axtask/src/wait_queue.rs index 51b0e5c..74a69d8 100644 --- a/modules/axtask/src/wait_queue.rs +++ b/modules/axtask/src/wait_queue.rs @@ -1,11 +1,11 @@ +use crate::schedule::schedule; #[cfg(feature = "irq")] use crate::schedule::schedule_timeout; -use crate::schedule::schedule; -use spinlock::SpinNoIrq; use crate::wait_list::WaitTaskList; use crate::wait_list::WaitTaskNode; use crate::AxTaskRef; use alloc::sync::Arc; +use spinlock::SpinNoIrq; /// A queue to store sleeping tasks. /// /// # Examples @@ -32,11 +32,12 @@ use alloc::sync::Arc; #[macro_export] macro_rules! declare_wait { - ($name: ident) => { - let $name = Arc::new(WaitTaskNode::new($crate::current().as_task_ref().clone())); - }; + ($name: ident) => { + let $name = Arc::new(WaitTaskNode::new($crate::current().as_task_ref().clone())); + }; } +/// A queue to store tasks that are waiting for some conditions. pub struct WaitQueue { // Support queue lock by external caller,use SpinNoIrq // Arceos SpinNoirq current implementation implies irq_save, diff --git a/modules/axtrap/Cargo.toml b/modules/axtrap/Cargo.toml index 8c8da92..5733bcd 100644 --- a/modules/axtrap/Cargo.toml +++ b/modules/axtrap/Cargo.toml @@ -17,12 +17,12 @@ preempt = ["axtask/preempt", "percpu/preempt", "kernel_guard/preempt"] [dependencies] axlog = { git = "https://github.com/Starry-OS/axlog.git" } cfg-if = "1.0" -log = "0.4" -linux_syscall_api = { git = "https://github.com/Starry-OS/linux_syscall_api.git", optional = true } +log = "0.4.21" +linux_syscall_api = { path = "../../api/linux_syscall_api", optional = true } handler_table = { git = "https://github.com/Starry-OS/handler_table.git" } lazy_init = { git = "https://github.com/Starry-OS/lazy_init.git" } -axhal = { git = "https://github.com/Starry-OS/axhal.git" } -axtask = { git = "https://github.com/Starry-OS/axtask.git", optional = true } +axhal = { path = "../axhal" } +axtask = { path = "../axtask", optional = true } kernel_guard = { git = "https://github.com/Starry-OS/kernel_guard.git" } percpu = { git = "https://github.com/Starry-OS/percpu.git" } diff --git a/tools/axlibc/Cargo.toml b/tools/axlibc/Cargo.toml index 7f68981..8d8209a 100644 --- a/tools/axlibc/Cargo.toml +++ b/tools/axlibc/Cargo.toml @@ -54,11 +54,11 @@ select = ["arceos_posix_api/select"] epoll = ["arceos_posix_api/epoll"] [dependencies] -axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } -arceos_posix_api = { git = "https://github.com/Starry-OS/arceos_posix_api.git" } +axfeat = { path = "../../api/axfeat" } +arceos_posix_api = { path = "../../api/arceos_posix_api" } axio = { git = "https://github.com/Starry-OS/axio.git" } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } -arch_boot = { git = "https://github.com/Starry-OS/arch_boot.git" } +arch_boot = { path = "../../modules/arch_boot" } [build-dependencies] bindgen ={ version = "0.69" } \ No newline at end of file diff --git a/tools/axlibc/build.rs b/tools/axlibc/build.rs index 461bacc..40a6ff3 100644 --- a/tools/axlibc/build.rs +++ b/tools/axlibc/build.rs @@ -41,7 +41,7 @@ fn aarch64_vfp_compile() { // 编译汇编文件,增加 target-feature 选项 let status = Command::new("clang") - .args(&[ + .args([ "-c", asm_file.to_str().unwrap(), "-o", @@ -57,7 +57,7 @@ fn aarch64_vfp_compile() { // 打包对象文件为静态库 let lib_out_file = PathBuf::from(&out_dir).join("libvfp_setjmp.a"); let status = Command::new("ar") - .args(&[ + .args([ "crus", lib_out_file.to_str().unwrap(), asm_out_file.to_str().unwrap(), diff --git a/ulib/axstarry/Cargo.toml b/ulib/axstarry/Cargo.toml index 97644ce..fcb61ed 100644 --- a/ulib/axstarry/Cargo.toml +++ b/ulib/axstarry/Cargo.toml @@ -64,9 +64,9 @@ log-level-debug = ["axfeat/log-level-debug"] log-level-trace = ["axfeat/log-level-trace"] [dependencies] -linux_syscall_api = { git = "https://github.com/Starry-OS/linux_syscall_api.git" } -axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } +linux_syscall_api = { path = "../../api/linux_syscall_api" } +axfeat = { path = "../../api/axfeat" } axlog = { git = "https://github.com/Starry-OS/axlog.git" } -arch_boot = { git = "https://github.com/Starry-OS/arch_boot.git" } -axtask = { git = "https://github.com/Starry-OS/axtask.git" } -axfs = { git = "https://github.com/Starry-OS/axfs.git" } \ No newline at end of file +arch_boot = { path = "../../modules/arch_boot" } +axtask = { path = "../../modules/axtask" } +axfs = { path = "../../modules/axfs" } \ No newline at end of file diff --git a/ulib/axstarry/src/api.rs b/ulib/axstarry/src/api.rs index 7122626..764ae36 100644 --- a/ulib/axstarry/src/api.rs +++ b/ulib/axstarry/src/api.rs @@ -33,7 +33,7 @@ pub fn get_envs() -> Vec { /// /// The environment variables are hard coded, we need to read the file "/etc/environment" to get the environment variables pub fn run_testcase(testcase: &str) { - linux_syscall_api::run_testcase(testcase, get_envs()); + let _ = linux_syscall_api::run_testcase(testcase, get_envs()); } /// To print a string to the console diff --git a/ulib/axstarry/src/file.rs b/ulib/axstarry/src/file.rs index 3e543cd..c056f6f 100644 --- a/ulib/axstarry/src/file.rs +++ b/ulib/axstarry/src/file.rs @@ -1,6 +1,6 @@ //! Init some files and links in the filesystem for the apps -use alloc::{format, vec::*, string::ToString}; +use alloc::{format, string::ToString, vec::*}; use linux_syscall_api::{create_link, new_file, FileFlags, FilePath}; fn meminfo() -> &'static str { diff --git a/ulib/axstd/Cargo.toml b/ulib/axstd/Cargo.toml index 9b97dba..6f4e94d 100644 --- a/ulib/axstd/Cargo.toml +++ b/ulib/axstd/Cargo.toml @@ -72,9 +72,9 @@ log-level-debug = ["axfeat/log-level-debug"] log-level-trace = ["axfeat/log-level-trace"] [dependencies] -axfeat = { git = "https://github.com/Starry-OS/axfeat.git" } -arceos_api = { git = "https://github.com/Starry-OS/arceos_api.git" } +axfeat = { path = "../../api/axfeat" } +arceos_api = { path = "../../api/arceos_api" } axio = { git = "https://github.com/Starry-OS/axio.git" } axerrno = { git = "https://github.com/Starry-OS/axerrno.git" } spinlock = { git = "https://github.com/Starry-OS/spinlock.git" } -arch_boot = { git = "https://github.com/Starry-OS/arch_boot.git" } \ No newline at end of file +arch_boot = { path = "../../modules/arch_boot" } \ No newline at end of file