WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-changelog

[Xen-changelog] [xen-unstable] minios: add realloc

# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1200582390 0
# Node ID 8984cc0a1d80ebfe6a92d23bf35aea8d54914f45
# Parent  8f6640070a863aa30bfb242ad20e9a043ebe44b8
minios: add realloc

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Signed-off-by: Tim Deegan <tim.deegan@xxxxxxxxxxxxx>
---
 extras/mini-os/include/xmalloc.h |    3 +++
 extras/mini-os/lib/xmalloc.c     |   21 +++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff -r 8f6640070a86 -r 8984cc0a1d80 extras/mini-os/include/xmalloc.h
--- a/extras/mini-os/include/xmalloc.h  Thu Jan 17 14:41:44 2008 +0000
+++ b/extras/mini-os/include/xmalloc.h  Thu Jan 17 15:06:30 2008 +0000
@@ -9,12 +9,15 @@
 
 #define malloc(size) _xmalloc(size, 4)
 #define free(ptr) xfree(ptr)
+#define realloc(ptr, size) _realloc(ptr, size)
 
 /* Free any of the above. */
 extern void xfree(const void *);
 
 /* Underlying functions */
 extern void *_xmalloc(size_t size, size_t align);
+extern void *_realloc(void *ptr, size_t size);
+
 static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
 {
        /* Check for overflow. */
diff -r 8f6640070a86 -r 8984cc0a1d80 extras/mini-os/lib/xmalloc.c
--- a/extras/mini-os/lib/xmalloc.c      Thu Jan 17 14:41:44 2008 +0000
+++ b/extras/mini-os/lib/xmalloc.c      Thu Jan 17 15:06:30 2008 +0000
@@ -223,3 +223,24 @@ void xfree(const void *p)
     /* spin_unlock_irqrestore(&freelist_lock, flags); */
 }
 
+void *_realloc(void *ptr, size_t size)
+{
+    void *new;
+    struct xmalloc_hdr *hdr;
+
+    if (ptr == NULL)
+        return _xmalloc(size, 4);
+
+    hdr = (struct xmalloc_hdr *)ptr - 1;
+    if (hdr->size >= size) 
+        return ptr;
+    
+    new = _xmalloc(size, 4);
+    if (new == NULL) 
+        return NULL;
+
+    memcpy(new, ptr, hdr->size);
+    xfree(ptr);
+
+    return new;
+}

_______________________________________________
Xen-changelog mailing list
Xen-changelog@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-changelog

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-changelog] [xen-unstable] minios: add realloc, Xen patchbot-unstable <=