From nobody Mon Feb 9 15:30:09 2026 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=1566324694; cv=none; d=zoho.com; s=zohoarc; b=Cgbi+sjlTwv7cyW282uNOtRc3bn7JHzOVvIY4ml5/qL7Ish6pm+bW9UrmLC/uJA9WgJY/Vih+rgj0/aHKq42AllE9Km0LPLZagoANSJLYWTmhKpAYYLBo+WJNa9JLX2dspZ+OB4CdlM/mswxadUrCUAY9y0SVk0d7kc2XD4aWJo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566324694; 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=UYWRVDwHWFJKeISYGPAaSiXdHay0zpdhnuQoIQ5QuoU=; b=JsB39jVODNFg5QtgADM/L6NZsFnV7ig0kBxsJJt1o41dWy6/5IqZL9Atz6qtan6JN3puZQKne0wLWeIv8qq6+iwNvvQ1vcpEMwgpKeldjtgKqb079af3U27Ek427vDpr/9k8rEUCPR7kgBWNxLP77gPpXdeFQalbHUbDoaxSp94= 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 1566324694850441.7960096022765; Tue, 20 Aug 2019 11:11:34 -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 1i08aP-000664-D1; Tue, 20 Aug 2019 18:10:25 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1i08aO-00065T-1E for xen-devel@lists.xenproject.org; Tue, 20 Aug 2019 18:10:24 +0000 Received: from mail-lf1-x144.google.com (unknown [2a00:1450:4864:20::144]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id c06f55ba-c375-11e9-92eb-bc764e2007e4; Tue, 20 Aug 2019 18:10:12 +0000 (UTC) Received: by mail-lf1-x144.google.com with SMTP id h28so4835786lfj.5 for ; Tue, 20 Aug 2019 11:10:12 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-22.209.223.85.sovam.net.ua. [85.223.209.22]) by smtp.gmail.com with ESMTPSA id f6sm2900642lja.16.2019.08.20.11.10.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 20 Aug 2019 11:10:10 -0700 (PDT) X-Inumbo-ID: c06f55ba-c375-11e9-92eb-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; bh=kZfdOq/+AGxkg2VwkO+D5NSs5HyNMq9JZ1kdANT+Bnk=; b=Jrb2DpazIWO88b8zrS0b/B+vEYrMcfRKrSJxbA/qKv3hcCTLsaqT7oTeNsfM9sZ1qe NeTMVoDfXZpm36IC3H721epT3qwE78+SfF/bDAR70TpsY8iZ/E0Ixfv0Q43bvT44kWej 0TJVFMM75DzM5KkCx/hVNJsS6YdirrI+I0dlrh/AKS5jwIr5UxXKrBnWyaEfELmcf+pR dn1Xx8222XwSuoCYv+uOuwRA3JWbOm6GRcvcMXy92Q3qmodmbHobWwIBuR4F0uyrVQNi 1G3quZaaBYDeQyEbXFF9mJ0I6aKdcobuVWPkD3IkJjcJA2508zE2XHYLwgi2udx/m9HX W/EQ== 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; bh=kZfdOq/+AGxkg2VwkO+D5NSs5HyNMq9JZ1kdANT+Bnk=; b=AZ9xd8OvoBn8m0rjK69Pw8EOU++rLuLCRByqZW1XnDLPPrV3JwAKoOiOmrZe32tShp xOaS3ShpGHoUkeW4ljb7Ssznp+6aXklLE2DlwljrhRL76w9jASyqP3cseHTshexvr3Ox j3A/88tiveOjVDalehq/reHM3hVuuXMOr+W8teHVqHLPQLCngrfycAgIkMzMfh/f94tE L9NPjTdGcWruWesueZVb3pMgYI+tRyPX5mL9Y2Phw9OucoOVRzj6E3GvfgFo3BNv8xeh 6iN0GtqA7yVaE7SkOMWouA1vhx557dJXMNvd6sTEPH1Sp1Ak9KgN3fekc8hUdAtA30Ue 0wEg== X-Gm-Message-State: APjAAAVTy2O1+s6BBBx9zGWfy01bV+9PXYYtXv2ItbU+EJ+Iq6jQgnRZ WAKpVZ0dkfqj/YyttfUZud3zIvCJ X-Google-Smtp-Source: APXvYqzsR+0iryHKEfyRBzm7bowhHAc9PeG/t72fd1UwYtnM1rZpvp5996FpJoFVfnfzYDdJFMUPWA== X-Received: by 2002:ac2:4289:: with SMTP id m9mr17484739lfh.49.1566324611260; Tue, 20 Aug 2019 11:10:11 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 20 Aug 2019 21:09:43 +0300 Message-Id: <1566324587-3442-5-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1566324587-3442-1-git-send-email-olekstysh@gmail.com> References: <1566324587-3442-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V3 4/8] xen/common: Introduce xrealloc_flex_struct() helper macros 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: sstabellini@kernel.org, Wei Liu , Konrad Rzeszutek Wilk , George Dunlap , Andrew Cooper , Ian Jackson , Tim Deegan , Oleksandr Tyshchenko , julien.grall@arm.com, Jan Beulich , Volodymyr_Babchuk@epam.com MIME-Version: 1.0 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: Oleksandr Tyshchenko This patch introduces type-safe helper macros to re-allocate space for a structure with a flexible array of typed objects. For example, if we need to re-size an array with a single element: struct arrlen { size_t len; int data[1]; }; We can use the proposed macros in the following way: new_ptr =3D realloc_flex_struct(old_ptr, struct arrlen, data, num_elem); Subsequent patch will use this macros. Also, while here, introduce xmalloc_flex_struct() to allocate space for a structure with a flexible array of typed objects. Suggested-by: Volodymyr Babchuk Signed-off-by: Oleksandr Tyshchenko CC: Andrew Cooper CC: George Dunlap CC: Ian Jackson CC: Jan Beulich CC: Julien Grall CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: Tim Deegan CC: Wei Liu --- xen/include/xen/xmalloc.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h index 831152f..2eb88a8 100644 --- a/xen/include/xen/xmalloc.h +++ b/xen/include/xen/xmalloc.h @@ -35,6 +35,18 @@ #define xzalloc_array(_type, _num) \ ((_type *)_xzalloc_array(sizeof(_type), __alignof__(_type), _num)) =20 +/* Re-allocate space for a structure with a flexible array of typed object= s. */ +#define xrealloc_flex_struct(_ptr, _type, _field, _len) ({ = \ + /* type checking: make sure that incoming pointer is of correct type *= / \ + (void)((typeof(_ptr)) 0 =3D=3D (_type *) 0); = \ + ((_type *)_xrealloc(_ptr, offsetof(_type, _field[_len]), = \ + __alignof__(_type))); = \ +}) + +/* Allocate space for a structure with a flexible array of typed objects. = */ +#define xmalloc_flex_struct(_type, _field, _len) \ + ((_type *)_xmalloc(offsetof(_type, _field[_len]), __alignof__(_type))) + /* Allocate untyped storage. */ #define xmalloc_bytes(_bytes) _xmalloc(_bytes, SMP_CACHE_BYTES) #define xzalloc_bytes(_bytes) _xzalloc(_bytes, SMP_CACHE_BYTES) --=20 2.7.4 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel