From patchwork Wed Dec 29 19:17:01 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Przemyslaw Iskra X-Patchwork-Id: 76941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bilbo.ozlabs.org (localhost [127.0.0.1]) by ozlabs.org (Postfix) with ESMTP id A2A2E1007E6 for ; Thu, 30 Dec 2010 06:37:10 +1100 (EST) X-Greylist: delayed 1198 seconds by postgrey-1.32 at bilbo; Thu, 30 Dec 2010 06:37:07 EST Received: from ep09.pld-linux.org (ep09.pld-linux.org [217.73.31.20]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id DD175B70A7 for ; Thu, 30 Dec 2010 06:37:07 +1100 (EST) Received: from sparky by ep09.pld-linux.org with local (Exim 4.72) (envelope-from ) id 1PY1W9-0002xl-9h; Wed, 29 Dec 2010 20:17:01 +0100 Date: Wed, 29 Dec 2010 20:17:01 +0100 From: Przemyslaw Iskra To: yaboot-devel@lists.ozlabs.org Subject: Re: yaboot does not compile against new e2fsprogs release Message-ID: <20101229191700.GA8483@pld-linux.org> References: <20101229155921.cf81b721.acrux_it@libero.it> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20101229155921.cf81b721.acrux_it@libero.it> User-Agent: Mutt/1.5.20 (2009-06-14) X-BeenThere: yaboot-devel@lists.ozlabs.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Technical and development discussion regarding yaboot List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: yaboot-devel-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Errors-To: yaboot-devel-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org On Wed, Dec 29, 2010 at 03:59:21PM +0100, acrux wrote: > > hi all, > it seems that yaboot (1.3.16) does not compile against e2fsprogs > 1.41.12 > It could be the new (from e2fsprogs-1.41.13): > Added a new function to the ext2fs library, ext2fs_get_memalign(). attached patch could help, but note it is completely untested. diff --git a/include/stdlib.h b/include/stdlib.h index 0b5e99a..55707e4 100644 --- a/include/stdlib.h +++ b/include/stdlib.h @@ -11,10 +11,10 @@ extern void malloc_init(void *bottom, unsigned long size); extern void malloc_dispose(void); extern void *malloc(unsigned int size); +extern void *memalign(unsigned int alignment, unsigned int size); +int posix_memalign(void **memptr, unsigned int alignment, unsigned int size); extern void *realloc(void *ptr, unsigned int size); extern void free (void *m); -extern void mark (void **ptr); -extern void release (void *ptr); extern int sprintf(char * buf, const char *fmt, ...); extern int vsprintf(char *buf, const char *fmt, va_list args); diff --git a/lib/malloc.c b/lib/malloc.c index 81d7717..e9256b7 100644 --- a/lib/malloc.c +++ b/lib/malloc.c @@ -1,6 +1,7 @@ /* malloc.c - Dumb memory allocation routines * - * Copyright (C) 1997 Paul Mackerras + * Copyright (C) 2010 Przemyslaw Iskra + * 1997 Paul Mackerras * 1996 Maurizio Plaza * 1996 Jakub Jelinek * @@ -42,22 +43,51 @@ void malloc_dispose(void) last_alloc = 0; } -void *malloc (unsigned int size) +int posix_memalign(void **memptr, unsigned int alignment, unsigned int size) { char *caddr; if (!malloc_ptr) - return NULL; - if ((malloc_ptr + size + sizeof(int)) > malloc_top) { + return -1; /* should return ENOMEM */ + + if (alignment < sizeof(void*) ) + alignment = sizeof(void*); /* should return EINVAL */ + /* must be a power of 2 */ + if ((alignment & (alignment - 1)) != 0) + alignment = sizeof(long long); /* should return EINVAL */ + + if ((malloc_ptr + size + alignment) > malloc_top) { prom_printf("malloc failed\n"); - return NULL; + return -1; /* ENOMEM */ } - *(int *)malloc_ptr = size; - caddr = malloc_ptr + sizeof(int); - malloc_ptr += size + sizeof(int); + alignment--; + malloc_ptr = (char *) ((((unsigned int) malloc_ptr) + sizeof(int) + alignment) & (~alignment)); + ((int *)malloc_ptr)[-1] = size; + caddr = malloc_ptr; + malloc_ptr += size; last_alloc = caddr; - malloc_ptr = (char *) ((((unsigned int) malloc_ptr) + 3) & (~3)); - return caddr; + *memptr = caddr; + return 0; +} + +void *malloc (unsigned int size) +{ + void *ptr; + + if ( posix_memalign( &ptr, sizeof(void*), size ) != 0 ) + return NULL; + + return ptr; +} + +void *memalign (unsigned int alignment, unsigned int size) +{ + void *ptr; + + if ( posix_memalign( &ptr, alignment, size ) != 0 ) + return NULL; + + return ptr; } void *realloc(void *ptr, unsigned int size) @@ -86,21 +116,7 @@ void free (void *m) if (!malloc_ptr) return; if (m == last_alloc) - malloc_ptr = (char *) last_alloc - sizeof(int); -} - -void mark (void **ptr) -{ - if (!malloc_ptr) - return; - *ptr = (void *) malloc_ptr; -} - -void release (void *ptr) -{ - if (!malloc_ptr) - return; - malloc_ptr = (char *) ptr; + malloc_ptr = (int*) last_alloc - 1; } char *strdup(char const *str)