From nobody Tue Nov 11 08:27:22 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=1569339137; cv=none; d=zoho.com; s=zohoarc; b=cAYGjJtPGHf5coFpzzVQB7B2lXVfldOAcQQB2i9DWEHBCFn01/4ok/VKz1twH9QfvawNMy5SnRqC2L8JgtoQn4XS7/K5jOO/KBIP05xU1fkYtp46v82mEy7FBsitDOrTJYLvwGJNef/YgKQUvYacbFXS7y5vCdhbwD5aSXjIrOo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569339137; 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=/a9lIQb2kOrWXrL8nfojNknZoPqNIjBw5fu3TOz6P2w=; b=NbarLxffeCIw35mtBH9pcMUdCaRoMrPFOnBL9/jythLET4VkWRlZIDOITtnIeJS1A0vgCW2+w4SCVqAEasc5Cic5LnMdF96j9Y1sc6nbuYiCmQSUyW8vgjo3+CsntGX0QUCK7IMsTo5kya1FVOv3220rldHAeD2mE6nrU/5F0S4= 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 1569339137985221.37990681051247; Tue, 24 Sep 2019 08:32:17 -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 1iCmmV-0007ts-TI; Tue, 24 Sep 2019 15:31:11 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iCmmU-0007tR-Vr for xen-devel@lists.xenproject.org; Tue, 24 Sep 2019 15:31:11 +0000 Received: from mail-lf1-x142.google.com (unknown [2a00:1450:4864:20::142]) by localhost (Halon) with ESMTPS id 4c5337d8-dee0-11e9-97fb-bc764e2007e4; Tue, 24 Sep 2019 15:30:55 +0000 (UTC) Received: by mail-lf1-x142.google.com with SMTP id q11so1739458lfc.11 for ; Tue, 24 Sep 2019 08:30:55 -0700 (PDT) Received: from otyshchenko.kyiv.epam.com (ll-74.141.223.85.sovam.net.ua. [85.223.141.74]) by smtp.gmail.com with ESMTPSA id z128sm525818lfa.1.2019.09.24.08.30.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Sep 2019 08:30:52 -0700 (PDT) X-Inumbo-ID: 4c5337d8-dee0-11e9-97fb-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=dAXIdOzd5atuBvsXDzswi8p3w2Qe44gCP0DnzcVW2iI=; b=c9rxzKKSk0cCCaf04TMT7q8FmKtllw9FcvMS0MsrP2lO/cH92sh3wuI4ogVvd8fntN g+eKwqaDkxNnPUBPvQHu8MhtP4LgmF5Wp7wTaWC8uHf39Wu21KzoKm4Rt9IubIQ4mfpS M7Kt+v1UVA1m6pzDWPt1HXxPWs25rybA1BHtYiB+JHRHB9fmWRnqUdOW8fTboa5nQ6Dl 5Wp86FTv7tMefJ8sAGHRSpAnIE692bzk5Ia0+IxY25oR9pOa9lTl8mLj+4rsA+TW08i+ 4U6HrsGLbdNn0Ybv9zrYLjBYOteQsUo1oGn4eQ3ZvC7Ba1dKzh/nHjvPie9ysAPCUoU1 TuAQ== 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=dAXIdOzd5atuBvsXDzswi8p3w2Qe44gCP0DnzcVW2iI=; b=m4znBmj0gSML6a+PtX1qAClpufr48L73rR6EJ0ZaURVOgmmbuyfaaizQc2J+JXZECr SPpApIiJUoI95sawUEizattpMzRBhPaChctPjP8mO+8d9NJzhDbAAiS/E6u02L1Vj81x 7SV6dilBoAAc+dxET4A6UXawibbqiSDtzaRGX+zw3k+whe6H//afYpIxIMp5+/wFz+Cu 8lTpw/IaIR1VqKbgXCfg5gpTMOdTXleuaE5ryT3WZ4KnmRGT6IEqaulet/b9nDTGUDw9 Tz1S2Yr77EJCGpjlhcT8e0jwz/E3a1EXy6wFfprG8DdVrzV+MQIRyhTHdI0IBrX8g3ZN o4NQ== X-Gm-Message-State: APjAAAVpkClwLE4QhHlKmJjiurTE2lei/N9r7OQISFHZdgTu+odV0RC2 ZIpEzOK9u1smtxQZGAZwIX6zERlS28s= X-Google-Smtp-Source: APXvYqyTopsiIiak5OUxOOlpbxeMPwSJ/QGpMYAc5YuXNte2/WoJY0PWJEINJqb+/gUKPk3/I7pfpg== X-Received: by 2002:ac2:5dd0:: with SMTP id x16mr2354993lfq.38.1569339053076; Tue, 24 Sep 2019 08:30:53 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Tue, 24 Sep 2019 18:30:23 +0300 Message-Id: <1569339027-19484-5-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569339027-19484-1-git-send-email-olekstysh@gmail.com> References: <1569339027-19484-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V5 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 the "data" array: struct arrlen { size_t len; int data[]; }; We can use the proposed macros in the following way: new_ptr =3D realloc_flex_struct(old_ptr, data, nr_elem); where nr_elem is the desired number of elements. Subsequent patch will use this macros. Also, while here, introduce xmalloc(xzalloc)_flex_struct() to allocate space for a structure with a flexible array of typed objects. Suggested-by: Volodymyr Babchuk Signed-off-by: Oleksandr Tyshchenko Reviewed-by: Jan Beulich CC: Andrew Cooper CC: George Dunlap CC: Ian Jackson CC: Julien Grall CC: Konrad Rzeszutek Wilk CC: Stefano Stabellini CC: Tim Deegan CC: Wei Liu --- Changes V4 -> V5: - clarified patch description (data[] instead of data[1]) - introduced xzalloc_flex_struct() - added Jan's R-b - added missing parentheses around the entire constructs Changes V3 -> V4: - clarified patch description - modified to not use leading underscores - removed unnecessary pair of outermost parentheses - modified to use "nr" instead of "len" - placed xmalloc_flex_struct before xrealloc_flex_struct - simplified xrealloc_flex_struct macros --- 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..f515cee 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 +/* Allocate space for a structure with a flexible array of typed objects. = */ +#define xzalloc_flex_struct(type, field, nr) \ + ((type *)_xzalloc(offsetof(type, field[nr]), __alignof__(type))) + +#define xmalloc_flex_struct(type, field, nr) \ + ((type *)_xmalloc(offsetof(type, field[nr]), __alignof__(type))) + +/* Re-allocate space for a structure with a flexible array of typed object= s. */ +#define xrealloc_flex_struct(ptr, field, nr) \ + ((typeof(ptr))_xrealloc(ptr, offsetof(typeof(*(ptr)), field[nr]), \ + __alignof__(typeof(*(ptr))))) + /* 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