From patchwork Tue Dec 10 15:47:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Rosbrook X-Patchwork-Id: 11282887 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 706D214BD for ; Tue, 10 Dec 2019 15:49:48 +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 4BEE6206D5 for ; Tue, 10 Dec 2019 15:49:48 +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="FBccXHBT" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4BEE6206D5 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 1iehkq-0003OR-3h; Tue, 10 Dec 2019 15:48:52 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iehko-0003NL-SF for xen-devel@lists.xenproject.org; Tue, 10 Dec 2019 15:48:50 +0000 X-Inumbo-ID: 74232154-1b64-11ea-88e7-bc764e2007e4 Received: from mail-qv1-xf41.google.com (unknown [2607:f8b0:4864:20::f41]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 74232154-1b64-11ea-88e7-bc764e2007e4; Tue, 10 Dec 2019 15:48:04 +0000 (UTC) Received: by mail-qv1-xf41.google.com with SMTP id t5so4353960qvs.5 for ; Tue, 10 Dec 2019 07:48:04 -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=lfSXRpgw3eVeA7YwpoTkHPmcDjBPWceRwH/SOucJAAQ=; b=FBccXHBTUri+KAyO6xTjfajMJ39Yj0OBmAysXJTLpemtmDEzFQQPvYI39haJ4rDoF6 ZYHeB4MglGIXgCgFXyVK7d1l9zLNLmfcaYk2GHvd+YJ9oneLussrUPY1nhHepkIKy4jR ldpTbhMQjxHYfTlaN8WpHMunrb5CQ90SlTYU7RAqPBWqvhRQSX6zvQNpChZTZooyT9mt mXFeD0+ZEQlA1PJdlnYeCa0kG3NOwgkN3XcEQmrcH96PvppAtcygP/Vv5Lqd1T49OHzQ VAPJCc+zgSuo9qSEctUaMYsoj0GgAmc3PpXzVNw0gWCGIH4b3O+r83m2BcbT4M0Nnsoy +Jlg== 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=lfSXRpgw3eVeA7YwpoTkHPmcDjBPWceRwH/SOucJAAQ=; b=oPPgTsrTqyktKRJyAX3fZfSmy+/tc1sZFX8ygKW+wAQKzl8O8ZDvKF29id9J/312S/ pJzyXnPBSxrjYXfXtqHJ6nhbpEzNUUDIcOXMvTFAN9Lg8RFniLaZ2fXBbv3ld2SfayKQ XaYpyafB6oCWkIqd76DTaOi380eTep3BQItBEa6XFawOklpFQgwRuYmNMdnSDztgPpJE ukd7VMFS8P1QcMa16ZbfeDE+Ybje3nnYo4h6RSJVq0tgf0f4vGtb3KQfziRZ8dBL5dLT C1XVPKneR63TakMX0Nwo+pSdFc73/+xkJh/acn6oXc8Eo7gsqdtd4SBW4nKvwVi1QTbC ISqg== X-Gm-Message-State: APjAAAX7glVfjlxVdCri9YOCkq78mu7SksE1l0ygTzLsnHJZTS3QP3/2 PvxmDeztKSoIhreHZknkrVFSKSGA X-Google-Smtp-Source: APXvYqzuBusz/PYk0k4PcYgSBjqOXeyAI1CC2tDIejBw2FAwwmgPdy8r4De3xiCWU4U1V/zORgsnuw== X-Received: by 2002:a0c:ef0f:: with SMTP id t15mr27304967qvr.123.1575992884039; Tue, 10 Dec 2019 07:48:04 -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 m29sm1247848qtf.1.2019.12.10.07.48.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Dec 2019 07:48:03 -0800 (PST) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Tue, 10 Dec 2019 10:47:27 -0500 Message-Id: <7a789af7e2a0595132cf898a80ea6707537d31c2.1575990937.git.rosbrookn@ainfosec.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: References: MIME-Version: 1.0 Subject: [Xen-devel] [PATCH v3 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. Changes in v3: - In fromC, iterate over the indirect of hwcap instead of creating a slice from the C type. --- tools/golang/xenlight/xenlight.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenlight.go index f9c2f84c81..b395963512 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -306,20 +306,25 @@ 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) +func (hwcap *Hwcap) fromC(chwcap *C.libxl_hwcap) error { + for i := range *hwcap { + hwcap[i] = uint32(chwcap[i]) + } - // Make a slice pointing to the C array - mapslice := (*[1 << 30]C.uint32_t)(unsafe.Pointer(&chwcap[0]))[:size:size] + return nil +} - // And copy the C array into the Go array - copy(ghwcap, mapslice) +func (hwcap *Hwcap) toC() (C.libxl_hwcap, error) { + var chwcap C.libxl_hwcap - return + for i, v := range hwcap { + chwcap[i] = C.uint32_t(v) + } + + return chwcap, nil } // KeyValueList represents a libxl_key_value_list. @@ -442,7 +447,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)