From 165eee2248e21b2506f16c82d7aed2977a841638 Mon Sep 17 00:00:00 2001 From: myadav Date: Tue, 25 Feb 2025 17:26:09 -0500 Subject: [PATCH 01/17] fix access issue to devconatiner Signed-off-by: myadav Signed-off-by: Manoj Kumar Yadav --- .devcontainer/devcontainer.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 6db35bc47..5e9a31284 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,6 +20,9 @@ // Use 'postCreateCommand' to run commands after the container is created "postCreateCommand": "bash .devcontainer/setup.sh", + // Runs each time the container starts/restarts + // Only run these commands if /dev/kvm exists + "postStartCommand": "if [ -e /dev/kvm ]; then sudo chown root:kvm /dev/kvm && sudo chmod 660 /dev/kvm && sudo usermod -aG kvm vscode; else echo 'KVM device not found, skipping...'; fi", "customizations": { "vscode": { "extensions": [ From 2d61f66359d76a86759c651fb674b263d0f07500 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:21:39 -0800 Subject: [PATCH 02/17] Bump cc from 1.2.14 to 1.2.15 (#281) Bumps [cc](https://github.com/rust-lang/cc-rs) from 1.2.14 to 1.2.15. - [Release notes](https://github.com/rust-lang/cc-rs/releases) - [Changelog](https://github.com/rust-lang/cc-rs/blob/main/CHANGELOG.md) - [Commits](https://github.com/rust-lang/cc-rs/compare/cc-v1.2.14...cc-v1.2.15) --- updated-dependencies: - dependency-name: cc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index f0cfc39f3..bd5625b20 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -351,9 +351,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.14" +version = "1.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3d1b2e905a3a7b00a6141adb0e4c0bb941d11caf55349d863942a1cc44e3c9" +checksum = "c736e259eea577f443d5c86c304f9f4ae0295c43f3ba05c21f1d66b5f06001af" dependencies = [ "jobserver", "libc", From d74f8cedc0eea250854625c1f5a6f6dd78a80329 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:21:58 -0800 Subject: [PATCH 03/17] Bump serde_json from 1.0.138 to 1.0.139 (#279) Bumps [serde_json](https://github.com/serde-rs/json) from 1.0.138 to 1.0.139. - [Release notes](https://github.com/serde-rs/json/releases) - [Commits](https://github.com/serde-rs/json/compare/v1.0.138...v1.0.139) --- updated-dependencies: - dependency-name: serde_json dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bd5625b20..4a27c426c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2488,9 +2488,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.138" +version = "1.0.139" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d434192e7da787e94a6ea7e9670b26a036d0ca41e0b7efb2676dd32bae872949" +checksum = "44f86c3acccc9c65b153fe1b85a3be07fe5515274ec9f0653b4a0875731c72a6" dependencies = [ "itoa", "memchr", From c802547bb5aa0f38cf8f587f7f44b30d14769144 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:22:24 -0800 Subject: [PATCH 04/17] Bump anyhow from 1.0.95 to 1.0.96 (#277) Bumps [anyhow](https://github.com/dtolnay/anyhow) from 1.0.95 to 1.0.96. - [Release notes](https://github.com/dtolnay/anyhow/releases) - [Commits](https://github.com/dtolnay/anyhow/compare/1.0.95...1.0.96) --- updated-dependencies: - dependency-name: anyhow dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 4 ++-- src/hyperlight_common/Cargo.toml | 2 +- src/hyperlight_guest/Cargo.toml | 2 +- src/hyperlight_host/Cargo.toml | 2 +- src/hyperlight_testing/Cargo.toml | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4a27c426c..2e7fc2efb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -98,9 +98,9 @@ dependencies = [ [[package]] name = "anyhow" -version = "1.0.95" +version = "1.0.96" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34ac096ce696dc2fcabef30516bb13c0a68a11d30131d3df6f04711467681b04" +checksum = "6b964d184e89d9b6b67dd2715bc8e74cf3107fb2b529990c90cf517326150bf4" [[package]] name = "arbitrary" diff --git a/src/hyperlight_common/Cargo.toml b/src/hyperlight_common/Cargo.toml index f33476829..772bdc15d 100644 --- a/src/hyperlight_common/Cargo.toml +++ b/src/hyperlight_common/Cargo.toml @@ -16,7 +16,7 @@ workspace = true [dependencies] flatbuffers = { version = "25.2.10", default-features = false } -anyhow = { version = "1.0.95", default-features = false } +anyhow = { version = "1.0.96", default-features = false } log = "0.4.25" tracing = { version = "0.1.41", optional = true } strum = {version = "0.27", default-features = false, features = ["derive"]} diff --git a/src/hyperlight_guest/Cargo.toml b/src/hyperlight_guest/Cargo.toml index d73f90445..67d779a74 100644 --- a/src/hyperlight_guest/Cargo.toml +++ b/src/hyperlight_guest/Cargo.toml @@ -18,7 +18,7 @@ libc = [] # compile musl libc printf = [] # compile printf [dependencies] -anyhow = { version = "1.0.95", default-features = false } +anyhow = { version = "1.0.96", default-features = false } serde_json = { version = "1.0", default-features = false, features = ["alloc"] } buddy_system_allocator = "0.11.0" hyperlight-common = { workspace = true } diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index 8440c2c13..91653ac8a 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -114,7 +114,7 @@ windows = { version = "0.59", features = [ proc-maps = "0.4.0" [build-dependencies] -anyhow = { version = "1.0.95" } +anyhow = { version = "1.0.96" } cfg_aliases = "0.2.1" built = { version = "0.7.7", features = ["chrono", "git2"] } diff --git a/src/hyperlight_testing/Cargo.toml b/src/hyperlight_testing/Cargo.toml index 0abd20c96..37bba1c37 100644 --- a/src/hyperlight_testing/Cargo.toml +++ b/src/hyperlight_testing/Cargo.toml @@ -3,7 +3,7 @@ name = "hyperlight-testing" edition = "2021" [dependencies] -anyhow = "1.0.95" +anyhow = "1.0.96" log = "0.4" once_cell = "1.20" tracing = { version = "0.1.41", features = ["log"] } From a098630534fb5b58a0173a98aaa107af759d7568 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:22:42 -0800 Subject: [PATCH 05/17] Bump uuid from 1.13.2 to 1.14.0 (#276) Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.13.2 to 1.14.0. - [Release notes](https://github.com/uuid-rs/uuid/releases) - [Commits](https://github.com/uuid-rs/uuid/compare/v1.13.2...v1.14.0) --- updated-dependencies: - dependency-name: uuid dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 4 ++-- src/hyperlight_host/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2e7fc2efb..fdedf73c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3147,9 +3147,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.13.2" +version = "1.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8c1f41ffb7cf259f1ecc2876861a17e7142e63ead296f671f81f6ae85903e0d6" +checksum = "93d59ca99a559661b96bf898d8fce28ed87935fd2bea9f05983c1464dd6c71b1" dependencies = [ "getrandom 0.3.1", "serde", diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index 91653ac8a..9996ca36e 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -82,7 +82,7 @@ mshv-bindings3 = { package="mshv-bindings", version = "0.3.2", optional = true } mshv-ioctls3 = { package="mshv-ioctls", version = "0.3.2", optional = true} [dev-dependencies] -uuid = { version = "1.13.2", features = ["v4"] } +uuid = { version = "1.14.0", features = ["v4"] } signal-hook-registry = "1.4.1" envy = { version = "0.4.2" } serde = "1.0" From 70d63cce3c38588696ca9def32d61c4622c3e074 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:54:28 -0800 Subject: [PATCH 06/17] Bump serde from 1.0.217 to 1.0.218 (#278) Bumps [serde](https://github.com/serde-rs/serde) from 1.0.217 to 1.0.218. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.217...v1.0.218) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fdedf73c4..10cacc4c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2468,18 +2468,18 @@ checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.217" +version = "1.0.218" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02fc4265df13d6fa1d00ecff087228cc0a2b5f3c0e87e258d8b94a156e984c70" +checksum = "e8dfc9d19bdbf6d17e22319da49161d5d0108e4188e8b680aef6299eed22df60" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.217" +version = "1.0.218" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a9bf7cf98d04a2b28aead066b7496853d4779c9cc183c440dbac457641e19a0" +checksum = "f09503e191f4e797cb8aac08e9a4a4695c5edf6a2e70e376d961ddd5c969f82b" dependencies = [ "proc-macro2", "quote", From f3806a558abbe1db74e84766828badb6d73911dc Mon Sep 17 00:00:00 2001 From: Simon Davies Date: Thu, 27 Feb 2025 08:59:47 +0000 Subject: [PATCH 07/17] Fix mshv crate version to 0.3.2 (#290) Signed-off-by: Simon Davies Signed-off-by: Manoj Kumar Yadav --- src/hyperlight_host/Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index 9996ca36e..a063b56dc 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -78,8 +78,8 @@ kvm-bindings = { version = "0.11", features = ["fam-wrappers"], optional = true kvm-ioctls = { version = "0.20", optional = true } mshv-bindings2 = { package="mshv-bindings", version = "=0.2.1", optional = true } mshv-ioctls2 = { package="mshv-ioctls", version = "=0.2.1", optional = true} -mshv-bindings3 = { package="mshv-bindings", version = "0.3.2", optional = true } -mshv-ioctls3 = { package="mshv-ioctls", version = "0.3.2", optional = true} +mshv-bindings3 = { package="mshv-bindings", version = "=0.3.2", optional = true } +mshv-ioctls3 = { package="mshv-ioctls", version = "=0.3.2", optional = true} [dev-dependencies] uuid = { version = "1.14.0", features = ["v4"] } From 23eba2052fced5804bef621093eadf850b314b73 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Feb 2025 20:48:41 +0000 Subject: [PATCH 08/17] Bump windows-version from 0.1.2 to 0.1.3 (#296) Bumps [windows-version](https://github.com/microsoft/windows-rs) from 0.1.2 to 0.1.3. - [Release notes](https://github.com/microsoft/windows-rs/releases) - [Commits](https://github.com/microsoft/windows-rs/commits) --- updated-dependencies: - dependency-name: windows-version dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 10cacc4c4..d9f92b9db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3398,6 +3398,12 @@ dependencies = [ "syn", ] +[[package]] +name = "windows-link" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dccfd733ce2b1753b03b6d3c65edf020262ea35e20ccdf3e288043e6dd620e3" + [[package]] name = "windows-registry" version = "0.2.0" @@ -3522,11 +3528,11 @@ dependencies = [ [[package]] name = "windows-version" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c12476c23a74725c539b24eae8bfc0dac4029c39cdb561d9f23616accd4ae26d" +checksum = "7bfbcc4996dd183ff1376a20ade1242da0d2dcaff83cc76710a588d24fd4c5db" dependencies = [ - "windows-targets 0.53.0", + "windows-link", ] [[package]] From 3ab22a6243a4a00f2fac6f6efcf86a46fc51314c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Feb 2025 20:48:54 +0000 Subject: [PATCH 09/17] Bump libc from 0.2.169 to 0.2.170 (#295) Bumps [libc](https://github.com/rust-lang/libc) from 0.2.169 to 0.2.170. - [Release notes](https://github.com/rust-lang/libc/releases) - [Changelog](https://github.com/rust-lang/libc/blob/0.2.170/CHANGELOG.md) - [Commits](https://github.com/rust-lang/libc/compare/0.2.169...0.2.170) --- updated-dependencies: - dependency-name: libc dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 4 ++-- src/hyperlight_host/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d9f92b9db..072003afa 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1494,9 +1494,9 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] name = "libc" -version = "0.2.169" +version = "0.2.170" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" +checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" [[package]] name = "libfuzzer-sys" diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index a063b56dc..8f101c858 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -24,7 +24,7 @@ workspace = true goblin = { version = "0.9" } rand = { version = "0.9" } cfg-if = { version = "1.0.0" } -libc = { version = "0.2.169" } +libc = { version = "0.2.170" } paste = "1.0" flatbuffers = "25.2.10" page_size = "0.6.0" From 20e74951292c743e3d8e86b48a34ad5eaf3411e3 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Feb 2025 20:49:09 +0000 Subject: [PATCH 10/17] Bump uuid from 1.14.0 to 1.15.1 (#294) Bumps [uuid](https://github.com/uuid-rs/uuid) from 1.14.0 to 1.15.1. - [Release notes](https://github.com/uuid-rs/uuid/releases) - [Commits](https://github.com/uuid-rs/uuid/compare/v1.14.0...v1.15.1) --- updated-dependencies: - dependency-name: uuid dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 4 ++-- src/hyperlight_host/Cargo.toml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 072003afa..961870175 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3147,9 +3147,9 @@ checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821" [[package]] name = "uuid" -version = "1.14.0" +version = "1.15.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "93d59ca99a559661b96bf898d8fce28ed87935fd2bea9f05983c1464dd6c71b1" +checksum = "e0f540e3240398cce6128b64ba83fdbdd86129c16a3aa1a3a252efd66eb3d587" dependencies = [ "getrandom 0.3.1", "serde", diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index 8f101c858..28f7f974b 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -82,7 +82,7 @@ mshv-bindings3 = { package="mshv-bindings", version = "=0.3.2", optional = true mshv-ioctls3 = { package="mshv-ioctls", version = "=0.3.2", optional = true} [dev-dependencies] -uuid = { version = "1.14.0", features = ["v4"] } +uuid = { version = "1.15.1", features = ["v4"] } signal-hook-registry = "1.4.1" envy = { version = "0.4.2" } serde = "1.0" From d159c93f032f07b4347fd0b1e889a07edf89caf6 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Feb 2025 20:49:34 +0000 Subject: [PATCH 11/17] Bump crate-ci/typos from 1.29.7 to 1.29.10 (#289) Bumps [crate-ci/typos](https://github.com/crate-ci/typos) from 1.29.7 to 1.29.10. - [Release notes](https://github.com/crate-ci/typos/releases) - [Changelog](https://github.com/crate-ci/typos/blob/master/CHANGELOG.md) - [Commits](https://github.com/crate-ci/typos/compare/v1.29.7...v1.29.10) --- updated-dependencies: - dependency-name: crate-ci/typos dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- .github/workflows/ValidatePullRequest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ValidatePullRequest.yml b/.github/workflows/ValidatePullRequest.yml index 3bd524abb..0380813fa 100644 --- a/.github/workflows/ValidatePullRequest.yml +++ b/.github/workflows/ValidatePullRequest.yml @@ -64,4 +64,4 @@ jobs: steps: - uses: actions/checkout@v4 - name: Spell Check Repo - uses: crate-ci/typos@v1.29.7 + uses: crate-ci/typos@v1.29.10 From 7215c1303a1d3bb46e353b4237330f93d3db974d Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 27 Feb 2025 22:08:54 +0000 Subject: [PATCH 12/17] Bump log from 0.4.25 to 0.4.26 (#292) Bumps [log](https://github.com/rust-lang/log) from 0.4.25 to 0.4.26. - [Release notes](https://github.com/rust-lang/log/releases) - [Changelog](https://github.com/rust-lang/log/blob/master/CHANGELOG.md) - [Commits](https://github.com/rust-lang/log/compare/0.4.25...0.4.26) --- updated-dependencies: - dependency-name: log dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Signed-off-by: Manoj Kumar Yadav --- Cargo.lock | 4 ++-- src/hyperlight_common/Cargo.toml | 2 +- src/hyperlight_host/Cargo.toml | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 961870175..d468216cb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1587,9 +1587,9 @@ dependencies = [ [[package]] name = "log" -version = "0.4.25" +version = "0.4.26" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04cbf5b083de1c7e0222a7a51dbfdba1cbe1c6ab0b15e29fff3f6c077fd9cd9f" +checksum = "30bde2b3dc3671ae49d8e2e9f044c7c005836e7a023ee57cffa25ab82764bb9e" [[package]] name = "mach2" diff --git a/src/hyperlight_common/Cargo.toml b/src/hyperlight_common/Cargo.toml index 772bdc15d..3fb04a1a5 100644 --- a/src/hyperlight_common/Cargo.toml +++ b/src/hyperlight_common/Cargo.toml @@ -17,7 +17,7 @@ workspace = true [dependencies] flatbuffers = { version = "25.2.10", default-features = false } anyhow = { version = "1.0.96", default-features = false } -log = "0.4.25" +log = "0.4.26" tracing = { version = "0.1.41", optional = true } strum = {version = "0.27", default-features = false, features = ["derive"]} diff --git a/src/hyperlight_host/Cargo.toml b/src/hyperlight_host/Cargo.toml index 28f7f974b..70003e9c3 100644 --- a/src/hyperlight_host/Cargo.toml +++ b/src/hyperlight_host/Cargo.toml @@ -33,7 +33,7 @@ bitflags = "2.8.0" lazy_static = "1.4.0" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -log = "0.4.25" +log = "0.4.26" once_cell = { version = "1.20.3" } tracing = { version = "0.1.41", features = ["log"] } tracing-log = "0.2.0" From c06b052230f96ee0856c1e32a86704e95ce87264 Mon Sep 17 00:00:00 2001 From: Ludvig Liljenberg Date: Fri, 28 Feb 2025 10:15:44 -0800 Subject: [PATCH 13/17] Generic guest/host result API (#259) * Make `get_flatbuffer_result` generic Signed-off-by: Ludvig Liljenberg * Make `get_host_value_return_as` generic Signed-off-by: Ludvig Liljenberg * fix broken rebase Signed-off-by: Ludvig Liljenberg --------- Signed-off-by: Ludvig Liljenberg Signed-off-by: Manoj Kumar Yadav --- .../src/flatbuffer_wrappers/util.rs | 223 ++++++++++-------- .../src/host_function_call.rs | 103 ++------ src/hyperlight_guest_capi/src/flatbuffer.rs | 39 ++- .../rust_guests/callbackguest/src/main.rs | 16 +- src/tests/rust_guests/simpleguest/src/main.rs | 77 +++--- 5 files changed, 191 insertions(+), 267 deletions(-) diff --git a/src/hyperlight_common/src/flatbuffer_wrappers/util.rs b/src/hyperlight_common/src/flatbuffer_wrappers/util.rs index e1e4917c7..184da6afe 100644 --- a/src/hyperlight_common/src/flatbuffer_wrappers/util.rs +++ b/src/hyperlight_common/src/flatbuffer_wrappers/util.rs @@ -16,12 +16,13 @@ limitations under the License. use alloc::vec::Vec; -use flatbuffers::{FlatBufferBuilder, UnionWIPOffset, WIPOffset}; +use flatbuffers::FlatBufferBuilder; use crate::flatbuffers::hyperlight::generated::{ - hldouble as Fbhldouble, hldoubleArgs as FbhldoubleArgs, hlfloat as Fbhlfloat, - hlfloatArgs as FbhlfloatArgs, hlint as Fbhlint, hlintArgs as FbhlintArgs, hllong as Fbhllong, - hllongArgs as FbhllongArgs, hlsizeprefixedbuffer as Fbhlsizeprefixedbuffer, + hlbool as Fbhlbool, hlboolArgs as FbhlboolArgs, hldouble as Fbhldouble, + hldoubleArgs as FbhldoubleArgs, hlfloat as Fbhlfloat, hlfloatArgs as FbhlfloatArgs, + hlint as Fbhlint, hlintArgs as FbhlintArgs, hllong as Fbhllong, hllongArgs as FbhllongArgs, + hlsizeprefixedbuffer as Fbhlsizeprefixedbuffer, hlsizeprefixedbufferArgs as FbhlsizeprefixedbufferArgs, hlstring as Fbhlstring, hlstringArgs as FbhlstringArgs, hluint as Fbhluint, hluintArgs as FbhluintArgs, hlulong as Fbhlulong, hlulongArgs as FbhlulongArgs, hlvoid as Fbhlvoid, @@ -29,128 +30,142 @@ use crate::flatbuffers::hyperlight::generated::{ FunctionCallResultArgs as FbFunctionCallResultArgs, ReturnValue as FbReturnValue, }; -pub fn get_flatbuffer_result_from_double(value: f64) -> Vec { +/// Flatbuffer-encodes the given value +pub fn get_flatbuffer_result(val: T) -> Vec { let mut builder = FlatBufferBuilder::new(); - let hldouble = Fbhldouble::create(&mut builder, &FbhldoubleArgs { value }); + let res = &T::serialize(&val, &mut builder); + let result_offset = FbFunctionCallResult::create(&mut builder, res); - let rt = FbReturnValue::hldouble; - let rv: Option> = Some(hldouble.as_union_value()); + builder.finish_size_prefixed(result_offset, None); - get_flatbuffer_result(&mut builder, rt, rv) + builder.finished_data().to_vec() } -pub fn get_flatbuffer_result_from_float(value: f32) -> Vec { - let mut builder = FlatBufferBuilder::new(); - let hlfloat = Fbhlfloat::create(&mut builder, &FbhlfloatArgs { value }); - - let rt = FbReturnValue::hlfloat; - let rv: Option> = Some(hlfloat.as_union_value()); - - get_flatbuffer_result(&mut builder, rt, rv) +pub trait FlatbufferSerializable { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs; } -pub fn get_flatbuffer_result_from_int(value: i32) -> Vec { - let mut builder = FlatBufferBuilder::new(); - let hlint = Fbhlint::create(&mut builder, &FbhlintArgs { value }); - - let rt = FbReturnValue::hlint; - let rv: Option> = Some(hlint.as_union_value()); +/// Implementations for basic types below - get_flatbuffer_result(&mut builder, rt, rv) +impl FlatbufferSerializable for () { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some(Fbhlvoid::create(builder, &FbhlvoidArgs {}).as_union_value()), + return_value_type: FbReturnValue::hlvoid, + } + } } -pub fn get_flatbuffer_result_from_uint(value: u32) -> Vec { - let mut builder = FlatBufferBuilder::new(); - let hluint = Fbhluint::create(&mut builder, &FbhluintArgs { value }); - - let rt = FbReturnValue::hluint; - let rv: Option> = Some(hluint.as_union_value()); - - get_flatbuffer_result(&mut builder, rt, rv) +impl FlatbufferSerializable for &str { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + let string_offset = builder.create_string(self); + FbFunctionCallResultArgs { + return_value: Some( + Fbhlstring::create( + builder, + &FbhlstringArgs { + value: Some(string_offset), + }, + ) + .as_union_value(), + ), + return_value_type: FbReturnValue::hlstring, + } + } } -pub fn get_flatbuffer_result_from_long(value: i64) -> Vec { - let mut builder = FlatBufferBuilder::new(); - let hllong = Fbhllong::create(&mut builder, &FbhllongArgs { value }); - - let rt = FbReturnValue::hllong; - let rv: Option> = Some(hllong.as_union_value()); - - get_flatbuffer_result(&mut builder, rt, rv) +impl FlatbufferSerializable for &[u8] { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + let vec_offset = builder.create_vector(self); + FbFunctionCallResultArgs { + return_value: Some( + Fbhlsizeprefixedbuffer::create( + builder, + &FbhlsizeprefixedbufferArgs { + size_: self.len() as i32, + value: Some(vec_offset), + }, + ) + .as_union_value(), + ), + return_value_type: FbReturnValue::hlsizeprefixedbuffer, + } + } } -pub fn get_flatbuffer_result_from_ulong(value: u64) -> Vec { - let mut builder = FlatBufferBuilder::new(); - let hlulong = Fbhlulong::create(&mut builder, &FbhlulongArgs { value }); - - let rt = FbReturnValue::hlulong; - let rv: Option> = Some(hlulong.as_union_value()); - - get_flatbuffer_result(&mut builder, rt, rv) +impl FlatbufferSerializable for f32 { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some( + Fbhlfloat::create(builder, &FbhlfloatArgs { value: *self }).as_union_value(), + ), + return_value_type: FbReturnValue::hlfloat, + } + } } -pub fn get_flatbuffer_result_from_void() -> Vec { - let mut builder = FlatBufferBuilder::new(); - let hlvoid = Fbhlvoid::create(&mut builder, &FbhlvoidArgs {}); - - let rt = FbReturnValue::hlvoid; - let rv: Option> = Some(hlvoid.as_union_value()); - - get_flatbuffer_result(&mut builder, rt, rv) +impl FlatbufferSerializable for f64 { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some( + Fbhldouble::create(builder, &FbhldoubleArgs { value: *self }).as_union_value(), + ), + return_value_type: FbReturnValue::hldouble, + } + } } -pub fn get_flatbuffer_result_from_string(value: &str) -> Vec { - let mut builder = FlatBufferBuilder::new(); - - let string_offset = builder.create_string(value); - let hlstring = Fbhlstring::create( - &mut builder, - &FbhlstringArgs { - value: Some(string_offset), - }, - ); - - let rt = FbReturnValue::hlstring; - let rv: Option> = Some(hlstring.as_union_value()); - - get_flatbuffer_result(&mut builder, rt, rv) +impl FlatbufferSerializable for i32 { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some( + Fbhlint::create(builder, &FbhlintArgs { value: *self }).as_union_value(), + ), + return_value_type: FbReturnValue::hlint, + } + } } -pub fn get_flatbuffer_result_from_vec(data: &[u8]) -> Vec { - let mut builder = FlatBufferBuilder::new(); - - let vec_offset = builder.create_vector(data); - - let hlsizeprefixedbuffer = Fbhlsizeprefixedbuffer::create( - &mut builder, - &FbhlsizeprefixedbufferArgs { - size_: data.len() as i32, - value: Some(vec_offset), - }, - ); - - // Indicate that the return value is a size-prefixed buffer. - let rt = FbReturnValue::hlsizeprefixedbuffer; - let rv: Option> = Some(hlsizeprefixedbuffer.as_union_value()); - - // Get the FlatBuffer result. - get_flatbuffer_result(&mut builder, rt, rv) +impl FlatbufferSerializable for i64 { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some( + Fbhllong::create(builder, &FbhllongArgs { value: *self }).as_union_value(), + ), + return_value_type: FbReturnValue::hllong, + } + } } -fn get_flatbuffer_result( - builder: &mut FlatBufferBuilder, - return_value_type: FbReturnValue, - return_value: Option>, -) -> Vec { - let result_offset = FbFunctionCallResult::create( - builder, - &FbFunctionCallResultArgs { - return_value, - return_value_type, - }, - ); +impl FlatbufferSerializable for u32 { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some( + Fbhluint::create(builder, &FbhluintArgs { value: *self }).as_union_value(), + ), + return_value_type: FbReturnValue::hluint, + } + } +} - builder.finish_size_prefixed(result_offset, None); +impl FlatbufferSerializable for u64 { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some( + Fbhlulong::create(builder, &FbhlulongArgs { value: *self }).as_union_value(), + ), + return_value_type: FbReturnValue::hlulong, + } + } +} - builder.finished_data().to_vec() +impl FlatbufferSerializable for bool { + fn serialize(&self, builder: &mut FlatBufferBuilder) -> FbFunctionCallResultArgs { + FbFunctionCallResultArgs { + return_value: Some( + Fbhlbool::create(builder, &FbhlboolArgs { value: *self }).as_union_value(), + ), + return_value_type: FbReturnValue::hlbool, + } + } } diff --git a/src/hyperlight_guest/src/host_function_call.rs b/src/hyperlight_guest/src/host_function_call.rs index f5e96a7ba..c5a496c8c 100644 --- a/src/hyperlight_guest/src/host_function_call.rs +++ b/src/hyperlight_guest/src/host_function_call.rs @@ -14,6 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ +use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; use core::arch::global_asm; @@ -23,7 +24,7 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{ ParameterValue, ReturnType, ReturnValue, }; use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode; -use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result_from_int; +use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result; use hyperlight_common::mem::RunMode; use crate::error::{HyperlightGuestError, Result}; @@ -39,94 +40,20 @@ pub enum OutBAction { Abort = 102, } -pub fn get_host_value_return_as_void() -> Result<()> { +/// Get a return value from a host function call. +/// This usually requires a host function to be called first using `call_host_function`. +pub fn get_host_return_value>() -> Result { let return_value = try_pop_shared_input_data_into::() .expect("Unable to deserialize a return value from host"); - if let ReturnValue::Void = return_value { - Ok(()) - } else { - Err(HyperlightGuestError::new( - ErrorCode::GuestError, - "Host return value was not void as expected".to_string(), - )) - } -} - -pub fn get_host_value_return_as_int() -> Result { - let return_value = try_pop_shared_input_data_into::() - .expect("Unable to deserialize return value from host"); - - // check that return value is an int and return - if let ReturnValue::Int(i) = return_value { - Ok(i) - } else { - Err(HyperlightGuestError::new( - ErrorCode::GuestError, - "Host return value was not an int as expected".to_string(), - )) - } -} - -pub fn get_host_value_return_as_uint() -> Result { - let return_value = try_pop_shared_input_data_into::() - .expect("Unable to deserialize return value from host"); - - // check that return value is an int and return - if let ReturnValue::UInt(ui) = return_value { - Ok(ui) - } else { - Err(HyperlightGuestError::new( - ErrorCode::GuestError, - "Host return value was not a uint as expected".to_string(), - )) - } -} - -pub fn get_host_value_return_as_long() -> Result { - let return_value = try_pop_shared_input_data_into::() - .expect("Unable to deserialize return value from host"); - - // check that return value is an int and return - if let ReturnValue::Long(l) = return_value { - Ok(l) - } else { - Err(HyperlightGuestError::new( - ErrorCode::GuestError, - "Host return value was not a long as expected".to_string(), - )) - } -} - -pub fn get_host_value_return_as_ulong() -> Result { - let return_value = try_pop_shared_input_data_into::() - .expect("Unable to deserialize return value from host"); - - // check that return value is an int and return - if let ReturnValue::ULong(ul) = return_value { - Ok(ul) - } else { - Err(HyperlightGuestError::new( + T::try_from(return_value).map_err(|_| { + HyperlightGuestError::new( ErrorCode::GuestError, - "Host return value was not a ulong as expected".to_string(), - )) - } -} - -// TODO: Make this generic, return a Result - -pub fn get_host_value_return_as_vecbytes() -> Result> { - let return_value = try_pop_shared_input_data_into::() - .expect("Unable to deserialize return value from host"); - - // check that return value is an Vec and return - if let ReturnValue::VecBytes(v) = return_value { - Ok(v) - } else { - Err(HyperlightGuestError::new( - ErrorCode::GuestError, - "Host return value was not an VecBytes as expected".to_string(), - )) - } + format!( + "Host return value was not a {} as expected", + core::any::type_name::() + ), + ) + }) } // TODO: Make this generic, return a Result this should allow callers to call this function and get the result type they expect @@ -194,8 +121,8 @@ pub fn print_output_as_guest_function(function_call: &FunctionCall) -> Result()?; + Ok(get_flatbuffer_result(res_i)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestError, diff --git a/src/hyperlight_guest_capi/src/flatbuffer.rs b/src/hyperlight_guest_capi/src/flatbuffer.rs index 43434c55a..33cfdbb4b 100644 --- a/src/hyperlight_guest_capi/src/flatbuffer.rs +++ b/src/hyperlight_guest_capi/src/flatbuffer.rs @@ -1,17 +1,8 @@ use alloc::boxed::Box; use core::ffi::{c_char, CStr}; -use hyperlight_common::flatbuffer_wrappers::util::{ - get_flatbuffer_result_from_double, get_flatbuffer_result_from_float, - get_flatbuffer_result_from_int, get_flatbuffer_result_from_long, - get_flatbuffer_result_from_string, get_flatbuffer_result_from_uint, - get_flatbuffer_result_from_ulong, get_flatbuffer_result_from_vec, - get_flatbuffer_result_from_void, -}; -use hyperlight_guest::host_function_call::{ - get_host_value_return_as_int, get_host_value_return_as_long, get_host_value_return_as_uint, - get_host_value_return_as_ulong, -}; +use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result; +use hyperlight_guest::host_function_call::get_host_return_value; use crate::types::FfiVec; @@ -21,49 +12,49 @@ use crate::types::FfiVec; #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_Int(value: i32) -> Box { - let vec = get_flatbuffer_result_from_int(value); + let vec = get_flatbuffer_result(value); Box::new(unsafe { FfiVec::from_vec(vec) }) } #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_UInt(value: u32) -> Box { - let vec = get_flatbuffer_result_from_uint(value); + let vec = get_flatbuffer_result(value); Box::new(unsafe { FfiVec::from_vec(vec) }) } #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_Long(value: i64) -> Box { - let vec = get_flatbuffer_result_from_long(value); + let vec = get_flatbuffer_result(value); Box::new(unsafe { FfiVec::from_vec(vec) }) } #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_ULong(value: u64) -> Box { - let vec = get_flatbuffer_result_from_ulong(value); + let vec = get_flatbuffer_result(value); Box::new(unsafe { FfiVec::from_vec(vec) }) } #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_Float(value: f32) -> Box { - let vec = get_flatbuffer_result_from_float(value); + let vec = get_flatbuffer_result(value); Box::new(unsafe { FfiVec::from_vec(vec) }) } #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_Double(value: f64) -> Box { - let vec = get_flatbuffer_result_from_double(value); + let vec = get_flatbuffer_result(value); Box::new(unsafe { FfiVec::from_vec(vec) }) } #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_Void() -> Box { - let vec = get_flatbuffer_result_from_void(); + let vec = get_flatbuffer_result(()); Box::new(unsafe { FfiVec::from_vec(vec) }) } @@ -71,7 +62,7 @@ pub extern "C" fn hl_flatbuffer_result_from_Void() -> Box { #[no_mangle] pub extern "C" fn hl_flatbuffer_result_from_String(value: *const c_char) -> Box { let str = unsafe { CStr::from_ptr(value) }; - let vec = get_flatbuffer_result_from_string(str.to_string_lossy().as_ref()); + let vec = get_flatbuffer_result(str.to_string_lossy().as_ref()); Box::new(unsafe { FfiVec::from_vec(vec) }) } @@ -80,7 +71,7 @@ pub extern "C" fn hl_flatbuffer_result_from_String(value: *const c_char) -> Box< pub extern "C" fn hl_flatbuffer_result_from_Bytes(data: *const u8, len: usize) -> Box { let slice = unsafe { core::slice::from_raw_parts(data, len) }; - let vec = get_flatbuffer_result_from_vec(slice); + let vec = get_flatbuffer_result(slice); Box::new(unsafe { FfiVec::from_vec(vec) }) } @@ -89,23 +80,23 @@ pub extern "C" fn hl_flatbuffer_result_from_Bytes(data: *const u8, len: usize) - #[no_mangle] pub extern "C" fn hl_get_host_return_value_as_Int() -> i32 { - get_host_value_return_as_int().expect("Unable to get host return value as int") + get_host_return_value().expect("Unable to get host return value as int") } #[no_mangle] pub extern "C" fn hl_get_host_return_value_as_UInt() -> u32 { - get_host_value_return_as_uint().expect("Unable to get host return value as uint") + get_host_return_value().expect("Unable to get host return value as uint") } // the same for long, ulong #[no_mangle] pub extern "C" fn hl_get_host_return_value_as_Long() -> i64 { - get_host_value_return_as_long().expect("Unable to get host return value as long") + get_host_return_value().expect("Unable to get host return value as long") } #[no_mangle] pub extern "C" fn hl_get_host_return_value_as_ULong() -> u64 { - get_host_value_return_as_ulong().expect("Unable to get host return value as ulong") + get_host_return_value().expect("Unable to get host return value as ulong") } // TODO add bool, float, double, string, vecbytes diff --git a/src/tests/rust_guests/callbackguest/src/main.rs b/src/tests/rust_guests/callbackguest/src/main.rs index c4e82c8e2..f08648e67 100644 --- a/src/tests/rust_guests/callbackguest/src/main.rs +++ b/src/tests/rust_guests/callbackguest/src/main.rs @@ -30,14 +30,12 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{ }; use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode; use hyperlight_common::flatbuffer_wrappers::guest_log_level::LogLevel; -use hyperlight_common::flatbuffer_wrappers::util::{ - get_flatbuffer_result_from_int, get_flatbuffer_result_from_void, -}; +use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result; use hyperlight_guest::error::{HyperlightGuestError, Result}; use hyperlight_guest::guest_function_definition::GuestFunctionDefinition; use hyperlight_guest::guest_function_register::register_function; use hyperlight_guest::host_function_call::{ - call_host_function, get_host_value_return_as_int, print_output_as_guest_function, + call_host_function, get_host_return_value, print_output_as_guest_function, }; use hyperlight_guest::logging::log_message; @@ -53,9 +51,9 @@ fn send_message_to_host_method( ReturnType::Int, )?; - let result = get_host_value_return_as_int()?; + let result = get_host_return_value::()?; - Ok(get_flatbuffer_result_from_int(result)) + Ok(get_flatbuffer_result(result)) } fn guest_function(function_call: &FunctionCall) -> Result> { @@ -111,7 +109,7 @@ fn guest_function4() -> Result> { ReturnType::Void, )?; - Ok(get_flatbuffer_result_from_void()) + Ok(get_flatbuffer_result(())) } fn guest_log_message(function_call: &FunctionCall) -> Result> { @@ -138,7 +136,7 @@ fn guest_log_message(function_call: &FunctionCall) -> Result> { line!(), ); - Ok(get_flatbuffer_result_from_int(message.len() as i32)) + Ok(get_flatbuffer_result(message.len() as i32)) } else { return Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -160,7 +158,7 @@ fn call_error_method(function_call: &FunctionCall) -> Result> { fn call_host_spin() -> Result> { call_host_function("Spin", None, ReturnType::Void)?; - Ok(get_flatbuffer_result_from_void()) + Ok(get_flatbuffer_result(())) } #[no_mangle] diff --git a/src/tests/rust_guests/simpleguest/src/main.rs b/src/tests/rust_guests/simpleguest/src/main.rs index 0854ab107..cdadf89dc 100644 --- a/src/tests/rust_guests/simpleguest/src/main.rs +++ b/src/tests/rust_guests/simpleguest/src/main.rs @@ -39,20 +39,13 @@ use hyperlight_common::flatbuffer_wrappers::function_types::{ }; use hyperlight_common::flatbuffer_wrappers::guest_error::ErrorCode; use hyperlight_common::flatbuffer_wrappers::guest_log_level::LogLevel; -use hyperlight_common::flatbuffer_wrappers::util::{ - get_flatbuffer_result_from_double, get_flatbuffer_result_from_float, - get_flatbuffer_result_from_int, get_flatbuffer_result_from_string, - get_flatbuffer_result_from_ulong, get_flatbuffer_result_from_vec, - get_flatbuffer_result_from_void, -}; +use hyperlight_common::flatbuffer_wrappers::util::get_flatbuffer_result; use hyperlight_common::mem::PAGE_SIZE; use hyperlight_guest::entrypoint::{abort_with_code, abort_with_code_and_message}; use hyperlight_guest::error::{HyperlightGuestError, Result}; use hyperlight_guest::guest_function_definition::GuestFunctionDefinition; use hyperlight_guest::guest_function_register::register_function; -use hyperlight_guest::host_function_call::{ - call_host_function, get_host_value_return_as_int, get_host_value_return_as_ulong, -}; +use hyperlight_guest::host_function_call::{call_host_function, get_host_return_value}; use hyperlight_guest::memory::malloc; use hyperlight_guest::{logging, MIN_STACK_ADDRESS}; use log::{error, LevelFilter}; @@ -67,13 +60,13 @@ fn set_static() -> Result> { for i in 0..length { BIGARRAY[i] = i as i32; } - Ok(get_flatbuffer_result_from_int(length as i32)) + Ok(get_flatbuffer_result(length as i32)) } } fn echo_double(function_call: &FunctionCall) -> Result> { if let ParameterValue::Double(value) = function_call.parameters.clone().unwrap()[0].clone() { - Ok(get_flatbuffer_result_from_double(value)) + Ok(get_flatbuffer_result(value)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -84,7 +77,7 @@ fn echo_double(function_call: &FunctionCall) -> Result> { fn echo_float(function_call: &FunctionCall) -> Result> { if let ParameterValue::Float(value) = function_call.parameters.clone().unwrap()[0].clone() { - Ok(get_flatbuffer_result_from_float(value)) + Ok(get_flatbuffer_result(value)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -99,8 +92,8 @@ fn print_output(message: &str) -> Result> { Some(Vec::from(&[ParameterValue::String(message.to_string())])), ReturnType::Int, )?; - let result = get_host_value_return_as_int()?; - Ok(get_flatbuffer_result_from_int(result)) + let result = get_host_return_value::()?; + Ok(get_flatbuffer_result(result)) } fn simple_print_output(function_call: &FunctionCall) -> Result> { @@ -118,7 +111,7 @@ fn set_byte_array_to_zero(function_call: &FunctionCall) -> Result> { if let ParameterValue::VecBytes(mut vec) = function_call.parameters.clone().unwrap()[0].clone() { vec.fill(0); - Ok(get_flatbuffer_result_from_vec(&vec)) + Ok(get_flatbuffer_result(&*vec)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -420,7 +413,7 @@ fn buffer_overrun(function_call: &FunctionCall) -> Result> { let result = (17i32).saturating_sub(length as i32); - Ok(get_flatbuffer_result_from_int(result)) + Ok(get_flatbuffer_result(result)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -442,7 +435,7 @@ fn infinite_recursion(a: &FunctionCall) -> Result> { fn stack_overflow(function_call: &FunctionCall) -> Result> { if let ParameterValue::Int(i) = function_call.parameters.clone().unwrap()[0].clone() { loop_stack_overflow(i); - Ok(get_flatbuffer_result_from_int(i)) + Ok(get_flatbuffer_result(i)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -460,12 +453,12 @@ fn loop_stack_overflow(i: i32) { fn large_var(_: &FunctionCall) -> Result> { let _buffer = black_box([0u8; (DEFAULT_GUEST_STACK_SIZE + 1) as usize]); - Ok(get_flatbuffer_result_from_int(DEFAULT_GUEST_STACK_SIZE + 1)) + Ok(get_flatbuffer_result(DEFAULT_GUEST_STACK_SIZE + 1)) } fn small_var(_: &FunctionCall) -> Result> { let _buffer = black_box([0u8; 1024]); - Ok(get_flatbuffer_result_from_int(1024)) + Ok(get_flatbuffer_result(1024)) } fn call_malloc(function_call: &FunctionCall) -> Result> { @@ -473,7 +466,7 @@ fn call_malloc(function_call: &FunctionCall) -> Result> { // will panic if OOM, and we need blackbox to avoid optimizing away this test let buffer = Vec::::with_capacity(size as usize); black_box(buffer); - Ok(get_flatbuffer_result_from_int(size)) + Ok(get_flatbuffer_result(size)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -493,7 +486,7 @@ fn malloc_and_free(function_call: &FunctionCall) -> Result> { allocated_buffer.resize(alloc_length as usize, 0); drop(allocated_buffer); - Ok(get_flatbuffer_result_from_int(size)) + Ok(get_flatbuffer_result(size)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -504,7 +497,7 @@ fn malloc_and_free(function_call: &FunctionCall) -> Result> { fn echo(function_call: &FunctionCall) -> Result> { if let ParameterValue::String(value) = function_call.parameters.clone().unwrap()[0].clone() { - Ok(get_flatbuffer_result_from_string(&value)) + Ok(get_flatbuffer_result(&*value)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -515,7 +508,7 @@ fn echo(function_call: &FunctionCall) -> Result> { fn get_size_prefixed_buffer(function_call: &FunctionCall) -> Result> { if let ParameterValue::VecBytes(data) = function_call.parameters.clone().unwrap()[0].clone() { - Ok(get_flatbuffer_result_from_vec(&data)) + Ok(get_flatbuffer_result(&*data)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -530,14 +523,14 @@ fn spin(_: &FunctionCall) -> Result> { } #[allow(unreachable_code)] - Ok(get_flatbuffer_result_from_void()) + Ok(get_flatbuffer_result(())) } fn test_abort(function_call: &FunctionCall) -> Result> { if let ParameterValue::Int(code) = function_call.parameters.clone().unwrap()[0].clone() { abort_with_code(code); } - Ok(get_flatbuffer_result_from_void()) + Ok(get_flatbuffer_result(())) } fn test_abort_with_code_and_message(function_call: &FunctionCall) -> Result> { @@ -549,14 +542,14 @@ fn test_abort_with_code_and_message(function_call: &FunctionCall) -> Result Result> { if let ParameterValue::String(message) = function_call.parameters.clone().unwrap()[0].clone() { panic!("{}", message); } - Ok(get_flatbuffer_result_from_void()) + Ok(get_flatbuffer_result(())) } fn test_write_raw_ptr(function_call: &FunctionCall) -> Result> { @@ -577,9 +570,9 @@ fn test_write_raw_ptr(function_call: &FunctionCall) -> Result> { // print_output(format!("writing to {:#x}\n", addr).as_str()).unwrap(); write_volatile(addr as *mut u8, 0u8); } - return Ok(get_flatbuffer_result_from_string("success")); + return Ok(get_flatbuffer_result("success")); } - Ok(get_flatbuffer_result_from_string("fail")) + Ok(get_flatbuffer_result("fail")) } fn execute_on_stack(_function_call: &FunctionCall) -> Result> { @@ -588,7 +581,7 @@ fn execute_on_stack(_function_call: &FunctionCall) -> Result> { let stack_fn: fn() = core::mem::transmute(&mut noop as *mut u8); stack_fn(); }; - Ok(get_flatbuffer_result_from_string("fail")) + Ok(get_flatbuffer_result("fail")) } fn execute_on_heap(_function_call: &FunctionCall) -> Result> { @@ -600,13 +593,13 @@ fn execute_on_heap(_function_call: &FunctionCall) -> Result> { black_box(heap_fn); // avoid optimization when running in release mode } // will only reach this point if heap is executable - Ok(get_flatbuffer_result_from_string("fail")) + Ok(get_flatbuffer_result("fail")) } fn test_rust_malloc(function_call: &FunctionCall) -> Result> { if let ParameterValue::Int(code) = function_call.parameters.clone().unwrap()[0].clone() { let ptr = unsafe { malloc(code as usize) }; - Ok(get_flatbuffer_result_from_int(ptr as i32)) + Ok(get_flatbuffer_result(ptr as i32)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -628,7 +621,7 @@ fn log_message(function_call: &FunctionCall) -> Result> { // was passed LevelFilter::Off, do nothing } } - Ok(get_flatbuffer_result_from_void()) + Ok(get_flatbuffer_result(())) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -641,7 +634,7 @@ fn trigger_exception(_: &FunctionCall) -> Result> { unsafe { core::arch::asm!("ud2"); } // trigger an undefined instruction exception - Ok(get_flatbuffer_result_from_void()) + Ok(get_flatbuffer_result(())) } static mut COUNTER: i32 = 0; @@ -652,7 +645,7 @@ fn add_to_static(function_call: &FunctionCall) -> Result> { COUNTER += i; COUNTER }; - Ok(get_flatbuffer_result_from_int(res)) + Ok(get_flatbuffer_result(res)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -663,7 +656,7 @@ fn add_to_static(function_call: &FunctionCall) -> Result> { fn get_static(function_call: &FunctionCall) -> Result> { if function_call.parameters.is_none() { - Ok(get_flatbuffer_result_from_int(unsafe { COUNTER })) + Ok(get_flatbuffer_result(unsafe { COUNTER })) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -686,9 +679,9 @@ fn violate_seccomp_filters(function_call: &FunctionCall) -> Result> { if function_call.parameters.is_none() { call_host_function("MakeGetpidSyscall", None, ReturnType::ULong)?; - let res = get_host_value_return_as_ulong()?; + let res = get_host_return_value::()?; - Ok(get_flatbuffer_result_from_ulong(res)) + Ok(get_flatbuffer_result(res)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -708,9 +701,9 @@ fn add(function_call: &FunctionCall) -> Result> { ReturnType::Int, )?; - let res = get_host_value_return_as_int()?; + let res = get_host_return_value::()?; - Ok(get_flatbuffer_result_from_int(res)) + Ok(get_flatbuffer_result(res)) } else { Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, @@ -1135,7 +1128,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { Some(Vec::from(&[ParameterValue::String(message.to_string())])), ReturnType::Int, )?; - let result = get_host_value_return_as_int()?; + let result = get_host_return_value::()?; let function_name = function_call.function_name.clone(); let param_len = function_call.parameters.clone().unwrap_or_default().len(); let call_type = function_call.function_call_type().clone(); @@ -1151,5 +1144,5 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { )); } - Ok(get_flatbuffer_result_from_int(99)) + Ok(get_flatbuffer_result(99)) } From 3005ed59d57e50786b7049138c68b7dc72f62b40 Mon Sep 17 00:00:00 2001 From: Ludvig Liljenberg Date: Fri, 28 Feb 2025 12:13:50 -0800 Subject: [PATCH 14/17] Run clippy on guests in CI (#237) * Clippy guests Signed-off-by: Ludvig Liljenberg * Add matrix target to recipe Signed-off-by: Ludvig Liljenberg * fix broken rebase Signed-off-by: Ludvig Liljenberg --------- Signed-off-by: Ludvig Liljenberg Signed-off-by: Manoj Kumar Yadav --- .github/workflows/dep_rust.yml | 4 +- Justfile | 4 + .../src/guest_function_call.rs | 2 +- .../src/guest_function_definition.rs | 4 +- src/hyperlight_guest_capi/src/dispatch.rs | 10 +- .../rust_guests/callbackguest/src/main.rs | 48 ++++---- src/tests/rust_guests/simpleguest/src/main.rs | 110 +++++++++--------- 7 files changed, 95 insertions(+), 87 deletions(-) diff --git a/.github/workflows/dep_rust.yml b/.github/workflows/dep_rust.yml index e5215e91d..c25e17a79 100644 --- a/.github/workflows/dep_rust.yml +++ b/.github/workflows/dep_rust.yml @@ -58,7 +58,9 @@ jobs: run: just fmt-check - name: clippy - run: just clippy ${{ matrix.config }} + run: | + just clippy ${{ matrix.config }} + just clippy-guests ${{ matrix.config }} # Does not check for updated Cargo.lock files for test rust guests as this causes an issue with this checkwhen deoendabot updates dependencies in common crates - name: Ensure up-to-date Cargo.lock diff --git a/Justfile b/Justfile index d5e73f312..c91c08780 100644 --- a/Justfile +++ b/Justfile @@ -138,6 +138,10 @@ fmt-apply: clippy target=default-target: cargo clippy --all-targets --all-features --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings +clippy-guests target=default-target: + cd src/tests/rust_guests/simpleguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings + cd src/tests/rust_guests/callbackguest && cargo clippy --profile={{ if target == "debug" { "dev" } else { target } }} -- -D warnings + clippy-apply-fix-unix: cargo clippy --fix --all diff --git a/src/hyperlight_guest/src/guest_function_call.rs b/src/hyperlight_guest/src/guest_function_call.rs index 3b904441b..60d5548db 100644 --- a/src/hyperlight_guest/src/guest_function_call.rs +++ b/src/hyperlight_guest/src/guest_function_call.rs @@ -58,7 +58,7 @@ pub(crate) fn call_guest_function(function_call: FunctionCall) -> Result let p_function = unsafe { let function_pointer = registered_function_definition.function_pointer; - core::mem::transmute::(function_pointer) + core::mem::transmute::(function_pointer) }; p_function(&function_call) diff --git a/src/hyperlight_guest/src/guest_function_definition.rs b/src/hyperlight_guest/src/guest_function_definition.rs index 67aced667..d9320cd61 100644 --- a/src/hyperlight_guest/src/guest_function_definition.rs +++ b/src/hyperlight_guest/src/guest_function_definition.rs @@ -33,7 +33,7 @@ pub struct GuestFunctionDefinition { /// The type of the return value from the host function call pub return_type: ReturnType, /// The function pointer to the guest function - pub function_pointer: i64, + pub function_pointer: usize, } impl GuestFunctionDefinition { @@ -42,7 +42,7 @@ impl GuestFunctionDefinition { function_name: String, parameter_types: Vec, return_type: ReturnType, - function_pointer: i64, + function_pointer: usize, ) -> Self { Self { function_name, diff --git a/src/hyperlight_guest_capi/src/dispatch.rs b/src/hyperlight_guest_capi/src/dispatch.rs index 98c89d8e5..eacd7b374 100644 --- a/src/hyperlight_guest_capi/src/dispatch.rs +++ b/src/hyperlight_guest_capi/src/dispatch.rs @@ -39,7 +39,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { let ffi_func_call = FfiFunctionCall::from_function_call(function_call)?; let guest_func = - unsafe { mem::transmute::(registered_func.function_pointer) }; + unsafe { mem::transmute::(registered_func.function_pointer) }; let function_result = guest_func(&ffi_func_call); unsafe { Ok(FfiVec::into_vec(*function_result)) } @@ -76,12 +76,8 @@ pub extern "C" fn hl_register_function_definition( let func_params = unsafe { slice::from_raw_parts(params_type, param_no).to_vec() }; - let func_def = GuestFunctionDefinition::new( - func_name, - func_params, - return_type, - func_ptr as usize as i64, - ); + let func_def = + GuestFunctionDefinition::new(func_name, func_params, return_type, func_ptr as usize); #[allow(static_mut_refs)] unsafe { &mut REGISTERED_C_GUEST_FUNCTIONS }.register(func_def); diff --git a/src/tests/rust_guests/callbackguest/src/main.rs b/src/tests/rust_guests/callbackguest/src/main.rs index f08648e67..c787599d5 100644 --- a/src/tests/rust_guests/callbackguest/src/main.rs +++ b/src/tests/rust_guests/callbackguest/src/main.rs @@ -60,10 +60,10 @@ fn guest_function(function_call: &FunctionCall) -> Result> { if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] { send_message_to_host_method("HostMethod", "Hello from GuestFunction, ", message) } else { - return Err(HyperlightGuestError::new( + Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "Invalid parameters passed to guest_function".to_string(), - )); + )) } } @@ -71,10 +71,10 @@ fn guest_function1(function_call: &FunctionCall) -> Result> { if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] { send_message_to_host_method("HostMethod1", "Hello from GuestFunction1, ", message) } else { - return Err(HyperlightGuestError::new( + Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "Invalid parameters passed to guest_function1".to_string(), - )); + )) } } @@ -82,10 +82,10 @@ fn guest_function2(function_call: &FunctionCall) -> Result> { if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] { send_message_to_host_method("HostMethod1", "Hello from GuestFunction2, ", message) } else { - return Err(HyperlightGuestError::new( + Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "Invalid parameters passed to guest_function2".to_string(), - )); + )) } } @@ -93,14 +93,14 @@ fn guest_function3(function_call: &FunctionCall) -> Result> { if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] { send_message_to_host_method("HostMethod1", "Hello from GuestFunction3, ", message) } else { - return Err(HyperlightGuestError::new( + Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "Invalid parameters passed to guest_function3".to_string(), - )); + )) } } -fn guest_function4() -> Result> { +fn guest_function4(_: &FunctionCall) -> Result> { call_host_function( "HostMethod4", Some(Vec::from(&[ParameterValue::String( @@ -123,7 +123,7 @@ fn guest_log_message(function_call: &FunctionCall) -> Result> { &function_call.parameters.as_ref().unwrap()[2], ) { let mut log_level = *level; - if log_level < 0 || log_level > 6 { + if !(0..=6).contains(&log_level) { log_level = 0; } @@ -138,10 +138,10 @@ fn guest_log_message(function_call: &FunctionCall) -> Result> { Ok(get_flatbuffer_result(message.len() as i32)) } else { - return Err(HyperlightGuestError::new( + Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "Invalid parameters passed to guest_log_message".to_string(), - )); + )) } } @@ -149,14 +149,14 @@ fn call_error_method(function_call: &FunctionCall) -> Result> { if let ParameterValue::String(message) = &function_call.parameters.as_ref().unwrap()[0] { send_message_to_host_method("ErrorMethod", "Error From Host: ", message) } else { - return Err(HyperlightGuestError::new( + Err(HyperlightGuestError::new( ErrorCode::GuestFunctionParameterTypeMismatch, "Invalid parameters passed to call_error_method".to_string(), - )); + )) } } -fn call_host_spin() -> Result> { +fn call_host_spin(_: &FunctionCall) -> Result> { call_host_function("Spin", None, ReturnType::Void)?; Ok(get_flatbuffer_result(())) } @@ -167,7 +167,7 @@ pub extern "C" fn hyperlight_main() { "PrintOutput".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - print_output_as_guest_function as i64, + print_output_as_guest_function as usize, ); register_function(print_output_def); @@ -175,7 +175,7 @@ pub extern "C" fn hyperlight_main() { "GuestMethod".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - guest_function as i64, + guest_function as usize, ); register_function(guest_function_def); @@ -183,7 +183,7 @@ pub extern "C" fn hyperlight_main() { "GuestMethod1".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - guest_function1 as i64, + guest_function1 as usize, ); register_function(guest_function1_def); @@ -191,7 +191,7 @@ pub extern "C" fn hyperlight_main() { "GuestMethod2".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - guest_function2 as i64, + guest_function2 as usize, ); register_function(guest_function2_def); @@ -199,7 +199,7 @@ pub extern "C" fn hyperlight_main() { "GuestMethod3".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - guest_function3 as i64, + guest_function3 as usize, ); register_function(guest_function3_def); @@ -207,7 +207,7 @@ pub extern "C" fn hyperlight_main() { "GuestMethod4".to_string(), Vec::new(), ReturnType::Int, - guest_function4 as i64, + guest_function4 as usize, ); register_function(guest_function4_def); @@ -219,7 +219,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::Int, ]), ReturnType::Int, - guest_log_message as i64, + guest_log_message as usize, ); register_function(guest_log_message_def); @@ -227,7 +227,7 @@ pub extern "C" fn hyperlight_main() { "CallErrorMethod".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - call_error_method as i64, + call_error_method as usize, ); register_function(call_error_method_def); @@ -235,7 +235,7 @@ pub extern "C" fn hyperlight_main() { "CallHostSpin".to_string(), Vec::new(), ReturnType::Int, - call_host_spin as i64, + call_host_spin as usize, ); register_function(call_host_spin_def); } diff --git a/src/tests/rust_guests/simpleguest/src/main.rs b/src/tests/rust_guests/simpleguest/src/main.rs index cdadf89dc..3813733c7 100644 --- a/src/tests/rust_guests/simpleguest/src/main.rs +++ b/src/tests/rust_guests/simpleguest/src/main.rs @@ -26,9 +26,9 @@ const MAX_BUFFER_SIZE: usize = 1024; extern crate alloc; use alloc::boxed::Box; -use alloc::format; use alloc::string::ToString; use alloc::vec::Vec; +use alloc::{format, vec}; use core::ffi::c_char; use core::hint::black_box; use core::ptr::write_volatile; @@ -54,13 +54,12 @@ extern crate hyperlight_guest; static mut BIGARRAY: [i32; 1024 * 1024] = [0; 1024 * 1024]; -fn set_static() -> Result> { +fn set_static(_: &FunctionCall) -> Result> { unsafe { - let length = BIGARRAY.len(); - for i in 0..length { - BIGARRAY[i] = i as i32; + for val in BIGARRAY.iter_mut() { + *val = 1; } - Ok(get_flatbuffer_result(length as i32)) + Ok(get_flatbuffer_result(BIGARRAY.len() as i32)) } } @@ -423,13 +422,13 @@ fn buffer_overrun(function_call: &FunctionCall) -> Result> { } #[allow(unconditional_recursion)] -fn infinite_recursion(a: &FunctionCall) -> Result> { +fn infinite_recursion(_a: &FunctionCall) -> Result> { // blackbox is needed so something //is written to the stack in release mode, //to trigger guard page violation let param = black_box(5); black_box(param); - infinite_recursion(a) + infinite_recursion(_a) } fn stack_overflow(function_call: &FunctionCall) -> Result> { @@ -482,8 +481,7 @@ fn malloc_and_free(function_call: &FunctionCall) -> Result> { } else { size.min(MAX_BUFFER_SIZE as i32) }; - let mut allocated_buffer = Vec::with_capacity(alloc_length as usize); - allocated_buffer.resize(alloc_length as usize, 0); + let allocated_buffer = vec![0; alloc_length as usize]; drop(allocated_buffer); Ok(get_flatbuffer_result(size)) @@ -517,6 +515,10 @@ fn get_size_prefixed_buffer(function_call: &FunctionCall) -> Result> { } } +#[expect( + clippy::empty_loop, + reason = "This function is used to keep the CPU busy" +)] fn spin(_: &FunctionCall) -> Result> { loop { // Keep the CPU 100% busy forever @@ -718,7 +720,7 @@ pub extern "C" fn hyperlight_main() { "SetStatic".to_string(), Vec::new(), ReturnType::Int, - set_static as i64, + set_static as usize, ); register_function(set_static_def); @@ -727,7 +729,7 @@ pub extern "C" fn hyperlight_main() { "PrintOutput".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - simple_print_output as i64, + simple_print_output as usize, ); register_function(simple_print_output_def); @@ -735,7 +737,7 @@ pub extern "C" fn hyperlight_main() { "PrintUsingPrintf".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - simple_print_output as i64, // alias to simple_print_output for now + simple_print_output as usize, // alias to simple_print_output for now ); register_function(print_using_printf_def); @@ -743,7 +745,7 @@ pub extern "C" fn hyperlight_main() { "StackOverflow".to_string(), Vec::from(&[ParameterType::Int]), ReturnType::Int, - stack_overflow as i64, + stack_overflow as usize, ); register_function(stack_overflow_def); @@ -751,7 +753,7 @@ pub extern "C" fn hyperlight_main() { "BufferOverrun".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Int, - buffer_overrun as i64, + buffer_overrun as usize, ); register_function(buffer_overrun_def); @@ -759,7 +761,7 @@ pub extern "C" fn hyperlight_main() { "LargeVar".to_string(), Vec::new(), ReturnType::Int, - large_var as i64, + large_var as usize, ); register_function(large_var_def); @@ -767,7 +769,7 @@ pub extern "C" fn hyperlight_main() { "SmallVar".to_string(), Vec::new(), ReturnType::Int, - small_var as i64, + small_var as usize, ); register_function(small_var_def); @@ -775,7 +777,7 @@ pub extern "C" fn hyperlight_main() { "CallMalloc".to_string(), Vec::from(&[ParameterType::Int]), ReturnType::Int, - call_malloc as i64, + call_malloc as usize, ); register_function(call_malloc_def); @@ -783,7 +785,7 @@ pub extern "C" fn hyperlight_main() { "MallocAndFree".to_string(), Vec::from(&[ParameterType::Int]), ReturnType::Int, - malloc_and_free as i64, + malloc_and_free as usize, ); register_function(malloc_and_free_def); @@ -791,7 +793,7 @@ pub extern "C" fn hyperlight_main() { "PrintTwoArgs".to_string(), Vec::from(&[ParameterType::String, ParameterType::Int]), ReturnType::Int, - print_two_args as i64, + print_two_args as usize, ); register_function(print_two_args_def); @@ -803,7 +805,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::Long, ]), ReturnType::Int, - print_three_args as i64, + print_three_args as usize, ); register_function(print_three_args_def); @@ -816,7 +818,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::String, ]), ReturnType::Int, - print_four_args as i64, + print_four_args as usize, ); register_function(print_four_args_def); @@ -830,7 +832,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::String, ]), ReturnType::Int, - print_five_args as i64, + print_five_args as usize, ); register_function(print_five_args_def); @@ -845,7 +847,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::Bool, ]), ReturnType::Int, - print_six_args as i64, + print_six_args as usize, ); register_function(print_six_args_def); @@ -861,7 +863,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::Bool, ]), ReturnType::Int, - print_seven_args as i64, + print_seven_args as usize, ); register_function(print_seven_args_def); @@ -878,7 +880,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::UInt, ]), ReturnType::Int, - print_eight_args as i64, + print_eight_args as usize, ); register_function(print_eight_args_def); @@ -896,7 +898,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::ULong, ]), ReturnType::Int, - print_nine_args as i64, + print_nine_args as usize, ); register_function(print_nine_args_def); @@ -915,7 +917,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::Int, ]), ReturnType::Int, - print_ten_args as i64, + print_ten_args as usize, ); register_function(print_ten_args_def); @@ -935,7 +937,7 @@ pub extern "C" fn hyperlight_main() { ParameterType::Float, ]), ReturnType::Int, - print_eleven_args as i64, + print_eleven_args as usize, ); register_function(print_eleven_args_def); @@ -943,7 +945,7 @@ pub extern "C" fn hyperlight_main() { "SetByteArrayToZero".to_string(), Vec::from(&[ParameterType::VecBytes]), ReturnType::VecBytes, - set_byte_array_to_zero as i64, + set_byte_array_to_zero as usize, ); register_function(set_byte_array_to_zero_def); @@ -951,7 +953,7 @@ pub extern "C" fn hyperlight_main() { "Echo".to_string(), Vec::from(&[ParameterType::String]), ReturnType::String, - echo as i64, + echo as usize, ); register_function(echo_def); @@ -959,19 +961,23 @@ pub extern "C" fn hyperlight_main() { "GetSizePrefixedBuffer".to_string(), Vec::from(&[ParameterType::VecBytes]), ReturnType::Int, - get_size_prefixed_buffer as i64, + get_size_prefixed_buffer as usize, ); register_function(get_size_prefixed_buffer_def); - let spin_def = - GuestFunctionDefinition::new("Spin".to_string(), Vec::new(), ReturnType::Int, spin as i64); + let spin_def = GuestFunctionDefinition::new( + "Spin".to_string(), + Vec::new(), + ReturnType::Int, + spin as usize, + ); register_function(spin_def); let abort_def = GuestFunctionDefinition::new( "GuestAbortWithCode".to_string(), Vec::from(&[ParameterType::Int]), ReturnType::Void, - test_abort as i64, + test_abort as usize, ); register_function(abort_def); @@ -979,7 +985,7 @@ pub extern "C" fn hyperlight_main() { "GuestAbortWithMessage".to_string(), Vec::from(&[ParameterType::Int, ParameterType::String]), ReturnType::Void, - test_abort_with_code_and_message as i64, + test_abort_with_code_and_message as usize, ); register_function(abort_with_code_message_def); @@ -987,7 +993,7 @@ pub extern "C" fn hyperlight_main() { "guest_panic".to_string(), Vec::from(&[ParameterType::String]), ReturnType::Void, - test_guest_panic as i64, + test_guest_panic as usize, ); register_function(guest_panic_def); @@ -995,7 +1001,7 @@ pub extern "C" fn hyperlight_main() { "TestMalloc".to_string(), Vec::from(&[ParameterType::Int]), ReturnType::Int, - test_rust_malloc as i64, + test_rust_malloc as usize, ); register_function(rust_malloc_def); @@ -1003,7 +1009,7 @@ pub extern "C" fn hyperlight_main() { "LogMessage".to_string(), Vec::from(&[ParameterType::String, ParameterType::Int]), ReturnType::Void, - log_message as i64, + log_message as usize, ); register_function(log_message_def); @@ -1011,7 +1017,7 @@ pub extern "C" fn hyperlight_main() { "InfiniteRecursion".to_string(), Vec::new(), ReturnType::Void, - infinite_recursion as i64, + infinite_recursion as usize, ); register_function(infinite_recursion_def); @@ -1019,7 +1025,7 @@ pub extern "C" fn hyperlight_main() { "test_write_raw_ptr".to_string(), Vec::from(&[ParameterType::Long]), ReturnType::String, - test_write_raw_ptr as i64, + test_write_raw_ptr as usize, ); register_function(test_write_raw_ptr_def); @@ -1027,7 +1033,7 @@ pub extern "C" fn hyperlight_main() { "ExecuteOnStack".to_string(), Vec::new(), ReturnType::String, - execute_on_stack as i64, + execute_on_stack as usize, ); register_function(execute_on_stack_def); @@ -1035,7 +1041,7 @@ pub extern "C" fn hyperlight_main() { "ExecuteOnHeap".to_string(), Vec::new(), ReturnType::String, - execute_on_heap as i64, + execute_on_heap as usize, ); register_function(execute_on_heap_def); @@ -1043,7 +1049,7 @@ pub extern "C" fn hyperlight_main() { "AddToStatic".to_string(), Vec::from(&[ParameterType::Int]), ReturnType::Int, - add_to_static as i64, + add_to_static as usize, ); register_function(add_to_static_def); @@ -1051,7 +1057,7 @@ pub extern "C" fn hyperlight_main() { "GetStatic".to_string(), Vec::new(), ReturnType::Int, - get_static as i64, + get_static as usize, ); register_function(get_static_def); @@ -1059,7 +1065,7 @@ pub extern "C" fn hyperlight_main() { "AddToStaticAndFail".to_string(), Vec::new(), ReturnType::Int, - add_to_static_and_fail as i64, + add_to_static_and_fail as usize, ); register_function(add_to_static_and_fail_def); @@ -1067,7 +1073,7 @@ pub extern "C" fn hyperlight_main() { "ViolateSeccompFilters".to_string(), Vec::new(), ReturnType::ULong, - violate_seccomp_filters as i64, + violate_seccomp_filters as usize, ); register_function(violate_seccomp_filters_def); @@ -1075,7 +1081,7 @@ pub extern "C" fn hyperlight_main() { "EchoFloat".to_string(), Vec::from(&[ParameterType::Float]), ReturnType::Float, - echo_float as i64, + echo_float as usize, ); register_function(echo_float_def); @@ -1083,7 +1089,7 @@ pub extern "C" fn hyperlight_main() { "EchoDouble".to_string(), Vec::from(&[ParameterType::Double]), ReturnType::Double, - echo_double as i64, + echo_double as usize, ); register_function(echo_double_def); @@ -1091,7 +1097,7 @@ pub extern "C" fn hyperlight_main() { "Add".to_string(), Vec::from(&[ParameterType::Int, ParameterType::Int]), ReturnType::Int, - add as i64, + add as usize, ); register_function(add_def); @@ -1099,7 +1105,7 @@ pub extern "C" fn hyperlight_main() { "TriggerException".to_string(), Vec::new(), ReturnType::Void, - trigger_exception as i64, + trigger_exception as usize, ); register_function(trigger_exception_def); } @@ -1116,7 +1122,7 @@ pub fn guest_dispatch_function(function_call: FunctionCall) -> Result> { logging::log_message( LogLevel::Information, - &message, + message, "source", "caller", "file", From 5d4f9bdaaaafe551ea5b63c74a091763aee70f24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Doru=20Bl=C3=A2nzeanu?= Date: Mon, 3 Mar 2025 11:40:04 +0200 Subject: [PATCH 15/17] devcontainer install gdb and vscode ext for debugging (#291) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Doru Blânzeanu Signed-off-by: Manoj Kumar Yadav --- .devcontainer/Dockerfile | 1 + .devcontainer/devcontainer.json | 1 + 2 files changed, 2 insertions(+) diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index fd6aa78f7..99b93e95b 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -14,6 +14,7 @@ RUN apt-get update \ build-essential \ cmake \ curl \ + gdb \ git \ gnupg \ gnuplot \ diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 5e9a31284..2c2763031 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -26,6 +26,7 @@ "customizations": { "vscode": { "extensions": [ + "ms-vscode.cpptools-extension-pack", "ms-vscode.cmake-tools", "rust-lang.rust-analyzer", "vadimcn.vscode-lldb" From fba3ec370b28b082eaf001595dd27eb83bb12342 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Yadav Date: Tue, 4 Mar 2025 04:15:36 +0000 Subject: [PATCH 16/17] move setup command to bash file Signed-off-by: Ubuntu Signed-off-by: Manoj Kumar Yadav --- .devcontainer/devcontainer.json | 6 +++--- .devcontainer/setup.sh | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 2c2763031..9a9973400 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -20,9 +20,9 @@ // Use 'postCreateCommand' to run commands after the container is created "postCreateCommand": "bash .devcontainer/setup.sh", - // Runs each time the container starts/restarts - // Only run these commands if /dev/kvm exists - "postStartCommand": "if [ -e /dev/kvm ]; then sudo chown root:kvm /dev/kvm && sudo chmod 660 /dev/kvm && sudo usermod -aG kvm vscode; else echo 'KVM device not found, skipping...'; fi", + // Runs each time the container starts/restarts and set kvm permissions + "postStartCommand": "bash .devcontainer/setup.sh", + "customizations": { "vscode": { "extensions": [ diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index db7b7196e..84ef7da87 100644 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -3,3 +3,11 @@ # Change device ownership sudo chown -R $REMOTE_USER:$REMOTE_GROUP $DEVICE +# Check for the KVM device and adjust permissions. +if [ -e /dev/kvm ]; then + sudo chown root:kvm /dev/kvm + sudo chmod 660 /dev/kvm + sudo usermod -aG kvm vscode +else + echo 'KVM device not found, skipping...' +fi \ No newline at end of file From bf72c57c7799d3142aec00bec2fc6da9271c5487 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Yadav Date: Tue, 4 Mar 2025 14:57:41 +0000 Subject: [PATCH 17/17] updating changes --- .devcontainer/devcontainer.json | 5 +---- .devcontainer/setup.sh | 9 --------- 2 files changed, 1 insertion(+), 13 deletions(-) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 9a9973400..4c35d5d23 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -17,10 +17,7 @@ "--device=/dev/kvm" ], - // Use 'postCreateCommand' to run commands after the container is created - "postCreateCommand": "bash .devcontainer/setup.sh", - - // Runs each time the container starts/restarts and set kvm permissions + // Runs each time the container starts/restarts "postStartCommand": "bash .devcontainer/setup.sh", "customizations": { diff --git a/.devcontainer/setup.sh b/.devcontainer/setup.sh index 84ef7da87..052a7d0c1 100644 --- a/.devcontainer/setup.sh +++ b/.devcontainer/setup.sh @@ -2,12 +2,3 @@ # Change device ownership sudo chown -R $REMOTE_USER:$REMOTE_GROUP $DEVICE - -# Check for the KVM device and adjust permissions. -if [ -e /dev/kvm ]; then - sudo chown root:kvm /dev/kvm - sudo chmod 660 /dev/kvm - sudo usermod -aG kvm vscode -else - echo 'KVM device not found, skipping...' -fi \ No newline at end of file