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-3.4-testing] minios: xmalloc and realloc fixes

To: xen-changelog@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-changelog] [xen-3.4-testing] minios: xmalloc and realloc fixes
From: "Xen patchbot-3.4-testing" <patchbot-3.4-testing@xxxxxxxxxxxxxxxxxxx>
Date: Thu, 29 Oct 2009 08:05:30 -0700
Delivery-date: Thu, 29 Oct 2009 08:06:16 -0700
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-changelog-request@lists.xensource.com?subject=help>
List-id: BK change log <xen-changelog.lists.xensource.com>
List-post: <mailto:xen-changelog@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-changelog>, <mailto:xen-changelog-request@lists.xensource.com?subject=unsubscribe>
Reply-to: xen-devel@xxxxxxxxxxxxxxxxxxx
Sender: xen-changelog-bounces@xxxxxxxxxxxxxxxxxxx
# HG changeset patch
# User Keir Fraser <keir.fraser@xxxxxxxxxx>
# Date 1256828550 0
# Node ID d626b239fed17f3c937231318d3a71409045bc35
# Parent  4174e32f7c891f51e2f8791389dae63d273ec4ec
minios: xmalloc and realloc fixes

 - xmalloc currently faults if xmalloc_new_page fails due to OOM
 - realloc treats xmalloc_hdr.size as the size of just the data region
   rather than the total size of data region + headers + padding.

From: James Pendergrass <James.Pendergrass@xxxxxxxxxx>
Signed-off-by: Keir Fraser <keir.fraser@xxxxxxxxxx>
xen-unstable changeset:   20383:e1fd971ec20e
xen-unstable date:        Thu Oct 29 08:34:51 2009 +0000
---
 extras/mini-os/lib/xmalloc.c |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)

diff -r 4174e32f7c89 -r d626b239fed1 extras/mini-os/lib/xmalloc.c
--- a/extras/mini-os/lib/xmalloc.c      Thu Oct 29 15:02:00 2009 +0000
+++ b/extras/mini-os/lib/xmalloc.c      Thu Oct 29 15:02:30 2009 +0000
@@ -187,6 +187,8 @@ void *_xmalloc(size_t size, size_t align
 
         /* Alloc a new page and return from that. */
         hdr = xmalloc_new_page(align_up(hdr_size, align) + size);
+        if ( hdr == NULL )
+            return NULL;
         data_begin = (uintptr_t)hdr + align_up(hdr_size, align);
     }
 
@@ -279,14 +281,18 @@ void *_realloc(void *ptr, size_t size)
     void *new;
     struct xmalloc_hdr *hdr;
     struct xmalloc_pad *pad;
+    size_t old_data_size;
 
     if (ptr == NULL)
         return _xmalloc(size, DEFAULT_ALIGN);
 
     pad = (struct xmalloc_pad *)ptr - 1;
     hdr = (struct xmalloc_hdr *)((char*)ptr - pad->hdr_size);
-    if (hdr->size >= size) {
-        maybe_split(hdr, size, hdr->size);
+
+    old_data_size = hdr->size - pad->hdr_size;
+    if ( old_data_size >= size )
+    {
+       maybe_split(hdr, pad->hdr_size + size, hdr->size);
         return ptr;
     }
     
@@ -294,7 +300,7 @@ void *_realloc(void *ptr, size_t size)
     if (new == NULL) 
         return NULL;
 
-    memcpy(new, ptr, hdr->size);
+    memcpy(new, ptr, old_data_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-3.4-testing] minios: xmalloc and realloc fixes, Xen patchbot-3.4-testing <=