debuggers.hg

changeset 20871:49a2c1069e14

xend: Properly interpret vcpu_avail Long Integer in xc.hvm_build().

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Wed Jan 20 09:33:59 2010 +0000 (2010-01-20)
parents 07f95839e431
children b0b41e735575
files tools/python/xen/lowlevel/xc/xc.c
line diff
     1.1 --- a/tools/python/xen/lowlevel/xc/xc.c	Tue Jan 19 15:44:54 2010 +0000
     1.2 +++ b/tools/python/xen/lowlevel/xc/xc.c	Wed Jan 20 09:33:59 2010 +0000
     1.3 @@ -911,20 +911,46 @@ static PyObject *pyxc_hvm_build(XcObject
     1.4  #if !defined(__ia64__)
     1.5      struct hvm_info_table *va_hvm;
     1.6      uint8_t *va_map, sum;
     1.7 +#endif
     1.8      int i;
     1.9 -#endif
    1.10      char *image;
    1.11      int memsize, target=-1, vcpus = 1, acpi = 0, apic = 1;
    1.12 -    uint64_t vcpu_avail = 1;
    1.13 +    PyObject *vcpu_avail_handle = NULL;
    1.14 +    uint8_t vcpu_avail[HVM_MAX_VCPUS/8];
    1.15  
    1.16      static char *kwd_list[] = { "domid",
    1.17                                  "memsize", "image", "target", "vcpus", 
    1.18                                  "vcpu_avail", "acpi", "apic", NULL };
    1.19 -    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iilii", kwd_list,
    1.20 +    if ( !PyArg_ParseTupleAndKeywords(args, kwds, "iis|iiOii", kwd_list,
    1.21                                        &dom, &memsize, &image, &target, &vcpus,
    1.22 -                                      &vcpu_avail, &acpi, &apic) )
    1.23 +                                      &vcpu_avail_handle, &acpi, &apic) )
    1.24          return NULL;
    1.25  
    1.26 +    memset(vcpu_avail, 0, sizeof(vcpu_avail));
    1.27 +    vcpu_avail[0] = 1;
    1.28 +    if ( vcpu_avail_handle != NULL )
    1.29 +    {
    1.30 +        if ( PyInt_Check(vcpu_avail_handle) )
    1.31 +        {
    1.32 +            unsigned long v = PyInt_AsLong(vcpu_avail_handle);
    1.33 +            for ( i = 0; i < sizeof(long)/8; i++ )
    1.34 +                vcpu_avail[i] = (uint8_t)(v>>(i*8));
    1.35 +        }
    1.36 +        else if ( PyLong_Check(vcpu_avail_handle) )
    1.37 +        {
    1.38 +            if ( _PyLong_AsByteArray((PyLongObject *)vcpu_avail_handle,
    1.39 +                                     (unsigned char *)vcpu_avail,
    1.40 +                                     sizeof(vcpu_avail), 1, 0) )
    1.41 +                return NULL;
    1.42 +        }
    1.43 +        else
    1.44 +        {
    1.45 +            errno = EINVAL;
    1.46 +            PyErr_SetFromErrno(xc_error_obj);
    1.47 +            return NULL;
    1.48 +        }
    1.49 +    }
    1.50 +
    1.51      if ( target == -1 )
    1.52          target = memsize;
    1.53  
    1.54 @@ -943,8 +969,7 @@ static PyObject *pyxc_hvm_build(XcObject
    1.55      va_hvm->acpi_enabled = acpi;
    1.56      va_hvm->apic_mode    = apic;
    1.57      va_hvm->nr_vcpus     = vcpus;
    1.58 -    ((uint64_t *)va_hvm->vcpu_online)[0] = vcpu_avail;
    1.59 -    ((uint64_t *)va_hvm->vcpu_online)[1] = 0;    
    1.60 +    memcpy(va_hvm->vcpu_online, vcpu_avail, sizeof(vcpu_avail));
    1.61      for ( i = 0, sum = 0; i < va_hvm->length; i++ )
    1.62          sum += ((uint8_t *)va_hvm)[i];
    1.63      va_hvm->checksum -= sum;