Skip to content

Correct binding for WHV_UINT128 #766

Open
@benpye

Description

@benpye

Hey,

I'm currently working on binding the Windows Hypervisor Platform APIs (doc).

There is a type WHV_UINT128 which is defined as a struct, aligned on a 16 byte boundary,

typedef union DECLSPEC_ALIGN(16) WHV_UINT128
{
    struct
    {
        UINT64  Low64;
        UINT64  High64;
    };

    UINT32  Dword[4];
} WHV_UINT128;

The difficulty here is that this type is used in a union with a bitfield hence my initial attempt did not work, see below:

STRUCT!{struct WHV_UINT128_s {
    Low64: UINT64,
    High64: UINT64,
}}
UNION!{union WHV_UINT128 {
    [u128; 1],
    s s_mut: WHV_UINT128_s,
    Dword Dword_mut: [UINT32; 4],
}}
STRUCT!{struct WHV_X64_FP_REGISTER {
    AsUINT128: WHV_UINT128,
}}
BITFIELD!{WHV_X64_FP_REGISTER AsUINT128: WHV_UINT128 [
    Mantissa set_Mantissa[0..64],
    BiasedExponent set_BiasedExponent[64..79],
    Sign set_Sign[79..80],
    Reserved set_Reserved[80..128],
]}

My naïve solution for this was to define WHV_UINT128 as u128 - this seemed to make the most logical sense, and results in the bitfield working.

Is there a preferred way forward here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugAny sort of bugwaiting for 0.4This issue will be fixed in 0.4

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions