From nobody Mon Feb 9 14:34:29 2026 Delivered-To: importer@patchew.org Received-SPF: none (zohomail.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 (zohomail.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=1575992965; cv=none; d=zohomail.com; s=zohoarc; b=ELEEGKcfIJ35Gv4LaS8HtOedYoejE2iv1WPMFKQ2nHMXxf9jGqgeC1T80G91/qrkBJijQdiKpA5UCmVWCRI8CwyxetuHY7GpS3cMFZqjVtrJEfOByMRF7p/kCxkNDq8FQeKUvjmjyaTR/Uyr5hiSuhRjobMrBTAOvVuPY9Ik7Bc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575992965; 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; bh=FJukvunWNd+QXlT8BRxIiGGrH3miGX7HaD955+oL0iE=; b=YcW3UUxdFu+wrSjZUGaJqZUigxigD+JOMr4mppUpJEJFyQW9N62dBNpA8HEK1KVrEsnqSBl87vHQJMPwvE8D8DdC7bQ7JX8vy1XxTL+H7KK7RSsSuFlRPHrDZe7+N+EiUh55xOl6he3T+xZ7GkjwLtX8T77UcFGrM7+VzXhOJu4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.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 1575992965398145.58547653033338; Tue, 10 Dec 2019 07:49:25 -0800 (PST) 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 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) 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) X-Inumbo-ID: 74232154-1b64-11ea-88e7-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=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) 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 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 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/xenl= ight.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 } =20 -type Hwcap []C.uint32_t +// Hwcap represents a libxl_hwcap. +type Hwcap [8]uint32 =20 -func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) { - // Alloc a Go slice for the bytes - size :=3D 8 - ghwcap =3D make([]C.uint32_t, size) +func (hwcap *Hwcap) fromC(chwcap *C.libxl_hwcap) error { + for i :=3D range *hwcap { + hwcap[i] =3D uint32(chwcap[i]) + } =20 - // Make a slice pointing to the C array - mapslice :=3D (*[1 << 30]C.uint32_t)(unsafe.Pointer(&chwcap[0]))[:size:si= ze] + return nil +} =20 - // 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 =20 - return + for i, v :=3D range hwcap { + chwcap[i] =3D C.uint32_t(v) + } + + return chwcap, nil } =20 // KeyValueList represents a libxl_key_value_list. @@ -442,7 +447,7 @@ func (cphys *C.libxl_physinfo) toGo() (physinfo *Physin= fo) { physinfo.SharingFreedPages =3D uint64(cphys.sharing_freed_pages) physinfo.SharingUsedFrames =3D uint64(cphys.sharing_used_frames) physinfo.NrNodes =3D uint32(cphys.nr_nodes) - physinfo.HwCap =3D cphys.hw_cap.toGo() + physinfo.HwCap.fromC(&cphys.hw_cap) physinfo.CapHvm =3D bool(cphys.cap_hvm) physinfo.CapHvmDirectio =3D bool(cphys.cap_hvm_directio) =20 --=20 2.19.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel