From nobody Tue Nov 11 07:31:05 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=1570461281; cv=none; d=zoho.com; s=zohoarc; b=oJxaz/lSK6P/KMdqtXm61PWRhcC/VaBp9hHuJMdPmsOEqSCxW6w0Dc3NrMauTy73INEz15JzomxsmBgQnyN2+s0DBDhMpJh0vHp5cQuLZzF7ll+qjKKoTx4dYRJIF/hJ/jCeud5nhOdzcmL0Jzr/kftfWpJOxhb2TlCsaKEHpyM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1570461281; 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=qbZWEjppbchpSCBhXDQTjD90bfg1NrFMUHMxoVf6c+g=; b=nfugnTi3mBjNPZY0yriMLPg5dLnKgNXCwcVqa78KP77viUV1alVYFAqMMOlQsGQpaDedaMidg5aGr/z9sQxZ99mV00coIDan/NwY+Y7a/TX3mMCg0QgE3CBrLN78o+LzH4T//5+DjBczKjoHvDy0fNbfM+K4inDJdonkR+SP3w4= 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 1570461281987827.265596725218; Mon, 7 Oct 2019 08:14:41 -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 1iHUhj-0006oN-3Z; Mon, 07 Oct 2019 15:13:43 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iHUhh-0006o1-NB for xen-devel@lists.xenproject.org; Mon, 07 Oct 2019 15:13:41 +0000 Received: from mail-qt1-x844.google.com (unknown [2607:f8b0:4864:20::844]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 004593ce-e915-11e9-8c93-bc764e2007e4; Mon, 07 Oct 2019 15:13:22 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id r5so19712303qtd.0 for ; Mon, 07 Oct 2019 08:13:22 -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.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 07 Oct 2019 08:13:20 -0700 (PDT) X-Inumbo-ID: 004593ce-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=TJRUOKvva5SLQ3Yr7539G+VB4p4r5aLPOvKs+CyiVbA=; b=YxdGMLfDM9zzVkeza3Z/PJHpdIk+Ls3pmKxvgSkI0YCRhMEcAIIEyft7svew0LH6jq sAUaT9TxcfrHdhLYcH7gqMwzlvyg9ekCR7cyVapi3MtlEUo0EXfVWhsOcmUCqiwQRIg5 10UWzY0FPaffJ2cO3utvRGMK519XY5sfgf0LbjNE/xGSI1faEWaRc7pSA/mdtq1xWe8I dOxYGPFBv1DhS7lblDGccbSNwev20PNUN2D4FVXylAa8qQGh/xGu3s5mASRkujDMNqvf sqRDL1zLRxyVhVYAtmFktCRpIkoLQV0JgWrVQjxi2ALhR/x2UZWTRrZQD32YISMoCw6q Mlwg== 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=TJRUOKvva5SLQ3Yr7539G+VB4p4r5aLPOvKs+CyiVbA=; b=AC4s8JyGdPypGMgpDcB7wgAjsGFSJKucqw1ZUP1ndtB+45TGUact5Zdn0Z7AOw5YqT 4/uAXjiJ1UTF/9tGQ3rguldfIeIJ0BDhbyj9m2eQrfV3Xpq6UnzxhXOehYwSWYytbh83 azuMSUoKiwVXcfFr9sqM+WaR6ij1a8fxhSocQu0Ce1FKdyY106K43wvvZs3S+y/ABRF0 e2V4QFl5wB+Wm/CmCKwao4cAxfVbe5XqtM3grx/8lbEeoIg3B+RSUKMOICQmedlwVFEW KoZfg8nPAL7Rln4d/eXxOFNUP5wEKxP2GcOR3/zMKRrExE1nniy7gwyZ3AcLT2OLH0cn Ux9Q== X-Gm-Message-State: APjAAAWDG7IK0xZy79QEOCLMw9VGgIqHEBVFtgCqLhf2TPzJBY305EpL nhQRuxV7JMfyQbzE5hkgjUSwduPo X-Google-Smtp-Source: APXvYqzVk64vhu/ZdN8eKk0DeCll8ZmeZyAj6CigP0BLVi6+bqSdNrny7mL7x03P5QjLROfXVNee4Q== X-Received: by 2002:a0c:88f0:: with SMTP id 45mr27359942qvo.78.1570461201345; Mon, 07 Oct 2019 08:13:21 -0700 (PDT) From: Nick Rosbrook To: xen-devel@lists.xenproject.org Date: Mon, 7 Oct 2019 11:12:52 -0400 Message-Id: <1a60b855c0886c8e7147d48923f16b4d0815db81.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 05/24] golang/xenlight: define KeyValueList builtin type 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 Define KeyValueList builtin type, analagous to libxl_key_value_list as map[string]string, and implement its fromC and toC functions. Signed-off-by: Nick Rosbrook --- Cc: George Dunlap Cc: Ian Jackson Cc: Wei Liu tools/golang/xenlight/xenlight.go | 33 ++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/tools/golang/xenlight/xenlight.go b/tools/golang/xenlight/xenl= ight.go index 4d4fad2a9d..8196a42855 100644 --- a/tools/golang/xenlight/xenlight.go +++ b/tools/golang/xenlight/xenlight.go @@ -202,11 +202,42 @@ func (chwcap C.libxl_hwcap) toGo() (ghwcap Hwcap) { return } =20 +// KeyValueList represents a libxl_key_value_list. +type KeyValueList map[string]string + +func (kvl KeyValueList) fromC(ckvl *C.libxl_key_value_list) error { + size :=3D int(C.libxl_key_value_list_length(ckvl)) + list :=3D (*[1 << 30]*C.char)(unsafe.Pointer(ckvl))[:size:size] + + for i :=3D 0; i < size*2; i +=3D 2 { + kvl[C.GoString(list[i])] =3D C.GoString(list[i+1]) + } + + return nil +} + +func (kvl KeyValueList) toC() (C.libxl_key_value_list, error) { + // Add extra slot for sentinel + var char *C.char + csize :=3D 2*len(kvl) + 1 + ckvl :=3D (C.libxl_key_value_list)(C.malloc(C.ulong(csize) * C.ulong(unsa= fe.Sizeof(char)))) + clist :=3D (*[1 << 31]*C.char)(unsafe.Pointer(ckvl))[:csize:csize] + + i :=3D 0 + for k, v :=3D range kvl { + clist[i] =3D C.CString(k) + clist[i+1] =3D C.CString(v) + i +=3D 2 + } + clist[len(clist)-1] =3D nil + + return ckvl, nil +} + // typedef struct { // uint32_t size; /* number of bytes in map */ // uint8_t *map; // } libxl_bitmap; - // Implement the Go bitmap type such that the underlying data can // easily be copied in and out. NB that we still have to do copies // both directions, because cgo runtime restrictions forbid passing to --=20 2.19.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel