[coreboot] fix memory allocator free list corruption

Jordan Crouse jordan.crouse at amd.com
Thu Aug 14 16:21:39 CEST 2008


On 14/08/08 13:12 +0200, Stefan Reinauer wrote:
> See patch
> 
> -- 
> coresystems GmbH • Brahmsstr. 16 • D-79104 Freiburg i. Br.
>       Tel.: +49 761 7668825 • Fax: +49 761 7664613
> Email: info at coresystems.dehttp://www.coresystems.de/
> Registergericht: Amtsgericht Freiburg • HRB 7656
> Geschäftsführer: Stefan Reinauer • Ust-IdNr.: DE245674866
> 

> * fix memory allocator bug that lead to freelist corruption on the first malloc
>   (and spent 8 bytes too much per malloc)
> * if the memory allocator detects freelist corruption, print a message instead
>   of silently dying.

> Signed-off-by: Stefan Reinauer <stepan at coresystems.de>
Acked-by: Jordan Crouse <jordan.crouse at amd.com>

I'm not 100% sure how we want to handle fatal errors.  I am not convinced
that a printf() -> halt() is the most customer friendly way.  But we have
so few of them right now, we don't need a solution right away.

Jordan

> Index: libc/malloc.c
> ===================================================================
> --- libc/malloc.c	(revision 3509)
> +++ libc/malloc.c	(working copy)
> @@ -92,13 +92,15 @@
>  		header = *((hdrtype_t *) ptr);
>  		int size = SIZE(header);
>  
> -		if (!HAS_MAGIC(header) || size == 0)
> +		if (!HAS_MAGIC(header) || size == 0) {
> +			printf("memory allocator panic.\n");
>  			halt();
> +		}
>  
>  		if (header & FLAG_FREE) {
>  			if (len <= size) {
>  				void *nptr = ptr + (HDRSIZE + len);
> -				int nsize = size - (len + 8);
> +				int nsize = size - (HDRSIZE + len);
>  
>  				/* Mark the block as used. */
>  				*((hdrtype_t *) ptr) = USED_BLOCK(len);
> @@ -109,7 +111,7 @@
>  
>  				if (nsize > 0)
>  					*((hdrtype_t *) nptr) =
> -					    FREE_BLOCK(nsize - 4);
> +					    FREE_BLOCK(nsize);
>  
>  				return (void *)(ptr + HDRSIZE);
>  			}

> --
> coreboot mailing list
> coreboot at coreboot.org
> http://www.coreboot.org/mailman/listinfo/coreboot


-- 
Jordan Crouse
Systems Software Development Engineer 
Advanced Micro Devices, Inc.





More information about the coreboot mailing list