From nobody Sat Sep 21 05:45:09 2024 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=1569496957; cv=none; d=zoho.com; s=zohoarc; b=KeCuz45G610VrC+7NCGMJAEO/6LHJ6ZmoiKP8wxEPwjDZO0cabZ4c862uPnPCvXrZe44os1/Ke22NhP7GisXvyFbjruHZGjgEmEsygkDQt564s544unACxPnwcab/gZTveHCDd5/Cp5Wgditn4xZ2lCyP4bpT+vpbX8cV/ZN4A0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1569496957; 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=Ur6b+M1fAxjOyMQMcd8tJWlju2l+KYA2R1Dxdu1ggx8py3KUgI7ow5fapiBX8FXKg7bjgSW0Q1sreOZWgjauVlhkqR7hitBLs8TG2zeaaxFH5MKwD6FC6bSnz+/gUKbGmhUNf81Kifs+fJLqynLt3u0wuJ2ApaSOHUuKuHZO6Vs= 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 1569496957575464.7763955679586; Thu, 26 Sep 2019 04:22:37 -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 1iDRpp-0008Pv-JN; Thu, 26 Sep 2019 11:21:21 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1iDRpn-0008O3-VI for xen-devel@lists.xenproject.org; Thu, 26 Sep 2019 11:21:19 +0000 Received: from mail-lj1-x244.google.com (unknown [2a00:1450:4864:20::244]) by localhost (Halon) with ESMTPS id b6a54ffc-e04f-11e9-8628-bc764e2007e4; Thu, 26 Sep 2019 11:20:58 +0000 (UTC) Received: by mail-lj1-x244.google.com with SMTP id m13so1729609ljj.11 for ; Thu, 26 Sep 2019 04:20:58 -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 n4sm526810lfi.63.2019.09.26.04.20.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 26 Sep 2019 04:20:57 -0700 (PDT) X-Inumbo-ID: b6a54ffc-e04f-11e9-8628-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=qvERueVUWGcvRjU9PHVaWcsnxxOxknWatng+s3KqSo26O+qAYin25nioWtvm0DmdHk V4yF7vI+z6G+nZY1DHG12ql4Ebanf90ooSgJd7EOO178byZi1R0L26E+Sl5oa69w0loq +CAvPdB9j4Xm7sWeXr9C8BH/rFEFiMGvnlQGua3nNnzlrzmjIiXPOFCoM9hEIESy7NGQ diXjqNpxE5Q6wJMtgmBLBXU4u3CLS7C0rpDwXLLKHrjOoAcr0qMzmfDoI4aZZoSM+d77 xIddAw+FCrEQSEZkjVra6/qw1VOm8Ur399G58574SiRpVVjIrZk13f7lCGsesdCZvZrO fEsw== 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=MpKF8OqfAxUPCIReBcTJ3BEnG+HN+W8M0IY8rH49tS3lsrQhGR6+V+wHPQrmJdFIdn DIsNcORnlxQp0CCy1WTc/+LzoiHonwIX7lVyeIs5BV/wZCv3t/IBuROUySruu6Pv+OrK vfKw64UP6YRQ69dZ72xTOZXvZZbs+hCzshUpPX7TAXpLrnGTMOYOx1t1C6v8wxnBaxPM YcuP3E0gpuWpNnSheuLPqzA9RegwnRva+Oe3ij2duNRoYn+l+vnm3OdoB7SgmlAZpY3Q UfODaSev0kW95ANz8Euh9ZUGN+6ew4FL52nEQunflCpWVbibfEf1rVD+RAKmsv7hRsYZ NV0A== X-Gm-Message-State: APjAAAUTN/hhkqOsLwBVI1hHREbS4Q9Dkc5799w8V1h6QUlbTSc7L2Jz vt7CPPFIycKQ4Z1/kd/No/dSJcXT++0= X-Google-Smtp-Source: APXvYqzsvs6tapShkjo34DjDboU6SSqraxPjEWYzvfEeupYOqPTZAWd/NIoG3eRsdvTIeaKDg7RW8w== X-Received: by 2002:a2e:2e17:: with SMTP id u23mr522736lju.26.1569496857662; Thu, 26 Sep 2019 04:20:57 -0700 (PDT) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Date: Thu, 26 Sep 2019 14:20:30 +0300 Message-Id: <1569496834-7796-5-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1569496834-7796-1-git-send-email-olekstysh@gmail.com> References: <1569496834-7796-1-git-send-email-olekstysh@gmail.com> Subject: [Xen-devel] [PATCH V6 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