From patchwork Thu Jun 8 19:30:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Goel, Sameer" X-Patchwork-Id: 9776323 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2F95A603B4 for ; Thu, 8 Jun 2017 19:33:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1A9AD28579 for ; Thu, 8 Jun 2017 19:33:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0FA8E28597; Thu, 8 Jun 2017 19:33:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 430D428579 for ; Thu, 8 Jun 2017 19:33:44 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJ39F-00014Q-Sh; Thu, 08 Jun 2017 19:31:13 +0000 Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJ39E-00013v-7t for xen-devel@lists.xenproject.org; Thu, 08 Jun 2017 19:31:12 +0000 Received: from [85.158.139.211] by server-11.bemta-5.messagelabs.com id 08/F6-01733-FF5A9395; Thu, 08 Jun 2017 19:31:11 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrJIsWRWlGSWpSXmKPExsVybKJsgu7/pZa RBtcZLb5vmczkwOhx+MMVlgDGKNbMvKT8igTWjMlr57IWvOKuuPDxHnsD4wfOLkZODiGBIon2 W29Yuhi5OFgEGpglHq/ayAqSkBCIlli34Rg7hM0ncfHFDyaQIgmBCYwSv742M4I4QgIHmSS2b P/AhKGdRcBF4sn7I4wgNqNAgcScDR+h7BSJWV1vwGw2AQ2J/hOHmUFsEQEPiavNy9hABjELfG GU+Lu2gw0kISygJrG45SwbxFBViV3Lt7OA2LwCzhJ7Nt6AulVB4vj2bWBDOYEWzzzRwwrxnLP EsfUPWScwCi9gZFjFqFGcWlSWWqRrZKqXVJSZnlGSm5iZo2toYKqXm1pcnJiempOYVKyXnJ+7 iREYpPUMDIw7GHe1+x1ilORgUhLlVWy1jBTiS8pPqcxILM6ILyrNSS0+xCjDwaEkwXtwCVBOs Cg1PbUiLTMHGC8waQkOHiURXhGQNG9xQWJucWY6ROoUo6KUOO8ukIQASCKjNA+uDRajlxhlpY R5GRkYGIR4ClKLcjNLUOVfMYpzMCoJ8/aDTOHJzCuBm/4KaDET0OIl7yxAFpckIqSkGhgjllk vUf5bzlVsnu+75mP7+jYVGx7l2N8Xsi9ucci9xfHu/feJHX+XLO690VEtL2Lb4fVT9e+XQ++z vPdNfbLlmmU/b2i7SvqNhOhI+a/VQd8exQs05q52c7qb4pKmaPeg/MKjZsUIXklpxZun6pwV7 /iUvlwqvtnxk+TDWx8LLyom1xlf/aLEUpyRaKjFXFScCADL4u0yzAIAAA== X-Env-Sender: sgoel@codeaurora.org X-Msg-Ref: server-8.tower-206.messagelabs.com!1496950269!102393493!1 X-Originating-IP: [198.145.29.96] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 4064 invoked from network); 8 Jun 2017 19:31:10 -0000 Received: from smtp.codeaurora.org (HELO smtp.codeaurora.org) (198.145.29.96) by server-8.tower-206.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Jun 2017 19:31:10 -0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6D3E6611B5; Thu, 8 Jun 2017 19:31:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1496950269; bh=BPYSTsIjq5+DNcpzPL0sSa7w6+ML0Zu4rWz9o2DZCro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lcLIKnD09nHqLn+NnEFdmGZWTdz1q6Detek8Md4nPubT1cvw9LTH0pcXejvj9fs5i N5btvkaP1a14uJw5FhO7iErYVczVjUL36A5WSIqOPkgZWIXTBvT+MBkhzr30rgDZW2 2ryF7ps9SIVpUcMs+uHLlPqAnc1hyvItE77n3fOg= Received: from sgoel-lnx.qualcomm.com (unknown [129.46.14.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sgoel@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 735DD61155; Thu, 8 Jun 2017 19:31:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1496950269; bh=BPYSTsIjq5+DNcpzPL0sSa7w6+ML0Zu4rWz9o2DZCro=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lcLIKnD09nHqLn+NnEFdmGZWTdz1q6Detek8Md4nPubT1cvw9LTH0pcXejvj9fs5i N5btvkaP1a14uJw5FhO7iErYVczVjUL36A5WSIqOPkgZWIXTBvT+MBkhzr30rgDZW2 2ryF7ps9SIVpUcMs+uHLlPqAnc1hyvItE77n3fOg= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 735DD61155 From: Sameer Goel To: xen-devel@lists.xenproject.org, Julien Grall Date: Thu, 8 Jun 2017 13:30:44 -0600 Message-Id: <1496950247-8755-4-git-send-email-sgoel@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1496950247-8755-1-git-send-email-sgoel@codeaurora.org> References: <1496950247-8755-1-git-send-email-sgoel@codeaurora.org> Cc: Stefano Stabellini , Tomasz Nowicki , Punit Agrawal , Sameer Goel , Robin Murphy , Shanker Donthineni Subject: [Xen-devel] [RFC 3/6] Introduce _xrealloc X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP Introduce a memory realloc function. Signed-off-by: Sameer Goel --- xen/common/xmalloc_tlsf.c | 13 +++++++++++++ xen/include/xen/xmalloc.h | 1 + 2 files changed, 14 insertions(+) diff --git a/xen/common/xmalloc_tlsf.c b/xen/common/xmalloc_tlsf.c index b256dc5..52385a8 100644 --- a/xen/common/xmalloc_tlsf.c +++ b/xen/common/xmalloc_tlsf.c @@ -612,6 +612,19 @@ void *_xzalloc(unsigned long size, unsigned long align) return p ? memset(p, 0, size) : p; } +void *_xrealloc(void *p, unsigned long new_size, unsigned long align) +{ + void *new_p = _xmalloc(new_size, align); + + if(new_p && p) + { + memcpy(new_p, p, new_size); + xfree(p); + } + + return new_p; +} + void xfree(void *p) { struct bhdr *b; diff --git a/xen/include/xen/xmalloc.h b/xen/include/xen/xmalloc.h index 24a99ac..41a9b2f 100644 --- a/xen/include/xen/xmalloc.h +++ b/xen/include/xen/xmalloc.h @@ -29,6 +29,7 @@ extern void xfree(void *); /* Underlying functions */ extern void *_xmalloc(unsigned long size, unsigned long align); extern void *_xzalloc(unsigned long size, unsigned long align); +extern void *_xrealloc(void *p, unsigned long new_size, unsigned long align); static inline void *_xmalloc_array( unsigned long size, unsigned long align, unsigned long num)