From 8eb5d2ecf1e6db0ec95b362707107e30ea4e50af Mon Sep 17 00:00:00 2001 From: Mark Poliakov Date: Sun, 9 Jun 2024 13:43:56 +0300 Subject: [PATCH] mem/heap: use libyalloc instead of linked_list_allocator in kernel --- Cargo.lock | 409 ++++++++++++++--------------- kernel/arch/aarch64/src/mem/mod.rs | 22 -- kernel/arch/x86_64/src/mem/mod.rs | 28 +- kernel/libk/libk-mm/Cargo.toml | 3 +- kernel/libk/libk-mm/src/heap.rs | 67 ++--- kernel/modules/test_mod/Cargo.lock | 65 ++--- kernel/src/arch/aarch64/mod.rs | 18 +- kernel/src/arch/x86_64/mod.rs | 17 +- kernel/src/main.rs | 3 - kernel/src/mem/heap.rs | 0 lib/libyalloc/Cargo.toml | 4 +- lib/libyalloc/src/allocator.rs | 46 ++-- lib/libyalloc/src/bucket.rs | 43 ++- lib/libyalloc/src/global.rs | 5 +- lib/libyalloc/src/lib.rs | 7 +- lib/libyalloc/src/sys.rs | 57 ++++ lib/libyalloc/src/util.rs | 58 +--- xtask/src/build/x86_64.rs | 2 +- 18 files changed, 403 insertions(+), 451 deletions(-) delete mode 100644 kernel/src/mem/heap.rs create mode 100644 lib/libyalloc/src/sys.rs diff --git a/Cargo.lock b/Cargo.lock index 25d41c01..7f955f3a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -17,7 +17,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", "thiserror", ] @@ -71,9 +71,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.2" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2969dcb958b36655471fc61f7e416fa76033bdd4bfed0678d8fee1e2d07a1f0" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] @@ -107,47 +107,48 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys", @@ -166,9 +167,9 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "bit-set" @@ -199,9 +200,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.4.2" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed570934406eb16438a4e976b1b4500774099c13b8cb96eec99f620f05090ddf" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "bitvec" @@ -233,22 +234,22 @@ checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "bytemuck" -version = "1.14.3" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2ef034f05691a48569bd920a96c81b9d91bbad1ab5ac7c4616c1f6ef36cb79f" +checksum = "78834c15cb5d5efe3452d58b1e8ba890dd62d21907f867f383358198e56ebca5" dependencies = [ "bytemuck_derive", ] [[package]] name = "bytemuck_derive" -version = "1.6.0" +version = "1.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4da9a32f3fed317401fa3c862968128267c3106685286e15d5aaa3d7389c2f60" +checksum = "1ee891b04274a59bd38b412188e24b849617b2e45a0fd8d057deb63e7403761b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] @@ -259,12 +260,13 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "cc" -version = "1.0.90" +version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" dependencies = [ "jobserver", "libc", + "once_cell", ] [[package]] @@ -275,9 +277,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "chrono" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", @@ -289,9 +291,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.2" +version = "4.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b230ab84b0ffdf890d5a10abdbc8b83ae1c4918275daea1ab8801f71536b2651" +checksum = "a9689a29b593160de5bc4aacab7b5d54fb52231de70122626c178e6a368994c7" dependencies = [ "clap_builder", "clap_derive", @@ -299,9 +301,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.2" +version = "4.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ae129e2e766ae0ec03484e609954119f123cc1fe650337e155d03b022f24f7b4" +checksum = "2e5387378c84f6faa26890ebf9f0a92989f8873d4d380467bcd0d8d8620424df" dependencies = [ "anstream", "anstyle", @@ -311,33 +313,33 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.0" +version = "4.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "307bc0538d5f0f83b8248db3087aa92fe504e4691294d0c96c0eabc33f47ba47" +checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "compiler_builtins" -version = "0.1.108" +version = "0.1.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d68bc55329711cd719c2687bb147bc06211b0521f97ef398280108ccb23227e9" +checksum = "b15acab2bb4fe4dad1f1e31f3d9e714f50ef561a0f87dd8a9da004f14d455e1a" dependencies = [ "rustc-std-workspace-core", ] @@ -359,9 +361,9 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.8.19" +version = "0.8.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "248e3bacc7dc6baa3b21e405ee045c3047101a49145e7e9eca583ab4c2ca5345" +checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" [[package]] name = "dependency-graph" @@ -386,7 +388,7 @@ version = "0.1.0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] @@ -413,9 +415,9 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "elf" @@ -454,7 +456,7 @@ checksum = "f282cfdfe92516eb26c2af8589c274c7c17681f5ecc03c18255fe741c6aa64eb" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] @@ -488,9 +490,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys", @@ -504,9 +506,9 @@ checksum = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" [[package]] name = "fastrand" -version = "2.0.1" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "25cbce373ec4653f1a01a31e8a5e5ec0c622dc27ff9c4e6606eefef5cbbed4a5" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fatfs" @@ -612,7 +614,7 @@ dependencies = [ name = "gentables" version = "0.1.0" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "clap", "elf 0.7.4", @@ -622,9 +624,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", "libc", @@ -648,16 +650,16 @@ checksum = "53010ccb100b96a67bc32c0175f0ed1426b31b655d562898e57325f81c023ac0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] name = "git2" -version = "0.18.2" +version = "0.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b3ba52851e73b46a4c3df1d89343741112003f0f6f13beb0dfac9e457c3fdcd" +checksum = "232e6a7bfe35766bf715e55a88b39a700596c0ccfd88cd3680b4cdb40d66ef70" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "libc", "libgit2-sys", "log", @@ -668,15 +670,15 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" -version = "0.4.1" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "home" @@ -728,14 +730,20 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.2.5" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b0b929d511467233429c45a44ac1dcaa21ba0f5ba11e4879e6ed28ddb4f9df4" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", "hashbrown", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "itertools" version = "0.11.0" @@ -756,15 +764,15 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.10" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1a46d1a171d865aa5f83f92695765caa047a9b4cbae2cbf37dbd613a793fd4c" +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.28" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -794,7 +802,7 @@ name = "kernel-arch-aarch64" version = "0.1.0" dependencies = [ "aarch64-cpu", - "bitflags 2.4.2", + "bitflags 2.5.0", "device-api", "kernel-arch-interface", "libk-mm-interface", @@ -825,7 +833,7 @@ dependencies = [ name = "kernel-arch-x86_64" version = "0.1.0" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "device-api", "kernel-arch-interface", "libk-mm-interface", @@ -853,9 +861,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" dependencies = [ "rustc-std-workspace-core", ] @@ -913,7 +921,7 @@ dependencies = [ "kernel-arch", "libk-mm-interface", "libk-util", - "linked_list_allocator", + "libyalloc", "log", "vmalloc", "yggdrasil-abi", @@ -923,7 +931,7 @@ dependencies = [ name = "libk-mm-interface" version = "0.1.0" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "kernel-arch-interface", "yggdrasil-abi", @@ -982,9 +990,9 @@ dependencies = [ [[package]] name = "libz-sys" -version = "1.1.15" +version = "1.1.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "037731f5d3aaa87a5675e895b63ddff1a87624bc29f77004ea829809654e48f6" +checksum = "c15da26e5af7e25c90b37a2d75cdbf940cf4a55316de9d84c679c9b8bfabf82e" dependencies = [ "cc", "libc", @@ -992,26 +1000,17 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "linked_list_allocator" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" -dependencies = [ - "spinning_top", -] - [[package]] name = "linux-raw-sys" -version = "0.4.13" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1025,9 +1024,9 @@ checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" [[package]] name = "memchr" -version = "2.7.1" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "memfs" @@ -1051,9 +1050,9 @@ dependencies = [ [[package]] name = "memoffset" -version = "0.9.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a634b1c61a95585bd15607c6ab0c4e5b226e695ff2800ba0cdccddf208c406c" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" dependencies = [ "autocfg", ] @@ -1078,9 +1077,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1100,9 +1099,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.101" +version = "0.9.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dda2b0f344e78efc2facf7d195d098df0dd72151b26ab98da807afc26c198dff" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" dependencies = [ "cc", "libc", @@ -1112,9 +1111,9 @@ dependencies = [ [[package]] name = "paste" -version = "1.0.14" +version = "1.0.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c" +checksum = "57c0d7b74b563b49d38dae00a0c37d4d6de9b432382b2892f0574ddcae73fd0a" [[package]] name = "percent-encoding" @@ -1124,9 +1123,9 @@ checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "petgraph" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1d3afd2628e69da2be385eb6f2fd57c8ac7977ceeff6dc166ff1657b0e386a9" +checksum = "b4c5cc86750666a3ed20bdaf5ca2a0344f9c67674cae0515bec2da16fbaa47db" dependencies = [ "fixedbitset", "indexmap", @@ -1134,9 +1133,9 @@ dependencies = [ [[package]] name = "pin-project-lite" -version = "0.2.13" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -1158,19 +1157,19 @@ checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "prettyplease" -version = "0.2.16" +version = "0.2.20" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41cf62165e97c7f814d2221421dbb9afcbcdb0a88068e5ea206e19951c2cbb5" +checksum = "5f12335488a2f3b0a83b14edad48dca9879ce89b2edd10e80237e4e852dd645e" dependencies = [ "proc-macro2", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" dependencies = [ "unicode-ident", ] @@ -1183,7 +1182,7 @@ checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", "bit-vec", - "bitflags 2.4.2", + "bitflags 2.5.0", "lazy_static", "num-traits", "rand", @@ -1208,9 +1207,9 @@ checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -1271,9 +1270,9 @@ dependencies = [ [[package]] name = "regex" -version = "1.10.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b62dbe01f0b06f9d8dc7d49e05a0785f153b00b2c227856282f671e0318c9b15" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", @@ -1294,9 +1293,9 @@ dependencies = [ [[package]] name = "regex-syntax" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "rsdp" @@ -1329,11 +1328,11 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.31" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ea3e1a662af26cd7a3ba09c0297a31af215563ecf42817c98df621387f4e949" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "errno", "libc", "linux-raw-sys", @@ -1342,9 +1341,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.14" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffc183a10b4478d04cbbbfc96d0873219d962dd5accaff2ffbd4ceb7df837f4" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "rusty-fork" @@ -1360,9 +1359,9 @@ dependencies = [ [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -1390,9 +1389,9 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" dependencies = [ "serde", ] @@ -1405,29 +1404,29 @@ checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] name = "serde_json" -version = "1.0.114" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c5f09b1bd632ef549eaa9f60a1f8de742bdbc698e6cee2095fc84dde5f549ae0" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -1436,9 +1435,9 @@ dependencies = [ [[package]] name = "serde_spanned" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eb3622f419d1296904700073ea6cc23ad690adbd66f13ea683df73298736f0c1" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -1460,9 +1459,9 @@ checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strsim" -version = "0.11.0" +version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5ee073c9e4cd00e28217186dbe12796d692868f432bf2e97ee73bed0c56dfa01" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" @@ -1477,9 +1476,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.52" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ "proc-macro2", "quote", @@ -1494,9 +1493,9 @@ checksum = "55937e1799185b12863d447f42597ed69d9928686b8d88a1df17376a097d8369" [[package]] name = "tar" -version = "0.4.40" +version = "0.4.41" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" +checksum = "cb797dad5fb5b76fcf519e702f4a589483b5ef06567f160c392832c1f5e44909" dependencies = [ "filetime", "libc", @@ -1517,22 +1516,22 @@ dependencies = [ [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] [[package]] @@ -1564,9 +1563,9 @@ checksum = "2b9e2fdb3a1e862c0661768b7ed25390811df1947a8acbfbefe09b47078d93c4" [[package]] name = "toml" -version = "0.8.11" +version = "0.8.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af06656561d28735e9c1cd63dfd57132c8155426aa6af24f36a00a351f88c48e" +checksum = "6f49eb2ab21d2f26bd6db7bf383edc527a7ebaee412d17af4d40fdccd442f335" dependencies = [ "serde", "serde_spanned", @@ -1576,18 +1575,18 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.22.7" +version = "0.22.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18769cd1cec395d70860ceb4d932812a0b4d06b1a4bb336745a4d21b9496e992" +checksum = "f21c7aaf97f1bd9ca9d4f9e73b0a6c74bd5afef56f2bc931943a6e1c37e04e38" dependencies = [ "indexmap", "serde", @@ -1642,9 +1641,9 @@ dependencies = [ [[package]] name = "utf8parse" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" +checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "vcpkg" @@ -1714,7 +1713,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", "wasm-bindgen-shared", ] @@ -1736,7 +1735,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -1749,48 +1748,25 @@ checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "which" -version = "6.0.0" +version = "6.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fa5e0c10bf77f44aac573e498d1a82d5fbd5e91f6fc0a99e7be4b38e85e101c" +checksum = "8211e4f58a2b2805adfbefbc07bab82958fc91e3836339b1ab7ae32465dce0d7" dependencies = [ "either", "home", - "once_cell", "rustix", - "windows-sys", + "winsafe", ] -[[package]] -name = "winapi" -version = "0.3.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" - [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys", ] -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" - [[package]] name = "windows-core" version = "0.52.0" @@ -1811,13 +1787,14 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ "windows_aarch64_gnullvm", "windows_aarch64_msvc", "windows_i686_gnu", + "windows_i686_gnullvm", "windows_i686_msvc", "windows_x86_64_gnu", "windows_x86_64_gnullvm", @@ -1826,55 +1803,67 @@ dependencies = [ [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "59b5e5f6c299a3c7890b876a2a587f3115162487e704907d9b6cd29473052ba1" dependencies = [ "memchr", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "wyz" version = "0.5.1" @@ -1919,7 +1908,7 @@ dependencies = [ "git2", "log", "qemu", - "semver 1.0.22", + "semver 1.0.23", "serde", "tar", "thiserror", @@ -1947,7 +1936,7 @@ dependencies = [ "libk-mm", "libk-util", "log", - "memoffset 0.9.0", + "memoffset 0.9.1", "static_assertions", "tock-registers 0.8.1", "ygg_driver_pci", @@ -2014,7 +2003,7 @@ name = "ygg_driver_pci" version = "0.1.0" dependencies = [ "acpi", - "bitflags 2.4.2", + "bitflags 2.5.0", "device-api", "libk-device", "libk-mm", @@ -2062,7 +2051,7 @@ dependencies = [ name = "ygg_driver_virtio_core" version = "0.1.0" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "device-api", "libk-mm", "log", @@ -2075,7 +2064,7 @@ dependencies = [ name = "ygg_driver_virtio_net" version = "0.1.0" dependencies = [ - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "device-api", "libk-mm", @@ -2113,7 +2102,7 @@ dependencies = [ "acpi-system", "aml", "atomic_enum", - "bitflags 2.4.2", + "bitflags 2.5.0", "bytemuck", "crossbeam-queue", "device-api", @@ -2168,20 +2157,20 @@ dependencies = [ [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.52", + "syn 2.0.66", ] diff --git a/kernel/arch/aarch64/src/mem/mod.rs b/kernel/arch/aarch64/src/mem/mod.rs index d248186b..df2c8e87 100644 --- a/kernel/arch/aarch64/src/mem/mod.rs +++ b/kernel/arch/aarch64/src/mem/mod.rs @@ -47,8 +47,6 @@ const_assert_eq!(KERNEL_L1_INDEX, 1); // 2MiB max const EARLY_MAPPING_L2I: usize = KERNEL_END_L2_INDEX + 1; // 1GiB max -const HEAP_MAPPING_L1I: usize = KERNEL_L1_INDEX + 1; -// 1GiB max const DEVICE_MAPPING_L1I: usize = KERNEL_L1_INDEX + 2; const DEVICE_MAPPING_L3_COUNT: usize = 4; // 16GiB max @@ -59,9 +57,6 @@ pub const RAM_MAPPING_L1_COUNT: usize = 16; const EARLY_MAPPING_OFFSET: usize = MAPPING_OFFSET | (KERNEL_L1_INDEX * L1::SIZE) | (EARLY_MAPPING_L2I * L2::SIZE); static mut EARLY_MAPPING_L3: PageTable = PageTable::zeroed(); -// 1GiB for heap mapping -pub const HEAP_MAPPING_OFFSET: usize = MAPPING_OFFSET | (HEAP_MAPPING_L1I * L1::SIZE); -pub static mut HEAP_MAPPING_L2: PageTable = PageTable::zeroed(); // 1GiB for device MMIO mapping const DEVICE_MAPPING_OFFSET: usize = MAPPING_OFFSET | (DEVICE_MAPPING_L1I * L1::SIZE); static mut DEVICE_MAPPING_L2: PageTable = PageTable::zeroed(); @@ -232,18 +227,6 @@ pub unsafe fn map_ram_l1(index: usize) { ((index * L1::SIZE) as u64) | ram_block_flags().bits(); } -/// # Safety -/// -/// Only meant to be used by the architecture initialization functions. -pub unsafe fn map_heap_l2(index: usize, page: PhysicalAddress) { - if index >= 512 { - todo!() - } - assert!(!HEAP_MAPPING_L2[index].is_present()); - // TODO UXN, PXN - HEAP_MAPPING_L2[index] = PageEntry::normal_block(page, PageAttributes::empty()); -} - // Device mappings unsafe fn map_device_memory_l3( base: PhysicalAddress, @@ -394,7 +377,6 @@ pub unsafe fn init_fixed_tables() { // TODO this could be built in compile-time too? let early_mapping_l3_phys = addr_of!(EARLY_MAPPING_L3) as usize - KERNEL_VIRT_OFFSET; let device_mapping_l2_phys = addr_of!(DEVICE_MAPPING_L2) as usize - KERNEL_VIRT_OFFSET; - let heap_mapping_l2_phys = addr_of!(HEAP_MAPPING_L2) as usize - KERNEL_VIRT_OFFSET; for i in 0..DEVICE_MAPPING_L3_COUNT { let device_mapping_l3_phys = PhysicalAddress::from_raw( @@ -407,10 +389,6 @@ pub unsafe fn init_fixed_tables() { KERNEL_TABLES.l2.data[EARLY_MAPPING_L2I] = (early_mapping_l3_phys as u64) | kernel_table_flags().bits(); - assert_eq!(KERNEL_TABLES.l1.data[HEAP_MAPPING_L1I], 0); - KERNEL_TABLES.l1.data[HEAP_MAPPING_L1I] = - (heap_mapping_l2_phys as u64) | kernel_table_flags().bits(); - assert_eq!(KERNEL_TABLES.l1.data[DEVICE_MAPPING_L1I], 0); KERNEL_TABLES.l1.data[DEVICE_MAPPING_L1I] = (device_mapping_l2_phys as u64) | kernel_table_flags().bits(); diff --git a/kernel/arch/x86_64/src/mem/mod.rs b/kernel/arch/x86_64/src/mem/mod.rs index 6c21b029..15092376 100644 --- a/kernel/arch/x86_64/src/mem/mod.rs +++ b/kernel/arch/x86_64/src/mem/mod.rs @@ -44,7 +44,6 @@ const_assert_eq!(KERNEL_L1_INDEX, 0); // Mapped at boot const EARLY_MAPPING_L2I: usize = KERNEL_START_L2_INDEX - 1; -const HEAP_MAPPING_L1I: usize = KERNEL_L1_INDEX + 1; const DEVICE_MAPPING_L1I: usize = KERNEL_L1_INDEX + 2; const RAM_MAPPING_L0I: usize = KERNEL_L0_INDEX - 1; @@ -60,10 +59,6 @@ const EARLY_MAPPING_OFFSET: usize = CANONICAL_ADDRESS_MASK | (KERNEL_L1_INDEX * L1::SIZE) | (EARLY_MAPPING_L2I * L2::SIZE); static mut EARLY_MAPPING_L3: PageTable = PageTable::zeroed(); -// 1GiB for heap mapping -pub const HEAP_MAPPING_OFFSET: usize = - CANONICAL_ADDRESS_MASK | (KERNEL_L0_INDEX * L0::SIZE) | (HEAP_MAPPING_L1I * L1::SIZE); -pub(super) static mut HEAP_MAPPING_L2: PageTable = PageTable::zeroed(); // 1GiB for device MMIO mapping const DEVICE_MAPPING_OFFSET: usize = CANONICAL_ADDRESS_MASK | (KERNEL_L0_INDEX * L0::SIZE) | (DEVICE_MAPPING_L1I * L1::SIZE); @@ -269,23 +264,6 @@ unsafe fn unmap_device_memory(map: &RawDeviceMemoryMapping() { - panic!("Attempted to map a misaligned 2MiB page"); - } - assert!(index < 512); - - if HEAP_MAPPING_L2[index].is_present() { - panic!("Page is already mappged: {:#x}", page); - } - - // TODO NX - HEAP_MAPPING_L2[index] = PageEntry::::block(page, PageAttributes::WRITABLE); -} - /// Memory mapping which may be used for performing early kernel initialization pub struct EarlyMapping<'a, T: ?Sized> { value: &'a mut T, @@ -371,7 +349,7 @@ pub fn clone_kernel_tables(dst: &mut PageTable) { /// * 0xFFFFFF8000000000 .. 0xFFFFFF8000200000 : --- /// * 0xFFFFFF8000200000 .. 0xFFFFFF8000400000 : EARLY_MAPPING_L3 /// * 0xFFFFFF8000400000 .. ... : KERNEL_TABLES.kernel_l3s -/// * 0xFFFFFF8040000000 .. 0xFFFFFF8080000000 : HEAP_MAPPING_L2 +/// * 0xFFFFFF8040000000 .. 0xFFFFFF8080000000 : --- /// * 0xFFFFFF8080000000 .. 0xFFFFFF8100000000 : DEVICE_MAPPING_L2 /// * 0xFFFFFF8080000000 .. 0xFFFFFF8080800000 : DEVICE_MAPPING_L3S /// * 0xFFFFFF8080800000 .. 0xFFFFFF8100000000 : ... @@ -383,7 +361,6 @@ pub unsafe fn init_fixed_tables() { // TODO this could be built in compile-time too? let early_mapping_l3_phys = addr_of!(EARLY_MAPPING_L3) as usize - KERNEL_VIRT_OFFSET; let device_mapping_l2_phys = addr_of!(DEVICE_MAPPING_L2) as usize - KERNEL_VIRT_OFFSET; - let heap_mapping_l2_phys = addr_of!(HEAP_MAPPING_L2) as usize - KERNEL_VIRT_OFFSET; let ram_mapping_l1_phys = addr_of!(RAM_MAPPING_L1) as usize - KERNEL_VIRT_OFFSET; for i in 0..DEVICE_MAPPING_L3_COUNT { @@ -397,9 +374,6 @@ pub unsafe fn init_fixed_tables() { KERNEL_TABLES.kernel_l2.data[EARLY_MAPPING_L2I] = (early_mapping_l3_phys as u64) | (PageAttributes::WRITABLE | PageAttributes::PRESENT).bits(); - assert_eq!(KERNEL_TABLES.kernel_l1.data[HEAP_MAPPING_L1I], 0); - KERNEL_TABLES.kernel_l1.data[HEAP_MAPPING_L1I] = - (heap_mapping_l2_phys as u64) | (PageAttributes::WRITABLE | PageAttributes::PRESENT).bits(); assert_eq!(KERNEL_TABLES.kernel_l1.data[DEVICE_MAPPING_L1I], 0); KERNEL_TABLES.kernel_l1.data[DEVICE_MAPPING_L1I] = (device_mapping_l2_phys as u64) | (PageAttributes::WRITABLE | PageAttributes::PRESENT).bits(); diff --git a/kernel/libk/libk-mm/Cargo.toml b/kernel/libk/libk-mm/Cargo.toml index db45185d..f390b0ba 100644 --- a/kernel/libk/libk-mm/Cargo.toml +++ b/kernel/libk/libk-mm/Cargo.toml @@ -12,5 +12,6 @@ libk-util = { path = "../libk-util" } libk-mm-interface = { path = "interface" } vmalloc = { path = "../../lib/vmalloc" } -linked_list_allocator = "0.10.5" +libyalloc = { path = "../../../lib/libyalloc", default-features = false, features = ["dep-of-kernel"] } + log = "0.4.20" diff --git a/kernel/libk/libk-mm/src/heap.rs b/kernel/libk/libk-mm/src/heap.rs index bbe0a33c..64f38c85 100644 --- a/kernel/libk/libk-mm/src/heap.rs +++ b/kernel/libk/libk-mm/src/heap.rs @@ -1,41 +1,58 @@ //! Kernel's global heap allocator use core::{ alloc::{GlobalAlloc, Layout}, - ops::Range, ptr::{null_mut, NonNull}, }; +use kernel_arch::KernelTableManagerImpl; +use libk_mm_interface::address::PhysicalAddress; use libk_util::sync::IrqSafeSpinlock; -use linked_list_allocator::Heap; +use libyalloc::{allocator::BucketAllocator, sys::PageProvider}; + +use crate::{address::Virtualize, phys, L3_PAGE_SIZE}; + +// TODO limits? + +struct KernelPageProvider; + +impl PageProvider for KernelPageProvider { + fn unmap_pages(address: NonNull, count: usize) { + log::trace!("Release {}K of heap", count * 4); + let phys = PhysicalAddress::from_virtualized(address.as_ptr().addr()); + for i in 0..count { + unsafe { + phys::free_page(phys.add(i * L3_PAGE_SIZE)); + } + } + } + + fn map_pages(count: usize) -> Option> { + log::trace!("Grow heap by {}K", count * 4); + let phys = phys::alloc_pages_contiguous(count).ok()?; + let virt = phys.raw_virtualize::(); + Some(unsafe { NonNull::new_unchecked(virt as *mut u8) }) + } +} /// Kernel heap manager pub struct KernelAllocator { - inner: IrqSafeSpinlock, + inner: IrqSafeSpinlock>, } impl KernelAllocator { const fn empty() -> Self { Self { - inner: IrqSafeSpinlock::new(Heap::empty()), + inner: IrqSafeSpinlock::new(BucketAllocator::new()), } } - - unsafe fn init(&self, base: usize, size: usize) { - self.inner.lock().init(base as _, size); - } - - fn range(&self) -> Range { - let lock = self.inner.lock(); - lock.bottom() as usize..lock.top() as usize - } } unsafe impl GlobalAlloc for KernelAllocator { unsafe fn alloc(&self, layout: Layout) -> *mut u8 { - match self.inner.lock().allocate_first_fit(layout) { - Ok(v) => v.as_ptr(), - Err(e) => { - log::error!("Failed to allocate {:?}: {:?}", layout, e); + match self.inner.lock().allocate(layout) { + Some(p) => p.as_ptr(), + None => { + log::error!("Failed to allocate {:?}", layout); null_mut() } } @@ -43,24 +60,10 @@ unsafe impl GlobalAlloc for KernelAllocator { unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { let ptr = NonNull::new(ptr).unwrap(); - self.inner.lock().deallocate(ptr, layout) + self.inner.lock().free(ptr, layout); } } /// Kernel's global allocator #[global_allocator] pub static GLOBAL_HEAP: KernelAllocator = KernelAllocator::empty(); - -/// Sets up kernel's global heap with given memory range. -/// -/// # Safety -/// -/// The caller must ensure the range is valid and mapped virtual memory. -pub unsafe fn init_heap(heap_base: usize, heap_size: usize) { - GLOBAL_HEAP.init(heap_base, heap_size); -} - -/// Returns the heap address range -pub fn heap_range() -> Range { - GLOBAL_HEAP.range() -} diff --git a/kernel/modules/test_mod/Cargo.lock b/kernel/modules/test_mod/Cargo.lock index 8c234695..365772e7 100644 --- a/kernel/modules/test_mod/Cargo.lock +++ b/kernel/modules/test_mod/Cargo.lock @@ -48,12 +48,6 @@ dependencies = [ "syn 1.0.109", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bitflags" version = "2.5.0" @@ -90,6 +84,12 @@ dependencies = [ "syn 2.0.53", ] +[[package]] +name = "cc" +version = "1.0.99" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c51067fd44124faa7f870b4b1c969379ad32b2ba805aa959430ceaa384f695" + [[package]] name = "cfg-if" version = "1.0.0" @@ -255,6 +255,12 @@ dependencies = [ "yggdrasil-abi", ] +[[package]] +name = "libc" +version = "0.2.155" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" + [[package]] name = "libk" version = "0.1.0" @@ -294,7 +300,7 @@ dependencies = [ "kernel-arch", "libk-mm-interface", "libk-util", - "linked_list_allocator", + "libyalloc", "log", "vmalloc", "yggdrasil-abi", @@ -323,22 +329,11 @@ dependencies = [ ] [[package]] -name = "linked_list_allocator" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9afa463f5405ee81cdb9cc2baf37e08ec7e4c8209442b5d72c04cfb2cd6e6286" +name = "libyalloc" +version = "0.1.0" dependencies = [ - "spinning_top", -] - -[[package]] -name = "lock_api" -version = "0.4.11" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" -dependencies = [ - "autocfg", - "scopeguard", + "libc", + "yggdrasil-rt", ] [[package]] @@ -416,12 +411,6 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" -[[package]] -name = "scopeguard" -version = "1.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" - [[package]] name = "serde" version = "1.0.197" @@ -453,15 +442,6 @@ dependencies = [ "serde", ] -[[package]] -name = "spinning_top" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9eb1a2f4c41445a3a0ff9abc5221c5fcd28e1f13cd7c0397706f9ac938ddb0" -dependencies = [ - "lock_api", -] - [[package]] name = "static_assertions" version = "1.1.0" @@ -554,6 +534,17 @@ dependencies = [ "serde", ] +[[package]] +name = "yggdrasil-rt" +version = "0.1.0" +dependencies = [ + "abi-generator", + "abi-lib", + "cc", + "prettyplease", + "yggdrasil-abi", +] + [[package]] name = "zerocopy" version = "0.7.32" diff --git a/kernel/src/arch/aarch64/mod.rs b/kernel/src/arch/aarch64/mod.rs index 850fc384..3e41bfe7 100644 --- a/kernel/src/arch/aarch64/mod.rs +++ b/kernel/src/arch/aarch64/mod.rs @@ -12,19 +12,18 @@ use device_tree::dt::{DevTreeIndexPropExt, DevTreeNodeInfo, DeviceTree, FdtMemor use git_version::git_version; use kernel_arch_aarch64::{ mem::{ - table::{L1, L2, L3}, - EarlyMapping, HEAP_MAPPING_OFFSET, MEMORY_LIMIT, RAM_MAPPING_L1_COUNT, + table::{L1, L3}, + EarlyMapping, MEMORY_LIMIT, RAM_MAPPING_L1_COUNT, }, ArchitectureImpl, PerCpuData, }; use libk::{arch::Cpu, device::external_interrupt_controller}; use libk_mm::{ address::{FromRaw, IntoRaw, PhysicalAddress}, - heap, phys::PhysicalMemoryRegion, phys::{self, reserved::reserve_region}, pointer::PhysicalRef, - table::{EntryLevel, EntryLevelExt}, + table::EntryLevelExt, }; use libk_util::OneTimeInit; use tock_registers::interfaces::Writeable; @@ -151,9 +150,6 @@ impl AArch64 { } unsafe fn init_memory_management(&'static self, dtb: PhysicalAddress) -> Result<(), Error> { - // 16x2MiB - const HEAP_PAGES: usize = 16; - // Initialize the runtime mappings kernel_arch_aarch64::mem::init_fixed_tables(); @@ -197,14 +193,6 @@ impl AArch64 { phys::init_from_iter(regions, Self::map_physical_memory)?; - // Setup the heap - for i in 0..HEAP_PAGES { - let l2_page = phys::alloc_2m_page()?; - kernel_arch_aarch64::mem::map_heap_l2(i, l2_page); - } - - heap::init_heap(HEAP_MAPPING_OFFSET, HEAP_PAGES * L2::SIZE); - // EarlyMapping for DTB no longer needed, it lives in physical memory and can be obtained // through PhysicalRef let dtb_slice: PhysicalRef<'static, [u8]> = PhysicalRef::map_slice(dtb, dtb_size); diff --git a/kernel/src/arch/x86_64/mod.rs b/kernel/src/arch/x86_64/mod.rs index 8ddf4c1d..b5567ab7 100644 --- a/kernel/src/arch/x86_64/mod.rs +++ b/kernel/src/arch/x86_64/mod.rs @@ -8,9 +8,9 @@ use device_api::{interrupt::Irq, Device}; use git_version::git_version; use kernel_arch_x86_64::{ mem::{ - init_fixed_tables, map_heap_block, + init_fixed_tables, table::{PageAttributes, PageEntry, PageTable, L1, L2, L3}, - EarlyMapping, HEAP_MAPPING_OFFSET, MEMORY_LIMIT, RAM_MAPPING_L1, + EarlyMapping, MEMORY_LIMIT, RAM_MAPPING_L1, }, PerCpuData, }; @@ -19,7 +19,6 @@ use libk::{arch::Cpu, device::register_external_interrupt_controller}; use libk_device::register_monotonic_timestamp_provider; use libk_mm::{ address::{FromRaw, IntoRaw, PhysicalAddress, Virtualize}, - heap, phys::{self, reserved::reserve_region, PhysicalMemoryRegion}, table::{EntryLevel, EntryLevelExt}, }; @@ -241,8 +240,6 @@ impl X86_64 { } unsafe fn init_memory_management(&self) -> Result<(), Error> { - const HEAP_PAGES: usize = 16; - init_fixed_tables(); // Reserve lower 4MiB just in case @@ -258,16 +255,6 @@ impl X86_64 { &BootData::YBoot(data) => Self::init_physical_memory_from_yboot(data)?, } - // Setup heap - for i in 0..HEAP_PAGES { - // Allocate in 2MiB chunks - let l2_page = phys::alloc_2m_page()?; - - map_heap_block(i, l2_page); - } - - heap::init_heap(HEAP_MAPPING_OFFSET, HEAP_PAGES * L2::SIZE); - Ok(()) } diff --git a/kernel/src/main.rs b/kernel/src/main.rs index 43afee57..70f649e2 100644 --- a/kernel/src/main.rs +++ b/kernel/src/main.rs @@ -41,7 +41,6 @@ use arch::Platform; use kernel_arch::{Architecture, ArchitectureImpl}; use libk::arch::Cpu; -use libk_mm::heap; use libk_util::sync::SpinFence; use crate::{arch::PLATFORM, fs::sysfs, task::spawn_kernel_closure}; @@ -93,8 +92,6 @@ pub fn kernel_secondary_main() -> ! { pub fn kernel_main() -> ! { libk::panic::set_handler(panic::panic_handler); - debugln!("Heap: {:#x?}", heap::heap_range()); - // Setup the sysfs sysfs::init(); fs::add_pseudo_devices().unwrap(); diff --git a/kernel/src/mem/heap.rs b/kernel/src/mem/heap.rs deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/libyalloc/Cargo.toml b/lib/libyalloc/Cargo.toml index e92bb0dc..0b22088a 100644 --- a/lib/libyalloc/Cargo.toml +++ b/lib/libyalloc/Cargo.toml @@ -17,7 +17,9 @@ libc = { version = "0.2.140", default-features = false } yggdrasil-rt = { path = "../runtime", default-features = false } [features] -default = [] +default = ["global"] +global = [] +dep-of-kernel = [] rustc-dep-of-std = [ "core", "compiler_builtins", diff --git a/lib/libyalloc/src/allocator.rs b/lib/libyalloc/src/allocator.rs index ff2878a5..562c272b 100644 --- a/lib/libyalloc/src/allocator.rs +++ b/lib/libyalloc/src/allocator.rs @@ -2,33 +2,34 @@ use core::{alloc::Layout, ops::Index, ptr::NonNull}; use crate::{ bucket::Bucket, - util::{self, Assert, IsTrue}, + sys::{self, PageProvider}, + util::{Assert, IsTrue}, }; -struct BucketList +struct BucketList where [u64; M / 64]: Sized, Assert<{ M % 64 == 0 }>: IsTrue, { - head: Option>>, + head: Option>>, } -pub struct BucketAllocator { +pub struct BucketAllocator { // 1024x64 = 16 pages - buckets_1024: BucketList<1024, 64>, + buckets_1024: BucketList, // 512x64 = 8 pages - buckets_512: BucketList<512, 64>, + buckets_512: BucketList, // 256x128 = 8 pages - buckets_256: BucketList<256, 128>, + buckets_256: BucketList, // 128x128 = 4 pages - buckets_128: BucketList<128, 128>, + buckets_128: BucketList, // 64x128 = 2 pages - buckets_64: BucketList<128, 128>, + buckets_64: BucketList, // 32x256 = 2 pages - buckets_32: BucketList<128, 128>, + buckets_32: BucketList, } -impl BucketList +impl BucketList where [u64; M / 64]: Sized, Assert<{ M % 64 == 0 }>: IsTrue, @@ -75,12 +76,12 @@ where } } -impl Index for BucketList +impl Index for BucketList where [u64; M / 64]: Sized, Assert<{ M % 64 == 0 }>: IsTrue, { - type Output = Bucket; + type Output = Bucket; fn index(&self, index: usize) -> &Self::Output { let mut current = 0; @@ -100,7 +101,7 @@ where } } -impl BucketAllocator { +impl BucketAllocator

{ pub const fn new() -> Self { Self { buckets_1024: BucketList::new(), @@ -116,14 +117,13 @@ impl BucketAllocator { let aligned = layout.pad_to_align(); match aligned.size() { - 0 => todo!(), ..=32 => self.buckets_32.allocate(), ..=64 => self.buckets_64.allocate(), ..=128 => self.buckets_128.allocate(), ..=256 => self.buckets_256.allocate(), ..=512 => self.buckets_512.allocate(), ..=1024 => self.buckets_1024.allocate(), - size => util::map_pages((size + util::PAGE_SIZE - 1) / util::PAGE_SIZE), + size => P::map_pages((size + sys::PAGE_SIZE - 1) / sys::PAGE_SIZE), } } @@ -131,7 +131,6 @@ impl BucketAllocator { let aligned = layout.pad_to_align(); match aligned.size() { - 0 => todo!(), ..=32 => self.buckets_32.free(ptr), ..=64 => self.buckets_64.free(ptr), ..=128 => self.buckets_128.free(ptr), @@ -139,8 +138,8 @@ impl BucketAllocator { ..=512 => self.buckets_512.free(ptr), ..=1024 => self.buckets_1024.free(ptr), size => { - assert_eq!(usize::from(ptr.addr()) % util::PAGE_SIZE, 0); - util::unmap_pages(ptr, (size + util::PAGE_SIZE - 1) / util::PAGE_SIZE); + assert_eq!(usize::from(ptr.addr()) % sys::PAGE_SIZE, 0); + P::unmap_pages(ptr, (size + sys::PAGE_SIZE - 1) / sys::PAGE_SIZE); } } } @@ -151,10 +150,11 @@ mod tests { use core::{alloc::Layout, ptr::NonNull}; use super::{BucketAllocator, BucketList}; + use crate::sys::OsPageProvider; #[test] fn single_list_allocation() { - let mut list = BucketList::<32, 64>::new(); + let mut list = BucketList::::new(); let mut vec = vec![]; for _ in 0..4 * 64 + 3 { @@ -173,7 +173,7 @@ mod tests { fn multi_list_allocation() { const SIZES: &[usize] = &[1, 3, 7, 15, 16, 24, 33, 65, 126, 255, 500, 1000]; - let mut allocator = BucketAllocator::new(); + let mut allocator = BucketAllocator::::new(); let mut vec = vec![]; for _ in 0..65 { @@ -199,7 +199,7 @@ mod tests { #[test] #[should_panic] fn double_free() { - let mut allocator = BucketAllocator::new(); + let mut allocator = BucketAllocator::::new(); let layout = Layout::from_size_align(63, 32).unwrap(); let ptr = allocator.allocate(layout).unwrap(); @@ -213,7 +213,7 @@ mod tests { fn large_alloc() { const SIZES: &[usize] = &[2000, 2048, 4000, 4096, 8192]; - let mut allocator = BucketAllocator::new(); + let mut allocator = BucketAllocator::::new(); let mut vec = vec![]; for &size in SIZES { diff --git a/lib/libyalloc/src/bucket.rs b/lib/libyalloc/src/bucket.rs index 3b0bc1a1..76de22a2 100644 --- a/lib/libyalloc/src/bucket.rs +++ b/lib/libyalloc/src/bucket.rs @@ -3,9 +3,12 @@ use core::{ ptr::NonNull, }; -use crate::util::{self, Assert, IsTrue, NonNullExt}; +use crate::{ + sys::PageProvider, + util::{Assert, IsTrue, NonNullExt}, +}; -pub struct Bucket +pub struct Bucket where [u64; M / 64]: Sized, Assert<{ M % 64 == 0 }>: IsTrue, @@ -13,10 +16,10 @@ where pub(crate) data: NonNull, bitmap: [u64; M / 64], allocated_count: usize, - pub(crate) next: Option>>, + pub(crate) next: Option>>, } -impl Bucket +impl Bucket where [u64; M / 64]: Sized, Assert<{ M % 64 == 0 }>: IsTrue, @@ -25,8 +28,8 @@ where let data_page_count = (M * N + 0xFFF) / 0x1000; let info_page_count = (size_of::() + 0xFFF) / 0x1000; - let data = util::map_pages(data_page_count)?; - let info = util::map_pages(info_page_count)?; + let data = P::map_pages(data_page_count)?; + let info = P::map_pages(info_page_count)?; let bucket = unsafe { info.cast::>().as_mut() }; let bucket = bucket.write(Self { @@ -85,11 +88,27 @@ where mod tests { use core::ptr::NonNull; - use crate::{bucket::Bucket, util::NonNullExt}; + use crate::{ + bucket::Bucket, + sys::{self, PageProvider}, + util::NonNullExt, + }; + + pub struct DummyPageProvider; + + impl PageProvider for DummyPageProvider { + fn map_pages(count: usize) -> Option> { + let v = vec![0u8; count * sys::PAGE_SIZE]; + let p = NonNull::from(&mut v.leak()[0]); + Some(p) + } + + fn unmap_pages(_address: NonNull, _count: usize) {} + } #[test] fn bucket_creation() { - let mut bucket = Bucket::<32, 64>::new().unwrap(); + let mut bucket = Bucket::::new().unwrap(); let bucket = unsafe { bucket.as_mut() }; assert_eq!(bucket.allocated_count, 0); assert_eq!(bucket.next, None); @@ -97,7 +116,7 @@ mod tests { #[test] fn bucket_allocation() { - let mut bucket = Bucket::<32, 64>::new().unwrap(); + let mut bucket = Bucket::::new().unwrap(); let bucket = unsafe { bucket.as_mut() }; let mut vec = vec![]; @@ -132,8 +151,8 @@ mod tests { #[test] fn free_outside_of_bucket() { - let mut bucket0 = Bucket::<32, 64>::new().unwrap(); - let mut bucket1 = Bucket::<64, 64>::new().unwrap(); + let mut bucket0 = Bucket::::new().unwrap(); + let mut bucket1 = Bucket::::new().unwrap(); let bucket0 = unsafe { bucket0.as_mut() }; let bucket1 = unsafe { bucket1.as_mut() }; @@ -150,7 +169,7 @@ mod tests { #[test] #[should_panic] fn double_free() { - let mut bucket0 = Bucket::<32, 64>::new().unwrap(); + let mut bucket0 = Bucket::::new().unwrap(); let bucket0 = unsafe { bucket0.as_mut() }; let ptr = bucket0.allocate().unwrap(); diff --git a/lib/libyalloc/src/global.rs b/lib/libyalloc/src/global.rs index f5bb6bdb..6d71f245 100644 --- a/lib/libyalloc/src/global.rs +++ b/lib/libyalloc/src/global.rs @@ -3,7 +3,7 @@ use core::{ ptr::{null_mut, NonNull}, }; -use crate::{allocator::BucketAllocator, util::Spinlock}; +use crate::{allocator::BucketAllocator, sys::OsPageProvider, util::Spinlock}; pub struct GlobalAllocator; @@ -37,4 +37,5 @@ unsafe impl Allocator for GlobalAllocator { } } -static GLOBAL_ALLOCATOR: Spinlock = Spinlock::new(BucketAllocator::new()); +static GLOBAL_ALLOCATOR: Spinlock> = + Spinlock::new(BucketAllocator::new()); diff --git a/lib/libyalloc/src/lib.rs b/lib/libyalloc/src/lib.rs index 7eb56561..7d3a968c 100644 --- a/lib/libyalloc/src/lib.rs +++ b/lib/libyalloc/src/lib.rs @@ -8,7 +8,7 @@ allocator_api )] #![cfg_attr(not(test), no_std)] -#![allow(incomplete_features)] +#![allow(incomplete_features, unexpected_cfgs)] #![deny(fuzzy_provenance_casts, lossy_provenance_casts)] #[cfg(test)] @@ -16,5 +16,8 @@ extern crate test; pub mod allocator; mod bucket; -pub mod global; +pub mod sys; mod util; + +#[cfg(any(feature = "global", rust_analyzer))] +pub mod global; diff --git a/lib/libyalloc/src/sys.rs b/lib/libyalloc/src/sys.rs new file mode 100644 index 00000000..33a041e0 --- /dev/null +++ b/lib/libyalloc/src/sys.rs @@ -0,0 +1,57 @@ +use core::ptr::NonNull; + +pub const PAGE_SIZE: usize = 0x1000; + +pub trait PageProvider { + fn map_pages(count: usize) -> Option>; + fn unmap_pages(address: NonNull, count: usize); +} + +#[cfg(not(feature = "dep-of-kernel"))] +pub struct OsPageProvider; + +#[cfg(any(all(unix, not(feature = "dep-of-kernel")), rust_analyzer))] +impl PageProvider for OsPageProvider { + fn map_pages(count: usize) -> Option> { + use core::ptr::null_mut; + + let address = unsafe { + libc::mmap( + null_mut(), + count * PAGE_SIZE, + libc::PROT_READ | libc::PROT_WRITE, + libc::MAP_ANONYMOUS | libc::MAP_PRIVATE, + -1, + 0, + ) + }; + + NonNull::new(address as *mut u8) + } + + fn unmap_pages(address: NonNull, count: usize) { + unsafe { + libc::munmap(address.as_ptr() as _, count * PAGE_SIZE); + } + } +} + +#[cfg(any(all(not(unix), not(feature = "dep-of-kernel")), rust_analyzer))] +impl PageProvider for OsPageProvider { + fn map_pages(count: usize) -> Option> { + use yggdrasil_rt::mem::MappingSource; + + let address = unsafe { + yggdrasil_rt::sys::map_memory(None, count * PAGE_SIZE, &MappingSource::Anonymous) + } + .ok()?; + + NonNull::new(core::ptr::from_exposed_addr_mut(address)) + } + + fn unmap_pages(address: NonNull, count: usize) { + unsafe { + yggdrasil_rt::sys::unmap_memory(address.addr().into(), count * PAGE_SIZE).unwrap(); + } + } +} diff --git a/lib/libyalloc/src/util.rs b/lib/libyalloc/src/util.rs index 3e97c1b3..19fcadb5 100644 --- a/lib/libyalloc/src/util.rs +++ b/lib/libyalloc/src/util.rs @@ -1,12 +1,12 @@ +use core::ptr::NonNull; + +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] use core::{ cell::UnsafeCell, ops::{Deref, DerefMut}, - ptr::NonNull, sync::atomic::{AtomicBool, Ordering}, }; -pub const PAGE_SIZE: usize = 0x1000; - pub enum Assert {} pub trait IsTrue {} impl IsTrue for Assert {} @@ -21,60 +21,18 @@ impl NonNullExt for NonNull { } } +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] pub struct Spinlock { state: AtomicBool, data: UnsafeCell, } +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] pub struct SpinlockGuard<'a, T: ?Sized> { lock: &'a Spinlock, } -pub fn map_pages(count: usize) -> Option> { - #[cfg(unix)] - { - use core::ptr::null_mut; - - let address = unsafe { - libc::mmap( - null_mut(), - count * PAGE_SIZE, - libc::PROT_READ | libc::PROT_WRITE, - libc::MAP_ANONYMOUS | libc::MAP_PRIVATE, - -1, - 0, - ) - }; - - NonNull::new(address as *mut u8) - } - - #[cfg(not(unix))] - { - use yggdrasil_rt::mem::MappingSource; - - let address = unsafe { - yggdrasil_rt::sys::map_memory(None, count * PAGE_SIZE, &MappingSource::Anonymous) - } - .ok()?; - - NonNull::new(core::ptr::from_exposed_addr_mut(address)) - } -} - -pub fn unmap_pages(address: NonNull, count: usize) { - #[cfg(unix)] - unsafe { - libc::munmap(address.as_ptr() as _, count * PAGE_SIZE); - } - #[cfg(not(unix))] - { - unsafe { - yggdrasil_rt::sys::unmap_memory(address.addr().into(), count * PAGE_SIZE).unwrap(); - } - } -} - +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] impl Spinlock { pub const fn new(value: T) -> Self where @@ -100,6 +58,7 @@ impl Spinlock { } } +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] impl<'a, T: ?Sized> Deref for SpinlockGuard<'a, T> { type Target = T; @@ -108,16 +67,19 @@ impl<'a, T: ?Sized> Deref for SpinlockGuard<'a, T> { } } +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] impl<'a, T: ?Sized> DerefMut for SpinlockGuard<'a, T> { fn deref_mut(&mut self) -> &mut Self::Target { unsafe { &mut *self.lock.data.get() } } } +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] impl<'a, T: ?Sized> Drop for SpinlockGuard<'a, T> { fn drop(&mut self) { self.lock.state.store(false, Ordering::Release); } } +#[cfg(any(not(feature = "dep-of-kernel"), rust_analyzer))] unsafe impl Sync for Spinlock {} diff --git a/xtask/src/build/x86_64.rs b/xtask/src/build/x86_64.rs index 45cc7b0d..bee0ad35 100644 --- a/xtask/src/build/x86_64.rs +++ b/xtask/src/build/x86_64.rs @@ -57,7 +57,7 @@ fn build_uefi_image( "if=/dev/zero", &format!("of={}", image_path.display()), "bs=1M", - "count=256", + "count=512", ], false, )?;