diff --git a/Cargo.lock b/Cargo.lock index 8f7e89bb8..77e96b86e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,15 +13,15 @@ dependencies = [ [[package]] name = "ahash" -version = "0.8.11" +version = "0.8.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e89da841a80418a9b391ebaea17f5c112ffaaa96f621d2c285b5174da76b9011" +checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75" dependencies = [ "cfg-if", "const-random", "once_cell", "version_check", - "zerocopy 0.7.35", + "zerocopy", ] [[package]] @@ -79,15 +79,15 @@ name = "another_ext4" version = "0.1.0" source = "git+https://github.com/LJxTHUCS/another_ext4.git?rev=3c3e03a#3c3e03a1b63a254f9cc5adb603d01c746f3fcf4b" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "log", ] [[package]] name = "anstyle" -version = "1.0.8" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bec1de6f59aedf83baf9ff929c98f2ad654b97c9510f4e70cf6f661d49fd5b1" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "arceos-shell" @@ -145,9 +145,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.3.0" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" +checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8" [[package]] name = "axalloc" @@ -202,7 +202,7 @@ version = "0.1.0" dependencies = [ "axerrno", "axio", - "bitflags 2.9.1", + "bitflags 2.9.3", "lazy_static", "log", "spin", @@ -291,7 +291,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.87", + "syn 2.0.106", "which", ] @@ -301,7 +301,7 @@ version = "0.66.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f2b84e06fc203107bfbad243f4aba2af864eb7db3b1cf46ea0a023b0b433d2a7" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "cexpr", "clang-sys", "lazy_static", @@ -314,7 +314,7 @@ dependencies = [ "regex", "rustc-hash", "shlex", - "syn 2.0.87", + "syn 2.0.106", "which", ] @@ -338,9 +338,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.9.1" +version = "2.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b8e56985ec62d17e9c1001dc89c88ecd7dc08e47eba5ec7c29c7b5eeecde967" +checksum = "34efbcccd345379ca2868b2b2c9d3782e9cc58ba87bc7d79d5b53d9c9ae6f25d" [[package]] name = "bitmap-allocator" @@ -364,9 +364,9 @@ checksum = "d44d578cadd17312c75e7d0ef489361f160ace58f7139aa32001fee1a51b89b5" [[package]] name = "bumpalo" -version = "3.16.0" +version = "3.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" +checksum = "46c5e41b57b8bba42a04676d81cb89e9ee8e859a1a66f80a5a72e1cb76b34d43" [[package]] name = "byteorder" @@ -380,7 +380,7 @@ version = "0.1.0" dependencies = [ "axerrno", "axfs_vfs", - "bitflags 2.9.1", + "bitflags 2.9.3", ] [[package]] @@ -391,9 +391,9 @@ checksum = "37b2a672a2cb129a2e41c10b1224bb368f9f37a2b16b612598138befd7b37eb5" [[package]] name = "cc" -version = "1.1.21" +version = "1.2.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07b1695e2c7e8fc85310cde85aeaab7e3097f593c91d209d3f9df76c928100f0" +checksum = "42bc4aea80032b7bf409b0bc7ccad88853858911b7713a8062fdc0623867bedc" dependencies = [ "jobserver", "libc", @@ -411,22 +411,22 @@ dependencies = [ [[package]] name = "cfg-if" -version = "1.0.0" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "2fd1289c04a9ea8cb22300a459a72a385d7c73d3259e2ed7dcb2af674838cfa9" [[package]] name = "chrono" -version = "0.4.38" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +checksum = "c469d952047f47f91b68d1cba3f10d63c11d73e4636f24f08daf0278abf01c4d" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "windows-targets", + "windows-link", ] [[package]] @@ -469,18 +469,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.17" +version = "4.5.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e5a21b8495e732f1b3c364c9949b201ca7bae518c502c80256c96ad79eaf6ac" +checksum = "1fc0e74a703892159f5ae7d3aac52c8e6c392f5ae5f359c70b5881d60aaac318" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.17" +version = "4.5.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cf2dd12af7a047ad9d6da2b6b249759a22a7abc0f474c1dae1777afa4b21a73" +checksum = "b3e7f4214277f3c7aa526a59dd3fbe306a370daee1f8b7b8c987069cd8e888a8" dependencies = [ "anstyle", "clap_lex", @@ -488,9 +488,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.2" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1462739cb27611015575c0c11df5df7601141071f07518d56fcc1be504cbec97" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "const-default" @@ -513,7 +513,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" dependencies = [ - "getrandom", + "getrandom 0.2.16", "once_cell", "tiny-keccak", ] @@ -532,13 +532,13 @@ checksum = "7f8f80099a98041a3d1622845c271458a2d73e688351bf3cb999266764b81d48" [[package]] name = "crate_interface" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6af24c4862260a825484470f5526a91ad1031e04ab899be62478241231f62b46" +checksum = "70272a03a2cef15589bac05d3d15c023752f5f8f2da8be977d983a9d9e6250fb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] @@ -579,15 +579,15 @@ dependencies = [ [[package]] name = "critical-section" -version = "1.1.3" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f64009896348fc5af4222e9cf7d7d82a95a256c634ebcf61c53e4ea461422242" +checksum = "790eea4361631c5e7d22598ecd5723ff611904e3344ce8720784c93e3d83d40b" [[package]] name = "crossbeam-deque" -version = "0.8.5" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "613f8cc01fe9cf1a3eb3d7f488fd2fa8388403e97039e2f73692932e291a770d" +checksum = "9dd111b7b7f7d55b72c0a6ae361660ee5853c9af73f70c3c2ef6858b950e2e51" dependencies = [ "crossbeam-epoch", "crossbeam-utils", @@ -604,15 +604,15 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.20" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" +checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28" [[package]] name = "crunchy" -version = "0.2.2" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" [[package]] name = "cstr_core" @@ -632,9 +632,18 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" [[package]] name = "defmt" -version = "0.3.8" +version = "0.3.100" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0963443817029b2024136fc4dd07a5107eb8f977eaf18fcd1fdeb11306b64ad" +dependencies = [ + "defmt 1.0.1", +] + +[[package]] +name = "defmt" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a99dd22262668b887121d4672af5a64b238f026099f1a2a1b322066c9ecfe9e0" +checksum = "548d977b6da32fa1d1fda2876453da1e7df63ad0304c8b3dae4dbe7b96f39b78" dependencies = [ "bitflags 1.3.2", "defmt-macros", @@ -642,24 +651,24 @@ dependencies = [ [[package]] name = "defmt-macros" -version = "0.3.9" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3a9f309eff1f79b3ebdf252954d90ae440599c26c2c553fe87a2d17195f2dcb" +checksum = "3d4fc12a85bcf441cfe44344c4b72d58493178ce635338a3f3b78943aceb258e" dependencies = [ "defmt-parser", - "proc-macro-error", + "proc-macro-error2", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] name = "defmt-parser" -version = "0.3.4" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff4a5fefe330e8d7f31b16a318f9ce81000d8e35e69b93eae154d16d2278f70f" +checksum = "10d60334b3b2e7c9d91ef8150abfb6fa4c1c39ebbcf4a81c2e346aad939fee3e" dependencies = [ - "thiserror 1.0.63", + "thiserror", ] [[package]] @@ -715,6 +724,19 @@ dependencies = [ "virtio-drivers", ] +[[package]] +name = "driver_rng" +version = "0.1.0" +dependencies = [ + "crate_interface", + "driver_common", + "lazy_init", + "percpu", + "rand", + "rand_xoshiro", + "spinlock", +] + [[package]] name = "driver_virtio" version = "0.1.0" @@ -725,6 +747,7 @@ dependencies = [ "driver_console", "driver_display", "driver_net", + "driver_rng", "log", "spin", "virtio-drivers", @@ -748,9 +771,9 @@ dependencies = [ [[package]] name = "either" -version = "1.13.0" +version = "1.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0" +checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "elf" @@ -811,23 +834,23 @@ checksum = "2f9ed6b3789237c8a0c1c505af1c7eb2c560df6186f01b098c3a1064ea532f38" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] name = "equivalent" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "errno" -version = "0.3.9" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" +checksum = "778e2ac28f6c47af28e4907f13ffd1e1ddbd400980a9abd7c8df189bf578a5ad" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.60.2", ] [[package]] @@ -835,7 +858,7 @@ name = "ext4_rs" version = "1.0.0" source = "git+https://github.com/yuoo655/ext4_rs.git?rev=6bcc7f5#6bcc7f5d6382ba1940f29f9a15869f35fe77b5c0" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "log", ] @@ -889,26 +912,38 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.15" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "335ff9f135e4384c8150d6f27c6daed433577f86b4750418338c01a1a2528592" +dependencies = [ + "cfg-if", + "libc", + "wasi 0.11.1+wasi-snapshot-preview1", +] + +[[package]] +name = "getrandom" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" +checksum = "26145e563e54f2cadc477553f1ec5ee650b00862f0a58bcd12cbdc5f0ea2d2f4" dependencies = [ "cfg-if", "libc", - "wasi", + "r-efi", + "wasi 0.14.2+wasi-0.2.4", ] [[package]] name = "glob" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "half" -version = "2.4.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dd08c532ae367adf81c312a4580bc67f1d0fe8bc9c460520283f4c0ff277888" +checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9" dependencies = [ "cfg-if", "crunchy", @@ -916,9 +951,9 @@ dependencies = [ [[package]] name = "handler_table" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e81913856cda07e1e7044a375043c2e4429ddb7d94a0d4ad10d4c27796ce4bd9" +checksum = "702cb690200d6303c1e1992bc648f3f3bf9c1d6a27fcf50551c513d61f339c99" [[package]] name = "hash32" @@ -939,6 +974,12 @@ dependencies = [ "allocator-api2", ] +[[package]] +name = "hashbrown" +version = "0.15.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" + [[package]] name = "heapless" version = "0.7.17" @@ -954,29 +995,30 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.4.0" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc" +checksum = "fc0fef456e4baa96da950455cd02c081ca953b141298e41db3fc7e36b1da849c" [[package]] name = "home" -version = "0.5.9" +version = "0.5.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +checksum = "589533453244b0995c858700322199b2becb13b627df2851f64a2775d024abcf" dependencies = [ - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "iana-time-zone" -version = "0.1.61" +version = "0.1.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "235e081f3925a06703c2d0117ea8b91f042756fd6e7a6e5d901e8ca1a996b220" +checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8" dependencies = [ "android_system_properties", "core-foundation-sys", "iana-time-zone-haiku", "js-sys", + "log", "wasm-bindgen", "windows-core", ] @@ -992,12 +1034,12 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.5.0" +version = "2.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" +checksum = "fe4cd85333e22411419a0bcae1297d25e58c9443848b11dc6a86fefe8c78a661" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.15.5", ] [[package]] @@ -1010,13 +1052,13 @@ dependencies = [ [[package]] name = "is-terminal" -version = "0.4.13" +version = "0.4.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "261f68e344040fbd0edea105bef17c66edf46f984ddb1115b775ce31be948f4b" +checksum = "e04d7f318608d35d4b61ddd75cbdaee86b023ebe2bd5a66ee0915f0bf93095a9" dependencies = [ "hermit-abi", "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1039,9 +1081,9 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c" [[package]] name = "ixgbe-driver" @@ -1057,27 +1099,29 @@ dependencies = [ [[package]] name = "jobserver" -version = "0.1.32" +version = "0.1.33" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48d1dbcbbeb6a7fec7e059840aa538bd62aaccf972c7346c4d9d2059312853d0" +checksum = "38f262f097c174adebe41eb73d66ae9c06b2844fb0da69969647bbddd9b0538a" dependencies = [ + "getrandom 0.3.3", "libc", ] [[package]] name = "js-sys" -version = "0.3.70" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1868808506b929d7b0cfa8f75951347aa71bb21144b7791bae35d9bccfcfe37a" +checksum = "1cfaf33c695fc6e08064efbc1f72ec937429614f25eef83af942d0e227c3a28f" dependencies = [ + "once_cell", "wasm-bindgen", ] [[package]] name = "kernel_guard" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36172feaa47f9967efd3bc5fc77462899286e821de3de68c5fe88176a24d3a1f" +checksum = "307e6be468f3d6b6d895e191f63c11602e4e76575ecca68325d8c8dbebe2870e" dependencies = [ "cfg-if", "crate_interface", @@ -1104,18 +1148,18 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.158" +version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8adc4bb1803a324070e64a98ae98f38934d91957a99cfb3a43dcbc01bc56439" +checksum = "6a82ae493e598baaea5209805c49bbf2ea7de956d50d7da0da1164f9c6d28543" [[package]] name = "libloading" -version = "0.8.5" +version = "0.8.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4979f22fdb869068da03c9f7528f8297c6fd2606bc3a4affe42e6a823fdb8da4" +checksum = "07033963ba89ebaf1584d767badaa2e8fcec21aedea6b8c0346d487d49c28667" dependencies = [ "cfg-if", - "windows-targets", + "windows-targets 0.53.3", ] [[package]] @@ -1124,15 +1168,15 @@ version = "0.1.0" [[package]] name = "linux-raw-sys" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" [[package]] name = "lock_api" -version = "0.4.12" +version = "0.4.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" +checksum = "96936507f153605bddfcda068dd804796c84324ed2510809e5b2a624c81da765" dependencies = [ "autocfg", "scopeguard", @@ -1160,9 +1204,9 @@ checksum = "0ca88d725a0a943b096803bd34e73a4437208b6077654cc4ecb2947a5f91618d" [[package]] name = "memchr" -version = "2.7.4" +version = "2.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" +checksum = "32a282da65faaf38286cf3be983213fcf1d2e2a58700e808f83f4ea9a4804bc0" [[package]] name = "memoffset" @@ -1258,15 +1302,15 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.19.0" +version = "1.21.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" +checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d" [[package]] name = "oorandom" -version = "11.1.4" +version = "11.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b410bbe7e14ab526a0e86877eb47c6996a2bd7746f027ba551028c925390e4e9" +checksum = "d6790f58c7ff633d8771f42965289203411a5e5c68388703c06e14f24770b41e" [[package]] name = "page_table" @@ -1282,7 +1326,7 @@ name = "page_table_entry" version = "0.1.0" dependencies = [ "aarch64-cpu", - "bitflags 2.9.1", + "bitflags 2.9.3", "log", "memory_addr", "x86_64 0.14.13", @@ -1321,7 +1365,7 @@ checksum = "8a9f4cc54a2e471ff72f1499461ba381ad4eae9cbd60d29c258545b995e406e0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] @@ -1354,21 +1398,21 @@ dependencies = [ [[package]] name = "ppv-lite86" -version = "0.2.20" +version = "0.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77957b295656769bb8ad2b6a6b09d897d94f05c41b069aede1fcdaa675eaea04" +checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9" dependencies = [ - "zerocopy 0.7.35", + "zerocopy", ] [[package]] name = "prettyplease" -version = "0.2.22" +version = "0.2.37" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479cf940fbbb3426c32c5d5176f62ad57549a0bb84773423ba8be9d089f5faba" +checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" dependencies = [ "proc-macro2", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] @@ -1384,47 +1428,51 @@ dependencies = [ ] [[package]] -name = "proc-macro-error" -version = "1.0.4" +name = "proc-macro-error-attr2" +version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +checksum = "96de42df36bb9bba5542fe9f1a054b8cc87e172759a1868aa05c1f3acc89dfc5" dependencies = [ - "proc-macro-error-attr", "proc-macro2", "quote", - "syn 1.0.109", - "version_check", ] [[package]] -name = "proc-macro-error-attr" -version = "1.0.4" +name = "proc-macro-error2" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +checksum = "11ec05c52be0a07b08061f7dd003e7d7092e0472bc731b4af7bb1ef876109802" dependencies = [ + "proc-macro-error-attr2", "proc-macro2", "quote", - "version_check", + "syn 2.0.106", ] [[package]] name = "proc-macro2" -version = "1.0.86" +version = "1.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5e719e8df665df0d1c8fbfd238015744736151d4445ec0836b8e628aae103b77" +checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.37" +version = "1.0.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" +checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d" dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "rand" version = "0.8.5" @@ -1452,7 +1500,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.16", ] [[package]] @@ -1479,18 +1527,18 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "11.1.0" +version = "11.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb9ee317cfe3fbd54b36a511efc1edd42e216903c9cd575e686dd68a2ba90d8d" +checksum = "c6df7ab838ed27997ba19a4664507e6f82b41fe6e20be42929332156e5e85146" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", ] [[package]] name = "rayon" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b418a60154510ca1a002a752ca9714984e21e4241e804d32555251faf8b78ffa" +checksum = "368f01d005bf8fd9b1206fb6fa653e6c4a81ceb1466406b81792d87c5677a58f" dependencies = [ "either", "rayon-core", @@ -1498,9 +1546,9 @@ dependencies = [ [[package]] name = "rayon-core" -version = "1.12.1" +version = "1.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1465873a3dfdaa8ae7cb14b4383657caab0b3e8a0aa9ae8e04b044854c8dfce2" +checksum = "22e18b0f0062d30d4230b2e85ff77fdfe4326feb054b9783a3460d8435c8ab91" dependencies = [ "crossbeam-deque", "crossbeam-utils", @@ -1508,9 +1556,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.6" +version = "1.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4219d74c6b67a3654a9fbebc4b419e22126d13d2f3c4a07ee0cb61ff79a79619" +checksum = "b544ef1b4eac5dc2db33ea63606ae9ffcfac26c1416a2806ae0bf5f56b201191" dependencies = [ "aho-corasick", "memchr", @@ -1520,9 +1568,9 @@ dependencies = [ [[package]] name = "regex-automata" -version = "0.4.7" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38caf58cc5ef2fed281f89292ef23f6365465ed9a41b7a7754eb4e26496c92df" +checksum = "809e8dc61f6de73b46c85f4c96486310fe304c434cfa43669d7b40f711150908" dependencies = [ "aho-corasick", "memchr", @@ -1531,9 +1579,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.4" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c" [[package]] name = "ringbuffer" @@ -1583,27 +1631,27 @@ version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" dependencies = [ - "semver 1.0.23", + "semver 1.0.26", ] [[package]] name = "rustix" -version = "0.38.37" +version = "0.38.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8acb788b847c24f28525660c4d7758620a7210875711f79e7f663cc152726811" +checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "rustversion" -version = "1.0.17" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" +checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d" [[package]] name = "rux9p" @@ -1652,6 +1700,7 @@ dependencies = [ "driver_display", "driver_net", "driver_pci", + "driver_rng", "driver_virtio", "log", "ruxconfig", @@ -1673,7 +1722,7 @@ dependencies = [ "axerrno", "axfs_vfs", "axio", - "bitflags 2.9.1", + "bitflags 2.9.3", "bitmaps", "capability", "flatten_objects", @@ -1739,6 +1788,7 @@ dependencies = [ "ruxdriver", "ruxfdtable", "ruxfifo", + "ruxrand", "spin", "spinlock", ] @@ -1771,7 +1821,7 @@ version = "0.1.0" dependencies = [ "ahash", "axerrno", - "bitflags 2.9.1", + "bitflags 2.9.3", "lazy_static", "log", "memory_addr", @@ -1790,7 +1840,7 @@ dependencies = [ "axerrno", "axio", "axlog", - "bitflags 2.9.1", + "bitflags 2.9.3", "cfg-if", "crate_interface", "driver_common", @@ -1809,7 +1859,7 @@ dependencies = [ "page_table_entry", "percpu", "ratio", - "raw-cpuid 11.1.0", + "raw-cpuid 11.5.0", "riscv", "ruxconfig", "sbi-rt", @@ -1820,7 +1870,7 @@ dependencies = [ "virtio-drivers", "x2apic", "x86", - "x86_64 0.14.13", + "x86_64 0.15.2", ] [[package]] @@ -1828,7 +1878,7 @@ name = "ruxmm" version = "0.1.0" dependencies = [ "axalloc", - "bitflags 2.9.1", + "bitflags 2.9.3", "cfg-if", "crate_interface", "kernel_guard", @@ -1865,12 +1915,12 @@ dependencies = [ "axfs_vfs", "axio", "axsync", - "bitflags 2.9.1", + "bitflags 2.9.3", "cfg-if", "cty", "driver_net", "flatten_objects", - "hashbrown", + "hashbrown 0.14.5", "iovec", "lazy_init", "lazy_static", @@ -1913,10 +1963,11 @@ dependencies = [ "axlog", "axsync", "bindgen 0.66.1", - "bitflags 2.9.1", + "bitflags 2.9.3", "capability", "cfg-if", "crate_interface", + "driver_virtio", "elf", "flatten_objects", "iovec", @@ -1934,6 +1985,7 @@ dependencies = [ "ruxhal", "ruxmm", "ruxnet", + "ruxrand", "ruxruntime", "ruxtask", "spin", @@ -1947,10 +1999,13 @@ name = "ruxrand" version = "0.1.0" dependencies = [ "crate_interface", + "driver_rng", "lazy_init", + "log", "percpu", "rand", "rand_xoshiro", + "ruxdriver", "spinlock", ] @@ -2043,9 +2098,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.18" +version = "1.0.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" +checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f" [[package]] name = "safe-mmio" @@ -2053,7 +2108,7 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db02a82ad13df46afeba34a4e54065fa912308b9101b060e4422898eac0e06f6" dependencies = [ - "zerocopy 0.8.26", + "zerocopy", ] [[package]] @@ -2104,9 +2159,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.23" +version = "1.0.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" +checksum = "56e6fa9c48d24d85fb3de5ad847117517440f6beceb7798af16b4a87d616b8d0" [[package]] name = "semver-parser" @@ -2116,29 +2171,29 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.210" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c8e3592472072e6e22e0a54d5904d9febf8508f65fb8552499a1abc7d1078c3a" +checksum = "5f0e2c6ed6606019b4e29e69dbaba95b11854410e5347d525002456dbbb786b6" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.210" +version = "1.0.219" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "243902eda00fad750862fc144cea25caca5e20d615af0a81bee94ca738f1df1f" +checksum = "5b0276cf7f2c73365f7157c8123c21cd9a50fbbd844757af28ca1f5925fc2a00" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] name = "serde_json" -version = "1.0.128" +version = "1.0.143" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ff5456707a1de34e7e37f2a6fd3d3f808c318259cbd01ab6377795054b483d8" +checksum = "d401abef1d108fbd9cbaebc3e46611f4b1021f714a0597a71f41ee463f5f4a5a" dependencies = [ "itoa", "memchr", @@ -2161,9 +2216,9 @@ dependencies = [ [[package]] name = "smallvec" -version = "1.15.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8917285742e9f3e1683f0a9c4e6b57960b7314d0b08d30d1ecd426713ee2eee9" +checksum = "67b1b7a3b5fe4f1376887184045fcf45c69e92af734b7aaddc05fb777b6fbd03" [[package]] name = "smoltcp" @@ -2173,7 +2228,7 @@ dependencies = [ "bitflags 1.3.2", "byteorder", "cfg-if", - "defmt", + "defmt 0.3.100", "heapless", "log", "managed", @@ -2234,9 +2289,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.87" +version = "2.0.106" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25aa4ce346d03a6dcd68dd8b4010bcb74e54e62c90c573f394c46eae99aba32d" +checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6" dependencies = [ "proc-macro2", "quote", @@ -2245,42 +2300,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.63" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0342370b38b6a11b6cc11d6a805569958d54cfa061a29969c3b5ce2ea405724" +checksum = "3467d614147380f2e4e374161426ff399c91084acd2363eaf549172b3d5e60c0" dependencies = [ - "thiserror-impl 1.0.63", -] - -[[package]] -name = "thiserror" -version = "2.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567b8a2dae586314f7be2a752ec7474332959c6460e02bde30d702a66d488708" -dependencies = [ - "thiserror-impl 2.0.12", -] - -[[package]] -name = "thiserror-impl" -version = "1.0.63" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.87", + "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "2.0.12" +version = "2.0.16" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f7cf42b4507d8ea322120659672cf1b9dbb93f8f2d4ecfd6e51350ff5b17a1d" +checksum = "6c5e1be1c48b9172ee610da68fd9cd2770e7a4056cb3fc98710ee6906f0c7960" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] @@ -2323,9 +2358,9 @@ checksum = "696941a0aee7e276a165a978b37918fd5d22c55c3d6bda197813070ca9c0f21c" [[package]] name = "toml_datetime" -version = "0.6.8" +version = "0.6.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0dd7358ecb8fc2f8d014bf86f6f638ce72ba252a2c3a2572f2a795f1d23efb41" +checksum = "22cddaf88f4fbc13c51aebbf5f8eceb5c7c5a9da2ac40a13519eb5b0a0e8f11c" [[package]] name = "toml_edit" @@ -2345,7 +2380,7 @@ dependencies = [ "axerrno", "axio", "axlog", - "bitflags 2.9.1", + "bitflags 2.9.3", "lazy_init", "num_enum", "ringbuffer", @@ -2359,20 +2394,20 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] [[package]] name = "unicode-ident" -version = "1.0.13" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" +checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512" [[package]] name = "unicode-width" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0336d538f7abc86d282a4189614dfaa90810dfc2c6f6427eaf88e16311dd225d" +checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" [[package]] name = "unsafe_unwrap" @@ -2391,13 +2426,13 @@ name = "virtio-drivers" version = "0.11.0" source = "git+https://github.com/syswonder/virtio-drivers.git?rev=31f6555#31f6555c79f00f90caaedb09a8b1eab248c01afc" dependencies = [ - "bitflags 2.9.1", + "bitflags 2.9.3", "embedded-io", "enumn", "log", "safe-mmio", - "thiserror 2.0.12", - "zerocopy 0.8.26", + "thiserror", + "zerocopy", ] [[package]] @@ -2436,41 +2471,50 @@ dependencies = [ [[package]] name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" +version = "0.11.1+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasi" +version = "0.14.2+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9683f9a5a998d873c0d21fcbe3c083009670149a8fab228644b8bd36b2c48cb3" +dependencies = [ + "wit-bindgen-rt", +] [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "1edc8929d7499fc4e8f0be2262a241556cfc54a0bea223790e71446f2aab1ef5" dependencies = [ "cfg-if", "once_cell", + "rustversion", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "2f0a0651a5c2bc21487bde11ee802ccaf4c51935d0d3d42a6101f98161700bc6" dependencies = [ "bumpalo", "log", - "once_cell", "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "7fe63fc6d09ed3792bd0897b314f53de8e16568c2b3f7982f468c0bf9bd0b407" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -2478,28 +2522,31 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "8ae87ea40c9f689fc23f209965b6fb8a99ad69aeeb0231408be24920604395de" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.100" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "1a05d73b933a847d6cccdda8f838a22ff101ad9bf93e33684f39c1f5f0eece3d" +dependencies = [ + "unicode-ident", +] [[package]] name = "web-sys" -version = "0.3.70" +version = "0.3.77" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26fdeaafd9bd129f65e7c031593c24d62186301e0c72c8978fa1678be7d532c0" +checksum = "33b6dd2ef9186f1f2072e409e99cd22a975331a6b3591b12c764e0e55c60d5d2" dependencies = [ "js-sys", "wasm-bindgen", @@ -2519,29 +2566,70 @@ dependencies = [ [[package]] name = "winapi-util" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" +checksum = "0978bf7171b3d90bac376700cb56d606feb40f251a475a5d6634613564460b22" dependencies = [ - "windows-sys 0.59.0", + "windows-sys 0.60.2", ] [[package]] name = "windows-core" -version = "0.52.0" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +checksum = "c0fdd3ddb90610c7638aa2b3a3ab2904fb9e5cdbecc643ddb3647212781c4ae3" dependencies = [ - "windows-targets", + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", ] [[package]] -name = "windows-sys" -version = "0.52.0" +name = "windows-implement" +version = "0.60.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "windows-interface" +version = "0.59.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.106", +] + +[[package]] +name = "windows-link" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e6ad25900d524eaabdbbb96d20b4311e1e7ae1699af4fb28c17ae66c80d798a" + +[[package]] +name = "windows-result" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56f42bd332cc6c8eac5af113fc0c1fd6a8fd2aa08a0119358686e5160d0586c6" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +checksum = "56e6c93f3a0c3b36176cb1327a4958a0353d5d166c2a35cb268ace15e91d3b57" dependencies = [ - "windows-targets", + "windows-link", ] [[package]] @@ -2550,7 +2638,16 @@ version = "0.59.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" dependencies = [ - "windows-targets", + "windows-targets 0.52.6", +] + +[[package]] +name = "windows-sys" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f500e4d28234f72040990ec9d39e3a6b950f9f22d3dba18416c35882612bcb" +dependencies = [ + "windows-targets 0.53.3", ] [[package]] @@ -2559,14 +2656,31 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" dependencies = [ - "windows_aarch64_gnullvm", - "windows_aarch64_msvc", - "windows_i686_gnu", - "windows_i686_gnullvm", - "windows_i686_msvc", - "windows_x86_64_gnu", - "windows_x86_64_gnullvm", - "windows_x86_64_msvc", + "windows_aarch64_gnullvm 0.52.6", + "windows_aarch64_msvc 0.52.6", + "windows_i686_gnu 0.52.6", + "windows_i686_gnullvm 0.52.6", + "windows_i686_msvc 0.52.6", + "windows_x86_64_gnu 0.52.6", + "windows_x86_64_gnullvm 0.52.6", + "windows_x86_64_msvc 0.52.6", +] + +[[package]] +name = "windows-targets" +version = "0.53.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5fe6031c4041849d7c496a8ded650796e7b6ecc19df1a431c1a363342e5dc91" +dependencies = [ + "windows-link", + "windows_aarch64_gnullvm 0.53.0", + "windows_aarch64_msvc 0.53.0", + "windows_i686_gnu 0.53.0", + "windows_i686_gnullvm 0.53.0", + "windows_i686_msvc 0.53.0", + "windows_x86_64_gnu 0.53.0", + "windows_x86_64_gnullvm 0.53.0", + "windows_x86_64_msvc 0.53.0", ] [[package]] @@ -2575,48 +2689,96 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "86b8d5f90ddd19cb4a147a5fa63ca848db3df085e25fee3cc10b39b6eebae764" + [[package]] name = "windows_aarch64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" +[[package]] +name = "windows_aarch64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7651a1f62a11b8cbd5e0d42526e55f2c99886c77e007179efff86c2b137e66c" + [[package]] name = "windows_i686_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" +[[package]] +name = "windows_i686_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1dc67659d35f387f5f6c479dc4e28f1d4bb90ddd1a5d3da2e5d97b42d6272c3" + [[package]] name = "windows_i686_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" +[[package]] +name = "windows_i686_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ce6ccbdedbf6d6354471319e781c0dfef054c81fbc7cf83f338a4296c0cae11" + [[package]] name = "windows_i686_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" +[[package]] +name = "windows_i686_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "581fee95406bb13382d2f65cd4a908ca7b1e4c2f1917f143ba16efe98a589b5d" + [[package]] name = "windows_x86_64_gnu" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" +[[package]] +name = "windows_x86_64_gnu" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2e55b5ac9ea33f2fc1716d1742db15574fd6fc8dadc51caab1c16a3d3b4190ba" + [[package]] name = "windows_x86_64_gnullvm" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a6e035dd0599267ce1ee132e51c27dd29437f63325753051e71dd9e42406c57" + [[package]] name = "windows_x86_64_msvc" version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "windows_x86_64_msvc" +version = "0.53.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "271414315aff87387382ec3d271b52d7ae78726f5d44ac98b4f4030c91880486" + [[package]] name = "winnow" version = "0.5.40" @@ -2626,6 +2788,15 @@ dependencies = [ "memchr", ] +[[package]] +name = "wit-bindgen-rt" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f42320e61fe2cfd34354ecb597f86f413484a798ba44a8ca1165c58d42da6c1" +dependencies = [ + "bitflags 2.9.3", +] + [[package]] name = "x2apic" version = "0.5.0" @@ -2657,7 +2828,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c101112411baafbb4bf8d33e4c4a80ab5b02d74d2612331c61e8192fc9710491" dependencies = [ "bit_field", - "bitflags 2.9.1", + "bitflags 2.9.3", "rustversion", "volatile 0.4.6", ] @@ -2669,39 +2840,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae" dependencies = [ "bit_field", - "bitflags 2.9.1", + "bitflags 2.9.3", "rustversion", "volatile 0.4.6", ] -[[package]] -name = "zerocopy" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b9b4fd18abc82b8136838da5d50bae7bdea537c574d8dc1a34ed098d6c166f0" -dependencies = [ - "byteorder", - "zerocopy-derive 0.7.35", -] - [[package]] name = "zerocopy" version = "0.8.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1039dd0d3c310cf05de012d8a39ff557cb0d23087fd44cad61df08fc31907a2f" dependencies = [ - "zerocopy-derive 0.8.26", -] - -[[package]] -name = "zerocopy-derive" -version = "0.7.35" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" -dependencies = [ - "proc-macro2", - "quote", - "syn 2.0.87", + "zerocopy-derive", ] [[package]] @@ -2712,5 +2862,5 @@ checksum = "9ecf5b4cc5364572d7f4c329661bcc82724222973f2cab6f050a4e5c22f75181" dependencies = [ "proc-macro2", "quote", - "syn 2.0.87", + "syn 2.0.106", ] diff --git a/Makefile b/Makefile index ee4c54223..a78ffe565 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,7 @@ V9P ?= n BUS ?= mmio RISCV_BIOS ?= default GICV3 ?= n +RNG ?= n DISK_IMG ?= disk.img FS ?= fat32 diff --git a/api/ruxfeat/Cargo.toml b/api/ruxfeat/Cargo.toml index d13cca4b8..f8225300f 100644 --- a/api/ruxfeat/Cargo.toml +++ b/api/ruxfeat/Cargo.toml @@ -76,6 +76,9 @@ display = [ "ruxruntime/display", ] +#virtio random number generator +virtio-rng = ["ruxdriver/virtio-rng","ruxruntime/rng","ruxfs/rng"] + # 9P virtio-9p = [ "9pfs", diff --git a/api/ruxos_posix_api/Cargo.toml b/api/ruxos_posix_api/Cargo.toml index 6c81b07a3..f8f990506 100644 --- a/api/ruxos_posix_api/Cargo.toml +++ b/api/ruxos_posix_api/Cargo.toml @@ -32,6 +32,8 @@ poll = ["fd"] tls = ["ruxfeat/tls"] irq = ["ruxfeat/irq"] random-hw = [] +rng = ["ruxrand"] +virtio-rng = ["driver_virtio/rng","rng"] musl = ["ruxhal/musl", "ruxruntime/musl", "axalloc/slab", "ruxtask/musl"] @@ -52,6 +54,7 @@ ruxtask = { path = "../../modules/ruxtask", features = [ ruxfs = { path = "../../modules/ruxfs", optional = true } ruxfuse = { path = "../../modules/ruxfuse", optional = true } ruxnet = { path = "../../modules/ruxnet", optional = true } +ruxrand = { path = "../../modules/ruxrand", optional = true } # Other crates tty = { path = "../../crates/tty" } @@ -69,6 +72,8 @@ flatten_objects = { path = "../../crates/flatten_objects" } page_table = { path = "../../crates/page_table" } crate_interface = "0.1.1" capability = { path = "../../crates/capability" } +driver_virtio = { path = "../../crates/driver_virtio" } + cfg-if = "1.0" elf = { version = "0.7", default-features = false } diff --git a/api/ruxos_posix_api/src/imp/getrandom.rs b/api/ruxos_posix_api/src/imp/getrandom.rs index 99425d7dd..eb69ff53e 100644 --- a/api/ruxos_posix_api/src/imp/getrandom.rs +++ b/api/ruxos_posix_api/src/imp/getrandom.rs @@ -22,7 +22,7 @@ use crate::ctypes::{size_t, ssize_t}; use axerrno::LinuxError; -#[cfg(all(target_arch = "x86_64", feature = "random-hw"))] +#[cfg(all(target_arch = "x86_64", feature = "random-hw", not(feature = "rng")))] use core::arch::x86_64::__cpuid; static SEED: AtomicU64 = AtomicU64::new(0xae_f3); @@ -53,7 +53,7 @@ fn srand_lcg(seed: u64) { } /// Checking if the CPU core is compatible with hardware random number instructions. -#[cfg(feature = "random-hw")] +#[cfg(all(feature = "random-hw", not(feature = "rng")))] fn has_rdrand() -> bool { #[cfg(target_arch = "x86_64")] { @@ -77,7 +77,7 @@ fn has_rdrand() -> bool { } /// Return 64-bit unsigned random interger using cpu instruction -#[cfg(feature = "random-hw")] +#[cfg(all(feature = "random-hw", not(feature = "rng")))] fn random_hw() -> u64 { let mut _random: u64; @@ -118,33 +118,38 @@ pub unsafe extern "C" fn sys_srand(_seed: c_uint) { /// Returns a 32-bit unsigned random integer #[no_mangle] pub unsafe extern "C" fn sys_rand() -> c_int { - #[cfg(feature = "random-hw")] + #[cfg(all(feature = "rng", not(feature = "random-hw")))] { - match has_rdrand() { - true => (random_hw() >> 33) as c_int, - false => rand_lcg32() as c_int, - } + use ruxrand::random; + return random::(); } - #[cfg(not(feature = "random-hw"))] + #[cfg(all(feature = "random-hw", not(feature = "rng")))] { - rand_lcg32() as c_int + match has_rdrand() { + true => return (random_hw() >> 33) as c_int, + false => return rand_lcg32() as c_int, + } } + rand_lcg32() as c_int } /// Returns a 64-bit unsigned random integer #[no_mangle] pub unsafe extern "C" fn sys_random() -> c_long { - #[cfg(feature = "random-hw")] + #[cfg(all(feature = "rng", not(feature = "random-hw")))] { - match has_rdrand() { - true => (random_hw() >> 1) as c_long, - false => random_lcg64() as c_long, - } + use ruxrand::random; + return random::(); } - #[cfg(not(feature = "random-hw"))] + #[cfg(all(feature = "random-hw", not(feature = "rng")))] { - random_lcg64() as c_long + match has_rdrand() { + true => return (random_hw() >> 1) as c_long, + false => return random_lcg64() as c_long, + } } + + random_lcg64() as c_long } /// Fills the buffer pointed to by buf with up to buflen random bytes. @@ -159,15 +164,29 @@ pub unsafe extern "C" fn sys_getrandom(buf: *mut c_void, buflen: size_t, flags: if flags != 0 { warn!("flags are not implemented yet, flags: {flags}, ignored"); } - // fill the buffer 8 bytes at a time first, then fill the remaining bytes - let buflen_mod = buflen % (core::mem::size_of::() / core::mem::size_of::()); - let buflen_div = buflen / (core::mem::size_of::() / core::mem::size_of::()); - for i in 0..buflen_div { - *((buf as *mut u8 as *mut i64).add(i)) = sys_random() as i64; + #[cfg(feature = "rng")] + { + use ruxrand::request_entropy; + let slice: &mut [u8] = + unsafe { core::slice::from_raw_parts_mut(buf as *mut u8, buflen) }; + request_entropy(slice).map_err(|e| { + warn!("Failed to get random bytes: {e:?}"); + LinuxError::EIO + })?; + Ok(buflen as ssize_t) } - for i in 0..buflen_mod { - *((buf as *mut u8).add(buflen - buflen_mod + i)) = sys_rand() as u8; + #[cfg(not(feature = "rng"))] + { + // fill the buffer 8 bytes at a time first, then fill the remaining bytes + let buflen_mod = buflen % (core::mem::size_of::() / core::mem::size_of::()); + let buflen_div = buflen / (core::mem::size_of::() / core::mem::size_of::()); + for i in 0..buflen_div { + *((buf as *mut u8 as *mut i64).add(i)) = sys_random() as i64; + } + for i in 0..buflen_mod { + *((buf as *mut u8).add(buflen - buflen_mod + i)) = sys_rand() as u8; + } + Ok(buflen as ssize_t) } - Ok(buflen as ssize_t) }) } diff --git a/apps/c/libc-bench/Readme.md b/apps/c/libc-bench/Readme.md index 36120c62a..fdadaac7d 100644 --- a/apps/c/libc-bench/Readme.md +++ b/apps/c/libc-bench/Readme.md @@ -4,7 +4,7 @@ - Run with following command ``` -make A=apps/c/libc-bench/ MUSL=y BLK=y ARCH=aarch64 LOG=error SMP=4 run +make A=apps/c/libc-bench/ MUSL=y BLK=y RNG=y ARCH=aarch64 LOG=error SMP=4 run ``` - This benchmark includes (all codes are really simple to read): diff --git a/apps/c/random/features.txt b/apps/c/random/features.txt new file mode 100644 index 000000000..fce075eee --- /dev/null +++ b/apps/c/random/features.txt @@ -0,0 +1 @@ +virtio-rng \ No newline at end of file diff --git a/apps/c/random/main.c b/apps/c/random/main.c new file mode 100644 index 000000000..e337d37e9 --- /dev/null +++ b/apps/c/random/main.c @@ -0,0 +1,30 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Ruxos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +#define _GNU_SOURCE +#include +#include + +int main() { + printf("Using getrandom to fetch random bytes...\n"); + unsigned char buf[16]; + ssize_t n = getrandom(buf, sizeof(buf), 0); + if (n < 0) { + perror("getrandom"); + return 1; + } + + printf("Random bytes:\n"); + for (int i = 0; i < n; ++i) { + printf("%02x ", buf[i]); + } + printf("\n"); + + return 0; +} diff --git a/crates/driver_common/src/lib.rs b/crates/driver_common/src/lib.rs index 9d9f795c7..3a8785625 100644 --- a/crates/driver_common/src/lib.rs +++ b/crates/driver_common/src/lib.rs @@ -38,6 +38,8 @@ pub enum DeviceType { Display, /// Plan-9 device (e.g. 9pfs) _9P, + /// Random number generator device. + Rng, } /// The error type for device operation failures. diff --git a/crates/driver_rng/Cargo.toml b/crates/driver_rng/Cargo.toml new file mode 100644 index 000000000..93fba02b0 --- /dev/null +++ b/crates/driver_rng/Cargo.toml @@ -0,0 +1,28 @@ +[package] +name = "driver_rng" +version = "0.1.0" +edition = "2021" +authors = ["Haowen Liu <2401213328@stu.pku.edu.com>"] +description = "Common traits and types for random number generator device drivers" +license = "Mulan PSL v2" +homepage = "https://github.com/syswonder/ruxos" +repository = "https://github.com/syswonder/ruxos/tree/main/crates/driver_rng" + +[features] +default = [] +xoshiro= ["dep:rand_xoshiro"] + +easy-spin = [] + +[dependencies] +driver_common = { path = "../driver_common" } +crate_interface = "0.1.1" +rand = { version = "0.8.5", default-features = false } +rand_xoshiro = { version = "0.6.0", default-features = false, optional = true } + +spinlock = { version = "0.1.0", path = "../../crates/spinlock" } +percpu = "0.2" +lazy_init = { version = "0.1.0", path = "../../crates/lazy_init", default-features = false } + +[dev-dependencies] +rand = { version = "0.8.5" } \ No newline at end of file diff --git a/crates/driver_rng/src/lib.rs b/crates/driver_rng/src/lib.rs new file mode 100644 index 000000000..6a02956a3 --- /dev/null +++ b/crates/driver_rng/src/lib.rs @@ -0,0 +1,27 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Ruxos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +//! Common traits and types for random number generator device drivers. + +#![no_std] + +#[doc(no_inline)] +pub use driver_common::{BaseDriverOps, DevError, DevResult, DeviceType}; + +/// The information of the graphics device. +#[derive(Debug, Clone, Copy)] +pub struct RngInfo {} + +/// Operations that require a graphics device driver to implement. +pub trait RngDriverOps: BaseDriverOps { + /// Get the random number generator information. + fn info(&self) -> RngInfo; + /// Request random bytes from the device. + fn request_entropy(&mut self, dst: &mut [u8]) -> DevResult; +} diff --git a/crates/driver_virtio/Cargo.toml b/crates/driver_virtio/Cargo.toml index 57a1b5a7e..4d70a425b 100644 --- a/crates/driver_virtio/Cargo.toml +++ b/crates/driver_virtio/Cargo.toml @@ -18,6 +18,7 @@ net = ["driver_net"] gpu = ["driver_display"] v9p = ["driver_9p"] console = ["driver_console"] +rng = ["driver_rng"] [dependencies] log = { workspace = true } @@ -28,4 +29,5 @@ driver_net = { path = "../driver_net", optional = true } driver_display = { path = "../driver_display", optional = true } driver_9p = { path = "../driver_9p", optional = true } driver_console = { path = "../driver_console", optional = true } +driver_rng = { path = "../driver_rng", optional = true } virtio-drivers = { git = "https://github.com/syswonder/virtio-drivers.git", rev = "31f6555" } diff --git a/crates/driver_virtio/src/lib.rs b/crates/driver_virtio/src/lib.rs index f71803c92..f5f640098 100644 --- a/crates/driver_virtio/src/lib.rs +++ b/crates/driver_virtio/src/lib.rs @@ -31,6 +31,8 @@ mod console; mod gpu; #[cfg(feature = "net")] mod net; +#[cfg(feature = "rng")] +mod rng; #[cfg(feature = "v9p")] mod v9p; @@ -42,6 +44,8 @@ pub use self::console::VirtIoConsoleDev; pub use self::gpu::VirtIoGpuDev; #[cfg(feature = "net")] pub use self::net::VirtIoNetDev; +#[cfg(feature = "rng")] +pub use self::rng::VirtIoRngDev; #[cfg(feature = "v9p")] pub use self::v9p::VirtIo9pDev; @@ -99,6 +103,7 @@ const fn as_dev_type(t: VirtIoDevType) -> Option { GPU => Some(DeviceType::Display), _9P => Some(DeviceType::_9P), Console => Some(DeviceType::Char), + EntropySource => Some(DeviceType::Rng), _ => None, } } diff --git a/crates/driver_virtio/src/rng.rs b/crates/driver_virtio/src/rng.rs new file mode 100644 index 000000000..cd4cb4b07 --- /dev/null +++ b/crates/driver_virtio/src/rng.rs @@ -0,0 +1,60 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Ruxos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ + +extern crate alloc; +use crate::as_dev_err; + +use driver_common::{BaseDriverOps, DevResult, DeviceType}; +use driver_rng::{RngDriverOps, RngInfo}; +use virtio_drivers::{device::rng::VirtIORng as InnerDev, transport::Transport, Hal}; + +/// The VirtIO RNG device driver. +pub struct VirtIoRngDev { + inner: InnerDev, + info: RngInfo, +} + +unsafe impl Send for VirtIoRngDev {} +unsafe impl Sync for VirtIoRngDev {} + +impl VirtIoRngDev { + /// Creates a new driver instance and initializes the device, or returns + /// an error if any step fails. + pub fn try_new(transport: T) -> DevResult { + let virtio = InnerDev::new(transport).unwrap(); + let info = RngInfo {}; + Ok(Self { + inner: virtio, + info, + }) + } +} + +impl RngDriverOps for VirtIoRngDev { + fn info(&self) -> RngInfo { + self.info + } + + fn request_entropy(&mut self, dst: &mut [u8]) -> DevResult { + match self.inner.request_entropy(dst) { + Ok(size) => Ok(size), + Err(e) => Err(as_dev_err(e)), + } + } +} + +impl const BaseDriverOps for VirtIoRngDev { + fn device_name(&self) -> &str { + "virtio-rng" + } + + fn device_type(&self) -> DeviceType { + DeviceType::Rng + } +} diff --git a/modules/ruxdriver/Cargo.toml b/modules/ruxdriver/Cargo.toml index f20fad8b6..69cf107bd 100644 --- a/modules/ruxdriver/Cargo.toml +++ b/modules/ruxdriver/Cargo.toml @@ -21,14 +21,16 @@ block = ["driver_block"] display = ["driver_display"] _9p = ["driver_9p"] pci = [] +rng = ["driver_rng"] # Enabled by features `virtio-*` virtio = ["driver_virtio", "dep:axalloc", "dep:ruxhal", "dep:ruxconfig", "ruxhal/virtio"] # various types of drivers -virtio-blk = ["block", "virtio", "driver_virtio/block","virtio"] -virtio-net = ["net", "virtio", "driver_virtio/net", "virtio"] -virtio-gpu = ["display", "virtio", "driver_virtio/gpu", "virtio"] -virtio-9p = ["_9p","virtio", "driver_virtio/v9p", "virtio"] +virtio-blk = ["block", "virtio", "driver_virtio/block"] +virtio-net = ["net", "virtio", "driver_virtio/net"] +virtio-gpu = ["display", "virtio", "driver_virtio/gpu"] +virtio-9p = ["_9p","virtio", "driver_virtio/v9p"] +virtio-rng = ["rng","driver_virtio/rng", "virtio"] virtio_console = ["virtio"] ramdisk = ["block", "driver_block/ramdisk"] bcm2835-sdhci = ["block", "driver_block/bcm2835-sdhci"] @@ -48,6 +50,7 @@ driver_net = { path = "../../crates/driver_net", optional = true } driver_display = { path = "../../crates/driver_display", optional = true } driver_9p = { path = "../../crates/driver_9p", optional = true } driver_pci = { path = "../../crates/driver_pci", optional = true } +driver_rng = { path = "../../crates/driver_rng", optional = true } driver_virtio = { path = "../../crates/driver_virtio", optional = true } axalloc = { path = "../axalloc", optional = true } diff --git a/modules/ruxdriver/build.rs b/modules/ruxdriver/build.rs index 7446613e4..eaab0efca 100644 --- a/modules/ruxdriver/build.rs +++ b/modules/ruxdriver/build.rs @@ -10,6 +10,7 @@ const NET_DEV_FEATURES: &[&str] = &["ixgbe", "virtio-net", "loopback"]; const BLOCK_DEV_FEATURES: &[&str] = &["ramdisk", "bcm2835-sdhci", "virtio-blk"]; const DISPLAY_DEV_FEATURES: &[&str] = &["virtio-gpu"]; +const RNG_DEV_FEATURES: &[&str] = &["virtio-rng"]; const _9P_DEV_FEATURES: &[&str] = &["virtio-9p"]; fn has_feature(feature: &str) -> bool { @@ -44,6 +45,7 @@ fn main() { ("net", NET_DEV_FEATURES), ("block", BLOCK_DEV_FEATURES), ("display", DISPLAY_DEV_FEATURES), + ("rng", RNG_DEV_FEATURES), ("_9p", _9P_DEV_FEATURES), ] { if !has_feature(dev_kind) { @@ -81,6 +83,10 @@ fn main() { "cargo::rustc-check-cfg=cfg(display_dev, values({}, \"dummy\"))", make_cfg_values(DISPLAY_DEV_FEATURES) ); + println!( + "cargo::rustc-check-cfg=cfg(rng_dev, values({}, \"dummy\"))", + make_cfg_values(RNG_DEV_FEATURES) + ); println!( "cargo::rustc-check-cfg=cfg(_9p_dev, values({}, \"dummy\"))", make_cfg_values(_9P_DEV_FEATURES) diff --git a/modules/ruxdriver/src/drivers.rs b/modules/ruxdriver/src/drivers.rs index b0c260db6..ad58be2c2 100644 --- a/modules/ruxdriver/src/drivers.rs +++ b/modules/ruxdriver/src/drivers.rs @@ -77,6 +77,12 @@ register_display_driver!( ::Device<'static> ); +#[cfg(rng_dev = "virtio-rng")] +register_rng_driver!( + ::Driver, + ::Device<'static> +); + #[cfg(_9p_dev = "virtio-9p")] register_9p_driver!( ::Driver, diff --git a/modules/ruxdriver/src/dummy.rs b/modules/ruxdriver/src/dummy.rs index f048ef60c..34bbed4cc 100644 --- a/modules/ruxdriver/src/dummy.rs +++ b/modules/ruxdriver/src/dummy.rs @@ -113,6 +113,32 @@ cfg_if! { } } +cfg_if! { + if #[cfg(rng_dev = "dummy")] { + pub struct DummyRngDev; + pub struct DummyRngDriver; + register_rng_driver!(DummyRngDriver, DummyRngDev); + + impl BaseDriverOps for DummyRngDev { + fn device_type(&self) -> DeviceType { + DeviceType::Rng + } + fn device_name(&self) -> &str { + "dummy-rng" + } + } + + impl RngDriverOps for DummyRngDev { + fn info(&self) -> driver_rng::RngInfo { + unreachable!() + } + fn request_entropy(&mut self, _: &mut [u8]) -> DevResult { + unreachable!() + } + } + } +} + cfg_if! { if #[cfg(_9p_dev = "dummy")] { pub struct Dummy9pDev; diff --git a/modules/ruxdriver/src/lib.rs b/modules/ruxdriver/src/lib.rs index 3d213a293..0bee88fd5 100644 --- a/modules/ruxdriver/src/lib.rs +++ b/modules/ruxdriver/src/lib.rs @@ -101,6 +101,8 @@ pub use self::structs::AxBlockDevice; pub use self::structs::AxDisplayDevice; #[cfg(feature = "net")] pub use self::structs::AxNetDevice; +#[cfg(feature = "rng")] +pub use self::structs::AxRngDevice; /// A structure that contains all device drivers, organized by their category. #[derive(Default)] @@ -114,6 +116,9 @@ pub struct AllDevices { /// All graphics device drivers. #[cfg(feature = "display")] pub display: AxDeviceContainer, + /// All random number generator device drivers. + #[cfg(feature = "rng")] + pub rng: AxDeviceContainer, /// All 9p device drivers. #[cfg(feature = "_9p")] pub _9p: AxDeviceContainer, @@ -134,6 +139,7 @@ impl AllDevices { /// Probes all supported devices. fn probe(&mut self) { for_each_drivers!(type Driver, { + info!("Probing for {:?} devices...", core::any::type_name::()); if let Some(dev) = Driver::probe_global() { info!( "registered a new {:?} device: {:?}", @@ -157,6 +163,8 @@ impl AllDevices { AxDeviceEnum::Block(dev) => self.block.push(dev), #[cfg(feature = "display")] AxDeviceEnum::Display(dev) => self.display.push(dev), + #[cfg(feature = "rng")] + AxDeviceEnum::Rng(dev) => self.rng.push(dev), #[cfg(feature = "_9p")] AxDeviceEnum::_9P(dev) => self._9p.push(dev), } @@ -203,6 +211,14 @@ pub fn init_drivers() -> AllDevices { debug!(" 9p device {}: {:?}", i, dev.device_name()); } } + #[cfg(feature = "rng")] + { + debug!("number of rng devices: {}", all_devs.rng.len()); + for (i, dev) in all_devs.rng.iter().enumerate() { + assert_eq!(dev.device_type(), DeviceType::Rng); + debug!(" rng device {}: {:?}", i, dev.device_name()); + } + } all_devs } diff --git a/modules/ruxdriver/src/macros.rs b/modules/ruxdriver/src/macros.rs index cfd406d9e..341707f2a 100644 --- a/modules/ruxdriver/src/macros.rs +++ b/modules/ruxdriver/src/macros.rs @@ -35,6 +35,14 @@ macro_rules! register_display_driver { }; } +macro_rules! register_rng_driver { + ($driver_type:ty, $device_type:ty) => { + /// The unified type of the NIC devices. + #[cfg(not(feature = "dyn"))] + pub type AxRngDevice = $device_type; + }; +} + macro_rules! register_9p_driver { ($driver_type:ty, $device_type:ty) => { /// The unified type of the NIC devices. @@ -72,6 +80,11 @@ macro_rules! for_each_drivers { type $drv_type = ::Driver; $code } + #[cfg(rng_dev = "virtio-rng")] + { + type $drv_type = ::Driver; + $code + } #[cfg(_9p_dev = "virtio-9p")] { type $drv_type = ::Driver; diff --git a/modules/ruxdriver/src/prelude.rs b/modules/ruxdriver/src/prelude.rs index 3b9d0e176..c2d6fdda2 100644 --- a/modules/ruxdriver/src/prelude.rs +++ b/modules/ruxdriver/src/prelude.rs @@ -19,3 +19,5 @@ pub use {crate::structs::AxBlockDevice, driver_block::BlockDriverOps}; pub use {crate::structs::AxDisplayDevice, driver_display::DisplayDriverOps}; #[cfg(feature = "net")] pub use {crate::structs::AxNetDevice, driver_net::NetDriverOps}; +#[cfg(feature = "rng")] +pub use {crate::structs::AxRngDevice, driver_rng::RngDriverOps}; diff --git a/modules/ruxdriver/src/structs/dyn.rs b/modules/ruxdriver/src/structs/dyn.rs index dbb70bc95..bbf0f20ef 100644 --- a/modules/ruxdriver/src/structs/dyn.rs +++ b/modules/ruxdriver/src/structs/dyn.rs @@ -21,6 +21,9 @@ pub type AxBlockDevice = Box; /// The unified type of the graphics display devices. #[cfg(feature = "display")] pub type AxDisplayDevice = Box; +/// The unified type of the random number generator devices. +#[cfg(feature = "rng")] +pub type AxRngDevice = Box; /// The unified type of the 9p devices. #[cfg(feature = "_9p")] pub type Ax9pDevice = Box; @@ -38,12 +41,18 @@ impl super::AxDeviceEnum { Self::Block(Box::new(dev)) } - /// Constructs a display device. + /// Constructs a rng device. #[cfg(feature = "display")] pub fn from_display(dev: impl DisplayDriverOps + 'static) -> Self { Self::Display(Box::new(dev)) } + /// Constructs a display device. + #[cfg(feature = "rng")] + pub fn from_rng(dev: impl RngDriverOps + 'static) -> Self { + Self::Rng(Box::new(dev)) + } + /// Constructs a 9p device. #[cfg(feature = "_9p")] pub fn from_9p(dev: impl _9pDriverOps + 'static) -> Self { diff --git a/modules/ruxdriver/src/structs/mod.rs b/modules/ruxdriver/src/structs/mod.rs index 888188dc3..10abc05c5 100644 --- a/modules/ruxdriver/src/structs/mod.rs +++ b/modules/ruxdriver/src/structs/mod.rs @@ -27,6 +27,9 @@ pub enum AxDeviceEnum { /// Graphic display device. #[cfg(feature = "display")] Display(AxDisplayDevice), + /// Random number generator device. + #[cfg(feature = "rng")] + Rng(AxRngDevice), /// Plan-9 protocol device. #[cfg(feature = "_9p")] _9P(Ax9pDevice), @@ -43,6 +46,8 @@ impl BaseDriverOps for AxDeviceEnum { Self::Block(_) => DeviceType::Block, #[cfg(feature = "display")] Self::Display(_) => DeviceType::Display, + #[cfg(feature = "rng")] + Self::Rng(_) => DeviceType::Rng, #[cfg(feature = "_9p")] Self::_9P(_) => DeviceType::_9P, _ => unreachable!(), @@ -59,6 +64,8 @@ impl BaseDriverOps for AxDeviceEnum { Self::Block(dev) => dev.device_name(), #[cfg(feature = "display")] Self::Display(dev) => dev.device_name(), + #[cfg(feature = "rng")] + Self::Rng(dev) => dev.device_name(), #[cfg(feature = "_9p")] Self::_9P(dev) => dev.device_name(), _ => unreachable!(), diff --git a/modules/ruxdriver/src/structs/static.rs b/modules/ruxdriver/src/structs/static.rs index c6eaa168f..67cb8d55f 100644 --- a/modules/ruxdriver/src/structs/static.rs +++ b/modules/ruxdriver/src/structs/static.rs @@ -15,6 +15,8 @@ pub use crate::drivers::AxBlockDevice; pub use crate::drivers::AxDisplayDevice; #[cfg(feature = "net")] pub use crate::drivers::AxNetDevice; +#[cfg(feature = "rng")] +pub use crate::drivers::AxRngDevice; impl super::AxDeviceEnum { /// Constructs a network device. @@ -35,6 +37,12 @@ impl super::AxDeviceEnum { Self::Display(dev) } + /// Constructs a rng device. + #[cfg(feature = "rng")] + pub const fn from_rng(dev: AxRngDevice) -> Self { + Self::Rng(dev) + } + /// Constructs a display device. #[cfg(feature = "_9p")] pub const fn from_9p(dev: Ax9pDevice) -> Self { diff --git a/modules/ruxdriver/src/virtio.rs b/modules/ruxdriver/src/virtio.rs index 8b91da47a..f96c4318e 100644 --- a/modules/ruxdriver/src/virtio.rs +++ b/modules/ruxdriver/src/virtio.rs @@ -20,6 +20,7 @@ use ruxhal::mem::phys_to_virt; feature = "virtio-blk", feature = "virtio-gpu", feature = "virtio-9p", + feature = "virtio-rng", feature = "pci" ))] use ruxhal::virtio::virtio_hal::VirtIoHalImpl; @@ -110,6 +111,22 @@ cfg_if! { } } +cfg_if! { + if #[cfg(rng_dev = "virtio-rng")] { + /// A VirtIO RNG device. + pub struct VirtIoRng; + + impl VirtIoDevMeta for VirtIoRng { + const DEVICE_TYPE: DeviceType = DeviceType::Rng; + type Device<'a> = driver_virtio::VirtIoRngDev>; + + fn try_new(transport: VirtIoTransport<'static>) -> DevResult { + Ok(AxDeviceEnum::from_rng(Self::Device::try_new(transport)?)) + } + } + } +} + /// A common driver for all VirtIO devices that implements DriverProbe. pub struct VirtIoDriver(PhantomData); diff --git a/modules/ruxfs/Cargo.toml b/modules/ruxfs/Cargo.toml index 5ffe62d60..975c8d35d 100644 --- a/modules/ruxfs/Cargo.toml +++ b/modules/ruxfs/Cargo.toml @@ -28,6 +28,7 @@ myfs = [] use-ramdisk = [] alloc = ["axalloc"] fp_simd = [] +rng = ["dep:ruxrand"] default = ["devfs", "ramfs", "procfs", "sysfs", "etcfs", "mntfs"] @@ -49,6 +50,7 @@ ruxfifo = { path = "../../crates/ruxfifo" } crate_interface = { version = "0.1.1" } ruxfdtable = { path = "../ruxfdtable" } ruxdriver = { path = "../ruxdriver", features = ["block"] } +ruxrand = { path = "../ruxrand", optional = true } axalloc = { path = "../axalloc", optional = true } memory_addr = "0.1.0" # lwext4_rust = { git = "https://github.com/elliott10/lwext4_rust", optional = true } diff --git a/modules/ruxfs/src/lib.rs b/modules/ruxfs/src/lib.rs index 0ac7d4379..f1591d6f0 100644 --- a/modules/ruxfs/src/lib.rs +++ b/modules/ruxfs/src/lib.rs @@ -48,6 +48,8 @@ pub mod fifo; mod file; pub mod fops; pub mod fuse_st; +#[cfg(feature = "rng")] +pub mod rng_rand; pub mod root; pub use directory::Directory; diff --git a/modules/ruxfs/src/mounts.rs b/modules/ruxfs/src/mounts.rs index 05b92cde8..a88e9da87 100644 --- a/modules/ruxfs/src/mounts.rs +++ b/modules/ruxfs/src/mounts.rs @@ -18,7 +18,13 @@ use crate::fs; pub(crate) fn devfs() -> Arc { let null = fs::devfs::NullDev; let zero = fs::devfs::ZeroDev; + #[cfg(feature = "rng")] + let random = crate::rng_rand::RandomDev; + #[cfg(feature = "rng")] + let urandom = crate::rng_rand::RandomDev; + #[cfg(not(feature = "rng"))] let random = fs::devfs::RandomDev; + #[cfg(not(feature = "rng"))] let urandom = fs::devfs::RandomDev; let fuse = crate::devfuse::FuseDev::new(); let pts = fs::devfs::init_pts(); diff --git a/modules/ruxfs/src/rng_rand.rs b/modules/ruxfs/src/rng_rand.rs new file mode 100644 index 000000000..3de843b23 --- /dev/null +++ b/modules/ruxfs/src/rng_rand.rs @@ -0,0 +1,51 @@ +/* Copyright (c) [2023] [Syswonder Community] + * [Rukos] is licensed under Mulan PSL v2. + * You can use this software according to the terms and conditions of the Mulan PSL v2. + * You may obtain a copy of Mulan PSL v2 at: + * http://license.coscl.org.cn/MulanPSL2 + * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. + * See the Mulan PSL v2 for more details. + */ +//! random number generator from ruxrand for `/dev/random` and `/dev/urandom` + +use axfs_vfs::{VfsNodeAttr, VfsNodeOps, VfsNodePerm, VfsNodeType, VfsResult}; + +use axerrno::AxError; + +use ruxrand::request_entropy; + +/// A random device behaves like `/dev/random`. +/// +/// It always returns a chunk of random bytes when read, and all writes are discarded. +pub struct RandomDev; + +impl VfsNodeOps for RandomDev { + fn get_attr(&self) -> VfsResult { + Ok(VfsNodeAttr::new( + 6, + VfsNodePerm::default_file(), + VfsNodeType::CharDevice, + 0, + 0, + )) + } + + fn set_mode(&self, _mode: VfsNodePerm) -> VfsResult { + Ok(()) + } + + fn read_at(&self, _offset: u64, buf: &mut [u8]) -> VfsResult { + request_entropy(buf).map_err(|_e| AxError::Io)?; + Ok(buf.len()) + } + + fn write_at(&self, _offset: u64, buf: &[u8]) -> VfsResult { + Ok(buf.len()) + } + + fn truncate(&self, _size: u64) -> VfsResult { + Ok(()) + } + + axfs_vfs::impl_vfs_non_dir_default! {} +} diff --git a/modules/ruxhal/Cargo.toml b/modules/ruxhal/Cargo.toml index b94e265be..60a93cf56 100644 --- a/modules/ruxhal/Cargo.toml +++ b/modules/ruxhal/Cargo.toml @@ -66,7 +66,7 @@ tty = { path = "../../crates/tty" } [target.'cfg(target_arch = "x86_64")'.dependencies] x86 = "0.52" -x86_64 = "0.14.13" +x86_64 = "0.15.2" x2apic = "0.5" raw-cpuid = "11.0" diff --git a/modules/ruxrand/Cargo.toml b/modules/ruxrand/Cargo.toml index 2f5c2e9cd..227b5119f 100644 --- a/modules/ruxrand/Cargo.toml +++ b/modules/ruxrand/Cargo.toml @@ -10,17 +10,19 @@ repository = "https://github.com/rcore-os/arceos/tree/main/modules/ruxrand" [features] default = [] - easy-spin = [] [dependencies] +log = "0.4" +percpu = "0.2" crate_interface = "0.1.1" +driver_rng = { path = "../../crates/driver_rng"} +lazy_init = { path = "../../crates/lazy_init" } +ruxdriver = { path = "../ruxdriver", features = ["rng"] } rand = { version = "0.8.5", default-features = false } rand_xoshiro = { version = "0.6.0", default-features = false } - spinlock = { version = "0.1.0", path = "../../crates/spinlock" } -percpu = "0.2" -lazy_init = { version = "0.1.0", path = "../../crates/lazy_init", default-features = false } [dev-dependencies] rand = { version = "0.8.5" } + diff --git a/modules/ruxrand/src/lib.rs b/modules/ruxrand/src/lib.rs index b174e3d68..bfee9d84e 100644 --- a/modules/ruxrand/src/lib.rs +++ b/modules/ruxrand/src/lib.rs @@ -29,11 +29,25 @@ pub mod rng; mod spin_rand; - -pub use rng::{percpu_rng, random, PercpuRng}; +pub use rng::{percpu_rng, random, request_entropy, PercpuRng}; pub use spin_rand::ExpRand; +use log::info; +use ruxdriver::{prelude::*, AxDeviceContainer}; + /// Initializes the per-CPU RNGs on the given CPU. -pub fn init(cpuid: usize) { - rng::init(cpuid); +pub fn init(mut rng_devs: Option>, cpuid: usize) { + match rng_devs { + Some(ref mut devs) => { + while !devs.is_empty() { + let dev = devs.take_one().expect("No RNG device found!"); + info!(" use RNG: {:?}", dev.device_name()); + rng::init_dev(dev, cpuid); + } + } + None => { + info!(" use RNG: pseudo-random"); + rng::init(cpuid); + } + } } diff --git a/modules/ruxrand/src/rng.rs b/modules/ruxrand/src/rng.rs index bbd40a60e..8d3863cb2 100644 --- a/modules/ruxrand/src/rng.rs +++ b/modules/ruxrand/src/rng.rs @@ -8,18 +8,37 @@ */ use lazy_init::LazyInit; +use log::debug; use percpu::def_percpu; use rand::{distributions::Standard, prelude::*}; use rand_xoshiro::Xoshiro256StarStar; +use ruxdriver::prelude::*; #[allow(clippy::unusual_byte_groupings)] const RNG_SEED: u64 = 0xBAD_C0FFEE_0DD_F00D; -type PercpuRngType = Xoshiro256StarStar; +/// A per-CPU random number generator type that can be either a Xoshiro RNG or a device RNG. +pub enum PercpuRngType { + /// A Xoshiro256StarStar pseudo RNG. + Xoshiro(Xoshiro256StarStar), + /// A device RNG, which is typically used for hardware RNG devices. + Device(AxRngDevice), +} #[def_percpu] pub(crate) static PERCPU_RNG: LazyInit = LazyInit::new(); +/// Initializes the random number generator device. +pub fn init_dev(rng_dev: AxRngDevice, cpuid: usize) { + // Initialize the per-CPU RNG for the given CPU ID. + // This is a placeholder function and should be implemented + // to initialize the RNG for the specific CPU. + debug!("Initializing per-CPU RNG for CPU ID: {cpuid}"); + PERCPU_RNG.with_current(|percpu_ref| { + percpu_ref.init_by(PercpuRngType::Device(rng_dev)); + }); +} + /// Initializes the per-CPU random number generator (RNG). /// /// This function seeds the RNG with a hard-coded seed value and then performs a @@ -30,128 +49,74 @@ pub(crate) static PERCPU_RNG: LazyInit = LazyInit::new(); /// space for randomness on each CPU. pub(crate) fn init(cpuid: usize) { PERCPU_RNG.with_current(|percpu_ref| { - let mut rng = PercpuRngType::seed_from_u64(RNG_SEED); + let mut rng = Xoshiro256StarStar::seed_from_u64(RNG_SEED); for _ in 0..cpuid { rng.long_jump(); } - percpu_ref.init_by(rng); + percpu_ref.init_by(PercpuRngType::Xoshiro(rng)); }); } -// Rationale for using a raw pointer in `PercpuRng`: -// -// Just like the case in `rand::thread_rng`, there will only -// ever be one mutable reference generated from the mutable pointer, because -// we only have such a reference inside `next_u32`, `next_u64`, etc. Within a -// single processor (which is the definition of `PercpuRng`), there will only ever -// be one of these methods active at a time. -// -// A possible scenario where there could be multiple mutable references is if -// `PercpuRng` is used inside `next_u32` and co. But the implementation is -// completely under our control. We just have to ensure none of them use -// `PercpuRng` internally, which is nonsensical anyway. We should also never run -// `PercpuRng` in destructors of its implementation, which is also nonsensical. -// -// Another possible scenario is that an interrupt happens at the middle of `next_u32` -// or so, and the interrupt handler uses `PercpuRng`. This is indeed a violation of the -// Rust aliasing model, but can hardly lead to any true hazard I think. It can be easily -// fixed by requiring no IRQ using `kernel_guard` when implementing the functions provided -// by `RngCore`. - -/// A RNG wrapper that's local to the calling CPU. The actual RNG type is -/// `PercpuRngType`, which is currently [`Xoshiro256StarStar`]. -/// -/// This type is ! [`Send`] and ! [`Sync`], preventing potential misuse under -/// SMP environments. Construct this type using [`Default::default`], or just -/// a call to [`percpu_rng`]. -#[derive(Clone, Debug)] -pub struct PercpuRng { - rng: *mut PercpuRngType, +/// Returns a 32-bit random number using the per-CPU RNG. +// TODO: Implement the actual RNG initialization logic +pub fn percpu_rng() { + todo!("Implement the per-CPU RNG initialization logic"); } -impl PercpuRng { - fn get_rng(&mut self) -> &mut PercpuRngType { - unsafe { &mut *self.rng } - } -} +/// A simple random number generator that uses the per-CPU RNG. +pub struct PercpuRng; -impl Default for PercpuRng { - fn default() -> Self { - percpu_rng() +/// Generates a random value of type `T` +pub fn random() -> T +where + Standard: rand::distributions::Distribution, +{ + let size = core::mem::size_of::(); + let mut buf = [0u8; 64]; + assert!(size <= 64, "Requested type is too big"); + + let dst = &mut buf[..size]; + let rng: *mut PercpuRngType = + unsafe { PERCPU_RNG.current_ref_mut_raw().get_mut_unchecked() as *mut _ }; + match unsafe { &mut *rng } { + PercpuRngType::Device(ref mut dev) => { + let _ = dev.request_entropy(dst); + unsafe { core::ptr::read_unaligned(dst.as_ptr() as *const T) } + } + PercpuRngType::Xoshiro(ref mut rng) => rng.gen(), } } -impl RngCore for PercpuRng { - #[inline(always)] - fn next_u32(&mut self) -> u32 { - self.get_rng().next_u32() - } - - #[inline(always)] - fn next_u64(&mut self) -> u64 { - self.get_rng().next_u64() - } - - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.get_rng().fill_bytes(dest) +/// Requests entropy from the RNG and fills the provided buffer. +pub fn request_entropy(dst: &mut [u8]) -> DevResult { + let rng: *mut PercpuRngType = + unsafe { PERCPU_RNG.current_ref_mut_raw().get_mut_unchecked() as *mut _ }; + match unsafe { &mut *rng } { + PercpuRngType::Device(ref mut dev) => dev.request_entropy(dst), + PercpuRngType::Xoshiro(ref mut rng) => { + rng.fill_bytes(dst); + Ok(dst.len()) + } } +} - fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> { - self.get_rng().try_fill_bytes(dest) - } +/// Returns a 32-bit unsigned random integer. +pub fn next_u32() -> u32 { + random::() } -impl CryptoRng for PercpuRng {} +/// Returns a 64-bit unsigned random integer. +pub fn next_u64() -> u64 { + random::() +} -/// Retrieves the per-CPU RNG [`PercpuRng`] that points to the CPU-local RNG states. -/// -/// The RNGs were initialized by the same seed, but jumped to different locations in -/// the pseudo-random sequence, effectively making the RNG independently and identically -/// distributed on all CPUs. -pub fn percpu_rng() -> PercpuRng { - // It is unsafe to return mutable pointer to a global data structure - // without preemption disabled, but the baddest thing that can happen whatsoever - // here is the rng being put into some "random" state, which I think is not fatal. - let rng = unsafe { PERCPU_RNG.current_ref_mut_raw().get_mut_unchecked() as *mut _ }; - PercpuRng { rng } +/// Fills the provided buffer with random bytes. +pub fn fill_bytes(dest: &mut [u8]) { + request_entropy(dest).expect("Failed to fill bytes from RNG"); } -/// Generates a random value using the per-CPU random number generator. -/// -/// This is simply a shortcut for `percpu_rng().gen()`. See [`percpu_rng`] for -/// documentation of the entropy source and [`Standard`] for documentation of -/// distributions and type-specific generation. -/// -/// # Provided implementations -/// -/// The following types have provided implementations that -/// generate values with the following ranges and distributions: -/// -/// * Integers (`i32`, `u32`, `isize`, `usize`, etc.): Uniformly distributed -/// over all values of the type. -/// * `char`: Uniformly distributed over all Unicode scalar values, i.e. all -/// code points in the range `0...0x10_FFFF`, except for the range -/// `0xD800...0xDFFF` (the surrogate code points). This includes -/// unassigned/reserved code points. -/// * `bool`: Generates `false` or `true`, each with probability 0.5. -/// * Floating point types (`f32` and `f64`): Uniformly distributed in the -/// half-open range `[0, 1)`. See notes below. -/// * Wrapping integers (`Wrapping`), besides the type identical to their -/// normal integer variants. -/// -/// Also supported is the generation of the following -/// compound types where all component types are supported: -/// -/// * Tuples (up to 12 elements): each element is generated sequentially. -/// * Arrays (up to 32 elements): each element is generated sequentially; -/// see also [`Rng::fill`] which supports arbitrary array length for integer -/// types and tends to be faster for `u32` and smaller types. -/// * `Option` first generates a `bool`, and if true generates and returns -/// `Some(value)` where `value: T`, otherwise returning `None`. -pub fn random() -> T -where - Standard: Distribution, -{ - percpu_rng().gen() +/// Attempts to fill the provided buffer with random bytes, returning an error if it fails. +pub fn try_fill_bytes(_dest: &mut [u8]) -> Result<(), rand::Error> { + todo!() } diff --git a/modules/ruxrand/src/spin_rand.rs b/modules/ruxrand/src/spin_rand.rs index 0d39d0aa0..424946dab 100644 --- a/modules/ruxrand/src/spin_rand.rs +++ b/modules/ruxrand/src/spin_rand.rs @@ -15,6 +15,8 @@ use core::{ use rand::RngCore; use spinlock::{Backoff, Relax}; +use crate::rng::next_u32; + #[cfg(feature = "easy-spin")] type SpinRng = EasyRng; @@ -26,12 +28,11 @@ fn exp_rand_backoff(current_limit: &mut u32, max: u32) { let limit = *current_limit; *current_limit = max.max(limit); - let mut rng = SpinRng::default(); // It is more "correct" to use `rng.gen_range(0..limit)`, // but since `limit` would only be powers of two, a simple // modulo would also keep the distribution uniform as long // as `rng.next_u32()` keeps a uniform distribution on `u32`. - let delay = rng.next_u32() % limit; + let delay = next_u32() % limit; for _ in 0..delay { core::hint::spin_loop(); } diff --git a/modules/ruxruntime/Cargo.toml b/modules/ruxruntime/Cargo.toml index 40f172483..c7057c826 100644 --- a/modules/ruxruntime/Cargo.toml +++ b/modules/ruxruntime/Cargo.toml @@ -33,6 +33,7 @@ virtio-9p = ["fs", "rux9p"] net-9p = ["fs", "rux9p"] fusefs = ["ruxdriver/virtio-blk"] net = ["ruxdriver", "ruxnet"] +rng = ["ruxdriver","rand"] display = ["ruxdriver", "ruxdisplay"] signal = ["ruxhal/signal", "ruxtask/signal"] diff --git a/modules/ruxruntime/src/lib.rs b/modules/ruxruntime/src/lib.rs index a7554df69..6bcc575a4 100644 --- a/modules/ruxruntime/src/lib.rs +++ b/modules/ruxruntime/src/lib.rs @@ -195,9 +195,6 @@ pub extern "C" fn rust_main(cpu_id: usize, dtb: usize) -> ! { ruxhal::platform_init(cpu_id); - #[cfg(feature = "rand")] - ruxrand::init(cpu_id); - #[cfg(feature = "multitask")] { ruxtask::init_scheduler(); @@ -214,11 +211,17 @@ pub extern "C" fn rust_main(cpu_id: usize, dtb: usize) -> ! { #[cfg(feature = "virtio_console")] ruxhal::virtio::virtio_console::directional_probing(); - #[cfg(any(feature = "fs", feature = "net", feature = "display"))] + #[cfg(any(feature = "fs", feature = "net", feature = "display", feature = "rand"))] { #[allow(unused_variables)] let all_devices = ruxdriver::init_drivers(); + #[cfg(feature = "rng")] + ruxrand::init(Some(all_devices.rng), cpu_id); + + #[cfg(not(feature = "rng"))] + ruxrand::init(None, cpu_id); + #[cfg(feature = "net")] ruxnet::init_network(all_devices.net); diff --git a/modules/ruxruntime/src/mp.rs b/modules/ruxruntime/src/mp.rs index 9c27e30ce..5a8185217 100644 --- a/modules/ruxruntime/src/mp.rs +++ b/modules/ruxruntime/src/mp.rs @@ -45,9 +45,6 @@ pub extern "C" fn rust_main_secondary(cpu_id: usize) -> ! { ruxhal::platform_init_secondary(); - #[cfg(feature = "rand")] - ruxrand::init(cpu_id); - #[cfg(feature = "multitask")] ruxtask::init_scheduler_secondary(); diff --git a/scripts/make/features.mk b/scripts/make/features.mk index 5c7da2450..8b3cfde8e 100644 --- a/scripts/make/features.mk +++ b/scripts/make/features.mk @@ -14,7 +14,7 @@ ifeq ($(APP_TYPE),c) ax_feat_prefix := ruxfeat/ lib_feat_prefix := ruxmusl/ - lib_features := fp_simd alloc irq sched_rr paging multitask fs net fd pipe select poll epoll random-hw signal + lib_features := fp_simd alloc irq sched_rr paging multitask fs net fd pipe select poll epoll random-hw signal rng else # TODO: it's better to use `ruxfeat/` as `ax_feat_prefix`, but all apps need to have `ruxfeat` as a dependency ax_feat_prefix := axstd/ @@ -55,6 +55,10 @@ ifeq ($(GICV3),y) override FEATURES += gic-v3 endif +ifeq ($(RNG),y) + override FEATURES += rng +endif + override FEATURES := $(strip $(FEATURES)) ax_feat := diff --git a/ulib/ruxmusl/Cargo.toml b/ulib/ruxmusl/Cargo.toml index 9660bfa82..fea53d3bb 100644 --- a/ulib/ruxmusl/Cargo.toml +++ b/ulib/ruxmusl/Cargo.toml @@ -34,6 +34,9 @@ fs = ["ruxos_posix_api/fs", "fd"] # Networking net = ["ruxos_posix_api/net", "fd"] +# random number generator +rng = ["ruxos_posix_api/rng"] + # Libc features fd = ["ruxos_posix_api/fd"] pipe = ["ruxos_posix_api/pipe"]