}
int _hvm_check_entry(struct hvm_domain_context *h,
- uint16_t type, uint32_t len)
+ uint16_t type, uint32_t len, bool_t strict_length)
{
struct hvm_save_descriptor *d
= (struct hvm_save_descriptor *)&h->data[h->cur];
"for type %u\n", len, type);
return -1;
}
- if ( (type != d->typecode) || (len != d->length) )
+ if ( (type != d->typecode) || (len < d->length) ||
+ (strict_length && (len != d->length)) )
{
gdprintk(XENLOG_WARNING,
"HVM restore mismatch: expected type %u length %u, "
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;
+ struct hvm_save_descriptor *d
+ = (struct hvm_save_descriptor *)&h->data[h->cur - sizeof(*d)];
+ BUG_ON(d->length > dest_len);
+ memcpy(dest, &h->data[h->cur], d->length);
+ if ( d->length < dest_len )
+ memset((char *)dest + d->length, 0, dest_len - d->length);
+ h->cur += d->length;
}
/*
/* Unmarshalling: test an entry's size and typecode and record the instance */
int _hvm_check_entry(struct hvm_domain_context *h,
- uint16_t type, uint32_t len);
+ uint16_t type, uint32_t len, bool_t strict_length);
/* Unmarshalling: copy the contents in a type-safe way */
void _hvm_read_entry(struct hvm_domain_context *h,
* 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)); \
+#define _hvm_load_entry(_x, _h, _dst, _strict) ({ \
+ int r; \
+ r = _hvm_check_entry((_h), HVM_SAVE_CODE(_x), \
+ HVM_SAVE_LENGTH(_x), (_strict)); \
+ if ( r == 0 ) \
+ _hvm_read_entry((_h), (_dst), HVM_SAVE_LENGTH(_x)); \
r; })
+#define hvm_load_entry(_x, _h, _dst) \
+ _hvm_load_entry(_x, _h, _dst, 1)
+#define hvm_load_entry_zeroextend(_x, _h, _dst) \
+ _hvm_load_entry(_x, _h, _dst, 0)
/* Unmarshalling: what is the instance ID of the next entry? */
static inline uint16_t hvm_load_instance(struct hvm_domain_context *h)