From patchwork Mon Oct 7 15:13:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11177797 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0422A139A for ; Mon, 7 Oct 2019 15:15:34 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D41F62070B for ; Mon, 7 Oct 2019 15:15:33 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="XpawqHaO" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D41F62070B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUiN-0007C3-2c; Mon, 07 Oct 2019 15:14:23 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUiL-0007B2-O3 for xen-devel@lists.xenproject.org; Mon, 07 Oct 2019 15:14:21 +0000 X-Inumbo-ID: 05e3b6e4-e915-11e9-8c93-bc764e2007e4 Received: from mail-qk1-x741.google.com (unknown [2607:f8b0:4864:20::741]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 05e3b6e4-e915-11e9-8c93-bc764e2007e4; Mon, 07 Oct 2019 15:13:31 +0000 (UTC) Received: by mail-qk1-x741.google.com with SMTP id w2so12924996qkf.2 for ; Mon, 07 Oct 2019 08:13:31 -0700 (PDT) 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=2htTM68zxP0j1foVUJTAU8c3I7wf8QEtD5IUSCOUF2w=; b=XpawqHaOGMZrPEdiqmvvu6Ip2+9JMcXN8U45lfBeZCG15vItXP8B6eZgxYADpyStHQ jRyd0Gb+jHZhqY5p52UrXQhYm8wMeYml1ekyfEEeuw7d/MzqMz+tdpPoRDnNK70lob4g 1XxuFWyOP12Y485P0nZ6DIwBoWfBQseb9eG+EaGvepSJDzewglzZshhGE2Li0F33Jw0s v8MeHRR+OhgM6L80oDxhMseCmn/ebNIoOiSpnS8yj3IkjMIgR+3OO6K2EFWy0c22aNry P+Bq8cAqk00M9OnfpECusmApohOO4QU912rAQysIFW0d9YFSTPSN/pn4ClTLf/EBUewa x8Rg== 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=2htTM68zxP0j1foVUJTAU8c3I7wf8QEtD5IUSCOUF2w=; b=Tf0JwyDjRNyO5xjIgzaNb+jeaF3+qplJismUkS3sFwRfHxt1U27UZZEBm0pJZ8OQOk L/tKkyFNX3h+P57b9URmVK6f8dlnjTYHrZgHO5xlOIXcj20216KRxwGi+Ylia1DdFrKO DLcB0NMbu7Ku6fjMDjyjkvbx9NHCdNgc9OAe70A3dhONhIsEmWDuqiFIMZAqHvecaetQ yfCAeQHUkYZjW+PXm6uaA5v8nnqxPAYC96xrgnTjkpcRB1YbXRI7wiBb3J+83zGvQOke lw4L3LAfObAsLgVcK41MudyGVH+FNYT/41WKal/NdXQy73K488u3FdF4oypO/b5iNXqm BnEA== X-Gm-Message-State: APjAAAV4xVMEVjmMGHYhO13PqiKvzPL7K6NZH262vm1SRiNnISLaOzdK fb7hCXepR8PsUU+D3SnmKnsTPz/Q X-Google-Smtp-Source: APXvYqweIcEUUWwSORHvAEcZd/08vp6vrZlvlcZpod6RdYz23iHYY0feR6N4KM9CiiVRz4RCg1IcAQ== X-Received: by 2002:a37:66c8:: with SMTP id a191mr24153146qkc.108.1570461210702; Mon, 07 Oct 2019 08:13:30 -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.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:13:30 -0700 (PDT) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 7 Oct 2019 11:13:00 -0400 Message-Id: <6dbe8bb54d634e7ebe4eb12245255c75ce22fbce.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 13/24] golang/xenlight: re-factor Hwcap type implementation 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 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" From: Nick Rosbrook Re-define Hwcap as [8]uint32, and implement toC function. Also, re-name and modify signature of toGo function to fromC. Signed-off-by: Nick Rosbrook Reviewed-by: George Dunlap --- Cc: George Dunlap Cc: Ian Jackson Cc: Wei Liu tools/golang/xenlight/xenlight.go | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 3e3753f92e..8d520bbd98 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -307,20 +307,29 @@ type Context struct { logger *C.xentoollog_logger_stdiostream } -type Hwcap []C.uint32_t - -func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) { - // Alloc a Go slice for the bytes - size := 8 - ghwcap = make([]C.uint32_t, size) +// Hwcap represents a libxl_hwcap. +type Hwcap [8]uint32 +func (hwcap *Hwcap) fromC(chwcap *C.libxl_hwcap) error { // Make a slice pointing to the C array - mapslice := (*[1 << 30]C.uint32_t)(unsafe.Pointer(&chwcap[0]))[:size:size] + mapslice := (*[8]C.uint32_t)(unsafe.Pointer(chwcap)) // And copy the C array into the Go array - copy(ghwcap, mapslice) + for i, v := range mapslice { + hwcap[i] = uint32(v) + } - return + return nil +} + +func (hwcap *Hwcap) toC() (C.libxl_hwcap, error) { + var chwcap C.libxl_hwcap + + for i, v := range hwcap { + chwcap[i] = C.uint32_t(v) + } + + return chwcap, nil } // KeyValueList represents a libxl_key_value_list. @@ -465,7 +474,7 @@ func (cphys *C.libxl_physinfo) toGo() (physinfo *Physinfo) { physinfo.SharingFreedPages = uint64(cphys.sharing_freed_pages) physinfo.SharingUsedFrames = uint64(cphys.sharing_used_frames) physinfo.NrNodes = uint32(cphys.nr_nodes) - physinfo.HwCap = cphys.hw_cap.toGo() + physinfo.HwCap.fromC(&cphys.hw_cap) physinfo.CapHvm = bool(cphys.cap_hvm) physinfo.CapHvmDirectio = bool(cphys.cap_hvm_directio)