From nobody Tue Nov 11 07:27:24 2025 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1570461353; cv=none; d=zoho.com; s=zohoarc; b=LbQMPK3ayqbgEG6bwfLlWmpjBAyiazIB1jwFPGh2CGqQptbzP0QaEXT40uddrIXW1VDoYce2kV/acfar9iJv0bzj1KNkle0tteB7Htr+ka707WYT7x6AKleru8c/VtaFhXzFip748/pnDFCbZpcbFGhSwIO3z+STuwz6VBcG+hE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570461353; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To:ARC-Authentication-Results; bh=chwHxnu9KC4ZmOrweoe6u97zUl7bhzE2aqWaAntqjl4=; b=RC8LMTuW7bHWmoAdQQrEpWzZ7QqB50onfMxLDwzR2i7tgxLV9bTct5Im8oXRFrI13HmztwkbP/v2h4zFlPZPq4gqgRhG65FRDx4f0VrVpperTkH13kNECPlkOFUqwSD7hhYArzpoCJcye6qLam1W/xZiB/zAwFxPqOMqKyaTaxw= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=fail; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1570461353794363.5414505454561; Mon, 7 Oct 2019 08:15:53 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUig-0007Tn-9U; Mon, 07 Oct 2019 15:14:42 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUif-0007TH-PO for xen-devel@lists.xenproject.org; Mon, 07 Oct 2019 15:14:41 +0000 Received: from mail-qk1-x741.google.com (unknown [2607:f8b0:4864:20::741]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 0903c88c-e915-11e9-8c93-bc764e2007e4; Mon, 07 Oct 2019 15:13:36 +0000 (UTC) Received: by mail-qk1-x741.google.com with SMTP id y144so12884170qkb.7 for ; Mon, 07 Oct 2019 08:13:36 -0700 (PDT) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id c185sm8354313qkg.74.2019.10.07.08.13.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:13:35 -0700 (PDT) X-Inumbo-ID: 0903c88c-e915-11e9-8c93-bc764e2007e4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2UsVtpDQx/GH4g6WuhNNT23rnCC0Le6n0pIDIcnnL7E=; b=JPttCl18A2aeL7ecgvuDjTs+fu/4pjUneLYmn0jRfWopDZiJRP5w4xyQukEZZvRZkg rwl5EluI9NLPOdjOYu361X8No0S3CgzS1judKDgjX1Fm5gl3fJTPmCqzAsxBnXRVO6vt BP0KzPwxHSTrL3NmqZwEob1OxfYm8phF93Fs91WW0A5pKXRJkbFELmRG/YvZTewQgiFg wBHXjjrOBozpIZV8LdRoYly8hxPL8FIgTmqWlWvb5AgiT4RjDge0twfhr6q0QEBnyyCf tc7ibV7Sm6JoIe+dZaMDpjKtM5x5rwIHLW+vpOdzeRQU4O5Qc4b+zy0/2lsmfyQnHTvq vYXA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2UsVtpDQx/GH4g6WuhNNT23rnCC0Le6n0pIDIcnnL7E=; b=rZc0Ss7f7iibdITorRVhkQvJWognPuXlcfjIaMKdht5iWVDssIU8x4ad25JGOrGq9g BJlVPZRhRWr7Jp6SJem5C7/1IutwiPeSTvpguOEolG2enfO6kcDfAfBtxv36Wj9Tv7/k eopVXAcOJ3WGboMI3MmwTnvFRl+yUGDpdFPZI0NTvZA0sBjXeDiT3R0KuoKEfyl/RSkw W4OOfy1O5sCqEvieNnBa3Lc65J0uS2r0CjoT4dsCx/6pMdOVljJvs86wiEU1ULrtu9e0 mJpj3udBls8NXgd4xXLBteUBLq5Xx+OMSVh73YCDi+1iFdzS5JVs8osHBYIKCQinvWH7 Mqxg== X-Gm-Message-State: APjAAAWq1Ju+dYbxaujZdjGSkL2B7k0DWZzQ466OntKmH4KbtZsDkUil 0CXp0GiKIqZiiPIFw+2xriG0FMxH X-Google-Smtp-Source: APXvYqwwXRCa1SmAcZN/CpupkYP3KVbGMdJVKIo297Fs/nk4B+hNA3vMU16k5gcZpJBARd3PT+xQYA== X-Received: by 2002:a37:a709:: with SMTP id q9mr23157083qke.135.1570461215790; Mon, 07 Oct 2019 08:13:35 -0700 (PDT) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 7 Oct 2019 11:13:04 -0400 Message-Id: <1e92395f2f4ef59a1a4e9f3c6b926182ba113653.1570456846.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 17/24] golang/xenlight: implement keyed union C to Go marshaling X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Nick Rosbrook , Ian Jackson , kerriganb@ainfosec.com, George Dunlap , Wei Liu Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) From: Nick Rosbrook Switch over union key to determine how to populate 'union' in Go struct. Since the unions of C types cannot be directly accessed, add C structs in cgo preamble to assist in marshaling keyed unions. This allows the C type defined in the preamble to be populated first, and then accessed directly to populate the Go struct. Signed-off-by: Nick Rosbrook --- Cc: George Dunlap Cc: Ian Jackson Cc: Wei Liu tools/golang/xenlight/gengotypes.py | 136 ++++++- tools/golang/xenlight/xenlight_helpers.go | 440 ++++++++++++++++++++++ 2 files changed, 575 insertions(+), 1 deletion(-) diff --git a/tools/golang/xenlight/gengotypes.py b/tools/golang/xenlight/ge= ngotypes.py index 75dcd01724..ececaafd72 100644 --- a/tools/golang/xenlight/gengotypes.py +++ b/tools/golang/xenlight/gengotypes.py @@ -28,6 +28,14 @@ go_builtin_types =3D ['bool', 'string', 'int', 'byte', # after a struct definition. type_extras =3D [] =20 +# cgo preamble for xenlight_helpers.go, created during type generation and +# written later. +cgo_helpers_preamble =3D [] + +# List of strings that need to be written to a file +# after a helper func definition. +helper_extras =3D [] + def xenlight_golang_generate_types(path =3D None, types =3D None, comment = =3D None): """ Generate a .go file (xenlight_types.go by default) @@ -159,6 +167,8 @@ def xenlight_golang_define_union(ty =3D None, structnam= e =3D ''): s =3D xenlight_golang_define_struct(f.type, typename=3Dname) type_extras.append(s) =20 + xenlight_golang_union_cgo_preamble(f.type, name=3Dname) + # Define function to implement 'union' interface name =3D xenlight_golang_fmt_name(name) s =3D 'func (x {}) is{}(){{}}\n'.format(name, interface_name) @@ -174,6 +184,18 @@ def xenlight_golang_define_union(ty =3D None, structna= me =3D ''): =20 return s =20 +def xenlight_golang_union_cgo_preamble(ty =3D None, name =3D ''): + s =3D '' + + s +=3D 'typedef struct {} {{\n'.format(name) + + for f in ty.fields: + s +=3D '\t{} {};\n'.format(f.type.typename, f.name) + + s +=3D '}} {};\n'.format(name) + + cgo_helpers_preamble.append(s) + def xenlight_golang_generate_helpers(path =3D None, types =3D None, commen= t =3D None): """ Generate a .go file (xenlight_helpers.go by default) @@ -187,6 +209,7 @@ def xenlight_golang_generate_helpers(path =3D None, typ= es =3D None, comment =3D None): if comment is not None: f.write(comment) f.write('package xenlight\n') + f.write('import (\n"unsafe"\n"errors"\n"fmt"\n)\n') =20 # Cgo preamble f.write('/*\n') @@ -195,6 +218,10 @@ def xenlight_golang_generate_helpers(path =3D None, ty= pes =3D None, comment =3D None): f.write('#include \n') f.write('\n') =20 + for s in cgo_helpers_preamble: + f.write(s) + f.write('\n') + f.write('*/\nimport "C"\n') =20 for ty in types: @@ -204,6 +231,12 @@ def xenlight_golang_generate_helpers(path =3D None, ty= pes =3D None, comment =3D None): f.write(xenlight_golang_define_from_C(ty)) f.write('\n') =20 + for extra in helper_extras: + f.write(extra) + f.write('\n') + + del helper_extras[:] + go_fmt(path) =20 def xenlight_golang_define_from_C(ty =3D None, typename =3D None, nested = =3D False): @@ -275,7 +308,7 @@ def xenlight_golang_define_from_C(ty =3D None, typename= =3D None, nested =3D False): s +=3D xenlight_golang_define_from_C(f.type, typename=3Df.name= , nested=3DTrue) =20 elif isinstance(f.type, idl.KeyedUnion): - pass + s +=3D xenlight_golang_union_from_C(f.type, f.name, ty.typenam= e) =20 else: raise Exception('type {} not supported'.format(f.type)) @@ -286,6 +319,107 @@ def xenlight_golang_define_from_C(ty =3D None, typena= me =3D None, nested =3D False): =20 return s =20 +def xenlight_golang_union_from_C(ty =3D None, union_name =3D '', struct_na= me =3D ''): + keyname =3D ty.keyvar.name + gokeyname =3D xenlight_golang_fmt_name(keyname) + keytype =3D ty.keyvar.type.typename + gokeytype =3D xenlight_golang_fmt_name(keytype) + + interface_name =3D '{}_{}_union'.format(struct_name, keyname) + interface_name =3D xenlight_golang_fmt_name(interface_name, exported= =3DFalse) + + cgo_keyname =3D keyname + if cgo_keyname in go_keywords: + cgo_keyname =3D '_' + cgo_keyname + + cases =3D {} + + for f in ty.fields: + val =3D '{}_{}'.format(keytype, f.name) + val =3D xenlight_golang_fmt_name(val) + + # Add to list of cases to make for the switch + # statement below. + if f.type is None: + continue + + cases[f.name] =3D val + + # Define fromC func for 'union' struct. + typename =3D '{}_{}_union_{}'.format(struct_name,keyname,f.name) + gotypename =3D xenlight_golang_fmt_name(typename) + + # Define the function here. The cases for keyed unions are a little + # different. + s =3D 'func (x *{}) fromC(xc *C.{}) error {{\n'.format(gotypename,= struct_name) + s +=3D 'if {}(xc.{}) !=3D {} {{\n'.format(gokeytype,cgo_keyname,va= l) + err_string =3D '"expected union key {}"'.format(val) + s +=3D 'return errors.New({})\n'.format(err_string) + s +=3D '}\n\n' + s +=3D 'tmp :=3D (*C.{})(unsafe.Pointer(&xc.{}[0]))\n'.format(type= name,union_name) + + s +=3D xenlight_golang_union_fields_from_C(f.type) + s +=3D 'return nil\n' + s +=3D '}\n' + + helper_extras.append(s) + + s =3D 'x.{} =3D {}(xc.{})\n'.format(gokeyname,gokeytype,cgo_keyname) + s +=3D 'switch x.{}{{\n'.format(gokeyname) + + # Create switch statement to determine which 'union element' + # to populate in the Go struct. + for case_name, case_val in cases.items(): + s +=3D 'case {}:\n'.format(case_val) + + gotype =3D '{}_{}_union_{}'.format(struct_name,keyname,case_name) + gotype =3D xenlight_golang_fmt_name(gotype) + goname =3D '{}_{}'.format(keyname,case_name) + goname =3D xenlight_golang_fmt_name(goname,exported=3DFalse) + + s +=3D 'var {} {}\n'.format(goname, gotype) + s +=3D 'if err :=3D {}.fromC(xc);'.format(goname) + s +=3D 'err !=3D nil {\n return err \n}\n' + + field_name =3D xenlight_golang_fmt_name('{}_union'.format(keyname)) + s +=3D 'x.{} =3D {}\n'.format(field_name, goname) + + # End switch statement + s +=3D 'default:\n' + err_string =3D '"invalid union key \'%v\'", x.{}'.format(gokeyname) + s +=3D 'return fmt.Errorf({})'.format(err_string) + s +=3D '}\n' + + return s + +def xenlight_golang_union_fields_from_C(ty =3D None): + s =3D '' + + for f in ty.fields: + gotypename =3D xenlight_golang_fmt_name(f.type.typename) + ctypename =3D f.type.typename + gofname =3D xenlight_golang_fmt_name(f.name) + cfname =3D f.name + + is_castable =3D (f.type.json_parse_type =3D=3D 'JSON_INTEGER' or + isinstance(f.type, idl.Enumeration) or + gotypename in go_builtin_types) + + if not is_castable: + s +=3D 'if err :=3D x.{}.fromC(&tmp.{});'.format(gofname,cfnam= e) + s +=3D 'err !=3D nil {\n return err \n}\n' + + # We just did an unsafe.Pointer cast from []byte to the 'union' ty= pe + # struct, so we need to make sure that any string fields are actua= lly + # converted properly. + elif gotypename =3D=3D 'string': + s +=3D 'x.{} =3D C.GoString(tmp.{})\n'.format(gofname,cfname) + + else: + s +=3D 'x.{} =3D {}(tmp.{})\n'.format(gofname,gotypename,cfnam= e) + + return s + def xenlight_golang_fmt_name(name, exported =3D True): """ Take a given type name and return an diff --git a/tools/golang/xenlight/xenlight_helpers.go b/tools/golang/xenli= ght/xenlight_helpers.go index 4ece90dc6b..b8abef8068 100644 --- a/tools/golang/xenlight/xenlight_helpers.go +++ b/tools/golang/xenlight/xenlight_helpers.go @@ -5,11 +5,122 @@ // package xenlight =20 +import ( + "errors" + "fmt" + "unsafe" +) + /* #cgo LDFLAGS: -lxenlight #include #include =20 +typedef struct libxl_channelinfo_connection_union_pty { + char * path; +} libxl_channelinfo_connection_union_pty; + +typedef struct libxl_domain_build_info_type_union_hvm { + char * firmware; + libxl_bios_type bios; + libxl_defbool pae; + libxl_defbool apic; + libxl_defbool acpi; + libxl_defbool acpi_s3; + libxl_defbool acpi_s4; + libxl_defbool acpi_laptop_slate; + libxl_defbool nx; + libxl_defbool viridian; + libxl_bitmap viridian_enable; + libxl_bitmap viridian_disable; + char * timeoffset; + libxl_defbool hpet; + libxl_defbool vpt_align; + uint64_t mmio_hole_memkb; + libxl_timer_mode timer_mode; + libxl_defbool nested_hvm; + libxl_defbool altp2m; + char * system_firmware; + char * smbios_firmware; + char * acpi_firmware; + libxl_hdtype hdtype; + libxl_defbool nographic; + libxl_vga_interface_info vga; + libxl_vnc_info vnc; + char * keymap; + libxl_sdl_info sdl; + libxl_spice_info spice; + libxl_defbool gfx_passthru; + libxl_gfx_passthru_kind gfx_passthru_kind; + char * serial; + char * boot; + libxl_defbool usb; + int usbversion; + char * usbdevice; + libxl_defbool vkb_device; + char * soundhw; + libxl_defbool xen_platform_pci; + libxl_string_list usbdevice_list; + libxl_vendor_device vendor_device; + libxl_ms_vm_genid ms_vm_genid; + libxl_string_list serial_list; + libxl_rdm_reserve rdm; + uint64_t rdm_mem_boundary_memkb; + uint64_t mca_caps; +} libxl_domain_build_info_type_union_hvm; + +typedef struct libxl_domain_build_info_type_union_pv { + char * kernel; + uint64_t slack_memkb; + char * bootloader; + libxl_string_list bootloader_args; + char * cmdline; + char * ramdisk; + char * features; + libxl_defbool e820_host; +} libxl_domain_build_info_type_union_pv; + +typedef struct libxl_domain_build_info_type_union_pvh { + libxl_defbool pvshim; + char * pvshim_path; + char * pvshim_cmdline; + char * pvshim_extra; +} libxl_domain_build_info_type_union_pvh; + +typedef struct libxl_device_usbdev_type_union_hostdev { + uint8_t hostbus; + uint8_t hostaddr; +} libxl_device_usbdev_type_union_hostdev; + +typedef struct libxl_device_channel_connection_union_socket { + char * path; +} libxl_device_channel_connection_union_socket; + +typedef struct libxl_event_type_union_domain_shutdown { + uint8_t shutdown_reason; +} libxl_event_type_union_domain_shutdown; + +typedef struct libxl_event_type_union_disk_eject { + char * vdev; + libxl_device_disk disk; +} libxl_event_type_union_disk_eject; + +typedef struct libxl_event_type_union_operation_complete { + int rc; +} libxl_event_type_union_operation_complete; + +typedef struct libxl_psr_hw_info_type_union_cat { + uint32_t cos_max; + uint32_t cbm_len; + bool cdp_enabled; +} libxl_psr_hw_info_type_union_cat; + +typedef struct libxl_psr_hw_info_type_union_mba { + uint32_t cos_max; + uint32_t thrtl_max; + bool linear; +} libxl_psr_hw_info_type_union_mba; + */ import "C" =20 @@ -151,6 +262,27 @@ func (x *Channelinfo) fromC(xc *C.libxl_channelinfo) e= rror { x.State =3D int(xc.state) x.Evtch =3D int(xc.evtch) x.Rref =3D int(xc.rref) + x.Connection =3D ChannelConnection(xc.connection) + switch x.Connection { + case ChannelConnectionPty: + var connectionPty ChannelinfoConnectionUnionPty + if err :=3D connectionPty.fromC(xc); err !=3D nil { + return err + } + x.ConnectionUnion =3D connectionPty + default: + return fmt.Errorf("invalid union key '%v'", x.Connection) + } + return nil +} + +func (x *ChannelinfoConnectionUnionPty) fromC(xc *C.libxl_channelinfo) err= or { + if ChannelConnection(xc.connection) !=3D ChannelConnectionPty { + return errors.New("expected union key ChannelConnectionPty") + } + + tmp :=3D (*C.libxl_channelinfo_connection_union_pty)(unsafe.Pointer(&xc.u= [0])) + x.Path =3D C.GoString(tmp.path) return nil } =20 @@ -398,12 +530,180 @@ func (x *DomainBuildInfo) fromC(xc *C.libxl_domain_b= uild_info) error { } x.DmRestrict =3D defboolDmRestrict x.Tee =3D TeeType(xc.tee) + x.Type =3D DomainType(xc._type) + switch x.Type { + case DomainTypePv: + var typePv DomainBuildInfoTypeUnionPv + if err :=3D typePv.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typePv + case DomainTypeHvm: + var typeHvm DomainBuildInfoTypeUnionHvm + if err :=3D typeHvm.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typeHvm + case DomainTypePvh: + var typePvh DomainBuildInfoTypeUnionPvh + if err :=3D typePvh.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typePvh + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } x.ArchArm.GicVersion =3D GicVersion(xc.arch_arm.gic_version) x.ArchArm.Vuart =3D VuartType(xc.arch_arm.vuart) x.Altp2M =3D Altp2MMode(xc.altp2m) return nil } =20 +func (x *DomainBuildInfoTypeUnionHvm) fromC(xc *C.libxl_domain_build_info)= error { + if DomainType(xc._type) !=3D DomainTypeHvm { + return errors.New("expected union key DomainTypeHvm") + } + + tmp :=3D (*C.libxl_domain_build_info_type_union_hvm)(unsafe.Pointer(&xc.u= [0])) + x.Firmware =3D C.GoString(tmp.firmware) + x.Bios =3D BiosType(tmp.bios) + if err :=3D x.Pae.fromC(&tmp.pae); err !=3D nil { + return err + } + if err :=3D x.Apic.fromC(&tmp.apic); err !=3D nil { + return err + } + if err :=3D x.Acpi.fromC(&tmp.acpi); err !=3D nil { + return err + } + if err :=3D x.AcpiS3.fromC(&tmp.acpi_s3); err !=3D nil { + return err + } + if err :=3D x.AcpiS4.fromC(&tmp.acpi_s4); err !=3D nil { + return err + } + if err :=3D x.AcpiLaptopSlate.fromC(&tmp.acpi_laptop_slate); err !=3D nil= { + return err + } + if err :=3D x.Nx.fromC(&tmp.nx); err !=3D nil { + return err + } + if err :=3D x.Viridian.fromC(&tmp.viridian); err !=3D nil { + return err + } + if err :=3D x.ViridianEnable.fromC(&tmp.viridian_enable); err !=3D nil { + return err + } + if err :=3D x.ViridianDisable.fromC(&tmp.viridian_disable); err !=3D nil { + return err + } + x.Timeoffset =3D C.GoString(tmp.timeoffset) + if err :=3D x.Hpet.fromC(&tmp.hpet); err !=3D nil { + return err + } + if err :=3D x.VptAlign.fromC(&tmp.vpt_align); err !=3D nil { + return err + } + x.MmioHoleMemkb =3D uint64(tmp.mmio_hole_memkb) + x.TimerMode =3D TimerMode(tmp.timer_mode) + if err :=3D x.NestedHvm.fromC(&tmp.nested_hvm); err !=3D nil { + return err + } + if err :=3D x.Altp2M.fromC(&tmp.altp2m); err !=3D nil { + return err + } + x.SystemFirmware =3D C.GoString(tmp.system_firmware) + x.SmbiosFirmware =3D C.GoString(tmp.smbios_firmware) + x.AcpiFirmware =3D C.GoString(tmp.acpi_firmware) + x.Hdtype =3D Hdtype(tmp.hdtype) + if err :=3D x.Nographic.fromC(&tmp.nographic); err !=3D nil { + return err + } + if err :=3D x.Vga.fromC(&tmp.vga); err !=3D nil { + return err + } + if err :=3D x.Vnc.fromC(&tmp.vnc); err !=3D nil { + return err + } + x.Keymap =3D C.GoString(tmp.keymap) + if err :=3D x.Sdl.fromC(&tmp.sdl); err !=3D nil { + return err + } + if err :=3D x.Spice.fromC(&tmp.spice); err !=3D nil { + return err + } + if err :=3D x.GfxPassthru.fromC(&tmp.gfx_passthru); err !=3D nil { + return err + } + x.GfxPassthruKind =3D GfxPassthruKind(tmp.gfx_passthru_kind) + x.Serial =3D C.GoString(tmp.serial) + x.Boot =3D C.GoString(tmp.boot) + if err :=3D x.Usb.fromC(&tmp.usb); err !=3D nil { + return err + } + x.Usbversion =3D int(tmp.usbversion) + x.Usbdevice =3D C.GoString(tmp.usbdevice) + if err :=3D x.VkbDevice.fromC(&tmp.vkb_device); err !=3D nil { + return err + } + x.Soundhw =3D C.GoString(tmp.soundhw) + if err :=3D x.XenPlatformPci.fromC(&tmp.xen_platform_pci); err !=3D nil { + return err + } + if err :=3D x.UsbdeviceList.fromC(&tmp.usbdevice_list); err !=3D nil { + return err + } + x.VendorDevice =3D VendorDevice(tmp.vendor_device) + if err :=3D x.MsVmGenid.fromC(&tmp.ms_vm_genid); err !=3D nil { + return err + } + if err :=3D x.SerialList.fromC(&tmp.serial_list); err !=3D nil { + return err + } + if err :=3D x.Rdm.fromC(&tmp.rdm); err !=3D nil { + return err + } + x.RdmMemBoundaryMemkb =3D uint64(tmp.rdm_mem_boundary_memkb) + x.McaCaps =3D uint64(tmp.mca_caps) + return nil +} + +func (x *DomainBuildInfoTypeUnionPv) fromC(xc *C.libxl_domain_build_info) = error { + if DomainType(xc._type) !=3D DomainTypePv { + return errors.New("expected union key DomainTypePv") + } + + tmp :=3D (*C.libxl_domain_build_info_type_union_pv)(unsafe.Pointer(&xc.u[= 0])) + x.Kernel =3D C.GoString(tmp.kernel) + x.SlackMemkb =3D uint64(tmp.slack_memkb) + x.Bootloader =3D C.GoString(tmp.bootloader) + if err :=3D x.BootloaderArgs.fromC(&tmp.bootloader_args); err !=3D nil { + return err + } + x.Cmdline =3D C.GoString(tmp.cmdline) + x.Ramdisk =3D C.GoString(tmp.ramdisk) + x.Features =3D C.GoString(tmp.features) + if err :=3D x.E820Host.fromC(&tmp.e820_host); err !=3D nil { + return err + } + return nil +} + +func (x *DomainBuildInfoTypeUnionPvh) fromC(xc *C.libxl_domain_build_info)= error { + if DomainType(xc._type) !=3D DomainTypePvh { + return errors.New("expected union key DomainTypePvh") + } + + tmp :=3D (*C.libxl_domain_build_info_type_union_pvh)(unsafe.Pointer(&xc.u= [0])) + if err :=3D x.Pvshim.fromC(&tmp.pvshim); err !=3D nil { + return err + } + x.PvshimPath =3D C.GoString(tmp.pvshim_path) + x.PvshimCmdline =3D C.GoString(tmp.pvshim_cmdline) + x.PvshimExtra =3D C.GoString(tmp.pvshim_extra) + return nil +} + func (x *DeviceVfb) fromC(xc *C.libxl_device_vfb) error { x.BackendDomid =3D Domid(xc.backend_domid) x.BackendDomname =3D C.GoString(xc.backend_domname) @@ -582,6 +882,28 @@ func (x *DeviceUsbctrl) fromC(xc *C.libxl_device_usbct= rl) error { func (x *DeviceUsbdev) fromC(xc *C.libxl_device_usbdev) error { x.Ctrl =3D Devid(xc.ctrl) x.Port =3D int(xc.port) + x.Type =3D UsbdevType(xc._type) + switch x.Type { + case UsbdevTypeHostdev: + var typeHostdev DeviceUsbdevTypeUnionHostdev + if err :=3D typeHostdev.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typeHostdev + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } + return nil +} + +func (x *DeviceUsbdevTypeUnionHostdev) fromC(xc *C.libxl_device_usbdev) er= ror { + if UsbdevType(xc._type) !=3D UsbdevTypeHostdev { + return errors.New("expected union key UsbdevTypeHostdev") + } + + tmp :=3D (*C.libxl_device_usbdev_type_union_hostdev)(unsafe.Pointer(&xc.u= [0])) + x.Hostbus =3D byte(tmp.hostbus) + x.Hostaddr =3D byte(tmp.hostaddr) return nil } =20 @@ -624,6 +946,27 @@ func (x *DeviceChannel) fromC(xc *C.libxl_device_chann= el) error { x.BackendDomname =3D C.GoString(xc.backend_domname) x.Devid =3D Devid(xc.devid) x.Name =3D C.GoString(xc.name) + x.Connection =3D ChannelConnection(xc.connection) + switch x.Connection { + case ChannelConnectionSocket: + var connectionSocket DeviceChannelConnectionUnionSocket + if err :=3D connectionSocket.fromC(xc); err !=3D nil { + return err + } + x.ConnectionUnion =3D connectionSocket + default: + return fmt.Errorf("invalid union key '%v'", x.Connection) + } + return nil +} + +func (x *DeviceChannelConnectionUnionSocket) fromC(xc *C.libxl_device_chan= nel) error { + if ChannelConnection(xc.connection) !=3D ChannelConnectionSocket { + return errors.New("expected union key ChannelConnectionSocket") + } + + tmp :=3D (*C.libxl_device_channel_connection_union_socket)(unsafe.Pointer= (&xc.u[0])) + x.Path =3D C.GoString(tmp.path) return nil } =20 @@ -950,6 +1293,62 @@ func (x *Event) fromC(xc *C.libxl_event) error { } x.Domuuid =3D uuidDomuuid x.ForUser =3D uint64(xc.for_user) + x.Type =3D EventType(xc._type) + switch x.Type { + case EventTypeOperationComplete: + var typeOperationComplete EventTypeUnionOperationComplete + if err :=3D typeOperationComplete.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typeOperationComplete + case EventTypeDomainShutdown: + var typeDomainShutdown EventTypeUnionDomainShutdown + if err :=3D typeDomainShutdown.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typeDomainShutdown + case EventTypeDiskEject: + var typeDiskEject EventTypeUnionDiskEject + if err :=3D typeDiskEject.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typeDiskEject + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } + return nil +} + +func (x *EventTypeUnionDomainShutdown) fromC(xc *C.libxl_event) error { + if EventType(xc._type) !=3D EventTypeDomainShutdown { + return errors.New("expected union key EventTypeDomainShutdown") + } + + tmp :=3D (*C.libxl_event_type_union_domain_shutdown)(unsafe.Pointer(&xc.u= [0])) + x.ShutdownReason =3D byte(tmp.shutdown_reason) + return nil +} + +func (x *EventTypeUnionDiskEject) fromC(xc *C.libxl_event) error { + if EventType(xc._type) !=3D EventTypeDiskEject { + return errors.New("expected union key EventTypeDiskEject") + } + + tmp :=3D (*C.libxl_event_type_union_disk_eject)(unsafe.Pointer(&xc.u[0])) + x.Vdev =3D C.GoString(tmp.vdev) + if err :=3D x.Disk.fromC(&tmp.disk); err !=3D nil { + return err + } + return nil +} + +func (x *EventTypeUnionOperationComplete) fromC(xc *C.libxl_event) error { + if EventType(xc._type) !=3D EventTypeOperationComplete { + return errors.New("expected union key EventTypeOperationComplete") + } + + tmp :=3D (*C.libxl_event_type_union_operation_complete)(unsafe.Pointer(&x= c.u[0])) + x.Rc =3D int(tmp.rc) return nil } =20 @@ -963,5 +1362,46 @@ func (x *PsrCatInfo) fromC(xc *C.libxl_psr_cat_info) = error { =20 func (x *PsrHwInfo) fromC(xc *C.libxl_psr_hw_info) error { x.Id =3D uint32(xc.id) + x.Type =3D PsrFeatType(xc._type) + switch x.Type { + case PsrFeatTypeMba: + var typeMba PsrHwInfoTypeUnionMba + if err :=3D typeMba.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typeMba + case PsrFeatTypeCat: + var typeCat PsrHwInfoTypeUnionCat + if err :=3D typeCat.fromC(xc); err !=3D nil { + return err + } + x.TypeUnion =3D typeCat + default: + return fmt.Errorf("invalid union key '%v'", x.Type) + } + return nil +} + +func (x *PsrHwInfoTypeUnionCat) fromC(xc *C.libxl_psr_hw_info) error { + if PsrFeatType(xc._type) !=3D PsrFeatTypeCat { + return errors.New("expected union key PsrFeatTypeCat") + } + + tmp :=3D (*C.libxl_psr_hw_info_type_union_cat)(unsafe.Pointer(&xc.u[0])) + x.CosMax =3D uint32(tmp.cos_max) + x.CbmLen =3D uint32(tmp.cbm_len) + x.CdpEnabled =3D bool(tmp.cdp_enabled) + return nil +} + +func (x *PsrHwInfoTypeUnionMba) fromC(xc *C.libxl_psr_hw_info) error { + if PsrFeatType(xc._type) !=3D PsrFeatTypeMba { + return errors.New("expected union key PsrFeatTypeMba") + } + + tmp :=3D (*C.libxl_psr_hw_info_type_union_mba)(unsafe.Pointer(&xc.u[0])) + x.CosMax =3D uint32(tmp.cos_max) + x.ThrtlMax =3D uint32(tmp.thrtl_max) + x.Linear =3D bool(tmp.linear) return nil } --=20 2.19.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel