qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 3/7] migration: Document the effect of vmstate_info_nullptr


From: Fabiano Rosas
Subject: [PATCH 3/7] migration: Document the effect of vmstate_info_nullptr
Date: Tue, 7 Jan 2025 16:50:21 -0300

The migration stream lacks magic numbers at some key points. It's easy
to mis-parse data. Unfortunately, the VMS_NULLPTR_MARKER continues
with the trend. A '0' byte is ambiguous and could be interpreted as a
valid 0x30.

It is maybe not worth trying to change this while keeping backward
compatibility, so add some words of documentation to clarify.

Signed-off-by: Fabiano Rosas <farosas@suse.de>
---
 migration/vmstate-types.c    | 6 ++++++
 scripts/analyze-migration.py | 9 +++++++++
 2 files changed, 15 insertions(+)

diff --git a/migration/vmstate-types.c b/migration/vmstate-types.c
index e83bfccb9e..08ed059f87 100644
--- a/migration/vmstate-types.c
+++ b/migration/vmstate-types.c
@@ -339,6 +339,12 @@ static int put_nullptr(QEMUFile *f, void *pv, size_t size,
 
 const VMStateInfo vmstate_info_nullptr = {
     .name = "uint64",
+
+     /*
+      * Ideally these would actually read/write the size of a pointer,
+      * but we're stuck with just a byte now for backward
+      * compatibility.
+      */
     .get  = get_nullptr,
     .put  = put_nullptr,
 };
diff --git a/scripts/analyze-migration.py b/scripts/analyze-migration.py
index f2457b1dde..4292fde424 100755
--- a/scripts/analyze-migration.py
+++ b/scripts/analyze-migration.py
@@ -388,12 +388,21 @@ def read(self):
         return self.data
 
 class VMSDFieldUInt(VMSDFieldInt):
+    NULL_PTR_MARKER = 0x30
+
     def __init__(self, desc, file):
         super(VMSDFieldUInt, self).__init__(desc, file)
 
     def read(self):
         super(VMSDFieldUInt, self).read()
         self.data = self.udata
+
+        if self.data == self.NULL_PTR_MARKER:
+            # The migration stream encodes NULL pointers as '0' so any
+            # 0x30 in the stream could be a NULL. There's not much we
+            # can do without breaking backward compatibility.
+            pass
+
         return self.data
 
 class VMSDFieldIntLE(VMSDFieldInt):
-- 
2.35.3




reply via email to

[Prev in Thread] Current Thread [Next in Thread]