[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Xen-devel] [RFC 3/6] Introduce _xrealloc
- To: Sameer Goel <sgoel@xxxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx
- From: Julien Grall <julien.grall@xxxxxxx>
- Date: Thu, 8 Jun 2017 20:49:01 +0100
- Cc: Stefano Stabellini <sstabellini@xxxxxxxxxx>, Wei Liu <wei.liu2@xxxxxxxxxx>, George Dunlap <george.dunlap@xxxxxxxxxxxxx>, Tomasz Nowicki <tn@xxxxxxxxxxxx>, Punit Agrawal <punit.agrawal@xxxxxxx>, Jan Beulich <jbeulich@xxxxxxxx>, Andrew Cooper <Andrew.Cooper3@xxxxxxxxxx>, Ian Jackson <Ian.Jackson@xxxxxxxxxx>, nd@xxxxxxx, Robin Murphy <robin.murphy@xxxxxxx>, Shanker Donthineni <shankerd@xxxxxxxxxxxxxx>
- Delivery-date: Thu, 08 Jun 2017 19:49:22 +0000
- List-id: Xen developer discussion <xen-devel.lists.xen.org>
- Nodisclaimer: True
- Spamdiagnosticmetadata: NSPM
- Spamdiagnosticoutput: 1:99
CC the REST maintainers
On 08/06/2017 20:30, Sameer Goel wrote:
Introduce a memory realloc function.
Signed-off-by: Sameer Goel <sgoel@xxxxxxxxxxxxxx>
---
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)
Coding style: if ( ... )
+ {
+ 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)
--
Julien Grall
_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
https://lists.xen.org/xen-devel
|