From patchwork Fri Nov 15 19:44:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11247039 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 1CE0A13BD for ; Fri, 15 Nov 2019 19:47:06 +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 EA4D92073A for ; Fri, 15 Nov 2019 19:47:05 +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="rzSzXp3U" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EA4D92073A 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 1iVhXc-0001oy-Ok; Fri, 15 Nov 2019 19:46:00 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iVhXb-0001nZ-Hc for xen-devel@lists.xenproject.org; Fri, 15 Nov 2019 19:45:59 +0000 X-Inumbo-ID: 70d7d4a0-07e0-11ea-b678-bc764e2007e4 Received: from mail-qk1-x743.google.com (unknown [2607:f8b0:4864:20::743]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 70d7d4a0-07e0-11ea-b678-bc764e2007e4; Fri, 15 Nov 2019 19:45:13 +0000 (UTC) Received: by mail-qk1-x743.google.com with SMTP id d13so9051132qko.3 for ; Fri, 15 Nov 2019 11:45:13 -0800 (PST) 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=H+WE+lipIRlB+Fufpf96h4a0peDgVnMvRPfh/PoDswM=; b=rzSzXp3UJ/tuXb0n9DlnOT73g4cWmaDw4lpVYUaDTm6SGpvOU/kJPudRyvWf/0RhNE owu4UgBvxXPVy2HHQP1Yr2kKM/mcT2oY1YDtWLxxBKRvcvWFI4XGDGvB7RRg1rJ3cDVQ rIJop2eCiHMhHubSy9Wzj9xuUUpxMR39dmoUMC56U06hOdFn4LUbyBNXtS8yc1P8Kh1f uGb9NWNkGFjY0bAwbopeBtWOhDBPXoYlj/2Csu/76NnspcepX9BaUCJ7u4TkVnkddLJu 380TaFeMxISwE9lmVqutCR068d6tabKaUnYZCJFrU4fxHifFPJ43zSfDhZQVTYwN7F95 UIcg== 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=H+WE+lipIRlB+Fufpf96h4a0peDgVnMvRPfh/PoDswM=; b=Uk5Vp/bqnzraumBAvtMWhhbybrwIp3rF8Sfs6ixXngKbR2pafkBqiIoYQ2FkNSLlSU qqqPlyXcDkRUSXOT4WtVlRFDUQq9xCybHkIwzAZoFcCHpMdPqADE+7JyPxYW31UDIU7P obuXPUpYtbJzk5IWDxE6szlCh55jBH0zmLtMuS6EU/lcP7NBSw0BjwsHAuxZi2E7t3T1 BzRSx9R648Nhdtv9jNgIXoC0r11bFhdd/T8E0WkgtEW9jcM+YajvThMr+DC1RqdQuhds vmzzX6ZY3k63xUrAW6AJo2a67/O9+7rG4NdqQ8rqgVdqwq3N6QA9kAxCrzIs2LOEj/KY dX6w== X-Gm-Message-State: APjAAAV3/KWWx2zbN4fF1F3XMXNR2tWkyjO/sLY7wMa6iMS4963sjf5W JrMqD3koubdPtQfTIjr1HoLIG1VV X-Google-Smtp-Source: APXvYqzLS0MWglIeOpaqAjwbcybOsjEdU/E43FGKVhft+NhdZu5cEg8rblonadNsl5l3bFEDyLx9kQ== X-Received: by 2002:a37:9c85:: with SMTP id f127mr14392162qke.186.1573847112857; Fri, 15 Nov 2019 11:45:12 -0800 (PST) Received: from five.crux.rad.ainfosec.com (209-217-208-226.northland.net. [209.217.208.226]) by smtp.googlemail.com with ESMTPSA id y10sm4649679qkb.55.2019.11.15.11.45.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Nov 2019 11:45:12 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Fri, 15 Nov 2019 14:44:19 -0500 Message-Id: <3bf4e3167d703d680a6bd6f3226ba394b0ed443f.1573840474.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v2 12/22] 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 --- Changes in v2: - Fix comment in fromC since an array is being used now, not a slice. - Use a concise variable name instead of mapslice for the C array. tools/golang/xenlight/xenlight.go | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index 67c1bb1225..d6d912a037 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -312,20 +312,29 @@ type Context struct { logger *C.xentoollog_logger_stdiostream } -type Hwcap []C.uint32_t +// Hwcap represents a libxl_hwcap. +type Hwcap [8]uint32 -func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) { - // Alloc a Go slice for the bytes - size := 8 - ghwcap = make([]C.uint32_t, size) - - // Make a slice pointing to the C array - mapslice := (*[1 << 30]C.uint32_t)(unsafe.Pointer(&chwcap[0]))[:size:size] +func (hwcap *Hwcap) fromC(chwcap *C.libxl_hwcap) error { + // Make an array pointing to the C array + a := (*[8]C.uint32_t)(unsafe.Pointer(chwcap)) // And copy the C array into the Go array - copy(ghwcap, mapslice) + for i, v := range a { + 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. @@ -448,7 +457,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)