Skip to content

msb_krun_cpuid: fix compilation on Rust 1.93 by wrapping CPUID calls in unsafe blocks#50

Merged
appcypher merged 3 commits intosuperradcompany:krunfrom
Unique-Usman:ua/fixunsafeerror
Apr 24, 2026
Merged

msb_krun_cpuid: fix compilation on Rust 1.93 by wrapping CPUID calls in unsafe blocks#50
appcypher merged 3 commits intosuperradcompany:krunfrom
Unique-Usman:ua/fixunsafeerror

Conversation

@Unique-Usman
Copy link
Copy Markdown

Recent Rust versions (e.g., 1.93.0) require explicit unsafe blocks when calling low-level CPU intrinsics such as __cpuid, __cpuid_count, and __get_cpuid_max.

This crate was invoking these functions without unsafe blocks, which results in compilation errors:

error[E0133]: call to unsafe function is unsafe and requires unsafe function or block

Wrap all such calls in explicit unsafe {} blocks to satisfy the compiler and maintain correctness.

No functional changes intended—this aligns the code with Rust’s safety requirements for intrinsic operations.

…in unsafe blocks

Recent Rust versions (e.g., 1.93.0) require explicit `unsafe` blocks
when calling low-level CPU intrinsics such as `__cpuid`,
`__cpuid_count`, and `__get_cpuid_max`.

This crate was invoking these functions without `unsafe` blocks,
which results in compilation errors:

    error[E0133]: call to unsafe function is unsafe and requires unsafe function or block

Wrap all such calls in explicit `unsafe {}` blocks to satisfy
the compiler and maintain correctness.

No functional changes intended—this aligns the code with
Rust’s safety requirements for intrinsic operations.

Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
@Unique-Usman
Copy link
Copy Markdown
Author

An attempt to fix this -> #50

@Unique-Usman
Copy link
Copy Markdown
Author

@appcypher

Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
Syncs `common.rs` and `brand_string.rs` with containers/libkrun upstream:

- Fix import typo: `target_arch = "x86_64"` now correctly imports from
  `std::arch::x86_64` (not `x86`), restoring compilation on x86_64.
- Add `#[allow(unused_unsafe)]` to `get_cpuid` and `from_host_cpuid`.
  Rust 1.94 relaxed `__cpuid`, `__cpuid_count`, and `__get_cpuid_max`
  to safe `fn` via stdarch PR #1935, so the `unsafe {}` blocks needed
  on Rust 1.93 now trip `-D warnings` under clippy on 1.94+. The
  `allow` silences the lint while keeping the code compatible with
  both toolchains.
- Wrap the remaining `host_cpuid` calls in the test module in `unsafe`
  blocks for the same reason.
@appcypher appcypher merged commit cf4a320 into superradcompany:krun Apr 24, 2026
8 checks passed
appcypher added a commit that referenced this pull request Apr 26, 2026
Bump all msb_krun_* workspace crates and their internal path-dependency
version refs from 0.1.10 to 0.1.11, and refresh both lockfiles. The
libkrun C-API crate (1.17.3) and the rust_vm example are unchanged.

Changes since 0.1.10:

- feat(krun): expand DiskBuilder with id, cache, direct_io, sync (#51)
- msb_krun_cpuid: fix compilation on Rust 1.93 by wrapping CPUID calls
  in unsafe blocks (#50)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants