qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH 17/23] Add VMState support for static sized buffers


From: Juan Quintela
Subject: [Qemu-devel] [PATCH 17/23] Add VMState support for static sized buffers (uint_8)
Date: Thu, 20 Aug 2009 19:42:35 +0200

This patch adds support for static sized buffer and typecheks that the buffer 
is right.

Signed-off-by: Juan Quintela <address@hidden>
---
 hw/hw.h  |   18 ++++++++++++++++++
 savevm.c |   21 +++++++++++++++++++++
 2 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/hw/hw.h b/hw/hw.h
index 911ab6f..4713967 100644
--- a/hw/hw.h
+++ b/hw/hw.h
@@ -284,6 +284,7 @@ enum VMStateFlags {
     VMS_ARRAY   = 0x004,
     VMS_STRUCT  = 0x008,
     VMS_VARRAY  = 0x010,  /* Array with size in another field */
+    VMS_BUFFER  = 0x020,  /* static sized buffer */
 };

 typedef struct {
@@ -320,6 +321,7 @@ extern const VMStateInfo vmstate_info_uint32;
 extern const VMStateInfo vmstate_info_uint64;

 extern const VMStateInfo vmstate_info_timer;
+extern const VMStateInfo vmstate_info_buffer;

 #define type_check_array(t1,t2,n) ((t1(*)[n])0 - (t2*)0)
 #define type_check_pointer(t1,t2) ((t1**)0 - (t2*)0)
@@ -388,6 +390,16 @@ extern const VMStateInfo vmstate_info_timer;
         + type_check_array(_type,typeof_field(_state, _field),_num)  \
 }

+#define VMSTATE_STATIC_BUFFER(_field, _state, _version) {            \
+    .name       = (stringify(_field)),                               \
+    .version_id = (_version),                                        \
+    .size       = sizeof(typeof_field(_state,_field)),               \
+    .info       = &vmstate_info_buffer,                              \
+    .flags      = VMS_BUFFER,                                        \
+    .offset     = offsetof(_state, _field)                           \
+        + type_check_array(uint8_t,typeof_field(_state, 
_field),sizeof(typeof_field(_state,_field))) \
+}
+
 /* _f : field name
    _f_n : num of elements field_name
    _n : num of elements
@@ -458,6 +470,12 @@ extern const VMStateInfo vmstate_info_timer;
 #define VMSTATE_INT32_VARRAY(_f, _s, _f_n)                            \
     VMSTATE_INT32_VARRAY_V(_f, _s, _f_n, 0)

+#define VMSTATE_BUFFER_V(_f, _s, _v)                                  \
+    VMSTATE_STATIC_BUFFER(_f, _s, _v)
+
+#define VMSTATE_BUFFER(_f, _s)                                        \
+    VMSTATE_STATIC_BUFFER(_f, _s, 0)
+
 #define VMSTATE_END_OF_LIST()                                         \
     {}

diff --git a/savevm.c b/savevm.c
index 721bbf4..1b448b9 100644
--- a/savevm.c
+++ b/savevm.c
@@ -819,6 +819,27 @@ const VMStateInfo vmstate_info_timer = {
     .put  = put_timer,
 };

+/* uint8_t buffers */
+
+static int get_buffer(QEMUFile *f, void *pv, size_t size)
+{
+    uint8_t *v = pv;
+    qemu_get_buffer(f, v, size);
+    return 0;
+}
+
+static void put_buffer(QEMUFile *f, const void *pv, size_t size)
+{
+    uint8_t *v = (void *)pv;
+    qemu_put_buffer(f, v, size);
+}
+
+const VMStateInfo vmstate_info_buffer = {
+    .name = "buffer",
+    .get  = get_buffer,
+    .put  = put_buffer,
+};
+
 typedef struct SaveStateEntry {
     char idstr[256];
     int instance_id;
-- 
1.6.2.5





reply via email to

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