[syslinux:elflink] elflink: make malloc works

syslinux-bot for Feng Tang feng.tang at intel.com
Thu Aug 12 21:03:13 PDT 2010


Commit-ID:  406b3ea5275361e75db5bcba912e4d364e8f65df
Gitweb:     http://syslinux.zytor.com/commit/406b3ea5275361e75db5bcba912e4d364e8f65df
Author:     Feng Tang <feng.tang at intel.com>
AuthorDate: Sun, 13 Jun 2010 16:48:36 +0800
Committer:  Feng Tang <feng.tang at intel.com>
CommitDate: Tue, 20 Jul 2010 11:10:03 +0800

elflink: make malloc works

mask the malloc of com32, will still need to change
its way of calling inject_free_block


---
 com32/lib/free.c     |    2 ++
 com32/lib/malloc.c   |    2 ++
 com32/lib/sys/open.c |    2 +-
 core/elflink/cli.c   |    1 -
 core/fs/fs.c         |    4 ++--
 core/mem/free.c      |    4 +++-
 core/mem/init.c      |    3 +++
 core/mem/malloc.c    |   11 ++++++++++-
 8 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/com32/lib/free.c b/com32/lib/free.c
index ac9c789..fb8fdb4 100644
--- a/com32/lib/free.c
+++ b/com32/lib/free.c
@@ -98,6 +98,7 @@ void __inject_free_block(struct free_arena_header *ah)
     __free_block(ah);
 }
 
+#if 0
 void free(void *ptr)
 {
     struct free_arena_header *ah;
@@ -121,3 +122,4 @@ void free(void *ptr)
 
     /* Here we could insert code to return memory to the system. */
 }
+#endif
diff --git a/com32/lib/malloc.c b/com32/lib/malloc.c
index b03f456..ba79b65 100644
--- a/com32/lib/malloc.c
+++ b/com32/lib/malloc.c
@@ -139,6 +139,7 @@ static void *__malloc_from_block(struct free_arena_header *fp, size_t size)
     return (void *)(&fp->a + 1);
 }
 
+#if 0
 void *malloc(size_t size)
 {
     struct free_arena_header *fp;
@@ -166,6 +167,7 @@ void *malloc(size_t size)
     mp("will return 0x%p", buf);
     return buf;
 }
+#endif
 
 /* need to revisit this later */
 int posix_memalign(void **memptr, size_t align, size_t size)
diff --git a/com32/lib/sys/open.c b/com32/lib/sys/open.c
index d7a923b..1d7677b 100644
--- a/com32/lib/sys/open.c
+++ b/com32/lib/sys/open.c
@@ -57,7 +57,7 @@ int open(const char *pathname, int flags, ...)
 
     fd = opendev(&__file_dev, NULL, flags);
 
-    printf("enter, file = %s, fd = %d\n", pathname, fd);
+    //printf("enter, file = %s, fd = %d\n", pathname, fd);
 
     if (fd < 0)
 	return -1;
diff --git a/core/elflink/cli.c b/core/elflink/cli.c
index b3a2f91..db2c775 100644
--- a/core/elflink/cli.c
+++ b/core/elflink/cli.c
@@ -85,7 +85,6 @@ const char *edit_cmdline(const char *input, int top /*, int width */ ,
 	if (getscreensize(1, &height, &width))
 	    width = 80;
     }
-    printf("width = %d\n", width);
 
     strncpy(cmdline, input, MAX_CMDLINE_LEN);
     cmdline[MAX_CMDLINE_LEN - 1] = '\0';
diff --git a/core/fs/fs.c b/core/fs/fs.c
index 6c272e9..dfc24bc 100644
--- a/core/fs/fs.c
+++ b/core/fs/fs.c
@@ -220,7 +220,7 @@ int searchdir(const char *name)
     if (!pathbuf)
 	goto err;
 
-	mp("parent->ino = %d", parent->ino);
+	//mp("parent->ino = %d", parent->ino);
 
     do {
     got_link:
@@ -338,7 +338,7 @@ int open_file(const char *name, struct com32_filedata *filedata)
     mangle_name(mangled_name, name);
     rv = searchdir(mangled_name);
 
-    mp("name = %s, rv = %d", name, rv);
+    //mp("name = %s, rv = %d", name, rv);
 
     if (rv >= 0) {
 	file = handle_to_file(rv);
diff --git a/core/mem/free.c b/core/mem/free.c
index 58d7bd6..9d853a4 100644
--- a/core/mem/free.c
+++ b/core/mem/free.c
@@ -101,7 +101,7 @@ void __inject_free_block(struct free_arena_header *ah)
     size_t n_end;
 
     //dprintf("inject: %#zx bytes @ %p, heap %u (%p)\n",
-    mp("inject: %#zx bytes @ %p, heap %u (%p)",
+    printf("inject: %#zx bytes @%p, heap%u (%p)\n",
 	    ARENA_SIZE_GET(ah->a.attrs), ah,
 	    ARENA_HEAP_GET(ah->a.attrs), head);
 
@@ -116,6 +116,8 @@ void __inject_free_block(struct free_arena_header *ah)
         if ((size_t) ah >= n_end)
             continue;
 
+	printf("conflict:ah: %p, a_end: %p, nah: %p, n_end: %p\n", ah, a_end, nah, n_end);
+
         /* Otherwise we have some sort of overlap - reject this block */
         return;
     }
diff --git a/core/mem/init.c b/core/mem/init.c
index f35501c..5063633 100644
--- a/core/mem/init.c
+++ b/core/mem/init.c
@@ -3,6 +3,8 @@
 #include <string.h>
 #include "malloc.h"
 
+#include <stdio.h>
+
 struct free_arena_header __core_malloc_head[NHEAP];
 
 static __hugebss char main_heap[128 << 10];
@@ -29,6 +31,7 @@ void mem_init(void)
     ARENA_SIZE_SET(fp->a.attrs, sizeof main_heap);
     __inject_free_block(fp);
 
+	//mp("__lowmem_heap = 0x%p bios_free = 0x%p", __lowmem_heap, *bios_free_mem);
     /* Initialize the lowmem heap */
     fp = (struct free_arena_header *)__lowmem_heap;
     fp->a.attrs = ARENA_TYPE_USED | (HEAP_LOWMEM << ARENA_HEAP_POS);
diff --git a/core/mem/malloc.c b/core/mem/malloc.c
index b6953ad..0f41960 100644
--- a/core/mem/malloc.c
+++ b/core/mem/malloc.c
@@ -10,6 +10,8 @@
 #include <dprintf.h>
 #include "malloc.h"
 
+#include <stdio.h>
+
 static void *__malloc_from_block(struct free_arena_header *fp,
 				 size_t size, malloc_tag_t tag)
 {
@@ -63,6 +65,7 @@ static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag)
     struct free_arena_header *head = &__core_malloc_head[heap];
     void *p = NULL;
 
+    //mp("_malloc(%zu, %u, %u) @ %p = ",
     dprintf("_malloc(%zu, %u, %u) @ %p = ",
 	    size, heap, tag, __builtin_return_address(0));
 
@@ -79,7 +82,8 @@ static void *_malloc(size_t size, enum heap heap, malloc_tag_t tag)
         }
     }
 
-    dprintf("%p\n", p);
+    //dprintf("%p\n", p);
+    //printf("%p\n", p);
     return p;
 }
 
@@ -88,6 +92,11 @@ void *hmalloc(size_t size)
     return _malloc(size, HEAP_MAIN, MALLOC_CORE);
 }
 
+void *malloc(size_t size)
+{
+    return _malloc(size, HEAP_MAIN, MALLOC_CORE);
+}
+
 void *lmalloc(size_t size)
 {
     return _malloc(size, HEAP_LOWMEM, MALLOC_CORE);



More information about the Syslinux-commits mailing list