ia64/xen-unstable

changeset 16737:8984cc0a1d80

minios: add realloc

Signed-off-by: Samuel Thibault <samuel.thibault@eu.citrix.com>
Signed-off-by: Tim Deegan <tim.deegan@eu.citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Thu Jan 17 15:06:30 2008 +0000 (2008-01-17)
parents 8f6640070a86
children 2d9a8a4d7e73
files extras/mini-os/include/xmalloc.h extras/mini-os/lib/xmalloc.c
line diff
     1.1 --- a/extras/mini-os/include/xmalloc.h	Thu Jan 17 14:41:44 2008 +0000
     1.2 +++ b/extras/mini-os/include/xmalloc.h	Thu Jan 17 15:06:30 2008 +0000
     1.3 @@ -9,12 +9,15 @@
     1.4  
     1.5  #define malloc(size) _xmalloc(size, 4)
     1.6  #define free(ptr) xfree(ptr)
     1.7 +#define realloc(ptr, size) _realloc(ptr, size)
     1.8  
     1.9  /* Free any of the above. */
    1.10  extern void xfree(const void *);
    1.11  
    1.12  /* Underlying functions */
    1.13  extern void *_xmalloc(size_t size, size_t align);
    1.14 +extern void *_realloc(void *ptr, size_t size);
    1.15 +
    1.16  static inline void *_xmalloc_array(size_t size, size_t align, size_t num)
    1.17  {
    1.18  	/* Check for overflow. */
     2.1 --- a/extras/mini-os/lib/xmalloc.c	Thu Jan 17 14:41:44 2008 +0000
     2.2 +++ b/extras/mini-os/lib/xmalloc.c	Thu Jan 17 15:06:30 2008 +0000
     2.3 @@ -223,3 +223,24 @@ void xfree(const void *p)
     2.4      /* spin_unlock_irqrestore(&freelist_lock, flags); */
     2.5  }
     2.6  
     2.7 +void *_realloc(void *ptr, size_t size)
     2.8 +{
     2.9 +    void *new;
    2.10 +    struct xmalloc_hdr *hdr;
    2.11 +
    2.12 +    if (ptr == NULL)
    2.13 +        return _xmalloc(size, 4);
    2.14 +
    2.15 +    hdr = (struct xmalloc_hdr *)ptr - 1;
    2.16 +    if (hdr->size >= size) 
    2.17 +        return ptr;
    2.18 +    
    2.19 +    new = _xmalloc(size, 4);
    2.20 +    if (new == NULL) 
    2.21 +        return NULL;
    2.22 +
    2.23 +    memcpy(new, ptr, hdr->size);
    2.24 +    xfree(ptr);
    2.25 +
    2.26 +    return new;
    2.27 +}