diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 9a7c837..4938bad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,7 +18,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - toolchain: 1.84.1 + toolchain: 1.92.0 - uses: Swatinem/rust-cache@v2 - name: Lint (clippy) run: cargo clippy --all-features --all-targets @@ -35,7 +35,7 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: components: rustfmt, clippy - toolchain: 1.84.1 + toolchain: 1.92.0 - uses: Swatinem/rust-cache@v2 - name: Build rustdoc run: cargo doc --all-features --workspace @@ -53,7 +53,7 @@ jobs: - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@stable with: - toolchain: 1.84.1 + toolchain: 1.92.0 - uses: Swatinem/rust-cache@v2 - name: Build run: cargo build diff --git a/Cargo.lock b/Cargo.lock index 2d1d9c5..8409848 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,9 +4,9 @@ version = 4 [[package]] name = "anstream" -version = "0.6.14" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" +checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d" dependencies = [ "anstyle", "anstyle-parse", @@ -19,44 +19,39 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.7" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" +checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000" [[package]] name = "anstyle-parse" -version = "0.2.4" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" +checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.1.0" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad186efb764318d35165f1758e7dcef3b10628e26d41a44bc5550652e6804391" +checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc" dependencies = [ "windows-sys", ] [[package]] name = "anstyle-wincon" -version = "3.0.3" +version = "3.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" +checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d" dependencies = [ "anstyle", + "once_cell_polyfill", "windows-sys", ] -[[package]] -name = "autocfg" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" - [[package]] name = "bitflags" version = "1.3.2" @@ -65,15 +60,15 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] name = "bitflags" -version = "2.5.0" +version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" [[package]] name = "clap" -version = "4.5.7" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5db83dced34638ad474f39f250d7fea9598bdd239eaced1bdf45d597da0f433f" +checksum = "aa8876b300ab35ba921adea3dfd70157a46249b33f95c9084ae5709785478946" dependencies = [ "clap_builder", "clap_derive", @@ -81,9 +76,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.7" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f7e204572485eb3fbf28f871612191521df159bc3e15a9f5064c66dba3a8c05f" +checksum = "ec0797fb7aeb1406c84efac526901f7ec3ead2124f946b494e72879d4b54704d" dependencies = [ "anstream", "anstyle", @@ -93,33 +88,33 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.5" +version = "4.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c780290ccf4fb26629baa7a1081e68ced113f1d3ec302fa5948f1c381ebf06c6" +checksum = "f9c751b79415d4e559e3d1fcf128e09e720eb673a06d26cf6f392d37d75b66e0" dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.66", + "syn 3.0.9", ] [[package]] name = "clap_lex" -version = "0.7.1" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b82cf0babdbd58558212896d1a4272303a57bdb245c2bf1147185fb45640e70" +checksum = "1c133bc6a41be0d194c306b5506d15e6feeea7b1d6604bd3f8310dfb2ca96486" [[package]] name = "colorchoice" -version = "1.0.1" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" +checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570" [[package]] name = "core_affinity" -version = "0.8.1" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622892f5635ce1fc38c8f16dfc938553ed64af482edb5e150bf4caedbfcb2304" +checksum = "a034b3a7b624016c6e13f5df875747cc25f884156aad2abd12b6c46797971342" dependencies = [ "libc", "num_cpus", @@ -128,7 +123,7 @@ dependencies = [ [[package]] name = "cpuinfo" -version = "0.2.0" +version = "1.0.0" dependencies = [ "clap", "core_affinity", @@ -137,27 +132,20 @@ dependencies = [ "kvm-ioctls", "serde", "serde_json", - "serde_yaml", ] [[package]] name = "enum_dispatch" -version = "0.3.8" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0eb359f1476bf611266ac1f5355bc14aeca37b299d0ebccc038ee7058891c9cb" +checksum = "aa18ce2bc66555b3218614519ac839ddb759a7d6720732f979ef8d13be147ecd" dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 1.0.98", + "syn 2.0.119", ] -[[package]] -name = "hashbrown" -version = "0.11.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" - [[package]] name = "heck" version = "0.5.0" @@ -166,48 +154,38 @@ checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" [[package]] name = "hermit-abi" -version = "0.3.9" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" - -[[package]] -name = "indexmap" -version = "1.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6012d540c5baa3589337a98ce73408de9b5a25ec9fc2c6fd6be8f0d39e0ca5a" -dependencies = [ - "autocfg", - "hashbrown", -] +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" [[package]] name = "is_terminal_polyfill" -version = "1.70.0" +version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" +checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" [[package]] name = "itoa" -version = "1.0.11" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" [[package]] name = "kvm-bindings" -version = "0.11.1" +version = "0.14.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b13baf7bdfda2e10bcb109fcb099ef40cff82374eb6b7cdcf4695bdec4e522c" +checksum = "e3819cba3d5b448587dbed4b186fb61b0a8d02c5eb88846c9463aa514afe61a8" dependencies = [ "vmm-sys-util", ] [[package]] name = "kvm-ioctls" -version = "0.21.0" +version = "0.25.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "083c460d5a272c2f22205973e319147b791d92a288d7d7a8d4c6194f95229440" +checksum = "d7a59b7ac62625a405112180b56a99acb4498e1d18f5a7c0cd0916c79a076b0a" dependencies = [ - "bitflags 2.5.0", + "bitflags 2.13.2", "kvm-bindings", "libc", "vmm-sys-util", @@ -215,21 +193,21 @@ dependencies = [ [[package]] name = "libc" -version = "0.2.126" +version = "0.2.190" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "349d5a591cd28b49e1d1037471617a32ddcda5731b99419008085f72d5a53836" +checksum = "ce5d3ddc6d3fa000eb1536d85e147bfe31aacaba692ed6a876f95cb7c855be78" [[package]] -name = "linked-hash-map" -version = "0.5.6" +name = "memchr" +version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" [[package]] name = "num_cpus" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" +checksum = "91df4bbde75afed763b708b7eee1e8e7651e02d97f6d5dd763e89367e957b23b" dependencies = [ "hermit-abi", "libc", @@ -237,75 +215,75 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.13.0" +version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "once_cell_polyfill" +version = "1.70.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" [[package]] name = "proc-macro2" -version = "1.0.85" +version = "1.0.107" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22244ce15aa966053a896d1accb3a6e68469b97c7f33f284b99f0d576879fc23" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.36" +version = "1.0.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" dependencies = [ "proc-macro2", ] [[package]] -name = "ryu" -version = "1.0.10" +name = "serde" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3f6f92acf49d1b98f7a81226834412ada05458b7364277387724a237f062695" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] [[package]] -name = "serde" -version = "1.0.203" +name = "serde_core" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.203" +version = "1.0.229" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" dependencies = [ "proc-macro2", "quote", - "syn 2.0.66", + "syn 3.0.9", ] [[package]] name = "serde_json" -version = "1.0.117" +version = "1.0.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" dependencies = [ "itoa", - "ryu", - "serde", -] - -[[package]] -name = "serde_yaml" -version = "0.8.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "707d15895415db6628332b737c838b88c598522e4dc70647e59b72312924aebc" -dependencies = [ - "indexmap", - "ryu", + "memchr", "serde", - "yaml-rust", + "serde_core", + "zmij", ] [[package]] @@ -316,9 +294,9 @@ checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" [[package]] name = "syn" -version = "1.0.98" +version = "2.0.119" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c50aef8a904de4c23c788f104b7dddc7d6f79c647c7c8ce4cc8f73eb0ca773dd" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" dependencies = [ "proc-macro2", "quote", @@ -327,9 +305,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.66" +version = "3.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" +checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b" dependencies = [ "proc-macro2", "quote", @@ -338,9 +316,9 @@ dependencies = [ [[package]] name = "unicode-ident" -version = "1.0.1" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" [[package]] name = "utf8parse" @@ -350,9 +328,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "vmm-sys-util" -version = "0.12.1" +version = "0.15.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d1435039746e20da4f8d507a72ee1b916f7b4b05af7a91c093d2c6561934ede" +checksum = "506c62fdf617a5176827c2f9afbcf1be155b03a9b4bf9617a60dbc07e3a1642f" dependencies = [ "bitflags 1.3.2", "libc", @@ -381,83 +359,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" [[package]] -name = "windows-sys" -version = "0.52.0" +name = "windows-link" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" -dependencies = [ - "windows-targets", -] +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" [[package]] -name = "windows-targets" -version = "0.52.5" +name = "windows-sys" +version = "0.61.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" 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-link", ] [[package]] -name = "windows_aarch64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" - -[[package]] -name = "windows_aarch64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" - -[[package]] -name = "windows_i686_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -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.5" +name = "zmij" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" - -[[package]] -name = "windows_x86_64_gnu" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" - -[[package]] -name = "windows_x86_64_gnullvm" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" - -[[package]] -name = "windows_x86_64_msvc" -version = "0.52.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" - -[[package]] -name = "yaml-rust" -version = "0.4.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "56c1936c4cc7a1c9ab21a1ebb602eb942ba868cbd44a99cb7cdc5892335e1c85" -dependencies = [ - "linked-hash-map", -] +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" diff --git a/Cargo.toml b/Cargo.toml index fe4d49f..2b58b48 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,23 +1,22 @@ [package] name = "cpuinfo" description = "A utility to identify a cpu and features present. It uses the 'CPUID' instruction and on platforms that support it, feature MSRs." -version = "0.2.2" +version = "1.0.0" authors = ["Joshua Job "] -edition = "2018" +edition = "2024" license = "MIT" repository = "https://github.com/ScaleComputing/cpuinfo.git" [dependencies] clap = { version = "4.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] } -serde_yaml = "0.8" enum_dispatch = "0.3.8" serde_json = "1.0.117" core_affinity = "^0.8.1" [target.'cfg(target_os = "linux")'.dependencies] -kvm-ioctls = { version = "0.21", optional = true } -kvm-bindings = { version = "0.11", features = ["fam-wrappers"], optional = true } +kvm-ioctls = { version = "0.25", optional = true } +kvm-bindings = { version = "0.14", features = ["fam-wrappers"], optional = true } [features] default = ["use_msr", "kvm"] diff --git a/deny.toml b/deny.toml new file mode 100644 index 0000000..3f741b8 --- /dev/null +++ b/deny.toml @@ -0,0 +1,241 @@ +# This template contains all of the possible sections and their default values + +# Note that all fields that take a lint level have these possible values: +# * deny - An error will be produced and the check will fail +# * warn - A warning will be produced, but the check will not fail +# * allow - No warning or error will be produced, though in some cases a note +# will be + +# The values provided in this template are the default values that will be used +# when any section or field is not specified in your own configuration + +# Root options + +# The graph table configures how the dependency graph is constructed and thus +# which crates the checks are performed against +[graph] +# If 1 or more target triples (and optionally, target_features) are specified, +# only the specified targets will be checked when running `cargo deny check`. +# This means, if a particular package is only ever used as a target specific +# dependency, such as, for example, the `nix` crate only being used via the +# `target_family = "unix"` configuration, that only having windows targets in +# this list would mean the nix crate, as well as any of its exclusive +# dependencies not shared by any other crates, would be ignored, as the target +# list here is effectively saying which targets you are building for. +targets = [ + # The triple can be any string, but only the target triples built in to + # rustc (as of 1.40) can be checked against actual config expressions + #"x86_64-unknown-linux-musl", + # You can also specify which target_features you promise are enabled for a + # particular target. target_features are currently not validated against + # the actual valid features supported by the target architecture. + #{ triple = "wasm32-unknown-unknown", features = ["atomics"] }, +] +# When creating the dependency graph used as the source of truth when checks are +# executed, this field can be used to prune crates from the graph, removing them +# from the view of cargo-deny. This is an extremely heavy hammer, as if a crate +# is pruned from the graph, all of its dependencies will also be pruned unless +# they are connected to another crate in the graph that hasn't been pruned, +# so it should be used with care. The identifiers are [Package ID Specifications] +# (https://doc.rust-lang.org/cargo/reference/pkgid-spec.html) +#exclude = [] +# If true, metadata will be collected with `--all-features`. Note that this can't +# be toggled off if true, if you want to conditionally enable `--all-features` it +# is recommended to pass `--all-features` on the cmd line instead +all-features = false +# If true, metadata will be collected with `--no-default-features`. The same +# caveat with `all-features` applies +no-default-features = false +# If set, these feature will be enabled when collecting metadata. If `--features` +# is specified on the cmd line they will take precedence over this option. +#features = [] + +# The output table provides options for how/if diagnostics are outputted +[output] +# When outputting inclusion graphs in diagnostics that include features, this +# option can be used to specify the depth at which feature edges will be added. +# This option is included since the graphs can be quite large and the addition +# of features from the crate(s) to all of the graph roots can be far too verbose. +# This option can be overridden via `--feature-depth` on the cmd line +feature-depth = 1 + +# This section is considered when running `cargo deny check advisories` +# More documentation for the advisories section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/advisories/cfg.html +[advisories] +# The path where the advisory databases are cloned/fetched into +#db-path = "$CARGO_HOME/advisory-dbs" +# The url(s) of the advisory databases to use +#db-urls = ["https://github.com/rustsec/advisory-db"] +# A list of advisory IDs to ignore. Note that ignored advisories will still +# output a note when they are encountered. +ignore = [ + #"RUSTSEC-0000-0000", + #{ id = "RUSTSEC-0000-0000", reason = "you can specify a reason the advisory is ignored" }, + #"a-crate-that-is-yanked@0.1.1", # you can also ignore yanked crate versions if you wish + #{ crate = "a-crate-that-is-yanked@0.1.1", reason = "you can specify why you are ignoring the yanked crate" }, +] +# If this is true, then cargo deny will use the git executable to fetch advisory database. +# If this is false, then it uses a built-in git library. +# Setting this to true can be helpful if you have special authentication requirements that cargo-deny does not support. +# See Git Authentication for more information about setting up git authentication. +#git-fetch-with-cli = true + +# This section is considered when running `cargo deny check licenses` +# More documentation for the licenses section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/licenses/cfg.html +[licenses] +# List of explicitly allowed licenses +# See https://spdx.org/licenses/ for list of possible licenses +# [possible values: any SPDX 3.11 short identifier (+ optional exception)]. +allow = [ + "MIT", + "Apache-2.0", + "BSD-3-Clause", + "Unicode-3.0", + #"Apache-2.0 WITH LLVM-exception", +] +# The confidence threshold for detecting a license from license text. +# The higher the value, the more closely the license text must be to the +# canonical license text of a valid SPDX license file. +# [possible values: any between 0.0 and 1.0]. +confidence-threshold = 0.8 +# Allow 1 or more licenses on a per-crate basis, so that particular licenses +# aren't accepted for every possible crate as with the normal allow list +exceptions = [ + # Each entry is the crate and version constraint, and its specific allow + # list + #{ allow = ["Zlib"], crate = "adler32" }, +] + +# Some crates don't have (easily) machine readable licensing information, +# adding a clarification entry for it allows you to manually specify the +# licensing information +#[[licenses.clarify]] +# The package spec the clarification applies to +#crate = "ring" +# The SPDX expression for the license requirements of the crate +#expression = "MIT AND ISC AND OpenSSL" +# One or more files in the crate's source used as the "source of truth" for +# the license expression. If the contents match, the clarification will be used +# when running the license check, otherwise the clarification will be ignored +# and the crate will be checked normally, which may produce warnings or errors +# depending on the rest of your configuration +#license-files = [ +# Each entry is a crate relative path, and the (opaque) hash of its contents +#{ path = "LICENSE", hash = 0xbd0eed23 } +#] + +[licenses.private] +# If true, ignores workspace crates that aren't published, or are only +# published to private registries. +# To see how to mark a crate as unpublished (to the official registry), +# visit https://doc.rust-lang.org/cargo/reference/manifest.html#the-publish-field. +ignore = false +# One or more private registries that you might publish crates to, if a crate +# is only published to private registries, and ignore is true, the crate will +# not have its license(s) checked +registries = [ + #"https://sekretz.com/registry +] + +# This section is considered when running `cargo deny check bans`. +# More documentation about the 'bans' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/bans/cfg.html +[bans] +# Lint level for when multiple versions of the same crate are detected +multiple-versions = "warn" +# Lint level for when a crate version requirement is `*` +wildcards = "allow" +# The graph highlighting used when creating dotgraphs for crates +# with multiple versions +# * lowest-version - The path to the lowest versioned duplicate is highlighted +# * simplest-path - The path to the version with the fewest edges is highlighted +# * all - Both lowest-version and simplest-path are used +highlight = "all" +# The default lint level for `default` features for crates that are members of +# the workspace that is being checked. This can be overridden by allowing/denying +# `default` on a crate-by-crate basis if desired. +workspace-default-features = "allow" +# The default lint level for `default` features for external crates that are not +# members of the workspace. This can be overridden by allowing/denying `default` +# on a crate-by-crate basis if desired. +external-default-features = "allow" +# List of crates that are allowed. Use with care! +allow = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is allowed" }, +] +# If true, workspace members are automatically allowed even when using deny-by-default +# This is useful for organizations that want to deny all external dependencies by default +# but allow their own workspace crates without having to explicitly list them +allow-workspace = false +# List of crates to deny +deny = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason it is banned" }, + # Wrapper crates can optionally be specified to allow the crate when it + # is a direct dependency of the otherwise banned crate + #{ crate = "ansi_term@0.11.0", wrappers = ["this-crate-directly-depends-on-ansi_term"] }, +] + +# List of features to allow/deny +# Each entry the name of a crate and a version range. If version is +# not specified, all versions will be matched. +#[[bans.features]] +#crate = "reqwest" +# Features to not allow +#deny = ["json"] +# Features to allow +#allow = [ +# "rustls", +# "__rustls", +# "__tls", +# "hyper-rustls", +# "rustls", +# "rustls-pemfile", +# "rustls-tls-webpki-roots", +# "tokio-rustls", +# "webpki-roots", +#] +# If true, the allowed features must exactly match the enabled feature set. If +# this is set there is no point setting `deny` +#exact = true + +# Certain crates/versions that will be skipped when doing duplicate detection. +skip = [ + #"ansi_term@0.11.0", + #{ crate = "ansi_term@0.11.0", reason = "you can specify a reason why it can't be updated/removed" }, +] +# Similarly to `skip` allows you to skip certain crates during duplicate +# detection. Unlike skip, it also includes the entire tree of transitive +# dependencies starting at the specified crate, up to a certain depth, which is +# by default infinite. +skip-tree = [ + #"ansi_term@0.11.0", # will be skipped along with _all_ of its direct and transitive dependencies + #{ crate = "ansi_term@0.11.0", depth = 20 }, +] + +# This section is considered when running `cargo deny check sources`. +# More documentation about the 'sources' section can be found here: +# https://embarkstudios.github.io/cargo-deny/checks/sources/cfg.html +[sources] +# Lint level for what to happen when a crate from a crate registry that is not +# in the allow list is encountered +unknown-registry = "warn" +# Lint level for what to happen when a crate from a git repository that is not +# in the allow list is encountered +unknown-git = "warn" +# List of URLs for allowed crate registries. Defaults to the crates.io index +# if not specified. If it is specified but empty, no registries are allowed. +allow-registry = ["https://github.com/rust-lang/crates.io-index"] +# List of URLs for allowed Git repositories +allow-git = [] + +[sources.allow-org] +# github.com organizations to allow git sources for +github = [] +# gitlab.com organizations to allow git sources for +gitlab = [] +# bitbucket.org organizations to allow git sources for +bitbucket = [] diff --git a/src/config.json b/src/config.json new file mode 100644 index 0000000..2894198 --- /dev/null +++ b/src/config.json @@ -0,0 +1,1207 @@ +{ + "cpuids": { + "0": { + "name": "Start", + "data_type": { + "type": "Start" + } + }, + "1": { + "name": "Model", + "data_type": { + "type": "BitField", + "eax": [ + { + "type": "Int", + "name": "stepping", + "bounds": { + "start": 0, + "end": 4 + } + }, + { + "type": "X86Model", + "name": "model" + }, + { + "type": "X86Family", + "name": "family", + "bounds": { + "start": 8, + "end": 11 + } + } + ], + "ebx": [], + "ecx": [ + { + "type": "Flag", + "name": "SSE3", + "bit": 0 + }, + { + "type": "Flag", + "name": "VMX", + "bit": 5 + }, + { + "type": "Flag", + "name": "x2APIC", + "bit": 21 + }, + { + "type": "Flag", + "name": "AESNI", + "bit": 25 + } + ], + "edx": [ + { + "type": "Flag", + "name": "fpu", + "bit": 0 + }, + { + "type": "Flag", + "name": "vme", + "bit": 0 + } + ] + } + }, + "7": { + "name": "Structured Extened Flags", + "data_type": { + "type": "SubLeafBitField", + "leaves": [ + { + "eax": [ + { + "type": "Int", + "name": "Sub-Leaf Count", + "bounds": { + "start": 0, + "end": 31 + } + } + ], + "ebx": [ + { + "type": "Flag", + "name": "HLE", + "bit": 4 + }, + { + "type": "Flag", + "name": "RTM", + "bit": 11 + }, + { + "type": "Flag", + "name": "MPX", + "bit": 14 + }, + { + "type": "Flag", + "name": "PT", + "bit": 25 + } + ], + "ecx": [], + "edx": [ + { + "type": "Flag", + "name": "AVX512 VP2Intersect", + "bit": 8 + }, + { + "type": "Flag", + "name": "RTM Always Abort", + "bit": 11 + }, + { + "type": "Flag", + "name": "RTM Force Abort", + "bit": 13 + }, + { + "type": "Flag", + "name": "Arch_Capabilities", + "bit": 29 + }, + { + "type": "Flag", + "name": "Core_Capabilities", + "bit": 30 + } + ] + }, + { + "eax": [ + { + "type": "Flag", + "name": "AVX VNNI", + "bit": 14 + } + ], + "ebx": [], + "ecx": [], + "edx": [] + }, + { + "eax": [], + "ebx": [], + "ecx": [], + "edx": [ + { + "type": "Flag", + "name": "PSFD", + "bit": 0 + } + ] + } + ] + } + }, + "0xd": { + "name": "Processor Extended State Enumeration", + "data_type": { + "type": "SubLeafBitField", + "leaves": [ + { + "eax": [ + { + "type": "Flag", + "name": "X87 State", + "bit": 0 + }, + { + "type": "Flag", + "name": "SSE State", + "bit": 1 + }, + { + "type": "Flag", + "name": "AVX State", + "bit": 2 + }, + { + "type": "Flag", + "name": "BNDREGS State", + "bit": 3 + }, + { + "type": "Flag", + "name": "BNDCSR State", + "bit": 4 + }, + { + "type": "Flag", + "name": "OPMASK State", + "bit": 5 + }, + { + "type": "Flag", + "name": "ZMM_Hi256 State", + "bit": 6 + }, + { + "type": "Flag", + "name": "Hi16_ZMM State", + "bit": 7 + }, + { + "type": "Flag", + "name": "IA32_XSS State", + "bit": 8 + }, + { + "type": "Flag", + "name": "PKRU State", + "bit": 9 + } + ], + "ebx": [], + "ecx": [], + "edx": [] + }, + { + "eax": [ + { + "type": "Flag", + "name": "XSAVEOPT", + "bit": 0 + }, + { + "type": "Flag", + "name": "XSAVEC", + "bit": 1 + }, + { + "type": "Flag", + "name": "XGETBV with ECX=1", + "bit": 2 + }, + { + "type": "Flag", + "name": "XSAVES", + "bit": 3 + }, + { + "type": "Flag", + "name": "Extended Feature Disable(XFD)", + "bit": 4 + } + ], + "ebx": [], + "ecx": [], + "edx": [] + } + ] + } + }, + "0x40000000": { + "name": "Hypervisor ID", + "data_type": { + "type": "Start" + } + }, + "0x40000001": { + "name": "Hypervisor Vendor-Neutral ID", + "data_type": { + "type": "String" + } + }, + "0x40000002": { + "name": "Hypervisor System ID", + "data_type": { + "type": "BitField", + "eax": [ + { + "type": "Int", + "name": "Build Number", + "bounds": { + "start": 0, + "end": 31 + } + } + ], + "ebx": [ + { + "type": "Int", + "name": "Major", + "bounds": { + "start": 16, + "end": 31 + } + }, + { + "type": "Int", + "name": "Minor", + "bounds": { + "start": 0, + "end": 15 + } + } + ], + "ecx": [], + "edx": [] + } + }, + "0x40000003": { + "name": "Hypervisor Feature ID", + "data_type": { + "type": "BitField", + "eax": [ + { + "type": "Int", + "name": "Privilege Mask Low", + "bounds": { + "start": 0, + "end": 31 + } + } + ], + "ebx": [ + { + "type": "Int", + "name": "Privilege Mask High", + "bounds": { + "start": 0, + "end": 31 + } + } + ], + "ecx": [ + { + "type": "Flag", + "name": "Mperf", + "bit": 5 + }, + { + "type": "Flag", + "name": "Shadow Stack", + "bit": 6 + }, + { + "type": "Flag", + "name": "PMU", + "bit": 7 + }, + { + "type": "Flag", + "name": "Trap Intercept", + "bit": 8 + } + ], + "edx": [ + { + "type": "Flag", + "name": "MWAIT(Depricated)", + "bit": 0 + }, + { + "type": "Flag", + "name": "Debug", + "bit": 1 + }, + { + "type": "Flag", + "name": "PerfMon", + "bit": 2 + }, + { + "type": "Flag", + "name": "Physical partition events", + "bit": 3 + }, + { + "type": "Flag", + "name": "Hypercall XMM", + "bit": 4 + }, + { + "type": "Flag", + "name": "Guest Idle", + "bit": 5 + }, + { + "type": "Flag", + "name": "Hypervisor sleep", + "bit": 6 + }, + { + "type": "Flag", + "name": "NUMA", + "bit": 7 + }, + { + "type": "Flag", + "name": "Timer Freq.", + "bit": 8 + }, + { + "type": "Flag", + "name": "MCEInject", + "bit": 9 + }, + { + "type": "Flag", + "name": "Crash MSR", + "bit": 10 + }, + { + "type": "Flag", + "name": "Debug MSR", + "bit": 11 + }, + { + "type": "Flag", + "name": "NPIEP", + "bit": 12 + }, + { + "type": "Flag", + "name": "DisableHypervisorAvailable", + "bit": 13 + }, + { + "type": "Flag", + "name": "ExtendedGvaRangesForFlushVirtualAddressListAvailable", + "bit": 14 + }, + { + "type": "Flag", + "name": "Hypercall XMM Return", + "bit": 15 + }, + { + "type": "Flag", + "name": "SintPollingModeAvailable", + "bit": 17 + }, + { + "type": "Flag", + "name": "HypercallMsrLockAvailable", + "bit": 18 + }, + { + "type": "Flag", + "name": "Direct Synthetic Timers", + "bit": 19 + }, + { + "type": "Flag", + "name": "PAT VSM", + "bit": 20 + }, + { + "type": "Flag", + "name": "bindcfgs VSM", + "bit": 21 + }, + { + "type": "Flag", + "name": "Unhalted Timer", + "bit": 23 + }, + { + "type": "Flag", + "name": "LBR", + "bit": 26 + } + ] + } + }, + "0x40000005": { + "name": "Hypervisor Feature ID", + "data_type": { + "type": "BitField", + "eax": [ + { + "type": "Int", + "name": "Max Virtual Porcessors", + "bounds": { + "start": 0, + "end": 31 + } + } + ], + "ebx": [ + { + "type": "Int", + "name": "Max Logical Porcessors", + "bounds": { + "start": 0, + "end": 31 + } + } + ], + "ecx": [ + { + "type": "Int", + "name": "Max Pysical Interrupt Vectors", + "bounds": { + "start": 0, + "end": 31 + } + } + ], + "edx": [] + } + }, + "0x80000002": { + "name": "Brand String 1", + "data_type": { + "type": "String" + } + }, + "0x80000003": { + "name": "Brand String 2", + "data_type": { + "type": "String" + } + }, + "0x80000004": { + "name": "Brand String 3", + "data_type": { + "type": "String" + } + }, + "0x80000008": { + "name": "Address Sizes and Extended Features", + "data_type": { + "type": "BitField", + "eax": [], + "ebx": [ + { + "type": "Flag", + "name": "WBNOINVD", + "bit": 9 + } + ], + "ecx": [], + "edx": [] + } + } + }, + "msrs": [ + { + "name": "Platform ID", + "address": "0x17", + "fields": [ + { + "type": "Int", + "name": "Platform_ID\"", + "bounds": { + "start": 50, + "end": 52 + } + } + ] + }, + { + "name": "Core_Capabilities", + "address": "0xcf", + "fields": [ + { + "type": "Flag", + "name": "SPLIT_LOCK_DISABLE_SUPPORTED", + "bit": 5 + } + ] + }, + { + "name": "Arch Capabilities", + "address": "0x10a", + "fields": [ + { + "type": "Flag", + "name": "RDCL_NO", + "bit": 0 + }, + { + "type": "Flag", + "name": "IBRS_ALL", + "bit": 1 + }, + { + "type": "Flag", + "name": "RSBA", + "bit": 2 + }, + { + "type": "Flag", + "name": "SKIP_L1DF_VMENTRY", + "bit": 3 + }, + { + "type": "Flag", + "name": "SSB_NO", + "bit": 4 + }, + { + "type": "Flag", + "name": "MDS_NO", + "bit": 5 + }, + { + "type": "Flag", + "name": "IF_PSCHANGE_MC_NO", + "bit": 6 + }, + { + "type": "Flag", + "name": "TSX_CTRL", + "bit": 7 + }, + { + "type": "Flag", + "name": "TAA_NO", + "bit": 8 + }, + { + "type": "Flag", + "name": "GDS_CTRL", + "bit": 25 + }, + { + "type": "Flag", + "name": "GDS_NO", + "bit": 26 + } + ] + }, + { + "name": "Microcode Update Option Control", + "address": "0x123", + "fields": [ + { + "type": "Flag", + "name": "GDS_MITG_DIS", + "bit": 4 + }, + { + "type": "Flag", + "name": "GDS_MITG_LOCK", + "bit": 5 + } + ] + }, + { + "name": "Perf_Capabilities", + "address": "0x345", + "fields": [ + { + "type": "Int", + "name": "LBR_FMT", + "bounds": { + "start": 0, + "end": 5 + } + }, + { + "type": "Flag", + "name": "PEBSTrap", + "bit": 6 + }, + { + "type": "Flag", + "name": "PEBSArchRegs", + "bit": 7 + }, + { + "type": "Int", + "name": "PEBS_FMT", + "bounds": { + "start": 8, + "end": 11 + } + }, + { + "type": "Flag", + "name": "SMM_FREEZE", + "bit": 12 + }, + { + "type": "Flag", + "name": "FULL_WRITE", + "bit": 13 + }, + { + "type": "Flag", + "name": "PEBS_BASELINE", + "bit": 14 + }, + { + "type": "Flag", + "name": "METRICS_AVAIL", + "bit": 15 + }, + { + "type": "Flag", + "name": "PEBS_PT_AVAIL", + "bit": 16 + } + ] + }, + { + "name": "Basic VMX", + "address": "0x480", + "fields": [ + { + "type": "Int", + "name": "Revision", + "bounds": { + "start": 0, + "end": 30 + } + }, + { + "type": "Int", + "name": "VMXON size", + "bounds": { + "start": 32, + "end": 44 + } + }, + { + "type": "Flag", + "name": "VMX controls", + "bit": 55 + }, + { + "type": "Flag", + "name": "Soft exceptions", + "bit": 56 + } + ] + }, + { + "name": "VMX: Pin-based Ctls", + "address": "0x481", + "fields": [ + { + "type": "Flag", + "name": "Ext Int Exit", + "bit": 32 + }, + { + "type": "Flag", + "name": "NMI Exits", + "bit": 35 + }, + { + "type": "Flag", + "name": "Virt NMI", + "bit": 37 + }, + { + "type": "Flag", + "name": "VMX Timer", + "bit": 38 + }, + { + "type": "Flag", + "name": "posted Int", + "bit": 39 + } + ] + }, + { + "name": "VMX: True Pin-based Ctls", + "address": "0x48d", + "fields": [ + { + "type": "Flag", + "name": "Ext Int Exit", + "bit": 32 + }, + { + "type": "Flag", + "name": "NMI Exits", + "bit": 35 + }, + { + "type": "Flag", + "name": "Virt NMI", + "bit": 37 + }, + { + "type": "Flag", + "name": "VMX Timer", + "bit": 38 + }, + { + "type": "Flag", + "name": "posted Int", + "bit": 39 + } + ] + }, + { + "name": "VMX: Proccessor Based Ctls - Most", + "address": "0x482", + "fields": [ + { + "type": "Flag", + "name": "Int Window Exit", + "bit": 34 + }, + { + "type": "Flag", + "name": "TSC Offsetting", + "bit": 35 + }, + { + "type": "Flag", + "name": "HLT exit", + "bit": 39 + }, + { + "type": "Flag", + "name": "INVLPG exit", + "bit": 41 + }, + { + "type": "Flag", + "name": "MWAIT exit", + "bit": 42 + }, + { + "type": "Flag", + "name": "RDPMC exit", + "bit": 43 + }, + { + "type": "Flag", + "name": "RDTSC exit", + "bit": 44 + }, + { + "type": "Flag", + "name": "CR3-load exit", + "bit": 47 + }, + { + "type": "Flag", + "name": "CR3-store exit", + "bit": 48 + }, + { + "type": "Flag", + "name": "Ctls 3", + "bit": 49 + }, + { + "type": "Flag", + "name": "CR8-load exit", + "bit": 51 + }, + { + "type": "Flag", + "name": "CR8-store exit", + "bit": 52 + }, + { + "type": "Flag", + "name": "TPR Shadow", + "bit": 53 + }, + { + "type": "Flag", + "name": "NMI exit", + "bit": 54 + }, + { + "type": "Flag", + "name": "MOV-DR exit", + "bit": 55 + }, + { + "type": "Flag", + "name": "IO exit-all", + "bit": 56 + }, + { + "type": "Flag", + "name": "IO bitmap", + "bit": 57 + }, + { + "type": "Flag", + "name": "Monitor Trap", + "bit": 59 + }, + { + "type": "Flag", + "name": "MSR bitmap", + "bit": 60 + }, + { + "type": "Flag", + "name": "MONITOR exit", + "bit": 61 + }, + { + "type": "Flag", + "name": "PAUSE exit", + "bit": 62 + }, + { + "type": "Flag", + "name": "Ctls 2", + "bit": 63 + } + ] + }, + { + "name": "VMX: Proccessor Based Ctls - All", + "address": "0x48e", + "fields": [ + { + "type": "Flag", + "name": "Int Window Exit", + "bit": 34 + }, + { + "type": "Flag", + "name": "TSC Offsetting", + "bit": 35 + }, + { + "type": "Flag", + "name": "HLT exit", + "bit": 39 + }, + { + "type": "Flag", + "name": "INVLPG exit", + "bit": 41 + }, + { + "type": "Flag", + "name": "MWAIT exit", + "bit": 42 + }, + { + "type": "Flag", + "name": "RDPMC exit", + "bit": 43 + }, + { + "type": "Flag", + "name": "RDTSC exit", + "bit": 44 + }, + { + "type": "Flag", + "name": "CR3-load exit", + "bit": 47 + }, + { + "type": "Flag", + "name": "CR3-store exit", + "bit": 48 + }, + { + "type": "Flag", + "name": "Ctls 3", + "bit": 49 + }, + { + "type": "Flag", + "name": "CR8-load exit", + "bit": 51 + }, + { + "type": "Flag", + "name": "CR8-store exit", + "bit": 52 + }, + { + "type": "Flag", + "name": "TPR Shadow", + "bit": 53 + }, + { + "type": "Flag", + "name": "NMI exit", + "bit": 54 + }, + { + "type": "Flag", + "name": "MOV-DR exit", + "bit": 55 + }, + { + "type": "Flag", + "name": "IO exit-all", + "bit": 56 + }, + { + "type": "Flag", + "name": "IO bitmap", + "bit": 57 + }, + { + "type": "Flag", + "name": "Monitor Trap", + "bit": 59 + }, + { + "type": "Flag", + "name": "MSR bitmap", + "bit": 60 + }, + { + "type": "Flag", + "name": "MONITOR exit", + "bit": 61 + }, + { + "type": "Flag", + "name": "PAUSE exit", + "bit": 62 + }, + { + "type": "Flag", + "name": "Ctls 2", + "bit": 63 + } + ] + }, + { + "name": "VMX: Proccessor Based Ctls 2", + "address": "0x48b", + "fields": [ + { + "type": "Flag", + "name": "Virt APIC", + "bit": 32 + }, + { + "type": "Flag", + "name": "Enable EPT", + "bit": 33 + }, + { + "type": "Flag", + "name": "Descriptor Table exit", + "bit": 34 + }, + { + "type": "Flag", + "name": "Enable RDTSCP", + "bit": 35 + }, + { + "type": "Flag", + "name": "Virt x2APIC", + "bit": 36 + }, + { + "type": "Flag", + "name": "Enable VPID", + "bit": 37 + }, + { + "type": "Flag", + "name": "WBINVD exit", + "bit": 38 + }, + { + "type": "Flag", + "name": "unrestricted", + "bit": 39 + }, + { + "type": "Flag", + "name": "Virt Apic", + "bit": 40 + }, + { + "type": "Flag", + "name": "Virt Interrupts", + "bit": 41 + }, + { + "type": "Flag", + "name": "PAUSE loop exit", + "bit": 42 + }, + { + "type": "Flag", + "name": "RDRAND exit", + "bit": 43 + }, + { + "type": "Flag", + "name": "Enable INVPCID", + "bit": 44 + }, + { + "type": "Flag", + "name": "Enable VMFUNC", + "bit": 45 + }, + { + "type": "Flag", + "name": "VMCS shadow", + "bit": 46 + }, + { + "type": "Flag", + "name": "ENCLS exit", + "bit": 47 + }, + { + "type": "Flag", + "name": "RDSEED exit", + "bit": 48 + }, + { + "type": "Flag", + "name": "Enable PML", + "bit": 49 + }, + { + "type": "Flag", + "name": "EPT exceptions", + "bit": 50 + }, + { + "type": "Flag", + "name": "VMX-PT conceal", + "bit": 51 + }, + { + "type": "Flag", + "name": "Enable XSAVE", + "bit": 52 + }, + { + "type": "Flag", + "name": "Mode EPT Ctrl", + "bit": 54 + }, + { + "type": "Flag", + "name": "EPT Write Perm size", + "bit": 55 + }, + { + "type": "Flag", + "name": "PT - Guest Addr", + "bit": 56 + }, + { + "type": "Flag", + "name": "TSC scaling", + "bit": 57 + }, + { + "type": "Flag", + "name": "User Wait", + "bit": 58 + }, + { + "type": "Flag", + "name": "Enable Pconfig", + "bit": 59 + }, + { + "type": "Flag", + "name": "ENCLV Exit", + "bit": 60 + } + ] + }, + { + "name": "VMX: Proccessor Based Ctls 3", + "address": "0x492", + "fields": [ + { + "type": "Flag", + "name": "LOADIWKEY", + "bit": 0 + }, + { + "type": "Flag", + "name": "Enable HLAT", + "bit": 1 + }, + { + "type": "Flag", + "name": "EPT Write Ctrl", + "bit": 2 + }, + { + "type": "Flag", + "name": "Guest Page Verify", + "bit": 3 + } + ] + } + ] +} diff --git a/src/config.yaml b/src/config.yaml deleted file mode 100644 index c3ad26b..0000000 --- a/src/config.yaml +++ /dev/null @@ -1,354 +0,0 @@ -cpuids: - 0: - name: "Start" - data_type: - type: Start - - 1: - name: "Model" - data_type: - type: BitField - eax: - - type: Int - name: stepping - bounds: - start: 0 - end: 4 - - type: X86Model - name: model - - type: X86Family - name: family - bounds: - start: 8 - end: 11 - ebx: [] - ecx: - - type: Flag - name: SSE3 - bit: 0 - - type: Flag - name: VMX - bit: 5 - - {type: Flag, name: x2APIC, bit: 21} - - {type: Flag, name: AESNI, bit: 25} - - edx: - - type: Flag - name: fpu - bit: 0 - - type: Flag - name: vme - bit: 0 - - 0x00000007: - name: "Structured Extened Flags" - data_type: - type: SubLeafBitField - leaves: - - eax: - - {type: Int, name: "Sub-Leaf Count", bounds: {start: 0, end: 31}} - ebx: - - {type: Flag, name: HLE, bit: 4} - - {type: Flag, name: RTM, bit: 11} - - {type: Flag, name: MPX, bit: 14} - - {type: Flag, name: PT, bit: 25} - ecx: [] - edx: - - {type: Flag, name: "AVX512 VP2Intersect", bit: 8} - - {type: Flag, name: "RTM Always Abort", bit: 11} - - {type: Flag, name: "RTM Force Abort", bit: 13} - - {type: Flag, name: "Arch_Capabilities", bit: 29} - - {type: Flag, name: "Core_Capabilities", bit: 30} - - eax: - - {type: Flag, name: "AVX VNNI", bit: 14} - ebx: [] - ecx: [] - edx: [] - - eax: [] - ebx: [] - ecx: [] - edx: - - {type: Flag, name: PSFD, bit: 0} - - 0x0000000D: - name: "Processor Extended State Enumeration" - data_type: - type: SubLeafBitField - leaves: - - eax: - - {type: Flag, name: "X87 State", bit: 0} - - {type: Flag, name: "SSE State", bit: 1} - - {type: Flag, name: "AVX State", bit: 2} - - {type: Flag, name: "BNDREGS State", bit: 3} - - {type: Flag, name: "BNDCSR State", bit: 4} - - {type: Flag, name: "OPMASK State", bit: 5} - - {type: Flag, name: "ZMM_Hi256 State", bit: 6} - - {type: Flag, name: "Hi16_ZMM State", bit: 7} - - {type: Flag, name: "IA32_XSS State", bit: 8} - - {type: Flag, name: "PKRU State", bit: 9} - ebx: [] - ecx: [] - edx: [] - - eax: - - {type: Flag, name: "XSAVEOPT", bit: 0} - - {type: Flag, name: "XSAVEC", bit: 1} - - {type: Flag, name: "XGETBV with ECX=1", bit: 2} - - {type: Flag, name: "XSAVES", bit: 3} - - {type: Flag, name: "Extended Feature Disable(XFD)", bit: 4} - ebx: [] - ecx: [] - edx: [] - - 0x40000000: - name: "Hypervisor ID" - data_type: - type: Start - - 0x40000001: - name: "Hypervisor Vendor-Neutral ID" - data_type: - type: String - - 0x40000002: - name: "Hypervisor System ID" - data_type: - type: BitField - eax: - - {type: Int, name: "Build Number", bounds: {start: 0, end: 31}} - ebx: - - {type: Int, name: "Major", bounds: {start: 16, end: 31}} - - {type: Int, name: "Minor", bounds: {start: 0, end: 15}} - ecx: [] - edx: [] - - 0x40000003: - name: "Hypervisor Feature ID" - data_type: - type: BitField - eax: - - {type: Int, name: "Privilege Mask Low", bounds: {start: 0, end: 31}} - ebx: - - {type: Int, name: "Privilege Mask High", bounds: {start: 0, end: 31}} - ecx: - - {type: Flag, name: Mperf, bit: 5} - - {type: Flag, name: "Shadow Stack", bit: 6} - - {type: Flag, name: PMU, bit: 7} - - {type: Flag, name: "Trap Intercept", bit: 8} - edx: - - {type: Flag, name: MWAIT(Depricated), bit: 0} - - {type: Flag, name: Debug, bit: 1} - - {type: Flag, name: PerfMon, bit: 2} - - {type: Flag, name: "Physical partition events", bit: 3} - - {type: Flag, name: Hypercall XMM, bit: 4} - - {type: Flag, name: Guest Idle, bit: 5} - - {type: Flag, name: Hypervisor sleep, bit: 6} - - {type: Flag, name: NUMA, bit: 7} - - {type: Flag, name: Timer Freq., bit: 8} - - {type: Flag, name: MCEInject, bit: 9} - - {type: Flag, name: Crash MSR, bit: 10} - - {type: Flag, name: Debug MSR, bit: 11} - - {type: Flag, name: NPIEP, bit: 12} - - {type: Flag, name: DisableHypervisorAvailable, bit: 13} - - {type: Flag, name: ExtendedGvaRangesForFlushVirtualAddressListAvailable, bit: 14} - - {type: Flag, name: Hypercall XMM Return, bit: 15} - - {type: Flag, name: SintPollingModeAvailable, bit: 17} - - {type: Flag, name: HypercallMsrLockAvailable, bit: 18} - - {type: Flag, name: Direct Synthetic Timers, bit: 19} - - {type: Flag, name: PAT VSM, bit: 20} - - {type: Flag, name: bindcfgs VSM, bit: 21} - - {type: Flag, name: Unhalted Timer, bit: 23} - - {type: Flag, name: LBR, bit: 26} - - 0x40000005: - name: "Hypervisor Feature ID" - data_type: - type: BitField - eax: - - {type: Int, name: "Max Virtual Porcessors", bounds: {start: 0, end: 31}} - ebx: - - {type: Int, name: "Max Logical Porcessors", bounds: {start: 0, end: 31}} - ecx: - - {type: Int, name: "Max Pysical Interrupt Vectors", bounds: {start: 0, end: 31}} - edx: [] - - 0x80000002: - name: "Brand String 1" - data_type: - type: String - - 0x80000003: - name: "Brand String 2" - data_type: - type: String - - 0x80000004: - name: "Brand String 3" - data_type: - type: String - 0x80000008: - name: "Address Sizes and Extended Features" - data_type: - type: BitField - eax: [] - ebx: - - {type: Flag, name: "WBNOINVD", bit: 9} - ecx: [] - edx: [] -msrs: - - name: "Platform ID" - address: 0x17 - fields: - - {type: Int, name: Platform_ID", bounds: {start: 50, end: 52}} - - - name: "Core_Capabilities" - address: 0xCF - fields: - - {type: Flag, name: "SPLIT_LOCK_DISABLE_SUPPORTED", bit: 5} - - - name: Arch Capabilities - address: 0x10a - fields: - - {type: Flag, name: RDCL_NO, bit: 0} - - {type: Flag, name: IBRS_ALL, bit: 1} - - {type: Flag, name: RSBA, bit: 2} - - {type: Flag, name: SKIP_L1DF_VMENTRY, bit: 3} - - {type: Flag, name: SSB_NO, bit: 4} - - {type: Flag, name: MDS_NO, bit: 5} - - {type: Flag, name: IF_PSCHANGE_MC_NO, bit: 6} - - {type: Flag, name: TSX_CTRL, bit: 7} - - {type: Flag, name: TAA_NO, bit: 8} - - {type: Flag, name: GDS_CTRL, bit: 25} - - {type: Flag, name: GDS_NO, bit: 26} - - name: Microcode Update Option Control - address: 0x123 - fields: - - {type: Flag, name: "GDS_MITG_DIS", bit: 4} - - {type: Flag, name: "GDS_MITG_LOCK", bit: 5} - - name: "Perf_Capabilities" - address: 0x345 - fields: - - {type: Int, name: "LBR_FMT", bounds: {start: 0, end: 5}} - - {type: Flag, name: "PEBSTrap", bit: 6} - - {type: Flag, name: "PEBSArchRegs", bit: 7} - - {type: Int, name: "PEBS_FMT",bounds: {start: 8, end: 11}} - - {type: Flag, name: "SMM_FREEZE", bit: 12} - - {type: Flag, name: "FULL_WRITE", bit: 13} - - {type: Flag, name: "PEBS_BASELINE", bit: 14} - - {type: Flag, name: "METRICS_AVAIL", bit: 15} - - {type: Flag, name: "PEBS_PT_AVAIL", bit: 16} - - name: Basic VMX - address: 0x480 - fields: - - {type: Int, name: "Revision", bounds:{ start: 0, end: 30}} - - {type: Int, name: "VMXON size", bounds: { start: 32, end: 44}} - - {type: Flag, name: "VMX controls", bit: 55} - - {type: Flag, name: "Soft exceptions", bit: 56} - - name: "VMX: Pin-based Ctls" - address: 0x481 - fields: - - {type: Flag, name: "Ext Int Exit", bit: 32} - - {type: Flag, name: "NMI Exits", bit: 35} - - {type: Flag, name: "Virt NMI", bit: 37} - - {type: Flag, name: "VMX Timer", bit: 38} - - {type: Flag, name: "posted Int", bit: 39} - - - name: "VMX: True Pin-based Ctls" - address: 0x48D - fields: - - {type: Flag, name: "Ext Int Exit", bit: 32} - - {type: Flag, name: "NMI Exits", bit: 35} - - {type: Flag, name: "Virt NMI", bit: 37} - - {type: Flag, name: "VMX Timer", bit: 38} - - {type: Flag, name: "posted Int", bit: 39} - - - name: "VMX: Proccessor Based Ctls - Most" - address: 0x482 - fields: - - {type: Flag, name: "Int Window Exit", bit: 34} - - {type: Flag, name: "TSC Offsetting", bit: 35} - - {type: Flag, name: "HLT exit", bit: 39} - - {type: Flag, name: "INVLPG exit", bit: 41} - - {type: Flag, name: "MWAIT exit", bit: 42} - - {type: Flag, name: "RDPMC exit", bit: 43} - - {type: Flag, name: "RDTSC exit", bit: 44} - - {type: Flag, name: "CR3-load exit", bit: 47} - - {type: Flag, name: "CR3-store exit", bit: 48} - - {type: Flag, name: "Ctls 3", bit: 49 } - - {type: Flag, name: "CR8-load exit", bit: 51} - - {type: Flag, name: "CR8-store exit", bit: 52} - - {type: Flag, name: "TPR Shadow", bit: 53} - - {type: Flag, name: "NMI exit", bit: 54} - - {type: Flag, name: "MOV-DR exit", bit: 55} - - {type: Flag, name: "IO exit-all", bit: 56} - - {type: Flag, name: "IO bitmap", bit: 57} - - {type: Flag, name: "Monitor Trap", bit: 59} - - {type: Flag, name: "MSR bitmap", bit: 60} - - {type: Flag, name: "MONITOR exit", bit: 61} - - {type: Flag, name: "PAUSE exit", bit: 62} - - {type: Flag, name: "Ctls 2", bit: 63} - - - name: "VMX: Proccessor Based Ctls - All" - address: 0x48E - fields: - - {type: Flag, name: "Int Window Exit", bit: 34} - - {type: Flag, name: "TSC Offsetting", bit: 35} - - {type: Flag, name: "HLT exit", bit: 39} - - {type: Flag, name: "INVLPG exit", bit: 41} - - {type: Flag, name: "MWAIT exit", bit: 42} - - {type: Flag, name: "RDPMC exit", bit: 43} - - {type: Flag, name: "RDTSC exit", bit: 44} - - {type: Flag, name: "CR3-load exit", bit: 47} - - {type: Flag, name: "CR3-store exit", bit: 48} - - {type: Flag, name: "Ctls 3", bit: 49 } - - {type: Flag, name: "CR8-load exit", bit: 51} - - {type: Flag, name: "CR8-store exit", bit: 52} - - {type: Flag, name: "TPR Shadow", bit: 53} - - {type: Flag, name: "NMI exit", bit: 54} - - {type: Flag, name: "MOV-DR exit", bit: 55} - - {type: Flag, name: "IO exit-all", bit: 56} - - {type: Flag, name: "IO bitmap", bit: 57} - - {type: Flag, name: "Monitor Trap", bit: 59} - - {type: Flag, name: "MSR bitmap", bit: 60} - - {type: Flag, name: "MONITOR exit", bit: 61} - - {type: Flag, name: "PAUSE exit", bit: 62} - - {type: Flag, name: "Ctls 2", bit: 63} - - - name: "VMX: Proccessor Based Ctls 2" - address: 0x48B - fields: - - {type: Flag, name: "Virt APIC", bit: 32} - - {type: Flag, name: "Enable EPT", bit: 33} - - {type: Flag, name: "Descriptor Table exit", bit: 34} - - {type: Flag, name: "Enable RDTSCP", bit: 35} - - {type: Flag, name: "Virt x2APIC", bit: 36} - - {type: Flag, name: "Enable VPID", bit: 37} - - {type: Flag, name: "WBINVD exit", bit: 38} - - {type: Flag, name: "unrestricted", bit: 39} - - {type: Flag, name: "Virt Apic", bit: 40} - - {type: Flag, name: "Virt Interrupts", bit: 41} - - {type: Flag, name: "PAUSE loop exit", bit: 42} - - {type: Flag, name: "RDRAND exit", bit: 43} - - {type: Flag, name: "Enable INVPCID", bit: 44} - - {type: Flag, name: "Enable VMFUNC", bit: 45} - - {type: Flag, name: "VMCS shadow", bit: 46} - - {type: Flag, name: "ENCLS exit", bit: 47} - - {type: Flag, name: "RDSEED exit", bit: 48} - - {type: Flag, name: "Enable PML", bit: 49} - - {type: Flag, name: "EPT exceptions", bit: 50} - - {type: Flag, name: "VMX-PT conceal", bit: 51} - - {type: Flag, name: "Enable XSAVE", bit: 52} - - {type: Flag, name: "Mode EPT Ctrl", bit: 54} - - {type: Flag, name: "EPT Write Perm size", bit: 55} - - {type: Flag, name: "PT - Guest Addr", bit: 56} - - {type: Flag, name: "TSC scaling", bit: 57} - - {type: Flag, name: "User Wait", bit: 58} - - {type: Flag, name: "Enable Pconfig", bit: 59} - - {type: Flag, name: "ENCLV Exit", bit: 60} - - - name: "VMX: Proccessor Based Ctls 3" - address: 0x492 - fields: - - {type: Flag, name: "LOADIWKEY", bit: 0} - - {type: Flag, name: "Enable HLAT", bit: 1} - - {type: Flag, name: "EPT Write Ctrl", bit: 2} - - {type: Flag, name: "Guest Page Verify", bit: 3} diff --git a/src/hex.rs b/src/hex.rs new file mode 100644 index 0000000..2d1e9c9 --- /dev/null +++ b/src/hex.rs @@ -0,0 +1,170 @@ +//! Serde helpers so definition files can write CPUID leaves and MSR addresses in hex +//! +//! JSON has no hex literals, so hex values are written as strings such as `"0x80000001"`. +//! Decimal numbers and strings are also accepted, and `_` may be used as a digit separator +//! (`"0x8000_0001"`). Values below 10 read the same in either base, so they are written in decimal. + +use serde::de::{self, Deserialize, Deserializer}; +use serde::ser::Serializer; +use std::collections::BTreeMap; +use std::num::ParseIntError; + +/// Format a u32 the way definition files write it: decimal below 10, otherwise `0x` hex +pub fn format_u32(value: u32) -> String { + if value < 10 { + value.to_string() + } else { + format!("{:#x}", value) + } +} + +/// Parse a `0x`-prefixed hex or a decimal string into a u32 +pub fn parse_u32(text: &str) -> Result { + let digits = text.replace('_', ""); + match digits + .strip_prefix("0x") + .or_else(|| digits.strip_prefix("0X")) + { + Some(hex) => u32::from_str_radix(hex, 16), + None => digits.parse(), + } +} + +/// `#[serde(with = "hex::u32")]` for a u32 that may be written as a hex string or a number +pub mod u32 { + use super::*; + + #[derive(serde::Deserialize)] + #[serde(untagged)] + enum NumOrString { + Num(u32), + String(String), + } + + pub fn serialize(value: &u32, serializer: S) -> Result { + serializer.serialize_str(&format_u32(*value)) + } + + pub fn deserialize<'de, D: Deserializer<'de>>(deserializer: D) -> Result { + match NumOrString::deserialize(deserializer)? { + NumOrString::Num(value) => Ok(value), + NumOrString::String(text) => parse_u32(&text) + .map_err(|e| de::Error::custom(format!("invalid number {:?}: {}", text, e))), + } + } +} + +/// `#[serde(with = "hex::u32_map")]` for a `BTreeMap` whose keys may be hex strings +pub mod u32_map { + use super::*; + use serde::Serialize; + + pub fn serialize(map: &BTreeMap, serializer: S) -> Result + where + S: Serializer, + V: Serialize, + { + serializer.collect_map(map.iter().map(|(key, value)| (format_u32(*key), value))) + } + + pub fn deserialize<'de, D, V>(deserializer: D) -> Result, D::Error> + where + D: Deserializer<'de>, + V: Deserialize<'de>, + { + let raw: Vec<(String, V)> = + deserializer.deserialize_map(EntriesVisitor(Default::default()))?; + let mut map = BTreeMap::new(); + for (text, value) in raw { + let key = parse_u32(&text) + .map_err(|e| de::Error::custom(format!("invalid key {:?}: {}", text, e)))?; + // "0x7" and "7" are the same leaf; refuse rather than silently keep one + if map.insert(key, value).is_some() { + return Err(de::Error::custom(format!("duplicate key {:#x}", key))); + } + } + Ok(map) + } + + /// Collect map entries in order without merging duplicate keys + struct EntriesVisitor(std::marker::PhantomData); + + impl<'de, V: Deserialize<'de>> de::Visitor<'de> for EntriesVisitor { + type Value = Vec<(String, V)>; + + fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "a map keyed by hex or decimal numbers") + } + + fn visit_map>(self, mut access: A) -> Result { + let mut entries = Vec::new(); + while let Some(entry) = access.next_entry()? { + entries.push(entry); + } + Ok(entries) + } + } +} + +#[cfg(test)] +mod test { + use super::*; + use serde::{Deserialize, Serialize}; + + #[derive(Serialize, Deserialize, Debug, PartialEq)] + struct Sample { + #[serde(with = "u32_map")] + map: BTreeMap, + #[serde(with = "u32")] + address: u32, + } + + #[test] + fn parse_u32_formats() { + assert_eq!(parse_u32("0x10a"), Ok(0x10a)); + assert_eq!(parse_u32("0X10A"), Ok(0x10a)); + assert_eq!(parse_u32("0x8000_0001"), Ok(0x8000_0001)); + assert_eq!(parse_u32("266"), Ok(266)); + assert!(parse_u32("0x").is_err()); + assert!(parse_u32("0x1_0000_0000").is_err()); + assert!(parse_u32("ten").is_err()); + } + + #[test] + fn hex_and_decimal_inputs() { + let sample: Sample = + serde_json::from_str(r#"{"map": {"0x80000001": "a", "7": "b"}, "address": "0x48d"}"#) + .unwrap(); + assert_eq!(sample.map[&0x80000001], "a"); + assert_eq!(sample.map[&7], "b"); + assert_eq!(sample.address, 0x48d); + + let sample: Sample = serde_json::from_str(r#"{"map": {}, "address": 266}"#).unwrap(); + assert_eq!(sample.address, 0x10a); + } + + #[test] + fn rejects_bad_and_duplicate_keys() { + assert!(serde_json::from_str::(r#"{"map": {"0xzz": "a"}, "address": 0}"#).is_err()); + let err = + serde_json::from_str::(r#"{"map": {"0x7": "a", "7": "b"}, "address": 0}"#) + .unwrap_err(); + assert!(err.to_string().contains("duplicate key 0x7"), "{}", err); + } + + #[test] + fn serializes_small_decimal_else_hex() { + assert_eq!(format_u32(0), "0"); + assert_eq!(format_u32(9), "9"); + assert_eq!(format_u32(10), "0xa"); + assert_eq!(format_u32(0x80000001), "0x80000001"); + + let sample = Sample { + map: BTreeMap::from([(7, "b".to_string()), (0xd, "c".to_string())]), + address: 0x10a, + }; + let text = serde_json::to_string(&sample).unwrap(); + assert_eq!(text, r#"{"map":{"7":"b","0xd":"c"},"address":"0x10a"}"#); + assert_eq!(serde_json::from_str::(&text).unwrap(), sample); + } +} diff --git a/src/lib.rs b/src/lib.rs index e7c3e16..087ee32 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -3,6 +3,7 @@ use enum_dispatch::enum_dispatch; pub mod bitfield; pub mod facts; +pub mod hex; pub mod layout; pub mod msr; diff --git a/src/main.rs b/src/main.rs index c8197ce..921d78b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -16,8 +16,8 @@ use std::error::Error; use std::fmt; use std::path::{Path, PathBuf}; -type YAMLFact = GenericFact; -type YAMLFactSet = FactSet; +type JsonFact = GenericFact; +type JsonFactSet = FactSet; #[enum_dispatch()] trait Command { @@ -132,7 +132,6 @@ impl Command for Disp { #[derive(Clone, PartialEq, Eq, ValueEnum)] enum FactsOutput { - Yaml, Json, } @@ -143,7 +142,7 @@ struct Facts { #[cfg(all(target_os = "linux", feature = "kvm"))] #[arg(short, long)] use_kvm: bool, - #[arg(short, long, value_enum, default_value = "yaml")] + #[arg(short, long, value_enum, default_value = "json")] out_type: FactsOutput, } @@ -151,8 +150,8 @@ fn collect_facts( config: &Definition, cpuid_selected: CpuidType, msr_store: Box, -) -> Result, Box> { - let mut ret: Vec = config +) -> Result, Box> { + let mut ret: Vec = config .cpuids .iter() .filter_map(|(leaf, desc)| desc.bind_leaf(*leaf, &cpuid_selected)) @@ -237,7 +236,6 @@ impl Command for Facts { println!( "{}", match self.out_type { - FactsOutput::Yaml => serde_yaml::to_string(&facts)?, FactsOutput::Json => serde_json::to_string(&facts)?, } ); @@ -245,16 +243,16 @@ impl Command for Facts { } } -fn read_facts_from_file(fname: &str) -> Result, Box> { +fn read_facts_from_file(fname: &str) -> Result, Box> { let file = std::fs::File::open(fname)?; - Ok(serde_yaml::from_reader(file)?) + Ok(serde_json::from_reader(file)?) } #[derive(Serialize, Debug)] struct DiffOutput { - added: Vec, - removed: Vec, - changed: Vec<(YAMLFact, YAMLFact)>, + added: Vec, + removed: Vec, + changed: Vec<(JsonFact, JsonFact)>, } impl DiffOutput { @@ -276,7 +274,7 @@ impl DiffFoundError { impl fmt::Display for DiffFoundError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let as_yaml = serde_yaml::to_string(&self.inner).map_err(|_| std::fmt::Error {})?; + let as_yaml = serde_json::to_string(&self.inner).map_err(|_| std::fmt::Error {})?; write!(f, "{}", as_yaml) } } @@ -293,8 +291,8 @@ struct Diff { impl Command for Diff { fn run(&self, _config: &Definition) -> Result<(), Box> { - let from: YAMLFactSet = read_facts_from_file(&self.from_file_name)?.into(); - let to: YAMLFactSet = read_facts_from_file(&self.to_file_name)?.into(); + let from: JsonFactSet = read_facts_from_file(&self.from_file_name)?.into(); + let to: JsonFactSet = read_facts_from_file(&self.to_file_name)?.into(); let output = DiffOutput { added: from.added_facts(&to).map(Clone::clone).collect(), @@ -307,11 +305,11 @@ impl Command for Diff { if output.is_empty() { if self.verbose { - println!("{}", serde_yaml::to_string(&output)?); + println!("{}", serde_json::to_string(&output)?); } Ok(()) } else { - println!("{}", serde_yaml::to_string(&output)?); + println!("{}", serde_json::to_string(&output)?); Err(DiffFoundError::new(output).into()) } } @@ -319,6 +317,7 @@ impl Command for Diff { #[derive(Serialize, Deserialize, Debug)] struct Definition { + #[serde(with = "cpuinfo::hex::u32_map")] pub cpuids: BTreeMap, pub msrs: Vec, } @@ -335,8 +334,8 @@ impl Definition { } fn find_read_config() -> Result> { - let file = include_str!("config.yaml"); - Ok(serde_yaml::from_str(file)?) + let file = include_str!("config.json"); + Ok(serde_json::from_str(file)?) } fn display_raw() -> Result<(), Box> { @@ -369,7 +368,7 @@ where { for path in paths { let file = std::fs::read(path)?; - let definition = serde_yaml::from_slice(&file)?; + let definition = serde_json::from_slice(&file)?; def.union(definition); } Ok(()) @@ -391,3 +390,13 @@ fn main() -> Result<(), Box> { args.command.run(&config) } + +#[cfg(test)] +mod test { + #[test] + fn builtin_config_parses() { + let config = super::find_read_config().expect("src/config.json must parse"); + assert!(config.cpuids.contains_key(&0x8000_0008)); + assert!(config.msrs.iter().any(|msr| msr.address == 0x10a)); + } +} diff --git a/src/msr.rs b/src/msr.rs index 2a2cfb0..14708f8 100644 --- a/src/msr.rs +++ b/src/msr.rs @@ -99,6 +99,7 @@ pub mod linux { #[derive(Serialize, Deserialize, Debug, Clone)] pub struct MSRDesc { pub name: String, + #[serde(with = "crate::hex::u32")] pub address: u32, pub fields: Vec, }