aboutsummaryrefslogtreecommitdiffstats
path: root/xen/arch/x86/hvm/vpic.c
diff options
context:
space:
mode:
authorTim Deegan <Tim.Deegan@xensource.com>2007-01-31 10:27:10 +0000
committerTim Deegan <Tim.Deegan@xensource.com>2007-01-31 10:27:10 +0000
commit674ccf326621592d655c3137cb2799a815857c58 (patch)
tree4001252fea388d4e27db25a2cab94b974b78be61 /xen/arch/x86/hvm/vpic.c
parentff0b3cef8ddd22fa2cce178c2bc894a966f8a0bb (diff)
downloadxen-674ccf326621592d655c3137cb2799a815857c58.tar.gz
xen-674ccf326621592d655c3137cb2799a815857c58.tar.bz2
xen-674ccf326621592d655c3137cb2799a815857c58.zip
[HVM] Save/restore: clean up marshalling code
- All entries are now defined as structs and saved/restored in self-contained operations. - Save/restore operations are type-safe, to tie each entry's typecode to a particular struct and its length. - Save/restore handlers are registered once per host instead of per domain. - Detect buffer overrun before it happens and abort. Signed-off-by: Tim Deegan <Tim.Deegan@xensource.com>
Diffstat (limited to 'xen/arch/x86/hvm/vpic.c')
-rw-r--r--xen/arch/x86/hvm/vpic.c39
1 files changed, 27 insertions, 12 deletions
diff --git a/xen/arch/x86/hvm/vpic.c b/xen/arch/x86/hvm/vpic.c
index 290b5f3129..41e3ed11a4 100644
--- a/xen/arch/x86/hvm/vpic.c
+++ b/xen/arch/x86/hvm/vpic.c
@@ -404,27 +404,44 @@ static void vpic_info(struct hvm_hw_vpic *s)
}
#endif
-static void vpic_save(hvm_domain_context_t *h, void *opaque)
+static int vpic_save(struct domain *d, hvm_domain_context_t *h)
{
- struct hvm_hw_vpic *s = opaque;
-
- vpic_info(s);
- hvm_put_struct(h, s);
+ struct hvm_hw_vpic *s;
+ int i;
+
+ /* Save the state of both PICs */
+ for ( i = 0; i < 2 ; i++ )
+ {
+ s = &d->arch.hvm_domain.vpic[i];
+ vpic_info(s);
+ if ( hvm_save_entry(PIC, i, h, s) )
+ return 1;
+ }
+
+ return 0;
}
-static int vpic_load(hvm_domain_context_t *h, void *opaque, int version_id)
+static int vpic_load(struct domain *d, hvm_domain_context_t *h)
{
- struct hvm_hw_vpic *s = opaque;
+ struct hvm_hw_vpic *s;
+ uint16_t inst;
- if (version_id != 1)
+ /* Which PIC is this? */
+ inst = hvm_load_instance(h);
+ if ( inst > 1 )
return -EINVAL;
+ s = &d->arch.hvm_domain.vpic[inst];
- hvm_get_struct(h, s);
- vpic_info(s);
+ /* Load the state */
+ if ( hvm_load_entry(PIC, h, s) != 0 )
+ return -EINVAL;
+ vpic_info(s);
return 0;
}
+HVM_REGISTER_SAVE_RESTORE(PIC, vpic_save, vpic_load);
+
void vpic_init(struct domain *d)
{
struct hvm_hw_vpic *vpic;
@@ -434,14 +451,12 @@ void vpic_init(struct domain *d)
memset(vpic, 0, sizeof(*vpic));
vpic->is_master = 1;
vpic->elcr = 1 << 2;
- hvm_register_savevm(d, "xen_hvm_i8259", 0x20, 1, vpic_save, vpic_load, vpic);
register_portio_handler(d, 0x20, 2, vpic_intercept_pic_io);
register_portio_handler(d, 0x4d0, 1, vpic_intercept_elcr_io);
/* Slave PIC. */
vpic++;
memset(vpic, 0, sizeof(*vpic));
- hvm_register_savevm(d, "xen_hvm_i8259", 0xa0, 1, vpic_save, vpic_load, vpic);
register_portio_handler(d, 0xa0, 2, vpic_intercept_pic_io);
register_portio_handler(d, 0x4d1, 1, vpic_intercept_elcr_io);
}