]> xenbits.xensource.com Git - people/vhanquez/xen.git/commitdiff
hvm save: Move some inline functions into common/hvm/save.c
authorKeir Fraser <keir@xen.org>
Thu, 7 Apr 2011 14:38:58 +0000 (15:38 +0100)
committerKeir Fraser <keir@xen.org>
Thu, 7 Apr 2011 14:38:58 +0000 (15:38 +0100)
Signed-off-by: Keir Fraser <keir@xen.org>
xen-unstable changeset:   22523:6dda9f988ef3
xen-unstable date:        Wed Dec 15 10:15:45 2010 +0000

xen/common/hvm/save.c
xen/include/xen/hvm/save.h

index 2e877ce18d995098c79aa311afb55fdd29f40c97..7a312dbfe8cfb3d0a2dc2f54fee1d2ace372ae0b 100644 (file)
@@ -244,6 +244,63 @@ int hvm_load(struct domain *d, hvm_domain_context_t *h)
     /* Not reached */
 }
 
+int _hvm_init_entry(struct hvm_domain_context *h,
+                    uint16_t tc, uint16_t inst, uint32_t len)
+{
+    struct hvm_save_descriptor *d 
+        = (struct hvm_save_descriptor *)&h->data[h->cur];
+    if ( h->size - h->cur < len + sizeof (*d) )
+    {
+        gdprintk(XENLOG_WARNING,
+                 "HVM save: no room for %"PRIu32" + %u bytes "
+                 "for typecode %"PRIu16"\n",
+                 len, (unsigned) sizeof (*d), tc);
+        return -1;
+    }
+    d->typecode = tc;
+    d->instance = inst;
+    d->length = len;
+    h->cur += sizeof(*d);
+    return 0;
+}
+
+void _hvm_write_entry(struct hvm_domain_context *h,
+                      void *src, uint32_t src_len)
+{
+    memcpy(&h->data[h->cur], src, src_len);
+    h->cur += src_len;
+}
+
+int _hvm_check_entry(struct hvm_domain_context *h, 
+                     uint16_t type, uint32_t len)
+{
+    struct hvm_save_descriptor *d 
+        = (struct hvm_save_descriptor *)&h->data[h->cur];
+    if ( len + sizeof (*d) > h->size - h->cur)
+    {
+        gdprintk(XENLOG_WARNING, 
+                 "HVM restore: not enough data left to read %u bytes "
+                 "for type %u\n", len, type);
+        return -1;
+    }    
+    if ( (type != d->typecode) || (len != d->length) )
+    {
+        gdprintk(XENLOG_WARNING, 
+                 "HVM restore mismatch: expected type %u length %u, "
+                 "saw type %u length %u\n", type, len, d->typecode, d->length);
+        return -1;
+    }
+    h->cur += sizeof(*d);
+    return 0;
+}
+
+void _hvm_read_entry(struct hvm_domain_context *h,
+                     void *dest, uint32_t dest_len)
+{
+    memcpy(dest, &h->data[h->cur], dest_len);
+    h->cur += dest_len;
+}
+
 /*
  * Local variables:
  * mode: C
index 49e9113493b1c676d0bb28a027c3f1088bd19d46..8fc322d6e53ee37410bf9d6586766526d8b40256 100644 (file)
@@ -30,77 +30,39 @@ typedef struct hvm_domain_context {
 } hvm_domain_context_t;
 
 /* Marshalling an entry: check space and fill in the header */
-static inline int _hvm_init_entry(struct hvm_domain_context *h,
-                                  uint16_t tc, uint16_t inst, uint32_t len)
-{
-    struct hvm_save_descriptor *d 
-        = (struct hvm_save_descriptor *)&h->data[h->cur];
-    if ( h->size - h->cur < len + sizeof (*d) )
-    {
-        gdprintk(XENLOG_WARNING,
-                 "HVM save: no room for %"PRIu32" + %u bytes "
-                 "for typecode %"PRIu16"\n",
-                 len, (unsigned) sizeof (*d), tc);
-        return -1;
-    }
-    d->typecode = tc;
-    d->instance = inst;
-    d->length = len;
-    h->cur += sizeof (*d);
-    return 0;
-}
+int _hvm_init_entry(struct hvm_domain_context *h,
+                    uint16_t tc, uint16_t inst, uint32_t len);
 
 /* Marshalling: copy the contents in a type-safe way */
-#define _hvm_write_entry(_x, _h, _src) do {                     \
-    *(HVM_SAVE_TYPE(_x) *)(&(_h)->data[(_h)->cur]) = *(_src);   \
-    (_h)->cur += HVM_SAVE_LENGTH(_x);                           \
-} while (0)
+void _hvm_write_entry(struct hvm_domain_context *h,
+                      void *src, uint32_t src_len);
 
 /* Marshalling: init and copy; evaluates to zero on success */
-#define hvm_save_entry(_x, _inst, _h, _src) ({          \
-    int r;                                              \
-    r = _hvm_init_entry((_h), HVM_SAVE_CODE(_x),        \
-                        (_inst), HVM_SAVE_LENGTH(_x));  \
-    if ( r == 0 )                                       \
-        _hvm_write_entry(_x, (_h), (_src));             \
+#define hvm_save_entry(_x, _inst, _h, _src) ({                  \
+    int r;                                                      \
+    r = _hvm_init_entry((_h), HVM_SAVE_CODE(_x),                \
+                        (_inst), HVM_SAVE_LENGTH(_x));          \
+    if ( r == 0 )                                               \
+        _hvm_write_entry((_h), (_src), HVM_SAVE_LENGTH(_x));    \
     r; })
 
 /* Unmarshalling: test an entry's size and typecode and record the instance */
-static inline int _hvm_check_entry(struct hvm_domain_context *h, 
-                                   uint16_t type, uint32_t len)
-{
-    struct hvm_save_descriptor *d 
-        = (struct hvm_save_descriptor *)&h->data[h->cur];
-    if ( len + sizeof (*d) > h->size - h->cur)
-    {
-        gdprintk(XENLOG_WARNING, 
-                 "HVM restore: not enough data left to read %u bytes "
-                 "for type %u\n", len, type);
-        return -1;
-    }    
-    if ( type != d->typecode || len != d->length )
-    {
-        gdprintk(XENLOG_WARNING, 
-                 "HVM restore mismatch: expected type %u length %u, "
-                 "saw type %u length %u\n", type, len, d->typecode, d->length);
-        return -1;
-    }
-    h->cur += sizeof (*d);
-    return 0;
-}
+int _hvm_check_entry(struct hvm_domain_context *h, 
+                     uint16_t type, uint32_t len);
 
 /* Unmarshalling: copy the contents in a type-safe way */
-#define _hvm_read_entry(_x, _h, _dst) do {                      \
-    *(_dst) = *(HVM_SAVE_TYPE(_x) *) (&(_h)->data[(_h)->cur]);  \
-    (_h)->cur += HVM_SAVE_LENGTH(_x);                           \
-} while (0)
-
-/* Unmarshalling: check, then copy. Evaluates to zero on success. */
-#define hvm_load_entry(_x, _h, _dst) ({                                 \
-    int r;                                                              \
-    r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x), HVM_SAVE_LENGTH(_x)); \
-    if ( r == 0 )                                                       \
-        _hvm_read_entry(_x, (_h), (_dst));                              \
+void _hvm_read_entry(struct hvm_domain_context *h,
+                     void *dest, uint32_t dest_len);
+
+/*
+ * Unmarshalling: check, then copy. Evaluates to zero on success. This load
+ * function requires the save entry to be the same size as the dest structure.
+ */
+#define hvm_load_entry(_x, _h, _dst) ({                                    \
+    int r;                                                                 \
+    r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x), HVM_SAVE_LENGTH(_x));    \
+    if ( r == 0 )                                                          \
+        _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x));                \
     r; })
 
 /* Unmarshalling: what is the instance ID of the next entry? */