Re: virDomainInfo marshalling prolem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2010/10/29 Daniel P. Berrange <berrange@xxxxxxxxxx>:
> On Fri, Oct 29, 2010 at 04:19:22PM +0200, Matthias Bolte wrote:
>> 2010/10/29 Â<arnaud.champion@xxxxxxxxxx>:
>> > Hi,
>> >
>> > I am working on the marshaling of the virDomainInfo structure. I have
>> > marshalled it in this way :
>> >
>> >
>> > ///
>> >
>> > <summary>
>> >
>> > /// Structure to handle domain informations
>> >
>> > /// </summary>
>> >
>> > [
>> >
>> > StructLayout(LayoutKind.Sequential)]
>> >
>> > public class DomainInfo
>> >
>> > {
>> >
>> > ÂÂÂÂ/// <summary>
>> > ÂÂÂÂ/// The running state, one of virDomainState.
>> > ÂÂÂÂ/// </summary>
>> > ÂÂÂÂprivate Byte state;
>> > ÂÂÂÂ/// <summary>
>> > ÂÂÂÂ/// The maximum memory in KBytes allowed.
>> > ÂÂÂÂ/// </summary>
>> > ÂÂÂÂpublic int maxMem;
>> > ÂÂÂÂ/// <summary>
>> > ÂÂÂÂ/// The memory in KBytes used by the domain.
>> > ÂÂÂÂ/// </summary>
>> > ÂÂÂÂpublic int memory;
>> > ÂÂÂÂ/// <summary>
>> > ÂÂÂÂ/// The number of virtual CPUs for the domain.
>> > ÂÂÂÂ/// </summary>
>> > ÂÂÂÂpublic short nrVirtCpu;
>> > ÂÂÂÂ/// <summary>
>> > ÂÂÂÂ/// The CPU time used in nanoseconds.
>> > ÂÂÂÂ/// </summary>
>> > ÂÂÂÂpublic long cpuTime;
>> > ÂÂÂÂ/// <summary>
>> > ÂÂÂÂ/// The running state, one of virDomainState.
>> > ÂÂÂÂ/// </summary>
>> > ÂÂÂÂpublic DomainState State { get { return (DomainState)state; } }
>> >
>> > }
>> >
>> > It work fine in 32 bits, but not in 64 bits, it seems that packing in 64
>> > bits is different so infos are not in order. Am I right ?
>> >
>>
>> In the struct looks like this
>>
>> struct _virDomainInfo {
>> Â Â unsigned char state; Â Â Â Â/* the running state, one of virDomainState */
>> Â Â unsigned long maxMem; Â Â Â /* the maximum memory in KBytes allowed */
>> Â Â unsigned long memory; Â Â Â /* the memory in KBytes used by the domain */
>> Â Â unsigned short nrVirtCpu; Â /* the number of virtual CPUs for the domain */
>> Â Â unsigned long long cpuTime; /* the CPU time used in nanoseconds */
>> };
>>
>> but you mapped unsigned long to int. First of all you should map this
>> to an unsigned type. You also lost the unsigned for some other
>> members.
>>
>> The problem probably is that long in C is 32bit on a 32bit platform an
>> 64bit on a 64bit platform. You mapped it to int that is always 32bit
>> in C#, when I looked it up correctly.
>
> Not quite. Windows just had to do things diffrently on 64-bit and so used
> the LLP64 model instead of LP64 used by the rest of the world :-(
>
> Âhttp://technet.microsoft.com/en-us/library/bb496995.aspx
>
> ÂIn the UNIX/64 data model:
> Â Â ÂThe size of int is 32 bits and the size of long and pointers is 64 bits.
>
> ÂIn the Win64 model:
> Â Â ÂThe size of int and long is 32 bits; the size of int64 (new type) and pointers is 64 bits.
>
> Regards,
> Daniel
>

Ah yes. I forgot about that one. So this gets even more complicated
when you want to get the C# bindings working on 32 and 64 bit Windows
and Linux.

Matthias

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]