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-devel

[Xen-devel] [PATCH] [Mini-OS] add realloc

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] [Mini-OS] add realloc
From: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Date: Thu, 17 Jan 2008 14:57:14 +0000
Delivery-date: Thu, 17 Jan 2008 06:58:24 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Mail-followup-to: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.12-2006-07-14
add realloc

Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
Signed-off-by: Tim Deegan <tim.deegan@xxxxxxxxxxxxx>

# HG changeset patch
# User Samuel Thibault <samuel.thibault@xxxxxxxxxxxxx>
# Date 1200581655 0
# Node ID 75de0dc5198095fa4e845f4132e3370557986748
# Parent  92de8fa028b8e6696fa386b7430537d1cf99e429
add realloc

diff -r 92de8fa028b8 -r 75de0dc51980 extras/mini-os/include/xmalloc.h
--- a/extras/mini-os/include/xmalloc.h  Thu Jan 17 14:05:38 2008 +0000
+++ b/extras/mini-os/include/xmalloc.h  Thu Jan 17 14:54:15 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 92de8fa028b8 -r 75de0dc51980 extras/mini-os/lib/xmalloc.c
--- a/extras/mini-os/lib/xmalloc.c      Thu Jan 17 14:05:38 2008 +0000
+++ b/extras/mini-os/lib/xmalloc.c      Thu Jan 17 14:54:15 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-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>
  • [Xen-devel] [PATCH] [Mini-OS] add realloc, Samuel Thibault <=