diff options
author | Keir Fraser <keir@xen.org> | 2011-04-07 15:38:58 +0100 |
---|---|---|
committer | Keir Fraser <keir@xen.org> | 2011-04-07 15:38:58 +0100 |
commit | 19dcac71b39cb11f74b083dd5c9327362ea94476 (patch) | |
tree | c3b8b435eff9da2bb64d8b441a43bac1830c2ec3 | |
parent | 2ef45cea50771acdda79f97fa6f69431f6e4d0fb (diff) | |
download | xen-19dcac71b39cb11f74b083dd5c9327362ea94476.tar.gz xen-19dcac71b39cb11f74b083dd5c9327362ea94476.tar.bz2 xen-19dcac71b39cb11f74b083dd5c9327362ea94476.zip |
hvm save: Move some inline functions into common/hvm/save.c
Signed-off-by: Keir Fraser <keir@xen.org>
xen-unstable changeset: 22523:6dda9f988ef3
xen-unstable date: Wed Dec 15 10:15:45 2010 +0000
-rw-r--r-- | xen/common/hvm/save.c | 57 | ||||
-rw-r--r-- | xen/include/xen/hvm/save.h | 86 |
2 files changed, 81 insertions, 62 deletions
diff --git a/xen/common/hvm/save.c b/xen/common/hvm/save.c index 2e877ce18d..7a312dbfe8 100644 --- a/xen/common/hvm/save.c +++ b/xen/common/hvm/save.c @@ -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 diff --git a/xen/include/xen/hvm/save.h b/xen/include/xen/hvm/save.h index 49e9113493..8fc322d6e5 100644 --- a/xen/include/xen/hvm/save.h +++ b/xen/include/xen/hvm/save.h @@ -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? */ |