yaboot does not compile against new e2fsprogs release

Przemyslaw Iskra sparky at pld-linux.org
Thu Dec 30 06:17:01 EST 2010


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.

-- 
 ____    sparky  --  Przemyslaw  ................ LANG...Pl,Ca,Es,En
/____) ___  ___  _ _ || Iskra   : WWW . http://ppcrcd.pld-linux.org/
\____\| -_)'___| ||^'||//\\//   : WWW2 ............ http://rsget.pl/
(____/||   (_-_|_||  ||\\ ||    : eMail ..... <sparky at pld-linux.org>
-------------- next part --------------
>From 0da8274d0217afae7176debcbc159f816ce062a4 Mon Sep 17 00:00:00 2001
From: Przemys?aw Iskra <sparky at pld-linux.org>
Date: Wed, 29 Dec 2010 20:07:43 +0100
Subject: [PATCH] Added posix_memalign() and memalign() functions.

Adding those missing functions should solve compilation problems with
recent e2fsprogs.

Signed-off-by: Przemys?aw Iskra <sparky at pld-linux.org>
---
 include/stdlib.h |    4 +-
 lib/malloc.c     |   66 +++++++++++++++++++++++++++++++++--------------------
 2 files changed, 43 insertions(+), 27 deletions(-)

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)
-- 
1.7.3.2



More information about the Yaboot-devel mailing list