Skip to content

Commit ab102b3

Browse files
committed
feat: upgrade kvm-bindings to Rust edition 2024
This commit upgrades kvm-bindings from the default Rust edition 2015 to edition 2024, addressing the need for explicit unsafe blocks and proper module path resolution. Changes: - Add \`edition = \"2024\"\` to kvm-bindings/Cargo.toml - Wrap unsafe function calls in explicit unsafe blocks in bindings.rs - from_raw_parts, from_raw_parts_mut, transmute calls - Fix import paths in fam_wrappers.rs and nested.rs: - \`use x86_64::bindings::*\` → \`use crate::x86_64::bindings::*\` - Add explicit \`crate::\` prefix for module imports - Remove \`extern crate core;\` (automatic in edition 2024) All tests pass with no warnings. Fixes #329 Signed-off-by: SteelCrab <pyh5523@gmail.com>
1 parent 543e643 commit ab102b3

File tree

16 files changed

+36
-37
lines changed

16 files changed

+36
-37
lines changed

kvm-bindings/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
[package]
22
name = "kvm-bindings"
33
version = "0.12.0"
4+
edition = "2024"
45
authors = ["Amazon firecracker team <firecracker-devel@amazon.com>"]
56
description = "Rust FFI bindings to KVM generated using bindgen."
67
repository = "https://github.com/rust-vmm/kvm"

kvm-bindings/src/arm64/bindings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ impl<T> __IncompleteArrayField<T> {
2222
}
2323
#[inline]
2424
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
25-
::std::slice::from_raw_parts(self.as_ptr(), len)
25+
unsafe {::std::slice::from_raw_parts(self.as_ptr(), len)}
2626
}
2727
#[inline]
2828
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
29-
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
29+
unsafe {::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)}
3030
}
3131
}
3232
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {

kvm-bindings/src/arm64/fam_wrappers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use vmm_sys_util::fam::{FamStruct, FamStructWrapper};
55

6-
use arm64::bindings::*;
6+
use crate::arm64::bindings::*;
77

88
// There is no constant in the kernel as far as the maximum number
99
// of registers on arm, but KVM_GET_REG_LIST usually returns around 450.

kvm-bindings/src/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ extern crate serde;
1818
#[cfg(feature = "serde")]
1919
extern crate zerocopy;
2020

21-
extern crate core;
22-
2321
#[cfg(feature = "serde")]
2422
#[macro_use]
2523
mod serialize;

kvm-bindings/src/riscv64/bindings.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ impl<T> __IncompleteArrayField<T> {
2222
}
2323
#[inline]
2424
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
25-
::std::slice::from_raw_parts(self.as_ptr(), len)
25+
unsafe {::std::slice::from_raw_parts(self.as_ptr(), len)}
2626
}
2727
#[inline]
2828
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
29-
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
29+
unsafe {::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)}
3030
}
3131
}
3232
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {

kvm-bindings/src/riscv64/fam_wrappers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
use vmm_sys_util::fam::{FamStruct, FamStructWrapper};
66

7-
use riscv64::bindings::*;
7+
use crate::riscv64::bindings::*;
88

99
// There is no constant in the kernel as far as the maximum number
1010
// of registers on RISC-V, but KVM_GET_REG_LIST usually returns around 160.

kvm-bindings/src/riscv64/serialize.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// Copyright 2024 Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
// SPDX-License-Identifier: Apache-2.0
44

5-
use bindings::{
5+
use crate::bindings::{
66
kvm_irq_routing, kvm_irq_routing_entry, kvm_irq_routing_entry__bindgen_ty_1,
77
kvm_irq_routing_msi__bindgen_ty_1, kvm_mp_state, kvm_one_reg, kvm_riscv_aia_csr,
88
kvm_riscv_config, kvm_riscv_core, kvm_riscv_csr, kvm_riscv_sbi_sta, kvm_riscv_smstateen_csr,

kvm-bindings/src/x86_64/bindings.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ impl<T> __IncompleteArrayField<T> {
106106
}
107107
#[inline]
108108
pub unsafe fn as_slice(&self, len: usize) -> &[T] {
109-
::std::slice::from_raw_parts(self.as_ptr(), len)
109+
unsafe {::std::slice::from_raw_parts(self.as_ptr(), len)}
110110
}
111111
#[inline]
112112
pub unsafe fn as_mut_slice(&mut self, len: usize) -> &mut [T] {
113-
::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)
113+
unsafe {::std::slice::from_raw_parts_mut(self.as_mut_ptr(), len)}
114114
}
115115
}
116116
impl<T> ::std::fmt::Debug for __IncompleteArrayField<T> {
@@ -127,11 +127,11 @@ impl<T> __BindgenUnionField<T> {
127127
}
128128
#[inline]
129129
pub unsafe fn as_ref(&self) -> &T {
130-
::std::mem::transmute(self)
130+
unsafe {::std::mem::transmute(self)}
131131
}
132132
#[inline]
133133
pub unsafe fn as_mut(&mut self) -> &mut T {
134-
::std::mem::transmute(self)
134+
unsafe {::std::mem::transmute(self)}
135135
}
136136
}
137137
impl<T> ::std::default::Default for __BindgenUnionField<T> {
@@ -3408,7 +3408,7 @@ impl ::std::fmt::Debug for kvm_irq_level {
34083408
#[derive(Copy, Clone)]
34093409
#[cfg_attr(
34103410
feature = "serde",
3411-
derive(zerocopy::IntoBytes, zerocopy::Immutable, zerocopy::FromBytes)
3411+
derive(zerocopy::IntoBytes, zerocopy::Immutable)
34123412
)]
34133413
pub struct kvm_irqchip {
34143414
pub chip_id: __u32,
@@ -3417,7 +3417,7 @@ pub struct kvm_irqchip {
34173417
}
34183418
#[repr(C)]
34193419
#[derive(Copy, Clone)]
3420-
#[cfg_attr(feature = "serde", derive(zerocopy::TryFromBytes))]
3420+
#[cfg_attr(feature = "serde", derive(zerocopy::TryFromBytes, zerocopy::FromBytes))]
34213421
pub union kvm_irqchip__bindgen_ty_1 {
34223422
pub dummy: [::std::os::raw::c_char; 512usize],
34233423
pub pic: kvm_pic_state,

kvm-bindings/src/x86_64/fam_wrappers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
use vmm_sys_util::fam::{FamStruct, FamStructWrapper};
55

6-
use x86_64::bindings::*;
6+
use crate::x86_64::bindings::*;
77

88
/// Maximum number of CPUID entries that can be returned by a call to KVM ioctls.
99
///
@@ -202,7 +202,7 @@ mod tests {
202202
use crate::KvmIrqRouting;
203203

204204
use super::{CpuId, MsrList, Msrs, Xsave};
205-
use x86_64::bindings::kvm_cpuid_entry2;
205+
use crate::x86_64::bindings::kvm_cpuid_entry2;
206206

207207
use vmm_sys_util::fam::FamStruct;
208208

kvm-bindings/src/x86_64/nested.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
//! state save/resume. See [`KvmNestedStateBuffer`].
66
77
use core::mem;
8-
use KVM_STATE_NESTED_SVM_VMCB_SIZE;
9-
use {kvm_nested_state__bindgen_ty_1, KVM_STATE_NESTED_VMX_VMCS_SIZE};
8+
use crate::KVM_STATE_NESTED_SVM_VMCB_SIZE;
9+
use crate::{kvm_nested_state__bindgen_ty_1, KVM_STATE_NESTED_VMX_VMCS_SIZE};
1010

1111
/// Non-zero variant of the bindgen data union.
1212
///

0 commit comments

Comments
 (0)