Skip to content

Commit 2079706

Browse files
trueptolemybonzini
authored andcommitted
rust/vmstate: Fix size field of VMStateField with VMS_ARRAY_OF_POINTER flag
The `size` field of the VMStateField with VMS_ARRAY_OF_POINTER flag should stores the size of pointer, which depends on platform. Currently, `*const`, `*mut`, `NonNull`, `Box<>` and their wrapper are supported, and they have the same size as `usize`. Store the size (of `usize`) when VMS_ARRAY_OF_POINTER flag is set. The size may be changed when more smart pointers are supported, but now the size of "usize" is enough. Signed-off-by: Zhao Liu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Paolo Bonzini <[email protected]>
1 parent c3d80af commit 2079706

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

rust/qemu-api/src/vmstate.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,10 @@ impl VMStateField {
256256
if (self.flags.0 & VMStateFlags::VMS_POINTER.0) != 0 {
257257
self.flags = VMStateFlags(self.flags.0 & !VMStateFlags::VMS_POINTER.0);
258258
self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_ARRAY_OF_POINTER.0);
259+
// VMS_ARRAY_OF_POINTER flag stores the size of pointer.
260+
// FIXME: *const, *mut, NonNull and Box<> have the same size as usize.
261+
// Resize if more smart pointers are supported.
262+
self.size = std::mem::size_of::<usize>();
259263
}
260264
self.flags = VMStateFlags(self.flags.0 & !VMStateFlags::VMS_SINGLE.0);
261265
self.flags = VMStateFlags(self.flags.0 | VMStateFlags::VMS_ARRAY.0);

0 commit comments

Comments
 (0)